diff options
| author | 2021-10-18 19:22:50 +0200 | |
|---|---|---|
| committer | 2021-10-18 21:26:06 +0200 | |
| commit | b489de9bfc2ce906dbb9c866938747fb2a16496a (patch) | |
| tree | 1c9ff1456170251904c0e278c2f863d40d4bdb02 /sqlite.zig | |
| parent | update sqlite bundled source code to 3.36.0 (diff) | |
| download | zig-sqlite-b489de9bfc2ce906dbb9c866938747fb2a16496a.tar.gz zig-sqlite-b489de9bfc2ce906dbb9c866938747fb2a16496a.tar.xz zig-sqlite-b489de9bfc2ce906dbb9c866938747fb2a16496a.zip | |
improve documentation of DynamicStatement
Diffstat (limited to 'sqlite.zig')
| -rw-r--r-- | sqlite.zig | 54 |
1 files changed, 27 insertions, 27 deletions
| @@ -1042,38 +1042,38 @@ pub fn StatementType(comptime opts: StatementOptions, comptime query: []const u8 | |||
| 1042 | 1042 | ||
| 1043 | pub const StatementOptions = struct {}; | 1043 | pub const StatementOptions = struct {}; |
| 1044 | 1044 | ||
| 1045 | /// DynamicStatement represents a statement in sqlite3. It almost works like sqlite3_stmt. | 1045 | /// DynamicStatement is a wrapper around a SQLite statement, providing high-level functions to execute |
| 1046 | /// The difference to `Statement` is that this structure comes without addtional comptime type-checking. | 1046 | /// a statement and retrieve rows for SELECT queries. |
| 1047 | /// | 1047 | /// |
| 1048 | /// The structure supports "host parameter names", which used in query to identify bind marker: | 1048 | /// The difference to `Statement` is that this type isn't bound to a single parsed query and can execute any query. |
| 1049 | /// ```` | 1049 | /// |
| 1050 | /// SELECT email FROM users WHERE name = @name AND password = $password; | 1050 | /// `DynamicStatement` supports "host parameter names", which can be used in a query to identify a bind marker: |
| 1051 | /// ```` | 1051 | /// |
| 1052 | /// | 1052 | /// SELECT email FROM users WHERE name = @name AND password = $password; |
| 1053 | /// To use these names, pass a normal structure instead of a tuple. Set `stmt` is the related `DynamicStatement`: | 1053 | /// |
| 1054 | /// ```` | 1054 | /// You can read more about these parameters in the sqlite documentation: https://sqlite.org/c3ref/bind_blob.html |
| 1055 | /// try stmt.one(.{ | ||
| 1056 | /// .name = "Tankman", .password = "Passw0rd", | ||
| 1057 | /// }) | ||
| 1058 | /// ```` | ||
| 1059 | /// | 1055 | /// |
| 1060 | /// It doesn't matter "@", "$" or ":" is being used, the one will be automatically chosen, | 1056 | /// To use these names use an anonymous struct with corresponding names like this: |
| 1061 | /// but it's not recommended to mix them up, because: sqlite3 thinks @A, $A and :A are | ||
| 1062 | /// different, but `DynamicStatement` will try :A, @A, $A in order when you passing a 'A' field. | ||
| 1063 | /// The ":A" will be binded while "@A", "$A" are left behind. | ||
| 1064 | /// TL;DR: don't use same name with different prefix ("@", "$", ":"). | ||
| 1065 | /// | 1057 | /// |
| 1066 | /// You can use unnamed markers with tuple: | 1058 | /// const stmt = "SELECT * FROM users WHERE name = @name AND password = @pasdword"; |
| 1067 | /// ```` | 1059 | /// const row = try stmt.one(Row, .{ |
| 1068 | /// SELECT email FROM users WHERE name = ? AND password = ?; | 1060 | /// .name = "Tankman", |
| 1069 | /// ```` | 1061 | /// .password = "Passw0rd", |
| 1070 | /// | 1062 | /// }); |
| 1071 | /// ```` | 1063 | /// |
| 1072 | /// try stmt.one(.{"Tankman", "Passw0rd"}); | 1064 | /// This works regardless of the prefix you used in the query. |
| 1073 | /// ```` | 1065 | /// While using the same name with a different prefix is supported by sqlite, `DynamicStatement` doesn't support |
| 1066 | /// it because we can't have multiple fields in a struct with the same name. | ||
| 1067 | /// | ||
| 1068 | /// You can also use unnamed markers with a tuple: | ||
| 1074 | /// | 1069 | /// |
| 1070 | /// const stmt = "SELECT email FROM users WHERE name = ? AND password = ?"; | ||
| 1071 | /// const row = try stmt.one(Row, .{"Tankman", "Passw0rd"}); | ||
| 1072 | /// | ||
| 1073 | /// TODO(vincent): clarify the following | ||
| 1075 | /// Named and unnamed markers could not be mixed, functions might be failed in slient. | 1074 | /// Named and unnamed markers could not be mixed, functions might be failed in slient. |
| 1076 | /// (Just like sqlite3's sqlite3_stmt, the unbinded values will be treated as NULL.) | 1075 | /// (Just like sqlite3's sqlite3_stmt, the unbinded values will be treated as NULL.) |
| 1076 | /// | ||
| 1077 | pub const DynamicStatement = struct { | 1077 | pub const DynamicStatement = struct { |
| 1078 | db: *c.sqlite3, | 1078 | db: *c.sqlite3, |
| 1079 | stmt: *c.sqlite3_stmt, | 1079 | stmt: *c.sqlite3_stmt, |