After a good while, i decided to return to FreePascal/Lazarus IDE for developing some apps.
So i running an issue, i'm using TSQLQuery.SQL using SQLite3 for my INSERT and UPDATE SQL statements since an TSQLQuery object in my form is shared for many TFrames, but this time i want to create an record from the Main form, the table has no NOT-NULL constraints and you can omit them normally, for example my table looks like this:
CREATE TABLE MedicalRecord(
record_id INTEGER UNIQUE NOT NULL PRIMARY KEY AUTOINCREMENT,
first_name TEXT,
last_name TEXT,
Age INTEGER,
Updated_Record DATETIME,
Created_Record DATETIME
);
As you can see the fields Updated_Record, Created_Record columns are optional, are only used for updating or inserting new records respectively, and record_id field must not can't be updated manually by the app, is something up for the database engine.
I use TSQLQuery.SQL for INSERT and UPDATE statements from the Wiki
http://wiki.freepascal.org/Working_With_TSQLQuery#Insert_query_example with this code
SQLQuery1.SQL.Text := 'INSERT INTO MedicalRecord VALUES(:FIRSTNAME , :LASTNAME , :AGE ,:CREATED_RECORD , :UPDATED_RECORD )';
with SQLQuery1 do begin
ParamByName('FIRSTNAME').AsString := FirstNameEdit.Text;
ParamByName('LASTNAME').AsString:= LastNameEdit.Text;
ParamByName('AGE').AsInteger:= AgeSpinEdit.Value;
ParamByName('CREATED_RECORD').AsDateTime:= Now;
ParamByName('UPDATED_RECORD').AsDateTime:= Now;
end;
SQLQuery1.ExecSQL;
SQLTransaction1.Commit;
But everytime i try to execute this code SQLite3Connection raises an exception:
"SQLite3Connection table Records has 6 columns but 5 values where supplied".It's complaining why the record_id field (the Primary Key) must be filled in the INSERT statement when shouldn't be.
There's an way to disable this unnecesary check done by SQLite3Connection?, disabling 'AutoCalcFields' and 'ParseSQL' properties from TSQLQuery doesn't help.
(Using the latest stable version of Lazarus, in Windows 10 x64)
Thanks.