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)
139#define __CHECK_ADDRESS(p) \
142 __SET_ERROR(eBadAddress); \
150#define __SET_ERROR(_errorCode) \
151 __queryHandle->connection()->setErrorStatus(_errorCode, __THIS_FILE__, __LINE__)
167bool SQL::Field::getDataSize(
195 return __getDataSize(_pn, _maxSize);
198static bool __CheckAccessType(
214 if (_accessType == _dataType)
244bool SQL::Field::getData(
281 if (!__CheckAccessType(__dataType, _dataType)) {
286 return __getData(_pv, _pn, _dataType);
292 : Field(_queryHandle)
301void SQL::Param::setName(String _name)
306bool SQL::Param::setData(
322 (-9999 <= p->nYear && p->nYear <= 9999)
323 && (1 <= p->nMonth && p->nMonth <= 12)
324 && (1 <= p->nDay && p->nDay <= 31)
334 && (p->nFrac <= 999999999)
342 (-9999 <= p->nYear && p->nYear <= 9999)
343 && (1 <= p->nMonth && p->nMonth <= 12)
344 && (1 <= p->nDay && p->nDay <= 31)
348 && (p->nFrac <= 999999999)
349 && (-720 <= p->nTzMin && p->nTzMin < 840)
357 (-999999999 <= p->nYears && p->nYears <= 999999999)
358 && (-11 <= p->nMonths && p->nMonths <= 11)
359 && (-999999999 <= p->nDays && p->nDays <= 999999999)
363 && (p->nFracs <= 999999999)
370 if (_dataType != _assignType) {
394 switch(_assignType) {
409 switch(_assignType) {
449 return __setData(_pv, _n, _dataType, _assignType);
453bool SQL::Param::setDataType(
472 return __setDataType(_dataType);
512#define __SET_ERROR(_errorCode) \
513 __connHandle->setErrorStatus(_errorCode, __THIS_FILE__, __LINE__)
519 __connHandle = _connHandle;
525 __placeholder = L
'?';
527 __states = stStandBy;
529 __connHandle->addRef();
537bool SQL::Query::prepare(
const char* _sql,
size_t _sqllen,
540 __states = stStandBy;
544 if (__prepare(_sql, _sqllen, _paramCount)) {
551bool SQL::Query::execute()
553 if (!inState(stPrepared)) {
565bool SQL::Query::fetch()
567 if(!inState(stExecuted)) {
585bool SQL::Query::nextResult()
587 if (!inState(stExecuted)) {
591 return __nextResult();
594bool SQL::Query::getField(
size_t _index, SQL::Field** _fieldHandleOut)
596 if (!inState(stExecuted)) {
601 if (_index >= __fieldCount) {
607 return __getField(_index, _fieldHandleOut);
610bool SQL::Query::getParam(
size_t _index, SQL::Param** _paramHandleOut)
612 if (!inState(stPrepared)) {
617 if (_index >= __paramCount) {
623 return __getParam(_index, _paramHandleOut);
628#define __SET_ERROR(_errorCode) \
629 setErrorStatus(_errorCode, __THIS_FILE__, __LINE__)
631void SQL::Connection::setErrorStatus(
632 SQL::Error _errorCode,
const wchar_t* _filename,
int _line)
634 __errorCode = _errorCode;
635 __errorFileName = _filename;
681 if (
__open(_connString, _connlen)) {
778 if ((_buf ==
NULL) || (_buflen ==
NULL) || (*_buflen <= 0))
833 const char* _pszConnectionString,
size_t _n,
834 ListedByteStringToByteStringMap& _map
838 ByteStringArray elts;
840 _pszConnectionString, _pszConnectionString + _n,
844 for(ByteStringArray::Iterator it = elts.begin(); it != elts.end(); it++) {
845 ByteStringArray pair;
846 (*it).split(
'=', pair);
847 if (pair.size() > 0) {
848 ByteStringArray::Iterator itPair = pair.begin();
849 ByteString name = *itPair++;
851 if (pair.size() > 1) {
854 _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)