3

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
Arount
  • 9,853
  • 1
  • 30
  • 43
larshgf
  • 43
  • 4
  • 5
    Not that I would like to discourage you, but I would suggest you to use ASCII names for tables. I bet there is a setting for it, I can search for, but still... – Victoria Aug 06 '17 at 11:40
  • Indeed, my instinct is that special character you have in the table name. Internally, something probably interprets it as `S?tning`. – Jerry Dodge Aug 06 '17 at 13:13
  • Thank you Victoria and Jerry! You were right. I changed the table name from Sætning to Saetning and now there is no "no such table" error. Instead I got me a "[FireDAC][phys][SQLite]ERROR: database is locked" - this is for sure a time-consuming hobby... :-) – larshgf Aug 06 '17 at 13:43
  • I bet you just forgot to disconnect the connection at design time (`Connected` property of your connection object). But my initial comment was just a suggestion. I'm not saying it's impossible. FireDAC should fully support Unicode table names in Unicode Delphi. – Victoria Aug 07 '17 at 07:10

1 Answers1

2

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);
Victoria
  • 7,822
  • 2
  • 21
  • 44
  • Allthough I changed to ANSI and renamed my tables (which solved the problem), I think that the "no such table" problem was generated - as you say - because of a unicode problem. In my FDConnection the string was not set to Unicode (by default you have to choose). – larshgf Aug 13 '17 at 19:53
  • No, by default, FireDAC picks the best for you. – Victoria Aug 13 '17 at 19:56
  • The othe problem ("database locked") was correctly caused by having my FDConnection still active in the Delphi IDE. - Well, when you are in the middle of "the steep learning curve" there is too many unknown factors.... Thanks for the fine answers!!! – larshgf Aug 13 '17 at 19:58
  • You're very welcome! Well, what would I appreciate now is if you could do a quick test with a fresh project composed from a connection (named `FDConnection`) and query object (named `FDQuery`) with default settings and run the code I've posted to verify that Unicode works for you in Delphi 10.1. Of course naming table and field like I did is horrible, but I would like a proof. If that works, you may consider [accept this post](https://meta.stackexchange.com/a/5235/367405), when it raises an `EAssertionFailed` exception, then there's something wrong with Unicode. – Victoria Aug 14 '17 at 09:08