src/internal.h
changeset 58 02e539965ef4
parent 45 424ce5ab82fd
parent 56 9dfc861273e5
child 59 54a2e6be81a7
--- a/src/internal.h	Sun Mar 08 01:16:54 2009 +0200
+++ b/src/internal.h	Sun Mar 08 01:33:45 2009 +0200
@@ -97,6 +97,13 @@
 };
 
 /*
+ * Backend result handle
+ */
+union evsql_result_handle {
+    PGresult *pq;
+};
+
+/*
  * A single query.
  *
  * Has the info needed to exec the query (as these may be queued), and the callback/result info.
@@ -106,7 +113,7 @@
     char *command;
     
     // possible query params
-    struct evsql_query_param_info {
+    struct evsql_query_params_pq {
         int count;
 
         Oid *types;
@@ -114,22 +121,39 @@
         int *lengths;
         int *formats;
 
+        // storage for numeric values
+        union evsql_item_value *item_vals;
+
         int result_format;
     } params;
 
     // our callback
     evsql_query_cb cb_fn;
     void *cb_arg;
+        
+    // the result we get
+    union evsql_result_handle result;
 
     // our position in the query list
     TAILQ_ENTRY(evsql_query) entry;
+};
 
-    // the result
-    union {
-        PGresult *evpq;
-    } result;
+// the result
+struct evsql_result {
+    struct evsql *evsql;
+
+    // possible error code
+    int error;
+    
+    // the actual result
+    union evsql_result_handle result;
+
+    // result_* state
+    struct evsql_result_info *info;
+    size_t row_offset;
 };
 
+
 // maximum length for a 'BEGIN TRANSACTION ...' query
 #define EVSQL_QUERY_BEGIN_BUF 512
 
@@ -137,4 +161,32 @@
 // 16 = bool in 8.3
 #define EVSQL_PQ_ARBITRARY_TYPE_OID 16
 
+/*
+ * Core query-submission interface.
+ *
+ * This performs some error-checking on the trans, allocates the evsql_query and does some basic initialization.
+ *
+ * This does not actually enqueue the query anywhere, no reference is stored anywhere.
+ *
+ * Returns the new evsql_query on success, NULL on failure.
+ */
+struct evsql_query *_evsql_query_new (struct evsql *evsql, struct evsql_trans *trans, evsql_query_cb query_fn, void *cb_arg);
+
+/*
+ * Begin processing the given query, which should now be fully filled out.
+ *
+ * If trans is given, it MUST be idle, and the query will be executed. Otherwise, it will either be executed directly
+ * or enqueued for future execution.
+ *
+ * Returns zero on success, nonzero on failure.
+ */
+int _evsql_query_enqueue (struct evsql *evsql, struct evsql_trans *trans, struct evsql_query *query, const char *command);
+
+/*
+ * Free the query and related resources, doesn't trigger any callbacks or remove from any queues.
+ *
+ * The command should already be taken care of (NULL).
+ */
+void _evsql_query_free (struct evsql_query *query);
+
 #endif /* EVSQL_INTERNAL_H */