Recent

Author Topic: Lazarus 4.2 sqlite3 db  (Read 5472 times)

Brownfox

  • Guest
Lazarus 4.2 sqlite3 db
« on: August 22, 2025, 02:28:43 pm »
Hi,
I am a beginner and I am trying to build a very simple daat base for my club.
I want display a field in a DBmemo, I have added a DBmemo, set datasouce and data field and add this line in procedure add :
SQLQuery.Params.ParamByName('Cotis').AsString := DBMemo1.Lines.Text;
I don't get compiler error but it doesn't work so I need some help.
I apologize for my bad English.
Thanks and Salutations
Bernard.

BlueIcaro

  • Hero Member
  • *****
  • Posts: 834
    • Blog personal
Re: Lazarus 4.2 sqlite3 db
« Reply #1 on: August 22, 2025, 08:42:36 pm »
Hello, You don't give us a lot off information. Please show your code.
Also If you are starting with DataBase in Lazarus you can check the wiki: https://wiki.freepascal.org/SQLdb_Tutorial1

/BlueIcaro

Brownfox

  • Guest
Re: Lazarus 4.2 sqlite3 db
« Reply #2 on: August 26, 2025, 11:47:15 am »
Hi,
Thanks for your reply.

Code: Pascal  [Select][+][-]
  1.       // Requête INSERT
  2.       SQLQuery.SQL.Text := 'INSERT INTO adherents (Nom, Prenom,Mail,Adresse,Tel, Date,Cotis) VALUES (:Nom, :Prenom,:Mail, :Adresse, :Tel, :Date,:Cotis)';
  3.       SQLQuery.Params.ParamByName('Nom').AsString     := EditNom.Text;
  4.       SQLQuery.Params.ParamByName('Prenom').AsString  := EditPrenom.Text;
  5.       SQLQuery.Params.ParamByName('Mail').AsString    := EditMail.Text;
  6.       SQLQuery.Params.ParamByName('Adresse').AsString := EditAdresse.Text;
  7.       SQLQuery.Params.ParamByName('Tel').AsString     := EditTel.Text;
  8.       SQLQuery.Params.ParamByName('Cotis').AsString := AnsiString(DBMemo1.Lines.Text);
  9.  
In the sqlite3  table, the field cotis is set as text.
DBMemo1 datasource and datafield are set + r/w ok
The first 5 lines are ok in DBGrid
What is wrong in this line : SQLQuery.Params.ParamByName('Cotis').AsString := AnsiString(DBMemo1.Lines.Text);     ?
Merci ;)

Zvoni

  • Hero Member
  • *****
  • Posts: 3396
Re: Lazarus 4.2 sqlite3 db
« Reply #3 on: August 26, 2025, 12:31:58 pm »
Code: Pascal  [Select][+][-]
  1. SQLQuery.Params.ParamByName('Cotis').AsString := AnsiString(DBMemo1.Lines.Text);
  2. //Change to
  3. SQLQuery.Params.ParamByName('Cotis').AsMemo := DBMemo1.Lines.Text;
  4.  
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

Brownfox

  • Guest
Re: Lazarus 4.2 sqlite3 db
« Reply #4 on: August 26, 2025, 01:27:05 pm »
Thank you, but that doesn't work.

paweld

  • Hero Member
  • *****
  • Posts: 1636
Re: Lazarus 4.2 sqlite3 db
« Reply #5 on: August 26, 2025, 03:03:51 pm »
This is because TDBMemo does not contain any data - it is only a link to a field in the database.
So either use TMemo:
Code: Pascal  [Select][+][-]
  1. SQLQuery.Params.ParamByName('Cotis').AsMemo := Memo1.Lines.Text;
or retrieve the relevant data and DBMemo:
Code: Pascal  [Select][+][-]
  1. SQLQuery.Params.ParamByName('Cotis').AsMemo := DBMemo1.Field.Text;
Best regards / Pozdrawiam
paweld

Brownfox

  • Guest
Re: Lazarus 4.2 sqlite3 db
« Reply #6 on: August 26, 2025, 08:20:14 pm »
Hi, thanks for your reply.
When I add a member I fill DBMemo, it is not empty.
In order to debug, I added an Tedit and a button:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   Edit1.Text := DBMemo1.Lines.Text;
  4. end;                  
And edit1 contains what I wrote in DBMemo.
I wonder why DBMemo is not in the table field.
May be because i create the table with a python script ?????, I'm lost ;)

cdbc

  • Hero Member
  • *****
  • Posts: 2807
    • http://www.cdbc.dk
Re: Lazarus 4.2 sqlite3 db
« Reply #7 on: August 26, 2025, 09:41:45 pm »
Hi
Attached is a small Sqlite3-Demo-App, you can have a look at...
It amo. deals with memo-text...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

CharlyTango

  • Full Member
  • ***
  • Posts: 180
