Don't seem to be able to delete from SQLite

#1

I have an SQLite database, testing on my Andorid device, with a simple table, where I don’t seem to be able to get the SQLite delete command working.

I’ve removed the primary key etc to take that out of the equation.

My SQL looks like the following…

DELETE FROM MyTable WHERE GroupName = 'cars' AND Id IN ('CAR01','CAR02')

// Full code...
let db = await this.sqlite.create({name: 'mydb.sqlite', location: 'default'});
let delSql = `DELETE FROM ${this.TABLE_NAME} WHERE GroupName = '${groupName}' AND Id IN  ('CAR01','CAR02');
await db.executeSql(delSql); 

I just need to be able to delete before adding in new values. Inserts work fine, but whenever I try to delete, I get an exception with just the following…

image

No error strings, or no error in the console.

When I copy the database from the device, onto my desktop, and run the same SQL, it works no problems.

My Ionic info is

	$ ionic info

	cli packages: (C:\Users\peterc\AppData\Roaming\npm\node_modules)

		@ionic/cli-utils  : 1.19.2
		ionic (Ionic CLI) : 3.20.0

	global packages:

		cordova (Cordova CLI) : 7.0.1

	local packages:

		@ionic/app-scripts : 3.1.0
		Cordova Platforms  : android 6.2.3
		Ionic Framework    : ionic-angular 3.9.2

	System:

		Android SDK Tools : 26.0.2
		Node              : v8.11.3
		npm               : 5.6.0
		OS                : Windows 10

	Environment Variables:

		ANDROID_HOME : C:\Users\peterc\AppData\Local\Android\sdk

	Misc:

		backend : legacy

Does anyone have any ideas about this?

[UPDATE]

After the whole day on this, I realised, the delete was actually working (ie deleting), but it always throws the above exception even when it succeeds.

So I have had to add a local "exception gobbler "

 try {
        await db.executeSql(delSql);   
      } catch (error) {
      }

So I suppose the question is now why I always get an exception (that seems to have no details)

Thanks in advance

#2

Hi, today I faced your same issue executing some delete queries with the following plugin versions:

  • cordova-sqlite-storage: 2.5.2
  • ionic-native/sqlite: 4.16.0

I manage this strange situation with a code similar to this:

try {
await this.dataBase.executeSql(query, []);
console.log("success");
} catch(error) {
if(isSqlResultSet(error)){
console.warn("Not really an error");
} else {
console.error("error occurred " + error.message);
}

Where isSqlResultSet(error)) is a method that determines if the properties insertId, rows, rowsAffected are present in the given object.

#3

In my case, the problem was I forgot the second empty list to the call, ie I had

await this.dataBase.executeSql(query);

instead of

await this.dataBase.executeSql(query, []);

Ie I had forgotten the []

But it seems you have this in your query,