View Single Post
Old 12-19-2011, 01:18 PM   #8
sumpin
Enthusiast
sumpin is a splendid one to beholdsumpin is a splendid one to beholdsumpin is a splendid one to beholdsumpin is a splendid one to beholdsumpin is a splendid one to beholdsumpin is a splendid one to beholdsumpin is a splendid one to beholdsumpin is a splendid one to beholdsumpin is a splendid one to beholdsumpin is a splendid one to beholdsumpin is a splendid one to behold
 
Posts: 25
Karma: 19952
Join Date: Sep 2011
Location: USA
Device: Kindle 3/5/PW, Nook ST/1, iPad 1/3
I wrote stubs for missing functions so I could add my collections.json created by the kindle collections calibre plug-in to cc.db. Worked without a problem with is_journaling_enabled returning 0 (or 1, for that matter).

/*
gcc -I/usr/local/include -L/usr/local/lib -Wl,-R/usr/local/lib -shared -fPIC -o libfoo.so foo.c
sqlite3: .load ./libfoo.so
*/
#include <stdio.h>
#include <sqlite3ext.h>
SQLITE_EXTENSION_INIT1

//is_journaling_enabled
static
void
ije(sqlite3_context *context, int argc, sqlite3_value **argv)
{
sqlite3_result_int(context, 0);
}

//json_string
static
void
js(sqlite3_context *context, int argc, sqlite3_value **argv)
{
const char *z = sqlite3_value_text(argv[0]);
sqlite3_result_text(context, z, -1, SQLITE_TRANSIENT);
}

//get_language_from_titles
static
void
glft(sqlite3_context *context, int argc, sqlite3_value **argv)
{
sqlite3_result_text(context, "en", -1, SQLITE_STATIC);
}

int
sqlite3_extension_init(sqlite3 *db, char **pzErrMsg,
const sqlite3_api_routines *pApi)
{
SQLITE_EXTENSION_INIT2(pApi)
if ( sqlite3_create_function(db, "is_journaling_enabled", 0, SQLITE_ANY, NULL, &ije, NULL, NULL) )
{
*pzErrMsg = sqlite3_mprintf("Can't create function: %s\n", sqlite3_errmsg(db));
return SQLITE_ERROR;
}
if ( sqlite3_create_function(db, "json_string", 1, SQLITE_ANY, NULL, &js, NULL, NULL) )
{
*pzErrMsg = sqlite3_mprintf("Can't create function: %s\n", sqlite3_errmsg(db));
return SQLITE_ERROR;
}
if ( sqlite3_create_function(db, "get_language_from_titles", 1, SQLITE_ANY, NULL, &glft, NULL, NULL) )
{
*pzErrMsg = sqlite3_mprintf("Can't create function: %s\n", sqlite3_errmsg(db));
return SQLITE_ERROR;
}
return SQLITE_OK;
}
sumpin is offline   Reply With Quote