Developer Forums | About Us | Site Map
Search  
HOME > TUTORIALS > DATABASES > MYSQL TUTORIALS > EXECUTING SQL STATEMENTS IN MYSQL DATABASES USING C


Sponsors





Useful Lists

Web Host
site hosted by netplex

Online Manuals

Executing SQL statements in MySQL databases using C
By Neil Matthew & Richard Stones - 2004-02-06 Page:  1 2 3 4 5

mysql_fetch_rowmysql_fetch_row

MYSQL_ROW mysql_fetch_row(MYSQL_RES *result);

This function takes the result structure we obtained from store result, and retrieves a single row from it, returning the data in a row structure that it allocates for you. When there is no more data, or an error occurs, NULL is returned. We will come back to processing the data in this row structure later.

mysql_data_seek

void mysql_data_seek(MYSQL_RES *result, my_ulonglong offset);

Thisfunction allows you to jump about in the result set, setting the row that will be returned by the next fetch row operation. The offset value is a row number, and must be in the range zero to one less than the number of rows in the result set. Passing zero will cause the first row to be returned on the next call to mysql_fetch_row.

my_sql_row_tell, mysql_row_seek

MYSQL_ROW_OFFEST mysql_row_tell(MYSQL_RES *result);

This function returns an offset value, indicating the current position in the result set. It is not a row number, and you can't use it with mysql_data_seek. However you can use it with:

MYSQL_ROW_OFFSET mysql_row_seek(MYSQL_RES *result, MYSQL_ROW_OFFSET offset);

which moves the current position in the result set, and returns the previous position.

This pair of functions can sometimes be useful for jumping between known points in the result set. Be careful never to mix up the offset value used by row tell and row seek with the row number used by data_seek. These are not interchangeable, and your results will not be what you were hoping for.

mysql_free_result

There is one last function we need to know before we can use these new functions in anger, and that is mysql_free_result.

void mysql_free_result(MYSQL_RES *result);

When you've finished with a result set you must always call this function, to allow the MySQL library to tidy up the objects it has allocated.



View Executing SQL statements in MySQL databases using C Discussion

Page:  1 2 3 4 5 Next Page: Retrieving the data

First published by IBM developerWorks


Copyright 2004-2024 GrindingGears.com. All rights reserved.
Article copyright and all rights retained by the author.