Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
Databases
»
SOLVED: problem with count in sqlite
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
UOS - pre-compiled librar...
by
Fred vS
[
Today
at 12:34:06 am]
88 year D. Knuth changes ...
by
valdir.marcos
[March 12, 2026, 11:51:53 pm]
TChart: Wrong default val...
by
wp
[March 12, 2026, 10:14:38 pm]
Pipewire API
by
Fred vS
[March 12, 2026, 10:11:02 pm]
interface and GUID someth...
by
valdir.marcos
[March 12, 2026, 10:05:56 pm]
Hello! Anything new?
by
PascalDragon
[March 12, 2026, 09:39:09 pm]
TSplitter color property ...
by
valdir.marcos
[March 12, 2026, 09:20:11 pm]
Pocketbase
by
steve612
[March 12, 2026, 09:10:08 pm]
ShortStrings vs long stri...
by
valdir.marcos
[March 12, 2026, 08:55:02 pm]
Lazarus Bugfix Release 4....
by
dsiders
[March 12, 2026, 08:53:38 pm]
Any way to "embed" Window...
by
valdir.marcos
[March 12, 2026, 08:42:31 pm]
LazPaint (alpha-blending,...
by
CM630
[March 12, 2026, 08:38:30 pm]
Z80 ZX Spectrum and Syste...
by
d2010
[March 12, 2026, 07:58:28 pm]
could Ardour's YTK be use...
by
fifr
[March 12, 2026, 07:29:40 pm]
Qt6/Wayland clipboard: pa...
by
valdir.marcos
[March 12, 2026, 06:27:22 pm]
[ANN] PasBuild 1.5.0 rele...
by
valdir.marcos
[March 12, 2026, 06:19:54 pm]
Synchronizing Lazarus pro...
by
valdir.marcos
[March 12, 2026, 05:46:58 pm]
class not found
by
SA.Blackmon
[March 12, 2026, 05:27:32 pm]
Register global hotkey
by
Thaddy
[March 12, 2026, 04:20:28 pm]
Crystal report edit
by
Petrus Vorster
[March 12, 2026, 03:12:59 pm]
Faster asin() Was Hiding ...
by
MathMan
[March 12, 2026, 01:58:30 pm]
[ANN] PasBuild 1.6.0 rele...
by
Graeme
[March 12, 2026, 12:19:30 pm]
Debian removes FPC/Lazaru...
by
dbannon
[March 12, 2026, 08:44:10 am]
[revisited] triple click
by
dbannon
[March 12, 2026, 07:45:14 am]
Extended Module Player
by
Gigatron
[March 11, 2026, 11:33:54 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: SOLVED: problem with count in sqlite (Read 5497 times)
xaver13
Full Member
Posts: 111
SOLVED: problem with count in sqlite
«
on:
November 20, 2017, 08:05:25 pm »
Hello, I wanted to improve my working code. New lines are between "new added" and "new added end".
When I execute "Select count(ID) as cnt From wallet" in DB Browser it works fine.
But when I run this code in Lazarus, I get message on line 14 (open) about non existing column ... but this column exists!
Please any suggestions what could be wrong?
Code: Pascal
[Select]
[+]
[-]
procedure
TFormWallet2
.
FormActivate
(
Sender
:
TObject
)
;
begin
FormWallet2
.
DataSource1
.
DataSet
:
=
Query1
;
Query1
.
Close
;
SQLiteConnection1
.
Close
;
// Ensure the connection is closed when we start
SQLiteConnection1
.
Transaction
:
=
SQLTransaction1
;
SQLiteConnection1
.
DatabaseName
:
=
uWallet1
.
myHome
+
'/wallet.db'
;
SQLiteConnection1
.
Open
;
Query1
.
Database
:
=
SQLiteConnection1
;
SQLTransaction1
.
Database
:
=
SQLiteConnection1
;
SQLTransaction1
.
Active
:
=
True
;
//new added
Query1
.
SQL
.
Text
:
=
'Select count(ID) as cnt From wallet'
;
Query1
.
Open
;
ShowMessage
(
Query1
.
Fields
[
0
]
.
AsString
)
;
//recCount := Query1.Fields[0].AsInteger;
//recCount :=Query1.FieldByName('cnt').AsInteger;
//new added end
Query1
.
Close
;
Query1
.
SQL
.
Text
:
=
'Select * From wallet'
;
Query1
.
Open
;
«
Last Edit: November 21, 2017, 07:56:40 pm by xaver13
»
Logged
--
Jiri Cvrk
mangakissa
Hero Member
Posts: 1131
Re: problem with count in sqlite
«
Reply #1 on:
November 21, 2017, 08:57:42 am »
It works for me. Sometimes it's case sensitive and should the columnname set to 'id'
Have you tried to use count(*)?
Logged
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1
xaver13
Full Member
Posts: 111
Re: problem with count in sqlite
«
Reply #2 on:
November 21, 2017, 06:55:25 pm »
Quote from: mangakissa on November 21, 2017, 08:57:42 am
Have you tried to use count(*)?
Yes, I have tried count(*), with the same bad result. Maybe should be something wrong with the table? I will try to export it and import to another database.
Edited:
I have new database and tables established, but the error remains.
«
Last Edit: November 21, 2017, 07:06:17 pm by xaver13
»
Logged
--
Jiri Cvrk
xaver13
Full Member
Posts: 111
Re: problem with count in sqlite
«
Reply #3 on:
November 21, 2017, 07:56:20 pm »
This is working:
Code: Pascal
[Select]
[+]
[-]
FormWallet2
.
DataSource1
.
DataSet
:
=
Query1
;
Query1
.
Close
;
SQLiteConnection1
.
Close
;
// Ensure the connection is closed when we start
SQLiteConnection1
.
Transaction
:
=
SQLTransaction1
;
SQLiteConnection1
.
DatabaseName
:
=
uWallet1
.
myHome
+
'/wallet.db'
;
SQLiteConnection1
.
Open
;
Query1
.
Database
:
=
SQLiteConnection1
;
SQLTransaction1
.
Database
:
=
SQLiteConnection1
;
SQLTransaction1
.
Active
:
=
True
;
//new added
Query10
.
Database
:
=
SQLiteConnection1
;
Query10
.
SQL
.
Text
:
=
'Select count(id) as cnt From wallet'
;
//Query1.SQL.Text := 'Select max(id) as cnt From wallet';
Query10
.
Open
;
ShowMessage
(
Query10
.
Fields
[
0
]
.
AsString
)
;
//recCount := Query1.Fields[0].AsInteger;
//recCount :=Query1.FieldByName('cnt').AsInteger;
//new added end
Query10
.
Close
;
Query1
.
SQL
.
Text
:
=
'Select * From wallet'
;
Query1
.
Open
;
What I did not specified: the fragment of code is from a form, which uses TDBEdits, and the message was about DataField of some from it, and when I deleted this field message was changed to any TDBedit used and remained there.
When I added new Query, problem is solved. I have one piece of Connection, Transaction, Datasource but I need two Queries in this form.
«
Last Edit: November 22, 2017, 07:42:14 am by xaver13
»
Logged
--
Jiri Cvrk
mangakissa
Hero Member
Posts: 1131
Re: SOLVED: problem with count in sqlite
«
Reply #4 on:
November 22, 2017, 08:45:37 am »
That's not a problem.
Logged
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1
MacWomble
Jr. Member
Posts: 79
Re: SOLVED: problem with count in sqlite
«
Reply #5 on:
November 22, 2017, 09:05:49 am »
I use allways one special query in my applications for such special jobs like count, delete or something directly on the database - and after this, if neccassary, I send a refresh to the main query.
Logged
Mint 19.3 Cinnamon, FPC/ Lazarus Trunk 64Bit
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
Databases
»
SOLVED: problem with count in sqlite
TinyPortal
© 2005-2018