Support function calls with subfields, e.g. (func(args))."id".
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 28 Jun 2010 15:43:28 +0000 (15:43 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 28 Jun 2010 15:43:28 +0000 (15:43 +0000)
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
Open-ILS/src/c-apps/buildSQL.c
Open-ILS/src/c-apps/oils_storedq.c

index 1c20ff8..8f1a3cc 100644 (file)
@@ -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;
index 38f97ef..ab9da22 100644 (file)
@@ -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, '\"' );
+       }
 }
 
 /**
index f5b61f9..5ff7764 100644 (file)
@@ -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" ))