How to use prepared statements in Sqflite for Flutter

512

You can use the question mark syntax.

db.rawQuery("SELECT * FROM t WHERE c = ?", [myString]);
Share:
512
Pitr _
Author by

Pitr _

Updated on December 11, 2022

Comments

  • Pitr _
    Pitr _ over 1 year

    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.

  • Andrew
    Andrew almost 3 years
    And how does it cause the statement to be prepared and reused in the future?
  • Martyns
    Martyns almost 3 years
    @Andrew It doesn't get prepared and reused as far as I know. If you want low level control you can take a look at: pub.dev/packages/sqlite3 Although, from experience with a heavily based Sqlite app on Flutter, you don't really need to care that much about PreparedStatements. Performance has always been great (50K+ rows tables and multiple joins)