Browse Source
			
			
			Patch for Bug#21818 (Return value of ROW_COUNT() is incorrect
			
				
		Patch for Bug#21818 (Return value of ROW_COUNT() is incorrect
	
		
	
			
				for ALTER TABLE, LOAD DATA).
ROW_COUNT is now assigned according to the following rules:
  - In my_ok():
    - for DML statements: to the number of affected rows;
    - for DDL statements: to 0.
  - In my_eof(): to -1 to indicate that there was a result set.
    We derive this semantics from the JDBC specification, where int
    java.sql.Statement.getUpdateCount() is defined to (sic) "return the
    current result as an update count; if the result is a ResultSet
    object or there are no more results, -1 is returned".
  - In my_error(): to -1 to be compatible with the MySQL C API and
    MySQL ODBC driver.
  - For SIGNAL statements: to 0 per WL#2110 specification. Zero is used
    since that's the "default" value of ROW_COUNT in the diagnostics area.
			
			
				pull/73/head
			
			
		
				 22 changed files with 321 additions and 80 deletions
			
			
		- 
					2mysql-test/include/ctype_numconv.inc
- 
					3mysql-test/r/ctype_binary.result
- 
					3mysql-test/r/ctype_cp1251.result
- 
					3mysql-test/r/ctype_latin1.result
- 
					3mysql-test/r/ctype_ucs.result
- 
					4mysql-test/r/sp.result
- 
					2mysql-test/suite/funcs_1/r/innodb_storedproc_10.result
- 
					2mysql-test/suite/funcs_1/r/memory_storedproc_10.result
- 
					2mysql-test/suite/funcs_1/r/myisam_storedproc_10.result
- 
					2mysql-test/suite/funcs_1/r/ndb_storedproc_10.result
- 
					79mysql-test/suite/funcs_1/r/row_count_func.result
- 
					1mysql-test/suite/funcs_1/t/row_count_func-master.opt
- 
					115mysql-test/suite/funcs_1/t/row_count_func.test
- 
					2sql/item_func.cc
- 
					2sql/protocol.cc
- 
					15sql/sql_class.cc
- 
					49sql/sql_class.h
- 
					13sql/sql_delete.cc
- 
					22sql/sql_insert.cc
- 
					53sql/sql_parse.cc
- 
					14sql/sql_signal.cc
- 
					10sql/sql_update.cc
| @ -0,0 +1,79 @@ | |||
| 
 | |||
| # --  | |||
| # -- Test case for Bug#21818. | |||
| # --  | |||
| 
 | |||
| DROP TABLE IF EXISTS t1; | |||
| CREATE TABLE t1(a INT); | |||
| INSERT INTO t1 VALUES (1), (2), (3); | |||
| 
 | |||
| # -- Check 1. | |||
| SELECT * FROM t1 INTO OUTFILE "MYSQL_TMP_DIR/bug21818.txt"; | |||
| affected rows: 3 | |||
| 
 | |||
| SELECT ROW_COUNT(); | |||
| ROW_COUNT() | |||
| 3 | |||
| 
 | |||
| # -- Check 2. | |||
| SELECT a FROM t1 LIMIT 1 INTO @a; | |||
| affected rows: 1 | |||
| 
 | |||
| SELECT ROW_COUNT(); | |||
| ROW_COUNT() | |||
| 1 | |||
| 
 | |||
| # -- Check 3. | |||
| DROP DATABASE IF EXISTS mysqltest1; | |||
| CREATE DATABASE mysqltest1; | |||
| affected rows: 1 | |||
| 
 | |||
| SELECT ROW_COUNT(); | |||
| ROW_COUNT() | |||
| 1 | |||
| DROP DATABASE mysqltest1; | |||
| 
 | |||
| # -- Check 4. | |||
| DELETE FROM t1; | |||
| LOAD DATA INFILE 'MYSQL_TMP_DIR/bug21818.txt' INTO TABLE t1(a); | |||
| affected rows: 3 | |||
| info: Records: 3  Deleted: 0  Skipped: 0  Warnings: 0 | |||
| 
 | |||
| SELECT ROW_COUNT(); | |||
| ROW_COUNT() | |||
| 3 | |||
| 
 | |||
| # -- Check 5. | |||
| ALTER TABLE t1 ADD COLUMN b VARCHAR(255); | |||
| affected rows: 3 | |||
| info: Records: 3  Duplicates: 0  Warnings: 0 | |||
| 
 | |||
| SELECT ROW_COUNT(); | |||
| ROW_COUNT() | |||
| 3 | |||
| 
 | |||
| DROP TABLE t1; | |||
| 
 | |||
| # -- Check 6. | |||
| DROP TABLE IF EXISTS t2; | |||
| CREATE TABLE t1(a INT); | |||
| CREATE TABLE t2(a INT); | |||
| INSERT INTO t1 VALUES (1), (2), (3); | |||
| INSERT INTO t2 VALUES (ROW_COUNT()); | |||
| SELECT * FROM t2; | |||
| a | |||
| 3 | |||
| DROP TABLE t1; | |||
| DROP TABLE t2; | |||
| 
 | |||
