luasql-master的修改,支持调用存储过程
来源:互联网 发布:sms水动力学软件 编辑:程序博客网 时间:2024/05/17 23:27
针对luasql库不支持执行存储过程,需要针对C的代码进行修改
文件名: ls_mysql.c
/*
** Connects to a data source.
** param: one string for each connection parameter, said
** datasource, username, password, host and port.
*/
static int env_connect (lua_State *L) {
const char *sourcename = luaL_checkstring(L, 2);
const char *username = luaL_optstring(L, 3, NULL);
const char *password = luaL_optstring(L, 4, NULL);
const char *host = luaL_optstring(L, 5, NULL);
const int port = luaL_optint(L, 6, 0);
MYSQL *conn;
/* ==================== begin =================
** xxxxx
** 添加连接数据库的flag参数
** 用于扩充调用mysql的存储过程.
** 参数可选
*/
size_t client_flag = 0 ;
if(lua_gettop(L) == 7)
{
client_flag = (size_t)luaL_checknumber(L, 7);
}
getenvironment(L); /* validade environment */
/* Try to init the connection object. */
conn = mysql_init(NULL);
if (conn == NULL)
return luasql_faildirect(L, "error connecting: Out of memory.");
if (!mysql_real_connect(conn, host, username, password,
sourcename, port, NULL, client_flag))
{
char error_msg[100];
strncpy (error_msg, mysql_error(conn), 99);
mysql_close (conn); /* Close conn if connect failed */
return luasql_failmsg (L, "error connecting to database. MySQL: ", error_msg);
}
return create_connection(L, 1, conn);
}
默认情况下client_flag直接固定为0, 需要把参数开放出来给lua层,可选参数,默认为0
针对需要执行存储过程,则需要添加 CLIENT_MULTI_STATEMENTS 参数.
针对C的定义如下:
mysql/mysql_com.h:#defineCLIENT_MULTI_STATEMENTS (1UL << 16) /* Enable/disable multi-stmt support */
http://dev.mysql.com/doc/refman/5.0/en/mysql-real-connect.html
Flag Name Flag Description
CLIENT_COMPRESS
Use compression protocol.(使用压缩协议。)CLIENT_FOUND_ROWS
Return the number of found (matched) rows, not the number of changed rows.(返回找到(匹配)的行数,而不是改变了的行数。)CLIENT_IGNORE_SIGPIPE
Prevents the client library from installing a SIGPIPE
signal handler. This can be used to avoid conflicts with a handler that the application has already installed.(阻止客户端库安装一个SIGPIPE信号处理器。这个可以用于当应用程序已经安装该处理器的时候避免与其发生冲突。)CLIENT_IGNORE_SPACE
Allow spaces after function names. Makes all functions names reserved words.(允许在函数名后使用空格。所有函数名可以预留字。)CLIENT_INTERACTIVE
Allow interactive_timeout
seconds (instead of wait_timeout
seconds) of inactivity before closing the connection. The client's session wait_timeout
variable is set to the value of the session interactive_timeout
variable.(允许使用关闭连接之前的不活动交互超时的描述,而不是等待超时秒数。客户端的会话等待超时变量变为交互超时变量。)CLIENT_LOCAL_FILES
Enable LOAD DATA LOCAL
handling.CLIENT_MULTI_RESULTS
Tell the server that the client can handle multiple result sets from multiple-statement executions or stored procedures. This flag is automatically enabled ifCLIENT_MULTI_STATEMENTS
is enabled. See the note following this table for more information about this flag.(通知服务器客户端可以处理由多语句或者存储过程执行生成的多结果集。当打开CLIENT_MULTI_STATEMENTS时,
这个标志自动的被打开。可以在本表后查看更多关于该标志位的信息。)CLIENT_MULTI_STATEMENTS
Tell the server that the client may send multiple statements in a single string (separated by “;
”). If this flag is not set, multiple-statement execution is disabled. See the note following this table for more information about this flag.(通知服务器客户端可以发送多条语句(由分号分隔)。如果该标志为没有被设置,多条语句执行。)CLIENT_NO_SCHEMA
Don't allow the db_name.tbl_name.col_name
syntax. This is for ODBC. It causes the parser to generate an error if you use that syntax, which is useful for trapping bugs in some ODBC programs.(不允许“数据库名.表名.列名”这样的语法。这是对于ODBC的设置。当使用这样的语法时解析器会产生一个错误,这对于一些ODBC的程序限制bug来说是有用的。)CLIENT_ODBC
Unused.(不使用)CLIENT_SSL
Use SSL (encrypted protocol). This option should not be set by application programs; it is set internally in the client library. Instead, use mysql_ssl_set()
before callingmysql_real_connect()
.(使用SSL。这个设置不应该被应用程序设置,他应该是在客户端库内部是设置的。可以在调用mysql_real_connect()之前调用mysql_ssl_set()来代替设置。)CLIENT_REMEMBER_OPTIONS
Remember options specified by calls to mysql_options()
. Without this option, ifmysql_real_connect()
fails, you must repeat the mysql_options()
calls before trying to connect again. With this option, the mysql_options()
calls need not be repeated.(记住通过调用mysql_options()生成的设置。如果不使用这个设置,当mysql_real_connect失败时,再重新连接之前必须反复调用mysql_options()。当然,如果使用这个设置,就不必反复调用了。)CLIENT_MULTI_STATEMENTS
的说明:If you enable
CLIENT_MULTI_STATEMENTS
or CLIENT_MULTI_RESULTS
, you should process the result for every call to mysql_query()
or mysql_real_query()
by using a loop that calls mysql_next_result()
to determine whether there are more results. For an example, see Section 如果打开了
CLIENT_MULTI_STATEMENTS或
CLIENT_MULTI_RESULTS,你必须对每一个mysql_query()或者mysql_real_query()的调用结果通过一个循环来处理,在这个循环中,调用mysql_next_result()来决定(发现)是否有更多的结果,如
Section - luasql-master的修改,支持调用存储过程
- 调用存储过程进行图片的插入或修改
- 存储过程的调用
- 存储过程的调用
- 存储过程的调用
- 存储过程的调用!
- 存储过程的调用
- 存储过程的调用
- 存储过程的调用
- 存储过程的调用
- 存储过程的调用
- 存储过程第一讲:存储过程的创建,删除,修改,调用,查看
- 修改密码的存储过程
- 修改内容的存储过程
- 修改后的SQL分页存储过程,利用2分法,支持排序
- KeelKit 开始支持 VC++的 实体类生成 和 存储过程调用接口的生成
- 我调用的存储过程
- 存储过程的互相调用
- 【Android UI设计与开发】第04期:引导界面(四)仿人人网V5.9.2最新版引导界面
- WebService注解汇总
- 程序员面试金典1.7:若M*N矩阵中某个元素为0,则将其所在的行与列清零
- 类加载器
- C#中的多态
- luasql-master的修改,支持调用存储过程
- http 原生post 请求
- 类和对象
- 在 Activity 之间传递参数————传递值对象
- 状态机的原理简析及重要用途
- 百度地图获取当前位置坐标,并计算距离
- C#中sealed关键字
- 数据结构基础笔记(一)【严蔚敏】
- noip2003 栈 (卡特兰数)