Browse Source

Fixes and a bit of extended functionality.

mingodad 10 years ago
parent
commit
af97bca3e2
1 changed files with 15 additions and 12 deletions
  1. 15 12
      SquiLu-ext/sq_mysql.cpp

+ 15 - 12
SquiLu-ext/sq_mysql.cpp

@@ -6,6 +6,7 @@
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
 #include "sqstdblobimpl.h"
 #include "sqstdblobimpl.h"
+SQ_OPT_STRING_STRLEN();
 
 
 #include "dynamic_library.h"
 #include "dynamic_library.h"
 
 
@@ -231,11 +232,11 @@ static SQRESULT get_mysql_instance(HSQUIRRELVM v, SQInteger idx, MYSQL **self){
 	return _rc_;
 	return _rc_;
 }
 }
 
 
-#define GET_mysql_INSTANCE_AT(idx) \
-	MYSQL *self=NULL; \
+#define GET_mysql_INSTANCE_AT(idx) \
+	MYSQL *self=NULL; \
 	if((_rc_ = get_mysql_instance(v,idx,&self)) < 0) return _rc_;
 	if((_rc_ = get_mysql_instance(v,idx,&self)) < 0) return _rc_;
 
 
-#define GET_mysql_INSTANCE() GET_mysql_INSTANCE_AT(1)
+#define GET_mysql_INSTANCE() GET_mysql_INSTANCE_AT(1)
 
 
 static const SQChar *MySQL_Result_TAG = _SC("MySQL_Result");
 static const SQChar *MySQL_Result_TAG = _SC("MySQL_Result");
 static const SQChar *_curr_row_key = _SC("_curr_row");
 static const SQChar *_curr_row_key = _SC("_curr_row");
@@ -247,11 +248,11 @@ static SQRESULT get_mysql_result_instance(HSQUIRRELVM v, SQInteger idx, MYSQL_RE
 	return _rc_;
 	return _rc_;
 }
 }
 
 
-#define GET_mysql_result_INSTANCE_AT(idx) \
-	MYSQL_RES *self=NULL; \
+#define GET_mysql_result_INSTANCE_AT(idx) \
+	MYSQL_RES *self=NULL; \
 	if((_rc_ = get_mysql_result_instance(v,idx,&self)) < 0) return _rc_;
 	if((_rc_ = get_mysql_result_instance(v,idx,&self)) < 0) return _rc_;
 
 
