12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #include <sqlite3.h>
- #include <stdio.h>
- #include <string.h>
- void datado(void) {
- sqlite3 *db;
- char sqlbuffer[256];
- sqlite3_stmt *stmt;
- int rc;
- const char *database = "test.db";
- rc = sqlite3_open(database, &db);
- if (rc) {
- printf("Error opening database %s : %s", database, sqlite3_errmsg(db));
- return;
- }
- // unsure
- sqlite3_busy_timeout(db, 5000);
- strcpy(sqlbuffer, "SELECT * FROM USER;");
- sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL);
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- // total columns = sqlite_3_column_count(stmt);
- int i = sqlite3_column_int(stmt, 0);
- printf("%s %d : %s %s / %s %s\n", sqlite3_column_name(stmt, 0), i,
- sqlite3_column_name(stmt, 1), sqlite3_column_text(stmt, 1),
- sqlite3_column_name(stmt, 2), sqlite3_column_text(stmt, 2));
- };
- sqlite3_finalize(stmt);
- // for now
- // NEXT!
- char nick[] = "Captain";
- strcpy(sqlbuffer, "SELECT id FROM USER WHERE nick=?");
- sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL);
- sqlite3_bind_text(stmt, 1, nick, strlen(nick), SQLITE_STATIC);
- rc = sqlite3_step(stmt);
- if (rc == SQLITE_ROW) {
- int nid = sqlite3_column_int(stmt, 0);
- printf("%s ID is %d\n", nick, nid);
- } else {
- printf("Unable to locate record.\n");
- }
- sqlite3_finalize(stmt);
- sqlite3_close(db);
- }
- int main(int argc, char *argv[]) {
- printf("Welcome.\n");
- datado();
- return 0;
- }
|