Skip to content

Commit

Permalink
fix(Data):
Browse files Browse the repository at this point in the history
* make bool Session::isTransaction() return Poco::Optional
* move parsing to Statement
* SQLParser make build
* other fixes and improvemets #4230
  • Loading branch information
aleks-f committed Nov 27, 2023
1 parent 433f08d commit 08524db
Show file tree
Hide file tree
Showing 45 changed files with 949 additions and 196 deletions.
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"${POCO_BASE}/Redis/include",
"${POCO_BASE}/MongoDB/include",
"${POCO_BASE}/ApacheConnector/include",
"/usr/include"
"${POCO_BASE}/Data/src"
]
},
"configurations": [
Expand Down
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@
"strstream": "cpp",
"future": "cpp",
"shared_mutex": "cpp",
"stop_token": "cpp"
"stop_token": "cpp",
"codecvt": "cpp",
"numbers": "cpp",
"span": "cpp",
"semaphore": "cpp"
},
"files.exclude": {
"**/.dep": true,
Expand Down
14 changes: 11 additions & 3 deletions Data/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ objects = AbstractBinder AbstractBinding AbstractExtraction AbstractExtractor \
SessionPool SessionPoolContainer SQLChannel \
Statement StatementCreator StatementImpl Time Transcoder

target = PocoData
target_version = $(LIBVERSION)
target_libs = PocoFoundation
ifndef POCO_DATA_NO_SQL_PARSER
objects += SQLParser SQLParserResult \
bison_parser flex_lexer \
CreateStatement PrepareStatement SQLStatement \
Expr statements sqlhelper
target_includes = $(POCO_BASE)/Data/src
endif

target = PocoData
target_version = $(LIBVERSION)
target_libs = PocoFoundation

include $(POCO_BASE)/build/rules/lib
4 changes: 4 additions & 0 deletions Data/MySQL/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ objects = Binder Extractor SessionImpl Connector \
MySQLStatementImpl ResultMetadata MySQLException \
SessionHandle StatementExecutor Utility

ifndef POCO_DATA_NO_SQL_PARSER
target_includes = $(POCO_BASE)/Data/src
endif

target = PocoDataMySQL
target_version = $(LIBVERSION)
target_libs = PocoData PocoFoundation
Expand Down
4 changes: 4 additions & 0 deletions Data/MySQL/testsuite/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ SYSLIBS += -lmysqlclient -lz -lpthread -ldl

objects = MySQLTestSuite Driver MySQLTest SQLExecutor

ifndef POCO_DATA_NO_SQL_PARSER
target_includes = $(POCO_BASE)/Data/src
endif

target = testrunner
target_version = 1
target_libs = PocoDataMySQL PocoData PocoFoundation CppUnit
Expand Down
4 changes: 4 additions & 0 deletions Data/ODBC/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ objects = Binder ConnectionHandle Connector EnvironmentHandle \
Extractor ODBCException ODBCMetaColumn ODBCStatementImpl \
Parameter Preparator SessionImpl TypeInfo Unicode Utility

ifndef POCO_DATA_NO_SQL_PARSER
target_includes = $(POCO_BASE)/Data/src
endif

target = PocoDataODBC
target_version = $(LIBVERSION)
target_libs = PocoData PocoFoundation
Expand Down
2 changes: 0 additions & 2 deletions Data/ODBC/include/Poco/Data/ODBC/Handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ class Handle
SQLRETURN rc =
#endif
SQLFreeHandle(handleType, _handle);
// N.B. Destructors should not throw, but neither do we want to
// leak resources. So, we throw here in debug mode if things go bad.
poco_assert_dbg (!Utility::isError(rc));
}
catch (...)
Expand Down
2 changes: 1 addition & 1 deletion Data/ODBC/src/ODBCStatementImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ void ODBCStatementImpl::makeStep()
_extractors[currentDataSet()]->reset();
_nextResponse = SQLFetch(_stmt);
// workaround for SQL Server drivers 17, 18, ...
// stored procedure calls produce additional data,
// stored procedure calls may produce additional data,
// causing SQLFetch error 24000 (invalid cursor state);
// when it happens, SQLMoreResults() is called to
// force SQL_NO_DATA response
Expand Down
4 changes: 4 additions & 0 deletions Data/ODBC/testsuite/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ ifeq ($(POCO_CONFIG),MinGW)
objects += ODBCAccessTest
endif

ifndef POCO_DATA_NO_SQL_PARSER
target_includes = $(POCO_BASE)/Data/src
endif

