瀏覽代碼

lib/srdb1: extented DBv1 with async raw query and async insert

- functions that should be executed in async mode
Daniel-Constantin Mierla 11 年之前
父節點
當前提交
ca92959a87
共有 2 個文件被更改,包括 35 次插入0 次删除
  1. 34 0
      lib/srdb1/db.h
  2. 1 0
      lib/srdb1/db_id.c

+ 34 - 0
lib/srdb1/db.h

@@ -193,6 +193,23 @@ typedef int (*db_fetch_result_f) (const db1_con_t* _h, db1_res_t** _r, const int
 typedef int (*db_raw_query_f) (const db1_con_t* _h, const str* _s, db1_res_t** _r);
 typedef int (*db_raw_query_f) (const db1_con_t* _h, const str* _s, db1_res_t** _r);
 
 
 
 
+/**
+ * \brief Raw SQL query via async framework.
+ *
+ * This function can be used to do database specific queries. Please
+ * use this function only if needed, as this creates portability issues
+ * for the different databases. Also keep in mind that you need to
+ * escape all external data sources that you use. You could use the
+ * escape_common and unescape_common functions in the core for this task.
+ * \see escape_common
+ * \see unescape_common
+ * \param _h structure representing database connection
+ * \param _s the SQL query
+ * \return returns 0 if everything is OK, otherwise returns value < 0
+ */
+typedef int (*db_raw_query_async_f) (const db1_con_t* _h, const str* _s);
+
+
 /**
 /**
  * \brief Free a result allocated by db_query.
  * \brief Free a result allocated by db_query.
  *
  *
@@ -326,6 +343,21 @@ typedef int (*db_insert_update_f) (const db1_con_t* _h, const db_key_t* _k,
 typedef int (*db_insert_delayed_f) (const db1_con_t* _h, const db_key_t* _k,
 typedef int (*db_insert_delayed_f) (const db1_con_t* _h, const db_key_t* _k,
 				const db_val_t* _v, const int _n);
 				const db_val_t* _v, const int _n);
 
 
+/**
+ * \brief Insert a row into the specified table via async framework.
+ *
+ * This function implements INSERT DELAYED SQL directive. It is possible to
+ * insert one or more rows in a table with delay using this function.
+ * \param _h database connection handle
+ * \param _k array of keys (column names)
+ * \param _v array of values for keys specified in _k parameter
+ * \param _n number of keys-value pairs int _k and _v parameters
+ * \return returns 0 if everything is OK, otherwise returns value < 0
+ */
+typedef int (*db_insert_async_f) (const db1_con_t* _h, const db_key_t* _k,
+				const db_val_t* _v, const int _n);
+
+
 
 
 /**
 /**
  * \brief Retrieve the number of affected rows for the last query.
  * \brief Retrieve the number of affected rows for the last query.
@@ -388,11 +420,13 @@ typedef struct db_func {
 	                                            in a table */
 	                                            in a table */
 	db_insert_update_f insert_update; /* Insert into table, update on duplicate key */ 
 	db_insert_update_f insert_update; /* Insert into table, update on duplicate key */ 
 	db_insert_delayed_f insert_delayed;           /* Insert delayed into table */
 	db_insert_delayed_f insert_delayed;           /* Insert delayed into table */
+	db_insert_async_f insert_async;               /* Insert async into table */
 	db_affected_rows_f affected_rows; /* Numer of affected rows for last query */
 	db_affected_rows_f affected_rows; /* Numer of affected rows for last query */
 	db_start_transaction_f start_transaction; /* Start a single transaction consisting of multiple queries */
 	db_start_transaction_f start_transaction; /* Start a single transaction consisting of multiple queries */
 	db_end_transaction_f end_transaction; /* End a transaction */
 	db_end_transaction_f end_transaction; /* End a transaction */
 	db_abort_transaction_f abort_transaction; /* Abort a transaction */
 	db_abort_transaction_f abort_transaction; /* Abort a transaction */
 	db_query_f        query_lock;    /* query a table and lock rows for update */
 	db_query_f        query_lock;    /* query a table and lock rows for update */
+	db_raw_query_async_f    raw_query_async;      /* Raw query - SQL */
 } db_func_t;
 } db_func_t;
 
 
 
 

+ 1 - 0
lib/srdb1/db_id.c

@@ -254,6 +254,7 @@ struct db_id* new_db_id(const str* url, db_pooling_t pooling)
 	if (pooling == DB_POOLING_NONE) ptr->poolid = ++poolid;
 	if (pooling == DB_POOLING_NONE) ptr->poolid = ++poolid;
 	else ptr->poolid = 0;
 	else ptr->poolid = 0;
 	ptr->pid = my_pid();
 	ptr->pid = my_pid();
+	ptr->url.s = (char*)ptr + sizeof(struct db_id);
 	ptr->url.len = url->len;
 	ptr->url.len = url->len;
 	strncpy(ptr->url.s, url->s, url->len);
 	strncpy(ptr->url.s, url->s, url->len);
 	ptr->url.s[url->len] = '\0';
 	ptr->url.s[url->len] = '\0';