[fpc-pascal] EDatabaseError on SELECT

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Wed Feb 10 15:36:43 CET 2016


Hello,

I'm posting here because this seams to be an issue with using sqldb,
my SQL seams to be ok.

I create a table and add a row to it, but when trying to read that
same row using SELECT I get EDatabase error with message "Syntax error
near SELECT".

I create the Table and add a row to it like this:

  FSQLConn := TSQLite3Connection.Create(nil);
  FSQLTran := TSQLTransaction.Create(nil);
  FQuery := TSQLQuery.Create(nil);
  FQuery.DataBase := FSQLConn;
  FQuery.Transaction := FSQLTran;
.........
  lTableName := GetTableName(AListNr, dtkHeader);
  lSQL := Format('CREATE TABLE "%s"( "ID" INTEGER,'+
    ' "Block_NrOfItems" INTEGER, "Block_ParentList" INTEGER,'+
    ' "Block_IndexIn_ParentList" INTEGER, "Block_Kind" INTEGER,'+
    ' "Block_Name" TEXT);', [lTableName]);
  FSQLConn.ExecuteDirect(lSQL);

  lSQL := Format('INSERT INTO %s (ID, Block_NrOfItems, Block_ParentList,'+
    ' Block_IndexIn_ParentList, Block_Kind, Block_Name)'+
    ' VALUES (%u, %u, %u, %s, %u, ''%s'')',
    [lTableName, UINT32_ID_SINGLE_ROW_TABLE,
     AData.NrOfItems, AData.ParentList,
     IntToStr(AData.IndexIn_ParentList),
     AData.Kind, AData.Name]);
  FSQLConn.ExecuteDirect(lSQL);
  FSQLTran.Commit;

Here is the SELECT with error:

  lTableName := GetTableName(AListNr, dtkHeader);
  lSQL := Format('SELECT * FROM "%s" WHERE ID=%u', [lTableName,
UINT32_ID_SINGLE_ROW_TABLE]);
  FQuery.SQL.Add(lSQL);
  FQuery.Open; // <- EDatabaseError

I tested with sqlite3 command line and the same statement issues no
syntax error ...

Any ideas???

lTableName = Header_0
UINT32_ID_SINGLE_ROW_TABLE=0

thanks,
-- 
Felipe Monteiro de Carvalho



More information about the fpc-pascal mailing list