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
+10
-3
@@ -32,6 +32,13 @@ namespace jetc {
|
||||
return r;
|
||||
}
|
||||
|
||||
std::string Codegen::zstr(const std::string &raw) {
|
||||
// A plain C string literal stops at its first NUL, so text holding
|
||||
// one (raw bytes in a page) has to carry its length explicitly.
|
||||
if (raw.find('\0') == std::string::npos) return cstr(raw);
|
||||
return "coreutils::ZString(" + cstr(raw) + ", " + std::to_string(raw.size()) + ")";
|
||||
}
|
||||
|
||||
const char *Codegen::staticTypeOp(const std::string &type, const char *rc) {
|
||||
// type is known at compile time (a literal attribute value, not a
|
||||
// runtime expression) so the comparison operator is picked once here
|
||||
@@ -59,7 +66,7 @@ namespace jetc {
|
||||
|
||||
case NodeKind::TEXT: {
|
||||
if (n->text.empty()) break;
|
||||
target << I << "out << " << cstr(n->text) << ";\n";
|
||||
target << I << "out << " << zstr(n->text) << ";\n";
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -166,7 +173,7 @@ namespace jetc {
|
||||
}
|
||||
|
||||
case NodeKind::FALLBACK: {
|
||||
target << I << "{ coreutils::ZString span(" << cstr(n->rawSpan) << "); scope.interpretSpan(span, out); }\n";
|
||||
target << I << "{ coreutils::ZString span(" << zstr(n->rawSpan) << "); scope.interpretSpan(span, out); }\n";
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -213,7 +220,7 @@ namespace jetc {
|
||||
// correctness fallback: any invocation this compiler doesn't
|
||||
// itself recognize - e.g. reached through content this pass
|
||||
// never compiled - still resolves it exactly as it always has).
|
||||
target << I << "{ coreutils::ZString span(" << cstr(n->rawSpan) << "); scope.interpretSpan(span, out); }\n";
|
||||
target << I << "{ coreutils::ZString span(" << zstr(n->rawSpan) << "); scope.interpretSpan(span, out); }\n";
|
||||
if (compiledOk) {
|
||||
// The registration into compiledTags right after is the only
|
||||
// new behavior beyond the raw registration above - a pure
|
||||
|
||||
@@ -86,6 +86,7 @@ namespace jetc {
|
||||
void emitNode(const NodePtr &n, int indent, std::ostringstream &target);
|
||||
static std::string ind(int indent);
|
||||
static std::string cstr(const std::string &raw); // C++ string-literal escape
|
||||
static std::string zstr(const std::string &raw); // same, as a sized ZString if it holds a NUL
|
||||
static const char *staticTypeOp(const std::string &type, const char *rcVar);
|
||||
};
|
||||
|
||||
|
||||
@@ -83,6 +83,11 @@ namespace jetc {
|
||||
// otherwise), it was previously miscategorized as void.
|
||||
"set", "include", "cookie", "header", "read", "write",
|
||||
"call", "system", "dump",
|
||||
// <bind> (see __bind.cpp) supplies one <sql> placeholder value
|
||||
// and never has a closing tag - without this a bare
|
||||
// <bind value="..."> outside a <sql> span would scan forward
|
||||
// for a "</bind>" that doesn't exist.
|
||||
"bind",
|
||||
// <container> (see parseContainerSlot/Tag::renderContainer) -
|
||||
// real content always writes it as a bare marker with no
|
||||
// separate closing tag, even when it carries its own
|
||||
|
||||
Reference in new issue
Block a user