Changes for page 01 Lua Functions
Last modified by Theodore Xu on 2023/10/26 10:51
From version 10.1
edited by Hunter
on 2023/01/15 16:45
on 2023/01/15 16:45
Change comment:
There is no comment for this version
To version 20.1
edited by Theodore Xu
on 2023/08/25 09:49
on 2023/08/25 09:49
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
-
... ... @@ -1508,9 +1508,12 @@ 1508 1508 * Obtaining ICCID (read only) 1509 1509 ** addr_getstring("@W_HSW225",15) 1510 1510 * ((( 1511 -TSAP settings of Siemens LOGO PLC* ((( 1511 +TSAP settings of Siemens LOGO PLC* 1512 + 1513 +((( 1512 1512 addr_setword("@W_0#HSW1200",8192) means set the Local TSAP as 20.00 1513 1513 ))) 1516 + 1514 1514 * ((( 1515 1515 addr_setword("@W_0#HSW1201",4096) means set the Remote TSAP as 10.00 1516 1516 ))) ... ... @@ -1869,186 +1869,8 @@ 1869 1869 1870 1870 Failed: nil 1871 1871 1872 -= **11 M ySQL databaseoperation** =1875 += **11 Message summary algorithm** = 1873 1873 1874 -== **luaMySql.init(string sourcename, string username, string password, string host, number port, string character)** == 1875 - 1876 -**Function:** Configure database connection parameters 1877 - 1878 -**Parameter:** 1879 - 1880 -sourcename: the name of database 1881 - 1882 -username: the username of the connection 1883 - 1884 -password: the password of the connection 1885 - 1886 -host: the host name of the connection 1887 - 1888 -port: the host port of the connection 1889 - 1890 -character: the character set of the connection 1891 - 1892 -**Return:** 1893 - 1894 -Succeed: string 1895 - 1896 -Failed: multi 1897 - 1898 -== **luaMySql.exec(string statement)** == 1899 - 1900 -**Function:** Execute the given SQL statement without returning the result set (add, delete, change) 1901 - 1902 -**Parameter:** 1903 - 1904 -statement: the given SQL statement 1905 - 1906 -**Return:** 1907 - 1908 -Succeed: status: returns the number of rows affected by SQL statement execution. 1909 - 1910 -Failed: nil, errorString 1911 - 1912 -== **luaMySql.execWithResult(string statement)** == 1913 - 1914 -**Function:** Execute the given SQL statement returning the result set (check) 1915 - 1916 -**Parameter:** 1917 - 1918 -statement: the given SQL statement 1919 - 1920 -**Return:** 1921 - 1922 -Succeed: table: returns the result set 1923 - 1924 -Failed: nil, errorString 1925 - 1926 -**For example:** 1927 - 1928 -{{code language="LUA"}} 1929 -mysql = require"mysqlclient" 1930 - 1931 -function DataInitRight() 1932 - 1933 -local dbName = "db_lua1" 1934 - 1935 -local user = "root" 1936 - 1937 -local pwd = "123456" 1938 - 1939 -local host = "192.168.56.186" 1940 - 1941 -local port = 3306 1942 -local character = "UTF8" 1943 - 1944 -mysql.init(dbName, user, pwd, host, port, character) 1945 - 1946 -end 1947 - 1948 -function ExecFunc() 1949 - 1950 -status, errorString = mysql.exec("delete from tb_lua1 where mykey = 1951 - 1952 -10;") 1953 - 1954 -if nil == status then 1955 - 1956 -print("ExecFunc() error:", errorString) 1957 - 1958 -return -1 1959 - 1960 -else 1961 - 1962 -print("the number of rows affected by the command:", status) 1963 - 1964 -end 1965 - 1966 -return 0 1967 - 1968 -end 1969 - 1970 -function ExecWithResultFunc() 1971 - 1972 -status, errorString = mysql.execWithResult("select * from tb_lua1;") 1973 - 1974 -if nil == status then 1975 - 1976 -print("ExecWithResultFunc() error:", errorString) 1977 - 1978 -return -1 1979 - 1980 -else 1981 - 1982 -print("ExecWithResultFunc() 1983 - 1984 -success 1985 - 1986 -: status 1987 - 1988 -type 1989 - 1990 -= 1991 - 1992 -", 1993 - 1994 -type(status)) 1995 - 1996 -print("ExecWithResultFunc() success : status len = ", #status) 1997 - 1998 -local num = #status 1999 - 2000 -local i = 1 2001 - 2002 -if num > 0 then 2003 - 2004 -for i = 1, num, 1 do 2005 - 2006 -local var = string.format("select result[%d] :mykey = %d, 2007 - 2008 -value = %s", i, status[i].mykey, status[i].value) 2009 - 2010 -print(var) 2011 - 2012 -end 2013 - 2014 -end 2015 - 2016 -print("---------------") 2017 - 2018 -end 2019 - 2020 -return 0 2021 -end 2022 - 2023 -function luaMysql_apiTest.main() 2024 - 2025 -print("script running ...") 2026 - 2027 -DataInitRight() 2028 - 2029 ---use exec demo 2030 - 2031 -if ExecFunc() < 0 then 2032 - 2033 -return 2034 - 2035 -end 2036 - 2037 ---use execWithResult demo 2038 - 2039 -if ExecWithResultFunc() < 0 then 2040 - 2041 -return 2042 - 2043 -end 2044 - 2045 -print("script running success") 2046 - 2047 -end 2048 -{{/code}} 2049 - 2050 -= **12 Message summary algorithm** = 2051 - 2052 2052 == **hmac(string hash_func, string key, string message)** == 2053 2053 2054 2054 **Function:** HMAC calculate