commit a278b814b702bfce15f78844c84d6b7ae6a99e67
Author: Nikias Bassen <[email protected]>
Date:   Mon Dec 21 17:29:40 2009 +0100

    Write base_location entries based on the device

 src/itdb_sqlite.c         |   62 +++++++++++++++++++++++++++++++++++++++------
 src/itdb_sqlite_queries.h |    3 --
 2 files changed, 54 insertions(+), 11 deletions(-)
---
diff --git a/src/itdb_sqlite.c b/src/itdb_sqlite.c
index f9f345a..e5e9122 100644
--- a/src/itdb_sqlite.c
+++ b/src/itdb_sqlite.c
@@ -1181,17 +1181,63 @@ static int mk_Locations(Itdb_iTunesDB *itdb, const char 
*outpath, const char *uu
 
     sqlite3_exec(db, "BEGIN;", NULL, NULL, NULL);
 
-    /* kill all entries in 'location' as they will be re-inserted */
-    if (SQLITE_OK != sqlite3_exec(db, "DELETE FROM location;", NULL, NULL, 
&errmsg)) {
-       fprintf(stderr, "[%s] sqlite3_exec error: %s\n", __func__, 
sqlite3_errmsg(db));
-       if (errmsg) {
-           fprintf(stderr, "[%s] additional error information: %s\n", 
__func__, errmsg);
-           sqlite3_free(errmsg);
-           errmsg = NULL;
-       }
+    if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT INTO \"base_location\" 
(id, path) VALUES (?,?);", -1, &stmt, NULL)) {
+       fprintf(stderr, "[%s] sqlite3_prepare error: %s\n", __func__, 
sqlite3_errmsg(db));
        goto leave;
     }
+    idx = 0;
+    res = sqlite3_reset(stmt);
+    if (res != SQLITE_OK) {
+       fprintf(stderr, "[%s] sqlite3_reset returned %d\n", __func__, res);
+    }
+
+    sqlite3_bind_int(stmt, ++idx, 1);
+    if (itdb_device_is_iphone_family(itdb->device)) {
+       sqlite3_bind_text(stmt, ++idx, "iTunes_Control/Music", -1, 
SQLITE_STATIC);
+    } else {
+       sqlite3_bind_text(stmt, ++idx, "iPod_Control/Music", -1, SQLITE_STATIC);
+    }
+    res = sqlite3_step(stmt);
+    if (res == SQLITE_DONE) {
+       /* expected result */
+    } else {
+       fprintf(stderr, "[%s] sqlite3_step returned %d\n", __func__, res);
+    }
 
+    if (itdb_device_is_iphone_family (itdb->device)) {
+       idx = 0;
+       res = sqlite3_reset(stmt);
+       if (res != SQLITE_OK) {
+           fprintf(stderr, "[%s] sqlite3_reset returned %d\n", __func__, res);
+       }
+       sqlite3_bind_int(stmt, ++idx, 4);
+       sqlite3_bind_text(stmt, ++idx, "Podcasts", -1, SQLITE_STATIC);
+       res = sqlite3_step(stmt);
+       if (res == SQLITE_DONE) {
+           /* expected result */
+       } else {
+           fprintf(stderr, "[%s] sqlite3_step returned %d\n", __func__, res);
+       }
+
+       idx = 0;
+       res = sqlite3_reset(stmt);
+       if (res != SQLITE_OK) {
+           fprintf(stderr, "[%s] sqlite3_reset returned %d\n", __func__, res);
+       }
+       sqlite3_bind_int(stmt, ++idx, 6);
+       sqlite3_bind_text(stmt, ++idx, "iTunes_Control/Ringtones", -1, 
SQLITE_STATIC);
+       res = sqlite3_step(stmt);
+       if (res == SQLITE_DONE) {
+           /* expected result */
+       } else {
+           fprintf(stderr, "[%s] sqlite3_step returned %d\n", __func__, res);
+       }
+    }
+
+    if (stmt) {
+       sqlite3_finalize(stmt);
+    }
+ 
     if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT INTO \"location\" 
(item_pid, sub_id, base_location_id, location_type, location, extension, 
kind_id, date_created, file_size) VALUES(?,?,?,?,?,?,?,?,?);", -1, &stmt, 
NULL)) {
        fprintf(stderr, "[%s] sqlite3_prepare error: %s\n", __func__, 
sqlite3_errmsg(db));
        goto leave;
diff --git a/src/itdb_sqlite_queries.h b/src/itdb_sqlite_queries.h
index f2470c4..630ce0f 100644
--- a/src/itdb_sqlite_queries.h
+++ b/src/itdb_sqlite_queries.h
@@ -82,9 +82,6 @@ static const char Locations_create[] =
        "BEGIN TRANSACTION;" \
        "CREATE TABLE location (item_pid INTEGER NOT NULL, sub_id INTEGER NOT 
NULL DEFAULT 0, base_location_id INTEGER DEFAULT 0, location_type INTEGER, 
location TEXT, extension INTEGER, kind_id INTEGER DEFAULT 0, date_created 
INTEGER DEFAULT 0, file_size INTEGER DEFAULT 0, file_creator INTEGER, file_type 
INTEGER, num_dir_levels_file INTEGER, num_dir_levels_lib INTEGER, PRIMARY KEY 
(item_pid,sub_id));" \
        "CREATE TABLE base_location (id INTEGER NOT NULL, path TEXT, PRIMARY 
KEY (id));" \
-       "INSERT INTO \"base_location\" VALUES(1,'iTunes_Control/Music');" \
-       "INSERT INTO \"base_location\" VALUES(4,'Podcasts');" \
-       "INSERT INTO \"base_location\" VALUES(6,'iTunes_Control/Ringtones');" \
        "ANALYZE sqlite_master;" \
        "INSERT INTO \"sqlite_stat1\" 
VALUES('location','sqlite_autoindex_location_1','1 1 1');" \
        "COMMIT;";

------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to