From d480055a85149fd31d022df129b542a70587bad6 Mon Sep 17 00:00:00 2001 From: Guenter Obiltschnig Date: Wed, 16 May 2007 11:23:29 +0000 Subject: [PATCH] final Data changes --- .../Poco/Data/ODBC/ODBCStatementImpl.h | 2 +- Data/ODBC/src/ODBCColumn.cpp | 2 +- Data/ODBC/src/ODBCStatementImpl.cpp | 2 +- Data/SQLite/Makefile | 4 +- Data/SQLite/src/SQLiteStatementImpl.cpp | 7 +- Data/SQLite/src/Utility.cpp | 2 +- Data/SQLite/testsuite/src/SQLiteTest.cpp | 31 +-- Data/SQLite/testsuite/src/SQLiteTest.h | 4 +- Data/doc/DataDeveloperManual.page | 39 +-- Data/doc/DataReleaseNotes.page | 26 ++ Data/doc/DataUserManual.page | 259 ++++++++++++++---- Data/include/Poco/Data/BLOB.h | 5 +- Data/include/Poco/Data/BLOBStream.h | 6 +- Data/include/Poco/Data/Column.h | 4 +- Data/include/Poco/Data/Range.h | 4 +- Data/include/Poco/Data/RecordSet.h | 43 ++- Data/include/Poco/Data/SessionFactory.h | 6 +- Data/include/Poco/Data/Statement.h | 10 +- Data/include/Poco/Data/StatementImpl.h | 2 - Data/samples/Makefile | 3 +- Data/samples/RecordSet/src/RecordSet.cpp | 12 +- Data/samples/Tuple/Makefile | 4 +- Data/samples/Tuple/Tuple_vs71.vcproj | 12 +- Data/samples/Tuple/Tuple_vs80.vcproj | 2 +- Data/samples/samples_vs71.sln | 8 + Data/src/RecordSet.cpp | 28 +- Data/src/Statement.cpp | 11 +- Data/src/StatementImpl.cpp | 2 +- Data/testsuite/src/DataTest.cpp | 9 +- 29 files changed, 375 insertions(+), 174 deletions(-) create mode 100644 Data/doc/DataReleaseNotes.page diff --git a/Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h b/Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h index 0de6ee38c..e5295b05c 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h +++ b/Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h @@ -1,7 +1,7 @@ // // ODBCStatementImpl.h // -// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h#3 $ +// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h#4 $ // // Library: ODBC // Package: ODBC diff --git a/Data/ODBC/src/ODBCColumn.cpp b/Data/ODBC/src/ODBCColumn.cpp index 2f2e0be1f..e54333cb5 100644 --- a/Data/ODBC/src/ODBCColumn.cpp +++ b/Data/ODBC/src/ODBCColumn.cpp @@ -1,7 +1,7 @@ // // ODBCColumn.cpp // -// $Id: //poco/Main/Data/ODBC/src/ODBCColumn.cpp#3 $ +// $Id: //poco/Main/Data/ODBC/src/ODBCColumn.cpp#4 $ // // Library: ODBC // Package: ODBC diff --git a/Data/ODBC/src/ODBCStatementImpl.cpp b/Data/ODBC/src/ODBCStatementImpl.cpp index fef1ee78c..964d170a8 100644 --- a/Data/ODBC/src/ODBCStatementImpl.cpp +++ b/Data/ODBC/src/ODBCStatementImpl.cpp @@ -1,7 +1,7 @@ // // ODBCStatementImpl.cpp // -// $Id: //poco/Main/Data/ODBC/src/ODBCStatementImpl.cpp#2 $ +// $Id: //poco/Main/Data/ODBC/src/ODBCStatementImpl.cpp#3 $ // // Library: ODBC // Package: ODBC diff --git a/Data/SQLite/Makefile b/Data/SQLite/Makefile index 504eac56c..fc888e655 100644 --- a/Data/SQLite/Makefile +++ b/Data/SQLite/Makefile @@ -1,14 +1,14 @@ # # Makefile # -# $Id: //poco/Main/Data/SQLite/Makefile#3 $ +# $Id: //poco/Main/Data/SQLite/Makefile#4 $ # # Makefile for Poco SQLite # include $(POCO_BASE)/build/rules/global -SYSFLAGS += -DTHREADSAFE -DNO_TCL +SYSFLAGS += -DTHREADSAFE -DNO_TCL -DSQLITE_DISABLE_LFS objects = Binder Extractor SessionImpl Connector \ SQLiteException SQLiteStatementImpl Utility \ diff --git a/Data/SQLite/src/SQLiteStatementImpl.cpp b/Data/SQLite/src/SQLiteStatementImpl.cpp index e4b0db248..b2efd6cb0 100644 --- a/Data/SQLite/src/SQLiteStatementImpl.cpp +++ b/Data/SQLite/src/SQLiteStatementImpl.cpp @@ -1,7 +1,7 @@ // // SQLiteStatementImpl.cpp // -// $Id: //poco/Main/Data/SQLite/src/SQLiteStatementImpl.cpp#4 $ +// $Id: //poco/Main/Data/SQLite/src/SQLiteStatementImpl.cpp#6 $ // // Library: SQLite // Package: SQLite @@ -38,8 +38,9 @@ #include "Poco/Data/SQLite/Utility.h" #include "Poco/Data/SQLite/SQLiteException.h" #include "Poco/String.h" -#include "sqlite3.h" #include +#include +#include "sqlite3.h" namespace Poco { @@ -96,7 +97,7 @@ void SQLiteStatementImpl::compileImpl() else if(rc == SQLITE_OK && !pStmt) // comment/whitespace ignore { pSql = pLeftover; - if (strlen(pSql) == 0) + if (std::strlen(pSql) == 0) { // empty statement or an conditional statement! like CREATE IF NOT EXISTS // this is valid diff --git a/Data/SQLite/src/Utility.cpp b/Data/SQLite/src/Utility.cpp index fbddd433b..0670f552f 100644 --- a/Data/SQLite/src/Utility.cpp +++ b/Data/SQLite/src/Utility.cpp @@ -1,7 +1,7 @@ // // Utility.cpp // -// $Id: //poco/Main/Data/SQLite/src/Utility.cpp#4 $ +// $Id: //poco/Main/Data/SQLite/src/Utility.cpp#5 $ // // Library: SQLite // Package: SQLite diff --git a/Data/SQLite/testsuite/src/SQLiteTest.cpp b/Data/SQLite/testsuite/src/SQLiteTest.cpp index fc0138598..be3783bc2 100644 --- a/Data/SQLite/testsuite/src/SQLiteTest.cpp +++ b/Data/SQLite/testsuite/src/SQLiteTest.cpp @@ -1,7 +1,7 @@ // // SQLiteTest.cpp // -// $Id: //poco/Main/Data/SQLite/testsuite/src/SQLiteTest.cpp#3 $ +// $Id: //poco/Main/Data/SQLite/testsuite/src/SQLiteTest.cpp#5 $ // // Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // and Contributors. @@ -163,34 +163,6 @@ SQLiteTest::~SQLiteTest() } -void SQLiteTest::testTAC() -{ - Poco::File aFile("sqlite.db"); - - if (aFile.exists()) - aFile.remove(); - - Session ses (SessionFactory::instance().create(SQLite::Connector::KEY, "sqlite.db")); - - ses << "CREATE TABLE LogTest (Id INTEGER PRIMARY KEY, Time INTEGER, Value INTEGER)", now; - //ses << "PRAGMA synchronous = OFF", now; - - double value = -200000000000.0; - Poco::Int64 time = (Poco::Int64)22329988776655.0; - Poco::Stopwatch sw; - sw.start(); - ses.begin(); - Statement stmt = (ses << "INSERT INTO LogTest ([Time], Value) VALUES (:time, :value)", use(time), use(value)); - for(int i = 0; i < 1000; i++) - { - stmt.execute(); - } - ses.commit(); - sw.stop(); - std::cout << std::endl << "Ms for 1000 inserts: " << sw.elapsed() << std::endl; -} - - void SQLiteTest::testSimpleAccess() { Session tmp (SessionFactory::instance().create(SQLite::Connector::KEY, "dummy.db")); @@ -1619,7 +1591,6 @@ CppUnit::Test* SQLiteTest::suite() { CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SQLiteTest"); - CppUnit_addTest(pSuite, SQLiteTest, testTAC); CppUnit_addTest(pSuite, SQLiteTest, testSimpleAccess); CppUnit_addTest(pSuite, SQLiteTest, testInsertCharPointer); CppUnit_addTest(pSuite, SQLiteTest, testInsertCharPointer2); diff --git a/Data/SQLite/testsuite/src/SQLiteTest.h b/Data/SQLite/testsuite/src/SQLiteTest.h index 3afe6b127..ec12330e2 100644 --- a/Data/SQLite/testsuite/src/SQLiteTest.h +++ b/Data/SQLite/testsuite/src/SQLiteTest.h @@ -1,7 +1,7 @@ // // SQLiteTest.h // -// $Id: //poco/Main/Data/SQLite/testsuite/src/SQLiteTest.h#2 $ +// $Id: //poco/Main/Data/SQLite/testsuite/src/SQLiteTest.h#3 $ // // Definition of the SQLiteTest class. // @@ -110,8 +110,6 @@ public: void testInternalExtraction(); - void testTAC(); - void setUp(); void tearDown(); diff --git a/Data/doc/DataDeveloperManual.page b/Data/doc/DataDeveloperManual.page index 05c9bd6e7..a94e02e52 100644 --- a/Data/doc/DataDeveloperManual.page +++ b/Data/doc/DataDeveloperManual.page @@ -1,17 +1,18 @@ -POCO Data Developer Guide +POCO Data Connectors Developer Guide Data !!!Overview -Developing one's own <[DataConnector]> implementation is rather straight-forward. +Developing one's own <*Data Connector*> implementation is rather straight-forward. Just implement the following interfaces: * Poco::Data::AbstractBinder * Poco::Data::AbstractExtractor * Poco::Data::StatementImpl * Poco::Data::SessionImpl - * Poco::Data::SessionInstantiator + * Poco::Data::Connector * optional: Poco::Data::AbstractPreparation -It is recommended to implement the classes from top to down (ie. start with Binder and Extractor) and to use a namespace that has <[ Poco::Data ]> as parent, e.g.<[ Poco::Data::SQLite ]>. +It is recommended to implement the classes from top to down (ie. start with Binder and Extractor) and to use a +namespace that has <[ Poco::Data ]> as parent, e.g.<[ Poco::Data::SQLite ]>. !!!AbstractBinder An <[AbstractBinder]> is a class that maps values to placeholders. It is also responsible to bind primitive C++ data types to database @@ -398,31 +399,31 @@ The connection is opened in the constructor, and closed in the destructor. /// Aborts a transaction ---- -!!!SessionInstantiator -Finally, one needs to implement the <[SessionInstantiator]>. -Each <[SessionInstantiator]> should have a public static const string member named <*KEY*> and must have a factory method to <*create*> <[ Poco::AutoPtr ]> objects of type <[SessionImpl]>. +!!!Connector +Finally, one needs to implement the <[Connector]>. +Each <[Connector]> should have a public static const string member named <*KEY*> and must have a factory method to <*create*> <[ Poco::AutoPtr ]> objects of type <[SessionImpl]>. It should also have a static <*addToFactory()*> and a static <*removeFromFactory()*> method: - class My_API SessionInstantiator: public Poco::Data::SessionInstantiator - /// SessionInstantiator instantiates SessionImpl objects. + class My_API Connector: public Poco::Data::Connector + /// Connector instantiates SessionImpl objects. { public: static const std::string KEY; /// Keyword for creating sessions - SessionInstantiator(); - /// Creates the SessionInstantiator. + Connector(); + /// Creates the Connector. - ~SessionInstantiator(); - /// Destroys the SessionInstantiator. + ~Connector(); + /// Destroys the Connector. - Poco::AutoPtr < Poco::Data::SessionImpl > create(const std::string& initString); - /// Creates a SessionImpl object and initializes it with the given initString. + Poco::AutoPtr < Poco::Data::SessionImpl > createSession(const std::string& connectionString); + /// Creates a SessionImpl object and initializes it with the given connectionString. - static void addToFactory(); - /// Registers the SessionInstantiator under the Keyword SessionInstantiator::KEY at the Poco::Data::SessionFactory + static void registerConnector(); + /// Registers the Connector under the Keyword Connector::KEY at the Poco::Data::SessionFactory - static void removeFromFactory(); - /// Unregisters the SessionInstantiator under the Keyword SessionInstantiator::KEY at the Poco::Data::SessionFactory + static void unregisterConnector(); + /// Unregisters the Connector under the Keyword Connector::KEY at the Poco::Data::SessionFactory }; ---- diff --git a/Data/doc/DataReleaseNotes.page b/Data/doc/DataReleaseNotes.page new file mode 100644 index 000000000..3f17c5276 --- /dev/null +++ b/Data/doc/DataReleaseNotes.page @@ -0,0 +1,26 @@ +POCO Data Release Notes +Data + +!!!Release 1.3 + +Release 1.3 of the POCO C++ Libraries is the first official release containing the Data library. +The Data library has been available in a development state for the 1.2 release. For the 1.3 +release, a few things have been changed in an incompatible way that requires changes +to existing code. + +!!Summary of Changes + + - Class Poco::Data::RecordSet has been added providing generic access + to arbitrary tables. + - SessionInstantiator has been renamed Poco::Data::Connector. + - Poco::Data::BLOBInputStream and Poco::Data::BLOBOutputStream allow convenient access to Poco::Data::BLOB data. + - Poco::Data::Session and Poco::Data::Statement can be used in simpler ways. + - The DataConnectors project directory has been merged into the Data project directory. + + +!!Incompatible Changes and Possible Transition Issues + +SessionInstantiator has been renamed Poco::Data::Connector, and the +member functions addToFactory() and removeFromFactory() are now named +registerConnector() and unregisterConnector(), respectively. +This requires a change in all applications already using POCO Data. diff --git a/Data/doc/DataUserManual.page b/Data/doc/DataUserManual.page index 67c09c864..3c637cf42 100644 --- a/Data/doc/DataUserManual.page +++ b/Data/doc/DataUserManual.page @@ -2,12 +2,13 @@ POCO Data User Guide Data !!!First Steps -PocoData is POCO's database abstraction layer which allows users to easily send/retrieve data to/from various different databases. +POCO Data is POCO's database abstraction layer which allows users to easily +send/retrieve data to/from various different SQL databases. The following complete example shows how to use it: #include "Poco/Data/Common.h" - #include "Poco/Data/SQLite/SessionInstantiator.h" + #include "Poco/Data/SQLite/Connector.h" #include using namespace Poco::Data; @@ -15,20 +16,20 @@ The following complete example shows how to use it: void init() { - SQLite::SessionInstantiator::addToFactory(); + SQLite::Connector::registerConnector(); } void shutdown() { - SQLite::SessionInstantiator::removeFromFactory(); + SQLite::Connector::unregisterConnector(); } int main(int argc, char* argv[]) { init(); - Session ses (SessionFactory::instance().create(SQLite::SessionInstantiator::KEY, "dummy.db")); + Session ses("SQLite", "sample.db"); int count = 0; ses << "SELECT COUNT(*) FROM PERSON", into(count), now; std::cout << "People in DB " << count; @@ -37,11 +38,20 @@ The following complete example shows how to use it: ---- The above example is pretty much self explanatory. The <[Poco/Data/Common.h]> file pulls in some common includes, -the SQLite::SessionInstantiator is used to initialize the SQLite package so that we can later create an SQLite session -via the SessionFactory (note that <[ SQLite::SessionInstantiator::KEY ]> is simply the string "sqlite"). +the SQLite::Connector is used to register the SQLite connector so that we can later create an SQLite session +via the SessionFactory. The two-argument constructor + + Sesssion ses("SQLite", "sample.db"); +---- + +is actually equivalent to: + Session ses(SessionFactory::instance()::create("SQLite", "sample.db")); +---- + The << operator is used to send SQL statements to the Session, the <*into(count)*> simply informs the session where to store the result of the query. -Take note of the __now__ at the end of the SQL statement. It is required, otherwise the statement would not be executed. -The <* <[ using namespace Poco::Data ]> *> is for convenience only but highly recommended for good readable code (while <* <[ ses << "SELECT COUNT(*) FROM PERSON", Poco::Data::into(count), Poco::Data::now; ]> *> is valid, it simply looks... strange). +Take note of the at the end of the SQL statement. It is required, otherwise the statement would not be executed. +The <* <[ using namespace Poco::Data ]> *> is for convenience only but highly recommended for good readable code +(while <* <[ ses << "SELECT COUNT(*) FROM PERSON", Poco::Data::into(count), Poco::Data::now; ]> *> is valid, it simply looks... strange). The remainder of this tutorial is split up into the following parts: * Creating Sessions @@ -52,11 +62,14 @@ The remainder of this tutorial is split up into the following parts: * Working with complex data types: how to map C++ objects to a database table !!!Creating Sessions -Sessions are always created via the SessionFactory create method: +Sessions are always created via the SessionFactory create method, or implicitly +via the two-argument Session constructor. -Session create(const std::string& dbType, const std::string& initParams); +Session create(const std::string& connectorKey, const std::string& connectionString); ---- -The first parameter contains the type of the Session one wants to create, for the moment "sqlite" is supported and via the ODBC driver we support Oracle, SQLite, DB2, SQLServer and PostgreSQL. The second parameter contains the initialization string. +The first parameter contains the type of the Session one wants to create. For the moment "SQLite" is supported +directly, and via the ODBC driver support for Oracle, SQLite, DB2, SQLServer and PostgreSQL is available. +The second parameter contains the (connector-specific) connection string. In the case of SQLite, the location of the database file is sufficient. !!!Inserting and Retrieving Data @@ -70,15 +83,20 @@ If we want to insert one single forename we could simply write: ses << "INSERT INTO FORENAME VALUES(" << aName << ")", now; ---- -Well, we could do that, but we won't. A much better solution is to use and connect each placeholder via a expression with a variable that will provide the value during execution. Placeholders are recognized by having a in front of their name. Rewriting the above code now simply gives +Well, we could do that, but we won't. A much better solution is to use and connect each placeholder via a +expression with a variable that will provide the value during execution. +Placeholders are recognized by having a in front of their name. Rewriting the above code now simply gives std::string aName("Peter"); ses << "INSERT INTO FORENAME VALUES(:name)", use(aName), now; ---- -In this example the expression matches the <* :name *> with the <*Peter*> value. Note that apart from the nicer syntax, the real benefit of placeholders - which is performance - doesn't show here. Check the <*Working with Statements*> section to find out more. +In this example the expression matches the <* :name *> with the <*Peter*> value. +Note that apart from the nicer syntax, the real benefit of placeholders - which is performance - doesn't show here. +Check the <*Working with Statements*> section to find out more. -Retrieving data from the Database works similar. The expression matches the returned database values to C++ objects, it also allows to provide a default value in case null data is returned from the database: +Retrieving data from the Database works similar. The expression matches the returned database values to +C++ objects, it also allows to provide a default value in case null data is returned from the database: std::string aName; ses << "SELECT NAME FROM FORENAME", into(aName), now; // the default is the empty string @@ -103,12 +121,16 @@ Lets assume we have a Person table that contains an age, a first and a last name ses << "SELECT (firstname, lastname, age) FROM Person", into(firstName), into(lastName), into(age), now; ---- -Most important here is the of the into and use expressions. The first placeholder is matched by the first <*use*>, the 2nd by the 2nd <*use*> etc. -The same is true for the <*into*> statement. We select <*firstname*> as the first column of the result set, thus <*into(firstName)*> must be the first into clause. +Most important here is the of the into and use expressions. The first placeholder is matched by the first <*use*>, +the 2nd by the 2nd <*use*> etc. +The same is true for the <*into*> statement. We select <*firstname*> as the first column of the result set, +thus <*into(firstName)*> must be the first into clause. !! Handling NULL entries -A common case with databases are optional data fields that can contain NULL. To accomodate for NULL, the <*into*> expression allows you to define default values. -For example, assume that age is such an optional field and we want to provide as default value which is done by writing : +A common case with databases are optional data fields that can contain NULL. To accomodate for NULL, the <*into*> expression allows +you to define default values. +For example, assume that age is such an optional field and we want to provide as default value +which is done by writing : std::string firstName("Peter"; std::string lastName("Junior"); @@ -117,25 +139,35 @@ For example, assume that age is such an optional field and we want to provide as ses << "SELECT (firstname, lastname, age) FROM Person", into(firstName), into(lastName), into(age, -1), now; ---- -While you can achieve the same effect by initializing age previously to -1 (<*int age = -1*>), this won't work with collection types. Here you must provide the second parameter +While you can achieve the same effect by initializing age previously to -1 (<*int age = -1*>), +this won't work with collection types. Here you must provide the second parameter to init. Otherwise, values will be initialized to compiler specific values. !!!Working with Statements -We often mentioned the term <*Statement*> in the previous section, yet we only worked with database session objects so far, or at least, that's what I made you believe ;-). +We often mentioned the term <*Statement*> in the previous section, yet we only worked with database session objects so far, +or at least, that's what you have been made believe ;-). In reality, you have already worked with Statements. Lets take a look at the method signature of the << operator at Session: template Statement Session::operator << (const T& t) ---- -Simply ignore the template stuff in front, you won't need it. The only thing that counts here is that the operator <[ << ]> creates a <*Statement*> internally and returns it. -What happened in the previous examples is that the returned Statement was never assigned to a variable but simply passed on to the <*now*> part which executed the statement. Afterwards the statement was destroyed. +Simply ignore the template stuff in front, you won't need it. The only thing that counts here is that the operator <[ << ]> creates a +<*Statement*> internally and returns it. +What happened in the previous examples is that the returned Statement was never assigned to a variable but simply passed on to the <*now*> +part which executed the statement. Afterwards the statement was destroyed. Let's take one of the previous examples and change it so that we assign the statement: std::string aName("Peter"); Statement stmt = ( ses << "INSERT INTO FORENAME VALUES(:name)", use(aName) ); ---- Note that we must put brackets around the right part of the assignment, otherwise the compiler will complain. +If you don't like the above syntax, the following alternative is equivalent: + + Statement stmt(ses); + stmt << "INSERT INTO FORENAME VALUES(:name)", use(aName); +---- + What did we achieve by assigning the statement to a variable? Well, currently nothing, apart that we can control when to <*execute*>: std::string aName("Peter"); @@ -143,7 +175,8 @@ What did we achieve by assigning the statement to a variable? Well, currently no stmt.execute(); poco_assert (stmt.done()); ---- -By calling <*execute*> we asserted that our query was executed and that the value was inserted. The check to stmt.done() + +By calling <*execute*> we asserted that our query was executed and that the value was inserted. The check to <[stmt.done()]> simply guarantees that the statement was fully completed. !!Prepared Statements @@ -151,6 +184,7 @@ A prepared statement is created by omitting the <*now*> clause. Statement stmt = ( ses << "INSERT INTO FORENAME VALUES(:name)", use(aName) ); ---- + The advantage of a prepared statement is performance. Assume the following loop: std::string aName(); @@ -161,14 +195,17 @@ The advantage of a prepared statement is performance. Assume the following loop: stmt.execute(); } ---- + Instead of creating and parsing the Statement 100 times, we only do this once and then use the placeholder in combination with the <*use*> clause to insert 100 different values into the database. Still, this isn't the best way to insert a collection of values into a database. !!Things NOT To Do -<*use*> expects as input a parameter, which is bound later during execution. Thus, one can only use variables, but never constants. -The following code will very likely fail (but this is platform/compiler dependent and also depends if your building in release or debug mode, it will work from Monday to Thursday but will always fail on Friday, so shortly spoken: the kind of bugs -software developers REALLY love): + expects as input a parameter, which is bound later during execution. +Thus, one can only use variables, but never constants. +The following code will very likely fail (but this is platform/compiler dependent and also depends if your +building in release or debug mode, it will work from Monday to Thursday but will always fail on Friday, so shortly spoken: the kind of bugs +software developers <*really*> love): Statement stmt = (ses << INSERT INTO PERSON VALUES (:fn, :ln, :age)", use("Peter"), use("Junior"), use(4)); //ERR! stmt.execute(); @@ -177,7 +214,7 @@ The constant values <*Junior*>, <*Peter*> and <*4*> must be assigned to variable !!!Collection Support If one needs to handle many values at once, one ought to use a collection class. -Per default we support the following collection types: +Per default, the following collection types are supported: * vector: no requirements * set: the < operator must be supported by the datatype. Note that duplicate key/value pairs are ignored. * multiset: the < operator must be supported by the datatype @@ -197,14 +234,16 @@ A bulk insert example via vector would be: ---- The same example would work with set or multiset but not with map and multimap (std::string has no () operator). -Note that <*use*> requires collections! +Note that requires <*non-empty*> collections! Now reconsider the following example: std::string aName; ses << "SELECT NAME FROM FORENAME", into(aName), now; ---- -Previously, it worked because the table contained only one single entry but now the database table contains at least 100 strings, yet we only offer storage space for one single result. + +Previously, it worked because the table contained only one single entry but now the database table contains at least 100 strings, +yet we only offer storage space for one single result. Thus, the above code will fail and throw an exception. One possible way to handle this is: @@ -215,17 +254,23 @@ One possible way to handle this is: And again, instead of vector, one could use set or multiset. !!!The limit clause -Working with collections might be convenient to bulk process data but there is also the risk that large operations will block your application for a very long time. In addition, you might want to have better fine-grained control over your query, e.g. you only want to extract a subset of data until a condition is met. +Working with collections might be convenient to bulk process data but there is also the risk that large operations will +block your application for a very long time. In addition, you might want to have better fine-grained control over your +query, e.g. you only want to extract a subset of data until a condition is met. To elevate that problem, one can use the keyword. -Let's assume we are retrieving thousands of rows from a database to render the data to a GUI. To allow the user to stop fetching data any time (and to avoid having the user franatically click inside the GUI because it doesn't show anything for seconds), we have to partition this process: +Let's assume we are retrieving thousands of rows from a database to render the data to a GUI. +To allow the user to stop fetching data any time (and to avoid having the user franatically click inside the GUI because +it doesn't show anything for seconds), we have to partition this process: std::vector names; ses << "SELECT NAME FROM FORENAME", into(names), limit(50), now; ---- -The above example will retrieve up to 50 rows from the database (note that returning nothing is valid!) and <*append*> it to the names collection, i.e. the collection is not cleared! -If one wants to make sure that 50 rows are returned one must set the 2nd limit parameter (which per default is set to <*false*>) to <*true*>: +The above example will retrieve up to 50 rows from the database (note that returning nothing is valid!) and <*append*> +it to the names collection, i.e. the collection is not cleared! +If one wants to make sure that 50 rows are returned one must set the 2nd limit parameter +(which per default is set to <*false*>) to <*true*>: std::vector names; ses << "SELECT NAME FROM FORENAME", into(names), limit(50, true), now; @@ -257,7 +302,8 @@ To guarantee that at least one valid result row is returned use the is only the short name for . To iterate over a result set step-by-step, e.g. one wants to avoid using a collection class, one would write +Note that is only the short name for . To iterate over a result set step-by-step, e.g. one wants to avoid +using a collection class, one would write: std::string aName; Statement stmt = (ses << "SELECT NAME FROM FORENAME", into(aName), lowerLimit(1), upperLimit(1)); @@ -272,7 +318,8 @@ And for the lazy ones, there is the command: while (!stmt.done()) stmt.execute(); ---- -The third parameter to range is an optional boolean value which specifies if the upper limit is a hard limit, ie. if the amount of rows returned by the query must match exactly. Per default exact matching is off. +The third parameter to range is an optional boolean value which specifies if the upper limit is a hard limit, ie. +if the amount of rows returned by the query must match exactly. Per default exact matching is off. !!!Complex Data Type Mapping All the previous examples were contented to work with only the most basic data types: integer, string, ... @@ -305,8 +352,9 @@ Assume you have a class Person: } ---- -Ideally, one would like to use a Person as simple as one used a string. All that is needed is a template specialization of the <*TypeHandler*> template. Note that template specializations must be declared in the - as the original template, i.e. <*Poco::Data*>. The template specialization must implement the following methods: +Ideally, one would like to use a Person as simple as one used a string. All that is needed is a template specialization of the <*TypeHandler*> +template. Note that template specializations must be declared in the as the original template, i.e. <*Poco::Data*>. +The template specialization must implement the following methods: namespace Poco { namespace Data { @@ -315,7 +363,12 @@ Ideally, one would like to use a Person as simple as one used a string. All that class TypeHandler { public: - static void bind(std::size_t pos, const Person& obj, AbstractBinder* pBinder) + static std::size_t size() + { + return 3; // we handle three columns of the Table! + } + + static void bind(std::size_t pos, const Person& obj, AbstractBinder* pBinder) { poco_assert_dbg (pBinder != 0); // the table is defined as Person (FirstName VARCHAR(30), lastName VARCHAR, SocialSecNr INTEGER(3)) @@ -325,11 +378,6 @@ Ideally, one would like to use a Person as simple as one used a string. All that TypeHandler::bind(pos++, obj.getSocialSecNr(), pBinder); } - static std::size_t size() - { - return 3; // we handle three columns of the Table! - } - static void prepare(std::size_t pos, const Person& obj, AbstractPreparation* pPrepare) { poco_assert_dbg (pBinder != 0); @@ -354,12 +402,6 @@ Ideally, one would like to use a Person as simple as one used a string. All that obj.setLastName(lastName); obj.setSocialSecNr(socialSecNr); } - - private: - TypeHandler(); - ~TypeHandler(); - TypeHandler(const TypeHandler&); - TypeHandler& operator=(const TypeHandler&); }; } } // namespace Poco::Data @@ -369,4 +411,119 @@ And that's all you have to do. Working with Person is now as simple as working w std::map people; ses << "SELECT * FROM Person", into(people), now; ----- \ No newline at end of file +---- + +!!!RecordSet +The Poco::Data::RecordSet class provides a generic way to work with database tables. +Using a <[RecordSet]>, one can: + - iterate over all columns and rows in a table + - obtain meta information about columns (such as name, type, length, etc.) + +To work with a RecordSet, first create a Statement, execute it, and +create the RecordSet from the Statement, as follows: + + Statement select(session); + select << "SELECT * FROM Person"; + select.execute(); + RecordSet rs(select); +---- + +The number of rows in the RecordSet can be limited by specifying +a limit for the Statement. + +Following example demonstrates how to iterate over all rows and columns +in a RecordSet: + + bool more = rs.moveFirst(); + while (more) + { + for (std::size_t col = 0; col < cols; ++col) + { + std::cout << rs[col].convert() << " "; + } + std::cout << std::endl; + more = rs.moveNext(); + } +---- + +As mentioned above, the number of rows retrieved into a RecordSet at a +time can be limited using the <[limit]> or <[range]> clause. Iterating +over all rows in a table a bunch of rows at a time can thus be done as +follows: + + Statement select(session); + select << "SELECT * FROM Person", range(0, 10); + RecordSet rs(select); + while (!select.done()) + { + select.execute(); + bool more = rs.moveFirst(); + while (more) + { + for (std::size_t col = 0; col < cols; ++col) + { + std::cout << rs[col].convert() << " "; + } + std::cout << std::endl; + more = rs.moveNext(); + } + } +---- + + +!!!Tuples +Poco::Tuple and vectors of Poco::Tuple provide a convenient way to work with rows when +column types are known, because TypeHandlers for them are readily available. + +Consider the following example: + + typedef Poco::Tuple Person; + typedef std::vector People; + + People people; + people.push_back(Person("Bart Simpson", "Springfield", 12)); + people.push_back(Person("Lisa Simpson", "Springfield", 10)); + + Statement insert(session); + insert << "INSERT INTO Person VALUES(:name, :address, :age)", + use(people), now; +---- + +Of course, tuples can also be used in queries: + + Statement select(session); + select << "SELECT Name, Address, Age FROM Person", + into(people), + now; + + for (People::const_iterator it = people.begin(); it != people.end(); ++it) + { + std::cout << "Name: " << it->get<0>() << + ", Address: " << it->get<1>() << + ", Age: " << it->get<2>() <::const_iterator Iterator; diff --git a/Data/include/Poco/Data/BLOBStream.h b/Data/include/Poco/Data/BLOBStream.h index 54b9f7bef..c88ef7148 100644 --- a/Data/include/Poco/Data/BLOBStream.h +++ b/Data/include/Poco/Data/BLOBStream.h @@ -1,7 +1,7 @@ // // BLOBStream.h // -// $Id: //poco/Main/Data/include/Poco/Data/BLOBStream.h#2 $ +// $Id: //poco/Main/Data/include/Poco/Data/BLOBStream.h#3 $ // // Library: Data // Package: DataCore @@ -107,10 +107,6 @@ public: class Data_API BLOBInputStream: public BLOBIOS, public std::istream /// An input stream for reading from a BLOB. - /// - /// Using formatted input from a BLOBInputStream - /// is not recommended, due to the read-ahead behavior of - /// istream with formatted reads. { public: BLOBInputStream(BLOB& blob); diff --git a/Data/include/Poco/Data/Column.h b/Data/include/Poco/Data/Column.h index 09827fbee..9d5b135ec 100644 --- a/Data/include/Poco/Data/Column.h +++ b/Data/include/Poco/Data/Column.h @@ -1,7 +1,7 @@ // // Column.h // -// $Id: //poco/Main/Data/include/Poco/Data/Column.h#3 $ +// $Id: //poco/Main/Data/include/Poco/Data/Column.h#4 $ // // Library: Data // Package: DataCore @@ -174,8 +174,6 @@ public: return _pData->end(); } - - private: Column(); diff --git a/Data/include/Poco/Data/Range.h b/Data/include/Poco/Data/Range.h index 7abb52c1b..167c0e121 100644 --- a/Data/include/Poco/Data/Range.h +++ b/Data/include/Poco/Data/Range.h @@ -1,7 +1,7 @@ // // Range.h // -// $Id: //poco/Main/Data/include/Poco/Data/Range.h#4 $ +// $Id: //poco/Main/Data/include/Poco/Data/Range.h#5 $ // // Library: Data // Package: DataCore @@ -49,7 +49,7 @@ namespace Data { class Data_API Range - /// Limit stores information how many rows a query should return. + /// Range stores information how many rows a query should return. { public: Range(Poco::UInt32 lowValue, Poco::UInt32 upValue, bool hardLimit); diff --git a/Data/include/Poco/Data/RecordSet.h b/Data/include/Poco/Data/RecordSet.h index de566ad00..aac70e3a6 100644 --- a/Data/include/Poco/Data/RecordSet.h +++ b/Data/include/Poco/Data/RecordSet.h @@ -1,7 +1,7 @@ // // RecordSet.h // -// $Id: //poco/Main/Data/include/Poco/Data/RecordSet.h#5 $ +// $Id: //poco/Main/Data/include/Poco/Data/RecordSet.h#6 $ // // Library: Data // Package: DataCore @@ -54,10 +54,23 @@ namespace Data { class Data_API RecordSet: private Statement - /// RecordSet class provides access to data returned from a query. - /// Data access indexes (row and column) are 0-based. + /// RecordSet provides access to data returned from a query. + /// Data access indexes (row and column) are 0-based, as usual in C++. + /// /// Recordset provides navigation methods to iterate through the - /// recordset and retrieval methods to extract data. + /// recordset, retrieval methods to extract data, and methods + /// to get metadata (type, etc.) about columns. + /// + /// To work with a RecordSet, first create a Statement, execute it, and + /// create the RecordSet from the Statement, as follows: + /// + /// Statement select(session); + /// select << "SELECT * FROM Person"; + /// select.execute(); + /// RecordSet rs(select); + /// + /// The number of rows in the RecordSet can be limited by specifying + /// a limit for the Statement. { public: explicit RecordSet(const Statement& rStatement); @@ -91,8 +104,8 @@ public: const AbstractExtractionVec& rExtractions = extractions(); std::size_t s = rExtractions.size(); - if (0 == s || pos > s - 1) - throw RangeException(format("Invalid column number: %z", pos)); + if (0 == s || pos >= s) + throw RangeException(format("Invalid column index: %z", pos)); ExtractionVecPtr pExtraction = dynamic_cast(rExtractions[pos].get()); @@ -130,15 +143,28 @@ public: bool moveFirst(); /// Moves the row cursor to the first row. + /// + /// Returns true if there is at least one row in the RecordSet, + /// false otherwise. bool moveNext(); /// Moves the row cursor to the next row. + /// + /// Returns true if the row is available, or false + /// if the end of the record set has been reached and + /// no more rows are available. bool movePrevious(); /// Moves the row cursor to the previous row. + /// + /// Returns true if the row is available, or false + /// if there are no more rows available. bool moveLast(); /// Moves the row cursor to the last row. + /// + /// Returns true if there is at least one row in the RecordSet, + /// false otherwise. DynamicAny value(const std::string& name); /// Returns the value in the named column of the current row. @@ -195,7 +221,8 @@ private: if (pExtraction) { const Column& col = pExtraction->column(); - if (0 == Poco::icompare(name, col.name())) return col.position(); + if (0 == Poco::icompare(name, col.name())) + return col.position(); } } @@ -209,8 +236,6 @@ private: /// /// inlines /// - - inline std::size_t RecordSet::rowCount() const { poco_assert (extractions().size()); diff --git a/Data/include/Poco/Data/SessionFactory.h b/Data/include/Poco/Data/SessionFactory.h index 5b2889475..44dd545c4 100644 --- a/Data/include/Poco/Data/SessionFactory.h +++ b/Data/include/Poco/Data/SessionFactory.h @@ -1,7 +1,7 @@ // // SessionFactory.h // -// $Id: //poco/Main/Data/include/Poco/Data/SessionFactory.h#5 $ +// $Id: //poco/Main/Data/include/Poco/Data/SessionFactory.h#7 $ // // Library: Data // Package: DataCore @@ -63,7 +63,7 @@ class Data_API SessionFactory /// /// A concrete example to open an SQLite database stored in the file "dummy.db" would be /// - /// Session tmp(SessionFactory::instance().create(SQLite::Connector::KEY, "dummy.db")); + /// Session ses(SessionFactory::instance().create(SQLite::Connector::KEY, "dummy.db")); /// /// An even simpler way to create a session is to use the two argument constructor of Session, which /// automatically invokes the SessionFactory: @@ -85,7 +85,7 @@ public: Session create(const std::string& key, const std::string& connectionString); /// Creates a Session for the given key with the connectionString. Throws an Poco:Data::UnknownDataBaseException - /// if no instantiator is registered for that key. + /// if no Connector is registered for that key. private: SessionFactory(); diff --git a/Data/include/Poco/Data/Statement.h b/Data/include/Poco/Data/Statement.h index 355040368..d79cce296 100644 --- a/Data/include/Poco/Data/Statement.h +++ b/Data/include/Poco/Data/Statement.h @@ -1,7 +1,7 @@ // // Statement.h // -// $Id: //poco/Main/Data/include/Poco/Data/Statement.h#16 $ +// $Id: //poco/Main/Data/include/Poco/Data/Statement.h#17 $ // // Library: Data // Package: DataCore @@ -67,7 +67,7 @@ public: Statement(StatementImpl* pImpl); /// Creates the Statement. - Statement(Session& session); + explicit Statement(Session& session); /// Creates the Statement for the given Session. /// /// The following: @@ -131,6 +131,9 @@ public: /// Returns if the statement was completely executed or if a previously set limit stopped it /// and there is more work to do. When no limit is set, it will always - after calling execute() - return true. + Statement& reset(Session& session); + /// Resets the Statement so that it can be filled with a new SQL command. + protected: const AbstractExtractionVec& extractions() const; /// Returns the extractions vector. @@ -138,7 +141,7 @@ protected: const MetaColumn& metaColumn(std::size_t pos) const; /// Returns the type for the column at specified position. - inline const MetaColumn& metaColumn(const std::string& name) const; + const MetaColumn& metaColumn(const std::string& name) const; /// Returns the type for the column with specified name. private: @@ -211,6 +214,7 @@ inline const MetaColumn& Statement::metaColumn(std::size_t pos) const return _ptr->metaColumn(static_cast(pos)); } + inline const MetaColumn& Statement::metaColumn(const std::string& name) const { return _ptr->metaColumn(name); diff --git a/Data/include/Poco/Data/StatementImpl.h b/Data/include/Poco/Data/StatementImpl.h index 16eaa3cef..95c3075fe 100644 --- a/Data/include/Poco/Data/StatementImpl.h +++ b/Data/include/Poco/Data/StatementImpl.h @@ -216,8 +216,6 @@ private: // // inlines // - - inline void StatementImpl::addBinding(AbstractBinding* info) { _bindings.push_back(info); diff --git a/Data/samples/Makefile b/Data/samples/Makefile index 70541c870..6893d4a04 100644 --- a/Data/samples/Makefile +++ b/Data/samples/Makefile @@ -1,7 +1,7 @@ # # Makefile # -# $Id: //poco/Main/Data/samples/Makefile#1 $ +# $Id: //poco/Main/Data/samples/Makefile#2 $ # # Makefile for Poco Data Samples # @@ -12,3 +12,4 @@ projects: $(MAKE) -C Binding $(MAKECMDGOALS) $(MAKE) -C TypeHandler $(MAKECMDGOALS) $(MAKE) -C RecordSet $(MAKECMDGOALS) + $(MAKE) -C Tuple $(MAKECMDGOALS) diff --git a/Data/samples/RecordSet/src/RecordSet.cpp b/Data/samples/RecordSet/src/RecordSet.cpp index 4ea25bdd8..48ee1e420 100644 --- a/Data/samples/RecordSet/src/RecordSet.cpp +++ b/Data/samples/RecordSet/src/RecordSet.cpp @@ -1,7 +1,7 @@ // // RecordSet.cpp // -// $Id: //poco/Main/Data/samples/RecordSet/src/RecordSet.cpp#1 $ +// $Id: //poco/Main/Data/samples/RecordSet/src/RecordSet.cpp#2 $ // // This sample demonstrates the Data library. // @@ -59,13 +59,19 @@ int main(int argc, char** argv) select << "SELECT * FROM Person"; select.execute(); - // create a RecordSet and iterate over it + // create a RecordSet RecordSet rs(select); std::size_t cols = rs.columnCount(); + // print all column names + for (std::size_t col = 0; col < cols; ++col) + { + std::cout << rs.columnName(col) << std::endl; + } + // iterate over all rows and columns bool more = rs.moveFirst(); while (more) { - for (std::size_t col = 1; col <= cols; ++col) + for (std::size_t col = 0; col < cols; ++col) { std::cout << rs[col].convert() << " "; } diff --git a/Data/samples/Tuple/Makefile b/Data/samples/Tuple/Makefile index 77fcd55a8..567a7e1cc 100644 --- a/Data/samples/Tuple/Makefile +++ b/Data/samples/Tuple/Makefile @@ -1,14 +1,14 @@ # # Makefile # -# $Id: //poco/Main/Data/samples/Tuple/Makefile#1 $ +# $Id: //poco/Main/Data/samples/Tuple/Makefile#2 $ # # Makefile for Poco Data Tuple sample # include $(POCO_BASE)/build/rules/global -objects = Binding +objects = Tuple target = Tuple target_version = 1 diff --git a/Data/samples/Tuple/Tuple_vs71.vcproj b/Data/samples/Tuple/Tuple_vs71.vcproj index 90ae76549..d7e8740c3 100644 --- a/Data/samples/Tuple/Tuple_vs71.vcproj +++ b/Data/samples/Tuple/Tuple_vs71.vcproj @@ -2,8 +2,8 @@ + RelativePath=".\src\Tuple.cpp"> diff --git a/Data/samples/Tuple/Tuple_vs80.vcproj b/Data/samples/Tuple/Tuple_vs80.vcproj index 27ff97e43..e2c4659b7 100644 --- a/Data/samples/Tuple/Tuple_vs80.vcproj +++ b/Data/samples/Tuple/Tuple_vs80.vcproj @@ -3,7 +3,7 @@ ProjectType="Visual C++" Version="8.00" Name="Tuple" - ProjectGUID="{79D784CB-663C-444E-BCB2-1A1166D19DFB}" + ProjectGUID="{08C81227-3322-4DBD-A83F-55CCC933A5F7}" Keyword="Win32Proj" > diff --git a/Data/samples/samples_vs71.sln b/Data/samples/samples_vs71.sln index 35dfdc8da..9ccaad3c7 100644 --- a/Data/samples/samples_vs71.sln +++ b/Data/samples/samples_vs71.sln @@ -11,6 +11,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RecordSet", "RecordSet\Reco ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Tuple", "Tuple\Tuple_vs71.vcproj", "{08C81227-3322-4DBD-A83F-55CCC933A5F7}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject Global GlobalSection(SolutionConfiguration) = preSolution debug_shared = debug_shared @@ -29,6 +33,10 @@ Global {56F66D36-F11E-4AA1-AD37-4518A253059D}.debug_shared.Build.0 = debug_shared|Win32 {56F66D36-F11E-4AA1-AD37-4518A253059D}.release_shared.ActiveCfg = release_shared|Win32 {56F66D36-F11E-4AA1-AD37-4518A253059D}.release_shared.Build.0 = release_shared|Win32 + {08C81227-3322-4DBD-A83F-55CCC933A5F7}.debug_shared.ActiveCfg = debug_shared|Win32 + {08C81227-3322-4DBD-A83F-55CCC933A5F7}.debug_shared.Build.0 = debug_shared|Win32 + {08C81227-3322-4DBD-A83F-55CCC933A5F7}.release_shared.ActiveCfg = release_shared|Win32 + {08C81227-3322-4DBD-A83F-55CCC933A5F7}.release_shared.Build.0 = release_shared|Win32 EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection diff --git a/Data/src/RecordSet.cpp b/Data/src/RecordSet.cpp index 4bbd444df..265c143ee 100644 --- a/Data/src/RecordSet.cpp +++ b/Data/src/RecordSet.cpp @@ -58,18 +58,18 @@ DynamicAny RecordSet::value(std::size_t col, std::size_t row) const switch (columnType(col)) { case MetaColumn::FDT_BOOL: - case MetaColumn::FDT_INT8: return value(col, row); break; - case MetaColumn::FDT_UINT8: return value(col, row); break; - case MetaColumn::FDT_INT16: return value(col, row); break; - case MetaColumn::FDT_UINT16: return value(col, row); break; - case MetaColumn::FDT_INT32: return value(col, row); break; - case MetaColumn::FDT_UINT32: return value(col, row); break; - case MetaColumn::FDT_INT64: return value(col, row); break; - case MetaColumn::FDT_UINT64: return value(col, row); break; - case MetaColumn::FDT_FLOAT: return value(col, row); break; - case MetaColumn::FDT_DOUBLE: return value(col, row); break; - case MetaColumn::FDT_STRING: return value(col, row); break; - case MetaColumn::FDT_BLOB: return value(col, row); break; + case MetaColumn::FDT_INT8: return value(col, row); + case MetaColumn::FDT_UINT8: return value(col, row); + case MetaColumn::FDT_INT16: return value(col, row); + case MetaColumn::FDT_UINT16: return value(col, row); + case MetaColumn::FDT_INT32: return value(col, row); + case MetaColumn::FDT_UINT32: return value(col, row); + case MetaColumn::FDT_INT64: return value(col, row); + case MetaColumn::FDT_UINT64: return value(col, row); + case MetaColumn::FDT_FLOAT: return value(col, row); + case MetaColumn::FDT_DOUBLE: return value(col, row); + case MetaColumn::FDT_STRING: return value(col, row); + case MetaColumn::FDT_BLOB: return value(col, row); default: throw Poco::InvalidArgumentException("Data type not supported."); } @@ -120,7 +120,7 @@ bool RecordSet::moveNext() bool RecordSet::movePrevious() { - if (-1 == _currentRow) return false; + if (0 == _currentRow) return false; --_currentRow; return true; } @@ -137,6 +137,4 @@ bool RecordSet::moveLast() } - - } } // namespace Poco::Data diff --git a/Data/src/Statement.cpp b/Data/src/Statement.cpp index 817b41a9d..db01338ef 100644 --- a/Data/src/Statement.cpp +++ b/Data/src/Statement.cpp @@ -58,8 +58,7 @@ Statement::Statement(StatementImpl* pImpl): Statement::Statement(Session& session): _executed(false) { - Statement stmt(session.createStatementImpl()); - swap(stmt); + reset(session); } @@ -107,6 +106,14 @@ bool Statement::done() } +Statement& Statement::reset(Session& session) +{ + Statement stmt(session.createStatementImpl()); + swap(stmt); + return *this; +} + + void now(Statement& statement) { statement.execute(); diff --git a/Data/src/StatementImpl.cpp b/Data/src/StatementImpl.cpp index 63b544e72..1ada4af93 100644 --- a/Data/src/StatementImpl.cpp +++ b/Data/src/StatementImpl.cpp @@ -1,7 +1,7 @@ // // StatementImpl.cpp // -// $Id: //poco/Main/Data/src/StatementImpl.cpp#18 $ +// $Id: //poco/Main/Data/src/StatementImpl.cpp#19 $ // // Library: Data // Package: DataCore diff --git a/Data/testsuite/src/DataTest.cpp b/Data/testsuite/src/DataTest.cpp index 3ac9fa369..dc4476ead 100644 --- a/Data/testsuite/src/DataTest.cpp +++ b/Data/testsuite/src/DataTest.cpp @@ -1,7 +1,7 @@ // // DataTest.cpp // -// $Id: //poco/Main/Data/testsuite/src/DataTest.cpp#9 $ +// $Id: //poco/Main/Data/testsuite/src/DataTest.cpp#11 $ // // Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // and Contributors. @@ -43,9 +43,12 @@ #include "Poco/BinaryWriter.h" #include "Poco/Types.h" #include "Poco/Exception.h" +#include + using namespace Poco::Data; + using Poco::BinaryReader; using Poco::BinaryWriter; using Poco::UInt32; @@ -166,7 +169,7 @@ void DataTest::testBLOB() BLOB blobNumStr(strDigit.c_str(), strDigit.size()); assert (blobNumStr.size() == strDigit.size()); - assert (0 == strncmp(strDigit.c_str(), blobNumStr.rawContent(), blobNumStr.size())); + assert (0 == std::strncmp(strDigit.c_str(), blobNumStr.rawContent(), blobNumStr.size())); assert (*blobNumStr.begin() == '1'); assert (*(blobNumStr.end()-1) == '0'); BLOB blobNumVec(vecDigit); @@ -179,7 +182,7 @@ void DataTest::testBLOB() BLOB blobChrStr(strAlpha.c_str(), strAlpha.size()); BLOB blobChrVec(vecAlpha); assert (blobChrStr.size() == strAlpha.size()); - assert (0 == strncmp(strAlpha.c_str(), blobChrStr.rawContent(), blobChrStr.size())); + assert (0 == std::strncmp(strAlpha.c_str(), blobChrStr.rawContent(), blobChrStr.size())); assert (*blobChrStr.begin() == 'a'); assert (*(blobChrStr.end()-1) == 'z'); assert (blobChrStr == blobChrVec);