ROOT logo
//*-- AUTHOR : Ilse Koenig
//*-- Modified : 11/09/2000

//_HADES_CLASS_DESCRIPTION 
/////////////////////////////////////////////////////////////////////////
// HDbColumnType
//
// Base class for Oracle column types
//
// Derived classes are:
//   HDbColCharType  for Oracle type CHAR
//   HDbColVcType                    VARCHAR2
//   HDbColNumType                   NUMBER
//   HDbColDateType                  DATE
//   HDbColRowidType                 ROWID
//   HDbColLongType                  LONG
//   HDbColRawType                   RAW
//
//   Because of problems to convert LONG and RAW types to VARCHAR2, the
//   datatypes LONG and RAW are actually not supported.
//   
/////////////////////////////////////////////////////////////////////////

#include "hdbcolumntype.h"

ClassImp(HDbColumnType)
ClassImp(HDbColCharType)
ClassImp(HDbColVcType)
ClassImp(HDbColNumType)
ClassImp(HDbColDateType)
ClassImp(HDbColLongType)
ClassImp(HDbColRowidType)
ClassImp(HDbColRawType)

HDbColumnType::HDbColumnType(const Char_t* n, Int_t l, Int_t p, Int_t s ) {
  // Constructor
  SetName(n);
  varLength=l;
  dataPrecision=p;
  dataScale=s;
}  

TString HDbColumnType::getSelectString(const Char_t* col, const Char_t*) {
  // Base class funtion returns an emtpy string because the current type is not
  // supported
  Error("HDbColumnType::getNvlSelectString",
        "\n  Type %s of columnn %s actually not supported",
        GetName(), col);
  TString s("");
  return s;
}

TString HDbColumnType::getNvlSelectString(const Char_t* col, const Char_t* td,
                                          const Char_t*){
  // Base class funtion returns an emtpy string because the current type is not
  // supported
  TString s(getSelectString(col,td));
  return s;
}

HDbColCharType::HDbColCharType(Int_t l) : HDbColumnType("CHAR",l) {
  // Constructor for type CHAR (default length 1)
  if (l<=0) varLength=1;
}

TString HDbColCharType::getTypeString() {
  // Returns the type string, e.g. "CHAR(1)"
  TString s=("CHAR(");
  Char_t buf[10];
  sprintf(buf,"%i",varLength);
  s=s + buf + ")";
  return s;
}

TString HDbColCharType::getSelectString(const Char_t* col, const Char_t* td) {
  // Returns the name of the column enclosed in given text delimiter
  TString s;
  if (varLength>1) {
    if (strcmp(td,"'")==0) s=s + "''''||" + col + "||''''";
    else s=s + "'" + td + "'||" + col + "||'" + td + "'";
  }
  else s=col;
  return s;
}

TString HDbColCharType::getNvlSelectString(const Char_t* col, const Char_t* td,
                                           const Char_t* sNull) {
  // Returns the name of the column enclosed in given text delimiter or specified
  // null string if column value is null
  TString s;
  if (varLength>1) {
    if (strcmp(td,"'")==0)
       s=s + "''''||nvl(" + col + ",'" + sNull + "')||''''";
    else s=s + "'" + td + "'||nvl(" + col + ",'" + sNull + "')||'"
         + td + "'";
  }
  else s=s + "nvl(" + col + ",'" + sNull + "')";
  return s;
}

HDbColVcType::HDbColVcType(Int_t l) : HDbColumnType("VARCHAR2",l) {
  // Constructor for type VARCHAR2 (default length 80)
  if (l<=0) varLength=80;
}

TString HDbColVcType::getTypeString() {
  // Returns the type string, e.g. "VARCHAR2(80)"
  TString s=("VARCHAR2(");
  Char_t buf[10];
  sprintf(buf,"%i",varLength);
  s=s + buf + ")";
  return s;
}

TString HDbColVcType::getSelectString(const Char_t* col, const Char_t* td) {
  // Returns the name of the column enclosed in given text delimiter
  TString s;
  if (varLength>1) {
    if (strcmp(td,"'")==0) s=s + "''''||" + col + "||''''";
    else s=s + "'" + td + "'||" + col + "||'" + td + "'";
  }
  else s=col;
  return s;
}

