#1 2021-08-22 21:16:19

florian
Member
Registered: 2021-08-22
Posts: 7

TSQLDBSQLite3ConnectionProperties.execute variant error only on window

I made a little sample procedure to illustrate my problem.
The following code works fine on Linux however on Windows I get an exception:"could not convert variant of type (Null) into type (String)"
I am using Lazarus 2.0.10 and the latest mORMot from github

procedure Test();
var connection: TSQLDBSQLite3ConnectionProperties;
    V: Variant;
    s: String;
begin
  connection := TSQLDBSQLite3ConnectionProperties
    .create(ExeVersion.ProgramFilePath+'Test.db','','','');
  try
      with connection.Execute('SELECT strftime(''%H:%M'',datetime(current_timestamp,''localtime'')) as t;',[],@V) do begin
       while Step do begin
         s := v.t; //could not convert variant of type (Null) into type (String) , only occurs on windows
         showMessage(s);
       end;
        ReleaseRows;
      end;
  finally
   connection.free;
  end;
end; 

   


What am I missing?

Offline

#2 2021-08-23 07:05:58

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,345
Website

Re: TSQLDBSQLite3ConnectionProperties.execute variant error only on window

I guess you are using FPC 3.2.2.

This sounds like a FPC bug, when you use a late-binding symbol of 1 char only.
See https://synopse.info/forum/viewtopic.php?id=5894

If you use "tim" instead of "t" it should work.

Offline

#3 2021-08-23 07:38:27

florian
Member
Registered: 2021-08-22
Posts: 7

Re: TSQLDBSQLite3ConnectionProperties.execute variant error only on window

Thanks.

But that's not it. I'm using FPC 3.2.0
If I use "tim" instead of "t" the problem persists.

Offline

#4 2021-08-23 10:26:12

florian
Member
Registered: 2021-08-22
Posts: 7

Re: TSQLDBSQLite3ConnectionProperties.execute variant error only on window

Seems to have something to do with the 'localtime' parameter in the sqlite datetime function.

procedure Test();
var connection: TSQLDBSQLite3ConnectionProperties;
    query1, query2: String;
begin
  query1 := 'SELECT datetime(current_timestamp,''localtime'');'; //works only on linux
  query2 := 'SELECT datetime(current_timestamp);'; //works on linux and windows

  connection := TSQLDBSQLite3ConnectionProperties
    .create(ExeVersion.ProgramFilePath+'Test.db','','','');
  try
      with connection.Execute(query1,[]) do begin
       if step then showmessage(TimeToStr(ColumnDateTime(0))); //ColumnDateTime(0) returns 0 on windows, works on linux
       ReleaseRows;
      end;
  finally
   connection.free;
  end;
end;  

Any ideas?

Offline

#5 2021-08-24 06:02:44

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,345
Website

Re: TSQLDBSQLite3ConnectionProperties.execute variant error only on window

Good finding.
I will investigate.

Update 1: the localtime is not compiled with our SQlite3 because we defined SQLITE_OMIT_LOCALTIME in the compilation script to avoid linking issues.
I will fix it.

Update 2: I have included new localtime32/64() exports as needed by mingw.
A new SQLite3 compilation was needed. So it requires to download some new static binaries.

Offline

#6 2021-08-24 10:57:28

florian
Member
Registered: 2021-08-22
Posts: 7

Re: TSQLDBSQLite3ConnectionProperties.execute variant error only on window

It works now, nice!

Thank you.

Offline

Board footer

Powered by FluxBB