sqlite alias with a space

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
sandy771
Posts: 194
Joined: Tue 22 May 2007 13:57

sqlite alias with a space

Post by sandy771 » Fri 17 Apr 2015 10:58

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

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: sqlite alias with a space

Post by AlexP » Fri 17 Apr 2015 11:50

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.

sandy771
Posts: 194
Joined: Tue 22 May 2007 13:57

Re: sqlite alias with a space

Post by sandy771 » Fri 17 Apr 2015 15:32

Hmm sorry - problem may be with another component

sandy771
Posts: 194
Joined: Tue 22 May 2007 13:57

Re: sqlite alias with a space

Post by sandy771 » Mon 20 Apr 2015 09:05

I have checked and although part of my issue is with another component it seems that UniDac does not like double quoted aliases

sandy771
Posts: 194
Joined: Tue 22 May 2007 13:57

Re: sqlite alias with a space

Post by sandy771 » Mon 20 Apr 2015 10:28

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);
}

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: sqlite alias with a space

Post by AlexP » Mon 20 Apr 2015 12:06

>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);

sandy771
Posts: 194
Joined: Tue 22 May 2007 13:57

Re: sqlite alias with a space

Post by sandy771 » Tue 21 Apr 2015 17:43

Ahh sorry - senior moment

Post Reply