Changes for page 01 Lua Functions
Last modified by Theodore Xu on 2023/10/26 10:51
From version 12.1
edited by Hunter
on 2023/02/18 15:29
on 2023/02/18 15:29
Change comment:
There is no comment for this version
To version 17.1
edited by Theodore Xu
on 2023/08/24 16:45
on 2023/08/24 16:45
Change comment:
There is no comment for this version
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. Hunter1 +XWiki.AiXia - Content
-
... ... @@ -1,17 +1,5 @@ 1 1 = **1 Interface description** = 2 2 3 -(% style="width:749.222px" %) 4 -|=(% scope="row" style="width: 374px;" %)z|=(% style="width: 373px;" %)cxz 5 -|=(% style="width: 374px;" %) |(% style="width:373px" %) 6 -|=(% style="width: 374px;" %) |(% style="width:373px" %) 7 - 8 -|分类|宽|高 9 -|网页全屏|700-850|400 10 -|手机全屏|300|400 11 -|其他大图片|400左右|400左右 12 -|小图片|200左右|200左右 13 - 14 - 15 15 == **Data type definition** == 16 16 17 17 |=**Type**|=**Description** ... ... @@ -1941,125 +1941,69 @@ 1941 1941 **For example:** 1942 1942 1943 1943 {{code language="LUA"}} 1944 -mysql = require"mysqlclient" 1932 +-- Assuming the "mysqlclient" library is properly installed and available 1933 +mysql = require("mysqlclient") 1945 1945 1946 1946 function DataInitRight() 1947 - 1948 -local dbName = "db_lua1" 1949 - 1950 -local user = "root" 1951 - 1952 -local pwd = "123456" 1953 - 1954 -local host = "192.168.56.186" 1955 - 1956 -local port = 3306 1957 -local character = "UTF8" 1958 - 1959 -mysql.init(dbName, user, pwd, host, port, character) 1960 - 1936 + local dbName = "excel" 1937 + local user = "root" 1938 + local pwd = "XXXXX" 1939 + local host = "192.168.39.146" 1940 + local port = 3306 1941 + local character = "utf8mb3" 1942 + 1943 + mysql.init(dbName, user, pwd, host, port, character) 1961 1961 end 1962 1962 1963 1963 function ExecFunc() 1964 - 1965 -status, errorString = mysql.exec("delete from tb_lua1 where mykey = 1966 - 1967 -10;") 1968 - 1969 -if nil == status then 1970 - 1971 -print("ExecFunc() error:", errorString) 1972 - 1973 -return -1 1974 - 1975 -else 1976 - 1977 -print("the number of rows affected by the command:", status) 1978 - 1947 + status, errorString = mysql.exec("delete from student where Name = 'XXX';") --Delete statement, column name = table element 1948 + if nil == status then 1949 + print("ExecFunc() error:", errorString) 1950 + return -1 1951 + else 1952 + print("the number of rows affected by the command:", status) 1953 + end 1954 + return 0 1979 1979 end 1980 1980 1981 -return 0 1982 1982 1983 -end 1984 - 1985 1985 function ExecWithResultFunc() 1986 - 1987 -status, errorString = mysql.execWithResult("select * from tb_lua1;") 1988 - 1989 -if nil == status then 1990 - 1991 -print("ExecWithResultFunc() error:", errorString) 1992 - 1993 -return -1 1994 - 1995 -else 1996 - 1997 -print("ExecWithResultFunc() 1998 - 1999 -success 2000 - 2001 -: status 2002 - 2003 -type 2004 - 2005 -= 2006 - 2007 -", 2008 - 2009 -type(status)) 2010 - 2011 -print("ExecWithResultFunc() success : status len = ", #status) 2012 - 2013 -local num = #status 2014 - 2015 -local i = 1 2016 - 2017 -if num > 0 then 2018 - 2019 -for i = 1, num, 1 do 2020 - 2021 -local var = string.format("select result[%d] :mykey = %d, 2022 - 2023 -value = %s", i, status[i].mykey, status[i].value) 2024 - 2025 -print(var) 2026 - 1959 + status, errorString = mysql.execWithResult("select * from student;") 1960 + if nil == status then 1961 + print("ExecWithResultFunc() error:", errorString) 1962 + return -1 1963 + else 1964 + print("ExecWithResultFunc() success : status type = ", type(status)) 1965 + print("ExecWithResultFunc() success : status len = ", #status) 1966 + local num = #status 1967 + local i = 1 1968 + if num > 0 then 1969 + for i = 1, num, 1 do 1970 + local var = string.format("select result[%d] :Num = %d,Name = %s,Age = %d", i, status[i].Num, status[i].Name,status[i].Age) --Iterate through the data in the table, noting whether the elements are strings or numbers 1971 + print(var) 1972 + end 1973 + end 1974 + print("---------------") 1975 + end 1976 + return 0 2027 2027 end 2028 2028 2029 -end 1979 +function MySQL.main() 1980 + print("script running ...") 1981 + DataInitRight() 2030 2030 2031 -print("---------------") 1983 + -- use exec demo 1984 + if ExecFunc() < 0 then 1985 + return 1986 + end 2032 2032 2033 -end 1988 + -- use execWithResult demo 1989 + if ExecWithResultFunc() < 0 then 1990 + return 1991 + end 2034 2034 2035 -r eturn01993 + print("script running success") 2036 2036 end 2037 - 2038 -function luaMysql_apiTest.main() 2039 - 2040 -print("script running ...") 2041 - 2042 -DataInitRight() 2043 - 2044 ---use exec demo 2045 - 2046 -if ExecFunc() < 0 then 2047 - 2048 -return 2049 - 2050 -end 2051 - 2052 ---use execWithResult demo 2053 - 2054 -if ExecWithResultFunc() < 0 then 2055 - 2056 -return 2057 - 2058 -end 2059 - 2060 -print("script running success") 2061 - 2062 -end 2063 2063 {{/code}} 2064 2064 2065 2065 = **12 Message summary algorithm** =