TString HDbColVcType::getNvlSelectString(const Char_t* col, const Char_t* td,
                                           const Char_t* sNull) {
  // Returns the name of the column enclosed in given text delimiter or specified
  // null string if column value is null
  TString s;
  if (varLength>1) {
    if (strcmp(td,"'")==0)
       s=s + "''''||nvl(" + col + ",'" + sNull + "')||''''";
    else s=s + "'" + td + "'||nvl(" + col + ",'" + sNull + "')||'"
         + td + "'";
  }
  else s=s + "nvl(" + col + ",'" + sNull + "')";
  return s;
}

HDbColNumType::HDbColNumType(Int_t p, Int_t s)
               : HDbColumnType("NUMBER",sizeof(Double_t),p,s) {
  // Constructor for type NUMBER with specified precision and scale (default precision 40)
  if (p<=0) dataPrecision=40;
}

TString HDbColNumType::getTypeString() {
  // Returns the type string "NUMBER(p,s)"
  TString s=("NUMBER");
  if (dataPrecision==40) return s;
  Char_t buf[100];
  sprintf(buf,"%i",dataPrecision);
  s=s + "(" + buf;
  if (dataScale>=0) {
    sprintf(buf,"%i",dataScale);
    s=s + "," + buf;
  }
  s=s + ")";
  return s;
}

TString HDbColNumType::getSelectString(const Char_t* col, const Char_t*) {
  // Returns the string to convert the number column to characters
  // null string if column value is null
  TString s("to_char(");
  s=s + col + ")";
  return s;
}

TString HDbColNumType::getNvlSelectString(const Char_t* col, const Char_t*, const Char_t* sNull) {
  // Returns the string to convert the number column to characters or to replace by the
  // specified null string if the column value is null
  TString s("nvl(to_char(");
  s=s + col + "),'" + sNull + "')";
  return s;
}

HDbColDateType::HDbColDateType(Int_t l) : HDbColumnType("DATE",l) {
  // Constructor for type DATE
  if (l<=0) varLength=75;
}

TString HDbColDateType::getSelectString(const Char_t* col, const Char_t* td) {
  // Returns the string to convert the date column to characters enclosed in specified
  // text delimiter to allow a blank between the date and the time
  TString s;
  if (strcmp(td,"'")==0)
     s=s + "''''||to_char(" + col + ")||''''";
  else s=s + "'" + td + "'||to_char(" + col + ")||'" + td + "'";
  return s;
}

TString HDbColDateType::getNvlSelectString(const Char_t* col, const Char_t* td,
                                           const Char_t* sNull) {
  // Returns the string to convert the date column to characters enclosed in specified
  // text delimiter to allow a blank between the date and the time
  // or the specified null string if the column value is null
  TString s;
  if (strcmp(td,"'")==0)
     s=s + "''''||nvl(to_char(" + col + "),'" + sNull + "')||''''";
  else s=s + "'" + td + "'||nvl(to_char(" + col + "),'" + sNull + "')||'"
         + td + "'";
  return s;
}

HDbColLongType::HDbColLongType(Int_t l) : HDbColumnType("LONG",l) {
  // Constructor for type LONG (default length 32767)
  // WARNING: This datatype is actually not supported!
  if (l<=0) varLength=32767;
}

TString HDbColRowidType::getSelectString(const Char_t* col, const Char_t*) {
  // Returns the string to convert the rowid column to characters
  TString s("rowidtochar(");
  s=s + col + ")";
  return s;
}

TString HDbColRowidType::getNvlSelectString(const Char_t* col, const Char_t*,
                                            const Char_t* sNull) {
  // Returns the string to convert the rowid column to characters or the specified
  // null string if the column value is null
  TString s("nvl(rowidtochar(");
  s=s + col + "),'" + sNull + "')";
  return s;
}

HDbColRawType::HDbColRawType(Int_t l) : HDbColumnType("RAW",l) {
  // Constructor for type RAW (default length 255)
  // WARNING: This datatype is actually not supported!
  if (l<=0) varLength=255;
}

