fix for SF 1871946

This commit is contained in:
Aleksandar Fabijanic
2008-01-16 04:00:40 +00:00
parent b6edad3450
commit 4f5b88bc3d
5 changed files with 36 additions and 2 deletions

View File

@@ -69,6 +69,7 @@ POCO_DECLARE_EXCEPTION(SQLite_API, SchemaDiffersException, SQLiteException)
POCO_DECLARE_EXCEPTION(SQLite_API, RowTooBigException, SQLiteException)
POCO_DECLARE_EXCEPTION(SQLite_API, ConstraintViolationException, SQLiteException)
POCO_DECLARE_EXCEPTION(SQLite_API, DataTypeMismatchException, SQLiteException)
POCO_DECLARE_EXCEPTION(SQLite_API, ParameterCountMismatchException, SQLiteException)
POCO_DECLARE_EXCEPTION(SQLite_API, InvalidLibraryUseException, SQLiteException)
POCO_DECLARE_EXCEPTION(SQLite_API, OSFeaturesMissingException, SQLiteException)
POCO_DECLARE_EXCEPTION(SQLite_API, AuthorizationDeniedException, SQLiteException)

View File

@@ -63,6 +63,7 @@ POCO_IMPLEMENT_EXCEPTION(SchemaDiffersException, SQLiteException, "The database
POCO_IMPLEMENT_EXCEPTION(RowTooBigException, SQLiteException, "Too much data for one row of a table")
POCO_IMPLEMENT_EXCEPTION(ConstraintViolationException, SQLiteException, "Abort due to constraint violation")
POCO_IMPLEMENT_EXCEPTION(DataTypeMismatchException, SQLiteException, "Data type mismatch")
POCO_IMPLEMENT_EXCEPTION(ParameterCountMismatchException, SQLiteException, "Parameter count mismatch")
POCO_IMPLEMENT_EXCEPTION(InvalidLibraryUseException, SQLiteException, "Library used incorrectly")
POCO_IMPLEMENT_EXCEPTION(OSFeaturesMissingException, SQLiteException, "Uses OS features not supported on host")
POCO_IMPLEMENT_EXCEPTION(AuthorizationDeniedException, SQLiteException, "Authorization denied")

View File

@@ -79,7 +79,7 @@ void SQLiteStatementImpl::compileImpl()
while (rc == SQLITE_OK && !pStmt && !queryFound)
{
rc = sqlite3_prepare(_pDB, pSql, -1, &pStmt, &pLeftover);
rc = sqlite3_prepare_v2(_pDB, pSql, -1, &pStmt, &pLeftover);
if (rc != SQLITE_OK)
{
if (pStmt)
@@ -143,7 +143,12 @@ void SQLiteStatementImpl::bindImpl()
// bind
Bindings& binds = bindings();
if (binds.empty()) return;
int pc = sqlite3_bind_parameter_count(_pStmt);
if (binds.empty() && 0 == pc) return;
else if (binds.empty() && pc > 0)
throw ParameterCountMismatchException();
else if (!binds.empty() && binds.size() * (*binds.begin())->numOfColumnsHandled() != pc)
throw ParameterCountMismatchException();
std::size_t pos = 1; // sqlite starts with 1 not 0!

View File

@@ -44,6 +44,7 @@
#include <iostream>
#include "Poco/File.h"
#include "Poco/Stopwatch.h"
#include "Poco/Data/SQLite/SQLiteException.h"
using namespace Poco::Data;
@@ -53,6 +54,7 @@ using Poco::AnyCast;
using Poco::InvalidAccessException;
using Poco::RangeException;
using Poco::BadCastException;
using Poco::Data::SQLite::ParameterCountMismatchException;
struct Person
@@ -1577,6 +1579,29 @@ void SQLiteTest::testInternalExtraction()
}
void SQLiteTest::testBindingCount()
{
Session tmp (SQLite::Connector::KEY, "dummy.db");
tmp << "DROP TABLE IF EXISTS Ints", now;
tmp << "CREATE TABLE Ints (int0 INTEGER)", now;
int i = 42;
try { tmp << "INSERT INTO Ints VALUES (?)", now; }
catch (ParameterCountMismatchException&) { }
try { tmp << "INSERT INTO Ints VALUES (?)", use(i), use(i), now; }
catch (ParameterCountMismatchException&) { }
tmp << "INSERT INTO Ints VALUES (?)", use(i), now;
int j = 0;
try { tmp << "SELECT int0 from Ints where int0 = ?", into(i), now; }
catch (ParameterCountMismatchException&) { }
tmp << "SELECT int0 from Ints where int0 = ?", use(i), into(j), now;
assert (42 == j);
}
void SQLiteTest::setUp()
{
}
@@ -1648,6 +1673,7 @@ CppUnit::Test* SQLiteTest::suite()
CppUnit_addTest(pSuite, SQLiteTest, testTuple1);
CppUnit_addTest(pSuite, SQLiteTest, testTupleVector1);
CppUnit_addTest(pSuite, SQLiteTest, testInternalExtraction);
CppUnit_addTest(pSuite, SQLiteTest, testBindingCount);
return pSuite;
}

View File

@@ -109,6 +109,7 @@ public:
void testTupleVector10();
void testInternalExtraction();
void testBindingCount();
void setUp();
void tearDown();