SQLiteSQLBuilder.prototype.buildSQLUpdateSQL = function (dataObject, tablename, allowFields, options, idAttribute) { var self = this; var modify = this.buildFieldValues(dataObject, allowFields, idAttribute); var condition = this.buildWheres(options); var parameters = modify.parameters || []; parameters = parameters.concat(condition.parameters); return { parameters: parameters, sql: framework.String.Format("UPDATE {0} SET {1} {2};", tablename, modify.express, condition.express) }; }
this.execute(prepare.sql, prepare.parameters, function (err, info) { if (err == null && self.autoIncrement) { self.query(framework.String.Format("select {0} from [{1}] order by {0} desc limit 1;", idAttribute, self.tablename), [], function (err2, info) { self.dispatch("INSERT"); self.Env.Call(callback, err2, info[0][idAttribute]); }); } else { self.dispatch("INSERT"); self.Env.Call(callback, err, info); } });
SQLiteInnerAccessor.prototype.changeTable = function (newtable, id, autoIncrement) { if (framework.String.Equals(newtable, this.tablename, true)) { return; } this.tablename = newtable; this.idAttribute = id; this.autoIncrement = autoIncrement; this.fields = []; var self = this; //添加获取字段元数据队列 this.addTopLevel(function (callback) { self.readyFields(callback); }); }
SQLiteSQLBuilder.prototype.buildSelectSQL = function (tablename, options) { options = options || {}; var checkQues = this.checkQues; var condition = this.buildWheres(options); var fields = options.fields || []; var limit = options.limit; var offset = options.offset; var inject = fields.join(''); if (inject.indexOf("`") > -1 || fields.length <= 0) { fields = null; } var field_express = checkQues.isArray(fields) ? ("`" + fields.join("`,`") + "`") : "*"; var limit_express = (limit && parseInt(limit) > 0) ? " LIMIT " + parseInt(limit) : ""; var offset_express = (offset && parseInt(offset) > 0) ? " OFFSET " + parseInt(offset) : ""; var sql = framework.String.Format("SELECT {0} FROM {1} {2} {3} {4};", field_express, tablename, condition.express, limit_express, offset_express); return { parameters: condition.parameters, sql: sql }; }
SQLiteSQLBuilder.prototype.buildDeleteSQL = function (tablename, options) { var context = this.buildWheres(options); return { parameters: context.parameters, sql: framework.String.Format("DELETE FROM {0} {1};", tablename, context.express) }; }