Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
69d00bdb
Commit
69d00bdb
authored
Feb 06, 2004
by
konstantin@oak.local
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for bug #2247: "mysql_stmt_affected_rows returns affected rows from
last command"
parent
c4728c27
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
1 deletion
+85
-1
include/mysql.h
include/mysql.h
+2
-0
libmysql/libmysql.c
libmysql/libmysql.c
+3
-1
tests/client_test.c
tests/client_test.c
+80
-0
No files found.
include/mysql.h
View file @
69d00bdb
...
@@ -537,6 +537,8 @@ typedef struct st_mysql_stmt
...
@@ -537,6 +537,8 @@ typedef struct st_mysql_stmt
char
*
query
;
/* query buffer */
char
*
query
;
/* query buffer */
MEM_ROOT
mem_root
;
/* root allocations */
MEM_ROOT
mem_root
;
/* root allocations */
my_ulonglong
last_fetched_column
;
/* last fetched column */
my_ulonglong
last_fetched_column
;
/* last fetched column */
my_ulonglong
affected_rows
;
/* copy of mysql->affected_rows
after statement execution */
unsigned
long
stmt_id
;
/* Id for prepared statement */
unsigned
long
stmt_id
;
/* Id for prepared statement */
unsigned
int
last_errno
;
/* error code */
unsigned
int
last_errno
;
/* error code */
unsigned
int
param_count
;
/* parameters count */
unsigned
int
param_count
;
/* parameters count */
...
...
libmysql/libmysql.c
View file @
69d00bdb
...
@@ -2018,6 +2018,7 @@ static my_bool execute(MYSQL_STMT * stmt, char *packet, ulong length)
...
@@ -2018,6 +2018,7 @@ static my_bool execute(MYSQL_STMT * stmt, char *packet, ulong length)
set_stmt_errmsg
(
stmt
,
net
->
last_error
,
net
->
last_errno
,
net
->
sqlstate
);
set_stmt_errmsg
(
stmt
,
net
->
last_error
,
net
->
last_errno
,
net
->
sqlstate
);
DBUG_RETURN
(
1
);
DBUG_RETURN
(
1
);
}
}
stmt
->
affected_rows
=
mysql
->
affected_rows
;
DBUG_RETURN
(
0
);
DBUG_RETURN
(
0
);
}
}
...
@@ -2127,7 +2128,7 @@ ulong STDCALL mysql_param_count(MYSQL_STMT * stmt)
...
@@ -2127,7 +2128,7 @@ ulong STDCALL mysql_param_count(MYSQL_STMT * stmt)
my_ulonglong
STDCALL
mysql_stmt_affected_rows
(
MYSQL_STMT
*
stmt
)
my_ulonglong
STDCALL
mysql_stmt_affected_rows
(
MYSQL_STMT
*
stmt
)
{
{
return
stmt
->
mysql
->
last_used_con
->
affected_rows
;
return
stmt
->
affected_rows
;
}
}
...
@@ -3223,6 +3224,7 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt)
...
@@ -3223,6 +3224,7 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt)
DBUG_RETURN
(
0
);
DBUG_RETURN
(
0
);
}
}
mysql
->
affected_rows
=
result
->
row_count
=
result
->
data
->
rows
;
mysql
->
affected_rows
=
result
->
row_count
=
result
->
data
->
rows
;
stmt
->
affected_rows
=
result
->
row_count
;
result
->
data_cursor
=
result
->
data
->
data
;
result
->
data_cursor
=
result
->
data
->
data
;
result
->
fields
=
stmt
->
fields
;
result
->
fields
=
stmt
->
fields
;
result
->
field_count
=
stmt
->
field_count
;
result
->
field_count
=
stmt
->
field_count
;
...
...
tests/client_test.c
View file @
69d00bdb
...
@@ -8095,6 +8095,82 @@ static void test_bug1946()
...
@@ -8095,6 +8095,82 @@ static void test_bug1946()
rc
=
mysql_query
(
mysql
,
"DROP TABLE prepare_command"
);
rc
=
mysql_query
(
mysql
,
"DROP TABLE prepare_command"
);
}
}
static
void
test_bug2247
()
{
MYSQL_STMT
*
stmt
;
MYSQL_RES
*
res
;
int
rc
;
int
i
;
const
char
*
create
=
"CREATE TABLE bug2247(id INT UNIQUE AUTO_INCREMENT)"
;
const
char
*
insert
=
"INSERT INTO bug2247 VALUES (NULL)"
;
const
char
*
select
=
"SELECT id FROM bug2247"
;
const
char
*
update
=
"UPDATE bug2247 SET id=id+10"
;
const
char
*
drop
=
"DROP TABLE IF EXISTS bug2247"
;
ulonglong
exp_count
;
enum
{
NUM_ROWS
=
5
};
myheader
(
"test_bug2247"
);
fprintf
(
stdout
,
"
\n
Checking if stmt_affected_rows is not affected by
\n
"
"mysql_query ... "
);
/* create table and insert few rows */
rc
=
mysql_query
(
mysql
,
drop
);
myquery
(
rc
);
rc
=
mysql_query
(
mysql
,
create
);
myquery
(
rc
);
stmt
=
mysql_prepare
(
mysql
,
insert
,
strlen
(
insert
));
mystmt_init
(
stmt
);
for
(
i
=
0
;
i
<
NUM_ROWS
;
++
i
)
{
rc
=
mysql_execute
(
stmt
);
mystmt
(
stmt
,
rc
);
}
exp_count
=
mysql_stmt_affected_rows
(
stmt
);
assert
(
exp_count
==
1
);
rc
=
mysql_query
(
mysql
,
select
);
myquery
(
rc
);
/*
mysql_store_result overwrites mysql->affected_rows. Check that
mysql_stmt_affected_rows() returns the same value, whereas
mysql_affected_rows() value is correct.
*/
res
=
mysql_store_result
(
mysql
);
mytest
(
res
);
assert
(
mysql_affected_rows
(
mysql
)
==
NUM_ROWS
);
assert
(
exp_count
==
mysql_stmt_affected_rows
(
stmt
));
rc
=
mysql_query
(
mysql
,
update
);
myquery
(
rc
);
assert
(
mysql_affected_rows
(
mysql
)
==
NUM_ROWS
);
assert
(
exp_count
==
mysql_stmt_affected_rows
(
stmt
));
mysql_free_result
(
res
);
mysql_stmt_close
(
stmt
);
/* check that mysql_stmt_store_result modifies mysql_stmt_affected_rows */
stmt
=
mysql_prepare
(
mysql
,
select
,
strlen
(
select
));
mystmt_init
(
stmt
);
rc
=
mysql_execute
(
stmt
);
mystmt
(
stmt
,
rc
);
rc
=
mysql_stmt_store_result
(
stmt
);
mystmt
(
stmt
,
rc
);
exp_count
=
mysql_stmt_affected_rows
(
stmt
);
assert
(
exp_count
==
NUM_ROWS
);
rc
=
mysql_query
(
mysql
,
insert
);
myquery
(
rc
);
assert
(
mysql_affected_rows
(
mysql
)
==
1
);
assert
(
mysql_stmt_affected_rows
(
stmt
)
==
exp_count
);
mysql_stmt_close
(
stmt
);
fprintf
(
stdout
,
"OK"
);
}
/*
/*
Read and parse arguments and MySQL options from my.cnf
Read and parse arguments and MySQL options from my.cnf
...
@@ -8340,6 +8416,10 @@ int main(int argc, char **argv)
...
@@ -8340,6 +8416,10 @@ int main(int argc, char **argv)
test_bug1644
();
/* BUG#1644 */
test_bug1644
();
/* BUG#1644 */
test_bug1946
();
/* test that placeholders are allowed only in
test_bug1946
();
/* test that placeholders are allowed only in
prepared queries */
prepared queries */
test_bug2247
();
/* test that mysql_stmt_affected_rows() returns
number of rows affected by last prepared
statement execution
*/
end_time
=
time
((
time_t
*
)
0
);
end_time
=
time
((
time_t
*
)
0
);
total_time
+=
difftime
(
end_time
,
start_time
);
total_time
+=
difftime
(
end_time
,
start_time
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment