Parcourir la source

- move new_result and free_columns function to db directory
- remove the implementation of this functions in all database modules
- still missing
- postgresql and db_berkeley implement different, more thouroughly
free methods for colums and such
- review if we can use the common functions like the other three modules


git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@2871 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt il y a 18 ans
Parent
commit
676afffc5b
5 fichiers modifiés avec 104 ajouts et 1 suppressions
  1. 42 0
      lib/srdb1/db_col.c
  2. 36 0
      lib/srdb1/db_col.h
  3. 21 0
      lib/srdb1/db_res.c
  4. 5 0
      lib/srdb1/db_res.h
  5. 0 1
      lib/srdb1/db_ut.c

+ 42 - 0
lib/srdb1/db_col.c

@@ -0,0 +1,42 @@
+/* 
+ * $Id$ 
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ * Copyright (C) 2007 1und1 Internet AG
+ *
+ * This file is part of openser, a free SIP server.
+ *
+ * openser is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * openser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "db_col.h"
+
+#include "../dprint.h"
+#include "../mem/mem.h"
+
+/*
+ * Release memory used by columns
+ */
+inline int db_free_columns(db_res_t* _r)
+{
+	if (!_r) {
+		LM_ERR("invalid parameter\n");
+		return -1;
+	}
+
+	if (RES_NAMES(_r)) pkg_free(RES_NAMES(_r));
+	if (RES_TYPES(_r)) pkg_free(RES_TYPES(_r));
+	return 0;
+}

+ 36 - 0
lib/srdb1/db_col.h

@@ -0,0 +1,36 @@
+/* 
+ * $Id$ 
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ *
+ * This file is part of openser, a free SIP server.
+ *
+ * openser is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * openser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#ifndef DB_COL_H
+#define DB_COL_H
+
+
+#include "db_res.h"
+
+
+/*
+ * Release memory used by columns
+ */
+int db_free_columns(db_res_t* _r);
+
+#endif /* DB_COL_H */

+ 21 - 0
lib/srdb1/db_res.c

@@ -27,6 +27,8 @@
 #include "../dprint.h"
 #include "../mem/mem.h"
 
+#include <string.h>
+
 /*
  * Release memory used by rows
  */
@@ -44,6 +46,8 @@ inline int db_free_rows(db_res_t* _r)
 		LM_DBG("row[%d]=%p\n", i, &(RES_ROWS(_r)[i]));
 		db_free_row(&(RES_ROWS(_r)[i]));
 	}
+	RES_ROW_N(_r) = 0;
+
 	if (RES_ROWS(_r)) {
 		LM_DBG("%p=pkg_free() RES_ROWS\n", RES_ROWS(_r));
 		pkg_free(RES_ROWS(_r));
@@ -51,3 +55,20 @@ inline int db_free_rows(db_res_t* _r)
 	}
 	return 0;
 }
+
+
+/*
+ * Create a new result structure and initialize it
+ */
+inline db_res_t* db_new_result(void)
+{
+	db_res_t* r = NULL;
+	r = (db_res_t*)pkg_malloc(sizeof(db_res_t));
+	//LM_DBG("%p=pkg_malloc(%lu) _res\n", _r, (unsigned long)sizeof(db_res_t));
+	if (!r) {
+		LM_ERR("no private memory left\n");
+		return 0;
+	}
+	memset(r, 0, sizeof(db_res_t));
+	return r;
+}

+ 5 - 0
lib/srdb1/db_res.h

@@ -56,4 +56,9 @@ typedef struct db_res {
  */
 int db_free_rows(db_res_t* _r);
 
+/*
+ * Create a new result structure and initialize it
+ */
+inline db_res_t* db_new_result(void);
+
 #endif /* DB_RES_H */

+ 0 - 1
lib/srdb1/db_ut.c

@@ -245,7 +245,6 @@ int db_print_values(db_con_t* _c, char* _b, int _l, db_val_t* _v, int _n,
 }
 
 
-
 /*
  * Print where clause of SQL statement
  */