User:Dt192

From Mudlet
Revision as of 05:27, 31 January 2024 by Dt192 (talk | contribs)
Jump to navigation Jump to search

Sandbox

**List of orphaned pages**
https://wiki.mudlet.org/w/Area_51/Mapping_script
https://wiki.mudlet.org/w/Artists_performance_package
https://wiki.mudlet.org/w/Bounty_Process
https://wiki.mudlet.org/w/Chrome_OS
https://wiki.mudlet.org/w/Comparison_of_MUD_clients
https://wiki.mudlet.org/w/Connection_Window
https://wiki.mudlet.org/w/Dependency_Versions
https://wiki.mudlet.org/w/Fonts
https://wiki.mudlet.org/w/HowTo:OpenInWindowsCmd
https://wiki.mudlet.org/w/Mobile_Plan
https://wiki.mudlet.org/w/Mudlet_Packaging_System_Info_Template
https://wiki.mudlet.org/w/Mudlet_Sponsorship_Plan
https://wiki.mudlet.org/w/ProfileBackup
https://wiki.mudlet.org/w/Tutorials
https://wiki.mudlet.org/w/Updating_PPA
https://wiki.mudlet.org/w/VyzorDocumentation
https://wiki.mudlet.org/w/VyzorWalkthrough

**Links from the main website**
https://wiki.mudlet.org/w/Known_Issues

**Can't be deleted**
https://wiki.mudlet.org/w/Manual:Lua_Functions/Test

**To Delete**
...

So i don't forget again. This is how you sent raw sql to the db and fetch the result

luasql manual

mydb = db:create("mydb",
{
  mySheet = {
    name = "", id = 0, city = "",
    _index = { "name" },
    _unique = { "id" },
    _violations = "FAIL"
  }
})

myData = {
  {name="Ixokai", city="Magnagora", id=1},
  {name="Vadi", city="New Celest", id=2},
  {name="Heiko", city="Hallifax", id=3},
  {name="Keneanung", city="Hashan", id=4},
  {name="Carmain", city="Mhaldor", id=5},
  {name="Ixokai", city="Hallifax", id=6},
}

db:add(mydb.mySheet, unpack(myData))
local conn = db.__conn.mydb;
---------------------------------------------------------------------------------------

display(conn:getlastautoid())

----------------------------------------------------------------------------------------

results = conn:execute[[
   SELECT city,name FROM mySheet WHERE city = 'Hallifax'
]]

local city,name = results:fetch()
while city do
  print(city,name)
  city,name = results:fetch()
end

results:close()

----------------------------------------------------------------------------------------

results = conn:execute[[
  SELECT * FROM mySheet WHERE name = 'Ixokai'
]]

local res = results:fetch({}, "a")
while res do
  print(res.id, res.city, res.name)
  res = results:fetch(res, "a")
end

results:close()

----------------------------------------------------------------------------------------

function rows(conn, query)
  local cursor = assert(conn:execute(query))
  local res = {}
  return function ()
    return cursor:fetch(res, "a")
  end
end

local query = [[
  select * from mySheet WHERE id > 1 AND id < 5
]]

for row in rows(conn, query) do
  print(row.name, row.city, row.id)
end

----------------------------------------------------------------------------------------

function urows(conn, query)
  local cursor = assert(conn:execute(query))
  return function ()
    return cursor:fetch()
  end
end

local query = [[
  select name,city,id from mySheet WHERE id > 1 AND id < 5
]]

for name,city,id in urows(conn, query) do
  print(name, city, id)
end