Reputation: 53
How do I use prepared statements in Sqflite in Flutter? It seems to be missing some functions or it's just completely differently arranged. Currently, I'm using the standard rawInsert but my strings can sometimes break the query.
Upvotes: 3
Views: 1148
Reputation: 111
I am using transaction with rawInsert. In this code inserting will be ignored if there is an existing record.
return await Storage.database.transaction((txn) async {
await txn.rawInsert('INSERT OR IGNORE INTO $tableName(id, sender_id, recipient_id, message_id, message)' + 'VALUES("$id", "$senderId", "$recipientId", "$messageId", "$message")');
}).catchError((e) {
throw (e);
});
Upvotes: 0
Reputation: 3875
You can use the question mark syntax.
db.rawQuery("SELECT * FROM t WHERE c = ?", [myString]);
Upvotes: 4