prev | Other interesting taks How to Use sqlite with C /* Program# 112 date : 14-01-2009 Classify Upper & lower case and digit until $ */ #include <stdio.h> //gcc `pkg-config --libs sqlite3` sqlite_with_c.c -o sqlite_with_c int main(void) { sqlite3 *conn; sqlite3_stmt *res; int error = 0; int rec_count = 0; const char *errMSG; const char *tail; error = sqlite3_open("db.sqlite3", &conn); if (error) { puts("Can not open database"); exit(0); } error = sqlite3_exec(conn, "update server set servername='s1' where ipaddress='192.168.0.000'", 0, 0, 0); if (error) { puts("Can not update table"); exit(0); } error = sqlite3_prepare_v2(conn, "select * from server", 1000, &res, &tail); if (error != SQLITE_OK) { puts("We did not get any data!"); exit(0); } puts("=========================="); while (sqlite3_step(res) == SQLITE_ROW) { printf("%s|", sqlite3_column_text(res, 0)); printf("%s|", sqlite3_column_text(res, 1)); printf("%s|", sqlite3_column_text(res, 2)); printf("%u\n", sqlite3_column_int(res, 3)); rec_count++; } puts("=========================="); printf("We received %d records.\n", rec_count); sqlite3_finalize(res); sqlite3_close(conn); return 0; } |