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,
(SQLUSMALLINT) pos,
(SQLUSMALLINT) pos + 1,
SQL_PARAM_INPUT,
cDataType,
sqlDataType,

View File

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

View File

@ -179,24 +179,24 @@ private:
void preparePOD(std::size_t pos, SQLSMALLINT valueType)
{
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);
_pValues[pos-1] = new Poco::Any(T());
_pLengths[pos-1] = new SQLLEN;
*_pLengths[pos-1] = 0;
_pValues[pos] = new Poco::Any(T());
_pLengths[pos] = new SQLLEN;
*_pLengths[pos] = 0;
T* pVal = AnyCast<T>(_pValues[pos-1]);
T* pVal = AnyCast<T>(_pValues[pos]);
poco_assert_dbg (pVal);
if (Utility::isError(SQLBindCol(_rStmt,
(SQLUSMALLINT) pos,
(SQLUSMALLINT) pos + 1,
valueType,
(SQLPOINTER) pVal,
(SQLINTEGER) dataSize,
_pLengths[pos-1])))
_pLengths[pos])))
{
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
{
poco_assert (pos > 0 && pos <= _pValues.size());
poco_assert (pos >= 0 && pos < _pValues.size());
std::size_t sz = 0;
std::size_t maxsz = getMaxFieldSize();
try
{
sz = ODBCColumn(_rStmt, pos-1).length();
sz = ODBCColumn(_rStmt, pos).length();
}
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
{
poco_assert (pos > 0 && pos <= _pValues.size());
poco_assert (_pLengths[pos-1]);
poco_assert (pos >= 0 && pos < _pValues.size());
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));
if (Utility::isError(SQLBindParameter(_rStmt,
(SQLUSMALLINT) pos,
(SQLUSMALLINT) pos + 1,
SQL_PARAM_INPUT,
SQL_C_CHAR,
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));
if (Utility::isError(SQLBindParameter(_rStmt,
(SQLUSMALLINT) pos,
(SQLUSMALLINT) pos + 1,
SQL_PARAM_INPUT,
SQL_C_BINARY,
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);
len = 0;
rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos,
(SQLUSMALLINT) pos + 1,
cType, //C data type
pChar, //returned value
CHUNK_SIZE, //buffer length
@ -158,7 +158,7 @@ bool Extractor::extractManualImpl<Poco::Data::BLOB>(std::size_t pos,
memset(pChar, 0, CHUNK_SIZE);
len = 0;
rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos,
(SQLUSMALLINT) pos + 1,
cType, //C data type
pChar, //returned value
CHUNK_SIZE, //buffer length

View File

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

View File

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

View File

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