target = testrunner
target_version = 1
target_libs = PocoDataODBC PocoData PocoFoundation CppUnit
Expand Down
2 changes: 1 addition & 1 deletion Data/ODBC/testsuite/src/ODBCSQLServerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,9 +968,9 @@ CppUnit::Test* ODBCSQLServerTest::suite()
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSQLLogger);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testAutoCommit);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSessionTransactionNoAutoCommit);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTransaction);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTransactionIsolation);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSessionTransaction);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTransaction);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTransactor);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testNullable);
CppUnit_addTest(pSuite, ODBCSQLServerTest, testUnicode);
Expand Down
2 changes: 1 addition & 1 deletion Data/ODBC/testsuite/src/ODBCTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ void ODBCTest::testTransactionIsolation()
recreatePersonTable();
_pSession->setFeature("autoBind", bindValue(i));
_pSession->setFeature("autoExtract", bindValue(i+1));
_pExecutor->transactionIsolation(_rConnectString);
_pExecutor->transactionIsolation();
i += 2;
}
}
Expand Down
67 changes: 34 additions & 33 deletions Data/ODBC/testsuite/src/SQLExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4187,7 +4187,7 @@ void SQLExecutor::autoCommit(const std::string& connect)
}


void SQLExecutor::transactionIsolation(const std::string& connect)
void SQLExecutor::transactionIsolation()
{
auto ti = session().getTransactionIsolation();

Expand Down Expand Up @@ -4225,18 +4225,25 @@ void SQLExecutor::sessionTransaction(const std::string& connect)
std::string result;

session().setFeature("autoCommit", true);
assertTrue (session().getFeature("autoCommit"));
assertTrue (!session().isTransaction());

session().begin();
assertTrue (session().isTransaction());
assertTrue (!session().getFeature("autoCommit"));

// autocommit is invalid for session in transaction ...
// changing autocommit is invalid for session in transaction ...
try
{
session().setFeature("autoCommit", true);
fail ("must fail on autocommit setting during transaction");
}
catch(const Poco::InvalidAccessException& e) { }
// make sure nothing was changed ...
assertTrue (!session().getFeature("autoCommit"));
// but setting it to its current state is allowed (no-op)
session().setFeature("autoCommit", false);
assertTrue (!session().getFeature("autoCommit"));

session() << "INSERT INTO Person VALUES (?,?,?,?)", use(lastNames), use(firstNames), use(addresses), use(ages), now;
assertTrue (session().isTransaction());
Expand Down Expand Up @@ -4293,6 +4300,7 @@ void SQLExecutor::sessionTransactionNoAutoCommit(const std::string& connect)
}

std::string funct = "sessionTransactionNoAutoCommit()";

std::vector<std::string> lastNames = {"LN1", "LN2"};
std::vector<std::string> firstNames = {"FN1", "FN2"};
std::vector<std::string> addresses = {"ADDR1", "ADDR2"};
Expand All @@ -4311,20 +4319,24 @@ void SQLExecutor::sessionTransactionNoAutoCommit(const std::string& connect)
local << "SELECT COUNT(*) FROM Person", into(locCount), now;
assertTrue (0 == count);
assertTrue (2 == locCount);
#ifndef POCO_DATA_NO_SQL_PARSER
assertTrue (local.isTransaction());

// autocommit is invalid for session in transaction ...
try
{
local.setFeature("autoCommit", true);
fail ("must fail on autocommit setting during transaction");
fail ("must fail on autocommit setting during transaction", __LINE__);
}
catch(const Poco::InvalidAccessException& e) { }

// but setting it to its current state is allowed (no-op)
local.setFeature("autoCommit", false);

assertTrue (!session().isTransaction());

#else
session().commit();
#endif // POCO_DATA_NO_SQL_PARSER
local.commit();
assertTrue (!local.isTransaction());

Expand All @@ -4341,8 +4353,12 @@ void SQLExecutor::sessionTransactionNoAutoCommit(const std::string& connect)
local << "SELECT COUNT(*) FROM Person", into(locCount), now;
assertTrue (0 == count);
assertTrue (4 == locCount);
#ifndef POCO_DATA_NO_SQL_PARSER
assertTrue (local.isTransaction());
assertTrue (!session().isTransaction());
#else
session().commit();
#endif

local.rollback();
assertTrue (!local.isTransaction());
Expand All @@ -4354,7 +4370,10 @@ void SQLExecutor::sessionTransactionNoAutoCommit(const std::string& connect)
local << "SELECT COUNT(*) FROM Person", into(locCount), now;
assertTrue (2 == count);
assertTrue (2 == locCount);

#ifndef POCO_DATA_NO_SQL_PARSER
session().commit();
local.commit();
#endif
session().setFeature("autoCommit", autoCommit);
}

Expand Down Expand Up @@ -4399,34 +4418,26 @@ void SQLExecutor::transaction(const std::string& connect)
assertTrue (trans.isActive());
assertTrue (session().isTransaction());

