Skip to content

Commit 218d030

Browse files
authored
Merge pull request #120 from feefladder/readme-query-with-bindings
Add note about injection-safeness of query_with_bindings to README.md
2 parents 27b8d9a + 3751fd9 commit 218d030

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,21 @@ There are a couple of things you can do before panicking, namely:
266266
db.query_with_bindings("UPDATE "+ table_name +" SET "+ column_name +"=? WHERE id=?;", [100, 1])
267267
```
268268
269+
- SQLite's `query_with_bindings`, as also used by `update_rows`, is injection-safe. That is, any attempt to use sql inside of a bound variable will escape and insert it directly into the record. So the two equivalent statements:
270+
271+
```gdscript
272+
var table_name := "characters"
273+
db.query_with_bindings("UPDATE "+ table_name +" SET level=? WHERE id=?;", ["level+1", 1])
274+
db.update_rows(table_name, "id=1", {"level":"level+1"})
275+
```
276+
277+
will insert a literal `'level+1'` into the database, instead of incrementing the value by one. In stead, build a direct query:
278+
279+
```gdscript
280+
var table_name := "characters"
281+
db.query("UPDATE "+ table_name +" SET level=level+1 WHERE id=1")
282+
```
283+
269284
After exhausting these options, please open an issue that describes the error in proper detail.
270285

271286
### 2. Your plugin fails to load on my Windows machine!

0 commit comments

Comments
 (0)