added reallocation to sql callback #3

Manually merged
emil merged 1 commits from fa11_1eaf into master 2023-08-04 09:53:45 -04:00
Showing only changes of commit cb43b28c8f - Show all commits

View File

@ -147,7 +147,27 @@ rtos(void * data,
){
(void) colname;
char *const *const r = (char**)data;
char ** r = (char**)data;
size_t data_len = 0;
for(int i = 0; i < argc; i++)
{
if(argv[i])
{
data_len += strlen(argv[i]);
}
else
{
/* strlen("NULL") == 4 */
data_len += 4;
}
/* strlen("|") * 2 == 2 */
data_len += 2;
}
++data_len;
*r = (char *)calloc(data_len, sizeof(char));
for(int i = 0; i < argc; i++){
strcat(*r, "|");
if(argv[i]){
@ -167,9 +187,10 @@ DECL char *
dump()
{
char* errmsg;
/* TODO: allow for reallocing in rtos, start with a smaller value */
char* r = (char*)calloc(sizeof(char), 10000);
char* r = NULL;
DBERR(sqlite3_exec(connection, dump_stmt, rtos, &r, &errmsg));
return r;
}
@ -177,9 +198,10 @@ DECL char *
raw(char const * const sql)
{
char* errmsg;
/* TODO: allow for reallocing in rtos, start with a smaller value */
char *r = (char*)calloc(sizeof(char), 10000);
char *r = NULL;
sqlite3_exec(connection, sql, rtos, &r, &errmsg);
if (errmsg){
free(r);
r = errmsg;