Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QtSql>
- #include <iostream>
- using namespace std;
- int main(int argc, char** argv) {
- QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
- db.setDatabaseName(":memory:");
- bool ok = db.open();
- if (ok) {
- QSqlQuery q(db);
- if (!q.exec("create table users (id int auto_increment primary key, username varchar(64) not null, password char(40) not null, admin bool default 0 not null);"))
- cout << "error1" << endl;
- if (!q.exec("insert into users (username, password) values ('foobar', 'c81c0eef7c0243fc309282e0bc1f2fd6836808dc');"))
- cout << "error2" << endl;
- if (!q.exec("select id, admin from users where username='foobar' and password = 'c81c0eef7c0243fc309282e0bc1f2fd6836808dc'"))
- cout << "error3" << endl;
- if (q.first()) {
- cout << "ok" << endl;
- QSqlRecord r = q.record();
- QString id = r.value("id").toString();
- //QString id = q.value(1).toString();
- qDebug() << id;
- }
- else
- cout << "ko" << endl;
- db.close();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment