~ubuntu-branches/ubuntu/maverick/liferea/maverick

« back to all changes in this revision

Viewing changes to src/db.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2008-06-23 12:44:17 UTC
  • mfrom: (1.2.52 upstream)
  • Revision ID: james.westby@ubuntu.com-20080623124417-o4klc8dom3qwd7wn
Tags: 1.4.16b-0.1ubuntu1
* Merge from Debian unstable.
* Remaining Ubuntu changes:
  - Change Build-Depends from xulrunner-dev to xulrunner-1.9-dev.
  - Add intltool to Build-Depends.
  - Fix systray mis-behaviour when Liferea is visible in another workspace.
  - Add Hildonisation from Frothing as a patch.
  - Add libhildon-1-dev Build-Depends for lpia.
  - --enable-maemo when building on lpia.
  - Call intltool-update -p to generate translation template for Rosetta.
  - Do not build transitional packages (not required due to Conflicts/
    Provides/Replaces).
  - Build-depend on liblualib50-dev instead of liblua5.1-0-dev.
  - Do not build webkit package.
  - Munge Maintainer field as per spec.
* Ubuntu changes dropped:
  - mobile.desktop, it isn't needed any more.
  - Added xulrunner-1.9 to liferea dependencies.
  - Quilt changes.
* Edit xulrunner-1.9 patch to not patch configure, handle that in
  99_autoconf.

Show diffs side-by-side

added added

removed removed

Lines of Context:
168
168
        return schemaVersion;
169
169
}
170
170
 
171
 
#define SCHEMA_TARGET_VERSION 6
 
171
#define SCHEMA_TARGET_VERSION 7
172
172
        
173
173
/* opening or creation of database */
174
174
void
315
315
                                /* 1.4.9 -> 1.4.10 adding parent_item_id to itemset relation */
316
316
                                debug0 (DEBUG_DB, "migrating from schema version 5 to 6 (this drops all comments)");
317
317
                                db_exec ("BEGIN; "
 
318
                                         "DROP TRIGGER item_removal; "
 
319
                                         "DROP TRIGGER item_insert; "
318
320
                                         "DELETE FROM itemsets WHERE comment = 1; "
 
321
                                         "DELETE FROM items WHERE comment = 1; "
319
322
                                         "CREATE TEMPORARY TABLE itemsets_backup(item_id,node_id,read,comment); "
320
323
                                         "INSERT INTO itemsets_backup SELECT item_id,node_id,read,comment FROM itemsets; "
321
324
                                         "DROP TABLE itemsets; "
332
335
                                         "REPLACE INTO info (name, value) VALUES ('schemaVersion',6); "
333
336
                                         "END;");
334
337
                        }
 
338
                        
 
339
                        if (db_get_schema_version () == 6) {
 
340
                                /* 1.4.15 -> 1.4.16 adding parent_node_id to itemset relation */
 
341
                                debug0 (DEBUG_DB, "migrating from schema version 5 to 6 (this drops all comments)");
 
342
                                db_exec ("BEGIN; "
 
343
                                         "DROP TRIGGER item_removal; "
 
344
                                         "DROP TRIGGER item_insert; "
 
345
                                         "DELETE FROM itemsets WHERE comment = 1; "
 
346
                                         "DELETE FROM items WHERE comment = 1; "
 
347
                                         "CREATE TEMPORARY TABLE itemsets_backup(item_id,node_id,read,comment); "
 
348
                                         "INSERT INTO itemsets_backup SELECT item_id,node_id,read,comment FROM itemsets; "
 
349
                                         "DROP TABLE itemsets; "
 
350
                                         "CREATE TABLE itemsets ("
 
351
                                         "   item_id            INTEGER,"
 
352
                                         "   parent_item_id     INTEGER,"
 
353
                                         "   node_id            TEXT,"
 
354
                                         "   parent_node_id     TEXT,"
 
355
                                         "   read               INTEGER,"
 
356
                                         "   comment            INTEGER,"
 
357
                                         "   PRIMARY KEY (item_id, node_id)"
 
358
                                         "); "
 
359
                                         "INSERT INTO itemsets SELECT item_id,0,node_id,node_id,read,comment FROM itemsets_backup; "
 
360
                                         "DROP TABLE itemsets_backup; "
 
361
                                         "REPLACE INTO info (name, value) VALUES ('schemaVersion',7); "
 
362
                                         "END;");
 
363
                        }
