Install software:

opkg update 
opkg install sqlite3-cli
opkg install luasql-sqlite3
nano /mnt/sda1/luasqlite3.lua
#!/usr/bin/lua
sqlite3 = require "luasql.sqlite3"
local env  = sqlite3.sqlite3()
local conn = env:connect('/mnt/sda1/sensor.db')
print(env,conn)
status,errorString = conn:execute([[CREATE TABLE sample ('id' INTEGER, 'name' TEXT)]])
print(status,errorString )
status,errorString = conn:execute([[INSERT INTO sample values('1','Raj')]])
print(status,errorString )
cursor,errorString = conn:execute([[select * from sample]])
print(cursor,errorString)
row = cursor:fetch ({}, "a")
while row do
  print(string.format("Id: %s, Name: %s", row.id, row.name))
  row = cursor:fetch (row, "a")
end
-- close everything
cursor:close()
conn:close()
env:close()
chmod 755  /mnt/sda1/luasqlite3.lua
/mnt/sda1/luasqlite3.lua

Confirmed worked:

sqlite3 /mnt/sda1/sensor.db
SQLite version 3.7.12.1 2024-05-22 02:45:53
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select * from sample;
1|Raj

Comments powered by CComment