1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
int SqlDataBase::process_select_statement(char *VarSqlStatment)
{
MYSQL_RES *res_set;
int status;
int keep_going = 1;
if (mysql_query (conn, VarSqlStatment) != 0) /* the statement(s) failed */
{
print_error (conn, "Could not execute statement(s)");
return 0;
}
/* the statement(s) succeeded; enter result-retrieval loop */
do {
/* determine whether current statement returned data */
res_set = mysql_store_result (conn);
if (res_set) /* a result set was returned */
{
/* process rows and then free the result set */
process_result_set (conn, res_set);
mysql_free_result (res_set);
}
else /* no result set was returned */
{
/*
* does the lack of a result set mean that the statement didn't
* return one, or that it should have but an error occurred?
*/
if (mysql_field_count (conn) == 0)
{
/*
* statement generated no result set (it was not a SELECT,
* SHOW, DESCRIBE, etc.); just report rows-affected value.
*/
}
else /* an error occurred */
{
print_error (conn, "Could not retrieve result set");
keep_going = 0;
}
}
/* determine whether more results exist */
/* 0 = yes, -1 = no, >0 = error */
status = mysql_next_result (conn);
if (status != 0) /* no more results, or an error occurred */
{
keep_going = 0;
if (status > 0) /* error */
print_error (conn, "Could not execute statement");
}
} while (keep_going);
};
void SqlDataBase::process_result_set (MYSQL *conn, MYSQL_RES *res_set)
{
MYSQL_ROW row;
unsigned int i;
// Let the program know that the result set was empty
while ((row = mysql_fetch_row (res_set)) != NULL)
{
// Let the program know that the result set was empty
ResultSetThere = true;
for (i = 0; i < mysql_num_fields (res_set); i++)
{
if (i > 0)
{
fputc ('\t', stdout);
}
//function here for dealing with the returned results, but took them out to make code smaller and the problem function will never make it here
fputc ('\n', stdout);
}
if (mysql_errno (conn) !=0)
{
print_error (conn, "mysql_fetch_row() failed");
}
else
{
// printf ("Number of rows returned: %lu\n",
// (unsigned long) mysql_num_rows (res_set));
}
}
}
/* #@ _PRINT_ERROR_ */
void SqlDataBase::print_error (MYSQL *conn, char *message)
{
if (conn != NULL)
{
fprintf (stderr, "Error %u (%s): %s\n",
mysql_errno (conn), mysql_sqlstate (conn), mysql_error (conn));
}
}
|