TSQLColumnInfo.cxx

Go to the documentation of this file.
00001 // @(#)root/net:$Id: TSQLColumnInfo.cxx 23091 2008-04-09 15:04:27Z rdm $
00002 // Author: Sergey Linev   31/05/2006
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 ////////////////////////////////////////////////////////////////////////////////
00013 //                                                                      
00014 // TSQLColumnInfo
00015 //
00016 // Contains information about single column from SQL table
00017 // Has following methods:
00018 //   GetTypeName() - field type name in string form as it is reported by correspondent
00019 //          database method. Some databases providing full type name like "numeric(20)",
00020 //          other showing only "NUMERIC". As a result, one cannot use this string directly
00021 //          to create new field of similar types in other table 
00022 //   IsNullable() - says if field value can be NULL or not
00023 //   GetSQLType() - returns kind of sql type. Possible values:
00024 //      TSQLServer::kSQL_NONE        data type unknown
00025 //      TSQLServer::kSQL_CHAR        CHAR(n) - string with fixed length n
00026 //      TSQLServer::kSQL_VARCHAR     VARCHAR(n) - string with variable length upto n
00027 //      TSQLServer::kSQL_INTEGER     INTEGER, INT, TINYINT - any integer types
00028 //      TSQLServer::kSQL_FLOAT       FLOAT - float value
00029 //      TSQLServer::kSQL_DOUBLE      DOUBLE - double precision value
00030 //      TSQLServer::kSQL_NUMERIC     NUMERIC(n,s), NUMBER(n,s) - numeric values with length and precion
00031 //      TSQLServer::kSQL_BINARY      BLOB, VARBINARY  - binary data (vriable or fixed size)
00032 //      TSQLServer::kSQL_TIMESTAMP   TIMESTAMP - time and date stamp
00033 //   GetSize() - size of field in database. -1 if not known.
00034 //   GetLength() - length argument in type declaration like CHAR(len) or NUMERIC(len), -1 if not defined
00035 //   GetScale() - second argument in declarations like NUMERIC(len, s), -1 if not defined
00036 //   GetSigned() - is type signed(==1) or unsigned(==0), -1 if not defined
00037 //                                                                      
00038 ////////////////////////////////////////////////////////////////////////////////
00039 
00040 #include "TSQLColumnInfo.h"
00041 #include "TSQLServer.h"
00042 #include "TROOT.h"
00043 #include "Riostream.h"
00044 
00045 ClassImp(TSQLColumnInfo)
00046 
00047 //______________________________________________________________________________
00048 TSQLColumnInfo::TSQLColumnInfo() : 
00049    TNamed(),
00050    fTypeName(),
00051    fSQLType(-1),
00052    fSize(-1),
00053    fLength(-1),
00054    fScale(-1),
00055    fSigned(-1),
00056    fNullable(kFALSE)
00057 {
00058    // default contructor
00059 }
00060 
00061 //______________________________________________________________________________
00062 TSQLColumnInfo::TSQLColumnInfo(const char* columnname,
00063                                const char* sqltypename,
00064                                Bool_t nullable,
00065                                Int_t sqltype,
00066                                Int_t size,
00067                                Int_t length,
00068                                Int_t scale,
00069                                Int_t sign) :
00070    TNamed(columnname,"column information"),
00071    fTypeName(sqltypename),
00072    fSQLType(sqltype),
00073    fSize(size),
00074    fLength(length),
00075    fScale(scale),
00076    fSigned(sign),
00077    fNullable(nullable)
00078 {
00079    // normal constructor
00080 }
00081 
00082 //______________________________________________________________________________
00083 void TSQLColumnInfo::Print(Option_t*) const
00084 {
00085    // Prints column information to standard output
00086    
00087    TROOT::IndentLevel();
00088    cout << "Column: " << GetName() 
00089         << " type:'" << fTypeName << "'"; 
00090    if (fSQLType>=0) {
00091       cout << " typeid:";
00092       switch (fSQLType) {
00093          case TSQLServer::kSQL_CHAR : cout << "kSQL_CHAR"; break;
00094          case TSQLServer::kSQL_VARCHAR : cout << "kSQL_VARCHAR"; break;
00095          case TSQLServer::kSQL_INTEGER : cout << "kSQL_INTEGER"; break;
00096          case TSQLServer::kSQL_FLOAT : cout << "kSQL_FLOAT"; break;
00097          case TSQLServer::kSQL_DOUBLE : cout << "kSQL_DOUBLE"; break;
00098          case TSQLServer::kSQL_NUMERIC : cout << "kSQL_NUMERIC"; break;
00099          case TSQLServer::kSQL_BINARY : cout << "kSQL_BINARY"; break;
00100          case TSQLServer::kSQL_TIMESTAMP : cout << "kSQL_TIMESTAMP"; break;
00101          default: cout << fSQLType;
00102       }
00103    }
00104    cout << " nullable:" << (fNullable ? "yes" : "no");
00105    if (fSize>=0) cout << " size:" << fSize;
00106    if (fLength>=0) cout << " len:" << fLength;
00107    if (fScale>=0) cout << " scale:" << fScale;
00108    if (fSigned>=0) { 
00109       if (fSigned==0)
00110          cout << " unsigned";
00111       else
00112          cout << " signed";
00113    }
00114    cout << endl;
00115 }

Generated on Tue Jul 5 14:46:11 2011 for ROOT_528-00b_version by  doxygen 1.5.1