File tree 3 files changed +49
-1
lines changed
3 files changed +49
-1
lines changed Original file line number Diff line number Diff line change 13
13
14
14
Aaron Hopkins <go-sql-driver at die.net>
15
15
Achille Roussel <achille.roussel at gmail.com>
16
+ Aidan <aidan.liu at pingcap.com>
16
17
Alex Snast <alexsn at fb.com>
17
18
Alexey Palazhchenko <alexey.palazhchenko at gmail.com>
18
19
Andrew Reid <andrew.reid at tixtrack.com>
Original file line number Diff line number Diff line change @@ -3430,3 +3430,44 @@ func TestConnectionAttributes(t *testing.T) {
3430
3430
}
3431
3431
rows .Close ()
3432
3432
}
3433
+
3434
+ func TestErrorInMultiResult (t * testing.T ) {
3435
+ // https://github.com/go-sql-driver/mysql/issues/1361
3436
+ var db * sql.DB
3437
+ if _ , err := ParseDSN (dsn ); err != errInvalidDSNUnsafeCollation {
3438
+ db , err = sql .Open ("mysql" , dsn )
3439
+ if err != nil {
3440
+ t .Fatalf ("error connecting: %s" , err .Error ())
3441
+ }
3442
+ defer db .Close ()
3443
+ }
3444
+
3445
+ dbt := & DBTest {t , db }
3446
+ query := `
3447
+ CREATE PROCEDURE test_proc1()
3448
+ BEGIN
3449
+ SELECT 1,2;
3450
+ SELECT 3,4;
3451
+ SIGNAL SQLSTATE '10000' SET MESSAGE_TEXT = "some error", MYSQL_ERRNO = 10000;
3452
+ END;
3453
+ `
3454
+ runCallCommand (dbt , query , "test_proc1" )
3455
+ }
3456
+
3457
+ func runCallCommand (dbt * DBTest , query , name string ) {
3458
+ dbt .mustExec (fmt .Sprintf ("DROP PROCEDURE IF EXISTS %s" , name ))
3459
+ dbt .mustExec (query )
3460
+ defer dbt .mustExec ("DROP PROCEDURE " + name )
3461
+ rows , err := dbt .db .Query (fmt .Sprintf ("CALL %s" , name ))
3462
+ if err != nil {
3463
+ return
3464
+ }
3465
+ defer rows .Close ()
3466
+
3467
+ for rows .Next () {
3468
+ }
3469
+ for rows .NextResultSet () {
3470
+ for rows .Next () {
3471
+ }
3472
+ }
3473
+ }
Original file line number Diff line number Diff line change @@ -163,7 +163,13 @@ func (rows *mysqlRows) nextResultSet() (int, error) {
163
163
rows .rs = resultSet {}
164
164
// rows.mc.affectedRows and rows.mc.insertIds accumulate on each call to
165
165
// nextResultSet.
166
- return rows .mc .resultUnchanged ().readResultSetHeaderPacket ()
166
+ resLen , err := rows .mc .resultUnchanged ().readResultSetHeaderPacket ()
167
+ if err != nil {
168
+ // Clean up about multi-results flag
169
+ rows .rs .done = true
170
+ rows .mc .status = rows .mc .status & (^ statusMoreResultsExists )
171
+ }
172
+ return resLen , err
167
173
}
168
174
169
175
func (rows * mysqlRows ) nextNotEmptyResultSet () (int , error ) {
You can’t perform that action at this time.
0 commit comments