cannot detect if table was dropped sqlite

RESOLVED INVALID

Status

()

Toolkit
Storage
RESOLVED INVALID
6 years ago
2 years ago

People

(Reporter: noitidart, Unassigned)

Tracking

15 Branch
x86
Windows XP
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

6 years ago
User Agent: Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20100101 Firefox/15.0.1
Build ID: 20120905151427

Steps to reproduce:

I want to drop a table, and i want to know if it was dropped or not. (i also want to do the opposite, create it, and detect if it was created, but this example uses dropping)

if the table is not present, and i drop it, it throws an error. if i put it in a try catch there is no exception even if the table is not present and i am trying to drop it. this is inconsistent. if error is thrown when not in a try catch, an exception should be thrown when inside a try catch.

This code throws error as table doesnt exist:
[code]
        let s610520 = dbConn.createStatement('DROP TABLE main;');
        s610520.executeAsync({
            handleResult: function (aResultSet) {
        		//for (let row = aResultSet.getNextRow(); row; row = aResultSet.getNextRow()) {
        		//	let value = row.getResultByName("column_name");
        		//}
                Cu.reportError('start dump aResultSet');
                cDump(aResultSet);
                Cu.reportError('end dump aResultSet');
        	},
        
        	handleError: function (aError) {
        		Cu.reportError('s610520 Error: ' + aError.message);
        	},
        
        	handleCompletion: function (aReason) {
        		if (aReason != Ci.mozIStorageStatementCallback.REASON_FINISHED) {
            	    Cu.reportError('s610520 Query canceled or aborted!');
        		} else {
                    //will only throw this if the table gets made
                    Cu.reportError('s610520 completed succesfully: ' + aReason);
                    cDump(dbConn);
        		}
        	}
        });
[/code]

This code throws no exception when table doesnt exist. It should throw an exception.
[code]
        try {
        let s610520 = dbConn.createStatement('DROP TABLE main;');
        s610520.executeAsync({
            handleResult: function (aResultSet) {
        		//for (let row = aResultSet.getNextRow(); row; row = aResultSet.getNextRow()) {
        		//	let value = row.getResultByName("column_name");
        		//}
                Cu.reportError('start dump aResultSet');
                cDump(aResultSet);
                Cu.reportError('end dump aResultSet');
        	},
        
        	handleError: function (aError) {
        		Cu.reportError('s610520 Error: ' + aError.message);
        	},
        
        	handleCompletion: function (aReason) {
        		if (aReason != Ci.mozIStorageStatementCallback.REASON_FINISHED) {
            	    Cu.reportError('s610520 Query canceled or aborted!');
        		} else {
                    //will only throw this if the table gets made
                    Cu.reportError('s610520 completed succesfully: ' + aReason);
                    cDump(dbConn);
        		}
        	}
        });
        } catch (ex) {
            Cu.reportError('COULD NOT DROP: ' + ex);
       } 
[/code]


If you would like to create table please test with:
[code]
    dbFile = FileUtils.getFile('ProfD', ['surfacenotes.sqlite']);
    var alreadyExists = dbFile.exists();
    dbConn = Services.storage.openDatabase(dbFile); // Will also create the file if it does not exist
        let s610520 = dbConn.createStatement('CREATE TABLE main (id INTEGER NOT NULL PRIMARY KEY, type INTEGER NOT NULL, url TEXT NOT NULL, body TEXT, style TEXT NOT NULL, rel INTEGER, caret_start INTEGER NOT NULL, caret_end INTEGER, scroll_x INTEGER, scroll_y INTEGER);');
[/code]
Please describe the area this belongs to. Is this part of an addon or DOM storage ?
(Reporter)

Comment 2

6 years ago
oh this is apart of xpcom storage. not dom storage.
Component: Untriaged → Storage
Product: Firefox → Toolkit
the above code cannot work as expected cause when the callback is invoked the try/catch already finished.
It would work only using a Task and yield (or async function and await).
Status: UNCONFIRMED → RESOLVED
Last Resolved: 2 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.