Below is the list of changes that have just been committed into a local
5.0 repository of pem. When pem does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://www.mysql.com/doc/I/n/Installing_source_tree.html
ChangeSet
1.1676 04/05/04 13:45:20 pem@stripped +11 -0
WL#1567: Add ROW_COUNT() Function to retrieve count of rows updated/inserted/deleted
sql/sql_yacc.yy
1.285 04/05/04 13:44:54 pem@stripped +6 -0
New function ROW_COUNT().
sql/sql_update.cc
1.106 04/05/04 13:44:54 pem@stripped +6 -4
Set thd->row_count_func when updating.
sql/sql_parse.cc
1.333 04/05/04 13:44:54 pem@stripped +1 -1
Stored procedure CALLs send the row count from the last insert, delete or update.
sql/sql_insert.cc
1.104 04/05/04 13:44:54 pem@stripped +8 -3
Set thd->row_count_func when inserting.
sql/sql_delete.cc
1.118 04/05/04 13:44:54 pem@stripped +5 -0
Set thd->row_count_func when deleting.
sql/sql_class.h
1.182 04/05/04 13:44:54 pem@stripped +1 -0
New slot in THD for storing the row_count after insert, delete and update.
sql/lex.h
1.118 04/05/04 13:44:54 pem@stripped +1 -0
New symbol for function ROW_COUNT().
sql/item_func.h
1.85 04/05/04 13:44:54 pem@stripped +10 -0
New Item_func_row_count.
sql/item_func.cc
1.147 04/05/04 13:44:54 pem@stripped +9 -0
New Item_func_row_count.
mysql-test/t/sp.test
1.59 04/05/04 13:44:54 pem@stripped +19 -0
New test cases for function ROW_COUNT().
mysql-test/r/sp.result
1.61 04/05/04 13:44:54 pem@stripped +22 -0
New test cases for function ROW_COUNT().
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: pem
# Host: mysql.comhem.se
# Root: /home/pem/work/mysql-5.0
--- 1.146/sql/item_func.cc Wed Apr 7 19:07:36 2004
+++ 1.147/sql/item_func.cc Tue May 4 13:44:54 2004
@@ -3206,6 +3206,15 @@
}
+longlong Item_func_row_count::val_int()
+{
+ DBUG_ASSERT(fixed == 1);
+ THD *thd= current_thd;
+
+ return thd->row_count_func;
+}
+
+
Item_func_sp::Item_func_sp(sp_name *name)
:Item_func(), m_name(name), m_sp(NULL)
{
--- 1.84/sql/item_func.h Wed Apr 7 19:07:36 2004
+++ 1.85/sql/item_func.h Tue May 4 13:44:54 2004
@@ -1076,6 +1076,16 @@
};
+class Item_func_row_count :public Item_int_func
+{
+public:
+ Item_func_row_count() :Item_int_func() {}
+ longlong val_int();
+ const char *func_name() const { return "row_count"; }
+ void fix_length_and_dec() { decimals= 0; maybe_null=0; }
+};
+
+
/*
*
* Stored FUNCTIONs
--- 1.117/sql/lex.h Wed Apr 7 19:07:36 2004
+++ 1.118/sql/lex.h Tue May 4 13:44:54 2004
@@ -681,6 +681,7 @@
{ "RELEASE_LOCK", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_release_lock)},
{ "REVERSE", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_reverse)},
{ "ROUND", SYM(ROUND)},
+ { "ROW_COUNT", SYM(ROW_COUNT_SYM)},
{ "RPAD", F_SYM(FUNC_ARG3),0,CREATE_FUNC(create_func_rpad)},
{ "RTRIM", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_rtrim)},
{ "SEC_TO_TIME", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sec_to_time)},
--- 1.181/sql/sql_class.h Wed Apr 7 15:12:43 2004
+++ 1.182/sql/sql_class.h Tue May 4 13:44:54 2004
@@ -829,6 +829,7 @@
bool charset_is_system_charset, charset_is_collation_connection;
bool slow_command;
+ ulong row_count_func; /* For the ROW_COUNT() function */
sp_rcontext *spcont; // SP runtime context
sp_cache *sp_proc_cache;
sp_cache *sp_func_cache;
--- 1.117/sql/sql_delete.cc Wed Apr 7 15:12:43 2004
+++ 1.118/sql/sql_delete.cc Tue May 4 13:44:54 2004
@@ -96,6 +96,7 @@
{
delete select;
free_underlaid_joins(thd, &thd->lex->select_lex);
+ thd->row_count_func= 0;
send_ok(thd,0L);
DBUG_RETURN(0); // Nothing to delete
}
@@ -245,6 +246,7 @@
send_error(thd,thd->killed_errno());
else
{
+ thd->row_count_func= deleted;
send_ok(thd,deleted);
DBUG_PRINT("info",("%d records deleted",deleted));
}
@@ -550,7 +552,10 @@
if (local_error)
::send_error(thd);
else
+ {
+ thd->row_count_func= deleted;
::send_ok(thd, deleted);
+ }
return 0;
}
--- 1.103/sql/sql_insert.cc Wed Apr 28 12:08:51 2004
+++ 1.104/sql/sql_insert.cc Tue May 4 13:44:54 2004
@@ -419,7 +419,10 @@
goto abort;
if (values_list.elements == 1 && (!(thd->options & OPTION_WARNINGS) ||
!thd->cuted_fields))
- send_ok(thd,info.copied+info.deleted+info.updated,id);
+ {
+ thd->row_count_func= info.copied+info.deleted+info.updated;
+ send_ok(thd, thd->row_count_func, id);
+ }
else
{
char buff[160];
@@ -430,7 +433,8 @@
else
sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
(ulong) info.deleted+info.updated, (ulong) thd->cuted_fields);
- ::send_ok(thd,info.copied+info.deleted+info.updated,(ulonglong)id,buff);
+ thd->row_count_func= info.copied+info.deleted+info.updated;
+ ::send_ok(thd, thd->row_count_func, (ulonglong)id,buff);
}
free_underlaid_joins(thd, &thd->lex->select_lex);
table->insert_values=0;
@@ -1565,7 +1569,8 @@
else
sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
(ulong) info.deleted+info.updated, (ulong) thd->cuted_fields);
- ::send_ok(thd,info.copied+info.deleted+info.updated,last_insert_id,buff);
+ thd->row_count_func= info.copied+info.deleted+info.updated;
+ ::send_ok(thd, thd->row_count_func, last_insert_id, buff);
DBUG_RETURN(0);
}
--- 1.332/sql/sql_parse.cc Wed Apr 7 19:07:37 2004
+++ 1.333/sql/sql_parse.cc Tue May 4 13:44:54 2004
@@ -3582,7 +3582,7 @@
}
if (res == 0)
- send_ok(thd);
+ send_ok(thd, thd->row_count_func);
else
goto error; // Substatement should already have sent error
}
--- 1.105/sql/sql_update.cc Wed Apr 7 15:12:45 2004
+++ 1.106/sql/sql_update.cc Tue May 4 13:44:54 2004
@@ -399,8 +399,9 @@
char buff[80];
sprintf(buff, ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated,
(ulong) thd->cuted_fields);
- send_ok(thd,
- (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated,
+ thd->row_count_func=
+ (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated;
+ send_ok(thd, thd->row_count_func,
thd->insert_id_used ? thd->insert_id() : 0L,buff);
DBUG_PRINT("info",("%d records updated",updated));
}
@@ -1124,8 +1125,9 @@
sprintf(buff, ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated,
(ulong) thd->cuted_fields);
- ::send_ok(thd,
- (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated,
+ thd->row_count_func=
+ (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated;
+ ::send_ok(thd, thd->row_count_func,
thd->insert_id_used ? thd->insert_id() : 0L,buff);
return 0;
}
--- 1.284/sql/sql_yacc.yy Wed Apr 7 19:07:37 2004
+++ 1.285/sql/sql_yacc.yy Tue May 4 13:44:54 2004
@@ -436,6 +436,7 @@
%token X509_SYM
%token XOR
%token COMPRESSED_SYM
+%token ROW_COUNT_SYM
%token ERRORS
%token WARNINGS
@@ -3936,6 +3937,11 @@
| ROUND '(' expr ')'
{ $$= new Item_func_round($3, new Item_int((char*)"0",0,1),0); }
| ROUND '(' expr ',' expr ')' { $$= new Item_func_round($3,$5,0); }
+ | ROW_COUNT_SYM '(' ')'
+ {
+ $$= new Item_func_row_count();
+ Lex->safe_to_cache_query= 0;
+ }
| SUBDATE_SYM '(' expr ',' expr ')'
{ $$= new Item_date_add_interval($3, $5, INTERVAL_DAY, 1);}
| SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
--- 1.60/mysql-test/r/sp.result Wed Apr 28 12:08:50 2004
+++ 1.61/mysql-test/r/sp.result Tue May 4 13:44:54 2004
@@ -802,6 +802,28 @@
drop database sp_db3|
select type,db,name from mysql.proc where db = 'sp_db3'|
type db name
+create procedure rc()
+begin
+delete from t1;
+insert into t1 values ("a", 1), ("b", 2), ("c", 3);
+end|
+call rc()|
+select row_count()|
+row_count()
+3
+update t1 set data=42 where id = "b";
+select row_count()|
+row_count()
+1
+delete from t1|
+select row_count()|
+row_count()
+3
+delete from t1|
+select row_count()|
+row_count()
+0
+drop procedure rc|
create procedure bug822(a_id char(16), a_data int)
begin
declare n int;
--- 1.58/mysql-test/t/sp.test Tue Apr 6 16:29:35 2004
+++ 1.59/mysql-test/t/sp.test Tue May 4 13:44:54 2004
@@ -931,6 +931,25 @@
select type,db,name from mysql.proc where db = 'sp_db3'|
+# ROW_COUNT() function after a CALL
+# We test the other cases here too, although it's not strictly SP specific
+create procedure rc()
+begin
+ delete from t1;
+ insert into t1 values ("a", 1), ("b", 2), ("c", 3);
+end|
+
+call rc()|
+select row_count()|
+update t1 set data=42 where id = "b";
+select row_count()|
+delete from t1|
+select row_count()|
+delete from t1|
+select row_count()|
+drop procedure rc|
+
+
#
# Test cases for old bugs
#
| Thread |
|---|
| • bk commit into 5.0 tree (pem:1.1676) | pem | 4 May |