Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor some sqlite code

  • Loading branch information...
commit b49756e9a6086937e543301e780c2ccd49b2b58a 1 parent cf8a1f4
@andoma authored
View
14 src/db/db_support.c
@@ -85,14 +85,20 @@ db_step(sqlite3_stmt *pStmt)
}
int
-db_prepare(sqlite3 *db, const char *zSql, int nSql,
- sqlite3_stmt **ppStmt, const char **pz)
+db_preparex(sqlite3 *db, sqlite3_stmt **ppStmt, const char *zSql,
+ const char *file, int line)
{
int rc;
- while( SQLITE_LOCKED==(rc = sqlite3_prepare_v2(db, zSql, nSql, ppStmt, pz)) ){
+
+ while(SQLITE_LOCKED==(rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, NULL))) {
rc = wait_for_unlock_notify(db);
if( rc!=SQLITE_OK ) break;
}
+
+ if(rc != SQLITE_OK) {
+ TRACE(TRACE_ERROR, "SQLITE", "SQL Error %d at %s:%d",
+ rc, file, line);
+ }
return rc;
}
@@ -126,7 +132,7 @@ db_get_int64_from_query(sqlite3 *db, const char *query, int64_t *v)
sqlite3_stmt *stmt;
restart:
- rc = db_prepare(db, query, -1, &stmt, NULL);
+ rc = db_prepare(db, &stmt, query);
if(rc) {
if(rc == SQLITE_LOCKED)
goto restart;
View
7 src/db/db_support.h
@@ -19,8 +19,11 @@ int db_rollback_deadlock0(sqlite3 *db, const char *src);
int db_step(sqlite3_stmt *pStmt);
-int db_prepare(sqlite3 *db, const char *zSql, int nSql,
- sqlite3_stmt **ppStmt, const char **pz);
+int db_preparex(sqlite3 *db, sqlite3_stmt **ppStmt, const char *zSql,
+ const char *file, int line);
+
+
+#define db_prepare(db, stmt, sql) db_preparex(db, stmt, sql, __FILE__, __LINE__)
#define db_begin(db) db_begin0(db, __FUNCTION__)
#define db_commit(db) db_commit0(db, __FUNCTION__)
View
56 src/db/kvstore.c
@@ -113,15 +113,11 @@ get_url(void *db, const char *url, uint64_t *id)
int rc;
sqlite3_stmt *stmt;
- rc = db_prepare(db,
- "SELECT id FROM url WHERE url=?1",
- -1, &stmt, NULL);
+ rc = db_prepare(db, &stmt,
+ "SELECT id FROM url WHERE url=?1");
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return rc;
- }
sqlite3_bind_text(stmt, 1, url, -1, SQLITE_STATIC);
@@ -138,15 +134,13 @@ get_url(void *db, const char *url, uint64_t *id)
} else if(rc == SQLITE_DONE) {
sqlite3_finalize(stmt);
- rc = db_prepare(db,
- "INSERT INTO url ('url') VALUES (?1)",
- -1, &stmt, NULL);
+ rc = db_prepare(db, &stmt,
+ "INSERT INTO url ('url') VALUES (?1)");
+
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return rc;
- }
+
sqlite3_bind_text(stmt, 1, url, -1, SQLITE_STATIC);
rc = db_step(stmt);
@@ -209,25 +203,21 @@ kv_value_cb(void *opaque, prop_event_t event, ...)
}
if(event == PROP_SET_VOID) {
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"DELETE FROM url_kv "
"WHERE url_id = ?1 "
"AND domain = ?4 "
- "AND key = ?2"
- , -1, &stmt, NULL);
+ "AND key = ?2");
} else {
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"INSERT OR REPLACE INTO url_kv "
"(url_id, domain, key, value) "
"VALUES "
- "(?1, ?4, ?2, ?3)",
- -1, &stmt, NULL);
+ "(?1, ?4, ?2, ?3)");
}
if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
db_rollback(db);
kvstore_close(db);
return;
@@ -362,17 +352,15 @@ kv_prop_bind_create(prop_t *p, const char *url)
if(db == NULL)
return;
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"SELECT id,key,value "
"FROM url "
"LEFT OUTER JOIN url_kv ON id = url_id "
"WHERE url=?1 "
- "AND domain=?2 "
- , -1, &stmt, NULL);
+ "AND domain=?2");
+
if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
kvstore_close(db);
return;
}
@@ -432,18 +420,16 @@ kv_url_opt_get(void *db, const char *url, int domain, const char *key)
if(db == NULL)
return NULL;
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"SELECT value "
"FROM url, url_kv "
"WHERE url=?1 "
"AND key = ?2 "
"AND domain = ?3 "
"AND url.id = url_id"
- , -1, &stmt, NULL);
+ );
if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
return NULL;
}
sqlite3_bind_text(stmt, 1, url, -1, SQLITE_STATIC);
@@ -528,17 +514,15 @@ kv_url_opt_set(const char *url, int domain, const char *key,
return;
}
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"INSERT OR REPLACE INTO url_kv "
"(url_id, key, value, domain) "
"VALUES "
- "(?1, ?2, ?3, ?4)",
- -1, &stmt, NULL);
+ "(?1, ?2, ?3, ?4)"
+ );
if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
db_rollback(db);
kvstore_close(db);
return;
View
6 src/metadata/browsemdb.c
@@ -158,17 +158,15 @@ bmdb_files(prop_t *page, const char *url)
void *db = metadb_get();
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"SELECT i.url, p.url, i.contenttype "
"FROM item AS i, item AS p "
"WHERE i.url LIKE ?1 "
"AND (i.contenttype == 5 OR i.contenttype == 7) "
"AND i.parent = p.id"
- , -1, &stmt, NULL);
+ );
if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
goto err;
}
View
19 src/metadata/metadata.c
@@ -2191,15 +2191,12 @@ ms_set_enable(void *opaque, int value)
void *db = metadb_get();
- int rc = db_prepare(db,
+ int rc = db_prepare(db, &stmt,
"UPDATE datasource "
"SET enabled = ?2 "
- "WHERE id = ?1"
- , -1, &stmt, NULL);
+ "WHERE id = ?1");
if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
metadb_close(db);
return;
}
@@ -2233,13 +2230,10 @@ metadata_add_source(const char *name, const char *description,
if(db_begin(db))
goto err;
- rc = db_prepare(db,
- "SELECT id,prio,enabled FROM datasource WHERE name=?1",
- -1, &stmt, NULL);
+ rc = db_prepare(db, &stmt,
+ "SELECT id,prio,enabled FROM datasource WHERE name=?1");
if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
goto err;
}
@@ -2265,12 +2259,11 @@ metadata_add_source(const char *name, const char *description,
sqlite3_finalize(stmt);
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"INSERT INTO datasource "
"(name, prio, type, enabled) "
"VALUES "
- "(?1, ?2, ?3, ?4)"
- , -1, &stmt, NULL);
+ "(?1, ?2, ?3, ?4)");
if(rc != SQLITE_OK) {
TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
View
534 src/metadata/metadb.c
@@ -61,9 +61,7 @@ items_clear(void *opaque, prop_event_t event, ...)
int rc;
sqlite3_stmt *stmt;
- rc = db_prepare(db,
- "DELETE FROM item",
- -1, &stmt, NULL);
+ rc = db_prepare(db, &stmt, "DELETE FROM item");
if(rc == SQLITE_OK) {
rc = db_step(stmt);
@@ -161,9 +159,8 @@ db_item_get(sqlite3 *db, const char *url, time_t *mtimep)
int64_t rval = METADATA_PERMANENT_ERROR;
sqlite3_stmt *stmt;
- rc = db_prepare(db,
- "SELECT id,mtime from item where url=?1 ",
- -1, &stmt, NULL);
+ rc = db_prepare(db, &stmt,
+ "SELECT id,mtime from item where url=?1 ");
if(rc)
return METADATA_PERMANENT_ERROR;
sqlite3_bind_text(stmt, 1, url, -1, SQLITE_STATIC);
@@ -192,18 +189,14 @@ db_item_create(sqlite3 *db, const char *url, int contenttype, time_t mtime,
int rc;
sqlite3_stmt *stmt;
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"INSERT INTO item "
"(url, contenttype, mtime, parent, metadataversion) "
"VALUES "
- "(?1, ?2, ?3, ?4, " METADATA_VERSION_STR ")",
- -1, &stmt, NULL);
+ "(?1, ?2, ?3, ?4, " METADATA_VERSION_STR ")");
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return METADATA_PERMANENT_ERROR;
- }
sqlite3_bind_text(stmt, 1, url, -1, SQLITE_STATIC);
if(contenttype)
@@ -237,18 +230,15 @@ metadb_artist_get_by_title(void *db, const char *title, int ds_id,
int64_t rval = METADATA_PERMANENT_ERROR;
sqlite3_stmt *sel;
- rc = db_prepare(db,
+ rc = db_prepare(db, &sel,
"SELECT id "
"FROM artist "
"WHERE title=?1 "
"AND ds_id=?2"
- "AND (?3 OR ext_id = ?4)",
- -1, &sel, NULL);
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ "AND (?3 OR ext_id = ?4)");
+
+ if(rc != SQLITE_OK)
return METADATA_PERMANENT_ERROR;
- }
sqlite3_bind_text(sel, 1, title, -1, SQLITE_STATIC);
sqlite3_bind_int(sel, 2, ds_id);
@@ -264,12 +254,11 @@ metadb_artist_get_by_title(void *db, const char *title, int ds_id,
sqlite3_stmt *ins;
- rc = db_prepare(db,
+ rc = db_prepare(db, &ins,
"INSERT INTO artist "
"(title, ds_id, ext_id) "
"VALUES "
- "(?1, ?2, ?3)",
- -1, &ins, NULL);
+ "(?1, ?2, ?3)");
if(rc == SQLITE_OK) {
sqlite3_bind_text(ins, 1, title, -1, SQLITE_STATIC);
@@ -282,9 +271,6 @@ metadb_artist_get_by_title(void *db, const char *title, int ds_id,
rval = METADATA_DEADLOCK;
if(rc == SQLITE_DONE)
rval = sqlite3_last_insert_rowid(db);
- } else {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
}
} else if(rc == SQLITE_LOCKED) {
rval = METADATA_DEADLOCK;
@@ -307,20 +293,16 @@ metadb_album_get_by_title(void *db, const char *album, int64_t artist_id,
sqlite3_stmt *sel;
- rc = db_prepare(db,
+ rc = db_prepare(db, &sel,
"SELECT id "
"FROM album "
"WHERE title=?1 "
"AND artist_id IS ?2 "
"AND ds_id = ?3 "
- "AND (?4 OR ext_id = ?5)",
- -1, &sel, NULL);
+ "AND (?4 OR ext_id = ?5)");
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
- return METADATA_PERMANENT_ERROR;;
- }
+ if(rc != SQLITE_OK)
+ return METADATA_PERMANENT_ERROR;
sqlite3_bind_text(sel, 1, album, -1, SQLITE_STATIC);
if(artist_id != -1)
@@ -337,12 +319,11 @@ metadb_album_get_by_title(void *db, const char *album, int64_t artist_id,
// No entry found, INSERT it
sqlite3_stmt *ins;
- rc = db_prepare(db,
+ rc = db_prepare(db, &ins,
"INSERT INTO album "
"(title, ds_id, artist_id, ext_id) "
"VALUES "
- "(?1, ?3, ?2, ?4)",
- -1, &ins, NULL);
+ "(?1, ?3, ?2, ?4)");
if(rc == SQLITE_OK) {
sqlite3_bind_text(ins, 1, album, -1, SQLITE_STATIC);
@@ -358,9 +339,6 @@ metadb_album_get_by_title(void *db, const char *album, int64_t artist_id,
rval = sqlite3_last_insert_rowid(db);
if(rc == SQLITE_LOCKED)
rval = METADATA_DEADLOCK;
- } else {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
}
} else if(rc == SQLITE_LOCKED)
rval = METADATA_DEADLOCK;
@@ -381,18 +359,14 @@ metadb_insert_albumart(void *db, int64_t album_id, const char *url,
sqlite3_stmt *ins;
int rc;
- rc = db_prepare(db,
+ rc = db_prepare(db, &ins,
"INSERT INTO albumart "
"(album_id, url, width, height) "
"VALUES "
- "(?1, ?2, ?3, ?4)",
- -1, &ins, NULL);
+ "(?1, ?2, ?3, ?4)");
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return;
- }
sqlite3_bind_int64(ins, 1, album_id);
sqlite3_bind_text(ins, 2, url, -1, SQLITE_STATIC);
@@ -413,18 +387,14 @@ metadb_insert_artistpic(void *db, int64_t artist_id, const char *url,
sqlite3_stmt *ins;
int rc;
- rc = db_prepare(db,
+ rc = db_prepare(db, &ins,
"INSERT INTO artistpic "
"(artist_id, url, width, height) "
"VALUES "
- "(?1, ?2, ?3, ?4)",
- -1, &ins, NULL);
+ "(?1, ?2, ?3, ?4)");
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return;
- }
sqlite3_bind_int64(ins, 1, artist_id);
sqlite3_bind_text(ins, 2, url, -1, SQLITE_STATIC);
@@ -445,19 +415,15 @@ metadb_insert_videoart(void *db, int64_t videoitem_id, const char *url,
sqlite3_stmt *ins;
int rc;
- rc = db_prepare(db,
+ rc = db_prepare(db, &ins,
"INSERT OR REPLACE INTO videoart "
"(videoitem_id, url, width, height, "
"type, weight, grp, titled) "
"VALUES "
- "(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)",
- -1, &ins, NULL);
+ "(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)");
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return;
- }
sqlite3_bind_int64(ins, 1, videoitem_id);
sqlite3_bind_text(ins, 2, url, -1, SQLITE_STATIC);
@@ -482,14 +448,11 @@ metadb_delete_videoart(void *db, int64_t videoitem_id)
sqlite3_stmt *ins;
int rc;
- rc = db_prepare(db, "DELETE FROM videoart WHERE videoitem_id = ?1",
- -1, &ins, NULL);
+ rc = db_prepare(db, &ins,
+ "DELETE FROM videoart WHERE videoitem_id = ?1");
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return;
- }
sqlite3_bind_int64(ins, 1, videoitem_id);
db_step(ins);
@@ -516,19 +479,15 @@ metadb_insert_videocast(void *db, int64_t videoitem_id,
sqlite3_stmt *ins;
int rc;
- rc = db_prepare(db,
+ rc = db_prepare(db, &ins,
"INSERT OR REPLACE INTO videocast "
"(videoitem_id, name, character, department, job, "
"\"order\", image, width, height, ext_id) "
"VALUES "
- "(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)",
- -1, &ins, NULL);
+ "(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)");
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return;
- }
sqlite3_bind_int64(ins, 1, videoitem_id);
sqlite3_bind_text(ins, 2, name, -1, SQLITE_STATIC);
@@ -554,14 +513,11 @@ metadb_delete_videocast(void *db, int64_t videoitem_id)
sqlite3_stmt *ins;
int rc;
- rc = db_prepare(db, "DELETE FROM videocast WHERE videoitem_id = ?1",
- -1, &ins, NULL);
+ rc = db_prepare(db, &ins,
+ "DELETE FROM videocast WHERE videoitem_id = ?1");
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return;
- }
sqlite3_bind_int64(ins, 1, videoitem_id);
db_step(ins);
@@ -578,18 +534,14 @@ metadb_insert_videogenre(void *db, int64_t videoitem_id, const char *title)
sqlite3_stmt *ins;
int rc;
- rc = db_prepare(db,
+ rc = db_prepare(db, &ins,
"INSERT OR REPLACE INTO videogenre "
"(videoitem_id, title) "
"VALUES "
- "(?1, ?2)",
- -1, &ins, NULL);
+ "(?1, ?2)");
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return;
- }
sqlite3_bind_int64(ins, 1, videoitem_id);
sqlite3_bind_text(ins, 2, title, -1, SQLITE_STATIC);
@@ -629,7 +581,7 @@ metadb_insert_audioitem(sqlite3 *db, int64_t item_id, const metadata_t *md,
for(i = 0; i < 2; i++) {
sqlite3_stmt *stmt;
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
i == 0 ?
"INSERT OR FAIL INTO audioitem "
"(item_id, title, album_id, artist_id, duration, ds_id, track) "
@@ -642,14 +594,10 @@ metadb_insert_audioitem(sqlite3 *db, int64_t item_id, const metadata_t *md,
"artist_id = ?4, "
"duration = ?5 "
"WHERE item_id = ?1 AND ds_id = 1"
- ,
- -1, &stmt, NULL);
+ );
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return METADATA_PERMANENT_ERROR;
- }
sqlite3_bind_int64(stmt, 1, item_id);
@@ -716,19 +664,16 @@ metadb_get_album_art(void *db, const char *album, const char *artist)
int rc;
sqlite3_stmt *sel;
- rc = db_prepare(db,
+ rc = db_prepare(db, &sel,
"SELECT aa.url, aa.width, aa.height "
"FROM artist,album,albumart AS aa "
"WHERE artist.title=?1 "
"AND album.title=?2 "
"AND album.artist_id = artist.id "
- "AND aa.album_id = album.id",
- -1, &sel, NULL);
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ "AND aa.album_id = album.id"
+ );
+ if(rc != SQLITE_OK)
return NULL;
- }
sqlite3_bind_text(sel, 1, artist, -1, SQLITE_STATIC);
sqlite3_bind_text(sel, 2, album, -1, SQLITE_STATIC);
@@ -747,18 +692,16 @@ metadb_get_video_art(void *db, int64_t videoitem_id, int type)
int rc;
sqlite3_stmt *sel;
- rc = db_prepare(db,
+ rc = db_prepare(db, &sel,
"SELECT url "
"FROM videoart "
"WHERE videoitem_id=?1 "
"AND type=?2 "
- "ORDER BY weight DESC",
- -1, &sel, NULL);
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ "ORDER BY weight DESC"
+ );
+
+ if(rc != SQLITE_OK)
return NULL;
- }
sqlite3_bind_int64(sel, 1, videoitem_id);
sqlite3_bind_int(sel, 2, type);
@@ -802,16 +745,13 @@ metadb_get_video_genre(sqlite3 *db, int64_t videoitem_id)
int rc;
sqlite3_stmt *sel;
- rc = db_prepare(db,
+ rc = db_prepare(db, &sel,
"SELECT title "
"FROM videogenre "
- "WHERE videoitem_id = ?1",
- -1, &sel, NULL);
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ "WHERE videoitem_id = ?1");
+
+ if(rc != SQLITE_OK)
return NULL;
- }
sqlite3_bind_int64(sel, 1, videoitem_id);
rstr_t *r = metadb_construct_list(sel, 0);
@@ -829,17 +769,14 @@ metadb_get_video_cast(sqlite3 *db, int64_t videoitem_id, metadata_t *md)
int rc;
sqlite3_stmt *sel;
- rc = db_prepare(db,
+ rc = db_prepare(db, &sel,
"SELECT name,character,department,job,image "
"FROM videocast "
"WHERE videoitem_id = ?1 "
- "ORDER BY \"order\"",
- -1, &sel, NULL);
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ "ORDER BY \"order\"");
+
+ if(rc != SQLITE_OK)
return METADATA_PERMANENT_ERROR;
- }
sqlite3_bind_int64(sel, 1, videoitem_id);
@@ -875,17 +812,14 @@ metadb_get_artist_pics(void *db, const char *artist,
int rc;
sqlite3_stmt *sel;
int rval = METADATA_PERMANENT_ERROR;
- rc = db_prepare(db,
+ rc = db_prepare(db, &sel,
"SELECT ap.url, ap.width, ap.height "
"FROM artist,artistpic AS ap "
"WHERE artist.title=?1 "
- "AND ap.artist_id = artist.id",
- -1, &sel, NULL);
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ "AND ap.artist_id = artist.id");
+
+ if(rc != SQLITE_OK)
return METADATA_PERMANENT_ERROR;
- }
sqlite3_bind_text(sel, 1, artist, -1, SQLITE_STATIC);
@@ -922,20 +856,15 @@ metadb_insert_stream(sqlite3 *db, int64_t videoitem_id,
return 0;
}
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"INSERT INTO videostream "
"(videoitem_id, streamindex, info, isolang, "
"codec, mediatype, disposition, title) "
"VALUES "
- "(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)"
- ,
- -1, &stmt, NULL);
+ "(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)");
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return METADATA_PERMANENT_ERROR;
- }
sqlite3_bind_int64(stmt, 1, videoitem_id);
sqlite3_bind_int(stmt, 2, ms->ms_streamindex);
@@ -966,15 +895,11 @@ metadb_set_streams(sqlite3 *db, int64_t videoitem_id, const metadata_t *md)
sqlite3_stmt *stmt;
int rc, r;
- rc = db_prepare(db,
- "DELETE FROM videostream WHERE videoitem_id = ?1",
- -1, &stmt, NULL);
+ rc = db_prepare(db, &stmt,
+ "DELETE FROM videostream WHERE videoitem_id = ?1");
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return METADATA_PERMANENT_ERROR;
- }
sqlite3_bind_int64(stmt, 1, videoitem_id);
@@ -1011,20 +936,16 @@ metadb_insert_videoitem0(sqlite3 *db, int64_t item_id, int ds_id,
sqlite3_stmt *stmt;
if(i == 1) {
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"SELECT id "
"FROM videoitem "
"WHERE (?5 OR item_id = ?1) "
"AND ds_id = ?2 "
- "AND (?3 OR ext_id = ?4)"
- ,
- -1, &stmt, NULL);
-
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
- return METADATA_PERMANENT_ERROR;;
- }
+ "AND (?3 OR ext_id = ?4)");
+
+ if(rc != SQLITE_OK)
+ return METADATA_PERMANENT_ERROR;
+
sqlite3_bind_int(stmt, 5, !item_id);
sqlite3_bind_int64(stmt, 1, item_id);
sqlite3_bind_int64(stmt, 2, ds_id);
@@ -1039,14 +960,14 @@ metadb_insert_videoitem0(sqlite3 *db, int64_t item_id, int ds_id,
return METADATA_DEADLOCK;
TRACE(TRACE_ERROR, "SQLITE", "SQL Error 0x%x at %s:%d",
rc, __FUNCTION__, __LINE__);
- return METADATA_PERMANENT_ERROR;;
+ return METADATA_PERMANENT_ERROR;
}
id = sqlite3_column_int64(stmt, 0);
sqlite3_finalize(stmt);
}
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
i == 0 ?
"INSERT OR FAIL INTO videoitem "
"(item_id, ds_id, ext_id, "
@@ -1074,14 +995,10 @@ metadb_insert_videoitem0(sqlite3 *db, int64_t item_id, int ds_id,
"parent_id = ?19, "
"idx = ?20 "
"WHERE id = ?3 "
- ,
- -1, &stmt, NULL);
+ );
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
- return METADATA_PERMANENT_ERROR;;
- }
+ if(rc != SQLITE_OK)
+ return METADATA_PERMANENT_ERROR;
// Keys
if(item_id)
@@ -1189,7 +1106,7 @@ metadb_insert_imageitem(sqlite3 *db, int64_t item_id, const metadata_t *md)
for(i = 0; i < 2; i++) {
sqlite3_stmt *stmt;
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
i == 0 ?
"INSERT OR FAIL INTO imageitem "
"(item_id, original_time, manufacturer, equipment) "
@@ -1201,14 +1118,11 @@ metadb_insert_imageitem(sqlite3 *db, int64_t item_id, const metadata_t *md)
"manufacturer = ?3, "
"equipment = ?4 "
"WHERE item_id = ?1"
- ,
- -1, &stmt, NULL);
+ );
+
+ if(rc != SQLITE_OK)
+ return METADATA_PERMANENT_ERROR;
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
- return METADATA_PERMANENT_ERROR;;
- }
sqlite3_bind_int64(stmt, 1, item_id);
if(md->md_time)
@@ -1289,7 +1203,7 @@ metadb_metadata_write(void *db, const char *url, time_t mtime,
} else {
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
parent_id > 0 ?
"UPDATE item "
"SET contenttype=?1, "
@@ -1302,13 +1216,12 @@ metadb_metadata_write(void *db, const char *url, time_t mtime,
"SET contenttype=?1, "
"mtime=?2, "
"metadataversion=" METADATA_VERSION_STR " "
- "WHERE id=?3",
- -1, &stmt, NULL);
+ "WHERE id=?3"
+ );
+
if(rc != SQLITE_OK) {
db_rollback(db);
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
return;
}
@@ -1392,7 +1305,7 @@ static int
metadb_metadata_get_artist(sqlite3 *db, get_cache_t *gc, int64_t id)
{
if(id < 1)
- return METADATA_PERMANENT_ERROR;;
+ return METADATA_PERMANENT_ERROR;
if(id == gc->gc_artist_id)
return 0;
@@ -1400,16 +1313,14 @@ metadb_metadata_get_artist(sqlite3 *db, get_cache_t *gc, int64_t id)
int rc;
sqlite3_stmt *sel;
- rc = db_prepare(db,
+ rc = db_prepare(db, &sel,
"SELECT title "
"FROM artist "
- "WHERE id = ?1 AND ds_id=1",
- -1, &sel, NULL);
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
- return METADATA_PERMANENT_ERROR;;
- }
+ "WHERE id = ?1 AND ds_id=1"
+ );
+
+ if(rc != SQLITE_OK)
+ return METADATA_PERMANENT_ERROR;
sqlite3_bind_int64(sel, 1, id);
@@ -1417,7 +1328,7 @@ metadb_metadata_get_artist(sqlite3 *db, get_cache_t *gc, int64_t id)
if(rc != SQLITE_ROW) {
sqlite3_finalize(sel);
- return METADATA_PERMANENT_ERROR;;
+ return METADATA_PERMANENT_ERROR;
}
gc->gc_artist_id = id;
@@ -1436,7 +1347,7 @@ static int
metadb_metadata_get_album(sqlite3 *db, get_cache_t *gc, int64_t id)
{
if(id < 1)
- return METADATA_PERMANENT_ERROR;;
+ return METADATA_PERMANENT_ERROR;
if(id == gc->gc_album_id)
return 0;
@@ -1444,16 +1355,13 @@ metadb_metadata_get_album(sqlite3 *db, get_cache_t *gc, int64_t id)
int rc;
sqlite3_stmt *sel;
- rc = db_prepare(db,
+ rc = db_prepare(db, &sel,
"SELECT title "
"FROM album "
- "WHERE id = ?1 AND ds_id=1",
- -1, &sel, NULL);
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
- return METADATA_PERMANENT_ERROR;;
- }
+ "WHERE id = ?1 AND ds_id=1");
+
+ if(rc != SQLITE_OK)
+ return METADATA_PERMANENT_ERROR;
sqlite3_bind_int64(sel, 1, id);
@@ -1461,7 +1369,7 @@ metadb_metadata_get_album(sqlite3 *db, get_cache_t *gc, int64_t id)
if(rc != SQLITE_ROW) {
sqlite3_finalize(sel);
- return METADATA_PERMANENT_ERROR;;
+ return METADATA_PERMANENT_ERROR;
}
gc->gc_album_id = id;
@@ -1482,16 +1390,14 @@ metadb_metadata_get_audio(sqlite3 *db, metadata_t *md, int64_t item_id,
int rc;
sqlite3_stmt *sel;
- rc = db_prepare(db,
+ rc = db_prepare(db, &sel,
"SELECT title, album_id, artist_id, duration, track "
"FROM audioitem "
- "WHERE item_id = ?1 AND ds_id = 1",
- -1, &sel, NULL);
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
- return METADATA_PERMANENT_ERROR;;
- }
+ "WHERE item_id = ?1 AND ds_id = 1"
+ );
+
+ if(rc != SQLITE_OK)
+ return METADATA_PERMANENT_ERROR;
sqlite3_bind_int64(sel, 1, item_id);
@@ -1499,7 +1405,7 @@ metadb_metadata_get_audio(sqlite3 *db, metadata_t *md, int64_t item_id,
if(rc != SQLITE_ROW) {
sqlite3_finalize(sel);
- return METADATA_PERMANENT_ERROR;;
+ return METADATA_PERMANENT_ERROR;
}
md->md_title = rstr_alloc((void *)sqlite3_column_text(sel, 0));
@@ -1528,17 +1434,15 @@ metadb_metadata_get_video(sqlite3 *db, metadata_t *md, int64_t item_id,
int rc;
sqlite3_stmt *sel;
- rc = db_prepare(db,
+ rc = db_prepare(db, &sel,
"SELECT id, title, duration, format, year "
"FROM videoitem "
"WHERE item_id = ?1 "
- "AND ds_id = ?2",
- -1, &sel, NULL);
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
- return METADATA_PERMANENT_ERROR;;
- }
+ "AND ds_id = ?2"
+ );
+
+ if(rc != SQLITE_OK)
+ return METADATA_PERMANENT_ERROR;
sqlite3_bind_int64(sel, 1, item_id);
sqlite3_bind_int(sel, 2, ds_id);
@@ -1547,7 +1451,7 @@ metadb_metadata_get_video(sqlite3 *db, metadata_t *md, int64_t item_id,
if(rc != SQLITE_ROW) {
sqlite3_finalize(sel);
- return METADATA_PERMANENT_ERROR;;
+ return METADATA_PERMANENT_ERROR;
}
int64_t id = sqlite3_column_int64(sel, 0);
@@ -1572,17 +1476,15 @@ metadb_videoitem_set_preferred(void *db, const char *url, int64_t vid)
sqlite3_stmt *stmt;
int rc;
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"UPDATE videoitem "
"SET preferred = (CASE WHEN id=?2 THEN 1 ELSE 0 END) "
"WHERE item_id = (SELECT id FROM item WHERE url = ?1)"
- , -1, &stmt, NULL);
+ );
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return METADATA_PERMANENT_ERROR;
- }
+
sqlite3_bind_text(stmt, 1, url, -1, SQLITE_STATIC);
sqlite3_bind_int64(stmt, 2, vid);
@@ -1602,17 +1504,15 @@ metadb_videoitem_delete_from_ds(void *db, const char *url, int ds)
sqlite3_stmt *stmt;
int rc;
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"DELETE FROM videoitem "
"WHERE item_id = (SELECT id FROM item WHERE url = ?1) AND "
"ds_id = ?2"
- , -1, &stmt, NULL);
+ );
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return METADATA_PERMANENT_ERROR;
- }
+
sqlite3_bind_text(stmt, 1, url, -1, SQLITE_STATIC);
sqlite3_bind_int(stmt, 2, ds);
@@ -1635,20 +1535,17 @@ metadb_videoitem_alternatives0(void *db, prop_t *p, const char *url, int dsid,
sqlite3_stmt *sel;
prop_vec_t *pv = prop_vec_create(10);
- rc = db_prepare(db,
+ rc = db_prepare(db, &sel,
"SELECT v.id, v.title, v.year, v.preferred, v.status "
"FROM videoitem as v, item "
"WHERE item.url = ?1 "
"AND v.item_id = item.id "
"AND v.ds_id = ?2 "
"ORDER BY v.weight DESC"
- , -1, &sel, NULL);
+ );
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return 0;
- }
sqlite3_bind_text(sel, 1, url, -1, SQLITE_STATIC);
sqlite3_bind_int(sel, 2, dsid);
@@ -1729,17 +1626,14 @@ metadb_item_set_preferred_ds(void *db, const char *url, int ds_id)
{
int rc;
sqlite3_stmt *stmt;
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"UPDATE item "
"SET ds_id = ?2 "
- "WHERE url=?1",
- -1, &stmt, NULL);
+ "WHERE url=?1"
+ );
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return METADATA_PERMANENT_ERROR;
- }
sqlite3_bind_text(stmt, 1, url, -1, SQLITE_STATIC);
if(ds_id)
@@ -1768,15 +1662,13 @@ metadb_item_get_preferred_ds(const char *url)
if((db = metadb_get()) == NULL)
return METADATA_PERMANENT_ERROR;
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"SELECT ds_id "
"FROM item "
"WHERE url=?1"
- , -1, &stmt, NULL);
+ );
if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
metadb_close(db);
return METADATA_PERMANENT_ERROR;
}
@@ -1806,15 +1698,13 @@ metadb_item_get_user_title(const char *url)
if((db = metadb_get()) == NULL)
return NULL;
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"SELECT usertitle "
"FROM item "
"WHERE url=?1"
- , -1, &stmt, NULL);
+ );
if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
metadb_close(db);
return NULL;
}
@@ -1845,15 +1735,13 @@ metadb_item_set_user_title(const char *url, const char *str)
if((db = metadb_get()) == NULL)
return;
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"UPDATE item "
"SET usertitle=?2 "
"WHERE url=?1"
- , -1, &stmt, NULL);
+ );
if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
metadb_close(db);
return;
}
@@ -1878,19 +1766,16 @@ metadb_get_videoinfo2(void *db, int64_t id, metadata_t **mdp)
sqlite3_stmt *sel;
int rc;
- rc = db_prepare(db,
+ rc = db_prepare(db, &sel,
"SELECT v.parent_id, v.title, v.tagline, v.description, "
"v.year, v.rating, v.rate_count, v.imdb_id, v.idx, v.type, "
"v.id "
"FROM videoitem AS v "
"WHERE v.id = ?1 "
- , -1, &sel, NULL);
+ );
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return METADATA_PERMANENT_ERROR;
- }
sqlite3_bind_int64(sel, 1, id);
@@ -1946,15 +1831,16 @@ metadb_get_videoitem(void *db, const char *url)
int64_t rval = METADATA_PERMANENT_ERROR;
sqlite3_stmt *stmt;
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"SELECT videoitem.id "
"FROM videoitem,item "
"WHERE videoitem.item_id = item.id "
"AND item.url = ?1"
- , -1, &stmt, NULL);
- if(rc) {
+ );
+
+ if(rc)
return METADATA_PERMANENT_ERROR;
- }
+
sqlite3_bind_text(stmt, 1, url, -1, SQLITE_STATIC);
rc = db_step(stmt);
if(rc == SQLITE_ROW) {
@@ -1980,15 +1866,12 @@ metadb_get_videoinfo(void *db, const char *url,
*fixed_ds = 0;
*mdp = NULL;
- rc = db_prepare(db,
+ rc = db_prepare(db, &sel,
"SELECT id, ds_id FROM item WHERE url = ?1"
- , -1, &sel, NULL);
+ );
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return METADATA_PERMANENT_ERROR;
- }
sqlite3_bind_text(sel, 1, url, -1, SQLITE_STATIC);
@@ -2010,7 +1893,7 @@ metadb_get_videoinfo(void *db, const char *url,
*fixed_ds = ds_id;
- rc = db_prepare(db,
+ rc = db_prepare(db, &sel,
"SELECT v.id, v.title, v.tagline, v.description, v.year, "
"v.rating, v.rate_count, v.imdb_id, v.ds_id, v.status, "
"v.preferred, v.ext_id, ds.id, ds.enabled, v.querytype, "
@@ -2020,13 +1903,10 @@ metadb_get_videoinfo(void *db, const char *url,
"AND ds.id = v.ds_id "
"AND (?2 == 0 OR ?2 = v.ds_id) "
"ORDER BY ds.prio ASC, v.weight DESC"
- , -1, &sel, NULL);
+ );
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
+ if(rc != SQLITE_OK)
return METADATA_PERMANENT_ERROR;
- }
sqlite3_bind_int64(sel, 1, item_id);
sqlite3_bind_int(sel, 2, ds_id);
@@ -2122,16 +2002,16 @@ metadb_metadata_get_streams(sqlite3 *db, metadata_t *md, int64_t videoitem_id)
int strack = 0;
int vtrack = 0;
- rc = db_prepare(db,
- "SELECT streamindex, info, isolang, codec, mediatype, disposition, title "
+ rc = db_prepare(db, &sel,
+ "SELECT streamindex, info, isolang, codec, "
+ "mediatype, disposition, title "
"FROM videostream "
- "WHERE videoitem_id = ?1 ORDER BY streamindex",
- -1, &sel, NULL);
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
- return METADATA_PERMANENT_ERROR;;
- }
+ "WHERE videoitem_id = ?1 "
+ "ORDER BY streamindex"
+ );
+
+ if(rc != SQLITE_OK)
+ return METADATA_PERMANENT_ERROR;
sqlite3_bind_int64(sel, 1, videoitem_id);
@@ -2175,16 +2055,14 @@ metadb_metadata_get_image(sqlite3 *db, metadata_t *md, int64_t item_id)
int rc;
sqlite3_stmt *sel;
- rc = db_prepare(db,
+ rc = db_prepare(db, &sel,
"SELECT original_time, manufacturer, equipment "
"FROM imageitem "
- "WHERE item_id = ?1",
- -1, &sel, NULL);
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
- return METADATA_PERMANENT_ERROR;;
- }
+ "WHERE item_id = ?1"
+ );
+
+ if(rc != SQLITE_OK)
+ return METADATA_PERMANENT_ERROR;
sqlite3_bind_int64(sel, 1, item_id);
@@ -2192,7 +2070,7 @@ metadb_metadata_get_image(sqlite3 *db, metadata_t *md, int64_t item_id)
if(rc != SQLITE_ROW) {
sqlite3_finalize(sel);
- return METADATA_PERMANENT_ERROR;;
+ return METADATA_PERMANENT_ERROR;
}
md->md_time = sqlite3_column_int(sel, 0);
@@ -2263,15 +2141,14 @@ metadb_metadata_get(void *db, const char *url, time_t mtime)
if(db_begin(db))
return NULL;
- rc = db_prepare(db,
+ rc = db_prepare(db, &sel,
"SELECT id,contenttype from item "
"where url=?1 AND "
"mtime=?2 AND "
- "metadataversion=" METADATA_VERSION_STR,
- -1, &sel, NULL);
+ "metadataversion=" METADATA_VERSION_STR
+ );
+
if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
db_rollback(db);
return NULL;
}
@@ -2325,15 +2202,14 @@ metadb_metadata_scandir(void *db, const char *url, time_t *mtime)
sqlite3_stmt *sel;
int rc;
- rc = db_prepare(db,
- "SELECT id,url,contenttype,mtime,playcount,lastplay,metadataversion "
+ rc = db_prepare(db, &sel,
+ "SELECT id, url, contenttype, mtime, playcount, "
+ "lastplay, metadataversion "
"FROM item "
- "WHERE parent = ?1",
- -1, &sel, NULL);
+ "WHERE parent = ?1"
+ );
if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
db_rollback(db);
return NULL;
}
@@ -2398,12 +2274,11 @@ metadb_unparent_item(void *db, const char *url)
sqlite3_stmt *stmt;
- rc = db_prepare(db, "UPDATE item SET parent = NULL WHERE url=?1",
- -1, &stmt, NULL);
+ rc = db_prepare(db, &stmt,
+ "UPDATE item SET parent = NULL WHERE url=?1"
+ );
if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
db_rollback(db);
return;
}
@@ -2444,7 +2319,7 @@ metadb_register_play(const char *url, int inc, int content_type)
for(i = 0; i < 2; i++) {
sqlite3_stmt *stmt;
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
i == 0 ?
"UPDATE item "
"SET playcount = playcount + ?3, "
@@ -2454,12 +2329,10 @@ metadb_register_play(const char *url, int inc, int content_type)
"INSERT INTO item "
"(url, contenttype, playcount, lastplay) "
"VALUES "
- "(?1, ?4, ?3, ?2)",
- -1, &stmt, NULL);
+ "(?1, ?4, ?3, ?2)"
+ );
if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
db_rollback(db);
metadb_close(db);
return;
@@ -2511,7 +2384,7 @@ metadb_set_video_restartpos(const char *url, int64_t pos_ms)
for(i = 0; i < 2; i++) {
sqlite3_stmt *stmt;
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
i == 0 ?
"UPDATE item "
"SET restartposition = ?2, contenttype = ?3 "
@@ -2520,12 +2393,9 @@ metadb_set_video_restartpos(const char *url, int64_t pos_ms)
"INSERT INTO item "
"(url, contenttype, restartposition) "
"VALUES "
- "(?1, ?3, ?2)",
- -1, &stmt, NULL);
+ "(?1, ?3, ?2)");
if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
db_rollback(db);
metadb_close(db);
return;
@@ -2563,16 +2433,13 @@ video_get_restartpos(const char *url)
if((db = metadb_get()) == NULL)
return 0;
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"SELECT restartposition "
"FROM item "
- "WHERE url = ?1",
- -1, &stmt, NULL);
+ "WHERE url = ?1"
+ );
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
- } else {
+ if(rc == SQLITE_OK) {
sqlite3_bind_text(stmt, 1, url, -1, SQLITE_STATIC);
rc = db_step(stmt);
@@ -2623,17 +2490,16 @@ mip_get(sqlite3 *db, const char *url, metadb_item_info_t *mii)
int rc = METADATA_PERMANENT_ERROR;
sqlite3_stmt *stmt;
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
"SELECT "
"playcount,lastplay,restartposition "
"FROM item "
- "WHERE url=?1 ",
- -1, &stmt, NULL);
- if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
- return METADATA_PERMANENT_ERROR;;
- }
+ "WHERE url=?1"
+ );
+
+ if(rc != SQLITE_OK)
+ return METADATA_PERMANENT_ERROR;
+
sqlite3_bind_text(stmt, 1, url, -1, SQLITE_STATIC);
rc = db_step(stmt);
@@ -2753,7 +2619,7 @@ metadb_set_playcount(void *opaque, prop_event_t event, ...)
for(i = 0; i < 2; i++) {
sqlite3_stmt *stmt;
- rc = db_prepare(db,
+ rc = db_prepare(db, &stmt,
i == 0 ?
"UPDATE item "
"SET playcount = ?2 "
@@ -2763,11 +2629,9 @@ metadb_set_playcount(void *opaque, prop_event_t event, ...)
"(url, playcount, metadataversion) "
"VALUES "
"(?1, ?2, " METADATA_VERSION_STR ")"
- , -1, &stmt, NULL);
+ );
if(rc != SQLITE_OK) {
- TRACE(TRACE_ERROR, "SQLITE", "SQL Error at %s:%d",
- __FUNCTION__, __LINE__);
db_rollback(db);
metadb_close(db);
return;
Please sign in to comment.
Something went wrong with that request. Please try again.