[open-ils-commits] r12103 - trunk/Open-ILS/src/c-apps (scottmk)
svn at svn.open-ils.org
svn at svn.open-ils.org
Sat Feb 7 19:28:14 EST 2009
Author: scottmk
Date: 2009-02-07 19:28:13 -0500 (Sat, 07 Feb 2009)
New Revision: 12103
Modified:
trunk/Open-ILS/src/c-apps/oils_cstore.c
Log:
More tweaks, mostly to SELECT():
1. When building the select list, insert a separator comma in one
place instead of duplicating the code.
2. Narrowed the scope of fname.
3. Created a new transform_str variable instead of reusing _column
for a different purpose.
4. Juggled _column and _alias a bit so as to eliminate a strdup()
and a free().
5.In searchFieldTransform(): plugged a memory leak in the event of
an error return.
Modified: trunk/Open-ILS/src/c-apps/oils_cstore.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_cstore.c 2009-02-07 20:21:18 UTC (rev 12102)
+++ trunk/Open-ILS/src/c-apps/oils_cstore.c 2009-02-08 00:28:13 UTC (rev 12103)
@@ -1755,7 +1755,8 @@
OSRF_BUFFER_ADD( sql_buf, val );
} else {
osrfLogError(OSRF_LOG_MARK, "%s: Error quoting key string [%s]", MODULENAME, val);
- free(field_transform);
+ free(transform_subcolumn);
+ free(field_transform);
free(val);
buffer_free(sql_buf);
return NULL;
@@ -2473,6 +2474,13 @@
jsonIterator* select_itr = jsonNewIterator( selclass );
while ( (selfield = jsonIteratorNext( select_itr )) ) { // for each SELECT column
+ // If we need a separator comma, add one
+ if (first) {
+ first = 0;
+ } else {
+ OSRF_BUFFER_ADD_CHAR( select_buf, ',' );
+ }
+
// ... if it's a string, just toss it on the pile
if (selfield->type == JSON_STRING) {
@@ -2483,12 +2491,6 @@
const char* col_name = osrfHashGet(field, "name");
- if (first) {
- first = 0;
- } else {
- OSRF_BUFFER_ADD_CHAR( select_buf, ',' );
- }
-
if (locale) {
const char* i18n;
if (flags & DISABLE_I18N)
@@ -2516,33 +2518,31 @@
osrfHash* field = osrfHashGet( class_field_set, _column );
if (!field) continue; // No such field defined in IDL. Skip it.
- const char* fname = osrfHashGet(field, "name");
-
- if (first) {
- first = 0;
- } else {
- OSRF_BUFFER_ADD_CHAR( select_buf, ',' );
+ // Decide what to use as a column alias
+ char* _alias;
+ if ((tmp_const = jsonObjectGetKeyConst( selfield, "alias" ))) {
+ _alias = jsonObjectToSimpleString( tmp_const );
+ free(_column);
+ } else { // Use column name as its own alias
+ _alias = _column;
}
+ _column = NULL; // To emphasize that we're through with _column
- char* _alias;
- if ((tmp_const = jsonObjectGetKeyConst( selfield, "alias" ))) {
- _alias = jsonObjectToSimpleString( tmp_const );
- } else {
- _alias = strdup(_column);
- }
+ if (jsonObjectGetKeyConst( selfield, "transform" )) {
+ char* transform_str = searchFieldTransform(cname, field, selfield);
+ buffer_fadd(select_buf, " %s AS \"%s\"", transform_str, _alias);
+ free(transform_str);
+ } else {
- if (jsonObjectGetKeyConst( selfield, "transform" )) {
- free(_column);
- _column = searchFieldTransform(cname, field, selfield);
- buffer_fadd(select_buf, " %s AS \"%s\"", _column, _alias);
- } else {
+ const char* fname = osrfHashGet(field, "name");
+
if (locale) {
const char* i18n;
if (flags & DISABLE_I18N)
i18n = NULL;
else
i18n = osrfHashGet(field, "i18n");
-
+
if ( i18n && !strncasecmp("true", i18n, 4)) {
buffer_fadd( select_buf,
" oils_i18n_xlate('%s', '%s', '%s', '%s', \"%s\".%s::TEXT, '%s') AS \"%s\"",
@@ -2555,9 +2555,7 @@
}
}
- if (_alias) free(_alias);
- if (_column) free(_column);
-
+ free(_alias);
}
if (is_agg->size || (flags & SELECT_DISTINCT)) {
More information about the open-ils-commits
mailing list