Page Menu
Home
Xreate
Search
Configure Global Search
Log In
Docs
Questions
Repository
Issues
Patches
Internal API
Files
F2730251
sql.lp
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Mar 13, 9:29 PM
Size
1 KB
Mime Type
text/plain
Expires
Sun, Mar 15, 9:29 PM (1 d, 15 h)
Engine
blob
Format
Raw Data
Handle
243419
Attached To
rXR Xreate
sql.lp
View Options
#begin_lua
local n = 0
local env = luasql.sqlite3()
local conn = env:connect("test.sqlite3")
conn:execute("CREATE TABLE IF NOT EXISTS test (x, y)")
conn:execute("CREATE UNIQUE INDEX IF NOT EXISTS \
test_index ON test (x, y)")
function query()
local cur = conn:execute("SELECT * FROM test")
local res = {}
while true do
local row = {}
row = cur:fetch(row, "n")
if row == nil then break end
res[#res + 1] = Val.new(Val.FUNC, row)
end
cur:close()
return res
end
function insert(name)
Assignment.begin(name, 2)
while Assignment.next() do
if Assignment.isTrue() then
local x = Assignment.args()[1]
local y = Assignment.args()[2]
local res = conn:execute("INSERT INTO test \
VALUES(" .. x .. "," .. y .. ")")
if res ~= nil then n = n + 1 end
end
end
end
function onBeginStep() insert("p") end
function onModel() insert("q") end
function onEndStep() print("inserted " .. n .. " values") end
#end_lua.
p(1,1).
p(X+1,Y) :- (X,Y) := @query().
#odd { q(X,Y+1) : p(X,Y) }.
Event Timeline
Log In to Comment