mysql_stmt_execute() trashing stack
Posted by: John Deal
Date: July 26, 2011 11:42AM

I am having a problem with a mysql_stmt_execute() call that when executed overwrites the stack frame. The table in question is a simple 4 field table described below:

mysql> describe subscriptions;

+----------------+------------------+------+-----+---------+----------------+

| Field | Type | Null | Key | Default | Extra |

+----------------+------------------+------+-----+---------+----------------+

| subscriptionID | int(10) unsigned | NO | PRI | NULL | auto_increment |

| userID | int(10) unsigned | YES | MUL | NULL | |

| workplaceID | int(10) unsigned | YES | MUL | NULL | |

| rolesID | int(10) unsigned | YES | | NULL | |

+----------------+------------------+------+-----+---------+----------------+


The current data is:

mysql> select * from subscriptions;

+----------------+--------+-------------+---------+

| subscriptionID | userID | workplaceID | rolesID |

+----------------+--------+-------------+---------+

| 6 | 2 | 6 | NULL |

| 7 | 2 | 7 | NULL |

| 8 | 2 | 8 | NULL |

+----------------+--------+-------------+---------+


The SQL for the prepared statement is:

static const char m_get_subscription_workplace_list_sql[] = "select subscriptionID, userID, workplaceID, rolesID from subscriptions where userID = ?";

The code that binds the one input parameter and executes the query is:

SubscriptionList DbMySqlDirectory::get_user_subscription_workplace_list(

const unsigned int user_id)

{

subscription_record work_subscription;

SubscriptionList work_subscription_list;

int mysql_result;

unsigned long data_lengths[4] = {sizeof(user_id)};

my_bool is_nulls[4] = {false};

MYSQL_BIND bind[4];





cout << "DbMySqlDirectory::get_user_subscription_workplace_list()" << endl; // DEBUG!:JRD

memset(bind, 0, sizeof(bind)); // Initialize MYSQL_BIND structure.

bind[0].buffer_type = MYSQL_TYPE_LONG;

bind[0].buffer = (char*) &user_id;

bind[0].is_null = is_nulls;

// bind[0].length = data_lengths;



if (mysql_stmt_bind_param(m_prep_get_subscription_workplace_list, bind)

!= m_mysql_ok)

{ // Binding failed.

cout << "Error (DbMySqlDirectory::get_user_subscription_workplace_list): Binding of user_id failed. Message: "

<< mysql_stmt_error(m_prep_get_subscription_workplace_list) << endl;

return work_subscription_list;

}



if (mysql_stmt_execute(m_prep_get_subscription_workplace_list)

!= m_mysql_ok)


********At this point the stack is trash ****************************

Interesting the prepared statement area looks good with a status of MYSQL_STMT_EXECUTE_DONE and a last_error of zero. The method continues by binding the output and doing fetches reading all three records. Of course when the method does a return a segment fault is encountered because the return addresses are trashed.

I have no idea why mysql_stmt_execute() would trash the stack at that point. It should only be reading user data (the one bind parameter) not writing any user data at that point. Other information is other queries have been done on the same DB connection but the result sets are freed after each use.

Does anyone see what I am missing here?

Thanks!

Options: ReplyQuote


Subject
Views
Written By
Posted
mysql_stmt_execute() trashing stack
4356
July 26, 2011 11:42AM
1594
August 03, 2011 04:55PM
1749
August 06, 2011 11:29AM
2347
August 07, 2011 12:18PM
1479
August 07, 2011 12:26PM
2218
August 11, 2011 04:11PM
2004
August 13, 2011 01:25PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.