Some queries give results, and others don't. For example, the data results for UPDATE, INSERT, or DELETE statements always contain 0 rows. When running a SELECT statement, there may or may not be rows that matched your query, so it is always a good idea to make sure that you have data by checking the return value of qdb_statement().
To help you debug your application, you can use qdb_printmsg(stdout, result, QDB_FORMAT_SIMPLE) to print the fetched result to stdout() so that you can visualize your data.
Here's an example of getting the results of an operation:
qdb_result_t *result; // requires a statement previously run result = qdb_getresult(dbhandle); if (result == NULL) { char *errmsg; errmsg = qdb_geterrmsg(dbhandle); fprintf(stderr, "Error getting result: %s\n", errmsg); }
Memory for the results is allocated when the statement is run on the database, so you must free the result structure or you will have memory leaks. Do this by calling qdb_freeresult(), as shown in the example later in this chapter. Never call free() yourself.