ODBC string truncation bug fix

This commit is contained in:
Aleksandar Fabijanic 2008-02-02 21:45:21 +00:00
parent 533f42bfce
commit 9dde6fb1ef
4 changed files with 28 additions and 2 deletions

View File

@ -154,11 +154,16 @@ std::size_t Preparation::maxDataSize(std::size_t pos) const
try
{
sz = ODBCMetaColumn(_rStmt, pos).length();
ODBCMetaColumn mc(_rStmt, pos);
sz = mc.length();
// accomodate for terminating zero (non-bulk only!)
if (!isBulk() && ODBCMetaColumn::FDT_STRING == mc.type()) ++sz;
}
catch (StatementException&) { }
if (!sz || sz > maxsz) sz = maxsz;
return sz;
}

View File

@ -331,8 +331,15 @@ public:
/// Returns the length of prepared data. Defaults to 1.
/// The length is greater than one for bulk operations.
void setBulk(bool bulkPrep = true);
/// Sets bulk operation flag (always false at object creation time)
bool isBulk() const;
/// Returns bulk operation flag.
private:
Poco::UInt32 _length;
bool _bulk;
};
@ -351,6 +358,17 @@ inline Poco::UInt32 AbstractPreparation::getLength() const
}
inline void AbstractPreparation::setBulk(bool bulkPrep)
{
_bulk = bulkPrep;
}
inline bool AbstractPreparation::isBulk() const
{
return _bulk;
}
} } // namespace Poco::Data

View File

@ -43,6 +43,7 @@
#include "Poco/Data/Data.h"
#include "Poco/Data/AbstractExtraction.h"
#include "Poco/Data/Bulk.h"
#include "Poco/Data/Prepare.h"
#include <vector>
@ -130,6 +131,7 @@ public:
Poco::UInt32 limit = getLimit();
if (limit != _rResult.size()) _rResult.resize(limit);
pPrep->setLength(limit);
pPrep->setBulk(true);
return new Prepare<C>(pPrep, col, _rResult);
}

View File

@ -42,7 +42,8 @@ namespace Data {
AbstractPreparation::AbstractPreparation(Poco::UInt32 length):
_length(length)
_length(length),
_bulk(false)
{
}