-#define GET_mysql_result_INSTANCE() GET_mysql_result_INSTANCE_AT(1)
+#define GET_mysql_result_INSTANCE() GET_mysql_result_INSTANCE_AT(1)
 
 
 static SQRESULT sq_mysql_result_releasehook(SQUserPointer p, SQInteger size, HSQUIRRELVM v)
 static SQRESULT sq_mysql_result_releasehook(SQUserPointer p, SQInteger size, HSQUIRRELVM v)
 {
 {
@@ -452,11 +453,11 @@ static SQRESULT get_mysql_statement_instance(HSQUIRRELVM v, SQInteger idx, MYSQL
 	return _rc_;
 	return _rc_;
 }
 }
 
 
-#define GET_mysql_statement_INSTANCE_AT(idx) \
-	MYSQL_STMT *self=NULL; \
+#define GET_mysql_statement_INSTANCE_AT(idx) \
+	MYSQL_STMT *self=NULL; \
 	if((_rc_ = get_mysql_statement_instance(v,idx,&self)) < 0) return _rc_;
 	if((_rc_ = get_mysql_statement_instance(v,idx,&self)) < 0) return _rc_;
 
 
-#define GET_mysql_statement_INSTANCE() GET_mysql_statement_INSTANCE_AT(1)
+#define GET_mysql_statement_INSTANCE() GET_mysql_statement_INSTANCE_AT(1)
 
 
 static SQRESULT sq_mysql_statement_releasehook(SQUserPointer p, SQInteger size, HSQUIRRELVM v)
 static SQRESULT sq_mysql_statement_releasehook(SQUserPointer p, SQInteger size, HSQUIRRELVM v)
 {
 {
@@ -632,13 +633,15 @@ static SQRESULT sq_mysql_constructor(HSQUIRRELVM v)
     SQ_GET_STRING(v, 4, password);
     SQ_GET_STRING(v, 4, password);
     SQ_GET_STRING(v, 5, sourcename);
     SQ_GET_STRING(v, 5, sourcename);
     SQ_OPT_INTEGER(v, 6, port, 3306);
     SQ_OPT_INTEGER(v, 6, port, 3306);
+    SQ_OPT_STRING(v, 7, sockname, NULL);
+    SQ_OPT_INTEGER(v, 8, optflags, 0);
     MYSQL *self=0;
     MYSQL *self=0;
 
 
     if(load_libmysqlclient())
     if(load_libmysqlclient())
     {
     {
         self = dlmysql_init(NULL);
         self = dlmysql_init(NULL);
 		if (!self) return sq_throwerror(v, _SC("error connecting: Out of memory."));
 		if (!self) return sq_throwerror(v, _SC("error connecting: Out of memory."));
-		if (!dlmysql_real_connect(self, host, username, password, sourcename, port, NULL, 0))
+		if (!dlmysql_real_connect(self, host, username, password, sourcename, port, sockname, optflags))
 		{
 		{
 			SQRESULT res = sq_throwerror(v, _SC("error connecting to database. MySQL: %s"), dlmysql_error(self));
 			SQRESULT res = sq_throwerror(v, _SC("error connecting to database. MySQL: %s"), dlmysql_error(self));
 			dlmysql_close (self); /* Close conn if connect failed */
 			dlmysql_close (self); /* Close conn if connect failed */
@@ -790,7 +793,7 @@ static SQRESULT sq_mysql_escape_string(HSQUIRRELVM v){
 	SQ_FUNC_VARS_NO_TOP(v);
 	SQ_FUNC_VARS_NO_TOP(v);
 	GET_mysql_INSTANCE();
 	GET_mysql_INSTANCE();
 	SQ_GET_STRING(v, 2, str);
 	SQ_GET_STRING(v, 2, str);
-	SQInteger to_size = (str_size+1) * sizeof(SQChar);
+	SQInteger to_size = (str_size*2+1) * sizeof(SQChar);
 	SQChar *to = sq_getscratchpad(v, to_size);
 	SQChar *to = sq_getscratchpad(v, to_size);
 	if(to) {
 	if(to) {
 		SQInteger new_size = (SQInteger)dlmysql_real_escape_string(self, to, str, str_size);
 		SQInteger new_size = (SQInteger)dlmysql_real_escape_string(self, to, str, str_size);
@@ -803,7 +806,7 @@ static SQRESULT sq_mysql_escape_string(HSQUIRRELVM v){
 #define _DECL_FUNC(name,nparams,tycheck) {_SC(#name),  sq_mysql_##name,nparams,tycheck}
 #define _DECL_FUNC(name,nparams,tycheck) {_SC(#name),  sq_mysql_##name,nparams,tycheck}
 static SQRegFunction sq_mysql_methods[] =
 static SQRegFunction sq_mysql_methods[] =
 {
 {
-	_DECL_FUNC(constructor,  -5, _SC("xssssi")),
+	_DECL_FUNC(constructor,  -5, _SC("xssssisi")),
 	_DECL_FUNC(close,  1, _SC("x")),
 	_DECL_FUNC(close,  1, _SC("x")),
 	_DECL_FUNC(ping,  1, _SC("x")),
 	_DECL_FUNC(ping,  1, _SC("x")),
 	_DECL_FUNC(exec_dml,  2, _SC("xs")),
 	_DECL_FUNC(exec_dml,  2, _SC("xs")),