| # -- Check 7 (check that SQL errors reset row_count to -1). | |||
| CREATE TABLE t1(a INT); | |||
| INSERT INTO t1 VALUES (1), (2), (3); | |||
| SELECT f1(); | |||
| ERROR 42000: FUNCTION test.f1 does not exist | |||
| SELECT ROW_COUNT(); | |||
| ROW_COUNT() | |||
| -1 | |||
| DROP TABLE t1; | |||
| 
 | |||
| # -- End of test case for Bug#21818. | |||
| @ -0,0 +1 @@ | |||
| --secure-file-priv=$MYSQL_TMP_DIR | |||
| @ -0,0 +1,115 @@ | |||
| --echo | |||
| --echo # --  | |||
| --echo # -- Test case for Bug#21818. | |||
| --echo # --  | |||
| --echo | |||
| 
 | |||
| --disable_warnings | |||
| DROP TABLE IF EXISTS t1; | |||
| --enable_warnings | |||
| 
 | |||
| CREATE TABLE t1(a INT); | |||
| INSERT INTO t1 VALUES (1), (2), (3); | |||
| 
 | |||
| --echo | |||
| --echo # -- Check 1. | |||
| 
 | |||
| --enable_info | |||
| --echo SELECT * FROM t1 INTO OUTFILE "MYSQL_TMP_DIR/bug21818.txt"; | |||
| --disable_query_log # to avoid $MYSQL_TMP_DIR in query log | |||
| --eval SELECT * FROM t1 INTO OUTFILE "$MYSQL_TMP_DIR/bug21818.txt" | |||
| --enable_query_log | |||
| --disable_info | |||
| 
 | |||
| --echo | |||
| SELECT ROW_COUNT(); | |||
| 
 | |||
| --echo | |||
| --echo # -- Check 2. | |||
| 
 | |||
| --enable_info | |||
| SELECT a FROM t1 LIMIT 1 INTO @a; | |||
| --disable_info | |||
| 
 | |||
| --echo | |||
| SELECT ROW_COUNT(); | |||
| 
 | |||
| --echo | |||
| --echo # -- Check 3. | |||
| 
 | |||
| --disable_warnings | |||
| DROP DATABASE IF EXISTS mysqltest1; | |||
| --enable_warnings | |||
| 
 | |||
| --enable_info | |||
| CREATE DATABASE mysqltest1; | |||
| --disable_info | |||
| 
 | |||
| --echo | |||
| SELECT ROW_COUNT(); | |||
| 
 | |||
| DROP DATABASE mysqltest1; | |||
| 
 | |||
| --echo | |||
| --echo # -- Check 4. | |||
| 
 | |||
| DELETE FROM t1; | |||
| 
 | |||
| --enable_info | |||
| --echo LOAD DATA INFILE 'MYSQL_TMP_DIR/bug21818.txt' INTO TABLE t1(a); | |||
| --disable_query_log # to avoid $MYSQL_TMP_DIR in query log | |||
| --eval LOAD DATA INFILE '$MYSQL_TMP_DIR/bug21818.txt' INTO TABLE t1(a) | |||
| --enable_query_log | |||
| --disable_info | |||
| 
 | |||
| --echo | |||
| SELECT ROW_COUNT(); | |||
| 
 | |||
| --remove_file $MYSQL_TMP_DIR/bug21818.txt | |||
| 
 | |||
| --echo | |||
| --echo # -- Check 5. | |||
| 
 | |||
| --enable_info | |||
| ALTER TABLE t1 ADD COLUMN b VARCHAR(255); | |||
| --disable_info | |||
| 
 | |||
| --echo | |||
| SELECT ROW_COUNT(); | |||
| 
 | |||
| --echo | |||
| DROP TABLE t1; | |||
| 
 | |||
| --echo | |||
| --echo # -- Check 6. | |||
| 
 | |||
| --disable_warnings | |||
| DROP TABLE IF EXISTS t2; | |||
| --enable_warnings | |||
| 
 | |||
| CREATE TABLE t1(a INT); | |||
| CREATE TABLE t2(a INT); | |||
| 
 | |||
| INSERT INTO t1 VALUES (1), (2), (3); | |||
| INSERT INTO t2 VALUES (ROW_COUNT()); | |||
| 
 | |||
| SELECT * FROM t2; | |||
| 
 | |||
| DROP TABLE t1; | |||
| DROP TABLE t2; | |||
| 
 | |||
| --echo | |||
| --echo # -- Check 7 (check that SQL errors reset row_count to -1). | |||
| 
 | |||
| CREATE TABLE t1(a INT); | |||
| 
 | |||
| INSERT INTO t1 VALUES (1), (2), (3); | |||
| --error ER_SP_DOES_NOT_EXIST | |||
| SELECT f1(); | |||
| 
 | |||
| SELECT ROW_COUNT(); | |||
| 
 | |||
| DROP TABLE t1; | |||
| 
 | |||
| --echo | |||
| --echo # -- End of test case for Bug#21818. | |||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue