You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Binds the parameters contained in the `param_bindings`-variable to the query. Using this function stops any possible attempts at SQL data injection as the parameters are sanitized. More information regarding parameter bindings can be found [here](https://www.sqlite.org/c3ref/bind_blob.html).
116
+
Binds the parameters using nameless variables contained in the `param_bindings`-variable to the query. Using this function stops any possible attempts at SQL data injection as the parameters are sanitized. More information regarding parameter bindings can be found [here](https://www.sqlite.org/c3ref/bind_blob.html).
117
117
118
118
**Example usage**:
119
119
@@ -130,6 +130,27 @@ Additionally, a video tutorial by [Mitch McCollum (finepointcgi)](https://github
130
130
131
131
***NOTE**: Binding column names is not possible due to SQLite restrictions. If dynamic column names are required, insert the column name directly into the `query_string`-variable itself (see https://github.com/2shady4u/godot-sqlite/issues/41).*
Binds the parameters using named variables contained in the `param_bindings`-variable to the query. This will only work with String or StringName keys in the dictionary. If the named parameter is not found in the dictionary the query will fail. Using this function stops any possible attempts at SQL data injection as the parameters are sanitized. More information regarding parameter bindings can be found [here](https://www.sqlite.org/c3ref/bind_blob.html).
136
+
137
+
**Example usage**:
138
+
139
+
```gdscript
140
+
var column_name : String = "name";
141
+
var query_string : String = "SELECT %s FROM company WHERE age < :age;" % [column_name]
142
+
var param_bindings : Dictionary = { "age": 24 }
143
+
var success = db.query_with_named_bindings(query_string, param_bindings)
144
+
# Executes following query:
145
+
# SELECT name FROM company WHERE age < 24;
146
+
```
147
+
148
+
This will support the use of `:`, `@`, `$`, `?` as prefixes for the names. These are all treated the same ?age, :age, $age, @age. When passing in the dictionary only provide the word 'age' with no prefix.
149
+
150
+
Using bindings is optional, except for PackedByteArray (= raw binary data) which has to binded to allow the insertion and selection of BLOB data in the database.
151
+
152
+
***NOTE**: Binding column names is not possible due to SQLite restrictions. If dynamic column names are required, insert the column name directly into the `query_string`-variable itself (see https://github.com/2shady4u/godot-sqlite/issues/41).*
Each key/value pair of the `table_dictionary`-variable defines a column of the table. Each key defines the name of a column in the database, while the value is a dictionary that contains further column specifications.
Copy file name to clipboardExpand all lines: doc_classes/SQLite.xml
+21-1Lines changed: 21 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -82,6 +82,26 @@
82
82
[i][b]NOTE:[/b] Binding column names is not possible due to SQLite restrictions. If dynamic column names are required, insert the column name directly into the [code]query_string[/code]-variable itself (see [url=https://github.com/2shady4u/godot-sqlite/issues/41]https://github.com/2shady4u/godot-sqlite/issues/41[/url]).[/i]
83
83
</description>
84
84
</method>
85
+
<methodname="query_with_named_bindings">
86
+
<returntype="bool" />
87
+
<description>
88
+
Binds the parameters contained in the [code]param_bindings[/code]-variable to the query. This will only work with String or StringName keys in the dictionary.
89
+
If the named parameter is not found in the dictionary the query will fail.
90
+
Using this function stops any possible attempts at SQL data injection as the parameters are sanitized. More information regarding parameter bindings can be found [url=https://www.sqlite.org/c3ref/bind_blob.html]here[/url].
91
+
[b]Example usage[/b]:
92
+
[codeblock]
93
+
var column_name : String = "name";
94
+
var query_string : String = "SELECT %s FROM company WHERE age < :age;" % [column_name]
95
+
var param_bindings : Dictionary = { "age": 24 }
96
+
var success = db.query_with_named_bindings(query_string, param_bindings)
97
+
# Executes following query:
98
+
# SELECT name FROM company WHERE age < 24;
99
+
[/codeblock]
100
+
This will support the use of [code]:[/code], [code]@[/code], [code]$[/code], [code]?[/code] as prefixes for the names. These are all treated the same [code]?age[/code], [code]:age[/code], [code]$age[/code], [code]@age[/code]. When passing in the dictionary only provide the word [code]age[/code] with no prefix.
101
+
Using bindings is optional, except for PackedByteArray (= raw binary data) which has to binded to allow the insertion and selection of BLOB data in the database.
102
+
[i][b]NOTE:[/b] Binding column names is not possible due to SQLite restrictions. If dynamic column names are required, insert the column name directly into the [code]query_string[/code]-variable itself (see [url=https://github.com/2shady4u/godot-sqlite/issues/41]https://github.com/2shady4u/godot-sqlite/issues/41[/url]).[/i]
103
+
</description>
104
+
</method>
85
105
<methodname="create_table">
86
106
<returntype="bool" />
87
107
<description>
@@ -107,7 +127,7 @@
107
127
"auto_increment": true
108
128
}
109
129
[/codeblock]
110
-
For more concrete usage examples see the [code]database.gd[/code]-file as found [url=https://github.com/2shady4u/godot-sqlite/blob/master/demo/database.gd]here[url].
130
+
For more concrete usage examples see the [code]database.gd[/code]-file as found [url=https://github.com/2shady4u/godot-sqlite/blob/master/demo/database.gd]here[/url].
0 commit comments