Using GetText is a poor solution for a problem that does not exist.
We don't even know anything about the table structure. How is that date field defined?
What if you want to use that field to do some data calculations (like number of days since) inside a SELECT statement.
For me the code below works fine in FPC so there is no problem with strftime, even if it deals with a TEXT defined field.
But it might be better to just let SQLite3 determine the affinity and use DATE (in which case it will pick NUMERIC as underlying field).
https://www.sqlite.org/datatype3.htmlprogram test;
{$MODE OBJFPC}{$H+}
uses
Classes, SysUtils, dateutils, DB, sqldb, sqlite3conn;
var
Conn: TSQLite3Connection;
Trans: TSQLTransaction;
Query: TSQLQuery;
n: Integer;
begin
DeleteFile('test.db');
Conn := TSQLite3Connection.Create(nil);
Conn.DatabaseName := 'test.db';
try
Trans := TSQLTransaction.Create(Conn);
Trans.Database := Conn;
Query := TSQLQuery.Create(Conn);
Query.Database := Conn;
Query.Transaction := Trans;
Conn.ExecuteDirect('CREATE TABLE data (id INTEGER, xdate text);');
// but xdate DATE might be better here
Query.SQL.Text := 'INSERT INTO data (id, xdate) values (:id, :xdate)';
for n := 1 to 10 do
begin
Query.Params.ParamByName('id').AsInteger := n;
Query.Params.ParamByName('xdate').AsDate := Date;
// Query.Params.ParamByName('xdate').AsString := '2023-12-05'; // this works too
Query.ExecSQL;
end;
Trans.Commit;
Query.SQL.Text := 'SELECT id, strftime(''%d/%m/%Y'', xDate) as xdate FROM DATA';
Query.Open;
while not Query.EOF do
begin
writeln(format('id = %d xdate = %s', [Query.FieldByName('id').AsInteger, Query.FieldByName('xdate').AsString]));
Query.Next;
end;
finally
Conn.Free;
end;
readln;
end.
id = 1 xdate = 19/11/2024
id = 2 xdate = 19/11/2024
id = 3 xdate = 19/11/2024
id = 4 xdate = 19/11/2024
id = 5 xdate = 19/11/2024
id = 6 xdate = 19/11/2024
id = 7 xdate = 19/11/2024
id = 8 xdate = 19/11/2024
id = 9 xdate = 19/11/2024
id = 10 xdate = 19/11/2024
The problem is probably the predefined fields in the IDE object inspector (which causes the blank fields).