335
364
 
336
365
                        if (SCHEMA_TARGET_VERSION != db_get_schema_version ())
337
366
                                g_error ("Fatal: DB schema migration failed! Running with --debug-db could give some hints!");
370
399
                         "   item_id            INTEGER,"
371
400
                         "   parent_item_id     INTEGER,"
372
401
                         "   node_id            TEXT,"
 
402
                         "   parent_node_id     TEXT,"
373
403
                         "   read               INTEGER,"
374
404
                         "   comment            INTEGER,"
375
405
                         "   PRIMARY KEY (item_id, node_id)"
388
418
 
389
419
                db_exec ("CREATE INDEX metadata_idx ON metadata (item_id);");
390
420
 
391
 
                /* Set up item removal trigger */       
 
421
                /* Set up item removal trigger (does not remove comments!) */
392
422
                db_exec ("DROP TRIGGER item_removal;");
393
423
                db_exec ("CREATE TRIGGER item_removal DELETE ON itemsets "
394
424
                         "BEGIN "
395
425
                         "   DELETE FROM items WHERE ROWID = old.item_id; "
396
 
                         "   DELETE FROM itemsets WHERE parent_item_id = old.item_id; "
397
426
                         "   DELETE FROM metadata WHERE item_id = old.item_id; "
398
427
                         "END;");
399
428
 
450
479
                         "   DELETE FROM node WHERE node_id = old.node_id; "
451
480
                         "   DELETE FROM update_state WHERE node_id = old.node_id; "
452
481
                         "   DELETE FROM subscription_metadata WHERE node_id = old.node_id; "
453
 
                         "   DELETE FROM itemsets WHERE node_id = old.node_id; "
454
482
                         "END;");
455
483
 
456
484
                db_exec ("CREATE TABLE node ("
507
535
                          "item_id,"
508
536
                          "parent_item_id,"
509
537
                          "node_id,"
 
538
                          "parent_node_id,"
510
539
                          "read,"
511
540
                          "comment"
512
 
                          ") VALUES (?,?,?,?,?)");
 
541
                          ") VALUES (?,?,?,?,?,?)");
513
542
        
514
543
        db_new_statement ("itemsetReadCountStmt",
515
544
                          "SELECT COUNT(*) FROM itemsets "
520
549
                          "WHERE node_id = ?");
521
550
                       
522
551
        db_new_statement ("itemsetRemoveStmt",
523
 
                          "DELETE FROM itemsets WHERE item_id = ?");
 
552
                          "DELETE FROM itemsets WHERE parent_item_id = ?");
524
553
                        
525
554
        db_new_statement ("itemsetRemoveAllStmt",
526
 
                          "DELETE FROM itemsets WHERE node_id = ?");
 
555
                          "DELETE FROM itemsets WHERE parent_node_id = ?");
527
556
 
528
557
        db_new_statement ("itemsetMarkAllUpdatedStmt",
529
558
                          "UPDATE items SET updated = 0 WHERE ROWID IN "
556
585
                          "items.comment,"
557
586
                          "itemsets.item_id,"
558
587
                          "itemsets.parent_item_id, "
559
 
                          "itemsets.node_id"
 
588
                          "itemsets.node_id, "
 
589
                          "itemsets.parent_node_id "
560
590
                          " FROM items INNER JOIN itemsets "
561
591
                          "ON items.ROWID = itemsets.item_id "
562
592
                          "WHERE items.ROWID = ?");      
