@@ -450,6 +450,49 @@ func BenchmarkSQLParallel(b *testing.B) {
450
450
})
451
451
}
452
452
453
+ func BenchmarkSQLPreparedParallel (b * testing.B ) {
454
+ // Tarantool supports SQL since version 2.0.0
455
+ isLess , err := test_helpers .IsTarantoolVersionLess (2 , 0 , 0 )
456
+ if err != nil {
457
+ b .Fatal ("Could not check the Tarantool version" )
458
+ }
459
+ if isLess {
460
+ b .Skip ()
461
+ }
462
+
463
+ conn , err := Connect (server , opts )
464
+ if err != nil {
465
+ b .Errorf ("No connection available" )
466
+ return
467
+ }
468
+ defer conn .Close ()
469
+
470
+ spaceNo := 519
471
+ _ , err = conn .Replace (spaceNo , []interface {}{uint (1111 ), "hello" , "world" })
472
+ if err != nil {
473
+ b .Errorf ("No connection available" )
474
+ }
475
+
476
+ res , err := conn .Prepare ("SELECT NAME0,NAME1,NAME2 FROM SQL_TEST WHERE NAME0=?" )
477
+ if err != nil {
478
+ b .Fatalf ("failed to prepare statement: %s" , err )
479
+ }
480
+ if res .Code != 0 {
481
+ b .Fatalf ("failed to prepare statement: %s" , err )
482
+ }
483
+
484
+ b .ResetTimer ()
485
+ b .RunParallel (func (pb * testing.PB ) {
486
+ for pb .Next () {
487
+ _ , err := conn .Execute (res .StmtID , []interface {}{uint (1111 )})
488
+ if err != nil {
489
+ b .Errorf ("Select failed: %s" , err .Error ())
490
+ break
491
+ }
492
+ }
493
+ })
494
+ }
495
+
453
496
func BenchmarkSQLSerial (b * testing.B ) {
454
497
// Tarantool supports SQL since version 2.0.0
455
498
isLess , err := test_helpers .IsTarantoolVersionLess (2 , 0 , 0 )
@@ -483,6 +526,47 @@ func BenchmarkSQLSerial(b *testing.B) {
483
526
}
484
527
}
485
528
529
+ func BenchmarkSQLPreparedSerial (b * testing.B ) {
530
+ // Tarantool supports SQL since version 2.0.0
531
+ isLess , err := test_helpers .IsTarantoolVersionLess (2 , 0 , 0 )
532
+ if err != nil {
533
+ b .Fatal ("Could not check the Tarantool version" )
534
+ }
535
+ if isLess {
536
+ b .Skip ()
537
+ }
538
+
539
+ conn , err := Connect (server , opts )
540
+ if err != nil {
541
+ b .Errorf ("Failed to connect: %s" , err )
542
+ return
543
+ }
544
+ defer conn .Close ()
545
+
546
+ spaceNo := 519
547
+ _ , err = conn .Replace (spaceNo , []interface {}{uint (1111 ), "hello" , "world" })
548
+ if err != nil {
549
+ b .Errorf ("Failed to replace: %s" , err )
550
+ }
551
+
552
+ res , err := conn .Prepare ("SELECT NAME0,NAME1,NAME2 FROM SQL_TEST WHERE NAME0=?" )
553
+ if err != nil {
554
+ b .Fatalf ("failed to prepare statement: %s" , err )
555
+ }
556
+ if res .Code != 0 {
557
+ b .Fatalf ("failed to prepare statement: %s" , err )
558
+ }
559
+
560
+ b .ResetTimer ()
561
+ for i := 0 ; i < b .N ; i ++ {
562
+ _ , err := conn .Execute (res .StmtID , []interface {}{uint (1111 )})
563
+ if err != nil {
564
+ b .Errorf ("Select failed: %s" , err .Error ())
565
+ break
566
+ }
567
+ }
568
+ }
569
+
486
570
///////////////////
487
571
488
572
func TestClient (t * testing.T ) {
@@ -1001,6 +1085,41 @@ func TestSQL(t *testing.T) {
1001
1085
}
1002
1086
}
1003
1087
1088
+ func TestPreparedStmt (t * testing.T ) {
1089
+ // Tarantool supports SQL since version 2.0.0
1090
+ isLess , err := test_helpers .IsTarantoolVersionLess (2 , 0 , 0 )
1091
+ if err != nil {
1092
+ t .Fatal ("Could not check the Tarantool version" )
1093
+ }
1094
+ if isLess {
1095
+ t .Skip ()
1096
+ }
1097
+
1098
+ var conn * Connection
1099
+
1100
+ conn , err = Connect (server , opts )
1101
+ if err != nil {
1102
+ t .Fatalf ("Failed to connect: %s" , err .Error ())
1103
+ }
1104
+ if conn == nil {
1105
+ t .Fatal ("conn is nil after Connect" )
1106
+ }
1107
+ defer conn .Close ()
1108
+
1109
+ res , err := conn .Prepare (selectPosQuery2 )
1110
+ if err != nil {
1111
+ t .Fatalf ("failed to prepare request: %s" , err )
1112
+ }
1113
+
1114
+ res2 , err := conn .Execute (res .StmtID , []interface {}{1 , "test" })
1115
+ if err != nil {
1116
+ t .Fatalf ("failed to execute with prepared statement: %s" , err )
1117
+ }
1118
+ if res2 .Code != 0 {
1119
+ t .Fatalf ("Failed to execute: code error %d" , res .Code )
1120
+ }
1121
+ }
1122
+
1004
1123
func TestSQLTyped (t * testing.T ) {
1005
1124
// Tarantool supports SQL since version 2.0.0
1006
1125
isLess , err := test_helpers .IsTarantoolVersionLess (2 , 0 , 0 )
0 commit comments