Recent

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

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • 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

Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

GAN

  • Sr. Member
  • ****
  • Posts: 370
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̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • 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
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • 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
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

 

TinyPortal © 2005-2018