Page 1 of 1

sqlite alias with a space

Posted: Fri 17 Apr 2015 10:58
by sandy771
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

Re: sqlite alias with a space

Posted: Fri 17 Apr 2015 11:50
by AlexP
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.

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

Posted: Fri 17 Apr 2015 15:32
by sandy771
Hmm sorry - problem may be with another component

Re: sqlite alias with a space

Posted: Mon 20 Apr 2015 09:05
by sandy771
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

Posted: Mon 20 Apr 2015 10:28
by sandy771
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);
}

Re: sqlite alias with a space

Posted: Mon 20 Apr 2015 12:06
by AlexP
>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);

Re: sqlite alias with a space

Posted: Tue 21 Apr 2015 17:43
by sandy771
Ahh sorry - senior moment