Recent

Author Topic: Why is SQLite pinching off text field at 255 characters  (Read 1537 times)

bobonwhidbey

  • Sr. Member
  • ****
  • Posts: 430
    • Double Dummy Solver - free download
Why is SQLite pinching off text field at 255 characters
« on: July 13, 2017, 10:16:53 pm »
I use these units sqldb, sqlite3conn.

The DB table has been created with
 Query.SQL.Text := 'CREATE TABLE Data (ID int, Key text,Value text, PRIMARY KEY (ID,Key));';

I can view the DB file with DBBrowser for SQLite (a great program BTW) and see that the fields in question are about 1,500 characters long.The following reads the correct fields from the table BUT truncates the data.

 Query.SQL.Text := 'SELECT * FROM Data Where Key="ScoreTable"';
 s :=Query.FieldByName('Value').AsString; // only 255 characters in s ??

I can provide sample program and DB file that illustrate the problem.  TIA for your help

Win10 64-bit / Lazarus 32-bit 2.0.10 / FPC 3.2.0

GAN

  • Sr. Member
  • ****
  • Posts: 296
Re: Why is SQLite pinching off text field at 255 characters
« Reply #1 on: July 13, 2017, 11:47:42 pm »
Key is a reserved word in SQLite, not's a good idea to use it as a field's name.
Your var s must be ANSI String:

Quote
The type String may refer to ShortString or AnsiString, depending from the {$H} switch. If the switch is off ({$H-}) then any string declaration will define a ShortString. It size will be 255 chars, if not otherwise specified. If it is on ({$H+}) string without length specifier will define an AnsiString, otherwise a ShortString with specified length. In mode delphiunicode' String is UnicodeString.
From wiki http://wiki.freepascal.org/Character_and_string_types
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7.2.6 - Sqlite 3.32.3

https://gitlab.com/users/GAN__/projects

bobonwhidbey

  • Sr. Member
  • ****
  • Posts: 430
    • Double Dummy Solver - free download
Re: Why is SQLite pinching off text field at 255 characters
« Reply #2 on: July 14, 2017, 12:33:41 am »
ansistring didn't work for me  :(

I've attached the simple program and data file that shows the issue. Only 87 KB
Win10 64-bit / Lazarus 32-bit 2.0.10 / FPC 3.2.0

bobonwhidbey

  • Sr. Member
  • ****
  • Posts: 430
    • Double Dummy Solver - free download
Re: Why is SQLite pinching off text field at 255 characters
« Reply #3 on: July 14, 2017, 12:55:27 am »
Because of size restrictions, you will have to add the sqlite3.dll to your folder.

This attachment has all other necessary files
Win10 64-bit / Lazarus 32-bit 2.0.10 / FPC 3.2.0

 

TinyPortal © 2005-2018