Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
Search



Donate

Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Rockbox Ports are now being developed for various digital audio players!

+  Rockbox Technical Forums
|-+  Support and General Use
| |-+  Audio Playback, Database and Playlists
| | |-+  SQLite plugin
« previous next »
  • Print
Pages: [1]

Author Topic: SQLite plugin  (Read 2174 times)

Offline JamClerk

  • Member
  • *
  • Posts: 9
SQLite plugin
« on: July 23, 2012, 06:55:12 AM »
I am trying to implement a sqlite plugin - using the patch provided here: http://www.rockbox.org/tracker/task/8852

applying the patch was successful but now getting an error during 'make':

LD sqlite3test.rock
/home/ubuntu/Desktop/rockbox/rockbox/testSim/apps/plugins/sqlite3test.o: In function `exec':
sqlite3test.c:(.text+0xfc): undefined reference to `sqlite3_exec'
sqlite3test.c:(.text+0x10c): undefined reference to `sqlite3_free'
/home/ubuntu/Desktop/rockbox/rockbox/testSim/apps/plugins/sqlite3test.o: In function `plugin_start':
sqlite3test.c:(.text+0x130): undefined reference to `sqlite3_open'
sqlite3test.c:(.text+0x140): undefined reference to `sqlite3_close'
collect2: ld returned 1 exit status
make: *** [/home/ubuntu/Desktop/rockbox/rockbox/testSim/apps/plugins/sqlite3test.rock] Error 1

I'm new to developing in c and rockbox so anyone help me out here, thanks

sqlite3text.c looks like this:
Code: [Select]
#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

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; i<argc; i++){
        rb->snprintf(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(const void* parameter)
{
    (void)parameter;

    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;");

    return PLUGIN_OK;
}
Logged

Offline gevaerts

  • Administrator
  • Member
  • *
  • Posts: 1053
Re: SQLite plugin
« Reply #1 on: July 23, 2012, 07:38:38 AM »
Was applying the patch really successful? When I try, I get errors applying apps/plugins/lib/SOURCES and apps/plugins/SOURCES.

Also, did you get sqlite3.c and sqlite3.h as described?

Wich revision are you using? A quick test shows that for a current checkout you'll need to fix at least changed handling of the rb struct (i.e. remove all extern declatations in the new code) and replace uses of strncpy by strlcpy (after checking if it's a straight replacement), get rid of the MEM_FUNCTION_WRAPPERS() line, remove PLUGIN_HEADER, and change the plugin_start() function to the new form. After all that it builds for me.
Logged

Offline JamClerk

  • Member
  • *
  • Posts: 9
Re: SQLite plugin
« Reply #2 on: July 23, 2012, 09:20:46 AM »
wel i did get those two errors, but does updating the SOURCES file manually to include the patch not cure this?

i have the sqlite3.c/h downloaded and extracted into apps/plugins/lib

how do i check which revision im using? only started working with rockbox a week ago so should i be up to date?

if you look at the code i pasted in origional question you will see i already changed handling of struct and removed plugin_header, and updated the plugin_start function


apps/plugins/lib/sqlite3_aux.h and apps/plugins/lib/rockbox_vfs.c don't exist, is this because of the errors when applying patch?

thanks
Logged

Offline saratoga

  • Developer
  • Member
  • *
  • Posts: 8974
Re: SQLite plugin
« Reply #3 on: July 23, 2012, 11:29:51 AM »
Quote from: JamClerk on July 23, 2012, 09:20:46 AM
apps/plugins/lib/sqlite3_aux.h and apps/plugins/lib/rockbox_vfs.c don't exist, is this because of the errors when applying patch?

Looks like they're in the patch, so if you don't have them, its probably because the patch didn't apply.
Logged

Offline JamClerk

  • Member
  • *
  • Posts: 9
Re: SQLite plugin
« Reply #4 on: July 23, 2012, 11:47:59 AM »
have all required header files now created and rockbox built successfully, but when i put in on my sansa its full of problems:

my files only displays folders, not the music/ video or image files contained within the folders
songs are available through database but selecting one to play quickly flicks through entire list of songs without playing them
plugins lists show a 'no files' message, but they are all there in folders when plugged in to usb

any ideas what i could have broken?

thanks
Logged

Offline saratoga

  • Developer
  • Member
  • *
  • Posts: 8974
Re: SQLite plugin
« Reply #5 on: July 23, 2012, 11:50:21 AM »
Quote from: JamClerk on July 23, 2012, 11:47:59 AM
my files only displays folders, not the music/ video or image files contained within the folders

I'm guessing you have the view setting set to something like "playlists only". 
Logged

Offline JamClerk

  • Member
  • *
  • Posts: 9
Re: SQLite plugin
« Reply #6 on: July 24, 2012, 06:02:44 AM »
a fresh build fixed that problem, don't know what happened there,

but the sqlite plugin isn't owrking, it just crashed when run and displayed message 'Plugin returned error', im guessing that is coming from opening the file:
Code: [Select]
rc = sqlite3_open(DBFile, &db);
    if (rc)
    {
        sqlite3_close(db);
        return PLUGIN_ERROR;
    }

error being returned from sqlite3.c is 'no such vfs', what does this mean?

also how do i use the logf functionality for debugging? i looked in the system/debug menu but couldn't find any messages that i tried to write to logf
« Last Edit: July 24, 2012, 06:55:16 AM by JamClerk »
Logged

Offline torne

  • Developer
  • Member
  • *
  • Posts: 994
  • arf arf
Re: SQLite plugin
« Reply #7 on: July 24, 2012, 04:08:38 PM »
The vfs is the layer sqlite uses to access actual files (such as its database). When porting sqlite to a new platform you have to implement an appropriate vfs for that platform.

I haven't actually read the patch in question, but I'm guessing it's not correctly specifying the right vfs implementation to use.
Logged
some kind of ARM guy. ipodvideo/gigabeat-s/h120/clipv2. to save time let's assume i know everything.

  • Print
Pages: [1]
« previous next »
+  Rockbox Technical Forums
|-+  Support and General Use
| |-+  Audio Playback, Database and Playlists
| | |-+  SQLite plugin
 

  • SMF 2.0.17 | SMF © 2019, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.082 seconds with 14 queries.