易语言mysql

来源:互联网 发布:中国程序员数量不够 编辑:程序博客网 时间:2024/04/25 03:35
.版本 2
.支持库 mysql

.程序集 mysql
.程序集变量 mysql_handle, 整数型
.程序集变量 result_handle, 整数型

.子程序 du读字段, 文本型, 公开, 返回字段值
.参数 filename, 文本型
.局部变量 value, 文本型

读字段值 (result_handle, filename, value)
返回 (到文本 (value))

.子程序 lian链接mysql, 整数型, 公开, 链接mysql,内部赋值句柄myslq_handle
.参数 dbhost, 文本型
.参数 dbuser, 文本型
.参数 dbpass, 文本型
.参数 dbname, 文本型
.参数 dbpart, 整数型, 可空
.参数 dbcharset, 文本型, 可空

mysql_handle = 连接MySql (dbhost, dbuser, dbpass, dbname, dbpart)

.如果 (mysql_handle ≠ 0)
    .如果 (dbcharset = “”)
        执行SQL语句 (mysql_handle, “set names utf8”)
    .否则
        执行SQL语句 (mysql_handle, “set names ” + dbcharset)
    .如果结束

.否则
    信息框 (“mysql链接失败”, 0, )
.如果结束

返回 (mysql_handle)


.子程序 zhi执行sql, 整数型, 公开, 执行sql语句,内部赋值resault_handle,返回行数
.参数 sql, 文本型

.如果 (result_handle ≠ 0)
    释放记录集 (result_handle)
.否则

.如果结束

.如果 (执行SQL语句 (mysql_handle, sql))
    result_handle = 取记录集 (mysql_handle)
.否则

.如果结束

返回 (取记录集行数 (result_handle))


.子程序 fen分页查询, 整数型, 公开, 执行查询,内部赋值resault_handle
.参数 tablename, 文本型
.参数 where, 文本型, 可空
.参数 order, 文本型, 可空
.参数 data, 文本型, 可空
.参数 page, 整数型, 可空
.参数 pagesize, 整数型, 可空
.参数 limit, 文本型, 可空

.如果 (result_handle ≠ 0)
    释放记录集 (result_handle)
.否则

.如果结束

.如果 (where ≠ “”)
    where = “ where ” + where
.否则

.如果结束
.如果 (order ≠ “”)
    order = “ order by ” + order
.否则

.如果结束
.如果 (data = “”)
    data = “ * ”
.否则

.如果结束
.如果 (page = 0)
    page = 1
.否则

.如果结束
.如果 (pagesize = 0)
    pagesize = 20
.否则

.如果结束

limit = “ limit ” + 到文本 (page × pagesize) + “,” + 到文本 (pagesize)

.如果 (执行SQL语句 (mysql_handle, “select ” + data + “from” + tablename + where + order + limit))
    result_handle = 取记录集 (mysql_handle)
.否则

.如果结束

返回 (取记录集行数 (result_handle))


.子程序 cha查询, 整数型, 公开, 返回查询结果数
.参数 tablename, 文本型
.参数 field, 文本型, 可空
.参数 value, 文本型, 可空
.参数 order, 文本型, 可空
.参数 data, 文本型, 可空
.参数 limit, 文本型, 可空
.参数 b, 文本型, 可空
.局部变量 arr, 文本型, , "1"
.局部变量 arr2, 文本型, , "1"
.局部变量 n, 整数型
.局部变量 where, 文本型
.局部变量 i, 整数型

.如果 (b = “”)
    b = “,”
.否则

.如果结束

.如果 (field ≠ “”)
    arr = 分割文本 (field, b, )
    arr2 = 分割文本 (value, b, )
    n = 取数组成员数 (arr)
    .如果 (n = 取数组成员数 (arr2))
        where = “ where `” + arr [1] + “`='” + arr2 [1] + “'”
        .计次循环首 (n - 1, i)
            where = where + “ and `” + arr [i + 1] + “`='” + arr2 [i + 1] + “'”
        .计次循环尾 ()


    .否则
        返回 (0)


    .如果结束

.否则

.如果结束


.如果 (order ≠ “”)
    order = “ order by ” + order
.否则

.如果结束
.如果 (data = “”)
    data = “ * ”
.否则


.如果结束
.如果 (limit ≠ “”)
    limit = “ limit ” + limit
.否则

.如果结束

执行SQL语句 (mysql_handle, “select ” + data + “ from ” + tablename + where + order + limit)

