Recent

Author Topic: [SOLVED] TSQLQuery returns STRINGS as MEMO from SQLITE3  (Read 1116 times)

TheNick

  • New Member
  • *
  • Posts: 24
  • Pax vobiscum
[SOLVED] TSQLQuery returns STRINGS as MEMO from SQLITE3
« on: June 28, 2023, 07:51:55 pm »
Hi,
Why does the TSQLQuery returns datatype MEMO when the field are defined as TEXT that per definition is declared as STRING in SQLITE3?

Lazarus 2.2.6
FPC 3.2.2
Running on x86_64-linux-gtk2
« Last Edit: June 29, 2023, 09:22:14 pm by TheNick »
Never give up, never surrender! 😃

dsiders

  • Hero Member
  • *****
  • Posts: 1464
Re: TSQLQuery returns STRINGS as MEMO from SQLITE3
« Reply #1 on: June 28, 2023, 10:32:35 pm »
Hi,
Why does the TSQLQuery returns datatype MEMO when the field are defined as TEXT that per definition is declared as STRING in SQLITE3?

Lazarus 2.2.6
FPC 3.2.2
Running on x86_64-linux-gtk2

Please use the forum search function. This has been asked and answered at least a dozen times.
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

TheNick

  • New Member
  • *
  • Posts: 24
  • Pax vobiscum
Re: TSQLQuery returns STRINGS as MEMO from SQLITE3
« Reply #2 on: June 28, 2023, 10:34:32 pm »
Thank you, but did try that with no luck.
Never give up, never surrender! 😃

Zvoni

  • Hero Member
  • *****
  • Posts: 3135
Re: TSQLQuery returns STRINGS as MEMO from SQLITE3
« Reply #3 on: June 29, 2023, 08:52:15 am »
Code: SQL  [Select][+][-]
  1. SELECT CHAR(SomeTextColumn) AS Field1 FROM SomeTable
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1315
Re: TSQLQuery returns STRINGS as MEMO from SQLITE3
« Reply #4 on: June 29, 2023, 09:17:17 am »
While the SQL syntax requires you to specify data types for your fields, SQLite treats those as recommendations, unless you define the tables as "STRICT" (which is fairly new). Normally, SQLite only has a single, unified datatype. Variants. When in doubt, it's advisable to cast fields to the required format.

Some databases have lots of more or less the same data types, like (for MS SQL) fixed-length strings, strings that can grow up to a specified size, large blocks of text that sometimes don't allow much manipulation (memos), the same ones for variable-length chars, etc. While others (notably, SQLite and PostgreSQL) combine all those to a single type: text. This is also the default way to store most data in SQLite. And while you can specify the other variants in PostgreSQL, they're treated like text fields with an optional maximum length.




TheNick

  • New Member
  • *
  • Posts: 24
  • Pax vobiscum
Re: TSQLQuery returns STRINGS as MEMO from SQLITE3
« Reply #5 on: June 29, 2023, 09:19:05 pm »
Thank you @Zvoni and @SymbolicFrank! Learned something new tonight! :)

I have tried out to do it this way:
select cast(Name as varchar(255)), cast(Club as varchar(255)) from contenders where contendernbr=1;

I will experiment with @SymbolicFrank way of doing it.

Cheers,
Niclas
Never give up, never surrender! 😃

 

TinyPortal © 2005-2018