* Add new MySQL types

Fri, 21 May 2010 23:00:13 +0000

author
nrich@ii.net
date
Fri, 21 May 2010 23:00:13 +0000
changeset 36
942bfe1843bc
parent 35
72946c7c68da
child 37
b6b07eecac0a

* Add new MySQL types
* Fix memory leak in the MySQL handler
* Add new 'Drivers' method to the DBI class

DBI.lua file | annotate | diff | comparison | revisions
dbd/mysql/statement.c file | annotate | diff | comparison | revisions
--- a/DBI.lua	Fri Sep 18 12:54:32 2009 +0000
+++ b/DBI.lua	Fri May 21 23:00:13 2010 +0000
@@ -28,10 +28,10 @@
 
     -- no drivers available
     if table.maxn(available) < 1 then
-	return '(None)'
+	available = {'(None)'}
     end
 
-    return table.concat(available, ',')
+    return available
 end
 
  -- High level DB connection function
@@ -40,14 +40,16 @@
     local modulefile = name_to_module[driver]
 
     if not modulefile then
-	error(string.format("Driver '%s' not found. Available drivers are: %s", driver, available_drivers()))
+        local available = table.concat(available_drivers(), ',')
+	error(string.format("Driver '%s' not found. Available drivers are: %s", driver, available))
     end
 
     local m, err = pcall(require, modulefile)
 
     if not m then
 	-- cannot load the module, we cannot continue
-	error(string.format('Cannot load driver %s. Available drivers are: %s', driver, available_drivers()))
+        local available = table.concat(available_drivers(), ',')
+	error(string.format('Cannot load driver %s. Available drivers are: %s', driver, available))
     end
 
     local class_str = string.format('DBD.%s.Connection', driver)
@@ -75,3 +77,8 @@
 
     return sth:affected()
 end
+
+-- Lit drivers available on this system
+function Drivers()
+    return available_drivers() 
+end
--- a/dbd/mysql/statement.c	Fri Sep 18 12:54:32 2009 +0000
+++ b/dbd/mysql/statement.c	Fri May 21 23:00:13 2010 +0000
@@ -33,11 +33,11 @@
     
     switch (mysql_type) {
 	case MYSQL_TYPE_TINY:
-	    size = 4;
+	    size = 1;
 	    break;
 	case MYSQL_TYPE_YEAR:
 	case MYSQL_TYPE_SHORT:
-	    size = 4;
+	    size = 2;
 	    break;
 	case MYSQL_TYPE_INT24:
 	    size = 4;
@@ -151,6 +151,14 @@
 
     int p;
 
+    if (statement->metadata) {
+	/*
+	 * free existing metadata from any previous executions
+         */
+	mysql_free_result(statement->metadata);
+	statement->metadata = NULL;
+    }
+
     if (!statement->stmt) {
 	lua_pushboolean(L, 0);
 	lua_pushstring(L, DBI_ERR_EXECUTE_INVALID);
@@ -333,10 +341,24 @@
 			LUA_PUSH_ARRAY_NIL(d);
 		    }
 		} else if (lua_push == LUA_PUSH_INTEGER) {
-		    if (named_columns) {
-			LUA_PUSH_ATTRIB_INT(name, *(int *)(bind[i].buffer)); 
+		    if (fields[i].type == MYSQL_TYPE_YEAR || fields[i].type == MYSQL_TYPE_SHORT) {
+			if (named_columns) {
+			    LUA_PUSH_ATTRIB_INT(name, *(short *)(bind[i].buffer)); 
+			} else {
+			    LUA_PUSH_ARRAY_INT(d, *(short *)(bind[i].buffer)); 
+			}
+		    } else if (fields[i].type == MYSQL_TYPE_TINY) {
+			if (named_columns) {
+			    LUA_PUSH_ATTRIB_INT(name, (int)*(char *)(bind[i].buffer)); 
+			} else {
+			    LUA_PUSH_ARRAY_INT(d, (int)*(char *)(bind[i].buffer)); 
+			}
 		    } else {
-			LUA_PUSH_ARRAY_INT(d, *(int *)(bind[i].buffer)); 
+			if (named_columns) {
+			    LUA_PUSH_ATTRIB_INT(name, *(int *)(bind[i].buffer)); 
+			} else {
+			    LUA_PUSH_ARRAY_INT(d, *(int *)(bind[i].buffer)); 
+			}
 		    }
 		} else if (lua_push == LUA_PUSH_NUMBER) {
 		    if (named_columns) {

mercurial