· 9 years ago · Feb 16, 2017, 01:06 PM
1create table if not exists t_user (
2 username text,
3 password text
4);
5
6bool Foo(const QString &username, const QString &password)
7{
8 int res = 0;
9 sqlite3_stmt *stmt = NULL;
10 const char sql[] = "select count(username) from t_user where username = ? and password = ?;";
11 res = sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL);//res == SQLITE_OK
12
13 res = sqlite3_bind_text(stmt, 1, username.toUtf8().data(), username.toUtf8().size(), NULL);//res == SQLITE_OK
14 res = sqlite3_bind_text(stmt, 2, password.toUtf8().data(), password.toUtf8().size(), NULL);//res == SQLITE_OK
15
16 res = sqlite3_step(stmt);//res == SQLITE_ROW
17 res = sqlite3_column_int(stmt, 0);
18
19 sqlite3_finalize(stmt);
20 return res > 0;
21}