@@ -447,6 +447,10 @@ func (c *fakeConn) Prepare(query string) (driver.Stmt, error) {
447
447
return c .prepareCreate (stmt , parts )
448
448
case "INSERT" :
449
449
return c .prepareInsert (stmt , parts )
450
+ case "NOSERT" :
451
+ // Do all the prep-work like for an INSERT but don't actually insert the row.
452
+ // Used for some of the concurrent tests.
453
+ return c .prepareInsert (stmt , parts )
450
454
default :
451
455
stmt .Close ()
452
456
return nil , errf ("unsupported command type %q" , cmd )
@@ -497,13 +501,20 @@ func (s *fakeStmt) Exec(args []driver.Value) (driver.Result, error) {
497
501
}
498
502
return driver .ResultNoRows , nil
499
503
case "INSERT" :
500
- return s .execInsert (args )
504
+ return s .execInsert (args , true )
505
+ case "NOSERT" :
506
+ // Do all the prep-work like for an INSERT but don't actually insert the row.
507
+ // Used for some of the concurrent tests.
508
+ return s .execInsert (args , false )
501
509
}
502
510
fmt .Printf ("EXEC statement, cmd=%q: %#v\n " , s .cmd , s )
503
511
return nil , fmt .Errorf ("unimplemented statement Exec command type of %q" , s .cmd )
504
512
}
505
513
506
- func (s * fakeStmt ) execInsert (args []driver.Value ) (driver.Result , error ) {
514
+ // When doInsert is true, add the row to the table.
515
+ // When doInsert is false do prep-work and error checking, but don't
516
+ // actually add the row to the table.
517
+ func (s * fakeStmt ) execInsert (args []driver.Value , doInsert bool ) (driver.Result , error ) {
507
518
db := s .c .db
508
519
if len (args ) != s .placeholders {
509
520
panic ("error in pkg db; should only get here if size is correct" )
@@ -518,7 +529,10 @@ func (s *fakeStmt) execInsert(args []driver.Value) (driver.Result, error) {
518
529
t .mu .Lock ()
519
530
defer t .mu .Unlock ()
520
531
521
- cols := make ([]interface {}, len (t .colname ))
532
+ var cols []interface {}
533
+ if doInsert {
534
+ cols = make ([]interface {}, len (t .colname ))
535
+ }
522
536
argPos := 0
523
537
for n , colname := range s .colName {
524
538
colidx := t .columnIndex (colname )
@@ -532,10 +546,14 @@ func (s *fakeStmt) execInsert(args []driver.Value) (driver.Result, error) {
532
546
} else {
533
547
val = s .colValue [n ]
534
548
}
535
- cols [colidx ] = val
549
+ if doInsert {
550
+ cols [colidx ] = val
551
+ }
536
552
}
537
553
538
- t .rows = append (t .rows , & row {cols : cols })
554
+ if doInsert {
555
+ t .rows = append (t .rows , & row {cols : cols })
556
+ }
539
557
return driver .RowsAffected (1 ), nil
540
558
}
541
559
0 commit comments