[SOLVED] Segmentation fault in client on 2nd cursor mysql_stmt_fetch
I'm creating a prepared statement involving a query with 1 (bind) parameter and 1 (bind) result (and returning 1 row). The statement has its STMT_ATTR_CURSOR_TYPE set to CURSOR_TYPE_READ_ONLY and prefetches 1 row.
The statement 'stmt1' executes fine and I can fetch the single result. However, if I create a subsequent statement 'stmt2' with different data structures than stmt1, things go wrong.
If run mysql_stmt_close(stmt1) before running mysql_stmt_fetch(stmt2), then mysql_stmt_fetch(stmt2) fails and mysql reports "Prepared statement contains no metadata". If I don't run mysql_stmt_close(stmt1) before running mysql_stmt_fetch(stmt2) then the program produces a segmentation fault on mysql_stmt_fetch(stmt2).
Both statements are created (mysql_stmt_init) from the same database connection.
From what I've read, it seems that I should be able to have more than 1 prepared statement created from a single connection as long STMT_ATTR_CURSOR_TYPE is CURSOR_TYPE_READ_ONLY for both statements. While debugging the statements, stmt1 has stmt_id = 1 and stmt2 has stmt_id = 2. Both are bound to different MYSQL_BIND[] instances and use different parameters and results. In effect, both statements are separate other than having being initialized (mysql_stmt_init) from the same database connection.
stmt1 before calling fetch:
mem_root = {
free = 0x6552d0,
used = 0x0,
pre_alloc = 0x6552d0,
min_malloc = 32,
block_size = 2016,
block_num = 4,
first_block_usage = 0,
error_handler = 0
},
list = {
prev = 0x0,
next = 0x0,
data = 0x654f50
},
mysql = 0x63b200,
params = 0x6553a0,
bind = 0x655410,
fields = 0x6552e0,
result = {
data = 0x0,
embedded_info = 0x0,
alloc = {
free = 0x655af0,
used = 0x0,
pre_alloc = 0x655af0,
min_malloc = 24,
block_size = 4064,
block_num = 4,
first_block_usage = 0,
error_handler = 0
},
rows = 0,
fields = 0,
extension = 0x0
},
data_cursor = 0x0,
read_row_func = 0x7ffff7920700,
affected_rows = 18446744073709551615,
insert_id = 0,
stmt_id = 1,
flags = 1,
prefetch_rows = 1,
server_status = 66,
last_errno = 0,
param_count = 1,
field_count = 1,
state = MYSQL_STMT_EXECUTE_DONE,
last_error = '\000' <repeats 511 times>,
sqlstate = "00000",
send_types_to_server = 0 '\000',
bind_param_done = 1 '\001',
bind_result_done = 3 '\003',
unbuffered_fetch_cancelled = 0 '\000',
update_max_length = 0 '\000',
extension = 0x655290
}
stmt1 after calling fetch:
mem_root = {
free = 0x6552d0,
used = 0x0,
pre_alloc = 0x6552d0,
min_malloc = 32,
block_size = 2016,
block_num = 4,
first_block_usage = 0,
error_handler = 0
},
list = {
prev = 0x656db8,
next = 0x0,
data = 0x654f50
},
mysql = 0x63b200,
params = 0x6553a0,
bind = 0x655410,
fields = 0x6552e0,
result = {
data = 0x0,
embedded_info = 0x0,
alloc = {
free = 0x655af0,
used = 0x0,
pre_alloc = 0x655af0,
min_malloc = 24,
block_size = 4064,
block_num = 4,
first_block_usage = 0,
error_handler = 0
},
rows = 0,
fields = 0,
extension = 0x0
},
data_cursor = 0x0,
read_row_func = 0x7ffff791cec0,
affected_rows = 18446744073709551615,
insert_id = 0,
stmt_id = 1,
flags = 1,
prefetch_rows = 1,
server_status = 130,
last_errno = 0,
param_count = 1,
field_count = 1,
state = MYSQL_STMT_PREPARE_DONE,
last_error = '\000' <repeats 511 times>,
sqlstate = "00000",
send_types_to_server = 0 '\000',
bind_param_done = 1 '\001',
bind_result_done = 3 '\003',
unbuffered_fetch_cancelled = 0 '\000',
update_max_length = 0 '\000',
extension = 0x655290
}
stmt2 before calling fetch having called mysql_stmt_close(stmt1):
mem_root = {
free = 0x657100,
used = 0x0,
pre_alloc = 0x657100,
min_malloc = 32,
block_size = 2016,
block_num = 4,
first_block_usage = 0,
error_handler = 0
},
list = {
prev = 0x0,
next = 0x654f88,
data = 0x656d80
},
mysql = 0x63b200,
params = 0x6571e0,
bind = 0x657250,
fields = 0x657110,
result = {
data = 0x0,
embedded_info = 0x0,
alloc = {
free = 0x657920,
used = 0x0,
pre_alloc = 0x657920,
min_malloc = 24,
block_size = 4064,
block_num = 4,
first_block_usage = 0,
error_handler = 0
},
rows = 0,
fields = 0,
extension = 0x0
},
data_cursor = 0x0,
read_row_func = 0x7ffff7920700,
affected_rows = 18446744073709551615,
insert_id = 0,
stmt_id = 2,
flags = 1,
prefetch_rows = 1,
server_status = 66,
last_errno = 0,
param_count = 1,
field_count = 1,
state = MYSQL_STMT_EXECUTE_DONE,
last_error = '\000' <repeats 511 times>,
sqlstate = "00000",
send_types_to_server = 0 '\000',
bind_param_done = 1 '\001',
bind_result_done = 3 '\003',
unbuffered_fetch_cancelled = 0 '\000',
update_max_length = 0 '\000',
extension = 0x6570c0
}
I'm running mysql 5.5.18 on x86_64.
Thanks.
Edited 1 time(s). Last edit at 01/23/2012 10:46PM by Michael Soltis.