[Lazarus] SQLite & DB Aware Components

LacaK lacak at zoznam.sk
Fri Dec 2 07:13:27 CET 2016


Dňa 1.12.2016 o 21:40 Martin Collins via Lazarus napísal(a):
> On 01/12/16 16:15, Martin Collins via Lazarus wrote:
>>  From what I understand, SQLite TEXT type has no set length so db aware
>> components treat it as a memo. Therefore when I assign a TEXT field to a
>> db aware component, all that appears in the component is "(MEMO)", even
>> though most of my TEXT fields are only up to 10-30 characters long.
>> Solutions offered on-line suggest using a dbmemo (which I have for my
>> longer TEXT fields as that's what I want), but I need to use dbgrids,
>> dbedits, dbcomboboxs, etc for the shorter TEXT fields.
>>
> I have found a solution to my problem, with thanks to the following link:
>
> http://www.tweaking4all.com/software-development/lazarus-development/lazarus-pascal-getting-started-with-sqlite/#ATEXTfieldshowsamemoinaDBGrid
>
> The answer was altering my SQL Query text, from something like this:
>
> SELECT
>    "Filename",
>    "Date"
> FROM
>    "mytable";
>
> to this:
>
> SELECT
>    CAST( "Filename" AS VARCHAR) AS "Filename",
>    "Date"
> FROM
>    "mytable";
>
> Casting it as a different type in the SQL statement worked!
You are not required to that if you have declared table "mytable" as:
CREATE TABLE "mytable" (
  FileName varchar(100),
  Date datetime
)

-Laco


More information about the Lazarus mailing list