Pitr _
Pitr _

Reputation: 53

How to use prepared statements in Sqflite for Flutter

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

Answers (2)

Christopher Natan
Christopher Natan

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

Martyns
Martyns

Reputation: 3875

You can use the question mark syntax.

db.rawQuery("SELECT * FROM t WHERE c = ?", [myString]);

Upvotes: 4

Related Questions