Recent

Author Topic: [SOLVED] Tsqlite3dataset locate fails on memo fields  (Read 9035 times)

JanRoza

  • Hero Member
  • *****
  • Posts: 672
    • http://www.silentwings.nl
[SOLVED] Tsqlite3dataset locate fails on memo fields
« on: September 12, 2010, 06:48:07 pm »
In my program I've build in a search function on a tsqlite3dataset which works okay on all fields except on memo fields.
So if memo field contains "My shoes are new" and I search for "shoes" it is not found whereas if memo contains "Shoes are made for walking" it is found.
In the sqlite4fpc website in tutorial 3 I see a reference made to soWildCardKey which should make possible what I want.
Is this correct?
And if so how do I set this option on runtime via coding, I tried:

Code: [Select]
tblVluchten.Options := [soWildcardKey];
Code: [Select]
tblVluchten.Options := '[soWildcardKey]';
Code: [Select]
tblVluchten.Options := soWildcardKey;
but none of this compiles.
Can anyone tell me the correct syntax to achieve this?

Thanks!

Jan
(Lazarus 0.9.29 and fpc 2.4.3)
« Last Edit: September 13, 2010, 09:22:28 pm by JanRoza »
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
       Lazarus 3.2 FPC 3.2.2
       CodeTyphon 8.40 FPC 3.3.1

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 457
Re: Tsqlite3dataset locate fails on memo fields
« Reply #1 on: September 13, 2010, 03:46:38 am »
this would work:

tblVluchten.Options := [soWildcardKey];

(It's necessary the CustomSqliteDS in uses clause)

or set Options.soWildkardKey to true in Lazarus object inspector

BTW: i dont know if the version of 2.4.3 has this feature. Search soWildcardKey in CustomSqliteDS.pas. If not you must use the one found in http://sqlite4fpc.yolasite.com/ (read the instructions)

After that do:

Locate('Name', '*shoes*', [loCaseInsensitive]);


JanRoza

  • Hero Member
  • *****
  • Posts: 672
    • http://www.silentwings.nl
Re: Tsqlite3dataset locate fails on memo fields
« Reply #2 on: September 13, 2010, 08:31:01 pm »
I checked my version of CustomSqliteDS and it already had the soWildcardKey in it.
But your tip to include CustomSqliteDS in the uses clause was the golden tip, it works like a charme now.
Never knew of the existence of CustomSqliteDS so hadn't include it.
Would it not be better to automatically include it if a tsqlite3dataset is selected and place on a form?
Anyway I've learned something again tonight and won't forget this one!

Thanks Luiz  ;D
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
       Lazarus 3.2 FPC 3.2.2
       CodeTyphon 8.40 FPC 3.3.1

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 457
Re: [SOLVED] Tsqlite3dataset locate fails on memo fields
« Reply #3 on: September 13, 2010, 09:29:11 pm »
Quote
Would it not be better to automatically include it if a tsqlite3dataset is selected and place on a form?

I will take a look to see if is possible

anderson5420

  • New Member
  • *
  • Posts: 16
Re: [SOLVED] Tsqlite3dataset locate fails on memo fields
« Reply #4 on: March 11, 2011, 09:35:04 pm »
First, I would really like to thank Luiz for the Sqlite3Dataset component, it is both the easiest to use and most reliable database component going!

Everything works in my little paper file indexing program except the wildcard locates. I do have my FilesDataset.Options set to [soWildcardKey] (happens in the form's OnCreate event), have CustomSqliteDS in my main unit Uses clause, and am using the *wildcards in the SearchEdit, but it still is not working.  Some questions:

1 - Is there something else I could be overlooking with the wildcard locate?  This is really the last functionality that I want to implement.

2 - Just a confirmation, Locate and LocateNext only accept a single field, they do not accept a comma separated list of fields, correct?

3 - As an alternate, how would you build a select...where Field1, Field 2 like [SearchEdit.Text] order by Field1, Field2 to assign to the FilesDatast.SQL property?  I have tried everything I can think of, I know the literal ' character is '', but no she go...

Thanks!

« Last Edit: March 11, 2011, 09:37:14 pm by anderson5420 »

anderson5420

  • New Member
  • *
  • Posts: 16
Re: [SOLVED] Tsqlite3dataset locate fails on memo fields
« Reply #5 on: March 13, 2011, 02:34:33 am »
OK, answered question 3 this afternoon - this seems much more powerful than Locate / LocateNext because it selects the records that have the search text in any fields you specify, with each field taking a separate where [Field] like '%[SearchText]%'  Here is what works:

Code: [Select]
SQLText := 'select * from files where Filename like '''+'%'+SearchText+'%'
      + ''' or Reference like '''+'%'+SearchText+'%'+''' or Comments like '''+'%'
      + SearchText+'%'+''' order by Reference, Filename';    

When the user clicks the "Go" button, the select statement above returns all the records containing the SearchText in either the Reference, the Filename or the Comments fields.  The '%' is the wildcard character for the 'like' statement, matching any text before or after the SearchText. There is a "Clear Search" button that sets the SearchEdit.Text to '' and executes a 'select * from files order by Reference, Filename' - next up, add in the error checking I skipped over while trying to get the basic functionality working!  Fun!

  
« Last Edit: March 13, 2011, 02:45:04 am by anderson5420 »

totya

  • Hero Member
  • *****
  • Posts: 720
Re: [SOLVED] Tsqlite3dataset locate fails on memo fields
« Reply #6 on: April 24, 2015, 07:33:32 pm »
In my program I've build in a search function on a tsqlite3dataset which works okay on all fields except on memo fields.
So if memo field contains "My shoes are new" and I search for "shoes" it is not found whereas if memo contains "Shoes are made for walking" it is found.
In the sqlite4fpc website in tutorial 3 I see a reference made to soWildCardKey which should make possible what I want.

This topic doesn't solved really, because this problem is stay, soWildCardKey doesn't work:

http://sqlite4fpc.yolasite.com/dataset-tutorial-3.php
Quote
It's also possible to use wildcards in the search key, e.g., searching for '*Paul*' will match any value that has 'Paul' regardless of the position. To enable this option set soWildCardKey in ContactsDataset.options.

I played a bit around this bug, and I have found the solution, if loPartialKey removed from "Tutorial 03" code:

Code: [Select]
Options := [loCaseInsensitive, loPartialKey];
then wildcard search is working.

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 457
Re: [SOLVED] Tsqlite3dataset locate fails on memo fields
« Reply #7 on: April 26, 2015, 06:47:21 pm »
I adjusted the tutorial to remark that wild and partial search are mutually exclusive

totya

  • Hero Member
  • *****
  • Posts: 720
Re: [SOLVED] Tsqlite3dataset locate fails on memo fields
« Reply #8 on: April 26, 2015, 07:27:13 pm »
I adjusted the tutorial to remark that wild and partial search are mutually exclusive

Hi!

It's a good idea, but I think the best, if something Exception come from the source code (Locate/Locatenext), if these two options selected both. :)

Edit.:

Wait a moment, first, if you are the developer of Tsqlite3dataset then thank you, the second, I think the downloadable component on this site is older than recent Lazarus source (I compared them).
« Last Edit: April 26, 2015, 07:33:51 pm by totya »

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 457
Re: [SOLVED] Tsqlite3dataset locate fails on memo fields
« Reply #9 on: April 27, 2015, 09:52:35 pm »
Thanks. I updated the site.

Having both loPartialKey and soWildCard options has valid use cases (think that you mostly use wild search, but in specific cases wants to use partial search), so no need to throw an error

 

TinyPortal © 2005-2018