Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.

Fri, 28 Nov 2008 22:32:14 +0000

author
nrich@ii.net
date
Fri, 28 Nov 2008 22:32:14 +0000
changeset 6
22046b996150
parent 5
e66b88e013ca
child 7
4480ae002881

Fixed bug: double bind params were using the same variables memory space so they were all being set to the same number.

dbd/mysql/statement.c file | annotate | diff | comparison | revisions
--- a/dbd/mysql/statement.c	Wed Nov 26 10:46:42 2008 +0000
+++ b/dbd/mysql/statement.c	Fri Nov 28 22:32:14 2008 +0000
@@ -89,8 +89,7 @@
 
 	const char *str = NULL;
 	size_t str_len;
-
-	double num;
+	double *num = NULL;
 
 	switch(type) {
 	    case LUA_TNIL:
@@ -99,11 +98,16 @@
 		break;
 
 	    case LUA_TNUMBER:
-		num = luaL_checknumber(L, p);
+		/*
+		 * num needs to be it's own 
+		 * memory here
+                 */
+		num = (double *)malloc(sizeof(double));
+		*num = luaL_checknumber(L, p);
 
 		bind[i].buffer_type = MYSQL_TYPE_DOUBLE;
 		bind[i].is_null = (my_bool*)0;
-		bind[i].buffer = (char *)#
+		bind[i].buffer = (char *)num;
 		bind[i].length = 0;
 		break;
 
@@ -135,8 +139,24 @@
     metadata = mysql_stmt_result_metadata(statement->stmt);
 
 cleanup:
-    if (bind)
+    if (bind) {
+	int i;
+
+	for (i = 0; i < num_bind_params; i++) {
+	    /*
+	     * Free the memory associated with
+	     * the allocation of double bind
+	     * params. If the interface is
+	     * extended with other types they
+	     * will need to be added here
+             */
+	    if (bind[i].buffer_type == MYSQL_TYPE_DOUBLE && bind[i].buffer) {
+		free(bind[i].buffer);
+	    }
+	}
+
 	free(bind);
+    }
 
     if (error_message) {
 	lua_pushboolean(L, 0);

mercurial