From 500aab72f6c08d1f7de1c992f6b71649446c8258 Mon Sep 17 00:00:00 2001 From: scottmk Date: Mon, 28 Jun 2010 15:43:28 +0000 Subject: [PATCH] Support function calls with subfields, e.g. (func(args))."id". Note that this support treats the subfield as an optional component of the functional call, not as a type of expression in its own right. A subsequent commit will eliminate the "xfld" expression type. M Open-ILS/include/openils/oils_buildq.h M Open-ILS/src/c-apps/oils_storedq.c M Open-ILS/src/c-apps/buildSQL.c git-svn-id: svn://svn.open-ils.org/ILS/trunk@16821 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/include/openils/oils_buildq.h | 3 +-- Open-ILS/src/c-apps/buildSQL.c | 19 ++++++++++++------- Open-ILS/src/c-apps/oils_storedq.c | 2 -- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Open-ILS/include/openils/oils_buildq.h b/Open-ILS/include/openils/oils_buildq.h index 1c20ff8621..8f1a3cc44d 100644 --- a/Open-ILS/include/openils/oils_buildq.h +++ b/Open-ILS/include/openils/oils_buildq.h @@ -173,7 +173,6 @@ typedef enum { EXP_CAST, EXP_COLUMN, EXP_EXIST, - EXP_FIELD, EXP_FUNCTION, EXP_IN, EXP_ISNULL, @@ -196,7 +195,7 @@ struct Expression_ { char* table_alias; char* column_name; Expression* left_operand; - char* op; + char* op; // Not called "operator" because that's a keyword in C++ Expression* right_operand; int subquery_id; StoredQ* subquery; diff --git a/Open-ILS/src/c-apps/buildSQL.c b/Open-ILS/src/c-apps/buildSQL.c index 38f97ef990..ab9da2255e 100644 --- a/Open-ILS/src/c-apps/buildSQL.c +++ b/Open-ILS/src/c-apps/buildSQL.c @@ -728,13 +728,6 @@ static void buildExpression( BuildSQLState* state, const Expression* expr ) { buffer_add_char( state->sql, ')' ); } break; - case EXP_FIELD : - if( expr->negate ) - buffer_add( state->sql, "NOT " ); - - sqlAddMsg( state, "Field expressions not yet supported" ); - state->error = 1; - break; case EXP_FUNCTION : buildFunction( state, expr ); break; @@ -956,6 +949,11 @@ static void buildFunction( BuildSQLState* state, const Expression* expr ) { if( expr->negate ) buffer_add( state->sql, "NOT " ); + // If a subfield is specified, the function call + // needs an extra layer of parentheses + if( expr->column_name ) + buffer_add_char( state->sql, '(' ); + // We rely on the input side to ensure that the function name is available buffer_add( state->sql, expr->function_name ); buffer_add_char( state->sql, '(' ); @@ -964,6 +962,13 @@ static void buildFunction( BuildSQLState* state, const Expression* expr ) { buildSeries( state, expr->subexp_list, NULL ); buffer_add_char( state->sql, ')' ); + + if( expr->column_name ) { + // Add the name of the subfield + buffer_add( state->sql, ").\"" ); + buffer_add( state->sql, expr->column_name ); + buffer_add_char( state->sql, '\"' ); + } } /** diff --git a/Open-ILS/src/c-apps/oils_storedq.c b/Open-ILS/src/c-apps/oils_storedq.c index f5b61f9d5d..5ff77649dc 100644 --- a/Open-ILS/src/c-apps/oils_storedq.c +++ b/Open-ILS/src/c-apps/oils_storedq.c @@ -1540,8 +1540,6 @@ static Expression* constructExpression( BuildSQLState* state, dbi_result result type = EXP_COLUMN; else if( !strcmp( type_str, "xex" )) type = EXP_EXIST; - else if( !strcmp( type_str, "xfld" )) - type = EXP_FIELD; else if( !strcmp( type_str, "xfunc" )) type = EXP_FUNCTION; else if( !strcmp( type_str, "xin" )) -- 2.43.2