Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FDQuery append gives error "no such table"

In Delphi 10.1 I made a small program to learn about FireDAC and SQlite.

I have FDConnection, FDQuery (with SQL= SELECT * FROM Sætning) and DataSource + DBGrid. The DBGrid shows the (empty) table Sætning. I want to put data into my table from a listbox containg a CSV.

This is my code: (fdwSætning = an FDQuery)

procedure TMainForm.bCSV_SQLite_SætningClick(Sender: TObject);
var
  loop : integer;
  nr, lang, tekst : string;
begin
  { Read CSV file into Listbox }
  Listbox1.Items.LoadFromFile('GMS_Saetninger.txt');
  { Put the values from the CSV into the fields in each record }
  for loop:= 0 to Listbox1.Items.Count-1 do begin
    fdqSætning.Edit;
    nr:= copy(Listbox1.Items[loop],1,4);
    lang:= copy(Listbox1.Items[loop],5,2);
    tekst:= copy(Listbox1.Items[loop],8, length(Listbox1.Items[loop]));
    fdqSætning.Append;
    fdqSætning.FieldByName('SAETNING_ID').AsString:= nr;
    fdqSætning.FieldByName('LANGUAGE').AsString:= lang;
    fdqSætning.FieldByName('SENTENCE').AsString:= tekst;
    fdqSætning.Post;
  end;
end; 

When I run this code I get the error message

[FireDAC][phys][SQLite]ERROR:no such table: Sætning
like image 704
larshgf Avatar asked Jul 21 '26 08:07

larshgf


1 Answers

That should not happen. Since Delphi 2009, FireDAC fully supports Unicode metadata values, so as does SQLite DBMS. Possible explanation for what you describe is that you've created your table in some external tool (which cannot save Unicode metadata).

So even when I would highly suggest using only ASCII chars for database object names, you can still do something like this with FireDAC since Delphi 2009:

FDConnection.Params.Add('DriverID=SQLite');
FDConnection.Params.Add('Database=C:\MyDatabase.db');

FDQuery.SQL.Text := 'CREATE TABLE ṀÿṪäḅḷë (MɏFɨɇłđ INTEGER)';
FDQuery.ExecSQL;
FDQuery.SQL.Text := 'INSERT INTO ṀÿṪäḅḷë (MɏFɨɇłđ) VALUES (1234)';
FDQuery.ExecSQL;
FDQuery.SQL.Text := 'SELECT MɏFɨɇłđ FROM ṀÿṪäḅḷë';
FDQuery.Open;
Assert(FDQuery.FieldByName('MɏFɨɇłđ').AsInteger = 1234);
like image 100
Victoria Avatar answered Jul 24 '26 06:07

Victoria



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!