Home | Hardware | Internet News |Web Hosting |IT Management |Network Storage
LinuxPlanet
Search 
  Power Search | Tips 

 Front Door
 Discussion
 LinuxEngine
 Opinions
 Reports
 Reviews
 Tutorials
 News
 Technology Jobs

 Browse by subject.
Free Newsletter

Linux Planet
Linux Today
More Free Newsletters

Be a Commerce Partner


















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

Print this article
Email this article
Related Items

•  Apples and Oranges: A Linux DBMS Comparison


   LinuxPlanet / Tutorials



Apples and Oranges, Part II: A Linux DBMS Comparison
Bringing the Client to Life on MySQL

Matthias Warkus
Thursday, November 18, 1999 01:25:46 PM

MySQL's C API is pretty easy to use. The central element is a structure containing information about, and state of, the database connection, which is initialized by connecting to the MySQL server. A pointer to this structure must be passed to all MySQL client functions.

Queries are submitted as strings; this means that one must deal with C's string conversion facilities. Should data containing null bytes (\0) be used, the situation becomes more complicated, because a counted string is then passed instead of a C string.

To fetch a query's result, a pointer to a MYSQL_RES structure and a count variable are initialized with appropriate API functions, and then rows are fetched into a MYSQL_ROW variable, which is an array of strings. Directly putting results into integer variables, as PostgreSQL's implementation of ESQL could do, is not possible. The result buffer is then freed. As you can see, the semantics are almost the same as using a cursor in ESQL.

Here is list_books(), written using MySQL's C API:

list_books(void)
{
  int count;
  MYSQL_RES *result;

  mysql_query(&bookstore, "SELECT ARTICLE_NO, AUTHOR_FIRST_NAMES,\
AUTHOR_LAST_NAMES, TITLE, ISBN, WHOLESALE_PRICE, RETAIL_PRICE,\
COPIES_AVAILABLE FROM BOOK");
  result = mysql_store_result(&bookstore);

  for(count = mysql_num_rows(result); count > 0; count--)
	{
	  MYSQL_ROW record;
	  record = mysql_fetch_row(result);

	  printf("\nArticle no. %s\n", record[0]);
	  printf("%s, %s:\n", record[2], record[1]);
	  printf("    %s (%s)\n", record[3], record[4]);
	  printf("Bought at %s; selling at %s; %s copies available\n\n",
			 record[5], record[6], record[7]);
	};

  mysql_free_result(result);
}

The API functions are concisely, but sufficiently, documented in the Texinfo file that comes as MySQL's main source of documentation.

Next: Bringing the Client to Life on mSQL »

Skip Ahead

1 The Database Design
2 Adapting the Design to PostgreSQL
3 Adapting the Design to MySQL
4 Adapting the Design to mSQL
5 Implementing the Test Client
6 Bringing the Client to Life on PostgreSQL
7 Bringing the Client to Life on MySQL
8 Bringing the Client to Life on mSQL
9 Some Early Conclusions





Linux is a trademark of Linus Torvalds.


internet.com home | search | help! | about us

Jupiter Online Media

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers