Support IS NULL and IS NOT NULL expressions.
[working/Evergreen.git] / Open-ILS / include / openils / oils_buildq.h
index 718f38a..42ea5f1 100644 (file)
@@ -21,6 +21,9 @@ typedef struct FromRelation_ FromRelation;
 struct SelectItem_;
 typedef struct SelectItem_ SelectItem;
 
+struct BindVar_;
+typedef struct BindVar_ BindVar;
+
 struct Expression_;
 typedef struct Expression_ Expression;
 
@@ -50,10 +53,15 @@ struct BuildSQLState_ {
        int error;                    /**< Boolean; true if an error has occurred */
        osrfStringArray* error_msgs;  /**< Descriptions of errors, if any */
        growing_buffer* sql;          /**< To hold the constructed query */
+       osrfHash* bindvar_list;       /**< List of bind variables used by this query, each with
+                                          a pointer to the corresponding BindVar. */
        IdNode* query_stack;          /**< For avoiding infinite recursion of nested queries */
        IdNode* expr_stack;           /**< For avoiding infinite recursion of nested expressions */
        IdNode* from_stack;           /**< For avoiding infinite recursion of from clauses */
        int indent;                   /**< For prettifying SQL output: level of indentation */
+       int defaults_usable;          /**< Boolean; if true, we can use unconfirmed default
+                                          values for bind variables */
+       int values_required;          /**< Boolean: if true, we need values for a bind variables */
 };
 
 typedef enum {
@@ -73,6 +81,7 @@ struct StoredQ_ {
        Expression*   where_clause;
        SelectItem*   select_list;
        QSeq*         child_list;
+       Expression*   having_clause;
        OrderItem*    order_by_list;
 };
 
@@ -118,7 +127,25 @@ struct SelectItem_ {
 };
 
 typedef enum {
+       BIND_STR,
+       BIND_NUM,
+       BIND_STR_LIST,
+       BIND_NUM_LIST
+} BindVarType;
+
+struct BindVar_ {
+       BindVar*    next;
+       char*       name;
+       char*       label;
+       BindVarType type;
+       char*       description;
+       jsonObject* default_value;
+       jsonObject* actual_value;
+};
+
+typedef enum {
        EXP_BETWEEN,
+       EXP_BIND,
        EXP_BOOL,
        EXP_CASE,
        EXP_CAST,
@@ -127,9 +154,7 @@ typedef enum {
        EXP_FIELD,
        EXP_FUNCTION,
        EXP_IN,
-       EXP_NOT_BETWEEN,
-       EXP_NOT_EXIST,
-       EXP_NOT_IN,
+       EXP_ISNULL,
        EXP_NULL,
        EXP_NUMBER,
        EXP_OPERATOR,
@@ -154,6 +179,8 @@ struct Expression_ {
        int         subquery_id;
        StoredQ*    subquery;
        int         cast_type_id;
+       int         negate;             // Boolean
+       BindVar*    bind;
 };
 
 struct QSeq_ {
@@ -182,6 +209,8 @@ const char* sqlAddMsg( BuildSQLState* state, const char* msg, ... );
 
 StoredQ* getStoredQuery( BuildSQLState* state, int query_id );
 
+jsonObject* oilsGetColNames( BuildSQLState* state, StoredQ* query );
+
 void pop_id( IdNode** stack );
 
 void storedQFree( StoredQ* sq );
@@ -192,12 +221,14 @@ int buildSQL( BuildSQLState* state, StoredQ* query );
 
 void oilsStoredQSetVerbose( void );
 
-jsonObject* oilsExecSql( BuildSQLState* state );
-
 jsonObject* oilsFirstRow( BuildSQLState* state );
 
 jsonObject* oilsNextRow( BuildSQLState* state );
 
+jsonObject* oilsBindVarList( osrfHash* bindvar_list );
+
+int oilsApplyBindValues( BuildSQLState* state, jsonObject* bindings );
+
 #ifdef __cplusplus
 }
 #endif