Skip to content

Commit

Permalink
Merge branch 'cordova-sqlite-storage-commoncore' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher J. Brody committed Aug 18, 2019
2 parents b7ffdf8 + 5b0cfb2 commit 0b2489f
Show file tree
Hide file tree
Showing 3 changed files with 286 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#### cordova-sqlite-storage 3.2.2-dev

##### cordova-sqlite-storage-commoncore 1.0.0

- additional EU string manipulation test cases

#### cordova-sqlite-storage 3.2.1

- [email protected] with SQLite 3.28.0 update for all supported platforms Android/iOS/macOS/Windows
Expand Down
113 changes: 98 additions & 15 deletions spec/www/spec/db-tx-error-mapping-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ var isBrowser = isWebKitBrowser || isFirefox;
var isEdgeBrowser = isBrowser && (/Edge/.test(navigator.userAgent));
var isChromeBrowser = isBrowser && !isEdgeBrowser && (/Chrome/.test(navigator.userAgent));
var isSafariBrowser = isWebKitBrowser && !isEdgeBrowser && !isChromeBrowser;
var isAppleMobileOS = /iPhone/.test(navigator.userAgent) ||
/iPad/.test(navigator.userAgent) || /iPod/.test(navigator.userAgent);
// detect iOS platform:
var isAppleMobileOS =
(/iPhone/.test(navigator.userAgent)
|| /iPad/.test(navigator.userAgent)
|| /iPod/.test(navigator.userAgent));

