Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare(Mysql C API) #4

Closed
alex-hsl opened this issue Aug 23, 2012 · 9 comments
Closed

Prepare(Mysql C API) #4

alex-hsl opened this issue Aug 23, 2012 · 9 comments
Assignees

Comments

@alex-hsl
Copy link

I use 'prepare '(mysql c api) to insert/update/delete the sql, but the sql column of the result from tcpcollect contain garbled character.

@hoterran
Copy link
Owner

gave me code, thanks

@ghost ghost assigned hoterran Aug 23, 2012
@hoterran
Copy link
Owner

i am coding for deal prepare-statement sql

@alex-hsl
Copy link
Author

code:

#include <stdio.h>
#include <stdlib.h>
#include "mysql.h"

#define INSERT_SQL "insert player_copy(id, name) values(?, ?)"

void main(int argc, char *_argv)
{
MYSQL mysql,_sock;
MYSQL_STMT *st;
MYSQL_BIND bind[2];

int param_count;
int int_data;
int i;
char str_data[3];
unsigned long str_length;
my_bool is_null;

mysql_init(&mysql);
if (!(sock = mysql_real_connect(&mysql, "127.0.0.1", "root", "123456", "test", 3306, NULL, 0))) {
    fprintf(stderr, "Couldn't connect to engine!\n%s\n\n", mysql_error(&mysql));
    perror("");
    exit(1);
}

st = mysql_stmt_init(&mysql);
mysql_stmt_prepare(st, INSERT_SQL, 47);
param_count = mysql_stmt_param_count(st);
fprintf(stdout, " total parameters in INSERT: %d\n", param_count);

for (i = 1; i < 100000; i ++) {
    int_data = i;
    str_data[0] = 'a';
    str_data[1] = 'b';
    str_data[2] = 'c';
    str_length = 3;
    is_null = 0;

    bind[0].buffer_type= MYSQL_TYPE_LONG;
    bind[0].buffer= &int_data;
    bind[0].is_null= &is_null;

    bind[1].buffer_type= MYSQL_TYPE_VAR_STRING;
    bind[1].buffer= (char *)str_data;
    bind[1].is_null= &is_null;
    bind[1].length= &str_length;

    mysql_stmt_bind_param(st, bind);
    mysql_stmt_execute(st);
}

}

@alex-hsl alex-hsl reopened this Aug 27, 2012
@hoterran
Copy link
Owner

@alex-hsl i finished code for prepare-statment, i am tesing, thank you for issue.

@hoterran
Copy link
Owner

bug fix, please test

@alex-hsl
Copy link
Author

test new code, mysqlpcap show the error.I don't change the test code above.

mysqlpcap: protocol.c:338: store_param_datetime: Assertion `(length == 11) || (length == 4)' failed.

@hoterran
Copy link
Owner

hoterran commented Nov 1, 2012

tanks, let me chek again

@hoterran
Copy link
Owner

@alex-hsl 你的这个例子有点问题,表本身不存在,所以 stmt_id 返回的是 0。
代码里也有些 bug,针对 非法 的 stmt_id 没有做处理

hoterran added a commit that referenced this issue Nov 14, 2012
@hoterran
Copy link
Owner

@alex-hsl 提交修复了,你再看看~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants