Convert code to zero-based

This commit is contained in:
Aleksandar Fabijanic 2007-05-23 01:07:39 +00:00
parent 418bb651c1
commit 55b22cc271
8 changed files with 30 additions and 34 deletions

View File

@ -166,7 +166,7 @@ private:
} }
if (Utility::isError(SQLBindParameter(_rStmt, if (Utility::isError(SQLBindParameter(_rStmt,
(SQLUSMALLINT) pos, (SQLUSMALLINT) pos + 1,
SQL_PARAM_INPUT, SQL_PARAM_INPUT,
cDataType, cDataType,
sqlDataType, sqlDataType,

View File

@ -153,7 +153,7 @@ private:
T value = (T) 0; T value = (T) 0;
rc = SQLGetData(_rStmt, rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos, (SQLUSMALLINT) pos + 1,
cType, //C data type cType, //C data type
&value, //returned value &value, //returned value
0, //buffer length (ignored) 0, //buffer length (ignored)

View File

@ -179,24 +179,24 @@ private:
void preparePOD(std::size_t pos, SQLSMALLINT valueType) void preparePOD(std::size_t pos, SQLSMALLINT valueType)
{ {
poco_assert (DE_BOUND == _dataExtraction); poco_assert (DE_BOUND == _dataExtraction);
poco_assert (pos > 0 && pos <= _pValues.size()); poco_assert (pos >= 0 && pos < _pValues.size());
std::size_t dataSize = sizeof(T); std::size_t dataSize = sizeof(T);
_pValues[pos-1] = new Poco::Any(T()); _pValues[pos] = new Poco::Any(T());
_pLengths[pos-1] = new SQLLEN; _pLengths[pos] = new SQLLEN;
*_pLengths[pos-1] = 0; *_pLengths[pos] = 0;
T* pVal = AnyCast<T>(_pValues[pos-1]); T* pVal = AnyCast<T>(_pValues[pos]);
poco_assert_dbg (pVal); poco_assert_dbg (pVal);
if (Utility::isError(SQLBindCol(_rStmt, if (Utility::isError(SQLBindCol(_rStmt,
(SQLUSMALLINT) pos, (SQLUSMALLINT) pos + 1,
valueType, valueType,
(SQLPOINTER) pVal, (SQLPOINTER) pVal,
(SQLINTEGER) dataSize, (SQLINTEGER) dataSize,
_pLengths[pos-1]))) _pLengths[pos])))
{ {
throw StatementException(_rStmt, "SQLBindCol()"); throw StatementException(_rStmt, "SQLBindCol()");
} }
@ -307,14 +307,14 @@ inline std::size_t Preparation::columns() const
inline std::size_t Preparation::maxDataSize(std::size_t pos) const inline std::size_t Preparation::maxDataSize(std::size_t pos) const
{ {
poco_assert (pos > 0 && pos <= _pValues.size()); poco_assert (pos >= 0 && pos < _pValues.size());
std::size_t sz = 0; std::size_t sz = 0;
std::size_t maxsz = getMaxFieldSize(); std::size_t maxsz = getMaxFieldSize();
try try
{ {
sz = ODBCColumn(_rStmt, pos-1).length(); sz = ODBCColumn(_rStmt, pos).length();
} }
catch (StatementException&) catch (StatementException&)
{ {
@ -326,10 +326,10 @@ inline std::size_t Preparation::maxDataSize(std::size_t pos) const
inline std::size_t Preparation::actualDataSize(std::size_t pos) const inline std::size_t Preparation::actualDataSize(std::size_t pos) const
{ {
poco_assert (pos > 0 && pos <= _pValues.size()); poco_assert (pos >= 0 && pos < _pValues.size());
poco_assert (_pLengths[pos-1]); poco_assert (_pLengths[pos]);
return *_pLengths[pos-1]; return *_pLengths[pos];
} }

View File

@ -75,7 +75,7 @@ void Binder::bind(std::size_t pos, const std::string& val)
_dataSize.insert(SizeMap::value_type((SQLPOINTER) val.c_str(), size)); _dataSize.insert(SizeMap::value_type((SQLPOINTER) val.c_str(), size));
if (Utility::isError(SQLBindParameter(_rStmt, if (Utility::isError(SQLBindParameter(_rStmt,
(SQLUSMALLINT) pos, (SQLUSMALLINT) pos + 1,
SQL_PARAM_INPUT, SQL_PARAM_INPUT,
SQL_C_CHAR, SQL_C_CHAR,
SQL_LONGVARCHAR, SQL_LONGVARCHAR,
@ -104,7 +104,7 @@ void Binder::bind(std::size_t pos, const Poco::Data::BLOB& val)
_dataSize.insert(SizeMap::value_type((SQLPOINTER) val.rawContent(), size)); _dataSize.insert(SizeMap::value_type((SQLPOINTER) val.rawContent(), size));
if (Utility::isError(SQLBindParameter(_rStmt, if (Utility::isError(SQLBindParameter(_rStmt,
(SQLUSMALLINT) pos, (SQLUSMALLINT) pos + 1,
SQL_PARAM_INPUT, SQL_PARAM_INPUT,
SQL_C_BINARY, SQL_C_BINARY,
SQL_LONGVARBINARY, SQL_LONGVARBINARY,

View File

@ -110,7 +110,7 @@ bool Extractor::extractManualImpl<std::string>(std::size_t pos, std::string& val
memset(pChar, 0, CHUNK_SIZE); memset(pChar, 0, CHUNK_SIZE);
len = 0; len = 0;
rc = SQLGetData(_rStmt, rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos, (SQLUSMALLINT) pos + 1,
cType, //C data type cType, //C data type
pChar, //returned value pChar, //returned value
CHUNK_SIZE, //buffer length CHUNK_SIZE, //buffer length
@ -158,7 +158,7 @@ bool Extractor::extractManualImpl<Poco::Data::BLOB>(std::size_t pos,
memset(pChar, 0, CHUNK_SIZE); memset(pChar, 0, CHUNK_SIZE);
len = 0; len = 0;
rc = SQLGetData(_rStmt, rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos, (SQLUSMALLINT) pos + 1,
cType, //C data type cType, //C data type
pChar, //returned value pChar, //returned value
CHUNK_SIZE, //buffer length CHUNK_SIZE, //buffer length

View File

@ -120,11 +120,10 @@ void ODBCStatementImpl::compileImpl()
if (Preparation::DE_BOUND == ext && dataAvailable) if (Preparation::DE_BOUND == ext && dataAvailable)
{ {
std::size_t pos = 1;
Extractions& extracts = extractions(); Extractions& extracts = extractions();
Extractions::iterator it = extracts.begin(); Extractions::iterator it = extracts.begin();
Extractions::iterator itEnd = extracts.end(); Extractions::iterator itEnd = extracts.end();
for (; it != itEnd; ++it) for (std::size_t pos = 0; it != itEnd; ++it)
{ {
AbstractPrepare* pAP = (*it)->createPrepareObject(_pPreparation, pos); AbstractPrepare* pAP = (*it)->createPrepareObject(_pPreparation, pos);
pAP->prepare(); pAP->prepare();
@ -150,11 +149,9 @@ void ODBCStatementImpl::bindImpl()
Bindings& binds = bindings(); Bindings& binds = bindings();
if (!binds.empty()) if (!binds.empty())
{ {
std::size_t pos = 1;
Bindings::iterator it = binds.begin(); Bindings::iterator it = binds.begin();
Bindings::iterator itEnd = binds.end(); Bindings::iterator itEnd = binds.end();
for (; it != itEnd && (*it)->canBind(); ++it) for (std::size_t pos = 0; it != itEnd && (*it)->canBind(); ++it)
{ {
(*it)->bind(pos); (*it)->bind(pos);
pos += (*it)->numOfColumnsHandled(); pos += (*it)->numOfColumnsHandled();
@ -245,8 +242,7 @@ void ODBCStatementImpl::next()
Extractions& extracts = extractions(); Extractions& extracts = extractions();
Extractions::iterator it = extracts.begin(); Extractions::iterator it = extracts.begin();
Extractions::iterator itEnd = extracts.end(); Extractions::iterator itEnd = extracts.end();
std::size_t pos = 1; for (std::size_t pos = 0; it != itEnd; ++it)
for (; it != itEnd; ++it)
{ {
(*it)->extract(pos); (*it)->extract(pos);
pos += (*it)->numOfColumnsHandled(); pos += (*it)->numOfColumnsHandled();

View File

@ -61,7 +61,7 @@ Parameter::~Parameter()
void Parameter::init() void Parameter::init()
{ {
if (Utility::isError(SQLDescribeParam(_rStmt, if (Utility::isError(SQLDescribeParam(_rStmt,
(SQLUSMALLINT) _number, (SQLUSMALLINT) _number + 1,
&_dataType, &_dataType,
&_columnSize, &_columnSize,
&_decimalDigits, &_decimalDigits,

View File

@ -81,32 +81,32 @@ Preparation::~Preparation()
Poco::Any& Preparation::operator [] (std::size_t pos) Poco::Any& Preparation::operator [] (std::size_t pos)
{ {
poco_assert (pos > 0 && pos <= _pValues.size()); poco_assert (pos >= 0 && pos < _pValues.size());
return *_pValues[pos-1]; return *_pValues[pos];
} }
void Preparation::prepareRaw(std::size_t pos, SQLSMALLINT valueType, std::size_t size) void Preparation::prepareRaw(std::size_t pos, SQLSMALLINT valueType, std::size_t size)
{ {
poco_assert (DE_BOUND == _dataExtraction); poco_assert (DE_BOUND == _dataExtraction);
poco_assert (pos > 0 && pos <= _pValues.size()); poco_assert (pos >= 0 && pos < _pValues.size());
char* pChr = new char[size]; char* pChr = new char[size];
poco_assert_dbg (pChr); poco_assert_dbg (pChr);
memset(pChr, 0, size); memset(pChr, 0, size);
SharedPtr<char> sp = pChr; SharedPtr<char> sp = pChr;
_pValues[pos-1] = new Any(sp); _pValues[pos] = new Any(sp);
_pLengths[pos-1] = new SQLLEN; _pLengths[pos] = new SQLLEN;
*_pLengths[pos-1] = (SQLLEN) size; *_pLengths[pos] = (SQLLEN) size;
if (Utility::isError(SQLBindCol(_rStmt, if (Utility::isError(SQLBindCol(_rStmt,
(SQLUSMALLINT) pos, (SQLUSMALLINT) pos + 1,
valueType, valueType,
(SQLPOINTER) pChr, (SQLPOINTER) pChr,
(SQLINTEGER) size, (SQLINTEGER) size,
_pLengths[pos-1]))) _pLengths[pos])))
{ {
throw StatementException(_rStmt, "SQLBindCol()"); throw StatementException(_rStmt, "SQLBindCol()");
} }