From d796c9dd933ab96ec83b9a634feedd5d32e1ba3f Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Tue, 8 Nov 2011 12:31:36 -0600 Subject: Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731 --- examples/demo/sql/book.sql | 42 ++++++ examples/demo/sql/connect.ui | 244 ++++++++++++++++++++++++++++++++ examples/demo/sql/connect.ui.h | 20 +++ examples/demo/sql/sqlex.ui | 309 +++++++++++++++++++++++++++++++++++++++++ examples/demo/sql/sqlex.ui.h | 126 +++++++++++++++++ 5 files changed, 741 insertions(+) create mode 100644 examples/demo/sql/book.sql create mode 100644 examples/demo/sql/connect.ui create mode 100644 examples/demo/sql/connect.ui.h create mode 100644 examples/demo/sql/sqlex.ui create mode 100644 examples/demo/sql/sqlex.ui.h (limited to 'examples/demo/sql') diff --git a/examples/demo/sql/book.sql b/examples/demo/sql/book.sql new file mode 100644 index 000000000..417ef4347 --- /dev/null +++ b/examples/demo/sql/book.sql @@ -0,0 +1,42 @@ +-- The following SQL generates the database +-- used by the 'book' example programs +-- 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. + +DROP TABLE author; +DROP TABLE book; +DROP TABLE sequence; + +CREATE TABLE author +( id integer primary key, +forename varchar(40), +surname varchar(40) ); + +CREATE TABLE book +( id integer primary key, +title varchar(40), +price numeric(10,2), +authorid integer, +notes varchar(255) ); + +create index book_authorid_idx on book( authorid ); + +CREATE TABLE sequence +( tablename varchar(10), +sequence numeric); + +INSERT INTO author VALUES ( 0, 'Philip K', 'Dick' ); +INSERT INTO author VALUES ( 1, 'Robert', 'Heinlein' ); +INSERT INTO author VALUES ( 2, 'Sarah', 'Paretsky' ); + +INSERT INTO book VALUES ( 0, 'The Man Who Japed', 6.99, 0, 'A good book' ); +INSERT INTO book VALUES ( 1, 'The Man in the High Castle', 9.99, 0, 'Worth reading' ); +INSERT INTO book VALUES ( 2, 'The Number of the Beast', 8.99, 1, 'Get this!' ); +INSERT INTO book VALUES ( 3, 'Indemnity Only', 9.99, 2, 'Cool' ); +INSERT INTO book VALUES ( 4, 'Burn Marks', 9.99, 2, 'Need to make notes' ); +INSERT INTO book VALUES ( 5, 'Deadlock', 9.99, 2, 'Hmmm..' ); + +INSERT INTO sequence VALUES ( 'author', 2 ); +INSERT INTO sequence VALUES ( 'book', 5 ); diff --git a/examples/demo/sql/connect.ui b/examples/demo/sql/connect.ui new file mode 100644 index 000000000..ee875f318 --- /dev/null +++ b/examples/demo/sql/connect.ui @@ -0,0 +1,244 @@ + +ConnectDialog + + + ConnectDialog + + + + 0 + 0 + 303 + 247 + + + + Connect... + + + + unnamed + + + 11 + + + 6 + + + + GroupBox3 + + + Connection settings + + + + unnamed + + + 11 + + + 6 + + + + editDatabase + + + + + TextLabel3 + + + Database Name: + + + comboDatabase + + + + + editPassword + + + Password + + + + + TextLabel4 + + + &Username: + + + editUsername + + + + + TextLabel4_2 + + + &Password: + + + editPassword + + + + + comboDriver + + + + + editUsername + + + + + editHostname + + + + + TextLabel5 + + + &Hostname: + + + editHostname + + + + + TextLabel5_2 + + + P&ort: + + + portSpinBox + + + + + portSpinBox + + + Default + + + 65535 + + + -1 + + + -1 + + + + + TextLabel2 + + + D&river + + + comboDriver + + + + + + + Layout25 + + + + unnamed + + + 0 + + + 6 + + + + Spacer1 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + PushButton1 + + + &OK + + + true + + + + + PushButton2 + + + &Cancel + + + + + + + + + PushButton1 + clicked() + ConnectDialog + accept() + + + PushButton2 + clicked() + ConnectDialog + reject() + + + + comboDriver + editDatabase + editUsername + editPassword + editHostname + portSpinBox + PushButton1 + PushButton2 + + + connect.ui.h + + + init() + destroy() + + + diff --git a/examples/demo/sql/connect.ui.h b/examples/demo/sql/connect.ui.h new file mode 100644 index 000000000..cc1bce9bf --- /dev/null +++ b/examples/demo/sql/connect.ui.h @@ -0,0 +1,20 @@ +/**************************************************************************** +** ui.h extension file, included from the uic-generated form implementation. +** +** If you wish to add, delete or rename slots use TQt Designer which will +** update this file, preserving your code. Create an init() slot in place of +** a constructor, and a destroy() slot in place of a destructor. +*****************************************************************************/ + +#include + +void ConnectDialog::init() +{ + comboDriver->clear(); + comboDriver->insertStringList( TQSqlDatabase::drivers() ); +} + +void ConnectDialog::destroy() +{ + +} diff --git a/examples/demo/sql/sqlex.ui b/examples/demo/sql/sqlex.ui new file mode 100644 index 000000000..a7e972f8f --- /dev/null +++ b/examples/demo/sql/sqlex.ui @@ -0,0 +1,309 @@ + +SqlEx + + + SqlEx + + + + 0 + 0 + 654 + 438 + + + + Form1 + + + + unnamed + + + 11 + + + 6 + + + + vsplit + + + Vertical + + + + hsplit + + + Horizontal + + + + + Tables + + + true + + + true + + + + + Type + + + true + + + true + + + + + Retquired + + + true + + + true + + + + lv + + + 0 + + + true + + + true + + + LastColumn + + + + + dt + + + false + + + + + + gb + + + SQL Query + + + + unnamed + + + 11 + + + 6 + + + + Layout22 + + + + unnamed + + + 0 + + + 6 + + + + te + + + + + Layout21 + + + + unnamed + + + 0 + + + 6 + + + + Spacer3 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + submitBtn + + + + 5 + 0 + 0 + 0 + + + + + 80 + 0 + + + + &Submit + + + + + clearBtn + + + + 5 + 0 + 0 + 0 + + + + + 80 + 0 + + + + C&lear + + + + + + + + + + + + Layout23 + + + + unnamed + + + 0 + + + 6 + + + + lbl + + + Press "Connect" to open a database + + + + + conBtn + + + + 0 + 0 + 0 + 0 + + + + + 80 + 0 + + + + &Connect... + + + + + + + + + clearBtn + clicked() + te + clear() + + + conBtn + clicked() + SqlEx + dbConnect() + + + lv + returnPressed(TQListViewItem*) + SqlEx + showTable(TQListViewItem*) + + + lv + doubleClicked(TQListViewItem*) + SqlEx + showTable(TQListViewItem*) + + + submitBtn + clicked() + SqlEx + execQuery() + + + + sqlex.ui.h + + + init() + dbConnect() + execQuery() + showTable( TQListViewItem * item ) + + + diff --git a/examples/demo/sql/sqlex.ui.h b/examples/demo/sql/sqlex.ui.h new file mode 100644 index 000000000..b8e88ca91 --- /dev/null +++ b/examples/demo/sql/sqlex.ui.h @@ -0,0 +1,126 @@ +/**************************************************************************** +** ui.h extension file, included from the uic-generated form implementation. +** +** If you wish to add, delete or rename slots use TQt Designer which will +** update this file, preserving your code. Create an init() slot in place of +** a constructor, and a destroy() slot in place of a destructor. +*****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "connect.h" + +static void showError( const TQSqlError& err, TQWidget* parent = 0 ) +{ + TQString errStr ( "The database reported an error\n" ); + if ( !err.databaseText().isEmpty() ) + errStr += err.databaseText(); + if ( !err.driverText().isEmpty() ) + errStr += err.driverText(); + TQMessageBox::warning( parent, "Error", errStr ); +} + +ConnectDialog* conDiag = 0; + +void SqlEx::init() +{ + hsplit->setResizeMode( lv, TQSplitter::KeepSize ); + vsplit->setResizeMode( gb, TQSplitter::KeepSize ); + submitBtn->setEnabled( FALSE ); + conDiag = new ConnectDialog( this, "Connection Dialog", TRUE ); +} + +void SqlEx::dbConnect() +{ + if ( conDiag->exec() != TQDialog::Accepted ) + return; + if ( dt->sqlCursor() ) { + dt->setSqlCursor( 0 ); + } + // close old connection (if any) + if ( TQSqlDatabase::contains( "SqlEx" ) ) { + TQSqlDatabase* oldDb = TQSqlDatabase::database( "SqlEx" ); + oldDb->close(); + TQSqlDatabase::removeDatabase( "SqlEx" ); + } + // open the new connection + TQSqlDatabase* db = TQSqlDatabase::addDatabase( conDiag->comboDriver->currentText(), "SqlEx" ); + if ( !db ) { + TQMessageBox::warning( this, "Error", "Could not open database" ); + return; + } + db->setHostName( conDiag->editHostname->text() ); + db->setDatabaseName( conDiag->editDatabase->text() ); + db->setPort( conDiag->portSpinBox->value() ); + if ( !db->open( conDiag->editUsername->text(), conDiag->editPassword->text() ) ) { + showError( db->lastError(), this ); + return; + } + lbl->setText( "Double-Click on a table-name to view the contents" ); + lv->clear(); + + TQStringList tables = db->tables(); + for ( TQStringList::Iterator it = tables.begin(); it != tables.end(); ++it ) { + TQListViewItem* lvi = new TQListViewItem( lv, *it ); + TQSqlRecordInfo ri = db->recordInfo ( *it ); + for ( TQSqlRecordInfo::Iterator it = ri.begin(); it != ri.end(); ++it ) { + TQString req; + if ( (*it).isRetquired() > 0 ) { + req = "Yes"; + } else if ( (*it).isRetquired() == 0 ) { + req = "No"; + } else { + req = "?"; + } + TQListViewItem* fi = new TQListViewItem( lvi, (*it).name(), + TQVariant::typeToName( (*it).type() ), req ); + lvi->insertItem( fi ); + } + lv->insertItem( lvi ); + } + submitBtn->setEnabled( TRUE ); +} + +void SqlEx::execQuery() +{ + // use a custom cursor to populate the data table + TQSqlSelectCursor* cursor = new TQSqlSelectCursor( te->text(), TQSqlDatabase::database( "SqlEx", TRUE ) ); + if ( cursor->isSelect() ) { + dt->setSqlCursor( cursor, TRUE, TRUE ); + dt->setSort( TQStringList() ); + dt->refresh( TQDataTable::RefreshAll ); + TQString txt( "Query OK" ); + if ( cursor->size() >= 0 ) + txt += ", returned rows: " + TQString::number( cursor->size() ); + lbl->setText( txt ); + } else { + // an error occured if the cursor is not active + if ( !cursor->isActive() ) { + showError( cursor->lastError(), this ); + } else { + lbl->setText( TQString("Query OK, affected rows: %1").arg( cursor->numRowsAffected() ) ); + } + } +} + +void SqlEx::showTable( TQListViewItem * item ) +{ + // get the table name + TQListViewItem* i = item->parent(); + if ( !i ) { + i = item; + } + + // populate the data table + TQSqlCursor* cursor = new TQSqlCursor( i->text( 0 ), TRUE, TQSqlDatabase::database( "SqlEx", TRUE ) ); + dt->setSqlCursor( cursor, TRUE, TRUE ); + dt->setSort( cursor->primaryIndex() ); + dt->refresh( TQDataTable::RefreshAll ); + lbl->setText( "Displaying table " + i->text( 0 ) ); +} -- cgit v1.2.3