try { session() << "INSERT INTO Person VALUES (?,?,?,?)", use(lastNames), use(firstNames), use(addresses), use(ages), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
session() << "INSERT INTO Person VALUES (?,?,?,?)", use(lastNames), use(firstNames), use(addresses), use(ages), now;

assertTrue (session().isTransaction());
assertTrue (trans.isActive());

try { session() << "SELECT COUNT(*) FROM Person", into(count), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
session() << "SELECT COUNT(*) FROM Person", into(count), now;
assertTrue (2 == count);
assertTrue (session().isTransaction());
assertTrue (trans.isActive());
}
assertTrue (!session().isTransaction());

try { session() << "SELECT count(*) FROM Person", into(count), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
session() << "SELECT count(*) FROM Person", into(count), now;
assertTrue (0 == count);
assertTrue (session().isTransaction());
assertTrue (!session().isTransaction());
session().commit();

{
Transaction trans(session());
try { session() << "INSERT INTO Person VALUES (?,?,?,?)", use(lastNames), use(firstNames), use(addresses), use(ages), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
session() << "INSERT INTO Person VALUES (?,?,?,?)", use(lastNames), use(firstNames), use(addresses), use(ages), now;

Statement stmt1 = (local << "SELECT COUNT(*) FROM Person", into(locCount), async, now);

Expand All @@ -4440,20 +4451,14 @@ void SQLExecutor::transaction(const std::string& connect)
assertTrue (2 == locCount);
}

try { session() << "SELECT count(*) FROM Person", into(count), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
session() << "SELECT count(*) FROM Person", into(count), now;
assertTrue (2 == count);

try { session() << "DELETE FROM Person", now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
session() << "DELETE FROM Person", now;

Statement stmt1 = (local << "SELECT count(*) FROM Person", into(locCount), async, now);

try { session() << "SELECT count(*) FROM Person", into(count), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
session() << "SELECT count(*) FROM Person", into(count), now;
assertTrue (0 == count);
try
{
Expand Down Expand Up @@ -4493,19 +4498,15 @@ void SQLExecutor::transaction(const std::string& connect)
stmt2.wait();
assertTrue (0 == locCount);

try { session() << "SELECT count(*) FROM Person", into(count), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
session() << "SELECT count(*) FROM Person", into(count), now;
assertTrue (0 == count);

trans.execute(sql);

Statement stmt3 = (local << "SELECT COUNT(*) FROM Person", into(locCount), now);
assertTrue (2 == locCount);

try { session() << "SELECT count(*) FROM Person", into(count), now; }
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail (funct); }
session() << "SELECT count(*) FROM Person", into(count), now;
assertTrue (2 == count);
session().commit();

Expand Down
2 changes: 1 addition & 1 deletion Data/ODBC/testsuite/src/SQLExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ class SQLExecutor: public CppUnit::TestCase
void sqlLogger(const std::string& connect);

void autoCommit(const std::string& connect);
void transactionIsolation(const std::string& connect);
void transactionIsolation();

void sessionTransaction(const std::string& connect);
void sessionTransactionNoAutoCommit(const std::string& connect);
Expand Down
4 changes: 4 additions & 0 deletions Data/PostgreSQL/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ objects = Extractor BinaryExtractor Binder SessionImpl Connector \
PostgreSQLStatementImpl PostgreSQLException \
SessionHandle StatementExecutor PostgreSQLTypes Utility

ifndef POCO_DATA_NO_SQL_PARSER
target_includes = $(POCO_BASE)/Data/src
endif

target = PocoDataPostgreSQL
target_version = $(LIBVERSION)
target_libs = PocoData PocoFoundation
Expand Down
4 changes: 4 additions & 0 deletions Data/PostgreSQL/testsuite/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ SYSLIBS += -lpq -lz -lpthread -ldl

objects = PostgreSQLTestSuite Driver PostgreSQLTest SQLExecutor

ifndef POCO_DATA_NO_SQL_PARSER
target_includes = $(POCO_BASE)/Data/src
endif

target = testrunner
target_version = 1
target_libs = PocoDataPostgreSQL PocoData PocoFoundation CppUnit
Expand Down
16 changes: 9 additions & 7 deletions Data/SQLite/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ include $(POCO_BASE)/build/rules/global
COMMONFLAGS += -I$(POCO_BASE)/Data/SQLite/src

SYSFLAGS += -DSQLITE_THREADSAFE=1 -DSQLITE_DISABLE_LFS \
-DSQLITE_OMIT_UTF16 -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_COMPLETE \
-DSQLITE_OMIT_TCL_VARIABLE -DSQLITE_OMIT_DEPRECATED
-DSQLITE_OMIT_UTF16 -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_COMPLETE \
-DSQLITE_OMIT_TCL_VARIABLE -DSQLITE_OMIT_DEPRECATED

objects = Binder Extractor Notifier SessionImpl Connector \
SQLiteException SQLiteStatementImpl Utility

sqlite_objects = sqlite3
SQLiteException SQLiteStatementImpl Utility

ifdef POCO_UNBUNDLED
SYSLIBS += -lsqlite3
SYSLIBS += -lsqlite3
else
objects += $(sqlite_objects)
objects += sqlite3
endif

ifndef POCO_DATA_NO_SQL_PARSER
target_includes = $(POCO_BASE)/Data/src
endif

target = PocoDataSQLite
Expand Down
4 changes: 4 additions & 0 deletions Data/SQLite/testsuite/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ include $(POCO_BASE)/build/rules/global
objects = SQLiteTestSuite Driver \
SQLiteTest

ifndef POCO_DATA_NO_SQL_PARSER
target_includes = $(POCO_BASE)/Data/src
endif

target = testrunner
target_version = 1
target_libs = PocoDataSQLite PocoData PocoFoundation CppUnit
Expand Down
Loading

0 comments on commit 08524db

Please sign in to comment.