Fixed error in new item itemData insert (trying to bind across multiple statements) (yes we need unit tests)

Missing parens in Items._load() causing it to load all items in !all mode

Show type in debug output when binding params
This commit is contained in:
Dan Stillman 2006-06-02 16:37:17 +00:00
parent 60ada26e8d
commit 8f34487205
3 changed files with 14 additions and 19 deletions

View file

@ -410,7 +410,7 @@ Scholar.Item.prototype.save = function(){
if (Scholar.DB.valueQuery(sql2)){ if (Scholar.DB.valueQuery(sql2)){
sql = 'UPDATE itemCreators SET creatorID=?, ' sql = 'UPDATE itemCreators SET creatorID=?, '
+ 'creatorTypeID=? WHERE itemID=?' + 'creatorTypeID=? WHERE itemID=?'
+ " AND orderIndex=?;\n"; + " AND orderIndex=?";
sqlValues = [ sqlValues = [
{'int':creatorID}, {'int':creatorID},
@ -423,7 +423,7 @@ Scholar.Item.prototype.save = function(){
} }
// Otherwise insert // Otherwise insert
else { else {
sql = "INSERT INTO itemCreators VALUES (?,?,?,?);\n"; sql = "INSERT INTO itemCreators VALUES (?,?,?,?)";
sqlValues = [ sqlValues = [
{'int':itemID}, {'int':itemID},
@ -468,7 +468,7 @@ Scholar.Item.prototype.save = function(){
else { else {
sqlValues.push({'string':this.getField(fieldID)}); sqlValues.push({'string':this.getField(fieldID)});
} }
sql += " WHERE itemID=? AND fieldID=?;\n"; sql += " WHERE itemID=? AND fieldID=?";
sqlValues.push( sqlValues.push(
{'int':this.getID()}, {'int':this.getID()},
@ -478,8 +478,8 @@ Scholar.Item.prototype.save = function(){
Scholar.DB.query(sql, sqlValues); Scholar.DB.query(sql, sqlValues);
} }
else { else {
sql = "INSERT INTO itemData VALUES (?,?,?);\n"; sql = "INSERT INTO itemData VALUES (?,?,?)";
sqlValues = [ sqlValues = [
{'int':this.getID()}, {'int':this.getID()},
{'int':fieldID}, {'int':fieldID},
@ -505,7 +505,7 @@ Scholar.Item.prototype.save = function(){
if (del.length){ if (del.length){
sql = 'DELETE from itemData ' sql = 'DELETE from itemData '
+ 'WHERE itemID=' + this.getID() + ' ' + 'WHERE itemID=' + this.getID() + ' '
+ 'AND fieldID IN (' + del.join() + ");\n"; + 'AND fieldID IN (' + del.join() + ")";
Scholar.DB.query(sql); Scholar.DB.query(sql);
} }
} }
@ -559,9 +559,6 @@ Scholar.Item.prototype.save = function(){
// Set itemData // Set itemData
if (this._changedItemData.length){ if (this._changedItemData.length){
sql = '';
sqlValues = [];
for (fieldID in this._changedItemData.items){ for (fieldID in this._changedItemData.items){
if (!this.getField(fieldID)){ if (!this.getField(fieldID)){
continue; continue;
@ -570,12 +567,12 @@ Scholar.Item.prototype.save = function(){
// TODO: update DB methods so that this can be // TODO: update DB methods so that this can be
// implemented as a prepared statement that gets // implemented as a prepared statement that gets
// called multiple times // called multiple times
sql += "INSERT INTO itemData VALUES (?,?,?);\n"; sql = "INSERT INTO itemData VALUES (?,?,?)";
sqlValues.push( sqlValues = [
{'int':itemID}, {'int':itemID},
{'int':fieldID} {'int':fieldID}
); ];
if (Scholar.ItemFields.isInteger(fieldID)){ if (Scholar.ItemFields.isInteger(fieldID)){
sqlValues.push({'int':this.getField(fieldID)}); sqlValues.push({'int':this.getField(fieldID)});
@ -583,9 +580,7 @@ Scholar.Item.prototype.save = function(){
else { else {
sqlValues.push({'string':this.getField(fieldID)}); sqlValues.push({'string':this.getField(fieldID)});
} }
}
if (sql){
Scholar.DB.query(sql, sqlValues); Scholar.DB.query(sql, sqlValues);
} }
} }
@ -923,7 +918,7 @@ Scholar.Items = new function(){
+ 'FROM items I ' + 'FROM items I '
+ 'LEFT JOIN itemCreators IC ON (I.itemID=IC.itemID) ' + 'LEFT JOIN itemCreators IC ON (I.itemID=IC.itemID) '
+ 'LEFT JOIN creators C ON (IC.creatorID=C.creatorID) ' + 'LEFT JOIN creators C ON (IC.creatorID=C.creatorID) '
+ 'WHERE IC.orderIndex=0 OR IC.orderIndex IS NULL'; + 'WHERE (IC.orderIndex=0 OR IC.orderIndex IS NULL)';
if (arguments[0]!='all'){ if (arguments[0]!='all'){
sql += ' AND I.itemID IN (' + Scholar.join(arguments,',') + ')'; sql += ' AND I.itemID IN (' + Scholar.join(arguments,',') + ')';

View file

@ -170,12 +170,12 @@ Scholar.DB = new function(){
if (statement && params){ if (statement && params){
for (var i=0; i<params.length; i++){ for (var i=0; i<params.length; i++){
if (typeof params[i]['int'] != 'undefined'){ if (typeof params[i]['int'] != 'undefined'){
Scholar.debug('Binding parameter ' + (i+1) + ': ' + Scholar.debug('Binding parameter ' + (i+1) + ' of type int: ' +
params[i]['int'],5); params[i]['int'],5);
statement.bindInt32Parameter(i,params[i]['int']); statement.bindInt32Parameter(i,params[i]['int']);
} }
else if (typeof params[i]['string'] != 'undefined'){ else if (typeof params[i]['string'] != 'undefined'){
Scholar.debug('Binding parameter ' + (i+1) + ': "' + Scholar.debug('Binding parameter ' + (i+1) + ' of type string: "' +
params[i]['string'] + '"',5); params[i]['string'] + '"',5);
statement.bindUTF8StringParameter(i,params[i]['string']); statement.bindUTF8StringParameter(i,params[i]['string']);
} }

View file

@ -74,7 +74,7 @@ Scholar.Notifier = new function(){
} }
function _unregister(type, hash){ function _unregister(type, hash){
Scholar.debug('Unregistering ' + type + ' in notifier with hash ' + hash, 4); Scholar.debug("Unregistering ' + type + ' in notifier with hash '" + hash + "'", 4);
delete _observers[type][hash]; delete _observers[type][hash];
} }
} }