From da0011de3ba74563d6b1e5598e509e96eb242853 Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Tue, 28 Sep 2010 18:38:10 +0200 Subject: [PATCH] Load our SQLite extension --- src/Makefile.am | 2 +- src/db.c | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 4656cd9c..0096fa36 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -34,7 +34,7 @@ ANTLR_SOURCES = \ ANTLR_PRODUCTS = forked_daapd_CPPFLAGS = -D_GNU_SOURCE @ZLIB_CFLAGS@ @AVAHI_CFLAGS@ @SQLITE3_CFLAGS@ @FFMPEG_CFLAGS@ @CONFUSE_CFLAGS@ @TAGLIB_CFLAGS@ @MINIXML_CFLAGS@ @LIBPLIST_CFLAGS@ @LIBGCRYPT_CFLAGS@ @ALSA_CFLAGS@ @OSS4CPPFLAGS@ \ - -DDATADIR="\"$(pkgdatadir)\"" -DCONFDIR="\"$(sysconfdir)\"" -DSTATEDIR="\"$(localstatedir)\"" + -DDATADIR="\"$(pkgdatadir)\"" -DCONFDIR="\"$(sysconfdir)\"" -DSTATEDIR="\"$(localstatedir)\"" -DPKGLIBDIR="\"$(pkglibdir)\"" forked_daapd_LDADD = @ZLIB_LIBS@ @AVAHI_LIBS@ @SQLITE3_LIBS@ @FFMPEG_LIBS@ @CONFUSE_LIBS@ @FLAC_LIBS@ @TAGLIB_LIBS@ @LIBEVENT_LIBS@ @LIBAVL_LIBS@ @MINIXML_LIBS@ @ANTLR3C_LIBS@ @LIBPLIST_LIBS@ @LIBGCRYPT_LIBS@ @ALSA_LIBS@ @LIBUNISTRING@ forked_daapd_SOURCES = main.c \ diff --git a/src/db.c b/src/db.c index 434eaabf..c0e4e08e 100644 --- a/src/db.c +++ b/src/db.c @@ -3757,6 +3757,7 @@ db_daap_unicode_xcollation(void *notused, int llen, const void *left, int rlen, int db_perthread_init(void) { + char *errmsg; int ret; ret = sqlite3_open(db_path, &hdl); @@ -3768,19 +3769,35 @@ db_perthread_init(void) return -1; } - ret = sqlite3_create_function(hdl, "daap_songalbumid", 2, SQLITE_UTF8, NULL, db_daap_songalbumid_xfunc, NULL, NULL); + ret = sqlite3_enable_load_extension(hdl, 1); if (ret != SQLITE_OK) { - DPRINTF(E_LOG, L_DB, "Could not create daap_songalbumid function: %s\n", sqlite3_errmsg(hdl)); + DPRINTF(E_LOG, L_DB, "Could not enable extension loading\n"); sqlite3_close(hdl); return -1; } - ret = sqlite3_create_collation(hdl, "DAAP", SQLITE_UTF8, NULL, db_daap_unicode_xcollation); + errmsg = NULL; + ret = sqlite3_load_extension(hdl, PKGLIBDIR "/forked-daapd-sqlext.so", NULL, &errmsg); if (ret != SQLITE_OK) { - DPRINTF(E_LOG, L_DB, "Could not create sqlite3 custom collation DAAP: %s\n", sqlite3_errmsg(hdl)); + if (errmsg) + { + DPRINTF(E_LOG, L_DB, "Could not load SQLite extension: %s\n", errmsg); + sqlite3_free(errmsg); + } + else + DPRINTF(E_LOG, L_DB, "Could not load SQLite extension: %s\n", sqlite3_errmsg(hdl)); + + sqlite3_close(hdl); + return -1; + } + + ret = sqlite3_enable_load_extension(hdl, 0); + if (ret != SQLITE_OK) + { + DPRINTF(E_LOG, L_DB, "Could not disable extension loading\n"); sqlite3_close(hdl); return -1;