The special filename ":memory:" opens an in-memory database.

Posted by Narci on Sat 02 Aug 2014 09:16 AM — 3 posts, 13,197 views.

#0
This the code:

require "tprint"

DatabaseOpen ("db", GetInfo (66) .. ":memory:", 6)

rc = DatabaseExec ("db", [[
DROP TABLE IF EXISTS weapons;
CREATE TABLE weapons(
        weapon_id INTEGER NOT NULL PRIMARY KEY autoincrement,
        name  TEXT NOT NULL,
        damage INT default 10,
        weight REAL
      );
      ]])
      

-- put some data into the database
DatabaseExec ("db", 
  [[
  INSERT INTO weapons (name, damage) VALUES ('sword', 42);
  INSERT INTO weapons (name, damage) VALUES ('mace', 55);
  INSERT INTO weapons (name, damage) VALUES ('staff', 35);
  ]])

-- prepare a query
DatabasePrepare ("db", "SELECT * from weapons ORDER BY name")

-- find the column names
names = DatabaseColumnNames ("db")
tprint (names)

-- execute to get the first row
rc = DatabaseStep ("db")  -- read first row

-- now loop, displaying each row, and getting the next one
while rc == 100 do
  
  print ("")
  values = DatabaseColumnValues ("db")
  tprint (values)

  rc = DatabaseStep ("db")  -- read next row

end -- while loop

-- finished with the statement
DatabaseFinalize ("db")

DatabaseClose ("db")  -- close it



but it no work...
Amended on Sat 02 Aug 2014 09:45 AM by Narci
Australia Forum Administrator #1
Quote:

DatabaseOpen ("db", GetInfo (66) .. ":memory:", 6)


In my case GetInfo (66) is:


C:\Program Files\MUSHclient\


So the filename:


GetInfo (66) .. ":memory:"


would be:


C:\Program Files\MUSHclient\:memory:


Would it not?

That is not exactly the same as ":memory:" is it?

Your code works if you omit the "GetInfo (66)".
#2
Now,I know.
thank you!