mysql c 存储过程_mysql C API 调用存储过程

John -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4-svn0 (GNU/Linux) Comment: Using GnuPG with SUSE -http://enigmail.mozdev.org

iD8DBQFHxuj3d4I3jTtt9EIRAi5OAKCFoNWxM2GWmoVgUVBFjS3W8e2KqwCgoorP dlEBXsmKeQq0wqt+VlS0Pyo= =C75l -----END PGP SIGNATURE-----

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

int main(int argc, char **argv)

{

char *host_name="localhost";

char *user_name="xxxxxxx";

char *password="xxxxxxxx";

char *db_name="dbmail";

int status = 0;

MYSQL *mysql;

MYSQL_RES *result = 0;

char *query1 = "SELECT alias FROM dbmail_aliases WHERE alias='xx...@example.com'";

char *query2 = "call test('xx...@example.com')";

char *query;

if ((mysql = mysql_init(NULL)) == NULL)

printf("dict_mysql: insufficient memory\n");

if (mysql_real_connect (mysql, host_name, user_name, password, db_name, 3306, 0, CLIENT_MULTI_STATEMENTS) == NULL)

{

printf("mysql_real_connect() failed\n"); mysql_close(mysql);

exit(1);

}

query = query1;

if(argc == 2 && strcmp("2",argv[1])==0)

query = query2;

printf("query %s\n",query);

if (mysql_query(mysql, query))

{

printf("mysql query failed: %s\n", mysql_error(mysql));

exit(1);

}

do

{ /* did current statement return data? */

result = mysql_store_result(mysql);

if (result)

{ /* yes; process rows and free the result set */

process_result_set(mysql, result);

mysql_free_result(result);

}

else /* no result set or error */

{printf("error no [%d] error[%s] info[%s]\n",mysql_errno(mysql),mysql_error(mysql),mysql_info(mysql));

if (mysql_field_count(mysql) == 0)

{

printf("%lld rows affected\n", mysql_affected_rows(mysql));

}

else /* some error occurred */

{

printf("Could not retrieve result set\n");

break;

}

}

/* more results? -1 = no, >0 = error, 0 = yes (keep looping) */

if ((status = mysql_next_result(mysql)) > 0)

printf("status [%d] error no [%d] error[%s] info[%s]\n",status,mysql_errno(mysql),mysql_error(mysql),mysql_info(mysql));

} while (status == 0);

mysql_close(mysql); return 0;

}

int process_result_set(MYSQL * mysql,MYSQL_RES * result)

{

int numrows =0;

int i = 0;

int j = 0;

MYSQL_ROW row;

numrows = mysql_num_rows(result);

printf("retrieved %d rows\n", numrows);

if (numrows == 0)

{

return 0;

}

for (i = 0; i < numrows; i++)

{

row = mysql_fetch_row(result);

for (j = 0; j < mysql_num_fields(result); j++)

{

printf("row [%d] col [%d] result [%s]\n",i,j,row[j]);

}

}

return 0;

}

-- MySQL Documentation Mailing List For list archives: http://lists.mysql.com/mysqldoc To unsubscribe: http://lists.mysql.com/mysqldoc?unsub=pa...@mysql.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值