4.31. Lua database access

发布时间 : 2025-10-25 13:34:07 UTC      

Page Views: 10 views

This article mainly introduces the Lua database operation library: LuaSQL . He is open-source and supports databases such as ODBC, ADO , Oracle , MySQL , SQLite , and PostgreSQL.

This article introduces to you MySQL the database connection.

LuaSQL use LuaRocks to install the databasedriver you need to install as needed.

LuaRocks installation method:

$ wget http://luarocks.org/releases/luarocks-2.2.1.tar.gz $ tar zxpf luarocks-2.2.1.tar.gz $ cd luarocks-2.2.1 $ ./configure; sudo make bootstrap $ sudo luarocks install luasocket $ lua Lua 5.3.0 Copyright (C) 1994-2015 Lua.org, PUC-Rio > require "socket" 

Install LuaRocks: keplerproject/luarocks under Window

Install different database drivers:

luarocks install luasql-sqlite3 luarocks install luasql-postgres luarocks install luasql-mysql luarocks install luasql-sqlite luarocks install luasql-odbc 

You can also use the source code installation method, Lua Github source address: keplerproject/luasql

Lua connection MySql database:

4.31.1. Example #

require "luasql.mysql" --Creating Environment Objects env = luasql.mysql() --Connect to database conn = env:connect("Database name, username, password, IP address, port) --Set the encoding format for the database conn:execute"SET NAMES UTF8" --Perform database operations cur = conn:execute("select * from role") row = cur:fetch({},"a") --Creating File Objects file = io.open("role.txt","w+"); while row do var = string.format("%d %s\\n", row.id, row.name) print(var) file:write(var) row = cur:fetch(row,"a") end file:close() --Close File Object conn:close() --Close database connection env:close() --Shutdown Database Environment 
《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。