12#if __DCL_HAVE_ALLOC_DEBUG
13#undef __DCL_ALLOC_LEVEL
14#define __DCL_ALLOC_LEVEL __DCL_ALLOC_INTERNAL
33#define __SQLERROR_MSG(code, msg) {code, L"(" __T(#code) L")" __T(msg) }
35#define __SQLERROR_MSG(code, msg) {code, __T(msg) }
84 const wchar_t* psz = L
"Unknown error code";
86 if (_errorCode == errors[i].error) {
87 psz = errors[i].message;
92 size_t len = wcslen(psz);
93 if (*_buflen >= len) {
94 wcsncpy(_buf, psz, len);
103#define DATA_TYPE_NAME(type) case type : return __T(#type)
139#define __CHECK_ADDRESS(p) \
142 __SET_ERROR(eBadAddress); \
149#define __SET_ERROR(_errorCode) \
150 connection()->setErrorStatus(_errorCode, __THIS_FILE__, __LINE__)
168bool SQL::Field::getNull(
172 unsigned int state =
dynamic_cast<SQL::Param*
>(
this) ?
174 if (!__queryHandle->inState(state)) {
178 return __getDataSize(_size,
false);
181bool SQL::Field::getDataSize(
195 return __getDataSize(_size,
true);
198 unsigned int state =
dynamic_cast<SQL::Param*
>(
this) ?
200 if (!__queryHandle->inState(state)) {
205 bool r = __getDataSize(_size,
false);
206 if (
r && *_size == (
size_t)-1) {
214static bool __checkDataType__(
223 if (_sqlType == _bufType
228 if (_sqlType == _bufType)
290bool SQL::Field::getData(
311 !__checkDataType__(_bufType, __dataType)) {
319 unsigned int state =
dynamic_cast<SQL::Param*
>(
this) ?
321 if (!__queryHandle->inState(state)) {
326 size_t size = (size_t)-1;
327 if (!__getDataSize(&size,
false)) {
331 if (size == (
size_t)-1) {
336 return __getData(_buf, _size, _bufType);
343) : Field(_queryHandle)
351void SQL::Param::setName(
358bool SQL::Param::setData(
378 !__checkDataType__(_valType, _sqlType)) {
390 (-9999 <= p->
year && p->
year <= 9999)
392 && (1 <= p->
day && p->
day <= 31)
402 && (p->frac <= 999999999)
406 || (-720 <= p->tzoff && p->tzoff < 840)
413 (-9999 <= p->year && p->year <= 9999)
414 && (1 <= p->month && p->month <= 12)
415 && (1 <= p->day && p->day <= 31)
419 && (p->frac <= 999999999)
423 || (-720 <= p->tzoff && p->tzoff < 840)
430 (-999999999 <= p->years && p->years <= 999999999)
431 && (-11 <= p->months && p->months <= 11)
432 && (-999999999 <= p->
days && p->
days <= 999999999)
436 && (p->fracs <= 999999999)
451 return __setData(_val, _size, _valType, _sqlType);
454bool SQL::Param::setOutputType(
476 return __setOutputType(_sqlType);
510#define __SET_ERROR(_errorCode) \
511 __connHandle->setErrorStatus(_errorCode, __THIS_FILE__, __LINE__)
519 __connHandle = _connHandle;
525 __placeholder = L
'?';
527 __states = stStandBy;
529 __connHandle->addRef();
537bool SQL::Query::prepare(
543 __states = stStandBy;
547 if (__prepare(_sql, _sqllen, _paramCount)) {
554bool SQL::Query::execute()
556 if (!inState(stPrepared)) {
568bool SQL::Query::fetch()
570 if(!inState(stExecuted)) {
588bool SQL::Query::moreResults(
bool* _moreResults)
590 if (!inState(stExecuted)) {
594 return __moreResults(_moreResults);
597bool SQL::Query::getField(
599 SQL::Field** _fieldHandleOut
602 if (!inState(stExecuted)) {
607 if (_index >= __fieldCount) {
613 return __getField(_index, _fieldHandleOut);
616bool SQL::Query::getParam(
618 SQL::Param** _paramHandleOut
621 if (!inState(stPrepared)) {
626 if (_index >= __paramCount) {
632 return __getParam(_index, _paramHandleOut);
637#define __SET_ERROR(_errorCode) \
638 setErrorStatus(_errorCode, __THIS_FILE__, __LINE__)
640void SQL::Connection::setErrorStatus(
642 const wchar_t* _filename,
646 __errorCode = _errorCode;
647 __errorFileName = _filename;
666 const wchar_t* _serverTitle
687 const char* _connString,
698 if (
__open(_connString, _connlen)) {
801 if ((_buf ==
NULL) || (_buflen ==
NULL) || (*_buflen <= 0))
863 const char* _connstr,
865 ListedByteStringToByteStringMap& _results
869 ByteStringArray elts;
871 _connstr, _connstr + _strlen,
875 for(ByteStringArray::Iterator it = elts.begin();
876 it != elts.end(); it++) {
877 ByteStringArray pair;
878 (*it).split(
'=', pair);
879 if (pair.size() > 0) {
880 ByteStringArray::Iterator itPair = pair.begin();
881 ByteString name = *itPair++;
883 if (pair.size() > 1) {
886 _results[name.trim().toUpperCase()] = value.trim();
889 return _results.size();
DCLCAPI int __open(const String &_path, int _oflags,...)
#define __countof(array, type)
#define __DCL_ASSERT(expr)
#define IMPLEMENT_CLASSINFO(class_name, base_class_name)
__DCL_BEGIN_NAMESPACE struct __SQL_ERROR SQL_ERROR
#define DATA_TYPE_NAME(type)
#define __SQLERROR_MSG(code, msg)
#define __SET_ERROR(_errorCode)
#define __CHECK_ADDRESS(p)
#define __UNSET_STATE(state)
#define __SET_STATE(state)
virtual bool __getErrorMessage(char *_buf, size_t *_buflen)=0
virtual bool __getServerInfo(char *_buf, size_t *_buflen)=0
static size_t splitConnStr(const char *_connstr, size_t _strlen, ListedByteStringToByteStringMap &_results)
virtual bool __startTrans()=0
virtual bool __execute(const char *_sql, size_t _sqllen)=0
const wchar_t * __serverTitle
bool createQueryInstance(Query **_queryHandle)
bool execute(const char *_sql, size_t _sqllen)
Connection(const wchar_t *_serverTitle)
bool destroyQueryInstance(Query *_queryHandle)
bool open(const char *_conn, size_t _connlen)
virtual bool __commitTrans()=0
bool getErrorMessage(char *_buf, size_t *_buflen)
virtual bool __createQueryInstance(Query **_queryHandle)=0
virtual bool __rollbackTrans()=0
bool inState(unsigned int _state) const
const wchar_t * __errorFileName
bool getServerInfo(char *_buf, size_t *_buflen)
Field(Query *_queryHandle)
virtual bool __setOutputType(DataType _sqlType)
Param(Query *_queryHandle)
virtual bool __getData(void *_buf, size_t *_size, DataType _bufType)
virtual bool __getDataSize(size_t *_size, bool _maxsize)
Connection * __connHandle
virtual void __destroy()=0
Query(Connection *_connHandle)
virtual bool __moreResults(bool *_moreResults)
static const wchar_t * dataTypeName(DataType _dataType)
@ eInvalidConnectionString
static bool getErrorMessage(wchar_t *_buf, size_t *_buflen, Error _errorCode)
static long incrementAndGet(volatile long &_n)
static long decrementAndGet(volatile long &_n)