commit fd85af40f89550e4da20638bd5693d0e49ae8682
parent e417d8e690b33be6cae789abd02df28abf42a4cb
Author: Dan Stillman <dstillman@zotero.org>
Date: Fri, 16 Jun 2006 07:32:48 +0000
Many-to-one item note support in the schema and data layer -- still some issues on (I think) the interface side
Diffstat:
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
@@ -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
@@ -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
@@ -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,