[yunqa.de] Re: Determining size of TDISQLite3WideStringField

  • From: Delphi Inspiration <delphi@xxxxxxxx>
  • To: yunqa@xxxxxxxxxxxxx
  • Date: Sat, 05 Apr 2008 20:00:25 +0200

Yeoh Ray Mond wrote:

>How can I retrieve the size of a specific column in a SQLite table using 
>DISQLite?  I am retrieving data, and need to store a subset of that data in an 
>in-memory table.  In order to create that table, I need to know the 
>definitions of each field.  For a field identified as a 
>TDISQLite3WideStringField, the size returned is always 20.

Your question points to an old TDataSet limitation which dates back to when 
database could store fixed length strings only. To support those engines (BDE 
mostly), a TStringField.Size property to limit the length of string fields made 
complete sense.

Not so for DISQLite3! SQLite has no practical limits on string fields: It 
happily stores strings from 0 to 1000000000 characters in length. But even this 
number is only intended to avoid abuse -- the technical limit is as high as 
2E31-1.

So the answer to your question is: There is no maximum field size in DISQLite3, 
and TDISQLite3WideStringField takes care to reflect this by storing strings of 
any length, no mattern what its Size property specifies. The 
TDISQLite3WideStringField.Size = 20 only reflects the default size for 
TStringField.Size to give applications some posivite value instead of just 
returning 0.

>Is it possible to retrieve the maximum size of that field in the returned 
>result set, without having to calculate it manually?

No, this is not provided for because it could cause data loss when retrieving 
strings from the database which exceed the maximum size. So if you really must 
set a limit for your in-memory-table, you need to scan through all records or 
execute "SELECT max(length(StringField)) FROM Table;"

As an alternative, you might just want to set the field size to the maximum 
value. Best would of course be an in-memory table implementation which 
allocates memory only as required and/or does not pose any limitations on 
string field size in the first place.

Ralf  

_______________________________________________
Delphi Inspiration mailing list
yunqa@xxxxxxxxxxxxx
//www.freelists.org/list/yunqa



Other related posts: