Browse Source

lib/srdb1: Add support for affected rows.

affected_rows is the number of rows affected by a query.
Primarily used after UPDATE, INSERT and DELETE queries,
to know how many rows were affected.
Alex Hermann 14 years ago
parent
commit
26f2169a0a
3 changed files with 20 additions and 2 deletions
  1. 7 0
      lib/srdb1/db.c
  2. 11 0
      lib/srdb1/db.h
  3. 2 2
      lib/srdb1/db_cap.h

+ 7 - 0
lib/srdb1/db.c

@@ -139,6 +139,11 @@ int db_check_api(db_func_t* dbf, char *mname)
 	if (dbf->insert_delayed) {
 	if (dbf->insert_delayed) {
 		dbf->cap |= DB_CAP_INSERT_UPDATE;
 		dbf->cap |= DB_CAP_INSERT_UPDATE;
 	}
 	}
+
+	if (dbf->affected_rows) {
+		dbf->cap |= DB_CAP_AFFECTED_ROWS;
+	}
+
 	return 0;
 	return 0;
 error:
 error:
 	return -1;
 	return -1;
@@ -229,6 +234,8 @@ int db_bind_mod(const str* mod, db_func_t* mydbf)
 		dbf.replace = (db_replace_f)find_mod_export(tmp, "db_replace", 2, 0);
 		dbf.replace = (db_replace_f)find_mod_export(tmp, "db_replace", 2, 0);
 		dbf.last_inserted_id= (db_last_inserted_id_f)find_mod_export(tmp,
 		dbf.last_inserted_id= (db_last_inserted_id_f)find_mod_export(tmp,
 			"db_last_inserted_id", 1, 0);
 			"db_last_inserted_id", 1, 0);
+		dbf.affected_rows = (db_affected_rows_f)find_mod_export(tmp,
+			"db_affected_rows", 1, 0);
 		dbf.insert_update = (db_insert_update_f)find_mod_export(tmp,
 		dbf.insert_update = (db_insert_update_f)find_mod_export(tmp,
 			"db_insert_update", 2, 0);
 			"db_insert_update", 2, 0);
 		dbf.insert_delayed = (db_insert_delayed_f)find_mod_export(tmp,
 		dbf.insert_delayed = (db_insert_delayed_f)find_mod_export(tmp,

+ 11 - 0
lib/srdb1/db.h

@@ -296,6 +296,16 @@ 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 Retrieve the number of affected rows for the last query.
+ *
+ * The function returns the rows affected by the last query.
+ * If any other type of query was the last, it returns null.
+ * \param _h structure representing database connection
+ * \return returns the number of rows as integer or returns -1 on error
+ */
+typedef int (*db_affected_rows_f) (const db1_con_t* _h);
+
 
 
 /**
 /**
  * \brief Database module callbacks
  * \brief Database module callbacks
@@ -321,6 +331,7 @@ 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_affected_rows_f affected_rows; /* Numer of affected rows for last query */
 } db_func_t;
 } db_func_t;
 
 
 
 

+ 2 - 2
lib/srdb1/db_cap.h

@@ -48,8 +48,8 @@ typedef enum db_cap {
 	DB_CAP_FETCH   =   1 << 6,  /*!< driver supports fetch result queries                           */
 	DB_CAP_FETCH   =   1 << 6,  /*!< driver supports fetch result queries                           */
 	DB_CAP_LAST_INSERTED_ID = 1 << 7,  /*!< driver can return the ID of the last insert operation   */
 	DB_CAP_LAST_INSERTED_ID = 1 << 7,  /*!< driver can return the ID of the last insert operation   */
 	DB_CAP_INSERT_UPDATE = 1 << 8, /*!< driver can insert data into database & update on duplicate  */
 	DB_CAP_INSERT_UPDATE = 1 << 8, /*!< driver can insert data into database & update on duplicate  */
-	DB_CAP_INSERT_DELAYED = 1 << 9 /*!< driver can do insert delayed                                */
-
+	DB_CAP_INSERT_DELAYED = 1 << 9, /*!< driver can do insert delayed                                */
+	DB_CAP_AFFECTED_ROWS = 1 << 10 /*!< driver can return number of rows affected by the last query  */
 } db_cap_t;
 } db_cap_t;