sqlite disk I/O problem July 13, 2009 09:34PM | Registered: 16 years ago Posts: 48 |
#include#include #include #include #include "db.h" #include "sqlite3.h" static void *xfb = NULL; static GXRModeObj *rmode = NULL; sqlite3 *db; //--------------------------------------------------------------------------------- int main(int argc, char **argv) { //--------------------------------------------------------------------------------- VIDEO_Init(); WPAD_Init(); rmode = VIDEO_GetPreferredMode(NULL); xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(xfb); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); fatInitDefault(); printf("\x1b[2;0H"); printf("Hello World!"); DB_Open(); execQuery("select * from game", db); DB_Close(); while(1) { WPAD_ScanPads(); u32 pressed = WPAD_ButtonsDown(0); if ( pressed & WPAD_BUTTON_HOME ) exit(0); VIDEO_WaitVSync(); } return 0; }
#include "db.h" extern sqlite3 *db; // // HACK // // comment int _EXFUN(gettimeofday, (struct timeval *__p, void *__tz)); // in C:\devkitPro\devkitPPC\powerpc-gekko\include\sys\time.h // int gettimeofday(struct timeval *tp, struct timezone *tz) { if (tp != NULL) { tp->tv_sec = time(NULL); tp->tv_usec = 0; } if (tz != NULL) { tz->tz_minuteswest = 0; tz->tz_dsttime = 0; } return 0; } int DB_callback(void *NotUsed, int argc, char **argv, char **azColName) { NotUsed=0; int i; char merlo[255]; for(i=0; idb.h, argv ? argv: "NULL"); sprintf(merlo, "%s = %s\n", azColName, argv ? argv: "NULL"); } //WindowPrompt("OK?", merlo, 0, &okButton); printf("done\n"); return 0; } void execQuery(char* command, sqlite3* db) { char *zErrMsg = 0; //printf("%s", command); printf("pre\n"); int rc = sqlite3_exec(db, command, DB_callback, 0, &zErrMsg); //return; printf("post\n"); if(rc != SQLITE_OK) { //WindowPrompt("execQuery error", zErrMsg, 0, &okButton); printf("execQuery error %s\n", zErrMsg); /* This will free zErrMsg if assigned */ //if (zErrMsg) // free(zErrMsg); } else printf("DB QUERY OK\n"); } void DB_Open() { int rc; rc = sqlite3_open(DB_FILE, &db); if(rc) { printf("cannot open %s\n", (char*)sqlite3_errmsg(db)); //WindowPrompt("CANNOT OPEN", (char*)sqlite3_errmsg(db), 0, &okButton); sqlite3_close(db); } else printf("DB OPENED OK\n"); //else // WindowPrompt("OPEN OK", "Database opened!", 0, &okButton); } void DB_Close() { sqlite3_close(db); }
#ifndef __DB__ #define __DB__ #include "sqlite3.h" #include "time.h" #include <sys/time.h> #include#include #include #define DB_FILE "sd:/wiitdb.db" int DB_callback(void *NotUsed, int argc, char **argv, char **azColName); void execQuery(char* command, sqlite3* db); int gettimeofday(struct timeval *tp, struct timezone *tz); void DB_Open(); void DB_Close(); #endif
LIBS := -lfat -lwiiuse -lbte -logc -lm -lsqlite3 LIBDIRS := $(CURDIR)/libs/sqlite
Hello World!DB OPENED OK! pre post execQuery error disk I/O error
Re: sqlite disk I/O problem July 13, 2009 11:26PM | Registered: 16 years ago Posts: 78 |
s32 result; result = sqlite3_open_v2( "sd:/path/to/database.db", &db, SQLITE_OPEN_READONLY, "unix-none" ); OR result = sqlite3_open_v2( "sd:/path/to/database.db" , &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, "unix-none" ); if ( result != SQLITE_OK ) { /* error /* }
Re: sqlite disk I/O problem July 14, 2009 12:43AM | Registered: 16 years ago Posts: 48 |
library routine called out of sequence
Re: sqlite disk I/O problem July 18, 2009 09:31PM | Registered: 16 years ago Posts: 48 |
void getNameFromId(char* id, char* title){ char q[300]; sprintf(q, "select id, version, region, \ from table \ where id = '%s'", id); execQuery(q, db); } void execQuery(char* command, sqlite3* db) { char *zErrMsg = 0; int rc = sqlite3_exec(db, command, DB_callback, 0, &zErrMsg); if(rc != SQLITE_OK) { /* This crash if I use one of the free */ //if (zErrMsg) //free(zErrMsg); //sqlite3_free(zErrMsg); } } int DB_callback(void *NotUsed, int argc, char **argv, char **azColName) { NotUsed=0; int i; sprintf(cGame.id, argv[0]); sprintf(cGame.version, argv[1]); sprintf(cGame.region, argv[2]); return 0; }
Re: sqlite disk I/O problem July 19, 2009 12:01AM | Registered: 16 years ago Posts: 78 |
if(rc != SQLITE_OK) { /* This crash if I use one of the free */ //if (zErrMsg) //free(zErrMsg); //sqlite3_free(zErrMsg); }...crashes because you use free and then sqlite3_free on the same pointer. Just use sqlite3_free. You should print the error too; perhaps that will be a clue to the memory usage.
Re: sqlite disk I/O problem July 19, 2009 12:52AM | Registered: 16 years ago Posts: 48 |
Re: sqlite disk I/O problem July 19, 2009 05:41AM | Registered: 16 years ago Posts: 78 |
Re: sqlite disk I/O problem July 19, 2009 11:49AM | Registered: 16 years ago Posts: 48 |
Problem using sqlite (was Re: sqlite disk I/O problem) July 19, 2009 01:14PM | Registered: 16 years ago Posts: 48 |
DB OPENED OK RZDP01 PAL The Legend Of Zelda: Twilight Princess all: 1188 KB used: 1138 KB notused: 49 KB canfree: 38KB RMGP01 PAL Super Mario Galaxy all: 1188 KB used: 1141 KB notused: 46 KB canfree: 35KB RSPP01 PAL Wii Sports all: 1188 KB used: 1144 KB notused: 43 KB canfree: 30KB REXP01 PAL Excite Truck all: 1188 KB used: 1144 KB notused: 43 KB canfree: 30KB RMCP01 PAL Mario Kart Wii all: 1188 KB used: 1148 KB notused: 39 KB canfree: 30KB
Re: sqlite disk I/O problem July 19, 2009 02:31PM | Registered: 16 years ago Posts: 1,012 |
Quote
scognitochar *zErrMsg = 0; int rc = sqlite3_exec(db, command, DB_callback, 0, &zErrMsg); if(rc != SQLITE_OK) { /* This crash if I use one of the free */ //if (zErrMsg) //free(zErrMsg); //sqlite3_free(zErrMsg); }
Re: sqlite disk I/O problem July 19, 2009 02:47PM | Registered: 16 years ago Posts: 48 |
Re: sqlite disk I/O problem July 19, 2009 03:01PM | Registered: 16 years ago Posts: 1,012 |
to: but free(zErrMsg) will most likely not workQuote
but free(zErrMsg) can't work
Re: sqlite disk I/O problem July 19, 2009 03:20PM | Registered: 16 years ago Posts: 48 |
Re: sqlite disk I/O problem July 19, 2009 09:18PM | Registered: 16 years ago Posts: 48 |
Re: sqlite disk I/O problem July 19, 2009 11:53PM | Registered: 16 years ago Posts: 78 |
Re: sqlite disk I/O problem July 20, 2009 12:13AM | Registered: 16 years ago Posts: 1,012 |
If know next to nothing about sqlite, and nothing about mallinfo.Quote
scognito
Do you know anyway if you think it's normal I get the memory leak (almost) each time I execute a query!
Re: sqlite disk I/O problem July 22, 2009 07:28AM | Registered: 16 years ago Posts: 1,012 |
Re: sqlite disk I/O problem July 23, 2009 10:12AM | Registered: 16 years ago Posts: 48 |
Re: sqlite disk I/O problem July 23, 2009 10:34AM | Registered: 16 years ago Posts: 78 |
Re: sqlite disk I/O problem July 23, 2009 11:10AM | Registered: 16 years ago Posts: 48 |