I am aware of a bit of a code example on the wiki that is, IMHO, a bit buggy. I'd like people's reassurance before I edit it. Not sure of the etiquette around here.
I'm new here but, long, long ago, considered myself a reasonable Turbo Pascal and Delphi user. Recently needed a bit of code and remembered the FP/Lazaeus project. So, quickly found a good start on a bit of code called CreateTable on
http://wiki.freepascal.org/SqlDBHowto but to my surprise, the code has some problems. I really like the idea of example code, something you can copy and paste, and one way or another, run. This code has no GUI, starts with a "program" declaration, ends with "end." and so looks like standalone FP programme. But it does not compile because -
1. Is missing a function (noted in text).
2. Needs but has no "uses" clause.
3. Has a function returning a result via keyword 'result', OK in Lazarus but not FP.
4. Has badly constructed strings, using single inverted comma within the string, compiler thinks thats the end of the string.
5. Needs to free the Transaction before the Connection to avoid a run time error.
I have edited the example a bit and produced a working version in about the same number of lines.
program CreateTable;
uses
SysUtils, sqldb, db, sqlite3conn;
var
AConnection : TSQLite3Connection;
ATransaction : TSQLTransaction;
begin
AConnection := TSQLite3Connection.Create(nil);
AConnection.DatabaseName := 'test_dbase';
// Thats all SQLite needs, other dbases might also want -
// AConnection.Hostname := 'localhost';
// AConnection.UserName := 'sysdba';
// AConnection.Password := 'masterkey';
ATransaction := TSQLTransaction.Create(AConnection);
AConnection.Transaction := ATransaction;
AConnection.Open;
ATransaction.StartTransaction;
AConnection.ExecuteDirect('create table TBLNAMES (ID integer, NAME varchar(40));');
ATransaction.Commit;
ATransaction.StartTransaction;
AConnection.ExecuteDirect('insert into TBLNAMES (ID,NAME) values (1,''Name1'');');
AConnection.ExecuteDirect('insert into TBLNAMES (ID,NAME) values (2,''Name2'');');
ATransaction.Commit;
AConnection.Close;
ATransaction.Free;
AConnection.Free;
end.