22 #ifndef __ODBCXX_TYPES_H
23 #define __ODBCXX_TYPES_H
25 #include <odbc++/setup.h>
31 #if !defined(ODBCXX_QT)
38 #if defined(ODBCXX_NO_STD_TIME_T)
44 #if defined(ODBCXX_QT)
48 #if defined(ODBCXX_HAVE_ISQL_H) && defined(ODBCXX_HAVE_ISQLEXT_H)
51 #elif defined(ODBCXX_HAVE_SQL_H) && defined(ODBCXX_HAVE_SQLEXT_H)
55 # error "Whoops. Can not recognize the ODBC subsystem."
58 #if defined(ODBCXX_HAVE_SQLUCODE_H)
59 # include <sqlucode.h>
62 #if defined(ODBCXX_HAVE_DB2SQLCLI_H)
68 #if !defined(SQL_TRUE)
72 #if !defined(SQL_FALSE)
77 #if ODBCVER >= 0x0300 && !defined(SQL_NOT_DEFERRABLE)
78 # define SQL_NOT_DEFERRABLE 7
85 # define ODBC3_C(odbc3_value,old_value) odbc3_value
89 # define ODBC3_C(odbc3_value,old_value) old_value
101 # define ODBC3_DC(odbc3_value,old_value) \
102 (this->_getDriverInfo()->getMajorVersion()>=3?odbc3_value:old_value)
106 # define ODBC3_DC(odbc3_value,old_value) old_value
110 #if defined(ODBCXX_HAVE_INTTYPES_H)
111 # include <inttypes.h>
123 typedef __int64 Long;
125 #define DATASTATUS_TYPE SQLLEN
128 #elif defined(ODBCXX_HAVE_INTTYPES_H)
130 typedef int64_t Long;
131 #define DATASTATUS_TYPE SQLLEN
133 #define DATASTATUS_TYPE SQLINTEGER
134 # if ODBCXX_SIZEOF_INT == 8
138 # elif ODBCXX_SIZEOF_LONG == 8
142 # elif ODBCXX_SIZEOF_LONG_LONG == 8
144 typedef long long Long;
148 # error "Can't find an appropriate at-least-64-bit integer"
157 const int GETDATA_CHUNK_SIZE=4*1024;
159 const int PUTDATA_CHUNK_SIZE=GETDATA_CHUNK_SIZE;
163 const int STRING_TO_STREAM_CHUNK_SIZE=1024;
164 const int STREAM_TO_STRING_CHUNK_SIZE=STRING_TO_STREAM_CHUNK_SIZE;
187 DATE = ODBC3_C(SQL_TYPE_DATE,SQL_DATE),
207 TIME = ODBC3_C(SQL_TYPE_TIME,SQL_TIME),
216 #if defined(ODBCXX_HAVE_SQLUCODE_H)
221 WVARCHAR = SQL_WVARCHAR,
223 WLONGVARCHAR = SQL_WLONGVARCHAR
225 #if (ODBCVER >= 0x0350)
233 #if !defined(ODBCXX_QT)
243 ODBCXX_SIGNED_CHAR_TYPE* buf_;
246 Rep(
const ODBCXX_SIGNED_CHAR_TYPE* b,
size_t l)
247 :len_(l), refCount_(0) {
249 buf_= ODBCXX_OPERATOR_NEW_DEBUG(__FILE__, __LINE__) ODBCXX_SIGNED_CHAR_TYPE[len_];
250 memcpy((
void*)buf_,(
void*)b,len_);
264 :rep_(ODBCXX_OPERATOR_NEW_DEBUG(__FILE__, __LINE__) Rep(NULL,0)) {
269 Bytes(
const ODBCXX_SIGNED_CHAR_TYPE* data,
size_t dataLen)
270 :rep_(ODBCXX_OPERATOR_NEW_DEBUG(__FILE__, __LINE__) Rep(data,dataLen)) {
282 if(--rep_->refCount_==0) {
283 ODBCXX_OPERATOR_DELETE_DEBUG(__FILE__, __LINE__) rep_;
294 for(
size_t i=0;i<getSize();i++) {
295 if(*(getData()+i)!=*(b.
getData()+i))
303 if(--rep_->refCount_==0) {
304 ODBCXX_OPERATOR_DELETE_DEBUG(__FILE__, __LINE__) rep_;
309 const ODBCXX_SIGNED_CHAR_TYPE*
getData()
const {
320 #if defined(ODBCXX_HAVE_STRUCT_GUID)
325 class ODBCXX_EXPORT Guid {
327 ODBCXX_SIGNED_CHAR_TYPE data_[16];
332 for(
size_t x = 0; x < 16; ++x ) {
338 Guid(
const ODBCXX_SIGNED_CHAR_TYPE* data,
size_t dataLen) {
344 for (
size_t x = 0; x < dataLen; ++x) {
351 Guid(
const Guid& b) {
352 for (
int x = 0; x < 16; ++x) {
353 data_[x] = b.data_[x];
358 bool operator==(
const Guid& b)
const {
361 for (
size_t x=0; x < 16; ++x) {
363 if(data_[x] != b.data_[x])
375 const ODBCXX_SIGNED_CHAR_TYPE* getData()
const {
376 return (ODBCXX_SIGNED_CHAR_TYPE *)data_;
380 size_t getSize()
const {
385 Bytes getBytes()
const {
386 return Bytes(getData(), getSize());
392 const _GUID toStruct()
const {
396 structGuid.Data1 = ((
unsigned char)data_[3] << 24)
397 | ((
unsigned char)data_[2] << 16)
398 | ((
unsigned char)data_[1] << 8)
399 | (
unsigned char)data_[0];
400 structGuid.Data2 = (data_[5] << 8) | (
unsigned char)data_[4];
401 structGuid.Data3 = (data_[7] << 8) | (
unsigned char)data_[6];
402 structGuid.Data4[0] = data_[8];
403 structGuid.Data4[1] = data_[9];
404 structGuid.Data4[2] = data_[10];
405 structGuid.Data4[3] = data_[11];
406 structGuid.Data4[4] = data_[12];
407 structGuid.Data4[5] = data_[13];
408 structGuid.Data4[6] = data_[14];
409 structGuid.Data4[7] = data_[15];
413 const ODBCXX_STRING CharToHexStr(ODBCXX_SIGNED_CHAR_TYPE item)
const {
418 ODBCXX_SSTREAM stream;
419 stream << std::hex << 0 << 0;
420 stream << static_cast<int>(item);
421 ODBCXX_STRING result = stream.str();
422 return result.substr(result.size() - 2, 2);
425 const ODBCXX_STRING toString()
const {
428 ODBCXX_SSTREAM stream;
430 << ODBCXX_STRING_CONST(
"{")
431 << CharToHexStr(data_[3])
432 << CharToHexStr(data_[2])
433 << CharToHexStr(data_[1])
434 << CharToHexStr(data_[0])
435 << ODBCXX_STRING_CONST(
"-")
436 << CharToHexStr(data_[5])
437 << CharToHexStr(data_[4])
438 << ODBCXX_STRING_CONST(
"-")
439 << CharToHexStr(data_[7])
440 << CharToHexStr(data_[6])
441 << ODBCXX_STRING_CONST(
"-")
442 << CharToHexStr(data_[8])
443 << CharToHexStr(data_[9])
444 << CharToHexStr(data_[10])
445 << CharToHexStr(data_[11])
446 << CharToHexStr(data_[12])
447 << CharToHexStr(data_[13])
448 << CharToHexStr(data_[14])
449 << CharToHexStr(data_[15])
450 << ODBCXX_STRING_CONST(
"}");
463 virtual void _invalid(
const ODBCXX_CHAR_TYPE* what,
int value);
465 int _validateYear(
int y) {
469 int _validateMonth(
int m) {
471 this->_invalid(ODBCXX_STRING_CONST(
"month"),m);
476 int _validateDay(
int d) {
478 this->_invalid(ODBCXX_STRING_CONST(
"day"),d);
486 Date(
int year,
int month,
int day) {
488 this->setMonth(month);
510 Date(
const ODBCXX_STRING& str) {
532 virtual void setTime(std::time_t t);
535 std::time_t getTime()
const;
538 void parse(
const ODBCXX_STRING& str);
557 year_=this->_validateYear(year);
562 month_=this->_validateMonth(month);
567 day_=this->_validateDay(day);
571 virtual ODBCXX_STRING toString()
const;
581 virtual void _invalid(
const ODBCXX_CHAR_TYPE* what,
int value);
583 int _validateHour(
int h) {
585 this->_invalid(ODBCXX_STRING_CONST(
"hour"),h);
590 int _validateMinute(
int m) {
592 this->_invalid(ODBCXX_STRING_CONST(
"minute"),m);
597 int _validateSecond(
int s) {
599 this->_invalid(ODBCXX_STRING_CONST(
"second"),s);
606 Time(
int hour,
int minute,
int second) {
608 this->setMinute(minute);
609 this->setSecond(second);
630 Time(
const ODBCXX_STRING& str) {
638 second_(t.second_) {}
652 virtual void setTime(std::time_t t);
655 std::time_t getTime()
const;
658 void parse(
const ODBCXX_STRING& str);
677 hour_=this->_validateHour(h);
682 minute_=this->_validateMinute(m);
687 second_=this->_validateSecond(s);
690 virtual ODBCXX_STRING toString()
const;
700 virtual void _invalid(
const ODBCXX_CHAR_TYPE* what,
int value);
702 int _validateNanos(
int n) {
704 this->_invalid(ODBCXX_STRING_CONST(
"nanoseconds"),n);
712 int hour,
int minute,
int second,
714 :
Date(year,month,day),
Time(hour,minute,second) {
715 this->setNanos(nanos);
743 :
Date(t),
Time(t),nanos_(t.nanos_) {}
757 virtual void setTime(std::time_t t);
766 void parse(
const ODBCXX_STRING& s);
775 nanos_=this->_validateNanos(nanos);
778 virtual ODBCXX_STRING toString()
const;
786 template <
class T>
class CleanVector :
public std::vector<T> {
788 CleanVector(
const CleanVector<T>&);
789 CleanVector<T>& operator=(
const CleanVector<T>&);
792 explicit CleanVector() {}
793 virtual ~CleanVector() {
794 typename std::vector<T>::iterator i=this->begin();
795 typename std::vector<T>::iterator end=this->end();
797 ODBCXX_OPERATOR_DELETE_DEBUG(__FILE__, __LINE__) *i;
811 ODBCXX_CHAR_TYPE state_[SQL_SQLSTATE_SIZE+1];
812 ODBCXX_CHAR_TYPE description_[SQL_MAX_MESSAGE_LENGTH];
813 SQLINTEGER nativeCode_;
829 const ODBCXX_CHAR_TYPE* getSQLState()
const {
833 const ODBCXX_CHAR_TYPE* getDescription()
const {
837 int getNativeCode()
const {
847 ODBCXX_STRING reason_;
848 ODBCXX_STRING sqlState_;
850 #if defined(ODBCXX_UNICODE)
851 std::string reason8_;
852 #elif defined(ODBCXX_QT)
858 const ODBCXX_STRING& sqlState =ODBCXX_STRING_CONST(
""),
862 errorCode_(vendorCode)
863 #if defined(ODBCXX_UNICODE)
865 const size_t length =
sizeof(wchar_t)*reason_.size();
866 char* temp =ODBCXX_OPERATOR_NEW_DEBUG(__FILE__, __LINE__)
char[length+1];
867 wcstombs(temp,reason_.c_str(),length);
872 # if defined(ODBCXX_QT)
873 ,reason8_(reason.local8Bit())
880 :reason_(dm.getDescription()),
882 errorCode_(dm.getNativeCode()) {}
907 virtual const char*
what()
const throw() {
910 #if defined(ODBCXX_QT)
911 return reason8_.data();
913 # if defined(ODBCXX_UNICODE)
914 return reason8_.c_str();
916 return reason_.c_str();
938 SQLWarning(
const ODBCXX_STRING& reason = ODBCXX_STRING_CONST(
""),
939 const ODBCXX_STRING& sqlState = ODBCXX_STRING_CONST(
""),
951 typedef CleanVector<SQLWarning*> WarningList;
954 template <
class T>
class Deleter {
959 Deleter(
const Deleter<T>&);
960 Deleter<T>& operator=(
const Deleter<T>&);
963 explicit Deleter(T* ptr,
bool isArray =
false)
964 :ptr_(ptr), isArray_(isArray) {}
967 ODBCXX_OPERATOR_DELETE_DEBUG(__FILE__, __LINE__) ptr_;
977 #endif // __ODBCXX_TYPES_H
An SQL TINYINT.
Definition: types.h:211
virtual ~Time()
Destructor.
Definition: types.h:649
SQLWarning(const DriverMessage &dm)
Copy from a DriverMessage.
Definition: types.h:944
SQLException(const std::string &reason=ODBCXX_STRING_CONST(""), const std::string &sqlState=ODBCXX_STRING_CONST(""), int vendorCode=0)
Constructor.
Definition: types.h:857
An SQL TIMESTAMP.
Definition: types.h:209
Date(const std::string &str)
Constructor.
Definition: types.h:510
Bytes()
Default constructor.
Definition: types.h:263
Represents an SQL warning.
Definition: types.h:931
int getHour() const
Gets the hour of this time.
Definition: types.h:661
int getSecond() const
Gets the second of this time.
Definition: types.h:671
bool operator==(const Bytes &b) const
Comparison.
Definition: types.h:291
virtual ~SQLException()
Destructor.
Definition: types.h:885
Date(const Date &d)
Copy constructor.
Definition: types.h:515
An SQL BIT.
Definition: types.h:183
SQLException(const DriverMessage &dm)
Copy from a DriverMessage.
Definition: types.h:879
virtual ~SQLWarning()
Destructor.
Definition: types.h:948
const std::string & getMessage() const
Gets the description of this message.
Definition: types.h:901
Time & operator=(const Time &t)
Assignment operator.
Definition: types.h:641
An SQL NUMERIC (precision,scale)
Definition: types.h:201
void setSecond(int s)
Sets the second of this time.
Definition: types.h:686
An SQL LONGVARCHAR (variable length, huge)
Definition: types.h:199
Date & operator=(const Date &d)
Assignment operator.
Definition: types.h:521
Timestamp(int year, int month, int day, int hour, int minute, int second, int nanos=0)
Constructor.
Definition: types.h:711
An SQL SMALLINT.
Definition: types.h:205
Date(int year, int month, int day)
Constructor.
Definition: types.h:486
An SQL VARBINARY (variable length less than 256)
Definition: types.h:213
An SQL DOUBLE.
Definition: types.h:191
An SQL DATE.
Definition: types.h:457
std::time_t getTime() const
Returns the time_t value of 00:00:00 at this date.
An SQL BIGINT.
Definition: types.h:179
static const ODBCXX_CHAR_TYPE * scDEFSQLSTATE
Default SQLSTATE for Exceptions.
Definition: types.h:921
Timestamp(std::time_t t)
Constructor.
Definition: types.h:728
An SQL DATE.
Definition: types.h:187
int getDay() const
Gets the monthday of this date.
Definition: types.h:551
An SQL FLOAT.
Definition: types.h:193
Bytes(const Bytes &b)
Copy constructor.
Definition: types.h:275
virtual ~Date()
Destructor.
Definition: types.h:529
~Bytes()
Destructor.
Definition: types.h:302
An SQL TIME.
Definition: types.h:575
const ODBCXX_SIGNED_CHAR_TYPE * getData() const
Returns a pointer to the data.
Definition: types.h:309
static const std::string ssDEFSQLSTATE
Default SQLSTATE for Exceptions.
Definition: types.h:923
An SQL REAL.
Definition: types.h:203
An SQL TIMESTAMP.
Definition: types.h:696
SQLType
Type constants.
Definition: types.h:175
Time(int hour, int minute, int second)
Constructor.
Definition: types.h:606
An SQL INTEGER.
Definition: types.h:195
void setMinute(int m)
Sets the minute of this time.
Definition: types.h:681
An SQL BINARY (fixed length)
Definition: types.h:181
virtual const char * what() const
Gets the description of this message.
Definition: types.h:907
An SQL LONGVARBINARY (variable length, huge)
Definition: types.h:197
void setYear(int year)
Sets the year of this date.
Definition: types.h:556
int getNanos() const
Gets the nanoseconds value of this timestamp.
Definition: types.h:769
int getMonth() const
Gets the month of this date.
Definition: types.h:546
Bytes(const ODBCXX_SIGNED_CHAR_TYPE *data, size_t dataLen)
Constructor.
Definition: types.h:269
void setHour(int h)
Sets the hour of this time.
Definition: types.h:676
Time(const std::string &str)
Constructor.
Definition: types.h:630
Date(std::time_t t)
Constructor.
Definition: types.h:502
std::time_t getTime() const
Returns the time_t value of 1970-01-01 at this time.
void setMonth(int month)
Sets the month of this date.
Definition: types.h:561
Timestamp(const Timestamp &t)
Copy constructor.
Definition: types.h:742
Time(const Time &t)
Copy constructor.
Definition: types.h:635
A chunk of bytes.
Definition: types.h:240
SQL type constants.
Definition: types.h:172
const std::string & getSQLState() const
Gets the SQLSTATE of this exception.
Definition: types.h:896
int getYear() const
Gets the year of this date.
Definition: types.h:541
Time(std::time_t t)
Constructor.
Definition: types.h:622
Base class for everything that might contain warnings.
Definition: errorhandler.h:32
The exception thrown when errors occur inside the library.
Definition: types.h:845
int getErrorCode() const
Get the vendor error code of this exception.
Definition: types.h:888
An SQL VARCHAR (variable length less than 256)
Definition: types.h:215
virtual std::time_t getTime() const
Gets the time_t value of this timestamp.
Definition: types.h:760
An SQL DECIMAL (precision,scale)
Definition: types.h:189
Invalid SQL Type.
Definition: types.h:177
An SQL CHAR (fixed length)
Definition: types.h:185
SQLWarning(const std::string &reason=ODBCXX_STRING_CONST(""), const std::string &sqlState=ODBCXX_STRING_CONST(""), int vendorCode=0)
Constructor.
Definition: types.h:938
virtual ~Timestamp()
Destructor.
Definition: types.h:754
An SQL TIME.
Definition: types.h:207
void setNanos(int nanos)
Sets the nanoseconds value of this timestamp.
Definition: types.h:774
Timestamp(const std::string &s)
Constructor.
Definition: types.h:736
size_t getSize() const
Returns the size of the data.
Definition: types.h:314
Used internally - represents the result of an SQLError call.
Definition: types.h:807
Timestamp & operator=(const Timestamp &t)
Assignment operator.
Definition: types.h:746
int getMinute() const
Gets the minute of this time.
Definition: types.h:666
Bytes & operator=(const Bytes &b)
Assignment.
Definition: types.h:281
void setDay(int day)
Sets the day of this date.
Definition: types.h:566