lisimba / ext.data.websqlproxy Goto Github PK
View Code? Open in Web Editor NEWSench Touch WebSQL proxy for connecting models and stores to local WebSQL databases
Sench Touch WebSQL proxy for connecting models and stores to local WebSQL databases
The CREATE TABLE
SQL that was getting executed was incorrect, because it included the primary key twice. I updated constructFields
to have the following:
...
Ext.each(fields, function(f) {
var name = f.name;
if (name == me.pkField) { // added this
return; // added this
} // added this
var type = f.type.type;
...
setRecord: function(record) {
var me = this,
rawData = record.data,
fields = [],
values = [],
placeholders = [],
onSuccess = function(tx,rs,record) {
if (me.insertingInitialData) {
me.initialDataCount--;
if (me.initialDataCount === 0) {
me.insertingInitialData = false;
me.fireEvent('initialDataInserted');
}
}
// If record source did not have an id, then that means
// the database just generated one. So we'll update the
// record now.
if(typeof record.get('id') == 'undefined'){
record.internalId = rs.insertId;
record.data.id = rs.insertId;
}
};
//extract data to be inserted
for (var i in rawData) {
fields.push('"'+i+'"');
values.push(rawData[i]);
placeholders.push('?');
}
me.db.transaction(function(tx){
tx.executeSql('INSERT INTO ' + me.dbTable+'('+fields.join(',')+') VALUES ('+placeholders.join(',')+')',
values,
Ext.bind(onSuccess, me, [record], true), //on success
Ext.bind(me.onError, me)); // on error
});
return true;
},
I changed updateRecord
because id = record.internalId || record[me.pkField]
was turning up undefined, as were modifiedData = record.modified
and newData = record.data
.
I modified the id
variable to:
id = record.internalId || record[me.pkField] || record.data[me.pkField],
I changed the pairs
and values
initialization to:
/*for (var i in modifiedData) {
pairs.push('"'+i+'" = ?');
values.push(newData[i]);
}*/
var fields = Object.keys(record.data);
for (var i=0; i<fields.length; i++) {
var field = fields[i];
if (key == field) {
// Don't want to update primary key
continue;
}
pairs.push(field + ' = ?');
values.push(record.data[field]);
}
values.push(id);
The removeRecord
function says it takes an ID as a parameter, but using Chrome's debugger and Sencha Touch 1.1.1, what actually gets passed is the record itself (an instance of Ext.data.Model
). I made the following changes:
removeRecord: function(record) {
var me = this;
var id = record.internalId || record[me.pkField] || record.data[me.pkField];
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.