// @(#)root/net:$Id$
// Author: Sergey Linev   31/05/2006

/*************************************************************************
 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

////////////////////////////////////////////////////////////////////////////////
//
// TSQLColumnInfo
//
// Contains information about single column from SQL table
// Has following methods:
//   GetTypeName() - field type name in string form as it is reported by correspondent
//          database method. Some databases providing full type name like "numeric(20)",
//          other showing only "NUMERIC". As a result, one cannot use this string directly
//          to create new field of similar types in other table
//   IsNullable() - says if field value can be NULL or not
//   GetSQLType() - returns kind of sql type. Possible values:
//      TSQLServer::kSQL_NONE        data type unknown
//      TSQLServer::kSQL_CHAR        CHAR(n) - string with fixed length n
//      TSQLServer::kSQL_VARCHAR     VARCHAR(n) - string with variable length upto n
//      TSQLServer::kSQL_INTEGER     INTEGER, INT, TINYINT - any integer types
//      TSQLServer::kSQL_FLOAT       FLOAT - float value
//      TSQLServer::kSQL_DOUBLE      DOUBLE - double precision value
//      TSQLServer::kSQL_NUMERIC     NUMERIC(n,s), NUMBER(n,s) - numeric values with length and precion
//      TSQLServer::kSQL_BINARY      BLOB, VARBINARY  - binary data (vriable or fixed size)
//      TSQLServer::kSQL_TIMESTAMP   TIMESTAMP - time and date stamp
//   GetSize() - size of field in database. -1 if not known.
//   GetLength() - length argument in type declaration like CHAR(len) or NUMERIC(len), -1 if not defined
//   GetScale() - second argument in declarations like NUMERIC(len, s), -1 if not defined
//   GetSigned() - is type signed(==1) or unsigned(==0), -1 if not defined
//
////////////////////////////////////////////////////////////////////////////////

#include "TSQLColumnInfo.h"
#include "TSQLServer.h"
#include "TROOT.h"
#include "Riostream.h"

ClassImp(TSQLColumnInfo)

//______________________________________________________________________________
TSQLColumnInfo::TSQLColumnInfo() :
   TNamed(),
   fTypeName(),
   fSQLType(-1),
   fSize(-1),
   fLength(-1),
   fScale(-1),
   fSigned(-1),
   fNullable(kFALSE)
{
   // default contructor
}

//______________________________________________________________________________
TSQLColumnInfo::TSQLColumnInfo(const char* columnname,
                               const char* sqltypename,
                               Bool_t nullable,
                               Int_t sqltype,
                               Int_t size,
                               Int_t length,
                               Int_t scale,
                               Int_t sign) :
   TNamed(columnname,"column information"),
   fTypeName(sqltypename),
   fSQLType(sqltype),
   fSize(size),
   fLength(length),
   fScale(scale),
   fSigned(sign),
   fNullable(nullable)
{
   // normal constructor
}

//______________________________________________________________________________
void TSQLColumnInfo::Print(Option_t*) const
{
   // Prints column information to standard output

   TROOT::IndentLevel();
   std::cout << "Column: " << GetName()
        << " type:'" << fTypeName << "'";
   if (fSQLType>=0) {
      std::cout << " typeid:";
      switch (fSQLType) {
         case TSQLServer::kSQL_CHAR : std::cout << "kSQL_CHAR"; break;
         case TSQLServer::kSQL_VARCHAR : std::cout << "kSQL_VARCHAR"; break;
         case TSQLServer::kSQL_INTEGER : std::cout << "kSQL_INTEGER"; break;
         case TSQLServer::kSQL_FLOAT : std::cout << "kSQL_FLOAT"; break;
         case TSQLServer::kSQL_DOUBLE : std::cout << "kSQL_DOUBLE"; break;
         case TSQLServer::kSQL_NUMERIC : std::cout << "kSQL_NUMERIC"; break;
         case TSQLServer::kSQL_BINARY : std::cout << "kSQL_BINARY"; break;
         case TSQLServer::kSQL_TIMESTAMP : std::cout << "kSQL_TIMESTAMP"; break;
         default: std::cout << fSQLType;
      }
   }
   std::cout << " nullable:" << (fNullable ? "yes" : "no");
   if (fSize>=0) std::cout << " size:" << fSize;
   if (fLength>=0) std::cout << " len:" << fLength;
   if (fScale>=0) std::cout << " scale:" << fScale;
   if (fSigned>=0) {
      if (fSigned==0)
         std::cout << " unsigned";
      else
         std::cout << " signed";
   }
   std::cout << std::endl;
}
 TSQLColumnInfo.cxx:1
 TSQLColumnInfo.cxx:2
 TSQLColumnInfo.cxx:3
 TSQLColumnInfo.cxx:4
 TSQLColumnInfo.cxx:5
 TSQLColumnInfo.cxx:6
 TSQLColumnInfo.cxx:7
 TSQLColumnInfo.cxx:8
 TSQLColumnInfo.cxx:9
 TSQLColumnInfo.cxx:10
 TSQLColumnInfo.cxx:11
 TSQLColumnInfo.cxx:12
 TSQLColumnInfo.cxx:13
 TSQLColumnInfo.cxx:14
 TSQLColumnInfo.cxx:15
 TSQLColumnInfo.cxx:16
 TSQLColumnInfo.cxx:17
 TSQLColumnInfo.cxx:18
 TSQLColumnInfo.cxx:19
 TSQLColumnInfo.cxx:20
 TSQLColumnInfo.cxx:21
 TSQLColumnInfo.cxx:22
 TSQLColumnInfo.cxx:23
 TSQLColumnInfo.cxx:24
 TSQLColumnInfo.cxx:25
 TSQLColumnInfo.cxx:26
 TSQLColumnInfo.cxx:27
 TSQLColumnInfo.cxx:28
 TSQLColumnInfo.cxx:29
 TSQLColumnInfo.cxx:30
 TSQLColumnInfo.cxx:31
 TSQLColumnInfo.cxx:32
 TSQLColumnInfo.cxx:33
 TSQLColumnInfo.cxx:34
 TSQLColumnInfo.cxx:35
 TSQLColumnInfo.cxx:36
 TSQLColumnInfo.cxx:37
 TSQLColumnInfo.cxx:38
 TSQLColumnInfo.cxx:39
 TSQLColumnInfo.cxx:40
 TSQLColumnInfo.cxx:41
 TSQLColumnInfo.cxx:42
 TSQLColumnInfo.cxx:43
 TSQLColumnInfo.cxx:44
 TSQLColumnInfo.cxx:45
 TSQLColumnInfo.cxx:46
 TSQLColumnInfo.cxx:47
 TSQLColumnInfo.cxx:48
 TSQLColumnInfo.cxx:49
 TSQLColumnInfo.cxx:50
 TSQLColumnInfo.cxx:51
 TSQLColumnInfo.cxx:52
 TSQLColumnInfo.cxx:53
 TSQLColumnInfo.cxx:54
 TSQLColumnInfo.cxx:55
 TSQLColumnInfo.cxx:56
 TSQLColumnInfo.cxx:57
 TSQLColumnInfo.cxx:58
 TSQLColumnInfo.cxx:59
 TSQLColumnInfo.cxx:60
 TSQLColumnInfo.cxx:61
 TSQLColumnInfo.cxx:62
 TSQLColumnInfo.cxx:63
 TSQLColumnInfo.cxx:64
 TSQLColumnInfo.cxx:65
 TSQLColumnInfo.cxx:66
 TSQLColumnInfo.cxx:67
 TSQLColumnInfo.cxx:68
 TSQLColumnInfo.cxx:69
 TSQLColumnInfo.cxx:70
 TSQLColumnInfo.cxx:71
 TSQLColumnInfo.cxx:72
 TSQLColumnInfo.cxx:73
 TSQLColumnInfo.cxx:74
 TSQLColumnInfo.cxx:75
 TSQLColumnInfo.cxx:76
 TSQLColumnInfo.cxx:77
 TSQLColumnInfo.cxx:78
 TSQLColumnInfo.cxx:79
 TSQLColumnInfo.cxx:80
 TSQLColumnInfo.cxx:81
 TSQLColumnInfo.cxx:82
 TSQLColumnInfo.cxx:83
 TSQLColumnInfo.cxx:84
 TSQLColumnInfo.cxx:85
 TSQLColumnInfo.cxx:86
 TSQLColumnInfo.cxx:87
 TSQLColumnInfo.cxx:88
 TSQLColumnInfo.cxx:89
 TSQLColumnInfo.cxx:90
 TSQLColumnInfo.cxx:91
 TSQLColumnInfo.cxx:92
 TSQLColumnInfo.cxx:93
 TSQLColumnInfo.cxx:94
 TSQLColumnInfo.cxx:95
 TSQLColumnInfo.cxx:96
 TSQLColumnInfo.cxx:97
 TSQLColumnInfo.cxx:98
 TSQLColumnInfo.cxx:99
 TSQLColumnInfo.cxx:100
 TSQLColumnInfo.cxx:101
 TSQLColumnInfo.cxx:102
 TSQLColumnInfo.cxx:103
 TSQLColumnInfo.cxx:104
 TSQLColumnInfo.cxx:105
 TSQLColumnInfo.cxx:106
 TSQLColumnInfo.cxx:107
 TSQLColumnInfo.cxx:108
 TSQLColumnInfo.cxx:109
 TSQLColumnInfo.cxx:110
 TSQLColumnInfo.cxx:111
 TSQLColumnInfo.cxx:112
 TSQLColumnInfo.cxx:113
 TSQLColumnInfo.cxx:114
 TSQLColumnInfo.cxx:115