aboutsummaryrefslogtreecommitdiffstats
path: root/doc/codesnippets/doc/src/snippets/code/src_sql_kernel_qsqlquery.cpp
blob: 769f0be6cc3e752dd94a9da240900a2216cc812d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! [0]
SELECT forename, surname FROM people
//! [0]


//! [1]
q = QSqlQuery("select * from employees")
rec = q.record()

print "Number of columns: %d" % rec.count()

nameCol = rec.indexOf("name") # index of the field "name"
while q.next():
    print q.value(nameCol).toString() # output all names
//! [1]


//! [2]
q = QSqlQuery()
q.prepare("insert into myTable values (?, ?)")

QVariantList ints
ints << 1 << 2 << 3 << 4
q.addBindValue(ints)

QVariantList names
names << "Harald" << "Boris" << "Trond" << QVariant(QVariant.String)
q.addBindValue(names)

if not q.execBatch():
    print q.lastError()
//! [2]


//! [3]
1  Harald
2  Boris
3  Trond
4  NULL
//! [3]