source: trunk/examples/sql/overview/extract/main.cpp

Last change on this file was 202, checked in by rudi, 14 years ago

Added SQL examples

File size: 1.3 KB
Line 
1/****************************************************************************
2** $Id: main.cpp 2051 2007-02-21 10:04:20Z chehrlic $
3**
4** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
5**
6** This file is part of an example program for Qt. This example
7** program may be used, distributed and modified without limitation.
8**
9*****************************************************************************/
10
11#include <qapplication.h>
12#include <qsqldatabase.h>
13#include <qsqlcursor.h>
14#include "../connection.h"
15
16int main( int argc, char *argv[] )
17{
18 QApplication app( argc, argv, FALSE );
19
20 if ( createConnections() ) {
21 QSqlCursor cur( "creditors" );
22
23 QStringList orderFields = QStringList() << "surname" << "forename";
24 QSqlIndex order = cur.index( orderFields );
25
26 QStringList filterFields = QStringList() << "surname" << "city";
27 QSqlIndex filter = cur.index( filterFields );
28 cur.setValue( "surname", "Chirac" );
29 cur.setValue( "city", "Paris" );
30
31 cur.select( filter, order );
32
33 while ( cur.next() ) {
34 int id = cur.value( "id" ).toInt();
35 QString name = cur.value( "forename" ).toString() + " " +
36 cur.value( "surname" ).toString();
37 qDebug( QString::number( id ) + ": " + name );
38 }
39 }
40
41 return 0;
42}
Note: See TracBrowser for help on using the repository browser.