// should avoid popups (Safari seems to count 2x)
var DEFAULT_SIZE = isSafariBrowser ? 2000000 : 5000000;
Expand Down Expand Up @@ -99,10 +102,11 @@ var mytests = function() {
var db = openDatabase("Syntax-error-test.db", "1.0", "Demo", DEFAULT_SIZE);
expect(db).toBeDefined();

var sqlerror = null; // VERIFY this was received
// VERIFY that an error object was received in the end
var sqlerror = null;

db.transaction(function(tx) {
// This insertion has a SQL syntax error
// syntax error due to misspelling:
tx.executeSql('SLCT 1 ', [], function(tx) {
// NOT EXPECTED:
expect(false).toBe(true);
Expand Down Expand Up @@ -170,11 +174,84 @@ var mytests = function() {
});
}, MYTIMEOUT);

it(suiteName + 'INSERT with VALUES in the wrong place (with a trailing space) [TBD "incomplete input" vs "syntax error" message on (WebKit) Web SQL on Android 8.0(+) & iOS 12.0(+)]', function(done) {
it(suiteName + 'syntax error: comma after a field name', function(done) {
var db = openDatabase('comma-after-field-name-error-test.db');
expect(db).toBeDefined();

// VERIFY that an error object was received in the end
var sqlerror = null;

db.transaction(function(tx) {
// This insertion has a SQL syntax error
tx.executeSql('SELECT name, from Users', [], function(tx) {
// NOT EXPECTED:
expect(false).toBe(true);
throw new Error('abort tx');

}, function(tx, error) {
sqlerror = error;
expect(error).toBeDefined();
expect(error.code).toBeDefined();
expect(error.message).toBeDefined();

// error.hasOwnProperty('message') apparently NOT WORKING on
// WebKit Web SQL on Android 5.x/... or iOS 10.x/...:
if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))
expect(error.hasOwnProperty('message')).toBe(true);

if (isWindows || (isAndroid && isImpl2))
expect(error.code).toBe(0);
else
expect(error.code).toBe(5);

if (isWebSql && !(/Android 4.[1-3]/.test(navigator.userAgent)))
expect(error.message).toMatch(/could not prepare statement.*1 near \"from\": syntax error/);
else if (isWindows)
expect(error.message).toMatch(/Error preparing an SQLite statement/);
else
expect(error.message).toMatch(/near \"from\": syntax error/);

// FAIL transaction & check reported transaction error:
return true;
});
}, function (error) {
expect(!!sqlerror).toBe(true); // VERIFY the SQL error callback was triggered

expect(error).toBeDefined();
expect(error.code).toBeDefined();
expect(error.message).toBeDefined();

// error.hasOwnProperty('message') apparently NOT WORKING on
// WebKit Web SQL on Android 5.x/... or iOS 10.x/...:
if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))
expect(error.hasOwnProperty('message')).toBe(true);

if (isWindows || isWebSql || (isAndroid && isImpl2))
expect(error.code).toBe(0);
else
expect(error.code).toBe(5);

if (isWebSql)
expect(error.message).toMatch(/callback raised an exception.*or.*error callback did not return false/);
else if (isWindows)
expect(error.message).toMatch(/error callback did not return false.*Error preparing an SQLite statement/);
else
expect(error.message).toMatch(/error callback did not return false.*syntax error/);

isWebSql ? done() : db.close(done, done);
}, function() {
// NOT EXPECTED:
expect(false).toBe(true);
isWebSql ? done() : db.close(done, done);
});
}, MYTIMEOUT);

it(suiteName + 'INSERT with VALUES in the wrong place (and with a trailing space) [TBD "incomplete input" vs "syntax error" message IGNORED on (WebKit) Web SQL on Android 7.0(+) & iOS 12.0(+)]', function(done) {
var db = openDatabase("INSERT-Syntax-error-test.db", "1.0", "Demo", DEFAULT_SIZE);
expect(db).toBeDefined();

var sqlerror = null; // VERIFY this was received
// VERIFY that an error object was received in the end
var sqlerror = null;

db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS test_table');
Expand Down Expand Up @@ -202,10 +279,10 @@ var mytests = function() {
else
expect(error.code).toBe(5);

if (isWebSql && (isAppleMobileOS || /Android [7-9]/.test(navigator.userAgent)))
// TBD incomplete input vs syntax error message on Android 8.0(+) & iOS 12.0(+)
if (isWebSql && (isAppleMobileOS || (/Android [7-9]/.test(navigator.userAgent))))
// TBD incomplete input vs syntax error message IGNORED on Android 7.0(+) & iOS 12.0(+)
expect(error.message).toMatch(/could not prepare statement.*/);
else if (isWebSql && !isChromeBrowser && !(/Android 4.[1-3]/.test(navigator.userAgent)))
else if (isWebSql && !isBrowser && !(/Android 4.[1-3]/.test(navigator.userAgent)))
expect(error.message).toMatch(/could not prepare statement.*1 near \"VALUES\": syntax error/);
else if (isWebSql && isBrowser)
expect(error.message).toMatch(/could not prepare statement.*1 incomplete input/);
Expand Down Expand Up @@ -260,7 +337,8 @@ var mytests = function() {
var db = openDatabase("Constraint-violation-test.db", "1.0", "Demo", DEFAULT_SIZE);
expect(db).toBeDefined();

var sqlerror = null; // VERIFY this was received
// VERIFY that an error object was received in the end
var sqlerror = null;

db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS test_table');
Expand Down Expand Up @@ -352,7 +430,8 @@ var mytests = function() {
var db = openDatabase("Misspelled-function-name-error-test.db", "1.0", "Demo", DEFAULT_SIZE);
expect(db).toBeDefined();

var sqlerror = null; // VERIFY this was received
// VERIFY that an error object was received in the end
var sqlerror = null;

db.transaction(function(tx) {
// This insertion has a SQL syntax error
Expand Down Expand Up @@ -428,7 +507,8 @@ var mytests = function() {
var db = openDatabase("SELECT-FROM-bogus-table-error-test.db", "1.0", "Demo", DEFAULT_SIZE);
expect(db).toBeDefined();

var sqlerror = null; // VERIFY the SQL error callback was triggered
// VERIFY that an error object was received in the end
var sqlerror = null;

db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS BogusTable');
Expand Down Expand Up @@ -503,7 +583,8 @@ var mytests = function() {
var db = openDatabase("INSERT-missing-column-test.db", "1.0", "Demo", DEFAULT_SIZE);
expect(db).toBeDefined();

var sqlerror = null; // VERIFY this was received
// VERIFY that an error object was received in the end
var sqlerror = null;

db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS test_table');
Expand Down Expand Up @@ -580,7 +661,8 @@ var mytests = function() {
var db = openDatabase("INSERT-wrong-column-name-test.db", "1.0", "Demo", DEFAULT_SIZE);
expect(db).toBeDefined();

var sqlerror = null; // VERIFY this was received
// VERIFY that an error object was received in the end
var sqlerror = null;

db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS test_table');
Expand Down Expand Up @@ -660,7 +742,8 @@ var mytests = function() {
var db = openDatabase("create-virtual-table-using-bogus-module-error-test.db", "1.0", "Demo", DEFAULT_SIZE);
expect(db).toBeDefined();

var sqlerror = null; // VERIFY the SQL error callback was triggered
// VERIFY that an error object was received in the end
var sqlerror = null;

db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS test_table');
Expand Down
Loading

0 comments on commit 0b2489f

Please sign in to comment.