Code: Select all
## Use a script local variable to store the database id
local sDatabaseID
## Handlers to get and set the variable storing the database id
command setDatabaseID pDatabaseID
put pDatabaseID into sDatabaseID
end setDatabaseID
function getDatabaseID
return sDatabaseID
end getDatabaseID
command databaseConnect
local tDatabasePath, tDatabaseID
## The database must be in a writeable location
put specialFolderPath("documents") & "/runrevemails.sqlite" into tDatabasePath
## Open a connection to the database
## If the database does not already exist it will be created
put revOpenDatabase("sqlite", tDatabasePath, , , , ) into tDatabaseID
## Store the database id as a custom property so other handlers can access it
setDatabaseID tDatabaseID
end databaseConnect
command databaseClose
revCloseDatbase sDatabaseID
end databaseClose
on databaseCreateTables
## Add a contact_details table to the database
put getDatabaseID() into tDatabaseID
put "CREATE TABLE goals (name char(50), goal string)" into tSQL
revExecuteSQL tDatabaseID, tSQL
end databaseCreateTables
on databaseDeleteTables
## Add a contact_details table to the database
put getDatabaseID() into tDatabaseID
put "delete from goals" into tSQL
revExecuteSQL tDatabaseID, tSQL
end databaseDeleteTables
on databaseInsertContactDetails
## Insert names and email addresses into the database
put getDatabaseID() into tDatabaseID
global vGoalName
global vGoalText
put fld "goalName" into vGoalName
put fld "trialField" into vGoalText
put "INSERT into goals VALUES ( '"& vGoalName & "', '"& vGoalText & "' );" into tSQL
revExecuteSQL tDatabaseID, tSQL
end databaseInsertContactDetails
function databaseGetContactDetails
## Query the database for contact details to be displayed in the field
put getDatabaseID() into tDatabaseID
put "SELECT * from goals" into tSQL
put revDataFromQuery(tab,return,tDatabaseID,tSQL) into tRecords
return tRecords
end databaseGetContactDetails