I am trying to run a query on an sqlite table
select x as 'date sent' from y
This query fails - is there anything I am doing wrong?
Thanks
sqlite alias with a space
Re: sqlite alias with a space
Hello,
We can't reproduce the problem on the latest UniDAC version. Please modify the following code, so that the problem is reproduced and send it back to us. In addition, specify the exact versions of IDE, UniDAC and SQLite3.dll.
We can't reproduce the problem on the latest UniDAC version. Please modify the following code, so that the problem is reproduced and send it back to us. In addition, specify the exact versions of IDE, UniDAC and SQLite3.dll.
Code: Select all
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils, Uni, SQLiteUniprovider;
var
UniConnection: TUniConnection;
UniQuery: TUniQuery;
begin
UniConnection := TUniConnection.Create(nil);
try
UniConnection.ProviderName := 'SQLite';
UniConnection.ExecSQL('CREATE TABLE y(x date)');
UniConnection.ExecSQL('INSERT INTO y VALUES(date(''now''))');
UniQuery := TUniQuery.Create(nil);
try
UniQuery.Connection := UniConnection;
UniQuery.SQL.Text := 'select x as ''date sent'' from y';
UniQuery.Open;
Writeln(UniQuery.FieldByName('date sent').AsString);
finally
UniQuery.Free;
end;
finally
UniConnection.Free;
readln;
end;
end.
Re: sqlite alias with a space
Hmm sorry - problem may be with another component
Re: sqlite alias with a space
I have checked and although part of my issue is with another component it seems that UniDac does not like double quoted aliases
Re: sqlite alias with a space
Further info
using builder XE3
I can only get your example to run if I use
UniConnection1->ExecSQL("insert into y values(date(\"now\"))");
UniConnection1->ExecSQL("insert into y values(date(''now''))"); does not work neither does
UniConnection1->ExecSQL("insert into y values(date('now'))");
which ever variant i use I get an error "date sent" not found
UniConnection1->ExecSQL("Create table if not exists y(x date)");
UniConnection1->ExecSQL("insert into y values(date(\"now\"))");
UniQuery1->SQL->Clear();
UniQuery1->SQL->Add("select x as 'date sent' from y");
UniQuery1->Execute();
Memo2->Lines->Add(UniQuery1->FieldByName("\"date sent\"")->AsString);
}
using builder XE3
I can only get your example to run if I use
UniConnection1->ExecSQL("insert into y values(date(\"now\"))");
UniConnection1->ExecSQL("insert into y values(date(''now''))"); does not work neither does
UniConnection1->ExecSQL("insert into y values(date('now'))");
which ever variant i use I get an error "date sent" not found
UniConnection1->ExecSQL("Create table if not exists y(x date)");
UniConnection1->ExecSQL("insert into y values(date(\"now\"))");
UniQuery1->SQL->Clear();
UniQuery1->SQL->Add("select x as 'date sent' from y");
UniQuery1->Execute();
Memo2->Lines->Add(UniQuery1->FieldByName("\"date sent\"")->AsString);
}
Re: sqlite alias with a space
>UniConnection1->ExecSQL("insert into y values(date(''now''))"); //does not work neither does
Double quoting in Delphi is applied for escaping singe quotation marks.
In С++ Builder, one quotation mark is enough.
UniConnection1->ExecSQL("insert into y values(date('now'))");
>Memo2->Lines->Add(UniQuery1->FieldByName("\"date sent\"")->AsString);
When calling the field by name, there is no need to quote this field.
Memo2->Lines->Add(UniQuery1->FieldByName("date sent")->AsString);
Double quoting in Delphi is applied for escaping singe quotation marks.
In С++ Builder, one quotation mark is enough.
UniConnection1->ExecSQL("insert into y values(date('now'))");
>Memo2->Lines->Add(UniQuery1->FieldByName("\"date sent\"")->AsString);
When calling the field by name, there is no need to quote this field.
Memo2->Lines->Add(UniQuery1->FieldByName("date sent")->AsString);
Re: sqlite alias with a space
Ahh sorry - senior moment