743
773
static itemPtr
744
774
db_load_item_from_columns (sqlite3_stmt *stmt) 
745
775
{
746
 
        itemPtr item = item_new();
 
776
        itemPtr item = item_new ();
747
777
        
748
 
        item->readStatus        = sqlite3_column_int(stmt, 1)?TRUE:FALSE;
749
 
        item->newStatus         = sqlite3_column_int(stmt, 2)?TRUE:FALSE;
750
 
        item->updateStatus      = sqlite3_column_int(stmt, 3)?TRUE:FALSE;
751
 
        item->popupStatus       = sqlite3_column_int(stmt, 4)?TRUE:FALSE;
752
 
        item->flagStatus        = sqlite3_column_int(stmt, 5)?TRUE:FALSE;
753
 
        item->validGuid         = sqlite3_column_int(stmt, 8)?TRUE:FALSE;
754
 
        item->time              = sqlite3_column_int(stmt, 12);
755
 
        item->commentFeedId     = g_strdup(sqlite3_column_text(stmt, 13));
756
 
        item->isComment         = sqlite3_column_int(stmt, 14);
757
 
        item->id                = sqlite3_column_int(stmt, 15);
758
 
        item->parentItemId      = sqlite3_column_int(stmt, 16);
759
 
        item->nodeId            = g_strdup(sqlite3_column_text(stmt, 17));
 
778
        item->readStatus        = sqlite3_column_int (stmt, 1)?TRUE:FALSE;
 
779
        item->newStatus         = sqlite3_column_int (stmt, 2)?TRUE:FALSE;
 
780
        item->updateStatus      = sqlite3_column_int (stmt, 3)?TRUE:FALSE;
 
781
        item->popupStatus       = sqlite3_column_int (stmt, 4)?TRUE:FALSE;
 
782
        item->flagStatus        = sqlite3_column_int (stmt, 5)?TRUE:FALSE;
 
783
        item->validGuid         = sqlite3_column_int (stmt, 8)?TRUE:FALSE;
 
784
        item->time              = sqlite3_column_int (stmt, 12);
 
785
        item->commentFeedId     = g_strdup (sqlite3_column_text (stmt, 13));
 
786
        item->isComment         = sqlite3_column_int (stmt, 14);
 
787
        item->id                = sqlite3_column_int (stmt, 15);
 
788
        item->parentItemId      = sqlite3_column_int (stmt, 16);
 
789
        item->nodeId            = g_strdup (sqlite3_column_text (stmt, 17));
 
790
        item->parentNodeId      = g_strdup (sqlite3_column_text (stmt, 18));
760
791
 
761
792
        item_set_title                  (item, sqlite3_column_text(stmt, 0));
762
793
        item_set_source                 (item, sqlite3_column_text(stmt, 6));
765
796
        item_set_real_source_title      (item, sqlite3_column_text(stmt, 10));
766
797
        item_set_description            (item, sqlite3_column_text(stmt, 11));
767
798
 
768
 
        item->metadata = db_item_metadata_load(item);
 
799
        item->metadata = db_item_metadata_load (item);
769
800
 
770
801
        return item;
771
802
}
875
906
        
876
907
        debug3 (DEBUG_DB, "update of item \"%s\" (id=%lu, thread=%p)", item->title, item->id, g_thread_self());
877
908
        debug_start_measurement (DEBUG_DB);
878
 
 
879
 
        if(!item->id) {
880
 
                db_item_set_id(item);
 
909
        
 
910
        if (!item->id) {
 
911
                db_item_set_id (item);
881
912
 
882
913
                debug1(DEBUG_DB, "insert into table \"itemsets\": \"%s\"", item->title);        
883
914
                
886
917
                sqlite3_bind_int  (stmt, 1, item->id);
887
918
                sqlite3_bind_int  (stmt, 2, item->parentItemId);
888
919
                sqlite3_bind_text (stmt, 3, item->nodeId, -1, SQLITE_TRANSIENT);
889
 
                sqlite3_bind_int  (stmt, 4, item->readStatus);
890
 
                sqlite3_bind_int  (stmt, 5, item->isComment?1:0);
 
920
                sqlite3_bind_text (stmt, 4, item->parentNodeId, -1, SQLITE_TRANSIENT);
 
921
                sqlite3_bind_int  (stmt, 5, item->readStatus);
 
922
                sqlite3_bind_int  (stmt, 6, item->isComment?1:0);
891
923
                res = sqlite3_step (stmt);
892
924
                if (SQLITE_DONE != res) 
893
925
                        g_warning ("Insert in \"itemsets\" table failed (error code=%d, %s)", res, sqlite3_errmsg (db));