Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silently stops after first SQL statement in statement list #551

Open
brodybits opened this issue Sep 8, 2016 · 1 comment
Open

Silently stops after first SQL statement in statement list #551

brodybits opened this issue Sep 8, 2016 · 1 comment

Comments

@brodybits
Copy link
Contributor

Here is a test case that shows a possible silent data loss scenario if a statement list contains multiple INSERT statements:

        it(suiteName + 'INSERT statement list (NOT covered by Web SQL standard) - ' +
           (isWebSql ? 'Web SQL ERROR' : 'PLUGIN DEVIATION WITH DATA LOSS'), function(done) {
          var db = openDatabase('INSERT-statement-list-test.db', '1.0', 'Test', DEFAULT_SIZE);

          db.transaction(function(tx) {
            tx.executeSql('DROP TABLE IF EXISTS TestList;');
            tx.executeSql('CREATE TABLE TestList (data);');

            // NOT supported by Web SQL, plugin BROKEN:
            tx.executeSql('INSERT INTO TestList VALUES (1); INSERT INTO TestList VALUES(2);');
          }, function(error) {
            // ERROR RESULT (expected for Web SQL):
            if (!isWebSql)
              expect('Plugin behavior changed').toBe('--');
            expect(error).toBeDefined();

            // Close (plugin only) & finish:
            (isWebSql) ? done() : db.close(done, done);
          }, function() {
            if (isWebSql)
              expect('Unexpected result for Web SQL').toBe('--');

            db.transaction(function(tx2) {
              tx2.executeSql('SELECT * FROM TestList', [], function(ignored, resultSet) {
                // CORRECT RESULT:
                //expect(resultSet.rows.length).toBe(2);
                // ACTUAL RESULT for plugin WITH DATA LOSS:
                expect(resultSet.rows.length).toBe(1);

                // FIRST ROW CORRECT:
                expect(resultSet.rows.item(0).data).toBe(1);
                // SECOND ROW MISSING:
                //expect(resultSet.rows.item(1).data).toBe(2);

                // Close (plugin only) & finish:
                (isWebSql) ? done() : db.close(done, done);
              });
            });
          });
        }, MYTIMEOUT);

(WebKit) Web SQL rejects such a SQL statement list. The plugin should also reject such a SQL statement list and report an error.

To fix for iOS should be straightforward: When calling sqlite3_prepare_v2 check the OUT pzTail pointer to ensure there is no other statement afterwards. (And test what happens if a user adds one or more extra semicolons, with and without extra spaces in between, in both Web SQL and plugin.) This is expected to be more difficult for Android and Windows due to the extra library layers involved.

@filippopossenti
Copy link

Hi,
I am developing on a project that could actually benefit from the capability of running multiple statements within the same query.

Is there any chance to add support for the capability rather than just throwing an exception as described in #685 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants