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>
155 lines
8.2 KiB
Plaintext
155 lines
8.2 KiB
Plaintext
#!../jet-2.0
|
|
<jet filterblanklines="true" trimlines="true">
|
|
<comment>
|
|
End-to-end tests for <sql>/<bind> - see docs/design-sql-bound-parameters.md.
|
|
Run by tests/runbindtests.sh against a real MySQL server; only TEMPORARY
|
|
tables are used, so nothing outlives the connection. Compared byte-for-byte
|
|
with tests/testbind.expected. Generated - contains raw 0xBF and NUL bytes.
|
|
</comment>
|
|
<mysql host="$[&JETTEST_DB_HOST]" database="$[&JETTEST_DB_NAME]" user="$[&JETTEST_DB_USER]" password="$[&JETTEST_DB_PASSWORD]">
|
|
<sql>create temporary table bindtest (id int auto_increment primary key, s varbinary(255), n int, dec_v decimal(10,2), d date, dt datetime, b tinyint, t varchar(100) character set utf8mb4)</sql>
|
|
<comment> Injection strings and odd bytes come back byte-for-byte. </comment>
|
|
<set name="v" value="hello">
|
|
<sql>insert into bindtest (s) values (?)<bind value="$[v]"></sql>
|
|
<sql>select hex(s) as h from bindtest where id=last_insert_id()</sql>
|
|
default plain: <ifrow>$[.h]</ifrow>
|
|
<set name="v" value="x' or '1'='1">
|
|
<sql>insert into bindtest (s) values (?)<bind value="$[v]"></sql>
|
|
<sql>select hex(s) as h from bindtest where id=last_insert_id()</sql>
|
|
default or-injection: <ifrow>$[.h]</ifrow>
|
|
<set name="v" value="\'">
|
|
<sql>insert into bindtest (s) values (?)<bind value="$[v]"></sql>
|
|
<sql>select hex(s) as h from bindtest where id=last_insert_id()</sql>
|
|
default backslash-quote: <ifrow>$[.h]</ifrow>
|
|
<sql>select concat('a', char(92)) as v</sql><ifrow><set name="v" value="$[.v]"></ifrow>
|
|
<sql>insert into bindtest (s) values (?)<bind value="$[v]"></sql>
|
|
<sql>select hex(s) as h from bindtest where id=last_insert_id()</sql>
|
|
default trailing-backslash: <ifrow>$[.h]</ifrow>
|
|
<set name="v" value="-- ">
|
|
<sql>insert into bindtest (s) values (?)<bind value="$[v]"></sql>
|
|
<sql>select hex(s) as h from bindtest where id=last_insert_id()</sql>
|
|
default dashdash: <ifrow>$[.h]</ifrow>
|
|
<set name="v" value="; drop table t; --">
|
|
<sql>insert into bindtest (s) values (?)<bind value="$[v]"></sql>
|
|
<sql>select hex(s) as h from bindtest where id=last_insert_id()</sql>
|
|
default semicolon: <ifrow>$[.h]</ifrow>
|
|
<set name="v" value="¿' or 1=1 -- ">
|
|
<sql>insert into bindtest (s) values (?)<bind value="$[v]"></sql>
|
|
<sql>select hex(s) as h from bindtest where id=last_insert_id()</sql>
|
|
default gbk-bf27: <ifrow>$[.h]</ifrow>
|
|
<set name="v" value='say "hi"'>
|
|
<sql>insert into bindtest (s) values (?)<bind value="$[v]"></sql>
|
|
<sql>select hex(s) as h from bindtest where id=last_insert_id()</sql>
|
|
default double-quote: <ifrow>$[.h]</ifrow>
|
|
<set name="v" value="what?">
|
|
<sql>insert into bindtest (s) values (?)<bind value="$[v]"></sql>
|
|
<sql>select hex(s) as h from bindtest where id=last_insert_id()</sql>
|
|
default question: <ifrow>$[.h]</ifrow>
|
|
<set name="v" value="a |