Re: Lazarus 4.2 sqlite3 db
« Reply #8 on: August 27, 2025, 12:29:45 am »
@cdbc cannot compile the demo with fixes/fixes 4.3

istrlist.pas(39,41) Error: Cannot find sortbase used by istrlist.

BTW: you give a beginner a MVC Solution as a Demo ?
« Last Edit: August 27, 2025, 12:34:46 am by CharlyTango »
Lazarus stable, Win32/64

cdbc

  • Hero Member
  • *****
  • Posts: 2807
    • http://www.cdbc.dk
Re: Lazarus 4.2 sqlite3 db
« Reply #9 on: August 27, 2025, 01:03:19 am »
Hi
To compile in fpc fixes you have to change this:
Code: Pascal  [Select][+][-]
  1. {$ifNdef VER3_2_2}
to this:
Code: Pascal  [Select][+][-]
  1. {$if fpc_fullversion > 30204}
The 'istrlist' was implemented before fpc fixes was thought of and I wasn't aware that it wouldn't compile -- sorry mate.

In all fairness, it's /not/ the full-blown MVC, just a sane separation of concerns -- MV If you like -- ...and why shouldn't a newbie learn the good practices from the 'GetGo'?!?  ;)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

CharlyTango

  • Full Member
  • ***
  • Posts: 180
Re: Lazarus 4.2 sqlite3 db
« Reply #10 on: August 27, 2025, 01:03:46 am »
@Brownfox:
Yes there are different and more sophisticated methods to create a database application.
All of them have their justification and purpose, depending on the size of the project, its use, and the programmer's experience.
You described yourself as a beginner, so I'll show you how to solve your problem using Lazarus's built-in tools.

You don't have to deal with parameters at all, because Lazarus's database components do that for you.

In the small test application, you will see a simple mask in the fcustomer.pas form.
The form only contains a grid, several data-sensitive input fields, and a DBNavigator that takes control.
The database components determine how to handle the assigned SQL statement.
Of course, you can make everything more beautiful and complex, but this should be enough for a first understanding.

Lazarus stable, Win32/64

CharlyTango

  • Full Member
  • ***
  • Posts: 180
Re: Lazarus 4.2 sqlite3 db
« Reply #11 on: August 27, 2025, 01:13:34 am »
...and why shouldn't a newbie learn the good practices from the 'GetGo'?!?  ;)

Because maybe he should walk first, then run, and only later jump and fly.

I agree with you that some things aren't ideal (although MVC is pretty awesome). But if I had been presented with something like that when I was starting out, I would have run away screaming.

I can talk about an theme that I really understand.
Let's just say that it's probably not very wise from a teaching perspective to confront a talented beginner dancer with highly complex movements.   ;)
Lazarus stable, Win32/64

cdbc

  • Hero Member
  • *****
  • Posts: 2807
    • http://www.cdbc.dk
Re: Lazarus 4.2 sqlite3 db
« Reply #12 on: August 27, 2025, 01:23:53 am »
Hi
Okidoki, duly noted, but WTH, maybe someday he'll appreciate it  8-)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

CharlyTango

  • Full Member
  • ***
  • Posts: 180
Re: Lazarus 4.2 sqlite3 db
« Reply #13 on: August 27, 2025, 08:21:57 am »
After taking a closer look, I can say with certainty that he will appreciate it—maybe in a year or two. O:-)

But there are some things that even an old dog like me can learn, while others I don't understand strategically, but you'll have your reasons.
Lazarus stable, Win32/64

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: Lazarus 4.2 sqlite3 db
« Reply #14 on: August 28, 2025, 01:06:50 am »
Hello,
you can have a look to my sqlite3 Database example project in the examples of Lazarus ( examples/database/image_mushrooms). In the Gui you have a TDbMemo (Notes)
And in the code you can recreate the structure of the sqlite 3 database from sql :
Code: Pascal  [Select][+][-]
  1.       SQLite3Connection1.ExecuteDirect(
  2.       'CREATE TABLE DeadlyMushrooms '+LineEnding+
  3.       '-- This table created by Jurassic Pork '+LineEnding+
  4.       '-- for Free Pascal Lazarus '+LineEnding+
  5.       '-- Create date:2013-08-05 23:55:09 '+LineEnding+
  6.       '( '+LineEnding+
  7.       '       ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, '+LineEnding+
  8.       '       Scientific_Name VARCHAR NOT NULL, '+LineEnding+
  9.       '       Common_Name VARCHAR, '+LineEnding+
  10.       '       `Order`  VARCHAR, `Genus`  VARCHAR, `Notes`  TEXT, `Picture`  BLOB, `Image_Link`  VARCHAR)'
  11.       );
The example needs the packages lazreport, SQLDBLaz to be installed.

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

 

TinyPortal © 2005-2018