Add <bind> bound parameters for <sql> (phase 1)
Implements phase 1 of docs/design-sql-bound-parameters.md: <bind> supplies the value for the next ? placeholder of the enclosing <sql>, with typed validation (int, decimal, date, datetime, bool, ident with allow list), null="empty", and refusal to change the connection character set. - SqlBind.*: MySQL-free placeholder scanning and binding logic - __bind.*, __sql, __mysql: runtime wiring - Tag.cpp, jetc/JetParser.cpp: bind is a void tag in both - jetc/JetCodegen: emit sized ZString literals for text holding a NUL, which previously truncated the compiled page - tests: unit tests, end-to-end test against MySQL (interpreted and jetc-compiled), and the generator for the binary test page Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9fae14eb96
commit
a18d1358b0
18 files changed
+1103
-9
No files matched your search
+17
@@ -108,6 +108,10 @@ namespace jet {
|
||||
|
||||
if(!mysql) {
|
||||
MYSQL *handle = mysql_init(NULL);
|
||||
// Pin the connection character set so <bind>'s client-side
|
||||
// escaping and the server's parsing always agree (<sql> refuses
|
||||
// SET NAMES and friends for the same reason).
|
||||
mysql_options(handle, MYSQL_SET_CHARSET_NAME, "utf8mb4");
|
||||
mysql = mysql_real_connect(handle,
|
||||
hostVal.c_str(),
|
||||
userVal.c_str(),
|
||||
@@ -207,6 +211,19 @@ namespace jet {
|
||||
}
|
||||
}
|
||||
|
||||
std::string __mysql::escapeString(const std::string &value) {
|
||||
std::string to(value.size() * 2 + 1, '\0');
|
||||
unsigned long len = mysql_real_escape_string_quote(mysql, to.data(), value.data(), value.size(), '\'');
|
||||
if(len == (unsigned long)-1)
|
||||
throw coreutils::Exception("sql: bind value could not be escaped.");
|
||||
to.resize(len);
|
||||
return to;
|
||||
}
|
||||
|
||||
bool __mysql::noBackslashEscapes() {
|
||||
return (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES) != 0;
|
||||
}
|
||||
|
||||
void __mysql::nextRow() {
|
||||
row = mysql_fetch_row(result);
|
||||
fieldLength = mysql_fetch_lengths(result);
|
||||
|
||||
Reference in new issue
Block a user