Recent

Author Topic: Database example without GUI  (Read 2072 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 8000
Re: Database example without GUI
« Reply #15 on: November 01, 2024, 06:07:53 pm »
i have the transaction in line 35

Hmm. I admit that I overlooked that since it's not the "usual idiom"...

Code: Pascal  [Select][+][-]
  1.     sqlite3.Transaction:= TSQLTransaction.Create(sqlite3); // Your line 35
  2.  

But in your program that works you've got

Code: Pascal  [Select][+][-]
  1.       dbtrans:= TSQLTransaction.Create(nil);
  2.       sqlite3.Transaction := dbtrans;
  3.  

...which /is/ the usual idiom. So there's two changes there: the first is that you're no longer relying on the connection object to store the (pointer to the) transaction object, and the second is the nil parameter.

Referring to the documentation root at https://www.freepascal.org/docs.html hence via the FCL https://www.freepascal.org/docs-html/current/fcl/sqldb/tsqltransaction.create.html:

"AOwner Owner of the transaction component."

Deferring to the example from @dseligo, I note that he also uses a nil parameter: I suspect that you were setting up some sort of circular reference.

I also admit to being slightly uncomfortable with the number of times different database components need to be told about each other, and am particularly uncomfortable when this is done using the object inspector (effectively embedded in the form designer) of a GUI app. But it's a complex area and by and large the implementers have done a good job making the same framework work over a fairly wide number of backends...

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Tanto

  • New Member
  • *
  • Posts: 13
Re: Database example without GUI
« Reply #16 on: November 01, 2024, 06:22:12 pm »
@dseligo
your example works, thx very much

but in the first try, i got the same error like before  :o

now the funny reality of the life:
it was something wrong with the sqlite3.dll, i download a new one from sqlite.org and now it runs  :D

thx for everyone who try to help

Tanto

  • New Member
  • *
  • Posts: 13
Re: Database example without GUI
« Reply #17 on: November 01, 2024, 07:38:31 pm »
Hello @all

here the working example to connect to a SQLite3 Database.

thx for helping @all again

Download the sqlite3.dll from here
https://sqlite.org/download.html
i've used the following sqlite3.dll
https://sqlite.org/2024/sqlite-dll-win-x64-3470000.zip

if something missing, please tell me
« Last Edit: November 01, 2024, 07:41:05 pm by Tanto »

Handoko

  • Hero Member
  • *****
  • Posts: 5374
  • My goal: build my own game engine using Lazarus
Re: Database example without GUI
« Reply #18 on: November 01, 2024, 07:45:12 pm »
I got this error message:
Quote
Compile Project, Target: /home/handoko/Desktop/example_without_gui/project1: Exit code 1, Errors: 1
databasemodul2.pas(9,3) Error: Cannot find HelpModul1 used by databasemodul2 of the Project Inspector.

Tanto

  • New Member
  • *
  • Posts: 13
Re: Database example without GUI
« Reply #19 on: November 01, 2024, 08:14:51 pm »
@Handoko
sorry i forgot to clean this

now the hopefully cleaned version

Handoko

  • Hero Member
  • *****
  • Posts: 5374
  • My goal: build my own game engine using Lazarus
Re: Database example without GUI
« Reply #20 on: November 01, 2024, 08:19:38 pm »
Still has problem.

Tanto

  • New Member
  • *
  • Posts: 13
Re: Database example without GUI
« Reply #21 on: November 01, 2024, 08:27:28 pm »
@Handoko

ok, all good things come in three

i hope her is the last and clean version who works for you ;-)

Handoko

  • Hero Member
  • *****
  • Posts: 5374
  • My goal: build my own game engine using Lazarus
Re: Database example without GUI
« Reply #22 on: November 02, 2024, 03:38:05 am »
I just downloaded and tested the code running the from Lazarus' IDE and Linux Terminal. It did not generate any error. Below is the screenshot running it on Linux Terminal.

Tanto

  • New Member
  • *
  • Posts: 13
Re: Database example without GUI
« Reply #23 on: November 02, 2024, 08:17:48 am »
Hey,
this is very cool, because on Linux i doesn't test it, but now i know it runs also there.

thx

Tanto

  • New Member
  • *
  • Posts: 13
Re: Database example without GUI
« Reply #24 on: November 08, 2024, 12:39:23 pm »
Hello guys,
here is another example who contains the variant with sqlite and now with oracle to

on windows you need some dll's you have to download

best regards

MarkMLl

  • Hero Member
  • *****
  • Posts: 8000
Re: Database example without GUI
« Reply #25 on: November 08, 2024, 01:47:54 pm »
Thanks for that. Example code tested against Oracle is always appreciated, because they are perceived as being outside the reach or the average developer.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11930
  • FPC developer.
Re: Database example without GUI
« Reply #26 on: November 08, 2024, 04:02:24 pm »
(and of course also the databasename  (the database file) might need a path, specially when the exe is generated in lib/i386-win32 or so)

Tanto

  • New Member
  • *
  • Posts: 13
Re: Database example without GUI
« Reply #27 on: November 08, 2024, 04:30:29 pm »
Hi guys,

in the next time, I will extend this example with MySQL/MariaDB, MongoDB and PostgreSQL.

I think then, I will have covered all common databases.

So be happy and wait for the extension of this example.

best regards

Tanto

  • New Member
  • *
  • Posts: 13
Re: Database example without GUI
« Reply #28 on: November 10, 2024, 05:12:19 pm »
Hi @all,
i think i have finished the example project, for connecting a database without gui.

here my last example with PostgreSQL and MongoDB.

For MongoDB i use the mORMot2 Framework:
https://github.com/synopse/mORMot2

have fun and best regards

 

TinyPortal © 2005-2018