Topic: SQL query

Hello,
I am in trouble with this simple SQL statement : 'select distinct f_nom from personnes';
The query works fine with SqliteToolBox, directly with sqlite3 and others programs but fails in my unit.  Of course  'select f_nom from personnes'  works correctly.
you have a track?

Regards
agur

Re: SQL query

Hi Agur,

I don't have much information to find out what's going wrong with the query. SqliteToolbox is based on sqlitepass library with no add-on so if your query works inside SqliteToolbox it should also works with your unit.

You can check how SqliteToolbox handles your query by running the program inside the IDE and step through the code or you can send your code and db if your data or code are not confidential.

Regards.

Luc

Re: SQL query

Bonsoir Agur,

Après quelques essais, voici deux options pour solutionner ton problème.

Soit mettre le dataset en readonly := true avant d'exécuter la requête "select distinct..."
Soit changer le code suivant dans le fichier  SqlitePassSQLSmts.inc et recompiler la library.

Procedure TSqlitePassSelectStmt.AddPrimaryKeys;
  ....
  Tokenizer.Text := SQLSections.GetSectionText(kwSelect);
  Tokenizer.InsertAfter(kwSelect, FPrimaryKeyStmt);
  SQLSections.SetSectionTextFromTokenizer(kwSelect, Tokenizer);
  FPrimaryKeyCount := TablesName.Count;
  ...

par celui-ci

  Tokenizer.Text := SQLSections.GetSectionText(kwSelect);

  if Tokenizer.Locate(kwDistinct)
     then Tokenizer.InsertAfter(kwDistinct, FPrimaryKeyStmt)
     else Tokenizer.InsertAfter(kwSelect, FPrimaryKeyStmt);
  
  SQLSections.SetSectionTextFromTokenizer(kwSelect, Tokenizer);
  FPrimaryKeyCount := TablesName.Count;

La deuxième solution sera incluse dans la prochaine version. Elle évite le message d'erreur mais ne retourne pas une requête "Distinct"  réelle puisque une colonne rowid est ajoutée à la requête (pour écrire dans la base de données si besoin) et fausse le résultat. Donc, je te propose d'utiliser la 1ère solution.

@+

Luc