3 @brief Header for routines for building database queries.
14 typedef struct StoredQ_ StoredQ;
17 typedef struct FromRelation_ FromRelation;
20 typedef struct SelectItem_ SelectItem;
23 typedef struct Expression_ Expression;
26 typedef struct QSeq_ QSeq;
29 typedef struct OrderItem_ OrderItem;
31 struct BuildSQLState_;
32 typedef struct BuildSQLState_ BuildSQLState;
35 typedef struct IdNode_ IdNode;
38 @brief Stores various things related to the construction of an SQL query.
40 This struct carries around various bits and scraps of context for constructing an SQL
41 query. It also provides a way for buildSQLQuery() to return more than one kind of thing
42 to its caller. In particular it can return a status code, a list of error messages, and
43 (if there is no error) an SQL string.
45 struct BuildSQLState_ {
46 dbi_conn dbhandle; /**< Handle for the database connection */
47 int error; /**< Boolean; true if an error has occurred */
48 osrfStringArray* error_msgs; /**< Descriptions of errors, if any */
49 growing_buffer* sql; /**< To hold the constructed query */
50 IdNode* query_stack; /**< For avoiding infinite recursion of nested queries */
51 IdNode* expr_stack; /**< For avoiding infinite recursion of nested expressions */
52 IdNode* from_stack; /**< For avoiding infinite recursion of from clauses */
53 int indent; /**< For prettifying output: level of indentation */
67 int use_all; /**< Boolean */
68 int use_distinct; /**< Boolean */
69 FromRelation* from_clause;
70 Expression* where_clause;
71 SelectItem* select_list;
73 OrderItem* order_by_list;
90 struct FromRelation_ {
93 FromRelationType type;
100 int parent_relation_id;
103 Expression* on_clause;
104 FromRelation* join_list;
112 Expression* expression;
114 int grouped_by; // Boolean
141 int parenthesize; // Boolean
147 Expression* left_operand;
149 Expression* right_operand;
161 StoredQ* child_query;
169 Expression* expression;
172 BuildSQLState* buildSQLStateNew( dbi_conn dbhandle );
174 void buildSQLStateFree( BuildSQLState* state );
176 void buildSQLCleanup( void );
178 const char* sqlAddMsg( BuildSQLState* state, const char* msg, ... );
180 StoredQ* getStoredQuery( BuildSQLState* state, int query_id );
182 void pop_id( IdNode** stack );
184 void storedQFree( StoredQ* sq );
186 void storedQCleanup( void );
188 int buildSQL( BuildSQLState* state, StoredQ* query );
190 void oilsStoredQSetVerbose( void );