diff options
author | David Robillard <d@drobilla.net> | 2006-09-02 08:26:17 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2006-09-02 08:26:17 +0000 |
commit | 69e52cb83cf0233648695730c81cdc4f7c4f2a00 (patch) | |
tree | 5e8ebb5773cba2c1ffd827baf9a4fe528fbcaeeb /src/query.c | |
parent | cf11310c243320bbe53dbf7c6738cc84e33ba9d3 (diff) | |
download | lilv-69e52cb83cf0233648695730c81cdc4f7c4f2a00.tar.gz lilv-69e52cb83cf0233648695730c81cdc4f7c4f2a00.tar.bz2 lilv-69e52cb83cf0233648695730c81cdc4f7c4f2a00.zip |
Schema bug fixes (parsable now).
Fixed some leaks.
Internal query API cleanups.
Added latency reporting support.
git-svn-id: http://svn.drobilla.net/lad/libslv2@110 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/query.c')
-rw-r--r-- | src/query.c | 65 |
1 files changed, 41 insertions, 24 deletions
diff --git a/src/query.c b/src/query.c index 0517331..8f3ef40 100644 --- a/src/query.c +++ b/src/query.c @@ -83,40 +83,57 @@ slv2_plugin_run_query(const SLV2Plugin* p, return results; } +size_t +slv2_query_get_num_results(rasqal_query_results* results, const char* var_name) +{ + size_t result = 0; + + while (!rasqal_query_results_finished(results)) { + if (!strcmp(rasqal_query_results_get_binding_name(results, 0), var_name)) { + ++result; + } + rasqal_query_results_next(results); + } + + return result; +} SLV2Property -slv2_query_get_results(rasqal_query_results* results) +slv2_query_get_results(rasqal_query_results* results, const char* var_name) { struct _Property* result = NULL; - - if (rasqal_query_results_get_count(results) > 0) { - result = malloc(sizeof(struct _Property)); - result->num_values = 0; - result->values = NULL; - } - - while (!rasqal_query_results_finished(results)) { - - rasqal_literal* literal = - rasqal_query_results_get_binding_value_by_name(results, "value"); - assert(literal != NULL); - - // Add value on to the array. Yes, this is disgusting. - result->num_values++; - // FIXME LEAK: - result->values = realloc(result->values, result->num_values * sizeof(char*)); - result->values[result->num_values-1] = strdup(rasqal_literal_as_string(literal)); - - rasqal_query_results_next(results); - } - return result; + if (rasqal_query_results_get_bindings_count(results) > 0) { + result = malloc(sizeof(struct _Property)); + result->num_values = 0; + result->values = NULL; + } + + while (!rasqal_query_results_finished(results)) { + + rasqal_literal* literal = + rasqal_query_results_get_binding_value_by_name(results, var_name); + assert(literal != NULL); + + // Add value on to the array, reallocing all the way. + // Yes, this is disgusting. Roughly as disgusting as the rasqal query + // results API. coincidentally. + result->num_values++; + result->values = realloc(result->values, result->num_values * sizeof(char*)); + result->values[result->num_values-1] = strdup(rasqal_literal_as_string(literal)); + + rasqal_query_results_next(results); + } + + return result; } void slv2_property_free(struct _Property* prop) { - //struct _Property* prop = (struct _Property*)property; + for (size_t i=0; i < prop->num_values; ++i) + free(prop->values[i]); + free(prop->values); free(prop); } |