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