I'm getting SQLITE_DONE
instead of getting SQLITE_ROW
while selecting a single record from db. And it also doesn't shows the returned row.
Tried to check with SQLITE_DONE and tried to print record but it was giving exception read access violation
which i have asked here
here is the code
int login() {
char username[50], password[50];
int i = 0;
char c;
cout << "Enter Username: ";
cin >> username;
cout << "Enter Password: ";
c = _getch();
while (c != 13) // for hiding password on console
{
password[i] = c;
i++;
cout << "*";
c = _getch();
}
sqlite3 * conn = NULL;
int res = sqlite3_open( "./mtbs.db" , &conn);
if (SQLITE_OK != res) {
printf("%s\n", sqlite3_errmsg(conn));
return res;
}
sqlite3_stmt * stmt = NULL;
char * sql = "SELECT id, username FROM admin WHERE username = ? AND password = ? LIMIT 1";
res = sqlite3_prepare_v2(conn,
sql,
-1,
&stmt,
NULL);
if (SQLITE_OK != res) {
printf("\n%s\n", sqlite3_errmsg(conn));
sqlite3_close(conn);
return res;
}
res = sqlite3_bind_text(stmt, 1, username, strlen(username), SQLITE_STATIC);
if (SQLITE_OK != res) {
printf("\n%s\n", sqlite3_errmsg(conn));
sqlite3_close(conn);
return res;
}
res = sqlite3_bind_text(stmt, 2, password, strlen(password), SQLITE_STATIC);
if(SQLITE_OK != res){
printf("\n%s\n", sqlite3_errmsg(conn));
sqlite3_close(conn);
return res;
}
if (SQLITE_ROW == sqlite3_step(stmt)) { // this ends up as SQLITE_DONE
cout<< endl << sqlite3_column_text(stmt, 0) << "\t" << sqlite3_column_text(stmt, 1) << endl;
}
sqlite3_finalize(stmt);
sqlite3_close(conn);
return 1;
}