I am trying to query one of the SQLite 3 tables from Delphi. (My databse is world and I ahve a table called City in it). My code is:
procedure TForm1.Button1Click(Sender: TObject);
begin
// Set the path of your database file.
// Replace "full_path_to_your_database_file" with the absolute path
// to your SQLite database file.
SQLConnection1.Params.Add('World.db3');
try
// Establish the connection.
SQLConnection1.Connected := true;
Button1.Enabled := true;
Memo1.Text := 'Connection established!';
except
on E: EDatabaseError do
ShowMessage('Exception raised with message' + E.Message);
end;
end;
procedure TForm1.ShowSelectResults(results: TDataSet);
var
names: TStringList;
i: Integer;
currentField: TField;
currentLine: string;
begin
if not results.IsEmpty then
begin
results.First;
names := TStringList.Create;
results.GetFieldNames(names);
while not results.Eof do
begin
currentLine := '';
for i := 0 to names.Count - 1 do
begin
currentField := results.FieldByName(names[i]);
currentLine := currentLine + ' ' + currentField.AsString;
end;
memo1.Lines.Add(currentLine);
results.Next;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
results: TDataSet;
query: String;
begin
Memo1.Clear;
// A random query
query := 'SELECT * FROM City;';
try
// Execute the query on the database.
SQLConnection1.Execute(query, nil, results);
except
on E: Exception do
Memo1.Text := 'Exception raised with message: ' + E.Message;
end;
// Show the results of the query in a TMemo control.
ShowSelectResults(results);
end;
When I compile and execute this code, it is getting connected to the database; but throws this error. "Exception raised with message: no such table: City" I have spent hours and hours to figure out why I am hitting on this error. Tried out numerous versions of this code too. Doesn't seem to work either. Any help in this regard is highly appreciated.