summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c3cfa4b)
raw | patch | inline | side by side (parent: c3cfa4b)
author | Sebastian Harl <sh@tokkee.org> | |
Tue, 28 Jan 2014 19:12:22 +0000 (20:12 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Tue, 28 Jan 2014 19:12:22 +0000 (20:12 +0100) |
This will allow for more flexibility. However, it also requires to create a
copy of data queried using libdbi.
copy of data queried using libdbi.
src/include/core/data.h | patch | blob | history | |
src/utils/dbi.c | patch | blob | history | |
src/utils/unixsock.c | patch | blob | history |
index 4a4dd2d3385e5f2fbf9e17fbd39cf0e2161772b4..b657486b794b16cdb9bc00560cb0b2f4ab2090dc 100644 (file)
--- a/src/include/core/data.h
+++ b/src/include/core/data.h
union {
int64_t integer; /* SDB_TYPE_INTEGER */
double decimal; /* SDB_TYPE_DECIMAL */
- const char *string; /* SDB_TYPE_STRING */
+ char *string; /* SDB_TYPE_STRING */
sdb_time_t datetime; /* SDB_TYPE_DATETIME */
struct {
size_t length;
- const unsigned char *datum;
+ unsigned char *datum;
} binary; /* SDB_TYPE_BINARY */
} data;
} sdb_data_t;
diff --git a/src/utils/dbi.c b/src/utils/dbi.c
index 1de2f1abe678b74dae092b4b51b40a888b68ceb0..c8eb81616454a3078eb768f16b1affd32b81f1d9 100644 (file)
--- a/src/utils/dbi.c
+++ b/src/utils/dbi.c
data->data.decimal = dbi_result_get_double_idx(res, i);
break;
case SDB_TYPE_STRING:
- data->data.string = dbi_result_get_string_idx(res, i);
+ data->data.string = dbi_result_get_string_copy_idx(res, i);
break;
case SDB_TYPE_DATETIME:
{
case SDB_TYPE_BINARY:
{
size_t length = dbi_result_get_field_length_idx(res, i);
- const unsigned char *datum = dbi_result_get_binary_idx(res, i);
+ unsigned char *datum = dbi_result_get_binary_copy_idx(res, i);
data->data.binary.length = length;
data->data.binary.datum = datum;
}
return -1;
for (n = 0; n < num_rows; ++n) {
+ int status;
+
if (! dbi_result_seek_row(res, n + 1)) {
sdb_log(SDB_LOG_ERR, "dbi: Failed to retrieve row %llu: %s",
n, sdb_dbi_strerror(client->conn));
types[i], &data[i]))
continue;
- if (callback(client, num_fields, data, user_data))
+ status = callback(client, num_fields, data, user_data);
+ for (i = 0; i < num_fields; ++i) {
+ if ((data[i].type == SDB_TYPE_STRING) && (data[i].data.string))
+ free(data[i].data.string);
+ else if ((data[i].type == SDB_TYPE_BINARY)
+ && (data[i].data.binary.datum))
+ free(data[i].data.binary.datum);
+ }
+
+ if (status)
continue;
++success;
diff --git a/src/utils/unixsock.c b/src/utils/unixsock.c
index 62b6f45aa404f360ed1f623c07362dcb2c2e26b0..9a5c3fab8c91de6c510a99d8740e4ae2301e0a01 100644 (file)
--- a/src/utils/unixsock.c
+++ b/src/utils/unixsock.c
case SDB_TYPE_BINARY:
/* we don't support any binary information containing 0-bytes */
data->data.binary.length = strlen(string);
- data->data.binary.datum = (const unsigned char *)string;
+ data->data.binary.datum = (unsigned char *)string;
break;
default:
sdb_log(SDB_LOG_ERR, "unixsock: Unexpected type %i while "