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