Vijay Samuel: vjsamuel
Here is a piece of code that illustrates how to create a Drizzle object, a connection object, establish a connection, execute a query, buffer its result and do some basic operations on it. The code is pretty straight forward. DRIZZLE_RETURN_OK indicates the successful execution of a function. Make sure that you have libdrizzle installed in your machine.
#include <libdrizzle/libdrizzle.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
drizzle_st *drizzle;
drizzle_con_st *con;
if ((drizzle= drizzle_create(NULL)) == NULL)
{
printf(“Error creating drizzle object\n”);
return -1;
}
con= drizzle_con_add_tcp(drizzle, NULL, “localhost”, 4427, “root”, “password”, “db”, DRIZZLE_NON_BLOCKING);
drizzle_return_t ret= drizzle_con_connect(con);
if (ret == DRIZZLE_RETURN_OK)
{
printf(“Connection Established\n”);
}
drizzle_result_st *result;
int count= 0;
result= drizzle_query(con, result, “SHOW DATABASES”, strlen(“SHOW DATABASES”), &ret);
ret= drizzle_result_buffer(result);
printf(“%d\n”, (int)drizzle_result_row_count(result));
drizzle_con_free(con);
drizzle_free(drizzle);
return 0;
}
To compile this program, one needs to link to libdrizzle. Use the following command to compile the code file. (Assuming that the code file is connect.c and that you installed libdrizzle-1.0 headers at /usr/include)
gcc -o connect connect.c -ldrizzle -I /usr/include/libdrizzle-1.0 -L /usr/lib
Hope this helps. Happy hacking folks!
URL: http://vjsamuel.wordpress.com/2012/08/31/helloworld-with-libdrizzle/
_______________________________________________ Mailing list: https://launchpad.net/~drizzle-discuss Post to : [email protected] Unsubscribe : https://launchpad.net/~drizzle-discuss More help : https://help.launchpad.net/ListHelp

