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>
30 lines
1.1 KiB
C++
30 lines
1.1 KiB
C++
#include "__bind.h"
|
|
#include "__sql.h"
|
|
#include "Exception.h"
|
|
#include "SqlBind.h"
|
|
|
|
namespace jet {
|
|
|
|
__bind::__bind(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) {
|
|
output = false;
|
|
|
|
// Nearest enclosing <sql>, through any <if>/<for>/etc. in between.
|
|
__sql *sql = NULL;
|
|
for(Tag *scope = parent; scope && !sql; scope = scope->parent)
|
|
sql = dynamic_cast<__sql *>(scope);
|
|
if(!sql)
|
|
throw coreutils::Exception("bind must be inside sql.");
|
|
if(!keywordDefined("value"))
|
|
throw coreutils::Exception("bind must have a value.");
|
|
|
|
std::string value = resolveKeyword("value").str();
|
|
std::string type = keywordDefined("type") ? resolveKeyword("type").str() : "";
|
|
std::string nullMode = keywordDefined("null") ? resolveKeyword("null").str() : "";
|
|
bool hasAllow = keywordDefined("allow");
|
|
std::string allow = hasAllow ? resolveKeyword("allow").str() : "";
|
|
|
|
sql->addBind(makeBoundValue(value, type, nullMode, hasAllow, allow, (int)sql->bindCount() + 1));
|
|
}
|
|
|
|
}
|