File fhSQL.lua

Functions

close (dbconection, dbconnection) close Close db connection.
connect (connection_string) connect Connect to any ADO compliant database See https://www.connectionstrings.com for information on string format for different databases.
connectSQLite (sFilename) connectSQLite Connect to a SQLite3 database file, the database file will be created if it does not exist when opened.
execute (dbconection, statement) execute Executes provided SQL statement Any SQL statement can be used and the database recordset value will contain the result from the statement.
fetch (resultset, dbconnection) fetch Used to get a single row from a resultset, this is used where only a single row is needed if multiple rows are needed use the rows function.
rows (resultset, dbconnection) rows Used to iterate through result sets.
select (dbconection, statement) select Creates a result set based on the passed select statement.


Functions

close (dbconection, dbconnection)
close Close db connection.

Parameters:

  • dbconection:
  • dbconnection: Connection to close
connect (connection_string)
connect Connect to any ADO compliant database See https://www.connectionstrings.com for information on string format for different databases.

Parameters:

  • connection_string: connection string for database to use.

Return value:

    fhSQL Object - Object to use to run SQL statements against the selected database.
connectSQLite (sFilename)
connectSQLite Connect to a SQLite3 database file, the database file will be created if it does not exist when opened. Note when using SQLite, blob objects are truncated to 255 characters.

Parameters:

  • sFilename: database file name

Return value:

    fhSQL Object - Object to use to run SQL statements against the selected database.
execute (dbconection, statement)
execute Executes provided SQL statement Any SQL statement can be used and the database recordset value will contain the result from the statement. It is recommended to use the select function when calling the select statement as this supports multiple concurrent resultsets, but the execute command does not.
db:execute("insert into mytable values ('George Bush', '123-4567')")

Parameters:

  • dbconection:
  • statement:
fetch (resultset, dbconnection)
fetch Used to get a single row from a resultset, this is used where only a single row is needed if multiple rows are needed use the rows function.

Parameters:

  • resultset: result set from select call.
  • dbconnection: - connection

Return value:

    table table of fields
rows (resultset, dbconnection)
rows Used to iterate through result sets. Called on the returned result set from a select function. It provides a simple interation function for example
local people = db:select("select * from test ")
for person in people:rows() do
print(tostring(person.name).."\t"..tostring(person.phone))
end

Parameters:

  • resultset: - result set to read
  • dbconnection: - connection

Return value:

    table - table of fields from the row keyed on field name
select (dbconection, statement)
select Creates a result set based on the passed select statement. For example
local people = db:select("select * from test ")

Parameters:

  • dbconection:
  • statement:

Return value:

    resultSetObject, result set object which can be processed using the rows function.

Valid XHTML 1.0!