summaryrefslogtreecommitdiffstats
path: root/examples/sql
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-07-10 15:24:15 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-07-10 15:24:15 -0500
commitbd0f3345a938b35ce6a12f6150373b0955b8dd12 (patch)
tree7a520322212d48ebcb9fbe1087e7fca28b76185c /examples/sql
downloadqt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.tar.gz
qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.zip
Add Qt3 development HEAD version
Diffstat (limited to 'examples/sql')
-rw-r--r--examples/sql/blob/blob.pro11
-rw-r--r--examples/sql/blob/main.cpp106
-rw-r--r--examples/sql/overview/basicbrowsing/README1
-rw-r--r--examples/sql/overview/basicbrowsing/basicbrowsing.pro9
-rw-r--r--examples/sql/overview/basicbrowsing/main.cpp35
-rw-r--r--examples/sql/overview/basicbrowsing2/README1
-rw-r--r--examples/sql/overview/basicbrowsing2/basicbrowsing2.pro9
-rw-r--r--examples/sql/overview/basicbrowsing2/main.cpp43
-rw-r--r--examples/sql/overview/basicdatamanip/README1
-rw-r--r--examples/sql/overview/basicdatamanip/basicdatamanip.pro9
-rw-r--r--examples/sql/overview/basicdatamanip/main.cpp40
-rw-r--r--examples/sql/overview/connect1/README1
-rw-r--r--examples/sql/overview/connect1/connect1.pro9
-rw-r--r--examples/sql/overview/connect1/main.cpp31
-rw-r--r--examples/sql/overview/connection.cpp50
-rw-r--r--examples/sql/overview/connection.h24
-rw-r--r--examples/sql/overview/create_connections/README1
-rw-r--r--examples/sql/overview/create_connections/create_connections.pro9
-rw-r--r--examples/sql/overview/create_connections/main.cpp26
-rw-r--r--examples/sql/overview/custom1/custom1.pro8
-rw-r--r--examples/sql/overview/custom1/main.cpp109
-rw-r--r--examples/sql/overview/custom1/main.h52
-rw-r--r--examples/sql/overview/delete/README1
-rw-r--r--examples/sql/overview/delete/delete.pro9
-rw-r--r--examples/sql/overview/delete/main.cpp29
-rw-r--r--examples/sql/overview/extract/README1
-rw-r--r--examples/sql/overview/extract/extract.pro9
-rw-r--r--examples/sql/overview/extract/main.cpp41
-rw-r--r--examples/sql/overview/form1/form1.pro8
-rw-r--r--examples/sql/overview/form1/main.cpp69
-rw-r--r--examples/sql/overview/form2/form2.pro8
-rw-r--r--examples/sql/overview/form2/main.cpp77
-rw-r--r--examples/sql/overview/form2/main.h33
-rw-r--r--examples/sql/overview/insert/README1
-rw-r--r--examples/sql/overview/insert/insert.pro9
-rw-r--r--examples/sql/overview/insert/main.cpp37
-rw-r--r--examples/sql/overview/insert2/insert2.pro9
-rw-r--r--examples/sql/overview/insert2/main.cpp29
-rw-r--r--examples/sql/overview/navigating/README1
-rw-r--r--examples/sql/overview/navigating/main.cpp33
-rw-r--r--examples/sql/overview/navigating/navigating.pro9
-rw-r--r--examples/sql/overview/order1/README1
-rw-r--r--examples/sql/overview/order1/main.cpp32
-rw-r--r--examples/sql/overview/order1/order1.pro9
-rw-r--r--examples/sql/overview/order2/README1
-rw-r--r--examples/sql/overview/order2/main.cpp34
-rw-r--r--examples/sql/overview/order2/order2.pro9
-rw-r--r--examples/sql/overview/overview.pro33
-rw-r--r--examples/sql/overview/retrieve1/README1
-rw-r--r--examples/sql/overview/retrieve1/main.cpp30
-rw-r--r--examples/sql/overview/retrieve1/retrieve1.pro9
-rw-r--r--examples/sql/overview/retrieve2/README1
-rw-r--r--examples/sql/overview/retrieve2/main.cpp30
-rw-r--r--examples/sql/overview/retrieve2/retrieve2.pro9
-rw-r--r--examples/sql/overview/subclass1/main.cpp38
-rw-r--r--examples/sql/overview/subclass1/subclass1.pro8
-rw-r--r--examples/sql/overview/subclass2/main.cpp42
-rw-r--r--examples/sql/overview/subclass2/main.h23
-rw-r--r--examples/sql/overview/subclass2/subclass2.pro8
-rw-r--r--examples/sql/overview/subclass3/main.cpp57
-rw-r--r--examples/sql/overview/subclass3/main.h25
-rw-r--r--examples/sql/overview/subclass3/subclass3.pro8
-rw-r--r--examples/sql/overview/subclass4/main.cpp81
-rw-r--r--examples/sql/overview/subclass4/main.h25
-rw-r--r--examples/sql/overview/subclass4/subclass4.pro8
-rw-r--r--examples/sql/overview/subclass5/main.cpp94
-rw-r--r--examples/sql/overview/subclass5/main.h25
-rw-r--r--examples/sql/overview/subclass5/subclass5.pro8
-rw-r--r--examples/sql/overview/table1/main.cpp31
-rw-r--r--examples/sql/overview/table1/table1.pro8
-rw-r--r--examples/sql/overview/table2/main.cpp41
-rw-r--r--examples/sql/overview/table2/table2.pro8
-rw-r--r--examples/sql/overview/table3/main.cpp90
-rw-r--r--examples/sql/overview/table3/main.h40
-rw-r--r--examples/sql/overview/table3/table3.pro8
-rw-r--r--examples/sql/overview/table4/main.cpp109
-rw-r--r--examples/sql/overview/table4/main.h53
-rw-r--r--examples/sql/overview/table4/table4.pro8
-rw-r--r--examples/sql/overview/update/README1
-rw-r--r--examples/sql/overview/update/main.cpp32
-rw-r--r--examples/sql/overview/update/update.pro9
-rw-r--r--examples/sql/sql.pro9
-rw-r--r--examples/sql/sqltable/README18
-rw-r--r--examples/sql/sqltable/main.cpp71
-rw-r--r--examples/sql/sqltable/sqltable.doc24
-rw-r--r--examples/sql/sqltable/sqltable.pro10
86 files changed, 2217 insertions, 0 deletions
diff --git a/examples/sql/blob/blob.pro b/examples/sql/blob/blob.pro
new file mode 100644
index 0000000..9240f2e
--- /dev/null
+++ b/examples/sql/blob/blob.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+TARGET = blob
+
+CONFIG += qt warn_on release
+win32:CONFIG += console
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp
+INTERFACES =
diff --git a/examples/sql/blob/main.cpp b/examples/sql/blob/main.cpp
new file mode 100644
index 0000000..054d857
--- /dev/null
+++ b/examples/sql/blob/main.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlquery.h>
+#include <qsqlcursor.h>
+#include <qfile.h>
+
+#define DRIVER "QPSQL7" /* see the Qt SQL documentation for a list of available drivers */
+#define DATABASE "" /* the name of your database */
+#define USER "" /* user name with appropriate rights */
+#define PASSWORD "" /* password for USER */
+#define HOST "" /* host on which the database is running */
+
+int main( int argc, char ** argv )
+{
+
+ QApplication a( argc, argv, FALSE );
+ QSqlDatabase * db = QSqlDatabase::addDatabase( DRIVER );
+ db->setDatabaseName( DATABASE );
+ db->setUserName( USER );
+ db->setPassword( PASSWORD );
+ db->setHostName( HOST );
+ if ( !db->open() ) {
+ qWarning( db->lastError().databaseText() );
+ return 1;
+ }
+
+ if ( argc < 2 ) {
+ qWarning( "Usage: %s <filename>", argv[0] );
+ return 1;
+ }
+
+ // read a file which we want to insert into the database
+ QFile f( argv[1] );
+ if ( !f.open( IO_ReadOnly ) ) {
+ qWarning( "Unable to open data file '%s' - exiting", argv[1] );
+ return 1;
+ }
+ QByteArray binaryData = f.readAll();
+ qWarning( "Data size: %d", binaryData.size() );
+
+ // create a table with a binary field
+ QSqlQuery q;
+ if ( !q.exec( "CREATE TABLE blobexample ( id INT PRIMARY KEY, binfield LONGBLOB )" ) ) {
+ qWarning( "Unable to create table - exiting" );
+ return 1;
+ }
+
+ // insert a BLOB into the table
+ if ( !q.prepare( "INSERT INTO blobexample ( id, binfield ) VALUES ( ?, ? )" ) ) {
+ qWarning( "Unable to prepare query - exiting" );
+ return 1;
+ }
+ q.bindValue( 0, 1 );
+ q.bindValue( 1, binaryData );
+ if ( !q.exec() ) {
+ qWarning( "Unable to execute prepared query - exiting" );
+ return 1;
+ }
+
+ // read the BLOB back from the database
+ if ( !q.exec( "SELECT id, binfield FROM blobexample" ) ) {
+ qWarning( "Unable to execute query - exiting" );
+ return 1;
+ }
+ qWarning( "\nQSqlQuery:" );
+ while ( q.next() ) {
+ qWarning( "BLOB id: %d", q.value( 0 ).toInt() );
+ qWarning( "BLOB size: %d", q.value( 1 ).toByteArray().size() );
+ }
+
+ // write another BLOB using QSqlCursor
+ QSqlCursor cur( "blobexample" );
+ QSqlRecord * r = cur.primeInsert();
+ r->setValue( "id", 2 );
+ r->setValue( "binfield", binaryData );
+ if ( !cur.insert() ) {
+ qWarning( "Unable to insert BLOB using QSqlCursor - exiting" );
+ return 1;
+ }
+
+ // read the BLOBs back using QSqlCursor
+ if ( !cur.select() ) {
+ qWarning( "Unable retrieve blobexample table using QSqlCursor - exiting" );
+ return 1;
+ }
+ qWarning( "\nQSqlCursor:" );
+ while ( cur.next() ) {
+ qWarning( "BLOB id: %d", cur.value( "id" ).toInt() );
+ qWarning( "BLOB size: %d", cur.value( "binfield" ).toByteArray().size() );
+ }
+
+ if ( !q.exec( "DROP TABLE blobexample" ) ) {
+ qWarning( "Unable to drop table - exiting" );
+ return 1;
+ }
+ return 0;
+}
diff --git a/examples/sql/overview/basicbrowsing/README b/examples/sql/overview/basicbrowsing/README
new file mode 100644
index 0000000..eae3cd7
--- /dev/null
+++ b/examples/sql/overview/basicbrowsing/README
@@ -0,0 +1 @@
+This example is part of the overview in sql.html
diff --git a/examples/sql/overview/basicbrowsing/basicbrowsing.pro b/examples/sql/overview/basicbrowsing/basicbrowsing.pro
new file mode 100644
index 0000000..b7245c9
--- /dev/null
+++ b/examples/sql/overview/basicbrowsing/basicbrowsing.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../../include
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
+
diff --git a/examples/sql/overview/basicbrowsing/main.cpp b/examples/sql/overview/basicbrowsing/main.cpp
new file mode 100644
index 0000000..ae22243
--- /dev/null
+++ b/examples/sql/overview/basicbrowsing/main.cpp
@@ -0,0 +1,35 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlquery.h>
+#include "../connection.h"
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv, FALSE );
+
+ if ( createConnections() ) {
+ QSqlDatabase *oracledb = QSqlDatabase::database( "ORACLE" );
+ // Copy data from the oracle database to the ODBC (default)
+ // database
+ QSqlQuery target;
+ QSqlQuery query( "SELECT id, name FROM people", oracledb );
+ if ( query.isActive() ) {
+ while ( query.next() ) {
+ target.exec( "INSERT INTO people ( id, name ) VALUES ( " +
+ query.value(0).toString() +
+ ", '" + query.value(1).toString() + "' )" );
+ }
+ }
+ }
+
+ return 0;
+}
diff --git a/examples/sql/overview/basicbrowsing2/README b/examples/sql/overview/basicbrowsing2/README
new file mode 100644
index 0000000..eae3cd7
--- /dev/null
+++ b/examples/sql/overview/basicbrowsing2/README
@@ -0,0 +1 @@
+This example is part of the overview in sql.html
diff --git a/examples/sql/overview/basicbrowsing2/basicbrowsing2.pro b/examples/sql/overview/basicbrowsing2/basicbrowsing2.pro
new file mode 100644
index 0000000..9e6df96
--- /dev/null
+++ b/examples/sql/overview/basicbrowsing2/basicbrowsing2.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../../include
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/basicbrowsing2/main.cpp b/examples/sql/overview/basicbrowsing2/main.cpp
new file mode 100644
index 0000000..00cedaf
--- /dev/null
+++ b/examples/sql/overview/basicbrowsing2/main.cpp
@@ -0,0 +1,43 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlquery.h>
+#include "../connection.h"
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv, FALSE );
+
+ if ( createConnections() ) {
+ QSqlDatabase *oracledb = QSqlDatabase::database( "ORACLE" );
+ // Copy data from the oracle database to the ODBC (default)
+ // database
+ QSqlQuery target;
+ QSqlQuery query( "SELECT id, name FROM people", oracledb );
+ int count = 0;
+ if ( query.isActive() ) {
+ while ( query.next() ) {
+ target.exec( "INSERT INTO people ( id, name ) VALUES ( " +
+ query.value(0).toString() +
+ ", '" + query.value(1).toString() + "' )" );
+ if ( target.isActive() )
+ count += target.numRowsAffected();
+ }
+ }
+ }
+
+ return 0;
+}
+
+
+
+
+
diff --git a/examples/sql/overview/basicdatamanip/README b/examples/sql/overview/basicdatamanip/README
new file mode 100644
index 0000000..eae3cd7
--- /dev/null
+++ b/examples/sql/overview/basicdatamanip/README
@@ -0,0 +1 @@
+This example is part of the overview in sql.html
diff --git a/examples/sql/overview/basicdatamanip/basicdatamanip.pro b/examples/sql/overview/basicdatamanip/basicdatamanip.pro
new file mode 100644
index 0000000..9e6df96
--- /dev/null
+++ b/examples/sql/overview/basicdatamanip/basicdatamanip.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../../include
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/basicdatamanip/main.cpp b/examples/sql/overview/basicdatamanip/main.cpp
new file mode 100644
index 0000000..56d5a29
--- /dev/null
+++ b/examples/sql/overview/basicdatamanip/main.cpp
@@ -0,0 +1,40 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlquery.h>
+#include "../connection.h"
+
+bool createConnections();
+
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv, FALSE );
+
+ int rows = 0;
+
+ if ( createConnections() ) {
+ QSqlQuery query( "INSERT INTO staff ( id, forename, surname, salary ) "
+ "VALUES ( 1155, 'Ginger', 'Davis', 50000 )" );
+ if ( query.isActive() ) rows += query.numRowsAffected() ;
+
+ query.exec( "UPDATE staff SET salary=60000 WHERE id=1155" );
+ if ( query.isActive() ) rows += query.numRowsAffected() ;
+
+ query.exec( "DELETE FROM staff WHERE id=1155" );
+ if ( query.isActive() ) rows += query.numRowsAffected() ;
+ }
+
+ return ( rows == 3 ) ? 0 : 1;
+}
+
+
+
diff --git a/examples/sql/overview/connect1/README b/examples/sql/overview/connect1/README
new file mode 100644
index 0000000..eae3cd7
--- /dev/null
+++ b/examples/sql/overview/connect1/README
@@ -0,0 +1 @@
+This example is part of the overview in sql.html
diff --git a/examples/sql/overview/connect1/connect1.pro b/examples/sql/overview/connect1/connect1.pro
new file mode 100644
index 0000000..9e6df96
--- /dev/null
+++ b/examples/sql/overview/connect1/connect1.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../../include
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/connect1/main.cpp b/examples/sql/overview/connect1/main.cpp
new file mode 100644
index 0000000..c904902
--- /dev/null
+++ b/examples/sql/overview/connect1/main.cpp
@@ -0,0 +1,31 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include "../connection.h"
+
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv, FALSE );
+
+ QSqlDatabase *defaultDB = QSqlDatabase::addDatabase( DB_SALES_DRIVER );
+ defaultDB->setDatabaseName( DB_SALES_DBNAME );
+ defaultDB->setUserName( DB_SALES_USER );
+ defaultDB->setPassword( DB_SALES_PASSWD );
+ defaultDB->setHostName( DB_SALES_HOST );
+
+ if ( defaultDB->open() ) {
+ // Database successfully opened; we can now issue SQL commands.
+ }
+
+ return 0;
+}
+
diff --git a/examples/sql/overview/connection.cpp b/examples/sql/overview/connection.cpp
new file mode 100644
index 0000000..6afaa53
--- /dev/null
+++ b/examples/sql/overview/connection.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+#include <qsqldatabase.h>
+#include "connection.h"
+
+bool createConnections()
+{
+
+ QSqlDatabase *defaultDB = QSqlDatabase::addDatabase( DB_SALES_DRIVER );
+ defaultDB->setDatabaseName( DB_SALES_DBNAME );
+ defaultDB->setUserName( DB_SALES_USER );
+ defaultDB->setPassword( DB_SALES_PASSWD );
+ defaultDB->setHostName( DB_SALES_HOST );
+ if ( ! defaultDB->open() ) {
+ qWarning( "Failed to open sales database: " + defaultDB->lastError().text() );
+ return FALSE;
+ }
+
+ QSqlDatabase *oracle = QSqlDatabase::addDatabase( DB_ORDERS_DRIVER, "ORACLE" );
+ oracle->setDatabaseName( DB_ORDERS_DBNAME );
+ oracle->setUserName( DB_ORDERS_USER );
+ oracle->setPassword( DB_ORDERS_PASSWD );
+ oracle->setHostName( DB_ORDERS_HOST );
+ if ( ! oracle->open() ) {
+ qWarning( "Failed to open orders database: " + oracle->lastError().text() );
+ return FALSE;
+ }
+
+ QSqlQuery q(QString::null, defaultDB);
+ q.exec("create table people (id integer primary key, name char(40))");
+ q.exec("create table staff (id integer primary key, forename char(40), "
+ "surname char(40), salary float, statusid integer)");
+ q.exec("create table status (id integer primary key, name char(30))");
+ q.exec("create table creditors (id integer primary key, forename char(40), "
+ "surname char(40), city char(30))");
+ q.exec("create table prices (id integer primary key, name char(40), price float)");
+ q.exec("create table invoiceitem (id integer primary key, "
+ "pricesid integer, quantity integer, paiddate date)");
+
+ QSqlQuery q2(QString::null, oracle);
+ q2.exec("create table people (id integer primary key, name char(40))");
+
+ return TRUE;
+}
diff --git a/examples/sql/overview/connection.h b/examples/sql/overview/connection.h
new file mode 100644
index 0000000..e38ce6d
--- /dev/null
+++ b/examples/sql/overview/connection.h
@@ -0,0 +1,24 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+// Enter your connection info here
+
+#define DB_SALES_DRIVER "QSQLITE"
+#define DB_SALES_DBNAME ":memory:"
+#define DB_SALES_USER ""
+#define DB_SALES_PASSWD ""
+#define DB_SALES_HOST ""
+
+#define DB_ORDERS_DRIVER "QSQLITE"
+#define DB_ORDERS_DBNAME ":memory:"
+#define DB_ORDERS_USER ""
+#define DB_ORDERS_PASSWD ""
+#define DB_ORDERS_HOST ""
+
+bool createConnections();
diff --git a/examples/sql/overview/create_connections/README b/examples/sql/overview/create_connections/README
new file mode 100644
index 0000000..eae3cd7
--- /dev/null
+++ b/examples/sql/overview/create_connections/README
@@ -0,0 +1 @@
+This example is part of the overview in sql.html
diff --git a/examples/sql/overview/create_connections/create_connections.pro b/examples/sql/overview/create_connections/create_connections.pro
new file mode 100644
index 0000000..9e6df96
--- /dev/null
+++ b/examples/sql/overview/create_connections/create_connections.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../../include
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/create_connections/main.cpp b/examples/sql/overview/create_connections/main.cpp
new file mode 100644
index 0000000..01a60da
--- /dev/null
+++ b/examples/sql/overview/create_connections/main.cpp
@@ -0,0 +1,26 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include "../connection.h"
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv, FALSE );
+
+ if ( createConnections() ) {
+ // Databases successfully opened; get pointers to them:
+ QSqlDatabase *oracledb = QSqlDatabase::database( "ORACLE" );
+ // Now we can now issue SQL commands to the oracle connection
+ // or to the default connection
+ }
+
+ return 0;
+}
diff --git a/examples/sql/overview/custom1/custom1.pro b/examples/sql/overview/custom1/custom1.pro
new file mode 100644
index 0000000..c490bed
--- /dev/null
+++ b/examples/sql/overview/custom1/custom1.pro
@@ -0,0 +1,8 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+
+REQUIRES = full-config
+
+HEADERS = main.h
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/custom1/main.cpp b/examples/sql/overview/custom1/main.cpp
new file mode 100644
index 0000000..79c6ffe
--- /dev/null
+++ b/examples/sql/overview/custom1/main.cpp
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include "main.h"
+
+
+CustomEdit::CustomEdit( QWidget *parent, const char *name ) :
+ QLineEdit( parent, name )
+{
+ connect( this, SIGNAL(textChanged(const QString &)),
+ this, SLOT(changed(const QString &)) );
+}
+
+
+void CustomEdit::changed( const QString &line )
+{
+ setUpperLine( line );
+}
+
+
+void CustomEdit::setUpperLine( const QString &line )
+{
+ upperLineText = line.upper();
+ setText( upperLineText );
+}
+
+
+QString CustomEdit::upperLine() const
+{
+ return upperLineText;
+}
+
+
+FormDialog::FormDialog()
+{
+ QLabel *forenameLabel = new QLabel( "Forename:", this );
+ CustomEdit *forenameEdit = new CustomEdit( this );
+ QLabel *surnameLabel = new QLabel( "Surname:", this );
+ CustomEdit *surnameEdit = new CustomEdit( this );
+ QLabel *salaryLabel = new QLabel( "Salary:", this );
+ QLineEdit *salaryEdit = new QLineEdit( this );
+ salaryEdit->setAlignment( Qt::AlignRight );
+ QPushButton *saveButton = new QPushButton( "&Save", this );
+ connect( saveButton, SIGNAL(clicked()), this, SLOT(save()) );
+
+ QGridLayout *grid = new QGridLayout( this );
+ grid->addWidget( forenameLabel, 0, 0 );
+ grid->addWidget( forenameEdit, 0, 1 );
+ grid->addWidget( surnameLabel, 1, 0 );
+ grid->addWidget( surnameEdit, 1, 1 );
+ grid->addWidget( salaryLabel, 2, 0 );
+ grid->addWidget( salaryEdit, 2, 1 );
+ grid->addWidget( saveButton, 3, 0 );
+ grid->activate();
+
+ staffCursor = new QSqlCursor( "staff" );
+ staffCursor->setTrimmed( "forename", TRUE );
+ staffCursor->setTrimmed( "surname", TRUE );
+ idIndex = staffCursor->index( "id" );
+ staffCursor->select( idIndex );
+ staffCursor->first();
+
+ propMap = new QSqlPropertyMap;
+ propMap->insert( forenameEdit->className(), "upperLine" );
+
+ sqlForm = new QSqlForm( this );
+ sqlForm->setRecord( staffCursor->primeUpdate() );
+ sqlForm->installPropertyMap( propMap );
+ sqlForm->insert( forenameEdit, "forename" );
+ sqlForm->insert( surnameEdit, "surname" );
+ sqlForm->insert( salaryEdit, "salary" );
+ sqlForm->readFields();
+}
+
+
+FormDialog::~FormDialog()
+{
+ delete staffCursor;
+}
+
+
+void FormDialog::save()
+{
+ sqlForm->writeFields();
+ staffCursor->update();
+ staffCursor->select( idIndex );
+ staffCursor->first();
+}
+
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv );
+
+ if ( ! createConnections() )
+ return 1;
+
+ FormDialog *formDialog = new FormDialog();
+ formDialog->show();
+ app.setMainWidget( formDialog );
+
+ return app.exec();
+}
diff --git a/examples/sql/overview/custom1/main.h b/examples/sql/overview/custom1/main.h
new file mode 100644
index 0000000..ecbcd35
--- /dev/null
+++ b/examples/sql/overview/custom1/main.h
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qdialog.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qlineedit.h>
+#include <qpushbutton.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include <qsqlform.h>
+#include <qsqlpropertymap.h>
+#include "../connection.h"
+
+class CustomEdit : public QLineEdit
+{
+ Q_OBJECT
+ Q_PROPERTY( QString upperLine READ upperLine WRITE setUpperLine )
+ public:
+ CustomEdit( QWidget *parent=0, const char *name=0 );
+ QString upperLine() const;
+ void setUpperLine( const QString &line );
+ public slots:
+ void changed( const QString &line );
+ private:
+ QString upperLineText;
+};
+
+
+class FormDialog : public QDialog
+{
+ Q_OBJECT
+ public:
+ FormDialog();
+ ~FormDialog();
+ public slots:
+ void save();
+ private:
+ QSqlCursor *staffCursor;
+ QSqlForm *sqlForm;
+ QSqlPropertyMap *propMap;
+ QSqlIndex idIndex;
+};
+
+
diff --git a/examples/sql/overview/delete/README b/examples/sql/overview/delete/README
new file mode 100644
index 0000000..eae3cd7
--- /dev/null
+++ b/examples/sql/overview/delete/README
@@ -0,0 +1 @@
+This example is part of the overview in sql.html
diff --git a/examples/sql/overview/delete/delete.pro b/examples/sql/overview/delete/delete.pro
new file mode 100644
index 0000000..9e6df96
--- /dev/null
+++ b/examples/sql/overview/delete/delete.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../../include
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/delete/main.cpp b/examples/sql/overview/delete/main.cpp
new file mode 100644
index 0000000..94aeb32
--- /dev/null
+++ b/examples/sql/overview/delete/main.cpp
@@ -0,0 +1,29 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include "../connection.h"
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv, FALSE );
+
+ if ( createConnections() ) {
+ QSqlCursor cur( "prices" );
+ cur.select( "id=999" );
+ if ( cur.next() ) {
+ cur.primeDelete();
+ cur.del();
+ }
+ }
+
+ return 0;
+}
diff --git a/examples/sql/overview/extract/README b/examples/sql/overview/extract/README
new file mode 100644
index 0000000..eae3cd7
--- /dev/null
+++ b/examples/sql/overview/extract/README
@@ -0,0 +1 @@
+This example is part of the overview in sql.html
diff --git a/examples/sql/overview/extract/extract.pro b/examples/sql/overview/extract/extract.pro
new file mode 100644
index 0000000..c517268
--- /dev/null
+++ b/examples/sql/overview/extract/extract.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+DEPENDPATH =../../../include
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/extract/main.cpp b/examples/sql/overview/extract/main.cpp
new file mode 100644
index 0000000..3714c1a
--- /dev/null
+++ b/examples/sql/overview/extract/main.cpp
@@ -0,0 +1,41 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include "../connection.h"
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv, FALSE );
+
+ if ( createConnections() ) {
+ QSqlCursor cur( "creditors" );
+
+ QStringList orderFields = QStringList() << "surname" << "forename";
+ QSqlIndex order = cur.index( orderFields );
+
+ QStringList filterFields = QStringList() << "surname" << "city";
+ QSqlIndex filter = cur.index( filterFields );
+ cur.setValue( "surname", "Chirac" );
+ cur.setValue( "city", "Paris" );
+
+ cur.select( filter, order );
+
+ while ( cur.next() ) {
+ int id = cur.value( "id" ).toInt();
+ QString name = cur.value( "forename" ).toString() + " " +
+ cur.value( "surname" ).toString();
+ qDebug( QString::number( id ) + ": " + name );
+ }
+ }
+
+ return 0;
+}
diff --git a/examples/sql/overview/form1/form1.pro b/examples/sql/overview/form1/form1.pro
new file mode 100644
index 0000000..a6cd8cb
--- /dev/null
+++ b/examples/sql/overview/form1/form1.pro
@@ -0,0 +1,8 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/form1/main.cpp b/examples/sql/overview/form1/main.cpp
new file mode 100644
index 0000000..09b9f4c
--- /dev/null
+++ b/examples/sql/overview/form1/main.cpp
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qdialog.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qlineedit.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include <qsqlform.h>
+#include "../connection.h"
+
+class FormDialog : public QDialog
+{
+ public:
+ FormDialog();
+};
+
+
+FormDialog::FormDialog()
+{
+ QLabel *forenameLabel = new QLabel( "Forename:", this );
+ QLabel *forenameDisplay = new QLabel( this );
+ QLabel *surnameLabel = new QLabel( "Surname:", this );
+ QLabel *surnameDisplay = new QLabel( this );
+ QLabel *salaryLabel = new QLabel( "Salary:", this );
+ QLineEdit *salaryEdit = new QLineEdit( this );
+
+ QGridLayout *grid = new QGridLayout( this );
+ grid->addWidget( forenameLabel, 0, 0 );
+ grid->addWidget( forenameDisplay, 0, 1 );
+ grid->addWidget( surnameLabel, 1, 0 );
+ grid->addWidget( surnameDisplay, 1, 1 );
+ grid->addWidget( salaryLabel, 2, 0 );
+ grid->addWidget( salaryEdit, 2, 1 );
+ grid->activate();
+
+ QSqlCursor staffCursor( "staff" );
+ staffCursor.select();
+ staffCursor.next();
+
+ QSqlForm sqlForm( this );
+ sqlForm.setRecord( staffCursor.primeUpdate() );
+ sqlForm.insert( forenameDisplay, "forename" );
+ sqlForm.insert( surnameDisplay, "surname" );
+ sqlForm.insert( salaryEdit, "salary" );
+ sqlForm.readFields();
+}
+
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv );
+
+ if ( ! createConnections() ) return 1;
+
+ FormDialog *formDialog = new FormDialog();
+ formDialog->show();
+ app.setMainWidget( formDialog );
+
+ return app.exec();
+}
diff --git a/examples/sql/overview/form2/form2.pro b/examples/sql/overview/form2/form2.pro
new file mode 100644
index 0000000..c490bed
--- /dev/null
+++ b/examples/sql/overview/form2/form2.pro
@@ -0,0 +1,8 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+
+REQUIRES = full-config
+
+HEADERS = main.h
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/form2/main.cpp b/examples/sql/overview/form2/main.cpp
new file mode 100644
index 0000000..80bce49
--- /dev/null
+++ b/examples/sql/overview/form2/main.cpp
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include "main.h"
+
+FormDialog::FormDialog()
+ : staffCursor( "staff" )
+{
+ staffCursor.setTrimmed( "forename", TRUE );
+ staffCursor.setTrimmed( "surname", TRUE );
+
+ QLabel *forenameLabel = new QLabel( "Forename:", this );
+ QLineEdit *forenameEdit = new QLineEdit( this );
+ QLabel *surnameLabel = new QLabel( "Surname:", this );
+ QLineEdit *surnameEdit = new QLineEdit( this );
+ QLabel *salaryLabel = new QLabel( "Salary:", this );
+ QLineEdit *salaryEdit = new QLineEdit( this );
+ QPushButton *saveButton = new QPushButton( "&Save", this );
+ connect( saveButton, SIGNAL(clicked()), this, SLOT(save()) );
+
+ QGridLayout *grid = new QGridLayout( this );
+ grid->addWidget( forenameLabel, 0, 0 );
+ grid->addWidget( forenameEdit, 0, 1 );
+ grid->addWidget( surnameLabel, 1, 0 );
+ grid->addWidget( surnameEdit, 1, 1 );
+ grid->addWidget( salaryLabel, 2, 0 );
+ grid->addWidget( salaryEdit, 2, 1 );
+ grid->addWidget( saveButton, 3, 0 );
+ grid->activate();
+
+ idIndex = staffCursor.index( "id" );
+ staffCursor.select( idIndex );
+ staffCursor.first();
+
+ sqlForm = new QSqlForm( this );
+ sqlForm->setRecord( staffCursor.primeUpdate() );
+ sqlForm->insert( forenameEdit, "forename" );
+ sqlForm->insert( surnameEdit, "surname" );
+ sqlForm->insert( salaryEdit, "salary" );
+ sqlForm->readFields();
+}
+
+
+FormDialog::~FormDialog()
+{
+
+}
+
+
+void FormDialog::save()
+{
+ sqlForm->writeFields();
+ staffCursor.update();
+ staffCursor.select( idIndex );
+ staffCursor.first();
+}
+
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv );
+
+ if ( ! createConnections() )
+ return 1;
+
+ FormDialog *formDialog = new FormDialog();
+ formDialog->show();
+ app.setMainWidget( formDialog );
+
+ return app.exec();
+}
diff --git a/examples/sql/overview/form2/main.h b/examples/sql/overview/form2/main.h
new file mode 100644
index 0000000..c19a354
--- /dev/null
+++ b/examples/sql/overview/form2/main.h
@@ -0,0 +1,33 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qdialog.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qlineedit.h>
+#include <qpushbutton.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include <qsqlform.h>
+#include "../connection.h"
+
+class FormDialog : public QDialog
+{
+ Q_OBJECT
+ public:
+ FormDialog();
+ ~FormDialog();
+ public slots:
+ void save();
+ private:
+ QSqlCursor staffCursor;
+ QSqlForm *sqlForm;
+ QSqlIndex idIndex;
+};
diff --git a/examples/sql/overview/insert/README b/examples/sql/overview/insert/README
new file mode 100644
index 0000000..eae3cd7
--- /dev/null
+++ b/examples/sql/overview/insert/README
@@ -0,0 +1 @@
+This example is part of the overview in sql.html
diff --git a/examples/sql/overview/insert/insert.pro b/examples/sql/overview/insert/insert.pro
new file mode 100644
index 0000000..9e6df96
--- /dev/null
+++ b/examples/sql/overview/insert/insert.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../../include
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/insert/main.cpp b/examples/sql/overview/insert/main.cpp
new file mode 100644
index 0000000..7146bd1
--- /dev/null
+++ b/examples/sql/overview/insert/main.cpp
@@ -0,0 +1,37 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include "../connection.h"
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv, FALSE );
+
+ if ( createConnections() ) {
+ int count = 0;
+ QSqlCursor cur( "prices" );
+ QStringList names = QStringList() <<
+ "Screwdriver" << "Hammer" << "Wrench" << "Saw";
+ int id = 20;
+ for ( QStringList::Iterator name = names.begin();
+ name != names.end(); ++name ) {
+ QSqlRecord *buffer = cur.primeInsert();
+ buffer->setValue( "id", id );
+ buffer->setValue( "name", *name );
+ buffer->setValue( "price", 100.0 + (double)id );
+ count += cur.insert();
+ id++;
+ }
+ }
+
+ return 0;
+}
diff --git a/examples/sql/overview/insert2/insert2.pro b/examples/sql/overview/insert2/insert2.pro
new file mode 100644
index 0000000..9e6df96
--- /dev/null
+++ b/examples/sql/overview/insert2/insert2.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../../include
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/insert2/main.cpp b/examples/sql/overview/insert2/main.cpp
new file mode 100644
index 0000000..1b2ecdf
--- /dev/null
+++ b/examples/sql/overview/insert2/main.cpp
@@ -0,0 +1,29 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include "../connection.h"
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv, FALSE );
+
+ if ( createConnections() ) {
+ QSqlCursor cur( "prices" );
+ QSqlRecord *buffer = cur.primeInsert();
+ buffer->setValue( "id", 53981 );
+ buffer->setValue( "name", "Thingy" );
+ buffer->setValue( "price", 105.75 );
+ cur.insert();
+ }
+
+ return 0;
+}
diff --git a/examples/sql/overview/navigating/README b/examples/sql/overview/navigating/README
new file mode 100644
index 0000000..eae3cd7
--- /dev/null
+++ b/examples/sql/overview/navigating/README
@@ -0,0 +1 @@
+This example is part of the overview in sql.html
diff --git a/examples/sql/overview/navigating/main.cpp b/examples/sql/overview/navigating/main.cpp
new file mode 100644
index 0000000..26567bf
--- /dev/null
+++ b/examples/sql/overview/navigating/main.cpp
@@ -0,0 +1,33 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlquery.h>
+#include "../connection.h"
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv, FALSE );
+
+ if ( createConnections() ) {
+ QSqlQuery query( "SELECT id, name FROM people ORDER BY name" );
+ if ( ! query.isActive() ) return 1; // Query failed
+ int i;
+ i = query.size(); // In this example we have 9 records; i == 9.
+ query.first(); // Moves to the first record.
+ i = query.at(); // i == 0
+ query.last(); // Moves to the last record.
+ i = query.at(); // i == 8
+ query.seek( query.size() / 2 ); // Moves to the middle record.
+ i = query.at(); // i == 4
+ }
+
+ return 0;
+}
diff --git a/examples/sql/overview/navigating/navigating.pro b/examples/sql/overview/navigating/navigating.pro
new file mode 100644
index 0000000..9e6df96
--- /dev/null
+++ b/examples/sql/overview/navigating/navigating.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../../include
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/order1/README b/examples/sql/overview/order1/README
new file mode 100644
index 0000000..eae3cd7
--- /dev/null
+++ b/examples/sql/overview/order1/README
@@ -0,0 +1 @@
+This example is part of the overview in sql.html
diff --git a/examples/sql/overview/order1/main.cpp b/examples/sql/overview/order1/main.cpp
new file mode 100644
index 0000000..3d64748
--- /dev/null
+++ b/examples/sql/overview/order1/main.cpp
@@ -0,0 +1,32 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include "../connection.h"
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv, FALSE );
+
+ if ( createConnections() ) {
+ QSqlCursor cur( "staff" );
+ QStringList fields = QStringList() << "surname" << "forename";
+ QSqlIndex order = cur.index( fields );
+ cur.select( order );
+ while ( cur.next() ) {
+ qDebug( cur.value( "id" ).toString() + ": " +
+ cur.value( "surname" ).toString() + " " +
+ cur.value( "forename" ).toString() );
+ }
+ }
+
+ return 0;
+}
diff --git a/examples/sql/overview/order1/order1.pro b/examples/sql/overview/order1/order1.pro
new file mode 100644
index 0000000..9e6df96
--- /dev/null
+++ b/examples/sql/overview/order1/order1.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../../include
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/order2/README b/examples/sql/overview/order2/README
new file mode 100644
index 0000000..eae3cd7
--- /dev/null
+++ b/examples/sql/overview/order2/README
@@ -0,0 +1 @@
+This example is part of the overview in sql.html
diff --git a/examples/sql/overview/order2/main.cpp b/examples/sql/overview/order2/main.cpp
new file mode 100644
index 0000000..762562e
--- /dev/null
+++ b/examples/sql/overview/order2/main.cpp
@@ -0,0 +1,34 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include "../connection.h"
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv, FALSE );
+
+ if ( createConnections() ) {
+ QSqlCursor cur( "staff" );
+ QStringList fields = QStringList() << "id" << "forename";
+ QSqlIndex order = cur.index( fields );
+ QSqlIndex filter = cur.index( "surname" );
+ cur.setValue( "surname", "Bloggs" );
+ cur.select( filter, order );
+ while ( cur.next() ) {
+ qDebug( cur.value( "id" ).toString() + ": " +
+ cur.value( "surname" ).toString() + " " +
+ cur.value( "forename" ).toString() );
+ }
+ }
+
+ return 0;
+}
diff --git a/examples/sql/overview/order2/order2.pro b/examples/sql/overview/order2/order2.pro
new file mode 100644
index 0000000..9e6df96
--- /dev/null
+++ b/examples/sql/overview/order2/order2.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../../include
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/overview.pro b/examples/sql/overview/overview.pro
new file mode 100644
index 0000000..59be651
--- /dev/null
+++ b/examples/sql/overview/overview.pro
@@ -0,0 +1,33 @@
+TEMPLATE = subdirs
+
+CONFIG += ordered
+
+REQUIRES = full-config
+
+SUBDIRS = basicbrowsing \
+ basicbrowsing2 \
+ basicdatamanip \
+ connect1 \
+ create_connections \
+ custom1 \
+ delete \
+ extract \
+ form1 \
+ form2 \
+ insert \
+ insert2 \
+ navigating \
+ order1 \
+ order2 \
+ retrieve1 \
+ retrieve2 \
+ subclass1 \
+ subclass2 \
+ subclass3 \
+ subclass4 \
+ subclass5 \
+ table1 \
+ table2 \
+ table3 \
+ table4 \
+ update
diff --git a/examples/sql/overview/retrieve1/README b/examples/sql/overview/retrieve1/README
new file mode 100644
index 0000000..eae3cd7
--- /dev/null
+++ b/examples/sql/overview/retrieve1/README
@@ -0,0 +1 @@
+This example is part of the overview in sql.html
diff --git a/examples/sql/overview/retrieve1/main.cpp b/examples/sql/overview/retrieve1/main.cpp
new file mode 100644
index 0000000..b1cc06b
--- /dev/null
+++ b/examples/sql/overview/retrieve1/main.cpp
@@ -0,0 +1,30 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlquery.h>
+#include "../connection.h"
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv, FALSE );
+
+ if ( createConnections() ) {
+ QSqlQuery query( "SELECT id, surname FROM staff" );
+ if ( query.isActive() ) {
+ while ( query.next() ) {
+ qDebug( query.value(0).toString() + ": " +
+ query.value(1).toString() );
+ }
+ }
+ }
+
+ return 0;
+}
diff --git a/examples/sql/overview/retrieve1/retrieve1.pro b/examples/sql/overview/retrieve1/retrieve1.pro
new file mode 100644
index 0000000..9e6df96
--- /dev/null
+++ b/examples/sql/overview/retrieve1/retrieve1.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../../include
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/retrieve2/README b/examples/sql/overview/retrieve2/README
new file mode 100644
index 0000000..eae3cd7
--- /dev/null
+++ b/examples/sql/overview/retrieve2/README
@@ -0,0 +1 @@
+This example is part of the overview in sql.html
diff --git a/examples/sql/overview/retrieve2/main.cpp b/examples/sql/overview/retrieve2/main.cpp
new file mode 100644
index 0000000..69b172b
--- /dev/null
+++ b/examples/sql/overview/retrieve2/main.cpp
@@ -0,0 +1,30 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include "../connection.h"
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv );
+
+ if ( createConnections() ) {
+ QSqlCursor cur( "staff" ); // Specify the table/view name
+ cur.select(); // We'll retrieve every record
+ while ( cur.next() ) {
+ qDebug( cur.value( "id" ).toString() + ": " +
+ cur.value( "surname" ).toString() + " " +
+ cur.value( "salary" ).toString() );
+ }
+ }
+
+ return 0;
+}
diff --git a/examples/sql/overview/retrieve2/retrieve2.pro b/examples/sql/overview/retrieve2/retrieve2.pro
new file mode 100644
index 0000000..c58585e
--- /dev/null
+++ b/examples/sql/overview/retrieve2/retrieve2.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../../include
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/subclass1/main.cpp b/examples/sql/overview/subclass1/main.cpp
new file mode 100644
index 0000000..4d82695
--- /dev/null
+++ b/examples/sql/overview/subclass1/main.cpp
@@ -0,0 +1,38 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include <qdatatable.h>
+#include "../connection.h"
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv );
+
+ if ( createConnections() ) {
+ QSqlCursor invoiceItemCursor( "invoiceitem" );
+
+ QDataTable *invoiceItemTable = new QDataTable( &invoiceItemCursor );
+
+ app.setMainWidget( invoiceItemTable );
+
+ invoiceItemTable->addColumn( "pricesid", "PriceID" );
+ invoiceItemTable->addColumn( "quantity", "Quantity" );
+ invoiceItemTable->addColumn( "paiddate", "Paid" );
+
+ invoiceItemTable->refresh();
+ invoiceItemTable->show();
+
+ return app.exec();
+ }
+
+ return 1;
+}
diff --git a/examples/sql/overview/subclass1/subclass1.pro b/examples/sql/overview/subclass1/subclass1.pro
new file mode 100644
index 0000000..a6cd8cb
--- /dev/null
+++ b/examples/sql/overview/subclass1/subclass1.pro
@@ -0,0 +1,8 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/subclass2/main.cpp b/examples/sql/overview/subclass2/main.cpp
new file mode 100644
index 0000000..06016ba
--- /dev/null
+++ b/examples/sql/overview/subclass2/main.cpp
@@ -0,0 +1,42 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include "main.h"
+#include <qdatatable.h>
+
+InvoiceItemCursor::InvoiceItemCursor() :
+ QSqlCursor( "invoiceitem" )
+{
+ // NOOP
+}
+
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv );
+
+ if ( createConnections() ) {
+ InvoiceItemCursor invoiceItemCursor;
+
+ QDataTable *invoiceItemTable = new QDataTable( &invoiceItemCursor );
+
+ app.setMainWidget( invoiceItemTable );
+
+ invoiceItemTable->addColumn( "pricesid", "PriceID" );
+ invoiceItemTable->addColumn( "quantity", "Quantity" );
+ invoiceItemTable->addColumn( "paiddate", "Paid" );
+
+ invoiceItemTable->refresh();
+ invoiceItemTable->show();
+
+ return app.exec();
+ }
+
+ return 1;
+}
diff --git a/examples/sql/overview/subclass2/main.h b/examples/sql/overview/subclass2/main.h
new file mode 100644
index 0000000..024a651
--- /dev/null
+++ b/examples/sql/overview/subclass2/main.h
@@ -0,0 +1,23 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include "../connection.h"
+
+class QSqlRecord;
+
+class InvoiceItemCursor : public QSqlCursor
+{
+ public:
+ InvoiceItemCursor();
+};
+
+
diff --git a/examples/sql/overview/subclass2/subclass2.pro b/examples/sql/overview/subclass2/subclass2.pro
new file mode 100644
index 0000000..a6cd8cb
--- /dev/null
+++ b/examples/sql/overview/subclass2/subclass2.pro
@@ -0,0 +1,8 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/subclass3/main.cpp b/examples/sql/overview/subclass3/main.cpp
new file mode 100644
index 0000000..84f62ec
--- /dev/null
+++ b/examples/sql/overview/subclass3/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include "main.h"
+#include <qdatatable.h>
+
+InvoiceItemCursor::InvoiceItemCursor() :
+ QSqlCursor( "invoiceitem" )
+{
+ QSqlFieldInfo productName( "productname", QVariant::String );
+ append( productName );
+ setCalculated( productName.name(), TRUE );
+}
+
+
+QVariant InvoiceItemCursor::calculateField( const QString & name )
+{
+ if ( name == "productname" ) {
+ QSqlQuery query( "SELECT name FROM prices WHERE id=" +
+ field( "pricesid" )->value().toString() );
+ if ( query.next() )
+ return query.value( 0 );
+ }
+
+ return QVariant( QString::null );
+}
+
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv );
+
+ if ( createConnections() ) {
+ InvoiceItemCursor invoiceItemCursor;
+
+ QDataTable *invoiceItemTable = new QDataTable( &invoiceItemCursor );
+
+ app.setMainWidget( invoiceItemTable );
+
+ invoiceItemTable->addColumn( "productname", "Product" );
+ invoiceItemTable->addColumn( "quantity", "Quantity" );
+ invoiceItemTable->addColumn( "paiddate", "Paid" );
+
+ invoiceItemTable->refresh();
+ invoiceItemTable->show();
+
+ return app.exec();
+ }
+
+ return 1;
+}
diff --git a/examples/sql/overview/subclass3/main.h b/examples/sql/overview/subclass3/main.h
new file mode 100644
index 0000000..d84344a
--- /dev/null
+++ b/examples/sql/overview/subclass3/main.h
@@ -0,0 +1,25 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include "../connection.h"
+
+class QSqlRecord;
+
+class InvoiceItemCursor : public QSqlCursor
+{
+ public:
+ InvoiceItemCursor();
+ protected:
+ QVariant calculateField( const QString & name );
+};
+
+
diff --git a/examples/sql/overview/subclass3/subclass3.pro b/examples/sql/overview/subclass3/subclass3.pro
new file mode 100644
index 0000000..a6cd8cb
--- /dev/null
+++ b/examples/sql/overview/subclass3/subclass3.pro
@@ -0,0 +1,8 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/subclass4/main.cpp b/examples/sql/overview/subclass4/main.cpp
new file mode 100644
index 0000000..9a07eb0
--- /dev/null
+++ b/examples/sql/overview/subclass4/main.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include "main.h"
+#include <qdatatable.h>
+
+InvoiceItemCursor::InvoiceItemCursor() :
+ QSqlCursor( "invoiceitem" )
+{
+ QSqlFieldInfo productName( "productname", QVariant::String );
+ append( productName );
+ setCalculated( productName.name(), TRUE );
+
+ QSqlFieldInfo productPrice( "price", QVariant::Double );
+ append( productPrice );
+ setCalculated( productPrice.name(), TRUE );
+
+ QSqlFieldInfo productCost( "cost", QVariant::Double );
+ append( productCost );
+ setCalculated( productCost.name(), TRUE );
+}
+
+
+QVariant InvoiceItemCursor::calculateField( const QString & name )
+{
+
+ if ( name == "productname" ) {
+ QSqlQuery query( "SELECT name FROM prices WHERE id=" +
+ field( "pricesid" )->value().toString() );
+ if ( query.next() )
+ return query.value( 0 );
+ }
+ else if ( name == "price" ) {
+ QSqlQuery query( "SELECT price FROM prices WHERE id=" +
+ field( "pricesid" )->value().toString() );
+ if ( query.next() )
+ return query.value( 0 );
+ }
+ else if ( name == "cost" ) {
+ QSqlQuery query( "SELECT price FROM prices WHERE id=" +
+ field( "pricesid" )->value().toString() );
+ if ( query.next() )
+ return QVariant( query.value( 0 ).toDouble() *
+ value( "quantity").toDouble() );
+ }
+
+ return QVariant( QString::null );
+}
+
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv );
+
+ if ( createConnections() ) {
+ InvoiceItemCursor invoiceItemCursor;
+
+ QDataTable *invoiceItemTable = new QDataTable( &invoiceItemCursor );
+
+ app.setMainWidget( invoiceItemTable );
+
+ invoiceItemTable->addColumn( "productname", "Product" );
+ invoiceItemTable->addColumn( "price", "Price" );
+ invoiceItemTable->addColumn( "quantity", "Quantity" );
+ invoiceItemTable->addColumn( "cost", "Cost" );
+ invoiceItemTable->addColumn( "paiddate", "Paid" );
+
+ invoiceItemTable->refresh();
+ invoiceItemTable->show();
+
+ return app.exec();
+ }
+
+ return 1;
+}
diff --git a/examples/sql/overview/subclass4/main.h b/examples/sql/overview/subclass4/main.h
new file mode 100644
index 0000000..d84344a
--- /dev/null
+++ b/examples/sql/overview/subclass4/main.h
@@ -0,0 +1,25 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include "../connection.h"
+
+class QSqlRecord;
+
+class InvoiceItemCursor : public QSqlCursor
+{
+ public:
+ InvoiceItemCursor();
+ protected:
+ QVariant calculateField( const QString & name );
+};
+
+
diff --git a/examples/sql/overview/subclass4/subclass4.pro b/examples/sql/overview/subclass4/subclass4.pro
new file mode 100644
index 0000000..a6cd8cb
--- /dev/null
+++ b/examples/sql/overview/subclass4/subclass4.pro
@@ -0,0 +1,8 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/subclass5/main.cpp b/examples/sql/overview/subclass5/main.cpp
new file mode 100644
index 0000000..5c318a9
--- /dev/null
+++ b/examples/sql/overview/subclass5/main.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include "main.h"
+#include <qdatatable.h>
+
+InvoiceItemCursor::InvoiceItemCursor() :
+ QSqlCursor( "invoiceitem" )
+{
+ QSqlFieldInfo productName( "productname", QVariant::String );
+ append( productName );
+ setCalculated( productName.name(), TRUE );
+
+ QSqlFieldInfo productPrice( "price", QVariant::Double );
+ append( productPrice );
+ setCalculated( productPrice.name(), TRUE );
+
+ QSqlFieldInfo productCost( "cost", QVariant::Double );
+ append( productCost );
+ setCalculated( productCost.name(), TRUE );
+}
+
+
+QVariant InvoiceItemCursor::calculateField( const QString & name )
+{
+
+ if ( name == "productname" ) {
+ QSqlQuery query( "SELECT name FROM prices WHERE id=" +
+ field( "pricesid" )->value().toString() );
+ if ( query.next() )
+ return query.value( 0 );
+ }
+ else if ( name == "price" ) {
+ QSqlQuery query( "SELECT price FROM prices WHERE id=" +
+ field( "pricesid" )->value().toString() );
+ if ( query.next() )
+ return query.value( 0 );
+ }
+ else if ( name == "cost" ) {
+ QSqlQuery query( "SELECT price FROM prices WHERE id=" +
+ field( "pricesid" )->value().toString() );
+ if ( query.next() )
+ return QVariant( query.value( 0 ).toDouble() *
+ value( "quantity").toDouble() );
+ }
+
+ return QVariant( QString::null );
+}
+
+
+QSqlRecord *InvoiceItemCursor::primeInsert()
+{
+ QSqlRecord *buffer = editBuffer();
+ QSqlQuery query( "SELECT NEXTVAL( 'invoiceitem_seq' )" );
+ if ( query.next() )
+ buffer->setValue( "id", query.value( 0 ) );
+ buffer->setValue( "paiddate", QDate::currentDate() );
+ buffer->setValue( "quantity", 1 );
+
+ return buffer;
+}
+
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv );
+
+ if ( createConnections() ) {
+ InvoiceItemCursor invoiceItemCursor;
+
+ QDataTable *invoiceItemTable = new QDataTable( &invoiceItemCursor );
+
+ app.setMainWidget( invoiceItemTable );
+
+ invoiceItemTable->addColumn( "productname", "Product" );
+ invoiceItemTable->addColumn( "price", "Price" );
+ invoiceItemTable->addColumn( "quantity", "Quantity" );
+ invoiceItemTable->addColumn( "cost", "Cost" );
+ invoiceItemTable->addColumn( "paiddate", "Paid" );
+
+ invoiceItemTable->refresh();
+ invoiceItemTable->show();
+
+ return app.exec();
+ }
+
+ return 1;
+}
diff --git a/examples/sql/overview/subclass5/main.h b/examples/sql/overview/subclass5/main.h
new file mode 100644
index 0000000..48dab4e
--- /dev/null
+++ b/examples/sql/overview/subclass5/main.h
@@ -0,0 +1,25 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qdatetime.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include "../connection.h"
+
+class QSqlRecord;
+
+class InvoiceItemCursor : public QSqlCursor
+{
+ public:
+ InvoiceItemCursor();
+ QSqlRecord *primeInsert();
+ protected:
+ QVariant calculateField( const QString & name );
+};
diff --git a/examples/sql/overview/subclass5/subclass5.pro b/examples/sql/overview/subclass5/subclass5.pro
new file mode 100644
index 0000000..a6cd8cb
--- /dev/null
+++ b/examples/sql/overview/subclass5/subclass5.pro
@@ -0,0 +1,8 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/table1/main.cpp b/examples/sql/overview/table1/main.cpp
new file mode 100644
index 0000000..2334f54
--- /dev/null
+++ b/examples/sql/overview/table1/main.cpp
@@ -0,0 +1,31 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include <qdatatable.h>
+#include "../connection.h"
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv );
+
+ if ( createConnections() ) {
+ QSqlCursor staffCursor( "staff" );
+ QDataTable *staffTable = new QDataTable( &staffCursor, TRUE );
+ app.setMainWidget( staffTable );
+ staffTable->refresh();
+ staffTable->show();
+
+ return app.exec();
+ }
+
+ return 0;
+}
diff --git a/examples/sql/overview/table1/table1.pro b/examples/sql/overview/table1/table1.pro
new file mode 100644
index 0000000..a6cd8cb
--- /dev/null
+++ b/examples/sql/overview/table1/table1.pro
@@ -0,0 +1,8 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/table2/main.cpp b/examples/sql/overview/table2/main.cpp
new file mode 100644
index 0000000..2bc40eb
--- /dev/null
+++ b/examples/sql/overview/table2/main.cpp
@@ -0,0 +1,41 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include <qdatatable.h>
+#include "../connection.h"
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv );
+
+ if ( createConnections() ) {
+ QSqlCursor staffCursor( "staff" );
+
+ QDataTable *staffTable = new QDataTable( &staffCursor );
+
+ app.setMainWidget( staffTable );
+
+ staffTable->addColumn( "forename", "Forename" );
+ staffTable->addColumn( "surname", "Surname" );
+ staffTable->addColumn( "salary", "Annual Salary" );
+
+ QStringList order = QStringList() << "surname" << "forename";
+ staffTable->setSort( order );
+
+ staffTable->refresh();
+ staffTable->show();
+
+ return app.exec();
+ }
+
+ return 1;
+}
diff --git a/examples/sql/overview/table2/table2.pro b/examples/sql/overview/table2/table2.pro
new file mode 100644
index 0000000..a6cd8cb
--- /dev/null
+++ b/examples/sql/overview/table2/table2.pro
@@ -0,0 +1,8 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/table3/main.cpp b/examples/sql/overview/table3/main.cpp
new file mode 100644
index 0000000..03d0729
--- /dev/null
+++ b/examples/sql/overview/table3/main.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include "main.h"
+#include <qdatatable.h>
+
+StatusPicker::StatusPicker( QWidget *parent, const char *name )
+ : QComboBox( parent, name )
+{
+ QSqlCursor cur( "status" );
+ cur.select( cur.index( "name" ) );
+
+ int i = 0;
+ while ( cur.next() ) {
+ insertItem( cur.value( "name" ).toString(), i );
+ index2id[i] = cur.value( "id" ).toInt();
+ i++;
+ }
+}
+
+
+int StatusPicker::statusId() const
+{
+ return index2id[ currentItem() ];
+}
+
+
+void StatusPicker::setStatusId( int statusid )
+{
+ QMap<int,int>::Iterator it;
+ for ( it = index2id.begin(); it != index2id.end(); ++it ) {
+ if ( it.data() == statusid ) {
+ setCurrentItem( it.key() );
+ break;
+ }
+ }
+}
+
+
+
+QWidget *CustomSqlEditorFactory::createEditor(
+ QWidget *parent, const QSqlField *field )
+{
+ if ( field->name() == "statusid" ) {
+ QWidget *editor = new StatusPicker( parent );
+ return editor;
+ }
+
+ return QSqlEditorFactory::createEditor( parent, field );
+}
+
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv );
+
+ if ( createConnections() ) {
+ QSqlCursor staffCursor( "staff" );
+
+ QDataTable *staffTable = new QDataTable( &staffCursor );
+ QSqlPropertyMap *propMap = new QSqlPropertyMap();
+ CustomSqlEditorFactory *editorFactory = new CustomSqlEditorFactory();
+ propMap->insert( "StatusPicker", "statusid" );
+ staffTable->installPropertyMap( propMap );
+ staffTable->installEditorFactory( editorFactory );
+
+ app.setMainWidget( staffTable );
+
+ staffTable->addColumn( "forename", "Forename" );
+ staffTable->addColumn( "surname", "Surname" );
+ staffTable->addColumn( "salary", "Annual Salary" );
+ staffTable->addColumn( "statusid", "Status" );
+
+ QStringList order = QStringList() << "surname" << "forename";
+ staffTable->setSort( order );
+
+ staffTable->refresh();
+ staffTable->show();
+
+ return app.exec();
+ }
+
+ return 1;
+}
diff --git a/examples/sql/overview/table3/main.h b/examples/sql/overview/table3/main.h
new file mode 100644
index 0000000..3cee08d
--- /dev/null
+++ b/examples/sql/overview/table3/main.h
@@ -0,0 +1,40 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qcombobox.h>
+#include <qmap.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include <qsqleditorfactory.h>
+#include <qsqlpropertymap.h>
+#include "../connection.h"
+
+class StatusPicker : public QComboBox
+{
+ Q_OBJECT
+ Q_PROPERTY( int statusid READ statusId WRITE setStatusId )
+ public:
+ StatusPicker( QWidget *parent=0, const char *name=0 );
+ int statusId() const;
+ void setStatusId( int id );
+ private:
+ QMap< int, int > index2id;
+};
+
+
+class CustomSqlEditorFactory : public QSqlEditorFactory
+{
+ Q_OBJECT
+ public:
+ QWidget *createEditor( QWidget *parent, const QSqlField *field );
+};
+
+
+
diff --git a/examples/sql/overview/table3/table3.pro b/examples/sql/overview/table3/table3.pro
new file mode 100644
index 0000000..c490bed
--- /dev/null
+++ b/examples/sql/overview/table3/table3.pro
@@ -0,0 +1,8 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+
+REQUIRES = full-config
+
+HEADERS = main.h
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/table4/main.cpp b/examples/sql/overview/table4/main.cpp
new file mode 100644
index 0000000..1276c3d
--- /dev/null
+++ b/examples/sql/overview/table4/main.cpp
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include "main.h"
+
+
+StatusPicker::StatusPicker( QWidget *parent, const char *name )
+ : QComboBox( parent, name )
+{
+ QSqlCursor cur( "status" );
+ cur.select( cur.index( "name" ) );
+
+ int i = 0;
+ while ( cur.next() ) {
+ insertItem( cur.value( "name" ).toString(), i );
+ index2id[i] = cur.value( "id" ).toInt();
+ i++;
+ }
+}
+
+
+int StatusPicker::statusId() const
+{
+ return index2id[ currentItem() ];
+}
+
+
+void StatusPicker::setStatusId( int statusid )
+{
+ QMap<int,int>::Iterator it;
+ for ( it = index2id.begin(); it != index2id.end(); ++it ) {
+ if ( it.data() == statusid ) {
+ setCurrentItem( it.key() );
+ break;
+ }
+ }
+}
+
+
+void CustomTable::paintField( QPainter * p, const QSqlField* field,
+ const QRect & cr, bool b)
+{
+ if ( !field )
+ return;
+ if ( field->name() == "statusid" ) {
+ QSqlQuery query( "SELECT name FROM status WHERE id=" +
+ field->value().toString() );
+ QString text;
+ if ( query.next() ) {
+ text = query.value( 0 ).toString();
+ }
+ p->drawText( 2,2, cr.width()-4, cr.height()-4, fieldAlignment( field ), text );
+ }
+ else {
+ QDataTable::paintField( p, field, cr, b) ;
+ }
+}
+
+
+QWidget *CustomSqlEditorFactory::createEditor(
+ QWidget *parent, const QSqlField *field )
+{
+ if ( field->name() == "statusid" ) {
+ QWidget *editor = new StatusPicker( parent );
+ return editor;
+ }
+
+ return QSqlEditorFactory::createEditor( parent, field );
+}
+
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv );
+
+ if ( createConnections() ) {
+ QSqlCursor staffCursor( "staff" );
+
+ CustomTable *staffTable = new CustomTable( &staffCursor );
+ QSqlPropertyMap *propMap = new QSqlPropertyMap();
+ CustomSqlEditorFactory *editorFactory = new CustomSqlEditorFactory();
+ propMap->insert( "StatusPicker", "statusid" );
+ staffTable->installPropertyMap( propMap );
+ staffTable->installEditorFactory( editorFactory );
+
+ app.setMainWidget( staffTable );
+
+ staffTable->addColumn( "forename", "Forename" );
+ staffTable->addColumn( "surname", "Surname" );
+ staffTable->addColumn( "salary", "Annual Salary" );
+ staffTable->addColumn( "statusid", "Status" );
+
+ QStringList order = QStringList() << "surname" << "forename";
+ staffTable->setSort( order );
+
+ staffTable->refresh();
+ staffTable->show();
+
+ return app.exec();
+ }
+
+ return 1;
+}
diff --git a/examples/sql/overview/table4/main.h b/examples/sql/overview/table4/main.h
new file mode 100644
index 0000000..e175713
--- /dev/null
+++ b/examples/sql/overview/table4/main.h
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qcombobox.h>
+#include <qmap.h>
+#include <qpainter.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include <qsqleditorfactory.h>
+#include <qsqlpropertymap.h>
+#include <qdatatable.h>
+#include "../connection.h"
+
+class StatusPicker : public QComboBox
+{
+ Q_OBJECT
+ Q_PROPERTY( int statusid READ statusId WRITE setStatusId )
+public:
+ StatusPicker( QWidget *parent=0, const char *name=0 );
+ int statusId() const;
+ void setStatusId( int id );
+private:
+ QMap< int, int > index2id;
+};
+
+
+class CustomTable : public QDataTable
+{
+ Q_OBJECT
+public:
+ CustomTable(
+ QSqlCursor *cursor, bool autoPopulate = FALSE,
+ QWidget * parent = 0, const char * name = 0 ) :
+ QDataTable( cursor, autoPopulate, parent, name ) {}
+ void paintField(
+ QPainter * p, const QSqlField* field, const QRect & cr, bool );
+
+};
+
+
+class CustomSqlEditorFactory : public QSqlEditorFactory
+{
+ Q_OBJECT
+public:
+ QWidget *createEditor( QWidget *parent, const QSqlField *field );
+};
diff --git a/examples/sql/overview/table4/table4.pro b/examples/sql/overview/table4/table4.pro
new file mode 100644
index 0000000..c490bed
--- /dev/null
+++ b/examples/sql/overview/table4/table4.pro
@@ -0,0 +1,8 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+
+REQUIRES = full-config
+
+HEADERS = main.h
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/overview/update/README b/examples/sql/overview/update/README
new file mode 100644
index 0000000..eae3cd7
--- /dev/null
+++ b/examples/sql/overview/update/README
@@ -0,0 +1 @@
+This example is part of the overview in sql.html
diff --git a/examples/sql/overview/update/main.cpp b/examples/sql/overview/update/main.cpp
new file mode 100644
index 0000000..02cd303
--- /dev/null
+++ b/examples/sql/overview/update/main.cpp
@@ -0,0 +1,32 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qsqlcursor.h>
+#include "../connection.h"
+
+int main( int argc, char *argv[] )
+{
+ QApplication app( argc, argv, FALSE );
+
+ if ( createConnections() ) {
+ QSqlCursor cur( "prices" );
+ cur.select( "id=202" );
+ if ( cur.next() ) {
+ QSqlRecord *buffer = cur.primeUpdate();
+ double price = buffer->value( "price" ).toDouble();
+ double newprice = price * 1.05;
+ buffer->setValue( "price", newprice );
+ cur.update();
+ }
+ }
+
+ return 0;
+}
diff --git a/examples/sql/overview/update/update.pro b/examples/sql/overview/update/update.pro
new file mode 100644
index 0000000..9e6df96
--- /dev/null
+++ b/examples/sql/overview/update/update.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../../include
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp ../connection.cpp
diff --git a/examples/sql/sql.pro b/examples/sql/sql.pro
new file mode 100644
index 0000000..35f9291
--- /dev/null
+++ b/examples/sql/sql.pro
@@ -0,0 +1,9 @@
+TEMPLATE = subdirs
+
+CONFIG += ordered
+
+REQUIRES = full-config
+
+SUBDIRS = overview \
+ sqltable \
+ blob
diff --git a/examples/sql/sqltable/README b/examples/sql/sqltable/README
new file mode 100644
index 0000000..4fad463
--- /dev/null
+++ b/examples/sql/sqltable/README
@@ -0,0 +1,18 @@
+This SQL table example requires a connection to a SQL database.
+Modify main.cpp to connect to your specific database.
+
+This example program expects a table called 'simpletable' to exist in
+the database. You can create this table by running the following SQL
+script (modify to suit your backend, if necessary):
+
+drop table simpletable;
+create table simpletable
+(id number primary key,
+name varchar(20),
+address varchar(20) );
+
+-- optional, some sample data
+insert into simpletable (id, name, address)
+values (1, 'Trond', 'Oslo');
+insert into simpletable (id, name, address)
+values (2, 'Dave', 'Oslo');
diff --git a/examples/sql/sqltable/main.cpp b/examples/sql/sqltable/main.cpp
new file mode 100644
index 0000000..9c068aa
--- /dev/null
+++ b/examples/sql/sqltable/main.cpp
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qdatatable.h>
+#include <qsqlcursor.h>
+#include <qmessagebox.h>
+
+/* Modify the following to match your environment */
+#define DRIVER "QSQLITE" /* see the Qt SQL documentation for a list of available drivers */
+#define DATABASE ":memory:" /* the name of your database */
+#define USER "" /* user name with appropriate rights */
+#define PASSWORD "" /* password for USER */
+#define HOST "" /* host on which the database is running */
+
+class SimpleCursor : public QSqlCursor
+{
+public:
+ SimpleCursor () : QSqlCursor( "simpletable" ) {}
+protected:
+ QSqlRecord* primeInsert()
+ {
+ /* a real-world application would use sequences, or the like */
+ QSqlRecord* buf = QSqlCursor::primeInsert();
+ QSqlQuery q( "select max(id)+1 from simpletable" );
+ if ( q.next() )
+ buf->setValue( "id", q.value(0) );
+ return buf;
+ }
+};
+
+int main( int argc, char ** argv )
+{
+ QApplication a( argc, argv );
+
+ QSqlDatabase * db = QSqlDatabase::addDatabase( DRIVER );
+ db->setDatabaseName( DATABASE );
+ db->setUserName( USER );
+ db->setPassword( PASSWORD );
+ db->setHostName( HOST );
+
+ if( !db->open() ){
+ db->lastError().showMessage( "An error occured. Please read the README file in the sqltable"
+ "dir for more information.\n\n" );
+ return 1;
+ }
+
+ if (!db->tables().contains("simpletable")) {
+ QSqlQuery q("create table simpletable(id int, name varchar(20), address varchar(20))", db);
+ }
+
+ SimpleCursor cursor;
+
+ QDataTable table( &cursor ); /* data table uses our cursor */
+ table.addColumn( "name", "Name" );
+ table.addColumn( "address", "Address" );
+ table.setSorting( TRUE );
+
+ a.setMainWidget( &table );
+ table.refresh(); /* load data */
+ table.show(); /* show widget */
+
+ return a.exec();
+}
diff --git a/examples/sql/sqltable/sqltable.doc b/examples/sql/sqltable/sqltable.doc
new file mode 100644
index 0000000..bfa86f5
--- /dev/null
+++ b/examples/sql/sqltable/sqltable.doc
@@ -0,0 +1,24 @@
+/*
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+*/
+/*! \page sqltable-example.html
+
+ \ingroup sql-examples
+ \title SQL Table
+
+ This example shows how to use a QDataTable to browse data in a SQL database.
+
+ <hr>
+
+ Implementation:
+
+ \include sql/sqltable/main.cpp
+
+*/
diff --git a/examples/sql/sqltable/sqltable.pro b/examples/sql/sqltable/sqltable.pro
new file mode 100644
index 0000000..6a8c216
--- /dev/null
+++ b/examples/sql/sqltable/sqltable.pro
@@ -0,0 +1,10 @@
+TEMPLATE = app
+TARGET = sqltable
+
+CONFIG += qt warn_on release
+
+REQUIRES = full-config
+
+HEADERS =
+SOURCES = main.cpp
+INTERFACES =