]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
cassandra: Added support for returning "int" type values.
authorTimo Sirainen <tss@iki.fi>
Tue, 13 Oct 2015 17:39:50 +0000 (20:39 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 13 Oct 2015 17:39:50 +0000 (20:39 +0300)
It looks like we need to explicitly convert all types to strings.

src/lib-sql/driver-cassandra.c

index ac82032cdd79d54b995200928e0a818a2821ee81..ce3fbecf8cb76968867011af63cd7190f64b5aa9 100644 (file)
@@ -723,16 +723,35 @@ driver_cassandra_get_value(struct cassandra_result *result,
        void *output_dup;
        size_t output_size;
        CassError rc;
+       const char *type;
 
        if (cass_value_is_null(value)) {
                *str_r = NULL;
                return 0;
        }
 
-       rc = cass_value_get_bytes(value, &output, &output_size);
+       switch (cass_data_type_type(cass_value_data_type(value))) {
+       case CASS_VALUE_TYPE_INT: {
+               cass_int32_t num;
+
+               rc = cass_value_get_int32(value, &num);
+               if (rc == CASS_OK) {
+                       const char *str = t_strdup_printf("%d", num);
+                       output_size = strlen(str);
+                       output = (const void *)str;
+               }
+               type = "int32";
+               break;
+       }
+       default:
+               rc = cass_value_get_bytes(value, &output, &output_size);
+               type = "bytes";
+               break;
+       }
        if (rc != CASS_OK) {
                i_free(result->error);
-               result->error = i_strdup_printf("Couldn't get value as string (code=%d)", rc);
+               result->error = i_strdup_printf("Couldn't get value as %s: %s",
+                                               type, cass_error_desc(rc));
                return -1;
        }
        output_dup = p_malloc(result->row_pool, output_size + 1);