Skip to content Skip to sidebar Skip to footer

Dont Kown How To Fetch Database?

I'm complete beginner with sqlite and gtk. I'm making my 1st project in code::blocks. I have a problem in fetching the database my code is: #include #include

Solution 1:

sqlite3_exec is not suitable if you want to handle the returned data at the place where you are querying it, and has some other disadvantages.

For a query, you should always use sqlite3_prepare_v2, and then call sqlite3_step in a loop. To get variable values into the statement, use parameter markers (?) and the sqlite3_bind* functions. To read returned values, use the sqlite3_column_* functions (but in this case, you don't actually want to read any values).

char *user = "Supu";
char *password = "secret";
sqlite3_stmt *stmt;
constchar *sql = "SELECT username, password FROM user WHERE username = ? AND password = ?";
rc = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
if (rc != SQLITE_OK) {
    fprintf(stderr, "error: %s, %s\n", sql, sqlite3_errmsg(db));
} else {
    sqlite3_bind_text(stmt, 1, user, -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(stmt, 2, password, -1, SQLITE_TRANSIENT);
    while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
        printf("returned row: user = %s, password = %s\n",
               sqlite3_column_text(stmt, 0),
               sqlite3_column_text(stmt, 1));
        count++;
    }
    if (rc != SQLITE_DONE)
        fprintf(stderr, "error: %s\n", sqlite3_errmsg(db));
    sqlite3_finalize(stmt);
}

Post a Comment for "Dont Kown How To Fetch Database?"