Better blob handling (also better debug viewing)

This commit is contained in:
2020-10-07 16:26:57 +01:00
parent 29b06e0ad2
commit fb92672739
3 changed files with 17 additions and 7 deletions

View File

@@ -240,8 +240,13 @@ void freeColumn(struct column_data_t *col)
if (col->hasPointers) {
for (unsigned int r = 0; r < col->n_values; r++) {
if (!columnRowIsNull(col, r)) {
if (col->type == TYPE_STRING) {
free(*(col->data.ptr_str + r));
*(col->data.ptr_str + r) = 0;
} else {
free(*(col->data.ptr_blob + r));
*(col->data.ptr_blob + r) = 0;
}
}
}
@@ -378,12 +383,13 @@ int setColumnValue(struct column_data_t *col, uint64_t row, const char *value, s
case TYPE_BLOB:
case TYPE_RAW:
{
*(col->data.ptr_str + row) = (char *)malloc(value_size);
if (*(col->data.ptr_str + row) == 0) {
*(col->data.ptr_blob + row) = (char *)malloc(value_size);
if (*(col->data.ptr_blob + row) == 0) {
fprintf(stderr, "[%d]malloc: (%d) %s\n", __LINE__, errno, strerror(errno));
return -errno;
}
memcpy(*(col->data.ptr_str + row), value, value_size);
memcpy(*(col->data.ptr_blob + row), value, value_size);
*(col->data_lens + row) = value_size;
break;
}
}

View File

@@ -66,6 +66,8 @@ struct column_data_t {
double *ptr_double;
char **ptr_str;
char **ptr_blob;
} data;
size_t *data_lens;

View File

@@ -116,13 +116,15 @@ void db_value_sbva(str_builder *sb, e_column_type type, uint32_t n_args, va_list
tmp_len = va_arg(args, size_t);
esc_str = (char *)malloc(tmp_len * 2 + 1);
esc_str = (char *)malloc(tmp_len * 2 + 1 + 2);
if (esc_str == 0) {
fprintf(stderr, "[%d]malloc: (%d) %s\n", __LINE__, errno, strerror(errno));
return;
}
esc_len = mysql_hex_string(esc_str, tmp_str, tmp_len);
esc_str[0] = '0';
esc_str[1] = 'x';
esc_len = mysql_hex_string(esc_str + 2, tmp_str, tmp_len);
strbld_str(sb, esc_str, esc_len);
free(esc_str);
return;