samedi 5 septembre 2015

Sqlite with C, verify if data exsist in the table

I am building an application in C with sqlite database. I have a sqlite database where i stored many ip address(text).If a user input an ip address i want my application to check if that ip is inside the database.I could this pretty easy with Python but i cant produce same in C. Please find my code below.

sqlite3 *db;
sqlite3_stmt *res;
int rec_count = 0;
int rc;
char *errMSG;
const char *tail;
char *ip = "192.168.10.10";
int error = sqlite3_open("C:\\botdetect\\IP.db", &db);
if (error)
{
    fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
}

char *sql = "SELECT * FROM ipaddress WHERE IP=?";

sqlite3_prepare_v2(db, sql, -1, &res, 0);
sqlite3_bind_text(res, 1, ip, sizeof(ip), SQLITE_STATIC);
rc = sqlite3_step(res);

printf("rc is %d\n", rc);

sqlite3_finalize(res);

Aucun commentaire:

Enregistrer un commentaire