Hi,
I'm writing a small C program to clean the radius radacct table, removing ended sessions records and inserting on a separated database. The problem is that MySQL C API doesn't have an easy way to insert the result of a query on another database/table directly, you have to build a custom insert statement, I'm trying to do that, I'm using strncpy to copy the fields on the result row to the insert statement char array. It works for just a few records, than it returns me a segmentation fault error, here is the piece of code where the copy is made:
while(row = mysql_fetch_row(query_result))
{
for (i = 0; i < mysql_num_fields(query_result); i++)
{
strncpy(tmp, row[i], MAX_FIELD_LENGTH);
printf("%s ", tmp);
}
printf("\n");
}
tmp is declarated this way:
char tmp[50];
row is a MYSQL_ROW data structure, which is implemented as an array of strings.
Does anybody know whan can be causing that? Or maybem somebody knows a easier way to insert the result of a select on another table.
Thanks in advance.