Fixed object level calculation (containing folder's level+1, not folder's level itself); updated schema to match

This commit is contained in:
Dan Stillman 2006-05-16 07:21:31 +00:00
parent 396cce8a0d
commit 3f398783d1
4 changed files with 10 additions and 5 deletions

View file

@ -68,7 +68,7 @@ Scholar.Object.prototype.isEditableField = function(field){
* Build object from database
*/
Scholar.Object.prototype.loadFromID = function(id){
var sql = 'SELECT O.*, lastName AS firstCreator, F.level, ORD.orderIndex '
var sql = 'SELECT O.*, lastName AS firstCreator, F.level+1 AS level, ORD.orderIndex '
+ 'FROM objects O '
+ 'LEFT JOIN folders F USING (folderID) '
+ 'LEFT JOIN treeOrder ORD ON (O.objectID=ORD.id AND isFolder=0) '
@ -899,7 +899,7 @@ Scholar.Objects = new function(){
}
// Should be the same as query in Scholar.Object.loadFromID, just without objectID clause
var sql = 'SELECT O.*, lastName AS firstCreator, F.level, ORD.orderIndex '
var sql = 'SELECT O.*, lastName AS firstCreator, F.level+1 AS level, ORD.orderIndex '
+ 'FROM objects O '
+ 'LEFT JOIN folders F USING (folderID) '
+ 'LEFT JOIN treeOrder ORD ON (O.objectID=ORD.id AND isFolder=0) '

View file

@ -416,6 +416,11 @@ Scholar.DB = new function(){
}
if (i==5){
query("UPDATE folders SET level=-1, parentFolderID=NULL WHERE folderID=0");
_updateDBVersion(i);
}
if (i==6){
// do stuff
// _updateDBVersion(i);
}

View file

@ -1,7 +1,7 @@
const SCHOLAR_CONFIG = {
GUID: 'scholar@chnm',
DB_FILE: 'scholar.sqlite',
DB_VERSION: 3,
DB_VERSION: 5, // must match version at top of schema.sql
DB_REBUILD: false, // erase DB and recreate from schema
DEBUG_LOGGING: true,
DEBUG_TO_CONSOLE: false // dump debug messages to console rather than (much slower) Debug Logger

View file

@ -1,4 +1,4 @@
-- 3
-- 5
DROP TABLE IF EXISTS version;
CREATE TABLE version (
@ -112,7 +112,7 @@
FOREIGN KEY (parentFolderID) REFERENCES folders(folderID)
);
CREATE INDEX parentFolderID ON folders(parentFolderID);
INSERT INTO folders VALUES (0, 'root', 0, 0);
INSERT INTO folders VALUES (0, 'root', NULL, -1);
DROP TABLE IF EXISTS treeOrder;
CREATE TABLE treeOrder (