@@ -269,12 +269,23 @@ func TestTransactionScript(t *testing.T, harness Harness, script queries.Transac
269269 harness .Setup (setup .MydbData )
270270 e := mustNewEngine (t , harness )
271271 defer e .Close ()
272- TestTransactionScriptWithEngine (t , e , harness , script )
272+ TestTransactionScriptWithEngine (t , e , harness , script , false )
273273 })
274274}
275275
276- // TestTransactionScriptWithEngine runs the transaction test script given with the engine provided.
277- func TestTransactionScriptWithEngine (t * testing.T , e QueryEngine , harness Harness , script queries.TransactionTest ) {
276+ // TestTransactionScriptPrepared runs the test script given using prepared statements.
277+ func TestTransactionScriptPrepared (t * testing.T , harness Harness , script queries.TransactionTest ) bool {
278+ return t .Run (script .Name , func (t * testing.T ) {
279+ harness .Setup (setup .MydbData )
280+ e := mustNewEngine (t , harness )
281+ defer e .Close ()
282+ TestTransactionScriptWithEngine (t , e , harness , script , true )
283+ })
284+ }
285+
286+ // TestTransactionScriptWithEngine runs the transaction test script given with the engine provided. If |prepared| is true
287+ // then the queries will be prepared and then executed, otherwise they will be executed directly.
288+ func TestTransactionScriptWithEngine (t * testing.T , e QueryEngine , harness Harness , script queries.TransactionTest , prepared bool ) {
278289 setupSession := NewSession (harness )
279290 for _ , statement := range script .SetUpScript {
280291 if sh , ok := harness .(SkippingHarness ); ok {
@@ -307,17 +318,40 @@ func TestTransactionScriptWithEngine(t *testing.T, e QueryEngine, harness Harnes
307318 }
308319
309320 if assertion .ExpectedErr != nil {
310- AssertErrWithCtx (t , e , harness , clientSession , assertion .Query , assertion .Bindings , assertion .ExpectedErr )
321+ if prepared {
322+ AssertErrPreparedWithCtx (t , e , harness , clientSession , assertion .Query , assertion .ExpectedErr )
323+ } else {
324+ AssertErrWithCtx (t , e , harness , clientSession , assertion .Query , assertion .Bindings , assertion .ExpectedErr )
325+ }
311326 } else if assertion .ExpectedErrStr != "" {
312- AssertErrWithCtx (t , e , harness , clientSession , assertion .Query , assertion .Bindings , nil , assertion .ExpectedErrStr )
327+ if prepared {
328+ AssertErrPreparedWithCtx (t , e , harness , clientSession , assertion .Query , nil , assertion .ExpectedErrStr )
329+ } else {
330+ AssertErrWithCtx (t , e , harness , clientSession , assertion .Query , assertion .Bindings , nil , assertion .ExpectedErrStr )
331+ }
313332 } else if assertion .ExpectedWarning != 0 {
314- AssertWarningAndTestQuery (t , e , nil , harness , assertion .Query , assertion .Expected ,
315- nil , assertion .ExpectedWarning , assertion .ExpectedWarningsCount ,
316- assertion .ExpectedWarningMessageSubstring , false )
333+ if prepared {
334+ // TODO: Looks like we don't have a prepared version of this yet
335+ AssertWarningAndTestQuery (t , e , nil , harness , assertion .Query , assertion .Expected ,
336+ nil , assertion .ExpectedWarning , assertion .ExpectedWarningsCount ,
337+ assertion .ExpectedWarningMessageSubstring , false )
338+ } else {
339+ AssertWarningAndTestQuery (t , e , nil , harness , assertion .Query , assertion .Expected ,
340+ nil , assertion .ExpectedWarning , assertion .ExpectedWarningsCount ,
341+ assertion .ExpectedWarningMessageSubstring , false )
342+ }
317343 } else if assertion .SkipResultsCheck {
318- RunQueryWithContext (t , e , harness , clientSession , assertion .Query )
344+ if prepared {
345+ runQueryPreparedWithCtx (t , clientSession , e , assertion .Query , assertion .Bindings , false )
346+ } else {
347+ RunQueryWithContext (t , e , harness , clientSession , assertion .Query )
348+ }
319349 } else {
320- TestQueryWithContext (t , clientSession , e , harness , assertion .Query , assertion .Expected , nil , nil , nil )
350+ if prepared {
351+ TestPreparedQueryWithContext (t , clientSession , e , harness , assertion .Query , assertion .Expected , nil , nil , false )
352+ } else {
353+ TestQueryWithContext (t , clientSession , e , harness , assertion .Query , assertion .Expected , nil , nil , nil )
354+ }
321355 }
322356 })
323357 }
@@ -551,7 +585,7 @@ func injectBindVarsAndPrepare(
551585
552586 switch p := parsed .(type ) {
553587 case * sqlparser.Load , * sqlparser.Prepare , * sqlparser.Execute :
554- // LOAD DATA query cannot be used as PREPARED STATEMENT
588+ // LOAD DATA, PREPARE, and EXECUTE queries cannot be used as prepared statements
555589 return q , nil , nil
556590 case * sqlparser.Set :
557591 // SET system variable query cannot be used as PREPARED STATEMENT
@@ -564,7 +598,7 @@ func injectBindVarsAndPrepare(
564598
565599 b := planbuilder .New (ctx , e .EngineAnalyzer ().Catalog , e .EngineEventScheduler (), nil )
566600 b .SetParserOptions (sql .LoadSqlMode (ctx ).ParserOptions ())
567- resPlan , _ , err := b . BindOnly ( parsed , q , nil )
601+ resPlan , err := e . PrepareQuery ( ctx , q )
568602 if err != nil {
569603 return q , nil , err
570604 }
0 commit comments