Logo ROOT   6.12/07
Reference Guide
TSQLColumnInfo.cxx
Go to the documentation of this file.
1 // @(#)root/net:$Id$
2 // Author: Sergey Linev 31/05/2006
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 ////////////////////////////////////////////////////////////////////////////////
13 //
14 // TSQLColumnInfo
15 //
16 // Contains information about single column from SQL table
17 // Has following methods:
18 // GetTypeName() - field type name in string form as it is reported by correspondent
19 // database method. Some databases providing full type name like "numeric(20)",
20 // other showing only "NUMERIC". As a result, one cannot use this string directly
21 // to create new field of similar types in other table
22 // IsNullable() - says if field value can be NULL or not
23 // GetSQLType() - returns kind of sql type. Possible values:
24 // TSQLServer::kSQL_NONE data type unknown
25 // TSQLServer::kSQL_CHAR CHAR(n) - string with fixed length n
26 // TSQLServer::kSQL_VARCHAR VARCHAR(n) - string with variable length upto n
27 // TSQLServer::kSQL_INTEGER INTEGER, INT, TINYINT - any integer types
28 // TSQLServer::kSQL_FLOAT FLOAT - float value
29 // TSQLServer::kSQL_DOUBLE DOUBLE - double precision value
30 // TSQLServer::kSQL_NUMERIC NUMERIC(n,s), NUMBER(n,s) - numeric values with length and precion
31 // TSQLServer::kSQL_BINARY BLOB, VARBINARY - binary data (vriable or fixed size)
32 // TSQLServer::kSQL_TIMESTAMP TIMESTAMP - time and date stamp
33 // GetSize() - size of field in database. -1 if not known.
34 // GetLength() - length argument in type declaration like CHAR(len) or NUMERIC(len), -1 if not defined
35 // GetScale() - second argument in declarations like NUMERIC(len, s), -1 if not defined
36 // GetSigned() - is type signed(==1) or unsigned(==0), -1 if not defined
37 //
38 ////////////////////////////////////////////////////////////////////////////////
39 
40 #include "TSQLColumnInfo.h"
41 #include "TSQLServer.h"
42 #include "TROOT.h"
43 #include "Riostream.h"
44 
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// default contructor
49 
51  TNamed(),
52  fTypeName(),
53  fSQLType(-1),
54  fSize(-1),
55  fLength(-1),
56  fScale(-1),
57  fSigned(-1),
58  fNullable(kFALSE)
59 {
60 }
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 /// normal constructor
64 
65 TSQLColumnInfo::TSQLColumnInfo(const char* columnname,
66  const char* sqltypename,
67  Bool_t nullable,
68  Int_t sqltype,
69  Int_t size,
70  Int_t length,
71  Int_t scale,
72  Int_t sign) :
73  TNamed(columnname,"column information"),
74  fTypeName(sqltypename),
75  fSQLType(sqltype),
76  fSize(size),
77  fLength(length),
78  fScale(scale),
79  fSigned(sign),
80  fNullable(nullable)
81 {
82 }
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Prints column information to standard output
86 
88 {
90  std::cout << "Column: " << GetName()
91  << " type:'" << fTypeName << "'";
92  if (fSQLType>=0) {
93  std::cout << " typeid:";
94  switch (fSQLType) {
95  case TSQLServer::kSQL_CHAR : std::cout << "kSQL_CHAR"; break;
96  case TSQLServer::kSQL_VARCHAR : std::cout << "kSQL_VARCHAR"; break;
97  case TSQLServer::kSQL_INTEGER : std::cout << "kSQL_INTEGER"; break;
98  case TSQLServer::kSQL_FLOAT : std::cout << "kSQL_FLOAT"; break;
99  case TSQLServer::kSQL_DOUBLE : std::cout << "kSQL_DOUBLE"; break;
100  case TSQLServer::kSQL_NUMERIC : std::cout << "kSQL_NUMERIC"; break;
101  case TSQLServer::kSQL_BINARY : std::cout << "kSQL_BINARY"; break;
102  case TSQLServer::kSQL_TIMESTAMP : std::cout << "kSQL_TIMESTAMP"; break;
103  default: std::cout << fSQLType;
104  }
105  }
106  std::cout << " nullable:" << (fNullable ? "yes" : "no");
107  if (fSize>=0) std::cout << " size:" << fSize;
108  if (fLength>=0) std::cout << " len:" << fLength;
109  if (fScale>=0) std::cout << " scale:" << fScale;
110  if (fSigned>=0) {
111  if (fSigned==0)
112  std::cout << " unsigned";
113  else
114  std::cout << " signed";
115  }
116  std::cout << std::endl;
117 }
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
const char Option_t
Definition: RtypesCore.h:62
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Int_t fLength
size of column in bytes, -1 if not defing
Bool_t fNullable
if datatype signed or not, 0 - kFALSE, 1 - kTRUE, -1 - unknown
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Int_t fScale
datatype length definition, for instance VARCHAR(len) or FLOAT(len), -1 if not defined ...
virtual void Print(Option_t *option="") const
Prints column information to standard output.
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2746
const Bool_t kFALSE
Definition: RtypesCore.h:88
TSQLColumnInfo()
identify if value can be NULL
#define ClassImp(name)
Definition: Rtypes.h:359
Int_t fSize
datatype code (see TSQLServer::ESQLDataTypes constants), -1 if not defeined
Int_t fSQLType
sql type name, as reported by DB. Should be as much as close to declaration of column in CREATE TABLE...
Int_t fSigned
datatype scale factor, used for instance in NUMBER(len,scale) definition. -1 if not defined ...