The asString() methods in RWDBInserter, RWDBUpdater, RWDBDeleter, RWDBSelector and RWDBCompoundSelector provide the SQL representation of self. Note that these methods do not actually access the database, so there is no performance hit.
Each class contains these asString() methods:
RWCString asString() const; RWCString asString( bool verbose ) const; |
They return the SQL statement generated by the DB Interface Module in either of the following formats:
As the actual SQL statement sent to the database for execution, containing either placeholders or bound data
As a statement produced by replacing the placeholders in the SQL with the bound data values
The first method RWCString asString() returns a string that depends on the verboseAsString() setting of the related RWDBDatabase instance. See RWDBDatabase for more information.
The next method RWCString asString(bool verbose) returns a string that depends on verbose and is therefore independent of the verboseAsString() setting of the RWDBDatabase instance.
For more information on the asString() methods and their application, see RWDBInserter, RWDBUpdater, RWDBDeleter, RWDBSelector, and RWDBCompoundSelector in the SourcePro C++ API Reference Guide.
The following table and example illustrate the behavior of the asString() method given various settings.
The asString() method called | Setting of RWDBDatabase::verboseAsString() | Generated Output |
asString(false) | true or false | SQL as sent to the database |
asString(true) | true or false | Placeholders in the SQL replaced by bound values |
asString() | true | Placeholders in the SQL replaced by bound values |
asString() | false | SQL as sent to the database |
RWDBTable table = myDbase.table("TestTable"); RWDBInserter insert = table.inserter(); int aInt = 10; RWCString aString("Hello"); insert << aInt << aString; // 1 myDbase.verboseAsString(false); // 2 std::cout << "First Output : " << insert.asString(true) << std::endl; // 3 std::cout << "Second Output: " << insert.asString(false) << std::endl; // 4 std::cout << "Third Output : " << insert.asString() << std::endl; // 5 myDbase.verboseAsString(true); // 6 std::cout << "Fourth Output: " << insert.asString(true) << std::endl; // 7 std::cout << "Fifth Output : " << insert.asString(false) << std::endl; // 8 std::cout << "Sixth Output : " << insert.asString() << std::endl; // 9 |
Output
First Output : INSERT TestTable VALUES ( 10, 'Hello' ) Second Output: INSERT TestTable VALUES ( @c0, @c1 ) Third Output : INSERT TestTable VALUES ( @c0, @c1 ) Fourth Output: INSERT TestTable VALUES ( 10, 'Hello' ) Fifth Output : INSERT TestTable VALUES ( @c0, @c1 ) Sixth Output : INSERT TestTable VALUES ( 10, 'Hello' ) |
//1 | Adds an integer and an RWCString to the inserter. |
//2 | Sets the verboseAsString setting of the producing RWDBDatabase myDbase to false. |
//3 | The RWDBDatabase::verboseAsString setting is ignored, and any placeholders in the returned SQL are replaced with the data. |
//4 | The RWDBDatabase::verboseAsString setting is ignored, and the SQL returned is the same as that which would be sent to the database if the RWDBInserter object insert were executed. |
//5 | The verboseAsString() setting is used. Since the setting is false, the SQL returned is the same as that which would be sent to the database if the RWDBInserter object insert were executed. |
//6 | Sets the verboseAsString() setting of the producing RWDBDatabase, myDbase, to true. |
//7 | The RWDBDatabase::verboseAsString() setting is ignored, and any placeholders in the returned SQL are replaced with the data. |
//8 | The verboseAsString() setting is ignored, and the SQL returned is the same as that sent to the database when insert is executed. |
//9 | The verboseAsString() setting is used. Since the setting is true, any placeholders in the returned SQL will be replaced with the data. A similar enhancement in RWDBTracer allows traced SQL statements with the placeholders to be replaced by the bound data values. See RWDBTracer in the SourcePro C++ API Reference Guide for more information. |
Copyright © Rogue Wave Software, Inc. All Rights Reserved.
The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.