diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-05-28 10:17:01 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-05-28 10:17:01 +0900 |
commit | 5fffa30386502b5423e45c2ed5e6af756b11c7b4 (patch) | |
tree | fa17e10b048e8e13433b861cbe98cf895b2324c7 /doc/html/sql.html | |
parent | 04913ce7a46fd027856e83a96205fdc388742a19 (diff) | |
download | tqt3-5fffa30386502b5423e45c2ed5e6af756b11c7b4.tar.gz tqt3-5fffa30386502b5423e45c2ed5e6af756b11c7b4.zip |
Rename nt* sql related files to equivalent tq*
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'doc/html/sql.html')
-rw-r--r-- | doc/html/sql.html | 728 |
1 files changed, 364 insertions, 364 deletions
diff --git a/doc/html/sql.html b/doc/html/sql.html index 5fda741ff..e0b81f3d4 100644 --- a/doc/html/sql.html +++ b/doc/html/sql.html @@ -35,26 +35,26 @@ body { background: #ffffff; color: black; } <p> <p> <center><table cellpadding="4" cellspacing="2" border="0"> <tr bgcolor="#f0f0f0"> -<td valign="top"><a href="ntqsql.html">TQSql</a> -<td valign="top"><a href="ntqsqlcursor.html">TQSqlCursor</a> -<td valign="top"><a href="ntqsqldatabase.html">TQSqlDatabase</a> -<td valign="top"><a href="ntqsqldriver.html">TQSqlDriver</a> -<td valign="top"><a href="ntqsqldriverplugin.html">TQSqlDriverPlugin</a> +<td valign="top"><a href="tqsql.html">TQSql</a> +<td valign="top"><a href="tqsqlcursor.html">TQSqlCursor</a> +<td valign="top"><a href="tqsqldatabase.html">TQSqlDatabase</a> +<td valign="top"><a href="tqsqldriver.html">TQSqlDriver</a> +<td valign="top"><a href="tqsqldriverplugin.html">TQSqlDriverPlugin</a> <tr bgcolor="#d0d0d0"> -<td valign="top"><a href="ntqsqleditorfactory.html">TQSqlEditorFactory</a> -<td valign="top"><a href="ntqsqlerror.html">TQSqlError</a> -<td valign="top"><a href="ntqsqlfield.html">TQSqlField</a> -<td valign="top"><a href="qsqlfieldinfo.html">TQSqlFieldInfo</a> -<td valign="top"><a href="ntqsqlform.html">TQSqlForm</a> +<td valign="top"><a href="tqsqleditorfactory.html">TQSqlEditorFactory</a> +<td valign="top"><a href="tqsqlerror.html">TQSqlError</a> +<td valign="top"><a href="tqsqlfield.html">TQSqlField</a> +<td valign="top"><a href="tqsqlfieldinfo.html">TQSqlFieldInfo</a> +<td valign="top"><a href="tqsqlform.html">TQSqlForm</a> <tr bgcolor="#f0f0f0"> -<td valign="top"><a href="ntqsqlindex.html">TQSqlIndex</a> -<td valign="top"><a href="ntqsqlpropertymap.html">TQSqlPropertyMap</a> -<td valign="top"><a href="ntqsqlquery.html">TQSqlQuery</a> -<td valign="top"><a href="ntqsqlrecord.html">TQSqlRecord</a> -<td valign="top"><a href="qsqlrecordinfo.html">TQSqlRecordInfo</a> +<td valign="top"><a href="tqsqlindex.html">TQSqlIndex</a> +<td valign="top"><a href="tqsqlpropertymap.html">TQSqlPropertyMap</a> +<td valign="top"><a href="tqsqlquery.html">TQSqlQuery</a> +<td valign="top"><a href="tqsqlrecord.html">TQSqlRecord</a> +<td valign="top"><a href="tqsqlrecordinfo.html">TQSqlRecordInfo</a> <tr bgcolor="#d0d0d0"> -<td valign="top"><a href="ntqsqlresult.html">TQSqlResult</a> -<td valign="top"><a href="ntqsqlselectcursor.html">TQSqlSelectCursor</a> +<td valign="top"><a href="tqsqlresult.html">TQSqlResult</a> +<td valign="top"><a href="tqsqlselectcursor.html">TQSqlSelectCursor</a> <td valign="top" colspan="3" rowspan="1"> See also: <a href="sql-driver.html">Supported Drivers</a> </table></center> <p> <!-- toc --> @@ -144,7 +144,7 @@ your TQt applications. <p> <blockquote> This overview assumes that you have at least a basic knowledge of SQL. You should be able to understand simple <tt>SELECT</tt>, <tt>INSERT</tt>, <tt>UPDATE</tt> -and <tt>DELETE</tt> commands. Although the <a href="ntqsqlcursor.html">TQSqlCursor</a> class provides an +and <tt>DELETE</tt> commands. Although the <a href="tqsqlcursor.html">TQSqlCursor</a> class provides an interface to database browsing and editing that does not <em>require</em> a knowledge of SQL, a basic understanding of SQL is highly recommended. A standard text covering SQL databases is <em>An Introduction to Database Systems (7th ed.)</em> by C. J. Date, ISBN 0201385902. @@ -159,22 +159,22 @@ handle foreign key lookups. <p> <a href="#Architecture">SQL Module Architecture</a>. This describes how the classes fit together. <p> <a href="#Connecting_to_Databases">Connecting to Databases</a>. -This section explains how to set up database connections using the <a href="ntqsqldatabase.html">TQSqlDatabase</a> class. +This section explains how to set up database connections using the <a href="tqsqldatabase.html">TQSqlDatabase</a> class. <p> <a href="#Executing_SQL_commands">Executing SQL Commands</a>. This section demonstrates how to issue the standard data manipulation commands, <tt>SELECT</tt>, <tt>INSERT</tt>, <tt>UPDATE</tt> and <tt>DELETE</tt> on tables in the database (although any valid SQL statement can be sent to the -database). The focus is purely on database interaction using <a href="ntqsqlquery.html">TQSqlQuery</a>. +database). The focus is purely on database interaction using <a href="tqsqlquery.html">TQSqlQuery</a>. <p> <a href="#Using_QSqlCursor">Using Cursors</a>. This section explains -how to use the <a href="ntqsqlcursor.html">TQSqlCursor</a> class which provides a simpler API than the -raw SQL used with <a href="ntqsqlquery.html">TQSqlQuery</a>. +how to use the <a href="tqsqlcursor.html">TQSqlCursor</a> class which provides a simpler API than the +raw SQL used with <a href="tqsqlquery.html">TQSqlQuery</a>. <p> <a href="#Data-Aware_Widgets">Data-Aware Widgets</a>. This section shows how to programmatically link your database to the user interface. In -this section we introduce the <a href="ntqdatatable.html">TQDataTable</a>, <a href="ntqsqlform.html">TQSqlForm</a>, <a href="ntqsqlpropertymap.html">TQSqlPropertyMap</a> and <a href="ntqsqleditorfactory.html">TQSqlEditorFactory</a> classes and demonstrate how to +this section we introduce the <a href="tqdatatable.html">TQDataTable</a>, <a href="tqsqlform.html">TQSqlForm</a>, <a href="tqsqlpropertymap.html">TQSqlPropertyMap</a> and <a href="tqsqleditorfactory.html">TQSqlEditorFactory</a> classes and demonstrate how to use custom data-aware widgets. <a href="designer-manual.html">TQt Designer</a> provides an easy visual way of achieving the same thing. See the <a href="designer-manual.html">TQt Designer</a> manual, -<a href="ntqdatabrowser.html">TQDataBrowser</a> and <a href="ntqdataview.html">TQDataView</a> for more information. +<a href="tqdatabrowser.html">TQDataBrowser</a> and <a href="tqdataview.html">TQDataView</a> for more information. <p> <a href="#Subclassing_QSqlCursor">Subclassing TQSqlCursor</a>. This section gives examples of subclassing TQSqlCursor. Subclassing can be used to provide default and calculated values for fields (such as @@ -188,20 +188,20 @@ e.g. showing names rather than ids of foreign keys. <a name="2"></a><p> The SQL classes are divided into three layers: <p> <em>User Interface Layer.</em> These classes provide data-aware widgets that can be connected to tables or views in the database (by using a -<a href="ntqsqlcursor.html">TQSqlCursor</a> as a data source). End users can interact directly with +<a href="tqsqlcursor.html">TQSqlCursor</a> as a data source). End users can interact directly with these widgets to browse or edit data. <a href="designer-manual.html">TQt Designer</a> is fully integrated with the SQL classes and can be used to create data-aware forms. The data-aware widgets can also be programmed directly with your own C++ code. The classes that support -this layer include <a href="ntqsqleditorfactory.html">TQSqlEditorFactory</a>, <a href="ntqsqlform.html">TQSqlForm</a>, <a href="ntqsqlpropertymap.html">TQSqlPropertyMap</a>, <a href="ntqdatatable.html">TQDataTable</a>, <a href="ntqdatabrowser.html">TQDataBrowser</a> and <a href="ntqdataview.html">TQDataView</a>. +this layer include <a href="tqsqleditorfactory.html">TQSqlEditorFactory</a>, <a href="tqsqlform.html">TQSqlForm</a>, <a href="tqsqlpropertymap.html">TQSqlPropertyMap</a>, <a href="tqdatatable.html">TQDataTable</a>, <a href="tqdatabrowser.html">TQDataBrowser</a> and <a href="tqdataview.html">TQDataView</a>. <p> <em>SQL API Layer.</em> These classes provide access to databases. -Connections are made using the <a href="ntqsqldatabase.html">TQSqlDatabase</a> class. Database -interaction is achieved either by using the <a href="ntqsqlquery.html">TQSqlQuery</a> class and -executing SQL commands directly or by using the higher level <a href="ntqsqlcursor.html">TQSqlCursor</a> class which composes SQL commands automatically. In -addition to <a href="ntqsqldatabase.html">TQSqlDatabase</a>, <a href="ntqsqlcursor.html">TQSqlCursor</a> and <a href="ntqsqlquery.html">TQSqlQuery</a>, the SQL -API layer is supported by <a href="ntqsqlerror.html">TQSqlError</a>, <a href="ntqsqlfield.html">TQSqlField</a>, <a href="qsqlfieldinfo.html">TQSqlFieldInfo</a>, -<a href="ntqsqlindex.html">TQSqlIndex</a>, <a href="ntqsqlrecord.html">TQSqlRecord</a> and <a href="qsqlrecordinfo.html">TQSqlRecordInfo</a>. -<p> <em>Driver Layer.</em> This comprises three classes, <a href="ntqsqlresult.html">TQSqlResult</a>, <a href="ntqsqldriver.html">TQSqlDriver</a> and TQSqlDriverFactoryInterface. This layer provides the +Connections are made using the <a href="tqsqldatabase.html">TQSqlDatabase</a> class. Database +interaction is achieved either by using the <a href="tqsqlquery.html">TQSqlQuery</a> class and +executing SQL commands directly or by using the higher level <a href="tqsqlcursor.html">TQSqlCursor</a> class which composes SQL commands automatically. In +addition to <a href="tqsqldatabase.html">TQSqlDatabase</a>, <a href="tqsqlcursor.html">TQSqlCursor</a> and <a href="tqsqlquery.html">TQSqlQuery</a>, the SQL +API layer is supported by <a href="tqsqlerror.html">TQSqlError</a>, <a href="tqsqlfield.html">TQSqlField</a>, <a href="tqsqlfieldinfo.html">TQSqlFieldInfo</a>, +<a href="tqsqlindex.html">TQSqlIndex</a>, <a href="tqsqlrecord.html">TQSqlRecord</a> and <a href="tqsqlrecordinfo.html">TQSqlRecordInfo</a>. +<p> <em>Driver Layer.</em> This comprises three classes, <a href="tqsqlresult.html">TQSqlResult</a>, <a href="tqsqldriver.html">TQSqlDriver</a> and TQSqlDriverFactoryInterface. This layer provides the low level bridge between the database and the SQL classes. This layer is <a href="sql-driver.html">documented separately</a> since it is only relevant to driver writers, and is rarely used in standard @@ -214,17 +214,17 @@ the <a href="plugins-howto.html">Plugins</a>. <p> The <a href="sql-driver.html">SQL driver documentation</a> describes how to build plugins for specific database management systems. <p> Once a plugin is built, TQt will automatically load it, and the driver -will be available for use by <a href="ntqsqldatabase.html">TQSqlDatabase</a> (see <a href="ntqsqldatabase.html#drivers">TQSqlDatabase::drivers</a>() +will be available for use by <a href="tqsqldatabase.html">TQSqlDatabase</a> (see <a href="tqsqldatabase.html#drivers">TQSqlDatabase::drivers</a>() for more information). <p> <a name="Connecting_to_Databases"></a> <h2> Connecting to Databases </h2> <a name="4"></a><p> At least one database connection must be created and opened before the -<a href="ntqsqlquery.html">TQSqlQuery</a> or <a href="ntqsqlcursor.html">TQSqlCursor</a> classes can be used. -<p> If the application only needs a single database connection, the <a href="ntqsqldatabase.html">TQSqlDatabase</a> class can create a connection which is used by default +<a href="tqsqlquery.html">TQSqlQuery</a> or <a href="tqsqlcursor.html">TQSqlCursor</a> classes can be used. +<p> If the application only needs a single database connection, the <a href="tqsqldatabase.html">TQSqlDatabase</a> class can create a connection which is used by default for all SQL operations. If multiple database connections are required these can easily be set up. -<p> <a href="ntqsqldatabase.html">TQSqlDatabase</a> requires the <a href="qsqldatabase-h.html">ntqsqldatabase.h</a> header file. +<p> <a href="tqsqldatabase.html">TQSqlDatabase</a> requires the <a href="tqsqldatabase-h.html">tqsqldatabase.h</a> header file. <p> <a name="Connecting_to_a_Single_Database"></a> <h2> Connecting to a Single Database </h2> @@ -234,20 +234,20 @@ connection. <p> <pre> #include <<a href="qapplication-h.html">ntqapplication.h</a>> - #include <<a href="qsqldatabase-h.html">ntqsqldatabase.h</a>> + #include <<a href="tqsqldatabase-h.html">tqsqldatabase.h</a>> #include "../connection.h" int main( int argc, char *argv[] ) { <a href="ntqapplication.html">TQApplication</a> app( argc, argv, FALSE ); - <a name="x2141"></a> <a href="ntqsqldatabase.html">TQSqlDatabase</a> *defaultDB = TQSqlDatabase::<a href="ntqsqldatabase.html#addDatabase">addDatabase</a>( DB_SALES_DRIVER ); - <a name="x2143"></a> defaultDB-><a href="ntqsqldatabase.html#setDatabaseName">setDatabaseName</a>( DB_SALES_DBNAME ); - <a name="x2146"></a> defaultDB-><a href="ntqsqldatabase.html#setUserName">setUserName</a>( DB_SALES_USER ); - <a name="x2145"></a> defaultDB-><a href="ntqsqldatabase.html#setPassword">setPassword</a>( DB_SALES_PASSWD ); - <a name="x2144"></a> defaultDB-><a href="ntqsqldatabase.html#setHostName">setHostName</a>( DB_SALES_HOST ); + <a name="x2141"></a> <a href="tqsqldatabase.html">TQSqlDatabase</a> *defaultDB = TQSqlDatabase::<a href="tqsqldatabase.html#addDatabase">addDatabase</a>( DB_SALES_DRIVER ); + <a name="x2143"></a> defaultDB-><a href="tqsqldatabase.html#setDatabaseName">setDatabaseName</a>( DB_SALES_DBNAME ); + <a name="x2146"></a> defaultDB-><a href="tqsqldatabase.html#setUserName">setUserName</a>( DB_SALES_USER ); + <a name="x2145"></a> defaultDB-><a href="tqsqldatabase.html#setPassword">setPassword</a>( DB_SALES_PASSWD ); + <a name="x2144"></a> defaultDB-><a href="tqsqldatabase.html#setHostName">setHostName</a>( DB_SALES_HOST ); - <a name="x2142"></a> if ( defaultDB-><a href="ntqsqldatabase.html#open">open</a>() ) { + <a name="x2142"></a> if ( defaultDB-><a href="tqsqldatabase.html#open">open</a>() ) { // Database successfully opened; we can now issue SQL commands. } @@ -255,7 +255,7 @@ connection. } </pre><blockquote><p align="center"><em> From <a href="sql-overview-connect1-main-cpp.html">sql/overview/connect1/main.cpp</a> </em></p> -</blockquote><p> First we activate the driver by calling <a href="ntqsqldatabase.html#addDatabase">TQSqlDatabase::addDatabase</a>(), +</blockquote><p> First we activate the driver by calling <a href="tqsqldatabase.html#addDatabase">TQSqlDatabase::addDatabase</a>(), passing the name of the driver we wish to use for this connection. At the time of writing the available drivers are: <a href="sql-driver.html#TQODBC3">TQODBC3</a> (Open Database Connectivity, includes Microsoft SQL Server support), <a href="sql-driver.html#TQOCI8">TQOCI8</a> (Oracle 8 and 9), @@ -273,12 +273,12 @@ to setDatbaseName(). When connecting to ODBC data sources the Data Source Name (DSN) should be used in the setDatabaseName() call. <p> Third we call open() to open the database and give us access to the data. If this call fails it will return FALSE; error information can -be obtained from <a href="ntqsqldatabase.html#lastError">TQSqlDatabase::lastError</a>(). +be obtained from <a href="tqsqldatabase.html#lastError">TQSqlDatabase::lastError</a>(). <p> <a name="Connecting_to_Multiple_Databases"></a> <h3> Connecting to Multiple Databases </h3> <a name="5-1"></a><p> Connecting to multiple databases is achieved using the two argument form -of <a href="ntqsqldatabase.html#addDatabase">TQSqlDatabase::addDatabase</a>() where the second argument is a unique +of <a href="tqsqldatabase.html#addDatabase">TQSqlDatabase::addDatabase</a>() where the second argument is a unique identifier distinguishing the connection. <p> In the example below we have moved the connections into their own function, <tt>createConnections()</tt>, and added some basic error handling. @@ -302,45 +302,45 @@ bool createConnections(); function in <tt>connection.h</tt>. <p> -<pre> #include <<a href="qsqldatabase-h.html">ntqsqldatabase.h</a>> +<pre> #include <<a href="tqsqldatabase-h.html">tqsqldatabase.h</a>> #include "connection.h" bool createConnections() { - <a name="x2147"></a> <a href="ntqsqldatabase.html">TQSqlDatabase</a> *defaultDB = TQSqlDatabase::<a href="ntqsqldatabase.html#addDatabase">addDatabase</a>( DB_SALES_DRIVER ); - <a name="x2150"></a> defaultDB-><a href="ntqsqldatabase.html#setDatabaseName">setDatabaseName</a>( DB_SALES_DBNAME ); - <a name="x2153"></a> defaultDB-><a href="ntqsqldatabase.html#setUserName">setUserName</a>( DB_SALES_USER ); - <a name="x2152"></a> defaultDB-><a href="ntqsqldatabase.html#setPassword">setPassword</a>( DB_SALES_PASSWD ); - <a name="x2151"></a> defaultDB-><a href="ntqsqldatabase.html#setHostName">setHostName</a>( DB_SALES_HOST ); - <a name="x2149"></a> if ( ! defaultDB-><a href="ntqsqldatabase.html#open">open</a>() ) { - <a name="x2148"></a> <a href="ntqapplication.html#qWarning">tqWarning</a>( "Failed to open sales database: " + defaultDB-><a href="ntqsqldatabase.html#lastError">lastError</a>().text() ); + <a name="x2147"></a> <a href="tqsqldatabase.html">TQSqlDatabase</a> *defaultDB = TQSqlDatabase::<a href="tqsqldatabase.html#addDatabase">addDatabase</a>( DB_SALES_DRIVER ); + <a name="x2150"></a> defaultDB-><a href="tqsqldatabase.html#setDatabaseName">setDatabaseName</a>( DB_SALES_DBNAME ); + <a name="x2153"></a> defaultDB-><a href="tqsqldatabase.html#setUserName">setUserName</a>( DB_SALES_USER ); + <a name="x2152"></a> defaultDB-><a href="tqsqldatabase.html#setPassword">setPassword</a>( DB_SALES_PASSWD ); + <a name="x2151"></a> defaultDB-><a href="tqsqldatabase.html#setHostName">setHostName</a>( DB_SALES_HOST ); + <a name="x2149"></a> if ( ! defaultDB-><a href="tqsqldatabase.html#open">open</a>() ) { + <a name="x2148"></a> <a href="ntqapplication.html#qWarning">tqWarning</a>( "Failed to open sales database: " + defaultDB-><a href="tqsqldatabase.html#lastError">lastError</a>().text() ); return FALSE; } - <a href="ntqsqldatabase.html">TQSqlDatabase</a> *oracle = TQSqlDatabase::<a href="ntqsqldatabase.html#addDatabase">addDatabase</a>( DB_ORDERS_DRIVER, "ORACLE" ); - oracle-><a href="ntqsqldatabase.html#setDatabaseName">setDatabaseName</a>( DB_ORDERS_DBNAME ); - oracle-><a href="ntqsqldatabase.html#setUserName">setUserName</a>( DB_ORDERS_USER ); - oracle-><a href="ntqsqldatabase.html#setPassword">setPassword</a>( DB_ORDERS_PASSWD ); - oracle-><a href="ntqsqldatabase.html#setHostName">setHostName</a>( DB_ORDERS_HOST ); - if ( ! oracle-><a href="ntqsqldatabase.html#open">open</a>() ) { - <a href="ntqapplication.html#qWarning">tqWarning</a>( "Failed to open orders database: " + oracle-><a href="ntqsqldatabase.html#lastError">lastError</a>().text() ); + <a href="tqsqldatabase.html">TQSqlDatabase</a> *oracle = TQSqlDatabase::<a href="tqsqldatabase.html#addDatabase">addDatabase</a>( DB_ORDERS_DRIVER, "ORACLE" ); + oracle-><a href="tqsqldatabase.html#setDatabaseName">setDatabaseName</a>( DB_ORDERS_DBNAME ); + oracle-><a href="tqsqldatabase.html#setUserName">setUserName</a>( DB_ORDERS_USER ); + oracle-><a href="tqsqldatabase.html#setPassword">setPassword</a>( DB_ORDERS_PASSWD ); + oracle-><a href="tqsqldatabase.html#setHostName">setHostName</a>( DB_ORDERS_HOST ); + if ( ! oracle-><a href="tqsqldatabase.html#open">open</a>() ) { + <a href="ntqapplication.html#qWarning">tqWarning</a>( "Failed to open orders database: " + oracle-><a href="tqsqldatabase.html#lastError">lastError</a>().text() ); return FALSE; } - <a href="ntqsqlquery.html">TQSqlQuery</a> q(TQString::null, defaultDB); - <a name="x2154"></a> q.<a href="ntqsqlquery.html#exec">exec</a>("create table people (id integer primary key, name char(40))"); - q.<a href="ntqsqlquery.html#exec">exec</a>("create table staff (id integer primary key, forename char(40), " + <a href="tqsqlquery.html">TQSqlQuery</a> q(TQString::null, defaultDB); + <a name="x2154"></a> q.<a href="tqsqlquery.html#exec">exec</a>("create table people (id integer primary key, name char(40))"); + q.<a href="tqsqlquery.html#exec">exec</a>("create table staff (id integer primary key, forename char(40), " "surname char(40), salary float, statusid integer)"); - q.<a href="ntqsqlquery.html#exec">exec</a>("create table status (id integer primary key, name char(30))"); - q.<a href="ntqsqlquery.html#exec">exec</a>("create table creditors (id integer primary key, forename char(40), " + q.<a href="tqsqlquery.html#exec">exec</a>("create table status (id integer primary key, name char(30))"); + q.<a href="tqsqlquery.html#exec">exec</a>("create table creditors (id integer primary key, forename char(40), " "surname char(40), city char(30))"); - q.<a href="ntqsqlquery.html#exec">exec</a>("create table prices (id integer primary key, name char(40), price float)"); - q.<a href="ntqsqlquery.html#exec">exec</a>("create table invoiceitem (id integer primary key, " + q.<a href="tqsqlquery.html#exec">exec</a>("create table prices (id integer primary key, name char(40), price float)"); + q.<a href="tqsqlquery.html#exec">exec</a>("create table invoiceitem (id integer primary key, " "pricesid integer, quantity integer, paiddate date)"); - <a href="ntqsqlquery.html">TQSqlQuery</a> q2(TQString::null, oracle); - q2.<a href="ntqsqlquery.html#exec">exec</a>("create table people (id integer primary key, name char(40))"); + <a href="tqsqlquery.html">TQSqlQuery</a> q2(TQString::null, oracle); + q2.<a href="tqsqlquery.html#exec">exec</a>("create table people (id integer primary key, name char(40))"); return TRUE; } @@ -351,7 +351,7 @@ function in <tt>connection.h</tt>. <pre> #include <<a href="qapplication-h.html">ntqapplication.h</a>> - #include <<a href="qsqldatabase-h.html">ntqsqldatabase.h</a>> + #include <<a href="tqsqldatabase-h.html">tqsqldatabase.h</a>> #include "../connection.h" int main( int argc, char *argv[] ) @@ -360,7 +360,7 @@ function in <tt>connection.h</tt>. if ( createConnections() ) { // Databases successfully opened; get pointers to them: - <a name="x2155"></a> <a href="ntqsqldatabase.html">TQSqlDatabase</a> *oracledb = TQSqlDatabase::<a href="ntqsqldatabase.html#database">database</a>( "ORACLE" ); + <a name="x2155"></a> <a href="tqsqldatabase.html">TQSqlDatabase</a> *oracledb = TQSqlDatabase::<a href="tqsqldatabase.html#database">database</a>( "ORACLE" ); // Now we can now issue SQL commands to the oracle connection // or to the default connection } @@ -369,7 +369,7 @@ function in <tt>connection.h</tt>. } </pre><blockquote><p align="center"><em> From <a href="sql-overview-create_connections-main-cpp.html">sql/overview/create_connections/main.cpp</a> </em></p> -</blockquote><p> The static function <a href="ntqsqldatabase.html#database">TQSqlDatabase::database</a>() can be called from +</blockquote><p> The static function <a href="tqsqldatabase.html#database">TQSqlDatabase::database</a>() can be called from anywhere to provide a pointer to a database connection. If we call it without a parameter it will return the default connection. If called with the identifier we've used for a connection, e.g. "ORACLE", in the @@ -381,40 +381,40 @@ preview correctly in <a href="designer-manual.html">TQt Designer</a> will not run unless you implement your own database connections function. <p> Note that in the code above the ODBC connection was not named and is -therefore used as the default connection. <a href="ntqsqldatabase.html">TQSqlDatabase</a> maintains +therefore used as the default connection. <a href="tqsqldatabase.html">TQSqlDatabase</a> maintains ownership of the pointers returned by the addDatabase() static function. To remove a database from the list of maintained -connections, first close the database with <a href="ntqsqldatabase.html#close">TQSqlDatabase::close</a>(), and +connections, first close the database with <a href="tqsqldatabase.html#close">TQSqlDatabase::close</a>(), and then remove it using the static function -<a href="ntqsqldatabase.html#removeDatabase">TQSqlDatabase::removeDatabase</a>(). +<a href="tqsqldatabase.html#removeDatabase">TQSqlDatabase::removeDatabase</a>(). <p> <a name="Executing_SQL_commands"></a> -<h2> Executing SQL Commands Using <a href="ntqsqlquery.html">TQSqlQuery</a> +<h2> Executing SQL Commands Using <a href="tqsqlquery.html">TQSqlQuery</a> </h2> -<a name="6"></a><p> The <a href="ntqsqlquery.html">TQSqlQuery</a> class provides an interface for executing SQL commands. +<a name="6"></a><p> The <a href="tqsqlquery.html">TQSqlQuery</a> class provides an interface for executing SQL commands. It also has functions for navigating through the result sets of <tt>SELECT</tt> queries and for retrieving individual records and field values. -<p> The <a href="ntqsqlcursor.html">TQSqlCursor</a> class described in the next section inherits from <a href="ntqsqlquery.html">TQSqlQuery</a> and provides a higher level interface that composes SQL -commands for us. <a href="ntqsqlcursor.html">TQSqlCursor</a> is particularly easy to integrate with +<p> The <a href="tqsqlcursor.html">TQSqlCursor</a> class described in the next section inherits from <a href="tqsqlquery.html">TQSqlQuery</a> and provides a higher level interface that composes SQL +commands for us. <a href="tqsqlcursor.html">TQSqlCursor</a> is particularly easy to integrate with on-screen widgets. Programmers unfamiliar with SQL can safely skip this -section and use the <a href="ntqsqlcursor.html">TQSqlCursor</a> class covered in +section and use the <a href="tqsqlcursor.html">TQSqlCursor</a> class covered in <a href="#Using_QSqlCursor">"Using TQSqlCursor"</a>. <p> <a name="Transactions"></a> <h3> Transactions </h3> <a name="6-1"></a><p> If the underlying database engine supports transactions -<a href="ntqsqldriver.html#hasFeature">TQSqlDriver::hasFeature</a>( TQSqlDriver::Transactions ) will return TRUE. -You can use <a href="ntqsqldatabase.html#transaction">TQSqlDatabase::transaction</a>() to initiate a transaction, +<a href="tqsqldriver.html#hasFeature">TQSqlDriver::hasFeature</a>( TQSqlDriver::Transactions ) will return TRUE. +You can use <a href="tqsqldatabase.html#transaction">TQSqlDatabase::transaction</a>() to initiate a transaction, followed by the SQL commands you want to execute within the context of -the transaction, and then either <a href="ntqsqldatabase.html#commit">TQSqlDatabase::commit</a>() or -<a href="ntqsqldatabase.html#rollback">TQSqlDatabase::rollback</a>(). +the transaction, and then either <a href="tqsqldatabase.html#commit">TQSqlDatabase::commit</a>() or +<a href="tqsqldatabase.html#rollback">TQSqlDatabase::rollback</a>(). <p> <a name="Basic_Browsing"></a> <h3> Basic Browsing </h3> <a name="6-2"></a><p> <pre> #include <<a href="qapplication-h.html">ntqapplication.h</a>> - #include <<a href="qsqldatabase-h.html">ntqsqldatabase.h</a>> - #include <<a href="qsqlquery-h.html">ntqsqlquery.h</a>> + #include <<a href="tqsqldatabase-h.html">tqsqldatabase.h</a>> + #include <<a href="tqsqlquery-h.html">tqsqlquery.h</a>> #include "../connection.h" int main( int argc, char *argv[] ) @@ -422,16 +422,16 @@ the transaction, and then either <a href="ntqsqldatabase.html#commit">TQSqlDatab <a href="ntqapplication.html">TQApplication</a> app( argc, argv, FALSE ); if ( createConnections() ) { - <a name="x2156"></a> <a href="ntqsqldatabase.html">TQSqlDatabase</a> *oracledb = TQSqlDatabase::<a href="ntqsqldatabase.html#database">database</a>( "ORACLE" ); + <a name="x2156"></a> <a href="tqsqldatabase.html">TQSqlDatabase</a> *oracledb = TQSqlDatabase::<a href="tqsqldatabase.html#database">database</a>( "ORACLE" ); // Copy data from the oracle database to the ODBC (default) // database - <a href="ntqsqlquery.html">TQSqlQuery</a> target; - <a href="ntqsqlquery.html">TQSqlQuery</a> query( "SELECT id, name FROM people", oracledb ); - <a name="x2158"></a> if ( query.<a href="ntqsqlquery.html#isActive">isActive</a>() ) { - <a name="x2159"></a> while ( query.<a href="ntqsqlquery.html#next">next</a>() ) { - <a name="x2157"></a> target.<a href="ntqsqlquery.html#exec">exec</a>( "INSERT INTO people ( id, name ) VALUES ( " + - <a name="x2160"></a> query.<a href="ntqsqlquery.html#value">value</a>(0).toString() + - ", '" + query.<a href="ntqsqlquery.html#value">value</a>(1).toString() + "' )" ); + <a href="tqsqlquery.html">TQSqlQuery</a> target; + <a href="tqsqlquery.html">TQSqlQuery</a> query( "SELECT id, name FROM people", oracledb ); + <a name="x2158"></a> if ( query.<a href="tqsqlquery.html#isActive">isActive</a>() ) { + <a name="x2159"></a> while ( query.<a href="tqsqlquery.html#next">next</a>() ) { + <a name="x2157"></a> target.<a href="tqsqlquery.html#exec">exec</a>( "INSERT INTO people ( id, name ) VALUES ( " + + <a name="x2160"></a> query.<a href="tqsqlquery.html#value">value</a>(0).toString() + + ", '" + query.<a href="tqsqlquery.html#value">value</a>(1).toString() + "' )" ); } } } @@ -441,7 +441,7 @@ the transaction, and then either <a href="ntqsqldatabase.html#commit">TQSqlDatab </pre><blockquote><p align="center"><em> From <a href="sql-overview-basicbrowsing-main-cpp.html">sql/overview/basicbrowsing/main.cpp</a> </em></p> </blockquote><p> In the example above we've added an additional header file, -<a href="qsqlquery-h.html">ntqsqlquery.h</a>. The first query we create, <tt>target</tt>, uses the default +<a href="tqsqlquery-h.html">tqsqlquery.h</a>. The first query we create, <tt>target</tt>, uses the default database and is initially empty. For the second query, <tt>q</tt>, we specify the "ORACLE" database that we want to retrieve records from. Both the database connections were set up in the createConnections() function we @@ -451,20 +451,20 @@ to see if the query executed successfully. The next() function is used to iterate through the query results. The value() function returns the contents of fields as TQVariants. The insertions are achieved by creating and executing queries against the default -database using the <tt>target</tt> <a href="ntqsqlquery.html">TQSqlQuery</a>. +database using the <tt>target</tt> <a href="tqsqlquery.html">TQSqlQuery</a>. <p> Note that this example and all the other examples in this document use the tables defined in the <a href="#Example_Tables">Example Tables</a> section. <p> <pre> int count = 0; - <a name="x2162"></a> if ( query.<a href="ntqsqlquery.html#isActive">isActive</a>() ) { - <a name="x2163"></a> while ( query.<a href="ntqsqlquery.html#next">next</a>() ) { - <a name="x2161"></a> target.<a href="ntqsqlquery.html#exec">exec</a>( "INSERT INTO people ( id, name ) VALUES ( " + - <a name="x2165"></a> query.<a href="ntqsqlquery.html#value">value</a>(0).toString() + - ", '" + query.<a href="ntqsqlquery.html#value">value</a>(1).toString() + "' )" ); - if ( target.<a href="ntqsqlquery.html#isActive">isActive</a>() ) - <a name="x2164"></a> count += target.<a href="ntqsqlquery.html#numRowsAffected">numRowsAffected</a>(); + <a name="x2162"></a> if ( query.<a href="tqsqlquery.html#isActive">isActive</a>() ) { + <a name="x2163"></a> while ( query.<a href="tqsqlquery.html#next">next</a>() ) { + <a name="x2161"></a> target.<a href="tqsqlquery.html#exec">exec</a>( "INSERT INTO people ( id, name ) VALUES ( " + + <a name="x2165"></a> query.<a href="tqsqlquery.html#value">value</a>(0).toString() + + ", '" + query.<a href="tqsqlquery.html#value">value</a>(1).toString() + "' )" ); + if ( target.<a href="tqsqlquery.html#isActive">isActive</a>() ) + <a name="x2164"></a> count += target.<a href="tqsqlquery.html#numRowsAffected">numRowsAffected</a>(); } } </pre><blockquote><p align="center"><em> From <a href="sql-overview-basicbrowsing2-main-cpp.html">sql/overview/basicbrowsing2/main.cpp</a> @@ -488,8 +488,8 @@ cannot be determined, e.g. if the query fails. *****************************************************************************/ #include <<a href="qapplication-h.html">ntqapplication.h</a>> - #include <<a href="qsqldatabase-h.html">ntqsqldatabase.h</a>> - #include <<a href="qsqlquery-h.html">ntqsqlquery.h</a>> + #include <<a href="tqsqldatabase-h.html">tqsqldatabase.h</a>> + #include <<a href="tqsqlquery-h.html">tqsqlquery.h</a>> #include "../connection.h" bool createConnections(); @@ -501,15 +501,15 @@ cannot be determined, e.g. if the query fails. int rows = 0; if ( createConnections() ) { - <a href="ntqsqlquery.html">TQSqlQuery</a> query( "INSERT INTO staff ( id, forename, surname, salary ) " + <a href="tqsqlquery.html">TQSqlQuery</a> query( "INSERT INTO staff ( id, forename, surname, salary ) " "VALUES ( 1155, 'Ginger', 'Davis', 50000 )" ); - <a name="x2168"></a><a name="x2167"></a> if ( query.<a href="ntqsqlquery.html#isActive">isActive</a>() ) rows += query.<a href="ntqsqlquery.html#numRowsAffected">numRowsAffected</a>() ; + <a name="x2168"></a><a name="x2167"></a> if ( query.<a href="tqsqlquery.html#isActive">isActive</a>() ) rows += query.<a href="tqsqlquery.html#numRowsAffected">numRowsAffected</a>() ; - <a name="x2166"></a> query.<a href="ntqsqlquery.html#exec">exec</a>( "UPDATE staff SET salary=60000 WHERE id=1155" ); - if ( query.<a href="ntqsqlquery.html#isActive">isActive</a>() ) rows += query.<a href="ntqsqlquery.html#numRowsAffected">numRowsAffected</a>() ; + <a name="x2166"></a> query.<a href="tqsqlquery.html#exec">exec</a>( "UPDATE staff SET salary=60000 WHERE id=1155" ); + if ( query.<a href="tqsqlquery.html#isActive">isActive</a>() ) rows += query.<a href="tqsqlquery.html#numRowsAffected">numRowsAffected</a>() ; - query.<a href="ntqsqlquery.html#exec">exec</a>( "DELETE FROM staff WHERE id=1155" ); - if ( query.<a href="ntqsqlquery.html#isActive">isActive</a>() ) rows += query.<a href="ntqsqlquery.html#numRowsAffected">numRowsAffected</a>() ; + query.<a href="tqsqlquery.html#exec">exec</a>( "DELETE FROM staff WHERE id=1155" ); + if ( query.<a href="tqsqlquery.html#isActive">isActive</a>() ) rows += query.<a href="tqsqlquery.html#numRowsAffected">numRowsAffected</a>() ; } return ( rows == 3 ) ? 0 : 1; @@ -517,7 +517,7 @@ cannot be determined, e.g. if the query fails. </pre><blockquote><p align="center"><em> From <a href="sql-overview-basicdatamanip-main-cpp.html">sql/overview/basicdatamanip/main.cpp</a> </em></p> </blockquote><p> This example demonstrates straightforward SQL DML (data manipulation -language) commands. Since we did not specify a database in the <a href="ntqsqlquery.html">TQSqlQuery</a> constructor the default database is used. <a href="ntqsqlquery.html">TQSqlQuery</a> objects +language) commands. Since we did not specify a database in the <a href="tqsqlquery.html">TQSqlQuery</a> constructor the default database is used. <a href="tqsqlquery.html">TQSqlQuery</a> objects can also be used to execute SQL DDL (data definition language) commands such as <tt>CREATE TABLE</tt> and <tt>CREATE INDEX</tt>. <p> <a name="Navigating_Result_Sets"></a> @@ -526,7 +526,7 @@ such as <tt>CREATE TABLE</tt> and <tt>CREATE INDEX</tt>. <a name="6-4"></a><p> Once a <tt>SELECT</tt> query has been executed successfully we have access to the result set of records that matched the query criteria. We have already used one of the navigation functions, next(), which can be -used alone to step sequentially through the records. <a href="ntqsqlquery.html">TQSqlQuery</a> also +used alone to step sequentially through the records. <a href="tqsqlquery.html">TQSqlQuery</a> also provides first(), last() and prev(). After any of these commands we can check that we are on a valid record by calling isValid(). <p> We can also navigate to any arbitrary record using seek(). The @@ -536,16 +536,16 @@ size() - 1. Note that not all databases provide the size of a <p> <pre> if ( createConnections() ) { - <a href="ntqsqlquery.html">TQSqlQuery</a> query( "SELECT id, name FROM people ORDER BY name" ); - <a name="x2171"></a> if ( ! query.<a href="ntqsqlquery.html#isActive">isActive</a>() ) return 1; // Query failed + <a href="tqsqlquery.html">TQSqlQuery</a> query( "SELECT id, name FROM people ORDER BY name" ); + <a name="x2171"></a> if ( ! query.<a href="tqsqlquery.html#isActive">isActive</a>() ) return 1; // Query failed int i; - <a name="x2174"></a> i = query.<a href="ntqsqlquery.html#size">size</a>(); // In this example we have 9 records; i == 9. - <a name="x2170"></a> query.<a href="ntqsqlquery.html#first">first</a>(); // Moves to the first record. - <a name="x2169"></a> i = query.<a href="ntqsqlquery.html#at">at</a>(); // i == 0 - <a name="x2172"></a> query.<a href="ntqsqlquery.html#last">last</a>(); // Moves to the last record. - i = query.<a href="ntqsqlquery.html#at">at</a>(); // i == 8 - <a name="x2173"></a> query.<a href="ntqsqlquery.html#seek">seek</a>( query.<a href="ntqsqlquery.html#size">size</a>() / 2 ); // Moves to the middle record. - i = query.<a href="ntqsqlquery.html#at">at</a>(); // i == 4 + <a name="x2174"></a> i = query.<a href="tqsqlquery.html#size">size</a>(); // In this example we have 9 records; i == 9. + <a name="x2170"></a> query.<a href="tqsqlquery.html#first">first</a>(); // Moves to the first record. + <a name="x2169"></a> i = query.<a href="tqsqlquery.html#at">at</a>(); // i == 0 + <a name="x2172"></a> query.<a href="tqsqlquery.html#last">last</a>(); // Moves to the last record. + i = query.<a href="tqsqlquery.html#at">at</a>(); // i == 8 + <a name="x2173"></a> query.<a href="tqsqlquery.html#seek">seek</a>( query.<a href="tqsqlquery.html#size">size</a>() / 2 ); // Moves to the middle record. + i = query.<a href="tqsqlquery.html#at">at</a>(); // i == 4 } </pre><blockquote><p align="center"><em> From <a href="sql-overview-navigating-main-cpp.html">sql/overview/navigating/main.cpp</a> </em></p> @@ -553,8 +553,8 @@ size() - 1. Note that not all databases provide the size of a <p> Not all drivers support size(), but we can interrogate the driver to find out: <p> <pre> - <a href="ntqsqldatabase.html">TQSqlDatabase</a>* defaultDB = TQSqlDatabase::<a href="ntqsqldatabase.html#database">database</a>(); - if ( defaultDB-><a href="ntqsqldatabase.html#driver">driver</a>()->hasFeature( TQSqlDriver::QuerySize ) ) { + <a href="tqsqldatabase.html">TQSqlDatabase</a>* defaultDB = TQSqlDatabase::<a href="tqsqldatabase.html#database">database</a>(); + if ( defaultDB-><a href="tqsqldatabase.html#driver">driver</a>()->hasFeature( TQSqlDriver::QuerySize ) ) { // TQSqlQuery::size() supported } else { @@ -567,11 +567,11 @@ retrieve data from it. <p> <pre> if ( createConnections() ) { - <a href="ntqsqlquery.html">TQSqlQuery</a> query( "SELECT id, surname FROM staff" ); - <a name="x2175"></a> if ( query.<a href="ntqsqlquery.html#isActive">isActive</a>() ) { - <a name="x2176"></a> while ( query.<a href="ntqsqlquery.html#next">next</a>() ) { - <a href="ntqapplication.html#qDebug">tqDebug</a>( query.<a href="ntqsqlquery.html#value">value</a>(0).toString() + ": " + - <a name="x2177"></a> query.<a href="ntqsqlquery.html#value">value</a>(1).toString() ); + <a href="tqsqlquery.html">TQSqlQuery</a> query( "SELECT id, surname FROM staff" ); + <a name="x2175"></a> if ( query.<a href="tqsqlquery.html#isActive">isActive</a>() ) { + <a name="x2176"></a> while ( query.<a href="tqsqlquery.html#next">next</a>() ) { + <a href="ntqapplication.html#qDebug">tqDebug</a>( query.<a href="tqsqlquery.html#value">value</a>(0).toString() + ": " + + <a name="x2177"></a> query.<a href="tqsqlquery.html#value">value</a>(1).toString() ); } } } @@ -583,27 +583,27 @@ only navigation function you need is next(). executed. This can be useful to check that the query you think is being executed is the one actually being executed. <p> <a name="Using_QSqlCursor"></a> -<h2> Using <a href="ntqsqlcursor.html">TQSqlCursor</a> +<h2> Using <a href="tqsqlcursor.html">TQSqlCursor</a> </h2> -<a name="7"></a><p> The <a href="ntqsqlcursor.html">TQSqlCursor</a> class provides a high level interface to browsing and +<a name="7"></a><p> The <a href="tqsqlcursor.html">TQSqlCursor</a> class provides a high level interface to browsing and editing records in SQL database tables or views without the need to write your own SQL. -<p> TQSqlCursor can do almost everything that <a href="ntqsqlquery.html">TQSqlQuery</a> can, with two +<p> TQSqlCursor can do almost everything that <a href="tqsqlquery.html">TQSqlQuery</a> can, with two exceptions. Since cursors represent tables or views within the -database, by default, <a href="ntqsqlcursor.html">TQSqlCursor</a> objects retrieve all the fields of +database, by default, <a href="tqsqlcursor.html">TQSqlCursor</a> objects retrieve all the fields of each record in the table or view whenever navigating to a new record. If only some fields are relevant simply confine your processing to those and ignore the others. Or, manually disable the -generation of certain fields using <a href="ntqsqlrecord.html#setGenerated">TQSqlRecord::setGenerated</a>(). Another +generation of certain fields using <a href="tqsqlrecord.html#setGenerated">TQSqlRecord::setGenerated</a>(). Another approach is to create a <tt>VIEW</tt> which only presents the fields you're interested in; but note that some databases do not support editable views. So if you really don't want to retrieve all the fields in the -cursor, then you should use a <a href="ntqsqlquery.html">TQSqlQuery</a> instead, and customize the -query to suit your needs. You can edit records using a <a href="ntqsqlcursor.html">TQSqlCursor</a> +cursor, then you should use a <a href="tqsqlquery.html">TQSqlQuery</a> instead, and customize the +query to suit your needs. You can edit records using a <a href="tqsqlcursor.html">TQSqlCursor</a> providing that the table or view has a primary index that uniquely distinguishes each record. If this condition is not met then you'll -need to use a <a href="ntqsqlquery.html">TQSqlQuery</a> for edits. -<p> <a href="ntqsqlcursor.html">TQSqlCursor</a> operates on a single record at a time. Whenever performing +need to use a <a href="tqsqlquery.html">TQSqlQuery</a> for edits. +<p> <a href="tqsqlcursor.html">TQSqlCursor</a> operates on a single record at a time. Whenever performing an insert, update or delete using TQSqlCursor, only a single record in the database is affected. When navigating through records in the cursor, only one record at a time is available in application code. @@ -612,7 +612,7 @@ used to make changes to a single record in the database. The edit buffer is maintained in a separate memory area, and is unnaffected by the 'navigation buffer' which changes as the cursor moves from record to record. -<p> Before we can use <a href="ntqsqlcursor.html">TQSqlCursor</a> objects we must first create and open +<p> Before we can use <a href="tqsqlcursor.html">TQSqlCursor</a> objects we must first create and open a database connection. Connecting is described in the <a href="#Connecting_to_Databases">Connecting to Databases</a> section above. For the examples that follow we will assume that the connections have been created using the createConnections() function @@ -622,15 +622,15 @@ presented earlier. follows this one we show how to link widgets to database cursors. Once we have a knowledge of both cursors and data-aware widgets we can discuss <a href="#Subclassing_QSqlCursor">subclassing TQSqlCursor</a>. -<p> The <a href="ntqsqlcursor.html">TQSqlCursor</a> class requires the <a href="qsqlcursor-h.html">ntqsqlcursor.h</a> header file. +<p> The <a href="tqsqlcursor.html">TQSqlCursor</a> class requires the <a href="tqsqlcursor-h.html">tqsqlcursor.h</a> header file. <p> <a name="Retrieving_Records"></a> <h3> Retrieving Records </h3> <a name="7-1"></a><p> <pre> #include <<a href="qapplication-h.html">ntqapplication.h</a>> - #include <<a href="qsqldatabase-h.html">ntqsqldatabase.h</a>> - #include <<a href="qsqlcursor-h.html">ntqsqlcursor.h</a>> + #include <<a href="tqsqldatabase-h.html">tqsqldatabase.h</a>> + #include <<a href="tqsqlcursor-h.html">tqsqlcursor.h</a>> #include "../connection.h" int main( int argc, char *argv[] ) @@ -638,12 +638,12 @@ discuss <a href="#Subclassing_QSqlCursor">subclassing TQSqlCursor</a>. <a href="ntqapplication.html">TQApplication</a> app( argc, argv ); if ( createConnections() ) { - <a href="ntqsqlcursor.html">TQSqlCursor</a> cur( "staff" ); // Specify the table/view name - <a name="x2178"></a> cur.<a href="ntqsqlcursor.html#select">select</a>(); // We'll retrieve every record - while ( cur.<a href="ntqsqlquery.html#next">next</a>() ) { - <a name="x2179"></a> <a href="ntqapplication.html#qDebug">tqDebug</a>( cur.<a href="ntqsqlquery.html#value">value</a>( "id" ).toString() + ": " + - cur.<a href="ntqsqlquery.html#value">value</a>( "surname" ).toString() + " " + - cur.<a href="ntqsqlquery.html#value">value</a>( "salary" ).toString() ); + <a href="tqsqlcursor.html">TQSqlCursor</a> cur( "staff" ); // Specify the table/view name + <a name="x2178"></a> cur.<a href="tqsqlcursor.html#select">select</a>(); // We'll retrieve every record + while ( cur.<a href="tqsqlquery.html#next">next</a>() ) { + <a name="x2179"></a> <a href="ntqapplication.html#qDebug">tqDebug</a>( cur.<a href="tqsqlquery.html#value">value</a>( "id" ).toString() + ": " + + cur.<a href="tqsqlquery.html#value">value</a>( "surname" ).toString() + " " + + cur.<a href="tqsqlquery.html#value">value</a>( "salary" ).toString() ); } } @@ -651,9 +651,9 @@ discuss <a href="#Subclassing_QSqlCursor">subclassing TQSqlCursor</a>. } </pre><blockquote><p align="center"><em> From <a href="sql-overview-retrieve2-main-cpp.html">sql/overview/retrieve2/main.cpp</a> </em></p> -</blockquote><p> We create the <a href="ntqsqlcursor.html">TQSqlCursor</a> object, specifying the table or view to use. +</blockquote><p> We create the <a href="tqsqlcursor.html">TQSqlCursor</a> object, specifying the table or view to use. If we need to use a database other than the default we can specify it -in the <a href="ntqsqlcursor.html">TQSqlCursor</a> constructor. +in the <a href="tqsqlcursor.html">TQSqlCursor</a> constructor. <p> The SQL executed by the cur.select() call is <p> <pre> SELECT staff.id, staff.forename, staff.surname, staff.salary, staff.statusid FROM staff @@ -661,7 +661,7 @@ in the <a href="ntqsqlcursor.html">TQSqlCursor</a> constructor. <p> Next, we iterate through the records returned by this select statement using cur.next(). Field values are retrieved in in a similar way to -<a href="ntqsqlquery.html">TQSqlQuery</a>, except that we pass field names rather than numeric indexes +<a href="tqsqlquery.html">TQSqlQuery</a>, except that we pass field names rather than numeric indexes to value() and setValue(). <p> <a name="Sorting_Data"></a> <h4> Sorting and Filtering Records @@ -682,15 +682,15 @@ statement's <tt>WHERE</tt> clause). <p> This will retrieve only those staff whose <tt>id</tt> is greater than 100. <p> In addition to retrieving selected records we often want to specify a -sort order for the returned records. This is achieved by creating a <a href="ntqsqlindex.html">TQSqlIndex</a> object which contains the names of the field(s) we wish to +sort order for the returned records. This is achieved by creating a <a href="tqsqlindex.html">TQSqlIndex</a> object which contains the names of the field(s) we wish to sort by and pass this object to the select() call. <p> <pre> - <a href="ntqsqlcursor.html">TQSqlCursor</a> cur( "staff" ); - <a href="ntqsqlindex.html">TQSqlIndex</a> nameIndex = cur.<a href="ntqsqlcursor.html#index">index</a>( "surname" ); - cur.<a href="ntqsqlcursor.html#select">select</a>( nameIndex ); + <a href="tqsqlcursor.html">TQSqlCursor</a> cur( "staff" ); + <a href="tqsqlindex.html">TQSqlIndex</a> nameIndex = cur.<a href="tqsqlcursor.html#index">index</a>( "surname" ); + cur.<a href="tqsqlcursor.html#select">select</a>( nameIndex ); </pre> -<p> Here we create a <a href="ntqsqlindex.html">TQSqlIndex</a> object with one field, "surname". When +<p> Here we create a <a href="tqsqlindex.html">TQSqlIndex</a> object with one field, "surname". When we call the select() function we pass the index object, which specifies that the records should be returned sorted by staff.surname. Each field in the index object is used in the ORDER BY @@ -706,7 +706,7 @@ is straightforward. cur.select( "staff.surname LIKE 'A%'", nameIndex ); </pre> -<p> We pass in a filter string (the <tt>WHERE</tt> clause), and the <a href="ntqsqlindex.html">TQSqlIndex</a> +<p> We pass in a filter string (the <tt>WHERE</tt> clause), and the <a href="tqsqlindex.html">TQSqlIndex</a> object to sort by (the <tt>ORDER BY</tt> clause). This produces <p> <pre> SELECT staff.id, staff.forename, staff.surname, staff.salary, staff.statusid @@ -715,18 +715,18 @@ object to sort by (the <tt>ORDER BY</tt> clause). This produces <p> To sort by more than one field, an index can be created which contains multiple fields. Ascending and descending order can be set using -<a href="ntqsqlindex.html#setDescending">TQSqlIndex::setDescending</a>(); the default is ascending. +<a href="tqsqlindex.html#setDescending">TQSqlIndex::setDescending</a>(); the default is ascending. <p> -<pre> <a href="ntqsqlcursor.html">TQSqlCursor</a> cur( "staff" ); +<pre> <a href="tqsqlcursor.html">TQSqlCursor</a> cur( "staff" ); <a href="ntqstringlist.html">TQStringList</a> fields = TQStringList() << "surname" << "forename"; - <a name="x2181"></a> <a href="ntqsqlindex.html">TQSqlIndex</a> order = cur.<a href="ntqsqlcursor.html#index">index</a>( fields ); - <a name="x2182"></a> cur.<a href="ntqsqlcursor.html#select">select</a>( order ); - <a name="x2183"></a> while ( cur.<a href="ntqsqlquery.html#next">next</a>() ) { + <a name="x2181"></a> <a href="tqsqlindex.html">TQSqlIndex</a> order = cur.<a href="tqsqlcursor.html#index">index</a>( fields ); + <a name="x2182"></a> cur.<a href="tqsqlcursor.html#select">select</a>( order ); + <a name="x2183"></a> while ( cur.<a href="tqsqlquery.html#next">next</a>() ) { </pre><blockquote><p align="center"><em> From <a href="sql-overview-order1-main-cpp.html">sql/overview/order1/main.cpp</a> </em></p> </blockquote><p> Here we create a string list containing the fields we wish to sort by, -in the order they are to be used. Then we create a <a href="ntqsqlindex.html">TQSqlIndex</a> object +in the order they are to be used. Then we create a <a href="tqsqlindex.html">TQSqlIndex</a> object based on these fields, finally executing the select() call using this index. This executes <pre> @@ -738,13 +738,13 @@ index. This executes can create a filter based on an index. <p> -<pre> <a href="ntqsqlcursor.html">TQSqlCursor</a> cur( "staff" ); +<pre> <a href="tqsqlcursor.html">TQSqlCursor</a> cur( "staff" ); <a href="ntqstringlist.html">TQStringList</a> fields = TQStringList() << "id" << "forename"; - <a name="x2184"></a> <a href="ntqsqlindex.html">TQSqlIndex</a> order = cur.<a href="ntqsqlcursor.html#index">index</a>( fields ); - <a href="ntqsqlindex.html">TQSqlIndex</a> filter = cur.<a href="ntqsqlcursor.html#index">index</a>( "surname" ); - <a name="x2186"></a> cur.<a href="ntqsqlrecord.html#setValue">setValue</a>( "surname", "Bloggs" ); - <a name="x2185"></a> cur.<a href="ntqsqlcursor.html#select">select</a>( filter, order ); - while ( cur.<a href="ntqsqlquery.html#next">next</a>() ) { + <a name="x2184"></a> <a href="tqsqlindex.html">TQSqlIndex</a> order = cur.<a href="tqsqlcursor.html#index">index</a>( fields ); + <a href="tqsqlindex.html">TQSqlIndex</a> filter = cur.<a href="tqsqlcursor.html#index">index</a>( "surname" ); + <a name="x2186"></a> cur.<a href="tqsqlrecord.html#setValue">setValue</a>( "surname", "Bloggs" ); + <a name="x2185"></a> cur.<a href="tqsqlcursor.html#select">select</a>( filter, order ); + while ( cur.<a href="tqsqlquery.html#next">next</a>() ) { </pre><blockquote><p align="center"><em> From <a href="sql-overview-order2-main-cpp.html">sql/overview/order2/main.cpp</a> </em></p> </blockquote><p> This executes @@ -753,8 +753,8 @@ can create a filter based on an index. FROM staff WHERE staff.surname='Bloggs' ORDER BY staff.id ASC, staff.forename ASC </pre> -<p> The "order" <a href="ntqsqlindex.html">TQSqlIndex</a> contains two fields, "id" and "forename" -which are used to order the results. The "filter" <a href="ntqsqlindex.html">TQSqlIndex</a> +<p> The "order" <a href="tqsqlindex.html">TQSqlIndex</a> contains two fields, "id" and "forename" +which are used to order the results. The "filter" <a href="tqsqlindex.html">TQSqlIndex</a> contains a single field, "surname". When an index is passed as a filter to the select() function, for each field in the filter, a <em>fieldname=value</em> subclause is created where the value @@ -765,27 +765,27 @@ setValue() to ensure that the value used is the one we want. </h4> <a name="7-1-2"></a><p> -<pre> <a href="ntqsqlcursor.html">TQSqlCursor</a> cur( "creditors" ); +<pre> <a href="tqsqlcursor.html">TQSqlCursor</a> cur( "creditors" ); <a href="ntqstringlist.html">TQStringList</a> orderFields = TQStringList() << "surname" << "forename"; - <a name="x2188"></a> <a href="ntqsqlindex.html">TQSqlIndex</a> order = cur.<a href="ntqsqlcursor.html#index">index</a>( orderFields ); + <a name="x2188"></a> <a href="tqsqlindex.html">TQSqlIndex</a> order = cur.<a href="tqsqlcursor.html#index">index</a>( orderFields ); <a href="ntqstringlist.html">TQStringList</a> filterFields = TQStringList() << "surname" << "city"; - <a href="ntqsqlindex.html">TQSqlIndex</a> filter = cur.<a href="ntqsqlcursor.html#index">index</a>( filterFields ); - <a name="x2190"></a> cur.<a href="ntqsqlrecord.html#setValue">setValue</a>( "surname", "Chirac" ); - cur.<a href="ntqsqlrecord.html#setValue">setValue</a>( "city", "Paris" ); + <a href="tqsqlindex.html">TQSqlIndex</a> filter = cur.<a href="tqsqlcursor.html#index">index</a>( filterFields ); + <a name="x2190"></a> cur.<a href="tqsqlrecord.html#setValue">setValue</a>( "surname", "Chirac" ); + cur.<a href="tqsqlrecord.html#setValue">setValue</a>( "city", "Paris" ); - <a name="x2189"></a> cur.<a href="ntqsqlcursor.html#select">select</a>( filter, order ); + <a name="x2189"></a> cur.<a href="tqsqlcursor.html#select">select</a>( filter, order ); - while ( cur.<a href="ntqsqlquery.html#next">next</a>() ) { - <a name="x2191"></a> int id = cur.<a href="ntqsqlquery.html#value">value</a>( "id" ).toInt(); - <a href="ntqstring.html">TQString</a> name = cur.<a href="ntqsqlquery.html#value">value</a>( "forename" ).toString() + " " + - cur.<a href="ntqsqlquery.html#value">value</a>( "surname" ).toString(); + while ( cur.<a href="tqsqlquery.html#next">next</a>() ) { + <a name="x2191"></a> int id = cur.<a href="tqsqlquery.html#value">value</a>( "id" ).toInt(); + <a href="ntqstring.html">TQString</a> name = cur.<a href="tqsqlquery.html#value">value</a>( "forename" ).toString() + " " + + cur.<a href="tqsqlquery.html#value">value</a>( "surname" ).toString(); <a name="x2193"></a> <a href="ntqapplication.html#qDebug">tqDebug</a>( TQString::<a href="ntqstring.html#number">number</a>( id ) + ": " + name ); } </pre><blockquote><p align="center"><em> From <a href="sql-overview-extract-main-cpp.html">sql/overview/extract/main.cpp</a> </em></p> </blockquote><p> In this example we begin by creating a cursor on the creditors table. -We create two <a href="ntqsqlindex.html">TQSqlIndex</a> objects. The first, "order", is created +We create two <a href="tqsqlindex.html">TQSqlIndex</a> objects. The first, "order", is created from the "orderFields" string list. The second, "filter", is created from the "filterFields" string list. We set the values of the two fields used in the filter, "surname" and "city", to the values we're @@ -809,8 +809,8 @@ some processing function, in this example a simple <a href="ntqapplication.html# <h3> Manipulating Records </h3> <a name="7-2"></a><p> Records can be inserted, updated or deleted in a table or view using a -<a href="ntqsqlcursor.html">TQSqlCursor</a> providing that the table or view has a primary index -that uniquely distinguishes each record. If this is not the case a <a href="ntqsqlquery.html">TQSqlQuery</a> must be used instead. (Note that not all databases support +<a href="tqsqlcursor.html">TQSqlCursor</a> providing that the table or view has a primary index +that uniquely distinguishes each record. If this is not the case a <a href="tqsqlquery.html">TQSqlQuery</a> must be used instead. (Note that not all databases support editable views.) <p> Each cursor has an internal 'edit buffer' which is used by all the edit operations (insert, update and delete). The editing process is @@ -831,8 +831,8 @@ quote is a special character in SQL. <p> The primeInsert(), primeUpdate() and primeDelete() methods all return a pointer to the internal edit buffer. Each method can potentially perform different operations on the edit buffer before returning it. -By default, <a href="ntqsqlcursor.html#primeInsert">TQSqlCursor::primeInsert</a>() clears all the field values in -the edit buffer (see <a href="ntqsqlrecord.html#clearValues">TQSqlRecord::clearValues</a>()). Both <a href="ntqsqlcursor.html#primeUpdate">TQSqlCursor::primeUpdate</a>() and <a href="ntqsqlcursor.html#primeDelete">TQSqlCursor::primeDelete</a>() initialize the +By default, <a href="tqsqlcursor.html#primeInsert">TQSqlCursor::primeInsert</a>() clears all the field values in +the edit buffer (see <a href="tqsqlrecord.html#clearValues">TQSqlRecord::clearValues</a>()). Both <a href="tqsqlcursor.html#primeUpdate">TQSqlCursor::primeUpdate</a>() and <a href="tqsqlcursor.html#primeDelete">TQSqlCursor::primeDelete</a>() initialize the edit buffer with the current contents of the cursor before returning it. All three of these functions are virtual, so you can redefine the behavior (for example, reimplementing primeInsert() to auto-number @@ -853,17 +853,17 @@ changes to the database are accurately reflected in the cursor. </h4> <a name="7-2-1"></a><p> -<pre> <a href="ntqsqlcursor.html">TQSqlCursor</a> cur( "prices" ); +<pre> <a href="tqsqlcursor.html">TQSqlCursor</a> cur( "prices" ); <a href="ntqstringlist.html">TQStringList</a> names = TQStringList() << "Screwdriver" << "Hammer" << "Wrench" << "Saw"; int id = 20; <a name="x2197"></a> for ( TQStringList::Iterator name = names.<a href="ntqvaluelist.html#begin">begin</a>(); <a name="x2198"></a> name != names.<a href="ntqvaluelist.html#end">end</a>(); ++name ) { - <a name="x2195"></a> <a href="ntqsqlrecord.html">TQSqlRecord</a> *buffer = cur.<a href="ntqsqlcursor.html#primeInsert">primeInsert</a>(); - <a name="x2196"></a> buffer-><a href="ntqsqlrecord.html#setValue">setValue</a>( "id", id ); - buffer-><a href="ntqsqlrecord.html#setValue">setValue</a>( "name", *name ); - buffer-><a href="ntqsqlrecord.html#setValue">setValue</a>( "price", 100.0 + (double)id ); - <a name="x2194"></a> count += cur.<a href="ntqsqlcursor.html#insert">insert</a>(); + <a name="x2195"></a> <a href="tqsqlrecord.html">TQSqlRecord</a> *buffer = cur.<a href="tqsqlcursor.html#primeInsert">primeInsert</a>(); + <a name="x2196"></a> buffer-><a href="tqsqlrecord.html#setValue">setValue</a>( "id", id ); + buffer-><a href="tqsqlrecord.html#setValue">setValue</a>( "name", *name ); + buffer-><a href="tqsqlrecord.html#setValue">setValue</a>( "price", 100.0 + (double)id ); + <a name="x2194"></a> count += cur.<a href="tqsqlcursor.html#insert">insert</a>(); id++; } </pre><blockquote><p align="center"><em> From <a href="sql-overview-insert-main-cpp.html">sql/overview/insert/main.cpp</a> @@ -871,14 +871,14 @@ changes to the database are accurately reflected in the cursor. </blockquote><p> In this example we create a cursor on the "prices" table. Next we create a list of product names which we iterate over. For each iteration we call the cursor's primeInsert() method. This method -returns a pointer to a <a href="ntqsqlrecord.html">TQSqlRecord</a> buffer in which all the fields -are set to <tt>NULL</tt>. (Note that <a href="ntqsqlcursor.html#primeInsert">TQSqlCursor::primeInsert</a>() is virtual, -and can be customized by derived classes. See <a href="ntqsqlcursor.html">TQSqlCursor</a>). Next we +returns a pointer to a <a href="tqsqlrecord.html">TQSqlRecord</a> buffer in which all the fields +are set to <tt>NULL</tt>. (Note that <a href="tqsqlcursor.html#primeInsert">TQSqlCursor::primeInsert</a>() is virtual, +and can be customized by derived classes. See <a href="tqsqlcursor.html">TQSqlCursor</a>). Next we call setValue() for each field that requires a value. Finally we call insert() to insert the record. The insert() call returns the number of rows inserted. -<p> We obtained a pointer to a <a href="ntqsqlrecord.html">TQSqlRecord</a> object from the primeInsert() -call. <a href="ntqsqlrecord.html">TQSqlRecord</a> objects can hold the data for a single record plus some +<p> We obtained a pointer to a <a href="tqsqlrecord.html">TQSqlRecord</a> object from the primeInsert() +call. <a href="tqsqlrecord.html">TQSqlRecord</a> objects can hold the data for a single record plus some meta-data about the record. In practice most interaction with a TQSqlRecord consists of simple value() and setValue() calls as shown in this and the following example. @@ -887,29 +887,29 @@ this and the following example. </h4> <a name="7-2-2"></a><p> -<pre> <a href="ntqsqlcursor.html">TQSqlCursor</a> cur( "prices" ); - <a name="x2200"></a> cur.<a href="ntqsqlcursor.html#select">select</a>( "id=202" ); - if ( cur.<a href="ntqsqlquery.html#next">next</a>() ) { - <a name="x2199"></a> <a href="ntqsqlrecord.html">TQSqlRecord</a> *buffer = cur.<a href="ntqsqlcursor.html#primeUpdate">primeUpdate</a>(); - <a name="x2204"></a> double price = buffer-><a href="ntqsqlrecord.html#value">value</a>( "price" ).toDouble(); +<pre> <a href="tqsqlcursor.html">TQSqlCursor</a> cur( "prices" ); + <a name="x2200"></a> cur.<a href="tqsqlcursor.html#select">select</a>( "id=202" ); + if ( cur.<a href="tqsqlquery.html#next">next</a>() ) { + <a name="x2199"></a> <a href="tqsqlrecord.html">TQSqlRecord</a> *buffer = cur.<a href="tqsqlcursor.html#primeUpdate">primeUpdate</a>(); + <a name="x2204"></a> double price = buffer-><a href="tqsqlrecord.html#value">value</a>( "price" ).toDouble(); double newprice = price * 1.05; - <a name="x2203"></a> buffer-><a href="ntqsqlrecord.html#setValue">setValue</a>( "price", newprice ); - <a name="x2201"></a> cur.<a href="ntqsqlcursor.html#update">update</a>(); + <a name="x2203"></a> buffer-><a href="tqsqlrecord.html#setValue">setValue</a>( "price", newprice ); + <a name="x2201"></a> cur.<a href="tqsqlcursor.html#update">update</a>(); } </pre><blockquote><p align="center"><em> From <a href="sql-overview-update-main-cpp.html">sql/overview/update/main.cpp</a> </em></p> </blockquote><p> This example begins with the creation of a cursor over the prices table. We select the record we wish to update with the select() call and -move to it with the next() call. We call primeUpdate() to get a <a href="ntqsqlrecord.html">TQSqlRecord</a> pointer to a buffer which is populated with the contents of +move to it with the next() call. We call primeUpdate() to get a <a href="tqsqlrecord.html">TQSqlRecord</a> pointer to a buffer which is populated with the contents of the current record. We retrieve the value of the price field, calculate a new price, and set the the price field to the newly calculated value. Finally we call update() to update the record. The update() call returns the number of rows updated. <p> If many identical updates need to be performed, for example increasing the price of every item in the price list, using a single SQL statement -with <a href="ntqsqlquery.html">TQSqlQuery</a> is more efficient, e.g. +with <a href="tqsqlquery.html">TQSqlQuery</a> is more efficient, e.g. <p> <pre> - <a href="ntqsqlquery.html">TQSqlQuery</a> query( "UPDATE prices SET price = price * 1.05" ); + <a href="tqsqlquery.html">TQSqlQuery</a> query( "UPDATE prices SET price = price * 1.05" ); </pre> <p> <a name="Deleting_Records"></a> @@ -917,22 +917,22 @@ with <a href="ntqsqlquery.html">TQSqlQuery</a> is more efficient, e.g. </h4> <a name="7-2-3"></a><p> -<pre> <a href="ntqsqlcursor.html">TQSqlCursor</a> cur( "prices" ); - <a name="x2207"></a> cur.<a href="ntqsqlcursor.html#select">select</a>( "id=999" ); - <a name="x2208"></a> if ( cur.<a href="ntqsqlquery.html#next">next</a>() ) { - <a name="x2206"></a> cur.<a href="ntqsqlcursor.html#primeDelete">primeDelete</a>(); - <a name="x2205"></a> cur.<a href="ntqsqlcursor.html#del">del</a>(); +<pre> <a href="tqsqlcursor.html">TQSqlCursor</a> cur( "prices" ); + <a name="x2207"></a> cur.<a href="tqsqlcursor.html#select">select</a>( "id=999" ); + <a name="x2208"></a> if ( cur.<a href="tqsqlquery.html#next">next</a>() ) { + <a name="x2206"></a> cur.<a href="tqsqlcursor.html#primeDelete">primeDelete</a>(); + <a name="x2205"></a> cur.<a href="tqsqlcursor.html#del">del</a>(); </pre><blockquote><p align="center"><em> From <a href="sql-overview-delete-main-cpp.html">sql/overview/delete/main.cpp</a> </em></p> </blockquote><p> To delete records, select the record to be deleted and navigate to it. Then call primeDelete() to populate the cursor with the primary key of the selected record, (in this example, the <tt>prices.id</tt> field), and -then call <a href="ntqsqlcursor.html#del">TQSqlCursor::del</a>() to delete it. +then call <a href="tqsqlcursor.html#del">TQSqlCursor::del</a>() to delete it. <p> As with update(), if multiple deletions need to be made with some common criteria it is more efficient to do so using a single SQL statement, e.g. <p> <pre> - <a href="ntqsqlquery.html">TQSqlQuery</a> query( "DELETE FROM prices WHERE id >= 2450 AND id <= 2500" ); + <a href="tqsqlquery.html">TQSqlQuery</a> query( "DELETE FROM prices WHERE id >= 2450 AND id <= 2500" ); </pre> <p> <a name="Data-Aware_Widgets"></a> @@ -951,9 +951,9 @@ examples provides additional information. <a name="8-1"></a><p> <pre> #include <<a href="qapplication-h.html">ntqapplication.h</a>> - #include <<a href="qsqldatabase-h.html">ntqsqldatabase.h</a>> - #include <<a href="qsqlcursor-h.html">ntqsqlcursor.h</a>> - #include <<a href="qdatatable-h.html">ntqdatatable.h</a>> + #include <<a href="tqsqldatabase-h.html">tqsqldatabase.h</a>> + #include <<a href="tqsqlcursor-h.html">tqsqlcursor.h</a>> + #include <<a href="tqdatatable-h.html">tqdatatable.h</a>> #include "../connection.h" int main( int argc, char *argv[] ) @@ -961,10 +961,10 @@ examples provides additional information. <a href="ntqapplication.html">TQApplication</a> app( argc, argv ); if ( createConnections() ) { - <a href="ntqsqlcursor.html">TQSqlCursor</a> staffCursor( "staff" ); - <a href="ntqdatatable.html">TQDataTable</a> *staffTable = new <a href="ntqdatatable.html">TQDataTable</a>( &staffCursor, TRUE ); + <a href="tqsqlcursor.html">TQSqlCursor</a> staffCursor( "staff" ); + <a href="tqdatatable.html">TQDataTable</a> *staffTable = new <a href="tqdatatable.html">TQDataTable</a>( &staffCursor, TRUE ); app.<a href="ntqapplication.html#setMainWidget">setMainWidget</a>( staffTable ); - <a name="x2211"></a> staffTable-><a href="ntqdatatable.html#refresh">refresh</a>(); + <a name="x2211"></a> staffTable-><a href="tqdatatable.html#refresh">refresh</a>(); staffTable-><a href="ntqwidget.html#show">show</a>(); return app.<a href="ntqapplication.html#exec">exec</a>(); @@ -974,34 +974,34 @@ examples provides additional information. } </pre><blockquote><p align="center"><em> From <a href="sql-overview-table1-main-cpp.html">sql/overview/table1/main.cpp</a> </em></p> -</blockquote><p> Data-Aware tables require the <a href="qdatatable-h.html">ntqdatatable.h</a> and <a href="qsqlcursor-h.html">ntqsqlcursor.h</a> header +</blockquote><p> Data-Aware tables require the <a href="tqdatatable-h.html">tqdatatable.h</a> and <a href="tqsqlcursor-h.html">tqsqlcursor.h</a> header files. We create our application object, call createConnections() and -create the cursor. We create the <a href="ntqdatatable.html">TQDataTable</a> passing it a pointer to -the cursor, and set the autoPopulate flag to TRUE. Next we make our <a href="ntqdatatable.html">TQDataTable</a> the main widget and call refresh() to populate it with data +create the cursor. We create the <a href="tqdatatable.html">TQDataTable</a> passing it a pointer to +the cursor, and set the autoPopulate flag to TRUE. Next we make our <a href="tqdatatable.html">TQDataTable</a> the main widget and call refresh() to populate it with data and call show() to make it visible. -<p> The autoPopulate flag tells the <a href="ntqdatatable.html">TQDataTable</a> whether or nor it should +<p> The autoPopulate flag tells the <a href="tqdatatable.html">TQDataTable</a> whether or nor it should create columns based on the cursor. autoPopulate does not affect the loading of data into the table; that is achieved by the refresh() function. <p> -<pre> <a href="ntqsqlcursor.html">TQSqlCursor</a> staffCursor( "staff" ); - <a href="ntqdatatable.html">TQDataTable</a> *staffTable = new <a href="ntqdatatable.html">TQDataTable</a>( &staffCursor ); +<pre> <a href="tqsqlcursor.html">TQSqlCursor</a> staffCursor( "staff" ); + <a href="tqdatatable.html">TQDataTable</a> *staffTable = new <a href="tqdatatable.html">TQDataTable</a>( &staffCursor ); app.<a href="ntqapplication.html#setMainWidget">setMainWidget</a>( staffTable ); - <a name="x2214"></a> staffTable-><a href="ntqdatatable.html#addColumn">addColumn</a>( "forename", "Forename" ); - staffTable-><a href="ntqdatatable.html#addColumn">addColumn</a>( "surname", "Surname" ); - staffTable-><a href="ntqdatatable.html#addColumn">addColumn</a>( "salary", "Annual Salary" ); + <a name="x2214"></a> staffTable-><a href="tqdatatable.html#addColumn">addColumn</a>( "forename", "Forename" ); + staffTable-><a href="tqdatatable.html#addColumn">addColumn</a>( "surname", "Surname" ); + staffTable-><a href="tqdatatable.html#addColumn">addColumn</a>( "salary", "Annual Salary" ); <a href="ntqstringlist.html">TQStringList</a> order = TQStringList() << "surname" << "forename"; - <a name="x2216"></a> staffTable-><a href="ntqdatatable.html#setSort">setSort</a>( order ); + <a name="x2216"></a> staffTable-><a href="tqdatatable.html#setSort">setSort</a>( order ); - <a name="x2215"></a> staffTable-><a href="ntqdatatable.html#refresh">refresh</a>(); + <a name="x2215"></a> staffTable-><a href="tqdatatable.html#refresh">refresh</a>(); staffTable-><a href="ntqwidget.html#show">show</a>(); </pre><blockquote><p align="center"><em> From <a href="sql-overview-table2-main-cpp.html">sql/overview/table2/main.cpp</a> </em></p> -</blockquote><p> We create an empty <a href="ntqdatatable.html">TQDataTable</a> which we make into our main widget and +</blockquote><p> We create an empty <a href="tqdatatable.html">TQDataTable</a> which we make into our main widget and then we manually add the columns we want in the order we wish them to appear. For each column we specify the field name and optionally a display label. @@ -1028,9 +1028,9 @@ the code below can be automatically generated by <a href="designer-manual.html"> #include <<a href="qlabel-h.html">ntqlabel.h</a>> #include <<a href="qlayout-h.html">ntqlayout.h</a>> #include <<a href="qlineedit-h.html">ntqlineedit.h</a>> - #include <<a href="qsqldatabase-h.html">ntqsqldatabase.h</a>> - #include <<a href="qsqlcursor-h.html">ntqsqlcursor.h</a>> - #include <<a href="qsqlform-h.html">ntqsqlform.h</a>> + #include <<a href="tqsqldatabase-h.html">tqsqldatabase.h</a>> + #include <<a href="tqsqlcursor-h.html">tqsqlcursor.h</a>> + #include <<a href="tqsqlform-h.html">tqsqlform.h</a>> #include "../connection.h" class FormDialog : public <a href="ntqdialog.html">TQDialog</a> @@ -1057,16 +1057,16 @@ the code below can be automatically generated by <a href="designer-manual.html"> grid-><a href="qgridlayout.html#addWidget">addWidget</a>( salaryEdit, 2, 1 ); <a name="x2222"></a> grid-><a href="ntqlayout.html#activate">activate</a>(); - <a href="ntqsqlcursor.html">TQSqlCursor</a> staffCursor( "staff" ); - staffCursor.<a href="ntqsqlcursor.html#select">select</a>(); - staffCursor.<a href="ntqsqlquery.html#next">next</a>(); + <a href="tqsqlcursor.html">TQSqlCursor</a> staffCursor( "staff" ); + staffCursor.<a href="tqsqlcursor.html#select">select</a>(); + staffCursor.<a href="tqsqlquery.html#next">next</a>(); - <a href="ntqsqlform.html">TQSqlForm</a> sqlForm( this ); - <a name="x2227"></a><a name="x2223"></a> sqlForm.<a href="ntqsqlform.html#setRecord">setRecord</a>( staffCursor.<a href="ntqsqlcursor.html#primeUpdate">primeUpdate</a>() ); - <a name="x2225"></a> sqlForm.<a href="ntqsqlform.html#insert">insert</a>( forenameDisplay, "forename" ); - sqlForm.<a href="ntqsqlform.html#insert">insert</a>( surnameDisplay, "surname" ); - sqlForm.<a href="ntqsqlform.html#insert">insert</a>( salaryEdit, "salary" ); - <a name="x2226"></a> sqlForm.<a href="ntqsqlform.html#readFields">readFields</a>(); + <a href="tqsqlform.html">TQSqlForm</a> sqlForm( this ); + <a name="x2227"></a><a name="x2223"></a> sqlForm.<a href="tqsqlform.html#setRecord">setRecord</a>( staffCursor.<a href="tqsqlcursor.html#primeUpdate">primeUpdate</a>() ); + <a name="x2225"></a> sqlForm.<a href="tqsqlform.html#insert">insert</a>( forenameDisplay, "forename" ); + sqlForm.<a href="tqsqlform.html#insert">insert</a>( surnameDisplay, "surname" ); + sqlForm.<a href="tqsqlform.html#insert">insert</a>( salaryEdit, "salary" ); + <a name="x2226"></a> sqlForm.<a href="tqsqlform.html#readFields">readFields</a>(); } int main( int argc, char *argv[] ) @@ -1084,28 +1084,28 @@ the code below can be automatically generated by <a href="designer-manual.html"> </pre><blockquote><p align="center"><em> From <a href="sql-overview-form1-main-cpp.html">sql/overview/form1/main.cpp</a> </em></p> </blockquote><p> We include the header files for the widgets that we need. We also -include <a href="qsqldatabase-h.html">ntqsqldatabase.h</a> and <a href="qsqlcursor-h.html">ntqsqlcursor.h</a> as usual, but we now add -<a href="qsqlform-h.html">ntqsqlform.h</a>. +include <a href="tqsqldatabase-h.html">tqsqldatabase.h</a> and <a href="tqsqlcursor-h.html">tqsqlcursor.h</a> as usual, but we now add +<a href="tqsqlform-h.html">tqsqlform.h</a>. <p> The form will be presented as a dialog so we subclass <a href="ntqdialog.html">TQDialog</a> with our own FormDialog class. We use a <a href="ntqlineedit.html">TQLineEdit</a> for the salary so that the user can change it. All the widgets are laid out using a grid. <p> We create a cursor on the staff table, select all records and move to the first record. -<p> Now we create a <a href="ntqsqlform.html">TQSqlForm</a> object and set the <a href="ntqsqlform.html">TQSqlForm</a>'s record buffer +<p> Now we create a <a href="tqsqlform.html">TQSqlForm</a> object and set the <a href="tqsqlform.html">TQSqlForm</a>'s record buffer to the cursor's update buffer. For each widget that we wish to make data-aware we insert a pointer to the widget and the associated field -name into the <a href="ntqsqlform.html">TQSqlForm</a>. Finally we call readFields() to populate the +name into the <a href="tqsqlform.html">TQSqlForm</a>. Finally we call readFields() to populate the widgets with data from the database via the cursor's buffer. <p> <a name="Displaying_a_Record_in_a_DataForm"></a> <h4> Displaying a Record in a Data Form </h4> -<a name="8-2-2"></a><p> <a href="ntqdataview.html">TQDataView</a> is a Widget that can hold a read-only <a href="ntqsqlform.html">TQSqlForm</a>. In -addition to <a href="ntqsqlform.html">TQSqlForm</a> it offers the slot refresh( <a href="ntqsqlrecord.html">TQSqlRecord</a> * ) so it -can easily be linked together with a <a href="ntqdatatable.html">TQDataTable</a> to display a detailed +<a name="8-2-2"></a><p> <a href="tqdataview.html">TQDataView</a> is a Widget that can hold a read-only <a href="tqsqlform.html">TQSqlForm</a>. In +addition to <a href="tqsqlform.html">TQSqlForm</a> it offers the slot refresh( <a href="tqsqlrecord.html">TQSqlRecord</a> * ) so it +can easily be linked together with a <a href="tqdatatable.html">TQDataTable</a> to display a detailed view of a record: <p> <pre> - connect( myDataTable, TQ_SIGNAL( currentChanged( <a href="ntqsqlrecord.html">TQSqlRecord</a>* ) ), - myDataView, TQ_SLOT( refresh( <a href="ntqsqlrecord.html">TQSqlRecord</a>* ) ) ); + connect( myDataTable, TQ_SIGNAL( currentChanged( <a href="tqsqlrecord.html">TQSqlRecord</a>* ) ), + myDataView, TQ_SLOT( refresh( <a href="tqsqlrecord.html">TQSqlRecord</a>* ) ) ); </pre> <p> <a name="Editing_a_Record"></a> @@ -1124,15 +1124,15 @@ differences. public slots: void save(); private: - <a href="ntqsqlcursor.html">TQSqlCursor</a> staffCursor; - <a href="ntqsqlform.html">TQSqlForm</a> *sqlForm; - <a href="ntqsqlindex.html">TQSqlIndex</a> idIndex; + <a href="tqsqlcursor.html">TQSqlCursor</a> staffCursor; + <a href="tqsqlform.html">TQSqlForm</a> *sqlForm; + <a href="tqsqlindex.html">TQSqlIndex</a> idIndex; }; </pre><blockquote><p align="center"><em> From <a href="sql-overview-form2-main-h.html">sql/overview/form2/main.h</a> </em></p> </blockquote><p> The save slot will be used for a button that the user can press to -confirm their update. We also hold pointers to the <a href="ntqsqlcursor.html">TQSqlCursor</a> and the -<a href="ntqsqlform.html">TQSqlForm</a> since they will need to be accessed outside the constructor. +confirm their update. We also hold pointers to the <a href="tqsqlcursor.html">TQSqlCursor</a> and the +<a href="tqsqlform.html">TQSqlForm</a> since they will need to be accessed outside the constructor. <p> <pre> staffCursor.setTrimmed( "forename", TRUE ); @@ -1159,17 +1159,17 @@ the user can click to save their updates. staffCursor.select( idIndex ); staffCursor.first(); </pre> -<p> We create a <a href="ntqsqlindex.html">TQSqlIndex</a> object and then execute a select() using the +<p> We create a <a href="tqsqlindex.html">TQSqlIndex</a> object and then execute a select() using the index. We then move to the first record in the result set. -<p> <pre> sqlForm = new <a href="ntqsqlform.html">TQSqlForm</a>( this ); - <a name="x2233"></a> sqlForm-><a href="ntqsqlform.html#setRecord">setRecord</a>( staffCursor.primeUpdate() ); +<p> <pre> sqlForm = new <a href="tqsqlform.html">TQSqlForm</a>( this ); + <a name="x2233"></a> sqlForm-><a href="tqsqlform.html#setRecord">setRecord</a>( staffCursor.primeUpdate() ); </pre> -<p> We create a new <a href="ntqsqlform.html">TQSqlForm</a> object and set it's record buffer to the +<p> We create a new <a href="tqsqlform.html">TQSqlForm</a> object and set it's record buffer to the cursor's update buffer. -<p> <pre> <a name="x2231"></a> sqlForm-><a href="ntqsqlform.html#insert">insert</a>( forenameEdit, "forename" ); - sqlForm-><a href="ntqsqlform.html#insert">insert</a>( surnameEdit, "surname" ); - sqlForm-><a href="ntqsqlform.html#insert">insert</a>( salaryEdit, "salary" ); - <a name="x2232"></a> sqlForm-><a href="ntqsqlform.html#readFields">readFields</a>(); +<p> <pre> <a name="x2231"></a> sqlForm-><a href="tqsqlform.html#insert">insert</a>( forenameEdit, "forename" ); + sqlForm-><a href="tqsqlform.html#insert">insert</a>( surnameEdit, "surname" ); + sqlForm-><a href="tqsqlform.html#insert">insert</a>( salaryEdit, "salary" ); + <a name="x2232"></a> sqlForm-><a href="tqsqlform.html#readFields">readFields</a>(); </pre> <p> Now we link the buffer's fields to the <a href="ntqlineedit.html">TQLineEdit</a> controls. (In the previous example we linked the cursor's fields.) The edit controls are @@ -1184,28 +1184,28 @@ since they are children of the form and will be deleted by TQt at the right time. <p> <pre> void FormDialog::save() { - <a name="x2234"></a> sqlForm-><a href="ntqsqlform.html#writeFields">writeFields</a>(); + <a name="x2234"></a> sqlForm-><a href="tqsqlform.html#writeFields">writeFields</a>(); staffCursor.update(); staffCursor.select( idIndex ); staffCursor.first(); } </pre> <p> Finally we add the save functionality for when the user presses the -save button. We write back the data from the widgets to the <a href="ntqsqlrecord.html">TQSqlRecord</a> buffer with the writeFields() call. Then we update the +save button. We write back the data from the widgets to the <a href="tqsqlrecord.html">TQSqlRecord</a> buffer with the writeFields() call. Then we update the database with the updated version of the record with the cursor's update() function. At this point the cursor is no longer positioned at -a valid record so we reissue the select() call using our <a href="ntqsqlindex.html">TQSqlIndex</a> +a valid record so we reissue the select() call using our <a href="tqsqlindex.html">TQSqlIndex</a> and move to the first record. -<p> <a href="ntqdatabrowser.html">TQDataBrowser</a> and <a href="ntqdataview.html">TQDataView</a> are widgets which provide a great deal of -the above functionality. <a href="ntqdatabrowser.html">TQDataBrowser</a> provides a data form which -allows editing of and navigation through a cursor's records. <a href="ntqdataview.html">TQDataView</a> provides a read only form for data in a cursor or database +<p> <a href="tqdatabrowser.html">TQDataBrowser</a> and <a href="tqdataview.html">TQDataView</a> are widgets which provide a great deal of +the above functionality. <a href="tqdatabrowser.html">TQDataBrowser</a> provides a data form which +allows editing of and navigation through a cursor's records. <a href="tqdataview.html">TQDataView</a> provides a read only form for data in a cursor or database record. See the class documentation or the <a href="designer-manual.html">TQt Designer</a> manual for more information on using these widgets. <p> Link to <a href="sql.html">sql/overview/form2/main.cpp</a> <p> <a name="Custom_Editor_Widgets"></a> <h3> Custom Editor Widgets </h3> -<a name="8-3"></a><p> <a href="ntqsqlform.html">TQSqlForm</a> uses <a href="ntqsqlpropertymap.html">TQSqlPropertyMap</a> to handle the transfer of data between +<a name="8-3"></a><p> <a href="tqsqlform.html">TQSqlForm</a> uses <a href="tqsqlpropertymap.html">TQSqlPropertyMap</a> to handle the transfer of data between widgets and database fields. Custom widgets can also be used in a form by installing a property map that contains information about the properties of the custom widget which should be used to transfer the @@ -1231,7 +1231,7 @@ we will only cover the differences here. The full source is in <a href="sql-over <p> We've created a simple subclass of <a href="ntqlineedit.html">TQLineEdit</a> and added a property, upperLineText, which will hold an uppercase version of the text. We also created a slot, changed(). -<p> <pre> <a href="ntqsqlpropertymap.html">TQSqlPropertyMap</a> *propMap; +<p> <pre> <a href="tqsqlpropertymap.html">TQSqlPropertyMap</a> *propMap; </pre> <p> We will be using a property map so we add a pointer to a property map to our FormDialog's private data. @@ -1270,16 +1270,16 @@ CustomEdit instances directly to database fields. <p> We use the same FormDialog as we did before, but this time replace two of the <a href="ntqlineedit.html">TQLineEdit</a> widgets with our own CustomEdit widgets. <p> Laying out the grid and setting up the cursor is the same as before. -<p> <pre> propMap = new <a href="ntqsqlpropertymap.html">TQSqlPropertyMap</a>; - <a name="x2239"></a><a name="x2235"></a> propMap-><a href="ntqsqlpropertymap.html#insert">insert</a>( forenameEdit-><a href="tqobject.html#className">className</a>(), "upperLine" ); +<p> <pre> propMap = new <a href="tqsqlpropertymap.html">TQSqlPropertyMap</a>; + <a name="x2239"></a><a name="x2235"></a> propMap-><a href="tqsqlpropertymap.html#insert">insert</a>( forenameEdit-><a href="tqobject.html#className">className</a>(), "upperLine" ); </pre> <p> We create a new property map on the heap and register our CustomEdit class and its upperLine property with the property map. -<p> <pre> sqlForm = new <a href="ntqsqlform.html">TQSqlForm</a>( this ); - <a name="x2238"></a><a name="x2236"></a> sqlForm-><a href="ntqsqlform.html#setRecord">setRecord</a>( staffCursor-><a href="ntqsqlcursor.html#primeUpdate">primeUpdate</a>() ); - <a name="x2237"></a> sqlForm-><a href="ntqsqlform.html#installPropertyMap">installPropertyMap</a>( propMap ); +<p> <pre> sqlForm = new <a href="tqsqlform.html">TQSqlForm</a>( this ); + <a name="x2238"></a><a name="x2236"></a> sqlForm-><a href="tqsqlform.html#setRecord">setRecord</a>( staffCursor-><a href="tqsqlcursor.html#primeUpdate">primeUpdate</a>() ); + <a name="x2237"></a> sqlForm-><a href="tqsqlform.html#installPropertyMap">installPropertyMap</a>( propMap ); </pre> -<p> The final change is to install the property map into the <a href="ntqsqlform.html">TQSqlForm</a> once +<p> The final change is to install the property map into the <a href="tqsqlform.html">TQSqlForm</a> once the TQSqlForm has been created. This passes responsibility for the property map's memory to TQSqlForm which itself is owned by the FormDialog, so TQt will delete them at the right time. @@ -1289,9 +1289,9 @@ our CustomEdit widget. <p> <a name="Custom_Editor_Widgets_for_Tables"></a> <h4> Custom Editor Widgets for Tables </h4> -<a name="8-3-1"></a><p> We must reimpliment <a href="ntqsqleditorfactory.html">TQSqlEditorFactory</a> to use custom editor widgets in +<a name="8-3-1"></a><p> We must reimpliment <a href="tqsqleditorfactory.html">TQSqlEditorFactory</a> to use custom editor widgets in tables. In the following example we will create a custom editor based -on <a href="ntqcombobox.html">TQComboBox</a> and a TQSqlEditorFactory subclass to show how a <a href="ntqdatatable.html">TQDataTable</a> +on <a href="ntqcombobox.html">TQComboBox</a> and a TQSqlEditorFactory subclass to show how a <a href="tqdatatable.html">TQDataTable</a> can use a custom editor. <p> @@ -1312,27 +1312,27 @@ can use a custom editor. for it. The statusid's in the status table will probably be different from the combobox's indexes so we create a <a href="ntqmap.html">TQMap</a> to map combobox indexes to/from the statusids that we will list in the combobox. -<p> <pre> class CustomSqlEditorFactory : public <a href="ntqsqleditorfactory.html">TQSqlEditorFactory</a> +<p> <pre> class CustomSqlEditorFactory : public <a href="tqsqleditorfactory.html">TQSqlEditorFactory</a> { TQ_OBJECT public: - <a href="ntqwidget.html">TQWidget</a> *createEditor( <a href="ntqwidget.html">TQWidget</a> *parent, const <a href="ntqsqlfield.html">TQSqlField</a> *field ); + <a href="ntqwidget.html">TQWidget</a> *createEditor( <a href="ntqwidget.html">TQWidget</a> *parent, const <a href="tqsqlfield.html">TQSqlField</a> *field ); }; </pre> -<p> We also need to subclass <a href="ntqsqleditorfactory.html">TQSqlEditorFactory</a> declaring a createEditor() +<p> We also need to subclass <a href="tqsqleditorfactory.html">TQSqlEditorFactory</a> declaring a createEditor() function since that is the only function we need to reimplement. <p> <pre> StatusPicker::StatusPicker( <a href="ntqwidget.html">TQWidget</a> *parent, const char *name ) : <a href="ntqcombobox.html">TQComboBox</a>( parent, name ) { - <a href="ntqsqlcursor.html">TQSqlCursor</a> cur( "status" ); - <a name="x2242"></a><a name="x2241"></a> cur.<a href="ntqsqlcursor.html#select">select</a>( cur.<a href="ntqsqlcursor.html#index">index</a>( "name" ) ); + <a href="tqsqlcursor.html">TQSqlCursor</a> cur( "status" ); + <a name="x2242"></a><a name="x2241"></a> cur.<a href="tqsqlcursor.html#select">select</a>( cur.<a href="tqsqlcursor.html#index">index</a>( "name" ) ); int i = 0; - while ( cur.<a href="ntqsqlquery.html#next">next</a>() ) { - <a name="x2243"></a> <a href="ntqcombobox.html#insertItem">insertItem</a>( cur.<a href="ntqsqlquery.html#value">value</a>( "name" ).toString(), i ); - index2id[i] = cur.<a href="ntqsqlquery.html#value">value</a>( "id" ).toInt(); + while ( cur.<a href="tqsqlquery.html#next">next</a>() ) { + <a name="x2243"></a> <a href="ntqcombobox.html#insertItem">insertItem</a>( cur.<a href="tqsqlquery.html#value">value</a>( "name" ).toString(), i ); + index2id[i] = cur.<a href="tqsqlquery.html#value">value</a>( "id" ).toInt(); i++; } </pre><blockquote><p align="center"><em> From <a href="sql-overview-table3-main-cpp.html">sql/overview/table3/main.cpp</a> @@ -1367,64 +1367,64 @@ index2id TQMap. We compare each index2id element's data (statusid) to the id parameter's value. If we have a match we set the combobox's current item to the index2id element's key (the combobox index), and leave the loop. -<p> When the user edits the status field in the <a href="ntqdatatable.html">TQDataTable</a> they will be +<p> When the user edits the status field in the <a href="tqdatatable.html">TQDataTable</a> they will be presented with a combobox of valid status names taken from the status table. However the status displayed is still the raw statusid. To display the status name when the field isn't being edited requires us to subclass TQDataTable and reimplement the paintField() function. <p> -<pre> class CustomTable : public <a href="ntqdatatable.html">TQDataTable</a> +<pre> class CustomTable : public <a href="tqdatatable.html">TQDataTable</a> { TQ_OBJECT public: CustomTable( - <a href="ntqsqlcursor.html">TQSqlCursor</a> *cursor, bool autoPopulate = FALSE, + <a href="tqsqlcursor.html">TQSqlCursor</a> *cursor, bool autoPopulate = FALSE, <a href="ntqwidget.html">TQWidget</a> * parent = 0, const char * name = 0 ) : - <a href="ntqdatatable.html">TQDataTable</a>( cursor, autoPopulate, parent, name ) {} + <a href="tqdatatable.html">TQDataTable</a>( cursor, autoPopulate, parent, name ) {} void paintField( - <a href="ntqpainter.html">TQPainter</a> * p, const <a href="ntqsqlfield.html">TQSqlField</a>* field, const <a href="ntqrect.html">TQRect</a> & cr, bool ); + <a href="ntqpainter.html">TQPainter</a> * p, const <a href="tqsqlfield.html">TQSqlField</a>* field, const <a href="ntqrect.html">TQRect</a> & cr, bool ); }; </pre><blockquote><p align="center"><em> From <a href="sql-overview-table4-main-h.html">sql/overview/table4/main.h</a> </em></p> -</blockquote><p> We simply call the original <a href="ntqdatatable.html">TQDataTable</a> constructor without changing +</blockquote><p> We simply call the original <a href="tqdatatable.html">TQDataTable</a> constructor without changing anything. We also declare the paintField function. <p> -<pre> <a name="x2245"></a>void CustomTable::<a href="ntqdatatable.html#paintField">paintField</a>( <a href="ntqpainter.html">TQPainter</a> * p, const <a href="ntqsqlfield.html">TQSqlField</a>* field, +<pre> <a name="x2245"></a>void CustomTable::<a href="tqdatatable.html#paintField">paintField</a>( <a href="ntqpainter.html">TQPainter</a> * p, const <a href="tqsqlfield.html">TQSqlField</a>* field, const <a href="ntqrect.html">TQRect</a> & cr, bool b) { if ( !field ) return; - <a name="x2249"></a> if ( field-><a href="ntqsqlfield.html#name">name</a>() == "statusid" ) { - <a href="ntqsqlquery.html">TQSqlQuery</a> query( "SELECT name FROM status WHERE id=" + - <a name="x2250"></a> field-><a href="ntqsqlfield.html#value">value</a>().toString() ); + <a name="x2249"></a> if ( field-><a href="tqsqlfield.html#name">name</a>() == "statusid" ) { + <a href="tqsqlquery.html">TQSqlQuery</a> query( "SELECT name FROM status WHERE id=" + + <a name="x2250"></a> field-><a href="tqsqlfield.html#value">value</a>().toString() ); <a href="ntqstring.html">TQString</a> text; - if ( query.<a href="ntqsqlquery.html#next">next</a>() ) { - <a name="x2252"></a> text = query.<a href="ntqsqlquery.html#value">value</a>( 0 ).toString(); + if ( query.<a href="tqsqlquery.html#next">next</a>() ) { + <a name="x2252"></a> text = query.<a href="tqsqlquery.html#value">value</a>( 0 ).toString(); } p-><a href="ntqpainter.html#drawText">drawText</a>( 2,2, cr.<a href="ntqrect.html#width">width</a>()-4, cr.<a href="ntqrect.html#height">height</a>()-4, fieldAlignment( field ), text ); } else { - TQDataTable::<a href="ntqdatatable.html#paintField">paintField</a>( p, field, cr, b) ; + TQDataTable::<a href="tqdatatable.html#paintField">paintField</a>( p, field, cr, b) ; } </pre><blockquote><p align="center"><em> From <a href="sql-overview-table4-main-cpp.html">sql/overview/table4/main.cpp</a> </em></p> -</blockquote><p> The paintField code is based on <a href="ntqdatatable.html">TQDataTable</a>'s source code. We need to +</blockquote><p> The paintField code is based on <a href="tqdatatable.html">TQDataTable</a>'s source code. We need to make three changes. Firstly add an if clause <tt>field->name() == "statusid"</tt> and look up the textual value for the id with a -straighforward <a href="ntqsqlquery.html">TQSqlQuery</a>. Secondly call the superclass to handle other +straighforward <a href="tqsqlquery.html">TQSqlQuery</a>. Secondly call the superclass to handle other fields. The last change is in our main function where we change staffTable from being a TQDataTable to being a CustomTable. <p> <a name="Subclassing_QSqlCursor"></a> -<h2> Subclassing <a href="ntqsqlcursor.html">TQSqlCursor</a> +<h2> Subclassing <a href="tqsqlcursor.html">TQSqlCursor</a> </h2> <a name="9"></a><p> <pre> #include <<a href="qapplication-h.html">ntqapplication.h</a>> - #include <<a href="qsqldatabase-h.html">ntqsqldatabase.h</a>> - #include <<a href="qsqlcursor-h.html">ntqsqlcursor.h</a>> - #include <<a href="qdatatable-h.html">ntqdatatable.h</a>> + #include <<a href="tqsqldatabase-h.html">tqsqldatabase.h</a>> + #include <<a href="tqsqlcursor-h.html">tqsqlcursor.h</a>> + #include <<a href="tqdatatable-h.html">tqdatatable.h</a>> #include "../connection.h" int main( int argc, char *argv[] ) @@ -1432,17 +1432,17 @@ staffTable from being a TQDataTable to being a CustomTable. <a href="ntqapplication.html">TQApplication</a> app( argc, argv ); if ( createConnections() ) { - <a href="ntqsqlcursor.html">TQSqlCursor</a> invoiceItemCursor( "invoiceitem" ); + <a href="tqsqlcursor.html">TQSqlCursor</a> invoiceItemCursor( "invoiceitem" ); - <a href="ntqdatatable.html">TQDataTable</a> *invoiceItemTable = new <a href="ntqdatatable.html">TQDataTable</a>( &invoiceItemCursor ); + <a href="tqdatatable.html">TQDataTable</a> *invoiceItemTable = new <a href="tqdatatable.html">TQDataTable</a>( &invoiceItemCursor ); app.<a href="ntqapplication.html#setMainWidget">setMainWidget</a>( invoiceItemTable ); - <a name="x2255"></a> invoiceItemTable-><a href="ntqdatatable.html#addColumn">addColumn</a>( "pricesid", "PriceID" ); - invoiceItemTable-><a href="ntqdatatable.html#addColumn">addColumn</a>( "quantity", "Quantity" ); - invoiceItemTable-><a href="ntqdatatable.html#addColumn">addColumn</a>( "paiddate", "Paid" ); + <a name="x2255"></a> invoiceItemTable-><a href="tqdatatable.html#addColumn">addColumn</a>( "pricesid", "PriceID" ); + invoiceItemTable-><a href="tqdatatable.html#addColumn">addColumn</a>( "quantity", "Quantity" ); + invoiceItemTable-><a href="tqdatatable.html#addColumn">addColumn</a>( "paiddate", "Paid" ); - <a name="x2256"></a> invoiceItemTable-><a href="ntqdatatable.html#refresh">refresh</a>(); + <a name="x2256"></a> invoiceItemTable-><a href="tqdatatable.html#refresh">refresh</a>(); invoiceItemTable-><a href="ntqwidget.html#show">show</a>(); return app.<a href="ntqapplication.html#exec">exec</a>(); @@ -1453,7 +1453,7 @@ staffTable from being a TQDataTable to being a CustomTable. </pre><blockquote><p align="center"><em> From <a href="sql-overview-subclass1-main-cpp.html">sql/overview/subclass1/main.cpp</a> </em></p> </blockquote><p> This example is very similar to the table1 example presented earlier. We -create a cursor, add the fields and their display labels to a <a href="ntqdatatable.html">TQDataTable</a>, +create a cursor, add the fields and their display labels to a <a href="tqdatatable.html">TQDataTable</a>, call refresh() to load the data and call show() to show the widget. <p> Unfortunately this example is unsatisfactory. It is tedious to set the table name and any custom characteristics for the fields every time we @@ -1465,18 +1465,18 @@ useful (or even essential for primary keys) if we could default some of the values when the user adds a new record. <p> -<pre> class InvoiceItemCursor : public <a href="ntqsqlcursor.html">TQSqlCursor</a> +<pre> class InvoiceItemCursor : public <a href="tqsqlcursor.html">TQSqlCursor</a> { public: InvoiceItemCursor(); }; </pre><blockquote><p align="center"><em> From <a href="sql-overview-subclass2-main-h.html">sql/overview/subclass2/main.h</a> </em></p> -</blockquote><p> We have created a separate header file and subclassed <a href="ntqsqlcursor.html">TQSqlCursor</a>. +</blockquote><p> We have created a separate header file and subclassed <a href="tqsqlcursor.html">TQSqlCursor</a>. <p> <pre> InvoiceItemCursor::InvoiceItemCursor() : - <a href="ntqsqlcursor.html">TQSqlCursor</a>( "invoiceitem" ) + <a href="tqsqlcursor.html">TQSqlCursor</a>( "invoiceitem" ) { // NOOP } @@ -1501,20 +1501,20 @@ of the calculateField() function since we will be reimplementing it. <p> <pre> InvoiceItemCursor::InvoiceItemCursor() : - <a href="ntqsqlcursor.html">TQSqlCursor</a>( "invoiceitem" ) + <a href="tqsqlcursor.html">TQSqlCursor</a>( "invoiceitem" ) { - <a href="qsqlfieldinfo.html">TQSqlFieldInfo</a> productName( "productname", TQVariant::String ); - <a href="ntqsqlcursor.html#append">append</a>( productName ); - <a name="x2260"></a> <a href="ntqsqlcursor.html#setCalculated">setCalculated</a>( productName.<a href="qsqlfieldinfo.html#name">name</a>(), TRUE ); + <a href="tqsqlfieldinfo.html">TQSqlFieldInfo</a> productName( "productname", TQVariant::String ); + <a href="tqsqlcursor.html#append">append</a>( productName ); + <a name="x2260"></a> <a href="tqsqlcursor.html#setCalculated">setCalculated</a>( productName.<a href="tqsqlfieldinfo.html#name">name</a>(), TRUE ); } - <a name="x2259"></a>TQVariant InvoiceItemCursor::<a href="ntqsqlcursor.html#calculateField">calculateField</a>( const <a href="ntqstring.html">TQString</a> & name ) + <a name="x2259"></a>TQVariant InvoiceItemCursor::<a href="tqsqlcursor.html#calculateField">calculateField</a>( const <a href="ntqstring.html">TQString</a> & name ) { if ( name == "productname" ) { - <a href="ntqsqlquery.html">TQSqlQuery</a> query( "SELECT name FROM prices WHERE id=" + - <a href="ntqsqlrecord.html#field">field</a>( "pricesid" )->value().toString() ); - if ( query.<a href="ntqsqlquery.html#next">next</a>() ) - <a name="x2262"></a> return query.<a href="ntqsqlquery.html#value">value</a>( 0 ); + <a href="tqsqlquery.html">TQSqlQuery</a> query( "SELECT name FROM prices WHERE id=" + + <a href="tqsqlrecord.html#field">field</a>( "pricesid" )->value().toString() ); + if ( query.<a href="tqsqlquery.html#next">next</a>() ) + <a name="x2262"></a> return query.<a href="tqsqlquery.html#value">value</a>( 0 ); } return TQVariant( <a href="ntqstring.html#TQString-null">TQString::null</a> ); @@ -1522,13 +1522,13 @@ of the calculateField() function since we will be reimplementing it. </pre><blockquote><p align="center"><em> From <a href="sql-overview-subclass3-main-cpp.html">sql/overview/subclass3/main.cpp</a> </em></p> </blockquote><p> We have changed the InvoiceItemCursor constructor. We now create a new -<a href="ntqsqlfield.html">TQSqlField</a> called productname and append this to the +<a href="tqsqlfield.html">TQSqlField</a> called productname and append this to the InvoiceItemCursor's set of fields. We call setCalculated() on productname to identify it as a calculated field. The first argument to setCalculated() is the field name, the second a bool which if TRUE signifies that calculateField() must be called to get the field's value. -<p> <pre> <a name="x2258"></a> invoiceItemTable-><a href="ntqdatatable.html#addColumn">addColumn</a>( "productname", "Product" ); +<p> <pre> <a name="x2258"></a> invoiceItemTable-><a href="tqdatatable.html#addColumn">addColumn</a>( "productname", "Product" ); </pre> <p> We add our new fields with addColumn() which adds them to the form and sets their display names. @@ -1545,46 +1545,46 @@ function require some simple expansion. We'll look at each in turn. <p> <pre> InvoiceItemCursor::InvoiceItemCursor() : - <a href="ntqsqlcursor.html">TQSqlCursor</a>( "invoiceitem" ) + <a href="tqsqlcursor.html">TQSqlCursor</a>( "invoiceitem" ) { - <a href="qsqlfieldinfo.html">TQSqlFieldInfo</a> productName( "productname", TQVariant::String ); - <a href="ntqsqlcursor.html#append">append</a>( productName ); - <a name="x2264"></a> <a href="ntqsqlcursor.html#setCalculated">setCalculated</a>( productName.<a href="qsqlfieldinfo.html#name">name</a>(), TRUE ); + <a href="tqsqlfieldinfo.html">TQSqlFieldInfo</a> productName( "productname", TQVariant::String ); + <a href="tqsqlcursor.html#append">append</a>( productName ); + <a name="x2264"></a> <a href="tqsqlcursor.html#setCalculated">setCalculated</a>( productName.<a href="tqsqlfieldinfo.html#name">name</a>(), TRUE ); - <a href="qsqlfieldinfo.html">TQSqlFieldInfo</a> productPrice( "price", TQVariant::Double ); - <a href="ntqsqlcursor.html#append">append</a>( productPrice ); - <a href="ntqsqlcursor.html#setCalculated">setCalculated</a>( productPrice.<a href="qsqlfieldinfo.html#name">name</a>(), TRUE ); + <a href="tqsqlfieldinfo.html">TQSqlFieldInfo</a> productPrice( "price", TQVariant::Double ); + <a href="tqsqlcursor.html#append">append</a>( productPrice ); + <a href="tqsqlcursor.html#setCalculated">setCalculated</a>( productPrice.<a href="tqsqlfieldinfo.html#name">name</a>(), TRUE ); - <a href="qsqlfieldinfo.html">TQSqlFieldInfo</a> productCost( "cost", TQVariant::Double ); - <a href="ntqsqlcursor.html#append">append</a>( productCost ); - <a href="ntqsqlcursor.html#setCalculated">setCalculated</a>( productCost.<a href="qsqlfieldinfo.html#name">name</a>(), TRUE ); + <a href="tqsqlfieldinfo.html">TQSqlFieldInfo</a> productCost( "cost", TQVariant::Double ); + <a href="tqsqlcursor.html#append">append</a>( productCost ); + <a href="tqsqlcursor.html#setCalculated">setCalculated</a>( productCost.<a href="tqsqlfieldinfo.html#name">name</a>(), TRUE ); } </pre><blockquote><p align="center"><em> From <a href="sql-overview-subclass4-main-cpp.html">sql/overview/subclass4/main.cpp</a> </em></p> </blockquote><p> We create two extra fields, price and cost, and append them to the cursor's set of fields. Both are registered as calculated fields with calls to setCalculated(). -<p> <pre> <a name="x2263"></a>TQVariant InvoiceItemCursor::<a href="ntqsqlcursor.html#calculateField">calculateField</a>( const <a href="ntqstring.html">TQString</a> & name ) +<p> <pre> <a name="x2263"></a>TQVariant InvoiceItemCursor::<a href="tqsqlcursor.html#calculateField">calculateField</a>( const <a href="ntqstring.html">TQString</a> & name ) { if ( name == "productname" ) { - <a href="ntqsqlquery.html">TQSqlQuery</a> query( "SELECT name FROM prices WHERE id=" + - <a href="ntqsqlrecord.html#field">field</a>( "pricesid" )->value().toString() ); - <a name="x2265"></a> if ( query.<a href="ntqsqlquery.html#next">next</a>() ) - <a name="x2266"></a> return query.<a href="ntqsqlquery.html#value">value</a>( 0 ); + <a href="tqsqlquery.html">TQSqlQuery</a> query( "SELECT name FROM prices WHERE id=" + + <a href="tqsqlrecord.html#field">field</a>( "pricesid" )->value().toString() ); + <a name="x2265"></a> if ( query.<a href="tqsqlquery.html#next">next</a>() ) + <a name="x2266"></a> return query.<a href="tqsqlquery.html#value">value</a>( 0 ); } else if ( name == "price" ) { - <a href="ntqsqlquery.html">TQSqlQuery</a> query( "SELECT price FROM prices WHERE id=" + - <a href="ntqsqlrecord.html#field">field</a>( "pricesid" )->value().toString() ); - if ( query.<a href="ntqsqlquery.html#next">next</a>() ) - return query.<a href="ntqsqlquery.html#value">value</a>( 0 ); + <a href="tqsqlquery.html">TQSqlQuery</a> query( "SELECT price FROM prices WHERE id=" + + <a href="tqsqlrecord.html#field">field</a>( "pricesid" )->value().toString() ); + if ( query.<a href="tqsqlquery.html#next">next</a>() ) + return query.<a href="tqsqlquery.html#value">value</a>( 0 ); } else if ( name == "cost" ) { - <a href="ntqsqlquery.html">TQSqlQuery</a> query( "SELECT price FROM prices WHERE id=" + - <a href="ntqsqlrecord.html#field">field</a>( "pricesid" )->value().toString() ); - if ( query.<a href="ntqsqlquery.html#next">next</a>() ) - return TQVariant( query.<a href="ntqsqlquery.html#value">value</a>( 0 ).toDouble() * - <a href="ntqsqlquery.html#value">value</a>( "quantity").toDouble() ); + <a href="tqsqlquery.html">TQSqlQuery</a> query( "SELECT price FROM prices WHERE id=" + + <a href="tqsqlrecord.html#field">field</a>( "pricesid" )->value().toString() ); + if ( query.<a href="tqsqlquery.html#next">next</a>() ) + return TQVariant( query.<a href="tqsqlquery.html#value">value</a>( 0 ).toDouble() * + <a href="tqsqlquery.html#value">value</a>( "quantity").toDouble() ); } return TQVariant( TQString::null ); @@ -1605,7 +1605,7 @@ calculated field would be a lookup against a different table or view. user attempts to insert a new record. <p> -<pre> <a href="ntqsqlrecord.html">TQSqlRecord</a> *primeInsert(); +<pre> <a href="tqsqlrecord.html">TQSqlRecord</a> *primeInsert(); </pre><blockquote><p align="center"><em> From <a href="sql-overview-subclass5-main-h.html">sql/overview/subclass5/main.h</a> </em></p> </blockquote><p> We declare our own primeInsert() function since we will need to @@ -1613,14 +1613,14 @@ reimplement this. <p> The constructor and the calculateField() function remain unchanged. <p> -<pre> <a name="x2267"></a>TQSqlRecord *InvoiceItemCursor::<a href="ntqsqlcursor.html#primeInsert">primeInsert</a>() +<pre> <a name="x2267"></a>TQSqlRecord *InvoiceItemCursor::<a href="tqsqlcursor.html#primeInsert">primeInsert</a>() { - <a href="ntqsqlrecord.html">TQSqlRecord</a> *buffer = <a href="ntqsqlcursor.html#editBuffer">editBuffer</a>(); - <a href="ntqsqlquery.html">TQSqlQuery</a> query( "SELECT NEXTVAL( 'invoiceitem_seq' )" ); - <a name="x2268"></a> if ( query.<a href="ntqsqlquery.html#next">next</a>() ) - <a name="x2270"></a><a name="x2269"></a> buffer-><a href="ntqsqlrecord.html#setValue">setValue</a>( "id", query.<a href="ntqsqlquery.html#value">value</a>( 0 ) ); - buffer-><a href="ntqsqlrecord.html#setValue">setValue</a>( "paiddate", TQDate::currentDate() ); - buffer-><a href="ntqsqlrecord.html#setValue">setValue</a>( "quantity", 1 ); + <a href="tqsqlrecord.html">TQSqlRecord</a> *buffer = <a href="tqsqlcursor.html#editBuffer">editBuffer</a>(); + <a href="tqsqlquery.html">TQSqlQuery</a> query( "SELECT NEXTVAL( 'invoiceitem_seq' )" ); + <a name="x2268"></a> if ( query.<a href="tqsqlquery.html#next">next</a>() ) + <a name="x2270"></a><a name="x2269"></a> buffer-><a href="tqsqlrecord.html#setValue">setValue</a>( "id", query.<a href="tqsqlquery.html#value">value</a>( 0 ) ); + buffer-><a href="tqsqlrecord.html#setValue">setValue</a>( "paiddate", TQDate::currentDate() ); + buffer-><a href="tqsqlrecord.html#setValue">setValue</a>( "quantity", 1 ); return buffer; } |