12#if __DCL_HAVE_ALLOC_DEBUG
13#undef __DCL_ALLOC_LEVEL
14#define __DCL_ALLOC_LEVEL __DCL_ALLOC_INTERNAL
35#define __SQLERROR_MSG(code, msg) {code, L"(" __T(#code) L")" __T(msg) }
37#define __SQLERROR_MSG(code, msg) {code, __T(msg) }
87 const wchar_t* psz = L
"Unknown error code";
89 if (_errorCode == errors[i].error) {
90 psz = errors[i].message;
95 size_t len = wcslen(psz);
96 if (*_buflen >=
len) {
97 wcsncpy(_buf, psz,
len);
106#define DATA_TYPE_NAME(type) case type : return __T(#type)
142#define __CHECK_ADDRESS(p) \
145 __SET_ERROR(eBadAddress); \
153#define __SET_ERROR(_errorCode) \
154 __queryHandle->connection()->setErrorStatus(_errorCode, __THIS_FILE__, __LINE__)
172bool SQL::Field::getDataSize(
198 return __getDataSize(_pn, _maxSize);
201static bool __checkDataType__(
206 switch (_bufferType) {
211 if (_bufferType == _dataType)
273bool SQL::Field::getData(
294 !__checkDataType__(_dataType, __dataType)) {
312 return __getData(_pv, _pn, _dataType);
319 ) : Field(_queryHandle)
327void SQL::Param::setName(
334bool SQL::Param::setData(
352 if (!__checkDataType__(_dataType, _assignType)) {
364 (-9999 <= p->
year && p->
year <= 9999)
366 && (1 <= p->
day && p->
day <= 31)
377 && (p->frac <= 999999999)
381 || (-720 <= p->tzoff && p->tzoff < 840)
389 (-9999 <= p->year && p->year <= 9999)
390 && (1 <= p->month && p->month <= 12)
391 && (1 <= p->day && p->day <= 31)
395 && (p->frac <= 999999999)
399 || (-720 <= p->tzoff && p->tzoff < 840)
408 (-999999999 <= p->years && p->years <= 999999999)
409 && (-11 <= p->months && p->months <= 11)
410 && (-999999999 <= p->
days && p->
days <= 999999999)
414 && (p->fracs <= 999999999)
426 return __setData(_pv, _n, _dataType, _assignType);
429bool SQL::Param::setDataType(
451 return __setDataType(_dataType);
491#define __SET_ERROR(_errorCode) \
492 __connHandle->setErrorStatus(_errorCode, __THIS_FILE__, __LINE__)
500 __connHandle = _connHandle;
506 __placeholder = L
'?';
508 __states = stStandBy;
510 __connHandle->addRef();
518bool SQL::Query::prepare(
524 __states = stStandBy;
528 if (__prepare(_sql, _sqllen, _paramCount)) {
535bool SQL::Query::execute()
537 if (!inState(stPrepared)) {
549bool SQL::Query::fetch()
551 if(!inState(stExecuted)) {
569bool SQL::Query::nextResult()
571 if (!inState(stExecuted)) {
575 return __nextResult();
578bool SQL::Query::getField(
580 SQL::Field** _fieldHandleOut
583 if (!inState(stExecuted)) {
588 if (_index >= __fieldCount) {
594 return __getField(_index, _fieldHandleOut);
597bool SQL::Query::getParam(
599 SQL::Param** _paramHandleOut
602 if (!inState(stPrepared)) {
607 if (_index >= __paramCount) {
613 return __getParam(_index, _paramHandleOut);
618#define __SET_ERROR(_errorCode) \
619 setErrorStatus(_errorCode, __THIS_FILE__, __LINE__)
621void SQL::Connection::setErrorStatus(
623 const wchar_t* _filename,
627 __errorCode = _errorCode;
628 __errorFileName = _filename;
647 const wchar_t* _serverTitle
668 const char* _connString,
679 if (
__open(_connString, _connlen)) {
782 if ((_buf ==
NULL) || (_buflen ==
NULL) || (*_buflen <= 0))
844 const char* _pszConnectionString,
846 ListedByteStringToByteStringMap& _map
850 ByteStringArray elts;
852 _pszConnectionString, _pszConnectionString + _n,
856 for(ByteStringArray::Iterator it = elts.begin();
857 it != elts.end(); it++) {
858 ByteStringArray pair;
859 (*it).split(
'=', pair);
860 if (pair.size() > 0) {
861 ByteStringArray::Iterator itPair = pair.begin();
862 ByteString name = *itPair++;
864 if (pair.size() > 1) {
867 _map[name.trim().toUpperCase()] = value.trim();
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)
void CharsetConvertException *size_t n
virtual bool __createQueryInstance(Query **_queryHandleOut)=0
virtual bool __getErrorMessage(char *_buf, size_t *_buflen)=0
virtual bool __getServerInfo(char *_buf, size_t *_buflen)=0
virtual bool __startTrans()=0
virtual bool __execute(const char *_sql, size_t _sqllen)=0
const wchar_t * __serverTitle
bool execute(const char *_sql, size_t _sqllen)
bool open(const char *_connString, size_t _connlen)
bool getErrorMessage(char *_pbuf, size_t *_pn)
bool getServerInfo(char *_pbuf, size_t *_pn)
Connection(const wchar_t *_serverTitle)
bool inState(unsigned int uState) const
bool destroyQueryInstance(Query *_queryHandle)
virtual bool __commitTrans()=0
bool createQueryInstance(Query **_queryHandleOut)
static size_t splitConnectionString(const char *_connString, size_t _strlen, ListedByteStringToByteStringMap &_map)
virtual bool __rollbackTrans()=0
const wchar_t * __errorFileName
Field(Query *_queryHandle)
virtual bool __getData(void *_pv, size_t *_pn, DataType _dataType)
virtual bool __getDataSize(size_t *_pn, bool _maxSize)
Param(Query *_queryHandle)
virtual bool isNull() const
virtual bool __setDataType(DataType _dataType)
Connection * __connHandle
virtual void __destroy()=0
Query(Connection *_connHandle)
virtual bool __nextResult()
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)