I have created the following database
SqlResult := fDataBase.Exec("CREATE TABLE workstations (workstation string, location string, userId string);");
How do you use params in a sqlite INSERT statement.
For example, I assume it would be something as such
FDatabase.Exec("INSERT INTO workstations values(?,?,?);", [AWorkstation, ALocation, AUserId]);
However, Exec only takes a string........so do I have to actually build out the whole string to include the params?
FDatabase.Exec("INSERT INTO workstations values( + AWorkstation + ',' + ALocation + ',' + AUserId +');" );
reason I ask, is that the
TSQLiteDatabase has a CreateStatement function that returns a
TSQLiteStatement class
which has a SQL & Params property
and the following methods
prepare execute release
do I instead of calling the databases exec, i instead do a createstatement, assign sql and params, and then execute ?
e.g.
stm:= fDatabase.CreateStatement;
stm.SQL:= ?
stm.Params:= ?
stm.execute;
i have even tried
FDatabase.Exec('INSERT INTO workstations (workstation, location, userid) values(' + AWorkstation + ',' + ALocation + ',' + AUserId +');');
If I hardcode the values, this works
FDatabase.Exec("INSERT INTO workstations (workstation, location, userid) values('WS0202', 'Maintenance', 'jdoe');");
but, i need to be able to use params
also tried it with a format function and still doesn't work
FDatabase.Exec(Format("INSERT INTO workstations (workstation, location, userid) values(%s ,%s, %s );", [AWorkstation, ALocation, AUserId]));
FDatabase.Exec(Format("INSERT INTO workstations (workstation, location, userid) values('%s' ,'%s', '%s');", [AWorkstation, ALocation, AUserId]));