TString HDbColRawType::getTypeString() {
  // Returns the type string, e.g. "RAW(255)"
  TString s=("RAW(");
  Char_t buf[10];
  sprintf(buf,"%i",varLength);
  s=s + buf + ")";
  return s;
}
 hdbcolumntype.cc:1
 hdbcolumntype.cc:2
 hdbcolumntype.cc:3
 hdbcolumntype.cc:4
 hdbcolumntype.cc:5
 hdbcolumntype.cc:6
 hdbcolumntype.cc:7
 hdbcolumntype.cc:8
 hdbcolumntype.cc:9
 hdbcolumntype.cc:10
 hdbcolumntype.cc:11
 hdbcolumntype.cc:12
 hdbcolumntype.cc:13
 hdbcolumntype.cc:14
 hdbcolumntype.cc:15
 hdbcolumntype.cc:16
 hdbcolumntype.cc:17
 hdbcolumntype.cc:18
 hdbcolumntype.cc:19
 hdbcolumntype.cc:20
 hdbcolumntype.cc:21
 hdbcolumntype.cc:22
 hdbcolumntype.cc:23
 hdbcolumntype.cc:24
 hdbcolumntype.cc:25
 hdbcolumntype.cc:26
 hdbcolumntype.cc:27
 hdbcolumntype.cc:28
 hdbcolumntype.cc:29
 hdbcolumntype.cc:30
 hdbcolumntype.cc:31
 hdbcolumntype.cc:32
 hdbcolumntype.cc:33
 hdbcolumntype.cc:34
 hdbcolumntype.cc:35
 hdbcolumntype.cc:36
 hdbcolumntype.cc:37
 hdbcolumntype.cc:38
 hdbcolumntype.cc:39
 hdbcolumntype.cc:40
 hdbcolumntype.cc:41
 hdbcolumntype.cc:42
 hdbcolumntype.cc:43
 hdbcolumntype.cc:44
 hdbcolumntype.cc:45
 hdbcolumntype.cc:46
 hdbcolumntype.cc:47
 hdbcolumntype.cc:48
 hdbcolumntype.cc:49
 hdbcolumntype.cc:50
 hdbcolumntype.cc:51
 hdbcolumntype.cc:52
 hdbcolumntype.cc:53
 hdbcolumntype.cc:54
 hdbcolumntype.cc:55
 hdbcolumntype.cc:56
 hdbcolumntype.cc:57
 hdbcolumntype.cc:58
 hdbcolumntype.cc:59
 hdbcolumntype.cc:60
 hdbcolumntype.cc:61
 hdbcolumntype.cc:62
 hdbcolumntype.cc:63
 hdbcolumntype.cc:64
 hdbcolumntype.cc:65
 hdbcolumntype.cc:66
 hdbcolumntype.cc:67
 hdbcolumntype.cc:68
 hdbcolumntype.cc:69
 hdbcolumntype.cc:70
 hdbcolumntype.cc:71
 hdbcolumntype.cc:72
 hdbcolumntype.cc:73
 hdbcolumntype.cc:74
 hdbcolumntype.cc:75
 hdbcolumntype.cc:76
 hdbcolumntype.cc:77
 hdbcolumntype.cc:78
 hdbcolumntype.cc:79
 hdbcolumntype.cc:80
 hdbcolumntype.cc:81
 hdbcolumntype.cc:82
 hdbcolumntype.cc:83
 hdbcolumntype.cc:84
 hdbcolumntype.cc:85
 hdbcolumntype.cc:86
 hdbcolumntype.cc:87
 hdbcolumntype.cc:88
 hdbcolumntype.cc:89
 hdbcolumntype.cc:90
 hdbcolumntype.cc:91
 hdbcolumntype.cc:92
 hdbcolumntype.cc:93
 hdbcolumntype.cc:94
 hdbcolumntype.cc:95
 hdbcolumntype.cc:96
 hdbcolumntype.cc:97
 hdbcolumntype.cc:98
 hdbcolumntype.cc:99
 hdbcolumntype.cc:100
 hdbcolumntype.cc:101
 hdbcolumntype.cc:102
 hdbcolumntype.cc:103
 hdbcolumntype.cc:104
 hdbcolumntype.cc:105
 hdbcolumntype.cc:106
 hdbcolumntype.cc:107
 hdbcolumntype.cc:108
 hdbcolumntype.cc:109
 hdbcolumntype.cc:110
 hdbcolumntype.cc:111
 hdbcolumntype.cc:112
 hdbcolumntype.cc:113
 hdbcolumntype.cc:114
 hdbcolumntype.cc:115
 hdbcolumntype.cc:116
 hdbcolumntype.cc:117
 hdbcolumntype.cc:118
 hdbcolumntype.cc:119
 hdbcolumntype.cc:120
 hdbcolumntype.cc:121
 hdbcolumntype.cc:122
 hdbcolumntype.cc:123
 hdbcolumntype.cc:124
 hdbcolumntype.cc:125
 hdbcolumntype.cc:126
 hdbcolumntype.cc:127
 hdbcolumntype.cc:128
 hdbcolumntype.cc:129
 hdbcolumntype.cc:130
 hdbcolumntype.cc:131
 hdbcolumntype.cc:132
 hdbcolumntype.cc:133
 hdbcolumntype.cc:134
 hdbcolumntype.cc:135
 hdbcolumntype.cc:136
 hdbcolumntype.cc:137
 hdbcolumntype.cc:138
 hdbcolumntype.cc:139
 hdbcolumntype.cc:140
 hdbcolumntype.cc:141
 hdbcolumntype.cc:142
 hdbcolumntype.cc:143
 hdbcolumntype.cc:144
 hdbcolumntype.cc:145
 hdbcolumntype.cc:146
 hdbcolumntype.cc:147
 hdbcolumntype.cc:148
 hdbcolumntype.cc:149
 hdbcolumntype.cc:150
 hdbcolumntype.cc:151
 hdbcolumntype.cc:152
 hdbcolumntype.cc:153
 hdbcolumntype.cc:154
 hdbcolumntype.cc:155
 hdbcolumntype.cc:156
 hdbcolumntype.cc:157
 hdbcolumntype.cc:158
 hdbcolumntype.cc:159
 hdbcolumntype.cc:160
 hdbcolumntype.cc:161
 hdbcolumntype.cc:162
 hdbcolumntype.cc:163
 hdbcolumntype.cc:164
 hdbcolumntype.cc:165
 hdbcolumntype.cc:166
 hdbcolumntype.cc:167
 hdbcolumntype.cc:168
 hdbcolumntype.cc:169
 hdbcolumntype.cc:170
 hdbcolumntype.cc:171
 hdbcolumntype.cc:172
 hdbcolumntype.cc:173
 hdbcolumntype.cc:174
 hdbcolumntype.cc:175
 hdbcolumntype.cc:176
 hdbcolumntype.cc:177
 hdbcolumntype.cc:178
 hdbcolumntype.cc:179
 hdbcolumntype.cc:180
 hdbcolumntype.cc:181
 hdbcolumntype.cc:182
 hdbcolumntype.cc:183
 hdbcolumntype.cc:184
 hdbcolumntype.cc:185
 hdbcolumntype.cc:186
 hdbcolumntype.cc:187
 hdbcolumntype.cc:188
 hdbcolumntype.cc:189
 hdbcolumntype.cc:190
 hdbcolumntype.cc:191
 hdbcolumntype.cc:192
 hdbcolumntype.cc:193
 hdbcolumntype.cc:194
 hdbcolumntype.cc:195
 hdbcolumntype.cc:196
 hdbcolumntype.cc:197
 hdbcolumntype.cc:198
 hdbcolumntype.cc:199
 hdbcolumntype.cc:200
 hdbcolumntype.cc:201
 hdbcolumntype.cc:202
 hdbcolumntype.cc:203
 hdbcolumntype.cc:204
 hdbcolumntype.cc:205
 hdbcolumntype.cc:206
 hdbcolumntype.cc:207
 hdbcolumntype.cc:208
 hdbcolumntype.cc:209
 hdbcolumntype.cc:210
 hdbcolumntype.cc:211
 hdbcolumntype.cc:212
 hdbcolumntype.cc:213
 hdbcolumntype.cc:214
 hdbcolumntype.cc:215
 hdbcolumntype.cc:216
 hdbcolumntype.cc:217
 hdbcolumntype.cc:218
 hdbcolumntype.cc:219
 hdbcolumntype.cc:220
 hdbcolumntype.cc:221
 hdbcolumntype.cc:222
 hdbcolumntype.cc:223
 hdbcolumntype.cc:224
 hdbcolumntype.cc:225
 hdbcolumntype.cc:226
 hdbcolumntype.cc:227
 hdbcolumntype.cc:228
 hdbcolumntype.cc:229
 hdbcolumntype.cc:230
 hdbcolumntype.cc:231
 hdbcolumntype.cc:232
 hdbcolumntype.cc:233
 hdbcolumntype.cc:234
 hdbcolumntype.cc:235
 hdbcolumntype.cc:236
 hdbcolumntype.cc:237
 hdbcolumntype.cc:238
 hdbcolumntype.cc:239
 hdbcolumntype.cc:240
 hdbcolumntype.cc:241