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

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

Added SQL examples

File size: 1.1 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 <qsqlquery.h>
14#include "../connection.h"
15
16int main( int argc, char *argv[] )
17{
18 QApplication app( argc, argv, FALSE );
19
20 if ( createConnections() ) {
21 QSqlQuery query( "SELECT id, name FROM people ORDER BY name" );
22 if ( ! query.isActive() ) return 1; // Query failed
23 int i;
24 i = query.size(); // In this example we have 9 records; i == 9.
25 query.first(); // Moves to the first record.
26 i = query.at(); // i == 0
27 query.last(); // Moves to the last record.
28 i = query.at(); // i == 8
29 query.seek( query.size() / 2 ); // Moves to the middle record.
30 i = query.at(); // i == 4
31 }
32
33 return 0;
34}
Note: See TracBrowser for help on using the repository browser.