From fd85af40f89550e4da20638bd5693d0e49ae8682 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 16 Jun 2006 07:32:48 +0000 Subject: [PATCH] Many-to-one item note support in the schema and data layer -- still some issues on (I think) the interface side --- .../content/scholar/xpcom/data_access.js | 56 +++++++++++++++++++ .../content/scholar/xpcom/schema.js | 4 +- schema.sql | 13 ++++- 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/chrome/chromeFiles/content/scholar/xpcom/data_access.js b/chrome/chromeFiles/content/scholar/xpcom/data_access.js index 73940be9dd..a9c4cb6afb 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/data_access.js +++ b/chrome/chromeFiles/content/scholar/xpcom/data_access.js @@ -675,6 +675,62 @@ Scholar.Item.prototype.save = function(){ } +// +// Methods dealing with item notes +// +// save() is not required for note functions +// +/** +* Add a new note to an item and return the noteID +**/ +Scholar.Item.prototype.addNote = function(text){ + Scholar.DB.beginTransaction(); + var noteID = Scholar.getRandomID('itemNotes', 'noteID', 65535); + var sql = "INSERT INTO itemNotes (noteID, itemID, note) VALUES (?,?,?)"; + Scholar.DB.query(sql, + [{'int':noteID}, {'int':this.getID()}, {'string':text}] + ); + Scholar.DB.commitTransaction(); + return noteID; +} + +/** +* Update an item note +**/ +Scholar.Item.prototype.updateNote = function(noteID, text){ + var sql = "UPDATE itemNotes SET note=? WHERE itemID=? AND noteID=?"; + return Scholar.DB.query(sql, + [{'string':text}, {'int':this.getID()}, {'int':noteID}] + ); +} + +/** +* Delete an item note +**/ +Scholar.Item.prototype.removeNote = function(noteID){ + var sql = "DELETE FROM itemNotes WHERE itemID=" + this.getID() + + " AND noteID=" + noteID; + return Scholar.DB.query(sql); +} + +/** +* Get the text of an item note +**/ +Scholar.Item.prototype.getNote = function(noteID){ + var sql = "SELECT note FROM itemNotes WHERE itemID=" + this.getID() + + " AND noteID=" + noteID; + return Scholar.DB.valueQuery(sql); +} + +/** +* Returns an array of noteIDs for this item +**/ +Scholar.Item.prototype.getNotes = function(){ + var sql = "SELECT noteID FROM itemNotes WHERE itemID=" + this.getID(); + return Scholar.DB.columnQuery(sql); +} + + /** * Delete item from database and clear from Scholar.Items internal array **/ diff --git a/chrome/chromeFiles/content/scholar/xpcom/schema.js b/chrome/chromeFiles/content/scholar/xpcom/schema.js index d0da161906..e609148c21 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/schema.js +++ b/chrome/chromeFiles/content/scholar/xpcom/schema.js @@ -370,7 +370,7 @@ Scholar.Schema = new function(){ // // Change this value to match the schema version // - var toVersion = 19; + var toVersion = 20; if (toVersion != _getSchemaSQLVersion()){ throw('Schema version does not match version in _migrateSchema()'); @@ -385,7 +385,7 @@ Scholar.Schema = new function(){ // Each block performs the changes necessary to move from the // previous revision to that one. for (var i=parseInt(fromVersion) + 1; i<=toVersion; i++){ - if (i==19){ + if (i==20){ _initializeSchema(); } } diff --git a/schema.sql b/schema.sql index ffc637f5da..bd0bbead27 100644 --- a/schema.sql +++ b/schema.sql @@ -1,4 +1,4 @@ --- 19 +-- 20 DROP TABLE IF EXISTS version; CREATE TABLE version ( @@ -60,6 +60,17 @@ DROP INDEX IF EXISTS value; CREATE INDEX value ON itemData(value); + DROP TABLE IF EXISTS itemNotes; + CREATE TABLE itemNotes ( + noteID INT, + itemID INT, + note TEXT, + PRIMARY KEY (noteID), + FOREIGN KEY (itemID) REFERENCES items(itemID) + ); + DROP INDEX IF EXISTS itemNotes_itemID; + CREATE INDEX itemNotes_itemID ON itemNotes(itemID); + DROP TABLE IF EXISTS keywords; CREATE TABLE keywords ( keywordID INTEGER PRIMARY KEY,