I'm trying to get no. of entries from a table in Oracle DB. The application is developed in C and I'm using mySql lib to access the database. As I stated, I am using Oracle in the db layer and mysql functions in the application, this is done using libmysqlora. Everything is working perfectly except one thing, when I issue the query like 'select count(*) from , I get only first 3 digits of the actual count. Following is my entire code to read this:
int64_t vmsdb_read_count(char *table, char *query)
{
uint i;
MYSQL_ROW row;
boolean free_query = FALSE;
if (query == NULL) {
newvallocate(char, query, SHORT_QUERY_SIZE);
snprintf(query, SHORT_QUERY_SIZE, "select count(*) from %s", table);
free_query = TRUE;
}
if (mysql_query(mysql, query)) {
exiterr(Q_NOTICE, query);
goto ERROR;
}
if (!(res = mysql_store_result(mysql))) {
exiterr(Q_NOTICE, "MySQL failed to store results. ");
goto ERROR;
}
while((row = mysql_fetch_row(res))) {
for (i=0 ; i < mysql_num_fields(res); i++) {
int64_t count = atoll(row[i]);
mysql_free_result(res);
res = NULL;
if (free_query) {
vfree(query);
free_query = FALSE;
}
return (count);
}
}
mysql_free_result(res);
res = NULL;
ERROR:
if (free_query) {
vfree(query);
}
return 0;
}
For table 'destination', when I count rows in sqlplus:
SQL> select count(*) from destination;
17928
but When I use the aforementioned function for this:
printf("No. of rows in destination table = %d\n", vmsdb_read_count("destination", NULL));
output--> No. of rows in destination table = 179
Not just for this table, but for every other table in my database, the function only returns first three digits in the count value. What is the cause of this? And, how can I fix this issue?