dovecot-2.2: cassandra: Implemented support for binary values.

dovecot at dovecot.org dovecot at dovecot.org
Wed Sep 2 16:43:48 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/5119a85795f7
changeset: 19071:5119a85795f7
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Sep 02 19:42:45 2015 +0300
description:
cassandra: Implemented support for binary values.

diffstat:

 src/lib-sql/driver-cassandra.c |  28 ++++++++++++++++++++++------
 1 files changed, 22 insertions(+), 6 deletions(-)

diffs (86 lines):

diff -r d6d3bd868bd4 -r 5119a85795f7 src/lib-sql/driver-cassandra.c
--- a/src/lib-sql/driver-cassandra.c	Wed Sep 02 19:41:23 2015 +0300
+++ b/src/lib-sql/driver-cassandra.c	Wed Sep 02 19:42:45 2015 +0300
@@ -57,6 +57,7 @@
 
 	pool_t row_pool;
 	ARRAY_TYPE(const_string) fields;
+	ARRAY(size_t) field_sizes;
 
 	sql_query_callback_t *callback;
 	void *context;
@@ -640,9 +641,11 @@
 
 static int
 driver_cassandra_get_value(struct cassandra_result *result,
-			   const CassValue *value, const char **str_r)
+			   const CassValue *value, const char **str_r,
+			   size_t *len_r)
 {
-	const char *output;
+	const unsigned char *output;
+	void *output_dup;
 	size_t output_size;
 	CassError rc;
 
@@ -651,13 +654,16 @@
 		return 0;
 	}
 
-	rc = cass_value_get_string(value, &output, &output_size);
+	rc = cass_value_get_bytes(value, &output, &output_size);
 	if (rc != CASS_OK) {
 		i_free(result->error);
 		result->error = i_strdup_printf("Couldn't get value as string (code=%d)", rc);
 		return -1;
 	}
-	*str_r = p_strndup(result->row_pool, output, output_size);
+	output_dup = p_malloc(result->row_pool, output_size + 1);
+	memcpy(output_dup, output, output_size);
+	*str_r = output_dup;
+	*len_r = output_size;
 	return 0;
 }
 
@@ -667,6 +673,7 @@
 	const CassRow *row;
 	const CassValue *value;
 	const char *str;
+	size_t size;
 	unsigned int i;
 	int ret = 1;
 
@@ -678,14 +685,16 @@
 
 	p_clear(result->row_pool);
 	p_array_init(&result->fields, result->row_pool, 8);
+	p_array_init(&result->field_sizes, result->row_pool, 8);
 
 	row = cass_iterator_get_row(result->iterator);
 	for (i = 0; (value = cass_row_get_column(row, i)) != NULL; i++) {
-		if (driver_cassandra_get_value(result, value, &str) < 0) {
+		if (driver_cassandra_get_value(result, value, &str, &size) < 0) {
 			ret = -1;
 			break;
 		}
 		array_append(&result->fields, &str, 1);
+		array_append(&result->field_sizes, &size, 1);
 	}
 	return ret;
 }
@@ -728,7 +737,14 @@
 					       unsigned int idx ATTR_UNUSED,
 					       size_t *size_r ATTR_UNUSED)
 {
-	i_unreached();
+	struct cassandra_result *result = (struct cassandra_result *)_result;
+	const char *const *strp;
+	const size_t *sizep;
+
+	strp = array_idx(&result->fields, idx);
+	sizep = array_idx(&result->field_sizes, idx);
+	*size_r = *sizep;
+	return (const void *)*strp;
 }
 
 static const char *


More information about the dovecot-cvs mailing list