Delete a line in SQLite
Posted: Sat Feb 04, 2012 5:30 pm
Ok...I have spent countless hours trying to figure this out, and I hate to have to ask the community for help but I have no choice... I am trying to allow a user to delete a database entry when they select the line in a list field. In other words, I populate the list field with the contents of my database, and the user can select a line and choose to delete it from the records. I have been using the example from the lessons section regarding connecting and adding database entries, and I have modified it to create the type of table and column headers I want. The table "goals" simply consists of two columns "name" and "goal". The user types some text into a field called "trialField" and a name of the trial into a field "goalName", this then makes my database entry. I am having issues querying and deleting a single record.... I have tried the "DELETE FROM goals WHERE goal = blah blah blah....in every conceivable form and fashion but I am too dense to get it.... can anyone help an idiot out here? thanks...
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