@@ -269,12 +269,23 @@ func TestTransactionScript(t *testing.T, harness Harness, script queries.Transac
269
269
harness .Setup (setup .MydbData )
270
270
e := mustNewEngine (t , harness )
271
271
defer e .Close ()
272
- TestTransactionScriptWithEngine (t , e , harness , script )
272
+ TestTransactionScriptWithEngine (t , e , harness , script , false )
273
273
})
274
274
}
275
275
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 ) {
278
289
setupSession := NewSession (harness )
279
290
for _ , statement := range script .SetUpScript {
280
291
if sh , ok := harness .(SkippingHarness ); ok {
@@ -307,17 +318,40 @@ func TestTransactionScriptWithEngine(t *testing.T, e QueryEngine, harness Harnes
307
318
}
308
319
309
320
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
+ }
311
326
} 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
+ }
313
332
} 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
+ }
317
343
} 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
+ }
319
349
} 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
+ }
321
355
}
322
356
})
323
357
}
@@ -551,7 +585,7 @@ func injectBindVarsAndPrepare(
551
585
552
586
switch p := parsed .(type ) {
553
587
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
555
589
return q , nil , nil
556
590
case * sqlparser.Set :
557
591
// SET system variable query cannot be used as PREPARED STATEMENT
@@ -564,7 +598,7 @@ func injectBindVarsAndPrepare(
564
598
565
599
b := planbuilder .New (ctx , e .EngineAnalyzer ().Catalog , e .EngineEventScheduler (), nil )
566
600
b .SetParserOptions (sql .LoadSqlMode (ctx ).ParserOptions ())
567
- resPlan , _ , err := b . BindOnly ( parsed , q , nil )
601
+ resPlan , err := e . PrepareQuery ( ctx , q )
568
602
if err != nil {
569
603
return q , nil , err
570
604
}
0 commit comments