Index: apps/plugins/CATEGORIES =================================================================== --- apps/plugins/CATEGORIES (révision 16972) +++ apps/plugins/CATEGORIES (copie de travail) @@ -74,6 +74,7 @@ sort,viewers spacerocks,games splitedit,apps +sqlite3test,apps star,games starfield,demos stats,apps Index: apps/plugins/sqlite3test.c =================================================================== --- apps/plugins/sqlite3test.c (révision 0) +++ apps/plugins/sqlite3test.c (révision 0) @@ -0,0 +1,96 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: helloworld.c 12807 2007-03-16 21:56:08Z amiconn $ + * + * Copyright (C) 2002 Björn Stenberg + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "plugin.h" +#include "sqlite3.h" + +#ifdef ROCKBOX_HAS_LOGF +#define LOGF_ENABLE +#define logf rb->logf +#else +#define logf(f,args...) DEBUGF(f"\n",##args) +#endif + +extern int rockbox_register(int isDefault, struct plugin_api *api); + +PLUGIN_HEADER + +static struct plugin_api* rb; + +static int callback(void *NotUsed, int argc, char **argv, char **azColName){ + int fd = rb->open("/out", O_CREAT|O_WRONLY|O_APPEND); + char buf[512]; + int i, ret; + for(i=0; isnprintf(buf, sizeof(buf), "%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); + ret = rb->write(fd, buf, rb->strlen(buf)); + } + rb->close(fd); + return 0; +} + +static int exec(sqlite3 *db, const char *command) +{ + char *zErrMsg = 0; + int rc = sqlite3_exec(db, command, callback, 0, &zErrMsg); + + if (zErrMsg) { + logf("%s", zErrMsg); + } + + if (rc!=SQLITE_OK) { + sqlite3_free(zErrMsg); + } + + return rc; +} + +/* this is the plugin entry point */ +enum plugin_status plugin_start(struct plugin_api* api, void* parameter) +{ + (void)parameter; + + rb = api; + + rockbox_register(true, rb); + + int rc; + sqlite3 *db; + + rc = sqlite3_open("/test.db", &db); + if (rc) { + sqlite3_close(db); + return PLUGIN_ERROR; + } + + logf("DB opened"); + + + rc = exec(db, "create table tbl1(one varchar(10), two smallint);"); + rc = exec(db, "insert into tbl1 values('hello!',10);"); + rc = exec(db, "insert into tbl1 values('goodbye', 20);"); + rc = exec(db, "select * from tbl1;"); + + /* rc = sqlite3_exec(db, "select * from sqlite_master;", callback, 0, &zErrMsg); + if (rc!=SQLITE_OK) { + sqlite3_free(zErrMsg); + } + */ + + return PLUGIN_OK; +} Index: apps/plugins/lib/SOURCES =================================================================== --- apps/plugins/lib/SOURCES (révision 16972) +++ apps/plugins/lib/SOURCES (copie de travail) @@ -36,3 +36,5 @@ #endif pluginlib_actions.c helper.c +sqlite3.c +rockbox_vfs.c \ Pas de fin de ligne à la fin du fichier Index: apps/plugins/lib/sqlite3_aux.h =================================================================== --- apps/plugins/lib/sqlite3_aux.h (révision 0) +++ apps/plugins/lib/sqlite3_aux.h (révision 0) @@ -0,0 +1,63 @@ +#include "plugin.h" +struct plugin_api* rb; +#define OS_OTHER 1 +#define SQLITE_MEMORY_SIZE 75*1024 +#define SQLITE_OMIT_DATETIME_FUNCS +/* +#define SQLITE_OMIT_AUTHORIZATION +#define SQLITE_OMIT_AUTOVACUUM +#define SQLITE_OMIT_AUTOINCREMENT +#define SQLITE_OMIT_BLOB_LITERAL +#define SQLITE_OMIT_COMPLETE +#define SQLITE_OMIT_COMPOUND_SELECT +#define SQLITE_OMIT_CONFLICT_CLAUSE +#define SQLITE_OMIT_EXPLAIN +#define SQLITE_OMIT_FLOATING_POINT +#define SQLITE_OMIT_FOREIGN_KEY +#define SQLITE_OMIT_INTEGRITY_CHECK +#define SQLITE_OMIT_MEMORYDB +#define SQLITE_OMIT_PAGER_PRAGMAS +#define SQLITE_OMIT_PRAGMA +#define SQLITE_OMIT_PROGRESS_CALLBACK +#define SQLITE_OMIT_REINDEX +#define SQLITE_OMIT_SCHEMA_PRAGMAS +#define SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS +#define SQLITE_OMIT_SUBQUERY +#define SQLITE_OMIT_TCL_VARIABLE +#define SQLITE_OMIT_TRIGGER +#define SQLITE_OMIT_UTF16 +#define SQLITE_OMIT_VACUUM +#define SQLITE_OMIT_VIEW +*/ + +// wrappers + +MEM_FUNCTION_WRAPPERS(rb) + +size_t strlen(const char *s) +{ + return rb->strlen(s); +} +int strcmp(const char *s1, const char *s2) +{ + return rb->strcmp(s1,s2); +} +int atoi(const char *nptr) +{ + return rb->atoi(nptr); +} + +// stubs +time_t time(time_t *tloc) +{ + return 0; +} +struct tm *gmtime(const time_t *timep) +{ + return 0; +} +size_t strftime(char *s, size_t max, const char *format, + const struct tm *tm) +{ + return 0; +} Index: apps/plugins/lib/rockbox_vfs.c =================================================================== --- apps/plugins/lib/rockbox_vfs.c (révision 0) +++ apps/plugins/lib/rockbox_vfs.c (révision 0) @@ -0,0 +1,451 @@ + +#include "sqlite3.h" +#include "plugin.h" + +#ifdef ROCKBOX_HAS_LOGF +#define LOGF_ENABLE +#define logf rb->logf +#else +#define logf(f,args...) DEBUGF(f"\n",##args) +#endif + +/* + ** Maximum pathname length supported by the rockbox backend. + */ +#define ROCKBOX_MAX_PATHNAME MAX_PATH + +/* + ** Name used to identify this VFS. + */ +#define ROCKBOX_VFS_NAME "rockbox" + +typedef struct rockbox_file rockbox_file; +struct rockbox_file { + sqlite3_file base; + int fd; +}; + +struct plugin_api *rb; + +/* + ** Method declarations for rockbox_file. + */ +static int rockboxClose(sqlite3_file*); +static int rockboxRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); +static int rockboxWrite(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst); +static int rockboxTruncate(sqlite3_file*, sqlite3_int64 size); +static int rockboxSync(sqlite3_file*, int flags); +static int rockboxFileSize(sqlite3_file*, sqlite3_int64 *pSize); +static int rockboxLock(sqlite3_file*, int); +static int rockboxUnlock(sqlite3_file*, int); +static int rockboxCheckReservedLock(sqlite3_file*); +static int rockboxFileControl(sqlite3_file*, int op, void *pArg); +static int rockboxSectorSize(sqlite3_file*); +static int rockboxDeviceCharacteristics(sqlite3_file*); + +/* + ** Method declarations for rockbox_vfs. + */ +static int rockboxOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *); +static int rockboxDelete(sqlite3_vfs*, const char *zName, int syncDir); +static int rockboxAccess(sqlite3_vfs*, const char *zName, int flags); +static int rockboxGetTempName(sqlite3_vfs *pVfs, int nBufOut, char *zBufOut); +static int rockboxFullPathname(sqlite3_vfs*, const char *zPath, int nOut, char *zOut); +static void *rockboxDlOpen(sqlite3_vfs*, const char *zFilename); +static void rockboxDlError(sqlite3_vfs*, int nByte, char *zErrMsg); +static void *rockboxDlSym(sqlite3_vfs*,void*, const char *zSymbol); +static void rockboxDlClose(sqlite3_vfs*, void*); +static int rockboxRandomness(sqlite3_vfs*, int nByte, char *zOut); +static int rockboxSleep(sqlite3_vfs*, int microseconds); +static int rockboxCurrentTime(sqlite3_vfs*, double*); + +static sqlite3_vfs rockbox_vfs = { + 1, /* iVersion */ + sizeof(rockbox_file), /* szOsFile */ + ROCKBOX_MAX_PATHNAME, /* mxPathname */ + 0, /* pNext */ + ROCKBOX_VFS_NAME, /* zName */ + 0, /* pAppData */ + rockboxOpen, /* xOpen */ + rockboxDelete, /* xDelete */ + rockboxAccess, /* xAccess */ + rockboxGetTempName, /* xGetTempName */ + rockboxFullPathname, /* xFullPathname */ + rockboxDlOpen, /* xDlOpen */ + rockboxDlError, /* xDlError */ + rockboxDlSym, /* xDlSym */ + rockboxDlClose, /* xDlClose */ + rockboxRandomness, /* xRandomness */ + rockboxSleep, /* xSleep */ + rockboxCurrentTime /* xCurrentTime */ +}; + +static sqlite3_io_methods rockbox_io_methods = { + 1, /* iVersion */ + rockboxClose, /* xClose */ + rockboxRead, /* xRead */ + rockboxWrite, /* xWrite */ + rockboxTruncate, /* xTruncate */ + rockboxSync, /* xSync */ + rockboxFileSize, /* xFileSize */ + rockboxLock, /* xLock */ + rockboxUnlock, /* xUnlock */ + rockboxCheckReservedLock, /* xCheckReservedLock */ + rockboxFileControl, /* xFileControl */ + rockboxSectorSize, /* xSectorSize */ + rockboxDeviceCharacteristics /* xDeviceCharacteristics */ +}; + +/* + ** Close an rockbox-file. + */ +static int rockboxClose(sqlite3_file *pFile) +{ + logf("rockboxClose"); + + rb->close(((rockbox_file *)pFile)->fd); + return SQLITE_OK; +} + +/* + ** Read data from an rockbox-file. + */ +static int rockboxRead( + sqlite3_file *pFile, + void *zBuf, + int iAmt, + sqlite_int64 iOfst + ) +{ + logf("rockboxRead"); + + off_t newOffset = rb->lseek(((rockbox_file *)pFile)->fd, iOfst, SEEK_SET); + if (newOffset != iOfst) { + logf("rockboxRead: lseek failed. newOffset: %ld, iOfst: %ld", newOffset, iOfst); + return SQLITE_IOERR_READ; + } + + ssize_t got = rb->read(((rockbox_file *)pFile)->fd, zBuf, iAmt); + if (got == iAmt) { + return SQLITE_OK; + } else if (got < 0) { + logf("rockboxRead: read failed"); + return SQLITE_IOERR_READ; + } else { + rb->memset(&((char*)zBuf)[got], 0, iAmt-got); + return SQLITE_IOERR_SHORT_READ; + } +} + +/* + ** Write data to an rockbox-file. + */ +static int rockboxWrite( + sqlite3_file *pFile, + const void *zBuf, + int iAmt, + sqlite_int64 iOfst + ) +{ + logf("rockboxWrite"); + + int fd = ((rockbox_file *)pFile)->fd; + sqlite_int64 excess = iOfst - rb->filesize(fd); + + /* Contrary to unix's, rockbox's lseek doesn't allow seeking past the end + * of the file (this problem doesn't appear on the simulator because it + * uses the system lseek). + * As a workaround, we pad the file with zeros to reach the right position. + */ + if (excess > 0) { + logf("rockboxWrite: excess write"); + char buf[excess]; + rb->write(fd, buf, excess); + + } else { + off_t newOffset = rb->lseek(fd, iOfst, SEEK_SET); + logf("rockboxWrite: lseek, iOfst: %ld", iOfst); + + + if (newOffset != iOfst) { + logf("rockboxWrite: lseek failed. newOffset: %ld, iOfst: %ld", newOffset, iOfst); + return SQLITE_IOERR_READ; + } + } + + ssize_t wrote = rb->write(fd, zBuf, iAmt); + if (wrote < 0) { + logf("rockboxWrite: write failed"); + return SQLITE_IOERR_WRITE; + } + else{ + logf("rockboxWrite: wrote %ld", wrote); + return SQLITE_OK; + } +} + +/* + ** Truncate an rockbox-file. + */ +static int rockboxTruncate(sqlite3_file *pFile, sqlite_int64 size) +{ + logf("RockboxTruncate"); + + int fd = ((rockbox_file *)pFile)->fd; + int rc; + long excess = size - rb->filesize(fd); + + /* Contrary to unix's, rockbox's lseek doesn't allow seeking past the end + * of the file (this problem doesn't appear on the simulator because it + * uses the system lseek). + * As a workaround, we pad the file with zeros to reach the right position. + */ + if (excess > 0) { + char buf[excess]; + rb->memset(buf, 0, excess); + rb->lseek(fd, 0, SEEK_END); + rc = rb->write(fd, buf, excess); + if (rc < 0) + return SQLITE_IOERR_TRUNCATE; + else + return SQLITE_OK; + } else { + rc = rb->ftruncate(((rockbox_file *)pFile)->fd, (off_t)size); + if (rc) + return SQLITE_IOERR_TRUNCATE; + else + return SQLITE_OK; + } +} + +/* + ** Sync an rockbox-file. + */ +static int rockboxSync(sqlite3_file *pFile, int flags) +{ + logf("rockboxSync"); + return SQLITE_OK; +} + +/* + ** Return the current file-size of an rockbox-file. + */ +static int rockboxFileSize(sqlite3_file *pFile, sqlite_int64 *pSize) +{ + off_t rc = rb->filesize(((rockbox_file *)pFile)->fd); + + logf("rockboxFileSize: %ld", rc); + + if (rc < 0) + return SQLITE_IOERR_FSTAT; + else { + *pSize = (sqlite_int64)rc; + return SQLITE_OK; + } +} + +/* + ** Lock an rockbox-file. + */ +static int rockboxLock(sqlite3_file *pFile, int eLock) +{ + return SQLITE_OK; +} + +/* + ** Unlock an rockbox-file. + */ +static int rockboxUnlock(sqlite3_file *pFile, int eLock) +{ + return SQLITE_OK; +} + +/* + ** Check if another file-handle holds a RESERVED lock on an rockbox-file. + */ +static int rockboxCheckReservedLock(sqlite3_file *pFile) +{ + return SQLITE_OK; +} + +/* + ** File control method. For custom operations on an rockbox-file. + */ +static int rockboxFileControl(sqlite3_file *pFile, int op, void *pArg) +{ + return SQLITE_OK; +} + +/* + ** Return the sector-size in bytes for an rockbox-file. + */ +static int rockboxSectorSize(sqlite3_file *pFile) +{ + return SECTOR_SIZE; +} + +/* + ** Return the device characteristic flags supported by an rockbox-file. + */ +static int rockboxDeviceCharacteristics(sqlite3_file *pFile) +{ + logf("rockboxDeviceCharacteristics"); + return 0; +} + +/* + ** Open an rockbox file handle. + */ +static int rockboxOpen( + sqlite3_vfs *pVfs, + const char *zName, + sqlite3_file *pFile, + int flags, + int *pOutFlags + ) +{ + + logf("rockboxOpen"); + + int fd = 0; /* File descriptor returned by open() */ + int oflags = 0; /* Flags to pass to open() */ + + int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE); + int isCreate = (flags & SQLITE_OPEN_CREATE); + int isReadonly = (flags & SQLITE_OPEN_READONLY); + int isReadWrite = (flags & SQLITE_OPEN_READWRITE); + + if(isReadonly) oflags |= O_RDONLY; + if(isReadWrite) oflags |= O_RDWR; + if(isCreate) oflags |= O_CREAT; + + rb->memset(pFile, 0, sizeof(rockbox_file)); + fd = rb->open(zName, oflags); + if (fd < 0) { + + logf("rockboxOpen failed"); + + return SQLITE_CANTOPEN; + } + + ((rockbox_file *)pFile)->fd = fd; + pFile->pMethods = &rockbox_io_methods; + + return SQLITE_OK; +} + +/* + ** Delete the file located at zPath. If the dirSync argument is true, + ** ensure the file-system modifications are synced to disk before + ** returning. + */ +static int rockboxDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync) +{ + logf("rockboxDelete"); + return SQLITE_OK; +} + +/* + ** Test for access permissions. Return true if the requested permission + ** is available, or false otherwise. + */ +static int rockboxAccess(sqlite3_vfs *pVfs, const char *zPath, int flags){ + return 0; +} + +/* + ** Populate buffer zBufOut with a pathname suitable for use as a + ** temporary file. + */ +static int rockboxGetTempName(sqlite3_vfs *pVfs, int nBufOut, char *zBufOut) +{ + logf("rockboxGetTempName"); + rb->strncpy(zBufOut, "/.rockbox/temp", nBufOut); + return SQLITE_OK; +} + +/* + ** Populate buffer zOut with the full canonical pathname corresponding + ** to the pathname in zPath. + */ +static int rockboxFullPathname( + sqlite3_vfs *pVfs, /* Pointer to vfs object */ + const char *zPath, /* Possibly relative input path */ + int nOut, /* Size of output buffer in bytes */ + char *zOut /* Output buffer */ + ) +{ + logf("rockboxFullPathName"); + rb->strncpy(zOut, zPath, nOut); + return SQLITE_OK; +} + +/* + ** Open the dynamic library located at zPath and return a handle. + */ +static void *rockboxDlOpen(sqlite3_vfs *pVfs, const char *zPath) +{ + return 0; +} + +/* + ** Populate the buffer zErrMsg (size nByte bytes) with a human readable + ** utf-8 string describing the most recent error encountered associated + ** with dynamic libraries. + */ +static void rockboxDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg) +{ +} + +/* + ** Return a pointer to the symbol zSymbol in the dynamic library pHandle. + */ +static void *rockboxDlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol) +{ + return 0; +} + +/* + ** Close the dynamic library handle pHandle. + */ +static void rockboxDlClose(sqlite3_vfs *pVfs, void *pHandle) +{ +} + +/* + ** Populate the buffer pointed to by zBufOut with nByte bytes of + ** random data. + */ +static int rockboxRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut) +{ + return SQLITE_OK; +} + +/* + ** Sleep for nMicro microseconds. Return the number of microseconds + ** actually slept. + */ +static int rockboxSleep(sqlite3_vfs *pVfs, int nMicro) +{ + return 0; +} + +/* + ** Return the current time as a Julian Day number in *pTimeOut. + */ +static int rockboxCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut) +{ + return SQLITE_OK; +} + +/* + ** This procedure registers the rockbox vfs with SQLite. If the argument is + ** true, the rockbox vfs becomes the new default vfs. It is the only publicly + ** available function in this file. + */ +int rockbox_register(int isDefault, struct plugin_api *api) +{ + rb = api; + return sqlite3_vfs_register(&rockbox_vfs, isDefault); +} + Index: apps/plugins/SOURCES =================================================================== --- apps/plugins/SOURCES (révision 16972) +++ apps/plugins/SOURCES (copie de travail) @@ -19,6 +19,7 @@ stopwatch.c vbrfix.c viewer.c +sqlite3test.c #ifdef OLYMPUS_MROBE_500 /* remove these once the plugins before it are compileable */