diff options
Diffstat (limited to 'doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp')
-rw-r--r-- | doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp b/doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp new file mode 100644 index 0000000..7e6c913 --- /dev/null +++ b/doc/src/snippets/code/src_sql_kernel_qsqlresult.cpp @@ -0,0 +1,45 @@ +//! [0] +QSqlQuery q; +q.prepare("insert into test (i1, i2, s) values (?, ?, ?)"); + +QVariantList col1; +QVariantList col2; +QVariantList col3; + +col1 << 1 << 3; +col2 << 2 << 4; +col3 << "hello" << "world"; + +q.bindValue(0, col1); +q.bindValue(1, col2); +q.bindValue(2, col3); + +if (!q.execBatch()) + qDebug() << q.lastError(); +//! [0] + + +//! [1] +QSqlQuery query = ... +QVariant v = query.result()->handle(); +if (v.isValid() && qstrcmp(v.typeName(), "sqlite3_stmt*")) { + // v.data() returns a pointer to the handle + sqlite3_stmt *handle = *static_cast<sqlite3_stmt **>(v.data()); + if (handle != 0) { // check that it is not NULL + ... + } +} +//! [1] + + +//! [2] +if (v.typeName() == "PGresult*") { + PGresult *handle = *static_cast<PGresult **>(v.data()); + if (handle != 0) ... +} + +if (v.typeName() == "MYSQL_STMT*") { + MYSQL_STMT *handle = *static_cast<MYSQL_STMT **>(v.data()); + if (handle != 0) ... +} +//! [2] |