File fhSQL - Examples

Read SQLite Database

-- Testing fhSQL Example using SQLite3

require("fhSQL")

local db = fhSQL.connectSQLite("d:\\temp\\test.sql")

db:execute("create table test (name char(30), phone char(20))")

db:execute("insert into test values ('Bill Gates', '666-6666')")
db:execute("insert into test values ('Paul Allen', '606-0606')")
db:execute("insert into test values ('George Bush', '123-4567')")

local people = db:select("select * from test ")

for person in people:rows() do
  print(tostring(person.name).."\t"..tostring(person.phone))
end

db:execute("drop table test")
db:close()

collectgarbage()

Read Legacy Database

-- Read Individual Record Table from Legacy

require("fhSQL")
local dbfile = "d:\\work\\Legacy Family Tree\\Data\\Sample.fdb"
local db = fhSQL.connect("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="..dbfile)

local statement = select * from tblIR

local tables = db:select(statement)

for table in tables:rows() do
  for k,v in pairs(table) do
    print(k,v)
  end
end

db:close()

collectgarbage()

Read TMG Database

-- Read Research Log Record Table from TMG

require("fhSQL")
local dbfile = "D:\\temp\\gedcom\\Projects\\Sample"  -- Note this is the folder containing the database
local db = fhSQL.connect("Provider=VFPOLEDB.1;Data Source="..dbfile)

local statement = select * from sample_l

local tables = db:select(statement)

for table in tables:rows() do
  for k,v in pairs(table) do
    print(k,v)
  end
end

db:close()

collectgarbage()

Notes

For more connection string examples please see Connection Strings.com.