result_handle = 取记录集 (mysql_handle)
.如果 (result_handle = 0)
    信息框 (“执行sql命令失败!”, 0, )
    返回 (0)
.否则


.如果结束

返回 (取记录集行数 (result_handle))


.子程序 qu取记录集行数, 整数型, 公开
.参数 rh, 整数型

返回 (取记录集行数 (rh))

.子程序 xia下一条, , 公开, 调到下一条

到下一行 (result_handle)

.子程序 guan关闭mysql, , 公开

断开MySql (mysql_handle)


.子程序 shan删除记录, 逻辑型, 公开
.参数 tablename, 文本型
.参数 filename, 文本型
.参数 filevalue, 文本型

返回 (执行SQL语句 (mysql_handle, “delete from `” + tablename + “` where `” + filename + “` = '” + filevalue + “'”))

.子程序 geng更新记录, 逻辑型, 公开
.参数 tablename, 文本型
.参数 field, 文本型
.参数 data, 文本型
.参数 wherefield, 文本型
.参数 fieldvalue, 文本型
.参数 b, 文本型, 可空
.局部变量 arr, 文本型, , "1"
.局部变量 arr2, 文本型, , "1"
.局部变量 datas, 文本型
.局部变量 i, 整数型
.局部变量 num, 整数型
.局部变量 wherestr, 文本型

datas = “”
.如果 (b = “”)
    b = “,”
.否则

.如果结束
arr = 分割文本 (field, b, )
num = 取数组成员数 (arr)
.如果 (num ≠ 1)
    arr2 = 分割文本 (data, b, )
    .如果 (num ≠ 取数组成员数 (arr2))
        信息框 (“更新记录提交的信息不对称”, 0, )
        信息框 (“field:” + field + “;value:” + fieldvalue, 0, )
        返回 (假)
    .否则
        .计次循环首 (num, i)
            arr [i] = “`” + arr [i] + “`”
            arr2 [i] = “'” + arr2 [i] + “'”
            datas = datas + “,” + arr [i] + “=” + arr2 [i]
        .计次循环尾 ()
        datas = 文本替换 (datas, 1, 1, “”)

    .如果结束

.否则
    datas = “`” + field + “` = ” + “'” + data + “'”
.如果结束


arr = 分割文本 (wherefield, b, )
arr2 = 分割文本 (fieldvalue, b, )
num = 取数组成员数 (arr)
wherestr = “ where 1=1 ”
.如果 (num ≠ 取数组成员数 (arr2))
    信息框 (“条件信息不对称”, 0, )
.否则
    .如果 (num ≠ 1)
        .计次循环首 (num, i)
            arr [i] = “`” + arr [i] + “`”
            arr2 [i] = “'” + arr2 [i] + “'”
            wherestr = wherestr + “ and ” + arr [i] + “=” + arr2 [i]
        .计次循环尾 ()

    .否则
        wherestr = “ where `” + wherefield + “` = '” + fieldvalue + “' ”
    .如果结束

.如果结束

返回 (执行SQL语句 (mysql_handle, “update ” + tablename + “ set ” + datas + wherestr))


.子程序 tian添加记录, 逻辑型, 公开
.参数 tablename, 文本型
.参数 field, 文本型
.参数 data, 文本型
.参数 b, 文本型, 可空
.局部变量 arr, 文本型, , "1"
.局部变量 arr2, 文本型, , "1"
.局部变量 datas, 文本型
.局部变量 i, 整数型
.局部变量 num, 整数型
.局部变量 values, 文本型

.如果 (b = “”)
    b = “,”
.否则

.如果结束
datas = “”
arr = 分割文本 (field, b, )
num = 取数组成员数 (arr)
.如果 (num ≠ 1)
    arr2 = 分割文本 (data, b, )
    .如果 (num ≠ 取数组成员数 (arr2))
        信息框 (“更新记录提交的信息不对称”, 0, )
        返回 (假)
    .否则
        .计次循环首 (num, i)
            arr [i] = “`” + arr [i] + “`”
            arr2 [i] = “'” + arr2 [i] + “'”
            datas = datas + “,” + arr [i] + “=” + arr2 [i]
        .计次循环尾 ()
        datas = 文本替换 (datas, 1, 1, “”)

    .如果结束

.否则
    datas = “`” + field + “` = ” + “'” + data + “'”
.如果结束



返回 (执行SQL语句 (mysql_handle, “insert into ” + tablename + “ set ” + datas))

0 0
原创粉丝点击