#include #include #include #include void print_result(sqlite3_stmt *stmt); int main(int argc, char **argv){ sqlite3 *db; //the database sqlite3_stmt *stmt_q; //the SQL statement int rc; rc = sqlite3_open("mydb.sql", &db); if( rc ){ fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); return 1; } char *sql_qry = "select * from mytable "\ "where id=?; "; rc = sqlite3_prepare_v2(db, sql_qry, -1, &stmt_q, 0); if (rc != SQLITE_OK) { fprintf(stderr, "Failed preparing statement: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); return 1; } /* iterate through different ids */ char input_id[100]; printf("enter id: "); fgets(input_id, 100, stdin); if (input_id[0] != 'q') do { /** * read in a 64-bit long integer */ unsigned long long _id = strtoull(input_id, (char**) NULL, 10); //https://en.cppreference.com/w/c/string/byte/strtoul sqlite3_bind_int64(stmt_q, 1, (sqlite3_int64) _id); /** * uncomment the line below to see the SQL statement with the bound parameters */ //printf("%s\n", sqlite3_expanded_sql(stmt_q)); while((rc = sqlite3_step(stmt_q)) == SQLITE_ROW) { int col; for(col=0; col