Recent

Author Topic: Data from SQLite  (Read 1611 times)

amedeo

  • New Member
  • *
  • Posts: 35
Data from SQLite
« on: November 23, 2019, 01:39:31 pm »
Hallo, sorry for may bad english.
I am doing my first DB using Lazarus+SQLite and I have a ploblem showing data in a TDBGrid.
I build DB and TABLE using "DB Browser for SQLite" and I populated the TABLE with 3 recors. It is ok, I saw it.
In Lazarus I build the application with one form and: TSQlite3Connection, TSQLTransaction, TSQLQery, TDataSorce and a TDBGrid with all this objects connected, I thik, well. I see all columns and the correct numbers of rows and the value of the first field that is a interger AutoIncrement, in the remaining fields of the TDBGrid I see just "MEMO".
Someone can help me to understand and solve this problem?
Thaks

fmc

  • New Member
  • *
  • Posts: 37
Re: Data from SQLite
« Reply #1 on: November 23, 2019, 02:26:27 pm »
Try this:

Click on your DBGrid and go to your Object Inspector.
Scroll down and click Options, then tick dgDisplayMemoText.

 It's been a while since I used the stock DBGrid that comes with Lazarus, but I think that'll do the trick for you.

Btw, your English is fine.
Win X Pro / Lazarus 2.0.6 / FPC 3.0.4

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: Data from SQLite
« Reply #2 on: November 23, 2019, 02:42:51 pm »
And don't use AUTOINCREMENT on your Primary Key in SQLite
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

fmc

  • New Member
  • *
  • Posts: 37
Re: Data from SQLite
« Reply #3 on: November 23, 2019, 03:11:57 pm »
To further Zvoni's reply, this is how it works:

If you have a table that's:
Code: Pascal  [Select][+][-]
  1. CREATE TABLE IF NOT EXISTS customers(
  2.     cust_id INTEGER PRIMARY KEY,
  3.     cust_fname VARCHAR(20),
  4.     cust_lname VARCHAR(20));

the cust_id column will increment on its own. However if the table drops all rows, it starts from the beginning again.

As where if you use:
Code: Pascal  [Select][+][-]
  1. CREATE TABLE IF NOT EXISTS customers(
  2.     cust_id INTEGER PRIMARY KEY AUTOINCREMENT,
  3.     cust_fname VARCHAR(20),
  4.     cust_lname VARCHAR(20));

and dropped a row (or all of them again), it will start with the last cust_id that was in use. That's the difference.

So either works fine.
« Last Edit: November 23, 2019, 03:15:55 pm by fmc »
Win X Pro / Lazarus 2.0.6 / FPC 3.0.4

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Data from SQLite
« Reply #4 on: November 23, 2019, 03:12:19 pm »
Hallo, sorry for may bad english.
I am doing my first DB using Lazarus+SQLite and I have a ploblem showing data in a TDBGrid.
I build DB and TABLE using "DB Browser for SQLite" and I populated the TABLE with 3 recors. It is ok, I saw it.
In Lazarus I build the application with one form and: TSQlite3Connection, TSQLTransaction, TSQLQery, TDataSorce and a TDBGrid with all this objects connected, I thik, well. I see all columns and the correct numbers of rows and the value of the first field that is a interger AutoIncrement, in the remaining fields of the TDBGrid I see just "MEMO".
Someone can help me to understand and solve this problem?
Thaks
It will be easier to help you, if you attach a small sample project.
Maybe, you should review your SQLite's table structure.

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: Data from SQLite
« Reply #5 on: November 23, 2019, 03:42:52 pm »
To further Zvoni's reply, this is how it works:

If you have a table that's:
Code: Pascal  [Select][+][-]
  1. CREATE TABLE IF NOT EXISTS customers(
  2.     cust_id INTEGER PRIMARY KEY,
  3.     cust_fname VARCHAR(20),
  4.     cust_lname VARCHAR(20));

the cust_id column will increment on its own. However if the table drops all rows, it starts from the beginning again.

As where if you use:
Code: Pascal  [Select][+][-]
  1. CREATE TABLE IF NOT EXISTS customers(
  2.     cust_id INTEGER PRIMARY KEY AUTOINCREMENT,
  3.     cust_fname VARCHAR(20),
  4.     cust_lname VARCHAR(20));

and dropped a row (or all of them again), it will start with the last cust_id that was in use. That's the difference.

So either works fine.
Yes, to a degree. The amount of data not withstanding, why i prefer no AUTOINCREMENT in SQLite:
From the SQLite-Dox:
Quote
f a column has the type INTEGER PRIMARY KEY AUTOINCREMENT then a slightly different ROWID selection algorithm is used. The ROWID chosen for the new row is at least one larger than the largest ROWID that has ever before existed in that same table. If the table has never before contained any data, then a ROWID of 1 is used. If the largest possible ROWID has previously been inserted, then new INSERTs are not allowed and any attempt to insert a new row will fail with an SQLITE_FULL error. Only ROWID values from previous transactions that were committed are considered. ROWID values that were rolled back are ignored and can be reused.
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

amedeo

  • New Member
  • *
  • Posts: 35
Re: Data from SQLite
« Reply #6 on: November 23, 2019, 05:42:57 pm »
Solved. A lot of thanks, the proble is just to check an option  :D :D :D

fmc

  • New Member
  • *
  • Posts: 37
Re: Data from SQLite
« Reply #7 on: November 23, 2019, 05:46:15 pm »
Yeah  :D
Win X Pro / Lazarus 2.0.6 / FPC 3.0.4

 

TinyPortal © 2005-2018