No encontre un subforo adecuado para este tema, así que lo posteé aquí. Disculpen si aquí no iba. XD. El código es el siguiente:
Código
#include <stdio.h> #include <stdlib.h> #include <strings.h> #include <sqlite3.h> ///Global variables sqlite3 *db; char *zErrMsg = 0; int rc; char sql[128]; ///Used to extract interesting data from callbacks. int number_of_rows_fetched; int money; int money2; const char *data = "Callback function called!!\n"; ///This function is called each time that a row if found. ///The only way to keep tracking how many rows has the table, ///it's increasing the counter. static int callback(void *data, int argc, char **argv, char **azColName){ printf("Callback is running!!\n"); return 0; } int init(){ ///Open database rc = sqlite3_open("bank.db", &db); if(rc != SQLITE_OK){ fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); exit(0); }else{ fprintf(stderr, "Opened database successfully\n"); } ///Create Table if it doesn't exist memset(sql, 0, sizeof(sql)); strcat(sql, "CREATE TABLE accounts(" \ "id INT NOT NULL," \ "username TEXT NOT NULL," \ "password TEXT NOT NULL," \ "cash INT);"); ///Run query rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg); printf("After the crash, i still alive\n"); if( rc != SQLITE_OK ){ fprintf(stderr, "SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); }else{ fprintf(stdout, "Table created successfully\n"); } } int main(int argc, char* argv[]) { init(); return 0; }
Realmente he tenido dudas sobre si este tópico iría en este subforo, pero como no encuentro algo relacionado con Bases de Datos directamente, quise postearlo aqui.
Gracias de antemano.