Permalink
Browse files

Added REPLACE to auto included ?

  • Loading branch information...
1 parent 0a9a883 commit 3fb631da2fe1491aaf57220157d8f61e5d8dbe15 @psayre23 committed May 23, 2012
Showing with 48 additions and 209 deletions.
  1. +5 −3 WebSQL.js
  2. +8 −8 WebSQL.min.js
  3. +5 −3 jquery.websql.js
  4. +6 −6 jquery.websql.min.js
  5. +5 −3 src/core.js
  6. +19 −2 test/WebSQL.html
  7. +0 −184 test/jquery.websql.html
View
@@ -1,6 +1,6 @@
/* WebSQL (v0.1) Paul Sayre */
(function (context) {
-
+ var VERSION = '0.2';
// Public object
var pub = context.WebSQL = function (name, ver, desc, size, cb) {
@@ -38,7 +38,7 @@
}
// Add ? for fields in insert
- parts = /^\s*INSERT\s+INTO\s+\w+\s*\(([^\)]+)\)\s*$/i.exec(sql);
+ parts = /^\s*(?:INSERT|REPLACE)\s+INTO\s+\w+\s*\(([^\)]+)\)\s*$/i.exec(sql);
if(parts && parts[1]) {
sql += ' VALUES ('+(new Array(parts[1].split(',').length)).join('?,')+'?)';
}
@@ -251,6 +251,8 @@
};
+ pub.VERSION = VERSION;
+
// Test if an argument is an array
var isArray = Array.isArray || function (arg) {
@@ -263,7 +265,7 @@
};
-})(window);
+})(this);
(function (pub) {
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,6 +1,6 @@
/* WebSQL (v0.1) Paul Sayre */
(function (context) {
-
+ var VERSION = '0.2';
// Public object
var pub = context.WebSQL = function (name, ver, desc, size, cb) {
@@ -38,7 +38,7 @@
}
// Add ? for fields in insert
- parts = /^\s*INSERT\s+INTO\s+\w+\s*\(([^\)]+)\)\s*$/i.exec(sql);
+ parts = /^\s*(?:INSERT|REPLACE)\s+INTO\s+\w+\s*\(([^\)]+)\)\s*$/i.exec(sql);
if(parts && parts[1]) {
sql += ' VALUES ('+(new Array(parts[1].split(',').length)).join('?,')+'?)';
}
@@ -251,6 +251,8 @@
};
+ pub.VERSION = VERSION;
+
// Test if an argument is an array
var isArray = Array.isArray || function (arg) {
@@ -263,7 +265,7 @@
};
-})(window);
+})(this);
(function ($, pub) {
pub.when = $.when;
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,5 +1,5 @@
(function (context) {
-
+ var VERSION = '0.2';
// Public object
var pub = context.WebSQL = function (name, ver, desc, size, cb) {
@@ -37,7 +37,7 @@
}
// Add ? for fields in insert
- parts = /^\s*INSERT\s+INTO\s+\w+\s*\(([^\)]+)\)\s*$/i.exec(sql);
+ parts = /^\s*(?:INSERT|REPLACE)\s+INTO\s+\w+\s*\(([^\)]+)\)\s*$/i.exec(sql);
if(parts && parts[1]) {
sql += ' VALUES ('+(new Array(parts[1].split(',').length)).join('?,')+'?)';
}
@@ -250,6 +250,8 @@
};
+ pub.VERSION = VERSION;
+
// Test if an argument is an array
var isArray = Array.isArray || function (arg) {
@@ -262,5 +264,5 @@
};
-})(window);
+})(this);
View
@@ -31,6 +31,7 @@
ok(WebSQL, 'global object exists');
equal(typeof WebSQL.Deferred, 'function', 'Deferred is function');
equal(typeof WebSQL.when, 'function', 'when is function');
+ equal(typeof WebSQL.VERSION, 'string', 'Version number is exposed');
});
@@ -196,6 +197,23 @@
});
+ asyncTest('single replace', function () {
+ var db = WebSQL('test');
+ db.query(
+ 'DROP TABLE IF EXISTS tests',
+ 'CREATE TABLE tests (id INTEGER PRIMARY KEY AUTOINCREMENT, num INTEGER)'
+ );
+
+ var promise = db.query('REPLACE INTO tests (num)', [6]);
+
+ testPromise(promise);
+ promise.done(function (res) {
+ strictEqual(res.insertId, 1, 'Insert ID matched');
+ start();
+ });
+ });
+
+
asyncTest('multi insert', function () {
var db = WebSQL('test');
db.query(
@@ -224,16 +242,15 @@
[ [6], [7], [8], [9] ]
);
-
testPromise(promise);
-
promise.done(function () {
db.dump('json', true)
.fail(failCB('dump failed'))
.done(function (json) {
equal(typeof json, 'object', 'Results came back');
equal(typeof json['tests'], 'object', 'Tests table exists');
equal(json.tests.data.constructor, Array, 'Data is an array');
+ equal(json.tests.data[1].num, 7, 'Value exported correctly');
equal(json.tests.schema.table, createTableSQL, 'Create table SQL matches');
equal(json.tests.schema.indexes.length, 1, 'One index');
equal(json.tests.schema.indexes[0], createIndexSQL, 'Create index SQL matches');
Oops, something went wrong.

0 comments on commit 3fb631d

Please sign in to comment.