Changes for page 01 Lua Functions

Last modified by Theodore Xu on 2023/10/26 10:51

From version 16.1
edited by Theodore Xu
on 2023/08/24 16:41
Change comment: There is no comment for this version
To version 18.1
edited by Theodore Xu
on 2023/08/25 09:48
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1872,184 +1872,8 @@
1872 1872  
1873 1873  Failed: nil
1874 1874  
1875 -= **11 MySQL database operation** =
1875 += (% style="font-size:14px" %) (%%) =
1876 1876  
1877 -== **luaMySql.init(string sourcename, string username, string password, string host, number port, string character)** ==
1878 -
1879 -**Function:** Configure database connection parameters
1880 -
1881 -**Parameter:**
1882 -
1883 -sourcename: the name of database
1884 -
1885 -username: the username of the connection
1886 -
1887 -password: the password of the connection
1888 -
1889 -host: the host name of the connection
1890 -
1891 -port: the host port of the connection
1892 -
1893 -character: the character set of the connection
1894 -
1895 -**Return:**
1896 -
1897 -Succeed: string
1898 -
1899 -Failed: multi
1900 -
1901 -== **luaMySql.exec(string statement)** ==
1902 -
1903 -**Function:** Execute the given SQL statement without returning the result set (add, delete, change)
1904 -
1905 -**Parameter:**
1906 -
1907 -statement: the given SQL statement
1908 -
1909 -**Return:**
1910 -
1911 -Succeed: status: returns the number of rows affected by SQL statement execution.
1912 -
1913 -Failed: nil, errorString
1914 -
1915 -== **luaMySql.execWithResult(string statement)** ==
1916 -
1917 -**Function:** Execute the given SQL statement returning the result set (check)
1918 -
1919 -**Parameter:**
1920 -
1921 -statement: the given SQL statement
1922 -
1923 -**Return:**
1924 -
1925 -Succeed: table: returns the result set
1926 -
1927 -Failed: nil, errorString
1928 -
1929 -**For example:**
1930 -
1931 -{{code language="LUA"}}
1932 -mysql = require"mysqlclient"
1933 -
1934 -function DataInitRight()
1935 -
1936 -local dbName = "db_lua1"
1937 -
1938 -local user = "root"
1939 -
1940 -local pwd = "123456"
1941 -
1942 -local host = "192.168.56.186"
1943 -
1944 -local port = 3306
1945 -local character = "UTF8"
1946 -
1947 -mysql.init(dbName, user, pwd, host, port, character)
1948 -
1949 -end
1950 -
1951 -function ExecFunc()
1952 -
1953 -status, errorString = mysql.exec("delete from tb_lua1 where mykey =
1954 -
1955 -10;")
1956 -
1957 -if nil == status then
1958 -
1959 -print("ExecFunc() error:", errorString)
1960 -
1961 -return -1
1962 -
1963 -else
1964 -
1965 -print("the number of rows affected by the command:", status)
1966 -
1967 -end
1968 -
1969 -return 0
1970 -
1971 -end
1972 -
1973 -function ExecWithResultFunc()
1974 -
1975 -status, errorString = mysql.execWithResult("select * from tb_lua1;")
1976 -
1977 -if nil == status then
1978 -
1979 -print("ExecWithResultFunc() error:", errorString)
1980 -
1981 -return -1
1982 -
1983 -else
1984 -
1985 -print("ExecWithResultFunc()
1986 -
1987 -success
1988 -
1989 -: status
1990 -
1991 -type
1992 -
1993 -=
1994 -
1995 -",
1996 -
1997 -type(status))
1998 -
1999 -print("ExecWithResultFunc() success : status len = ", #status)
2000 -
2001 -local num = #status
2002 -
2003 -local i = 1
2004 -
2005 -if num > 0 then
2006 -
2007 -for i = 1, num, 1 do
2008 -
2009 -local var = string.format("select result[%d] :mykey = %d,
2010 -
2011 -value = %s", i, status[i].mykey, status[i].value)
2012 -
2013 -print(var)
2014 -
2015 -end
2016 -
2017 -end
2018 -
2019 -print("---------------")
2020 -
2021 -end
2022 -
2023 -return 0
2024 -end
2025 -
2026 -function luaMysql_apiTest.main()
2027 -
2028 -print("script running ...")
2029 -
2030 -DataInitRight()
2031 -
2032 ---use exec demo
2033 -
2034 -if ExecFunc() < 0 then
2035 -
2036 -return
2037 -
2038 -end
2039 -
2040 ---use execWithResult demo
2041 -
2042 -if ExecWithResultFunc() < 0 then
2043 -
2044 -return
2045 -
2046 -end
2047 -
2048 -print("script running success")
2049 -
2050 -end
2051 -{{/code}}
2052 -
2053 2053  = **12 Message summary algorithm** =
2054 2054  
2055 2055  == **hmac(string hash_func, string key, string message)** ==