Expression* compileStartTuple( Tokenizer& tokenizer ) { Expression * expr = NULL; std::vector<Expression*> params; std::stack<Expression*> stack; std::cout << "---" << std::endl; while ( tokenizer.parseForNextToken() ) { std::cout << "@ " << toString( tokenizer.getLastTokenType() ) << ": " << tokenizer.getLastToken() << std::endl; // // What is this element? If this is the start of an expression // if ( tokenizer.getLastTokenType() == TOK_OPEN ) { std::cout << "^^^" << std::endl; params.push_back( compileStartTuple(tokenizer) ); std::cout << "vvv" << std::endl; } else if ( tokenizer.getLastTokenType() == TOK_CLOSE ) { break; } else if ( tokenizer.getLastTokenType() == TOK_IDENT ) { params.push_back( new ValueExpression( Value( tokenizer.getLastToken() ) ) ); } else if ( tokenizer.getLastTokenType() == TOK_NUMERIC ) { params.push_back( new ValueExpression( Value( atof( tokenizer.getLastToken().c_str() ) ) ) ); } } expr = constructExpression( params ); assert( expr != NULL ); return expr; }
static Expression* getExpression( BuildSQLState* state, int id ) { // Check the stack to see if the current expression is nested inside itself. If it is, // then abort in order to avoid infinite recursion. If it isn't, then add it to the // stack. (Make sure to pop it off the stack before returning.) if( searchIdStack( state->expr_stack, id, NULL )) { osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state, "Infinite recursion detected; expression # %d is nested within itself", id )); state->error = 1; return NULL; } else push_id( &state->expr_stack, id, NULL ); Expression* exp = NULL; dbi_result result = dbi_conn_queryf( state->dbhandle, "SELECT id, type, parenthesize, parent_expr, seq_no, literal, table_alias, " "column_name, left_operand, operator, right_operand, function_id, subquery, cast_type " "FROM query.expression WHERE id = %d;", id ); if( result ) { if( dbi_result_first_row( result ) ) { exp = constructExpression( state, result ); if( exp ) { PRINT( "Got an expression\n" ); PRINT( "\tid = %d\n", exp->id ); PRINT( "\ttype = %d\n", exp->type ); PRINT( "\tparenthesize = %d\n", exp->parenthesize ); PRINT( "\tcolumn_name = %s\n", exp->column_name ? exp->column_name : "(none)" ); } else osrfLogError( OSRF_LOG_MARK, sqlAddMsg( state, "Unable to construct an Expression for id = %d", id )); } } else { const char* msg; int errnum = dbi_conn_error( state->dbhandle, &msg ); osrfLogError( OSRF_LOG_MARK, sqlAddMsg( state, "Unable to query query.expression table: #%d %s", errnum, msg ? msg : "No description available" )); } pop_id( &state->expr_stack ); return exp; }