* * *

Author Topic: Is Lazarus Dying, in part, for Lack of Easy SQL Connectivity?  (Read 9198 times)

scidatproc

  • Newbie
  • Posts: 1
Re: Is Lazarus Dying, in part, for Lack of Easy SQL Connectivity?
« Reply #15 on: July 04, 2018, 10:17:54 am »
The restriction of Lazarus to database applications on this topic here sounds very strange for me. Database applications are only a small part of the possibilities of Lazarus. I'm using Freepascal and Lazarus - from the beginning, at least 23 years - for writing scientific programs for data acquisition and processing, electronic and numerics simulations, and a compiler for microcontrollers. Lazarus can be applied for commercial applications, but it was not designed to be a commercial database system. Lazarus is an excellent tool for Linux and Windows even without database connectivity. Therefore, why should Lazarus die?

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6579
Re: Is Lazarus Dying, in part, for Lack of Easy SQL Connectivity?
« Reply #16 on: July 04, 2018, 10:29:38 am »
The hardest part of Lazarus, a part which is fully undocumented, is how to live with trolls  >:D

Scidatproc: I use Delphi to write machine vision apps fulltime. Some people call me crazy too ;-)
« Last Edit: July 04, 2018, 10:39:40 am by marcov »

Zvoni

  • Jr. Member
  • **
  • Posts: 59
Re: Is Lazarus Dying, in part, for Lack of Easy SQL Connectivity?
« Reply #17 on: July 04, 2018, 10:54:13 am »
The hardest part of Lazarus, a part which is fully undocumented, is how to live with trolls  >:D

Didn't you know?
Since "The Hobbit" every kid knows, that Trolls turn to Stone in Sunlight!
Easy to live with Trolls: Just stay on the sunny side of life!  8-) 8-) 8-)
People call me crazy because i'm jumping out of perfectly fine airplanes.
I say you're crazy not to!
--------------------------------------------------------------------------------------------------
For health reasons i try to avoid reading unformatted Code

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6579
Re: Is Lazarus Dying, in part, for Lack of Easy SQL Connectivity?
« Reply #18 on: July 04, 2018, 12:00:52 pm »
To put something constructive in a troll thread, here is a SQLite query program that I use to dump the tables of my ereader (mostly to find out which books are fully read, and which not, to free up space without manually scrolling like crazy through the menus)

It is not written to be short or clean, it is a throwaway copy-and-paste-and-adapt from an early script.  It also goes through the general DB layer, instead of figuring out all sqlite API peculiarities.

Code: Pascal  [Select]
  1. program sqlbookdb;
  2. // dumps tables of Pocketbook ereader.
  3. {$mode delphi}
  4. uses   Classes, SysUtils, sqlite3conn, sqldb, db,process;
  5.  
  6. function CreateQuery(pConnection: Tsqlconnection; pTransaction: TSQLTransaction): TSQLQuery;
  7. begin
  8.   result := TSQLQuery.Create(nil);
  9.   result.Database := pConnection;
  10.   result.Transaction := pTransaction
  11. end;
  12.  
  13. var
  14.   connect: TSQLite3Connection;
  15.   SQLQuery1: TSQLQuery;
  16.   transact: TSQLTransaction;
  17.   Query        : TSQLQuery;
  18. begin
  19.   connect:=TSQLite3Connection.create(nil);
  20.   connect.LoginPrompt := False;
  21.   connect.DatabaseName := 'D:\testing\touch2db\books.db';
  22.   connect.KeepConnection := False;
  23.   transact:=TSQLTransaction.create(nil);
  24.   transact.action:=caNone;
  25.   transact.database:=connect;
  26.   connect.Transaction:=transact;
  27.  
  28.  Query := CreateQuery(Connect, Transact);
  29.  if paramcount>0 then
  30.    Query.SQL.Text:='select Books.OID,Books.Authors,Books.Title,TagNames.TagName,Tags.Val from Books join Tags on (Books.OID=Tags.ItemID) join TagNames on (Tags.TagID=TagNames.OID) order by Books.TimeAdd'
  31.  else
  32.    Query.SQL.Text:='select Books.OID,Books.Authors,Books.Title,TagNames.TagName,Tags.Val from Books join Tags on (Books.OID=Tags.ItemID) join TagNames on (Tags.TagID=TagNames.OID) where Tags.TagId=80 order by Books.TimeAdd';
  33.  
  34.  
  35.  
  36.   Connect.Open;
  37.   Query.Open;
  38.   while not Query.Eof do
  39.   begin
  40.     Write( 'ID: '    , Query.FieldByName('OID').AsInteger,
  41.             ' Name: '  , Query.FieldByName('Authors').AsString,
  42.             ' title: '  , Query.FieldByName('Title').AsString,
  43.             ' tname: '  , Query.FieldByName('TagName').AsString,
  44.             ' Val: '  , Query.FieldByName('Val').AsString);
  45.     writeln;
  46.     Query.Next;
  47.   end;
  48.   Query.Close;
  49.   Connect.Close;
  50.   Query.Free;
  51.   Transact.Free;
  52.   Connect.Free;
  53. end.
  54.  

If there is anything good to come of this thread, there is maybe a lack in some easy to use examples. But that is something that can be fixed by anyone who wants to spend some time on the project instead of doing inflammatory posts.

Windsurfer

  • Sr. Member
  • ****
  • Posts: 336
    • Windsurfer
Re: Is Lazarus Dying, in part, for Lack of Easy SQL Connectivity?
« Reply #19 on: July 04, 2018, 12:40:24 pm »
Marcov, thanks for the code. I'll try it later.

Thanks to everyone else for their views and advice. I will read The Hobbit immediately, although I originally lost interest in 1966 after about five pages.

I have been using Lazarus for some years for quite big applications (but not Db related), have contributed a few examples and wiki help topics whenever I got stuck and had to work to find a solution. I'll do the same again with this.


Windsurfer

  • Sr. Member
  • ****
  • Posts: 336
    • Windsurfer
Re: Is Lazarus Dying, in part, for Lack of Easy SQL Connectivity?
« Reply #20 on: July 04, 2018, 01:29:05 pm »
Leledumbo,

Thanks. I did not have the -dev installed. I now have the following installed and the IDE compiles and links.

libsqlite3-0
libsqlite3-dev
libsqlite3-0:i386

Will try more later.

JD

  • Hero Member
  • *****
  • Posts: 1730
Re: Is Lazarus Dying, in part, for Lack of Easy SQL Connectivity?
« Reply #21 on: July 04, 2018, 02:39:16 pm »
Even though Lazarus is not just for database development, I guess the problem of tan is that SQLite3 connectivity is not enabled by default in Lazarus. Python's standard libraries comes with lots of extras.

Here is another trivial example using the Chinook database which compares Python & Lazarus manipulation of an SQLite database.

A)
Here is Python code for retrieving all the system tables from the Chinook database
Code: Pascal  [Select]
  1. import sqlite3
  2.  
  3. con = sqlite3.connect('chinook.db')
  4. cursor = con.cursor()
  5. cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%';")
  6. print(cursor.fetchall())
  7.  

B)
Here is the same code in Lazarus but which puts the tablenames in a combobox
Code: Pascal  [Select]
  1.       // Set the type of database we are trying to connect to
  2.       SQLConnector1.ConnectorType := 'SQLite3';
  3.       // Set the name and path of the database
  4.       // If the database is in the same directory as the program, the
  5.       // path can be omitted; just the name of the database will suffice
  6.       SQLConnector1.DatabaseName  := 'chinook.db';
  7.       // Now connect to the database
  8.       SQLConnector1.Connected     := True;
  9.       // Set the transaction to active
  10.       SQLTransaction1.Active := True;
  11.       // Run the query that gets the names of the non-system tables in the database
  12.       SQLQuery1.SQL.Text := 'SELECT tbl_name FROM sqlite_master WHERE type = ''table'' AND tbl_name NOT LIKE ''sqlite_%''';
  13.       SQLQuery1.Open;
  14.       //
  15.       while not SQLQuery1.EOF do
  16.       begin
  17.         ComboBox1.Items.Add(SQLQuery1.FieldByName('tbl_name').AsString);
  18.         SQLQuery1.Next;
  19.       end;
  20.  

As you can see, it is not that difficult to do.  :D

NOTE:
One just needs to add SQLConnector, SQLTransaction and SQLQuery to the project, connect the 3 components and then put the sqlite3 dll in the same directory as the project. The Chinook database is here http://www.sqlitetutorial.net/wp-content/uploads/2018/03/chinook.zip. The sqlite3 32-bit dll is here https://www.sqlite.org/2018/sqlite-dll-win32-x86-3240000.zip

The complete example (without the database and the sqlite 32 bit dll) is in the attachment. After connection, the database tables names are loaded into the combobox; selecting a table and then clicking on the search button will display the contents of the table in the DBGrid.

I hope this helps the newcomers.  :D

Cheers,

JD
« Last Edit: July 04, 2018, 04:31:52 pm by JD »
Windows (10, 7) - Lazarus 1.8/FPC 3.0.4, NewPascal, Delphi
Linux Mint Cinnamon  - Lazarus 1.8/FPC 3.0.4, NewPascal

Indy 10.6 series; mORMot; Zeos 7.2.1; SQLite, Firebird, PostgreSQL & MariaDB; VirtualTreeView 5.5.3 R1

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6579
Re: Is Lazarus Dying, in part, for Lack of Easy SQL Connectivity?
« Reply #22 on: July 04, 2018, 02:57:26 pm »
The fatal flaw in tan's concept is that brevity equals ease of use, while most beginners will copy and paste from examples. And that is one ctrl-C ctrl-V, regardless of amount of lines copied.

Anyway, I do think there could be more examples for database use. Maybe we should compare what it would take to make a small gui app with database connection and grid in Python and Lazarus.

Probably I can just copy-and-paste that from some Python example (where?) and the Lazarus side is doable as well.

edited... oh, you already have made a GUI example for Lazarus, now we just need the Python equivalent to compare with.

JD

  • Hero Member
  • *****
  • Posts: 1730
Re: Is Lazarus Dying, in part, for Lack of Easy SQL Connectivity?
« Reply #23 on: July 04, 2018, 03:02:19 pm »
edited... oh, you already have made a GUI example for Lazarus, now we just need the Python equivalent to compare with.

 :D :D That is the elephant in the room. I don't like TKinter (it is ugly in my opinion). wxPython is better but it is complicated to set up so Lazarus wins hands down in that area.  :D :D
Windows (10, 7) - Lazarus 1.8/FPC 3.0.4, NewPascal, Delphi
Linux Mint Cinnamon  - Lazarus 1.8/FPC 3.0.4, NewPascal

Indy 10.6 series; mORMot; Zeos 7.2.1; SQLite, Firebird, PostgreSQL & MariaDB; VirtualTreeView 5.5.3 R1

Thaddy

  • Hero Member
  • *****
  • Posts: 7130
Re: Is Lazarus Dying, in part, for Lack of Easy SQL Connectivity?
« Reply #24 on: July 04, 2018, 03:15:46 pm »
:D :D That is the elephant in the room. I don't like TKinter (it is ugly in my opinion). wxPython is better but it is complicated to set up so Lazarus wins hands down in that area.  :D :D
No this is the elephant:

Can you show us how you designed the python app visually and did that visual designer automatically keep sync with the underlying sourcecode and the other way around?

Probably listened too much to Nelly the elephant (the Toy Dolls are my friends, we played with them in the 80's) https://www.youtube.com/watch?v=9m7tPikH0UA
inline variables like in D10.3 are a bit like Brexit: if you are given the wrong information it sounds like a good idea. Every kid loves candy, but it makes you fat and your teeth will disappear.

JD

  • Hero Member
  • *****
  • Posts: 1730
Re: Is Lazarus Dying, in part, for Lack of Easy SQL Connectivity?
« Reply #25 on: July 04, 2018, 04:22:33 pm »
Can you show us how you designed the python app visually and did that visual designer automatically keep sync with the underlying sourcecode and the other way around?

 :D :D This is NOT possible as far as I know. No Python development tool (Spyder3, PyCharm, NinjaIDE, Anaconda etc) has that. I would not even want to try it since I know Lazarus does a better job. That is why I ONLY use Python for Data Science and system related stuff like backup scripts.

PgAdmin4 for PostgreSQL https://www.pgadmin.org/docs/pgadmin4/dev/ is an example of a Python database application using the Flask framework. It runs in a browser and it is slow in my opinion. But many people want browser based applications nowadays so we are stuck with it.  :( :(
PgAdmin3 which was written in C++ and wxWidgets was much faster but it has since been abandoned because of the trend towards browser based applications.

If I am forced to deploy web/browser based applications, I'd rather use Java EE. I do have several Lazarus based client-server REST applications developed with Indy10 and mORMot with a PostgreSQL backend that work very, very well so I am satisfied with Lazarus.  :D

JD
« Last Edit: July 04, 2018, 04:45:24 pm by JD »
Windows (10, 7) - Lazarus 1.8/FPC 3.0.4, NewPascal, Delphi
Linux Mint Cinnamon  - Lazarus 1.8/FPC 3.0.4, NewPascal

Indy 10.6 series; mORMot; Zeos 7.2.1; SQLite, Firebird, PostgreSQL & MariaDB; VirtualTreeView 5.5.3 R1

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6579
Re: Is Lazarus Dying, in part, for Lack of Easy SQL Connectivity?
« Reply #26 on: July 04, 2018, 04:33:45 pm »
Yup, I know pgadmin4, you can see the form build-up, and sometimes you are just waiting till something happens.

But even just getting some proper, working wxwidget or gtk dlls to go with the python wrapper can already be horrible experience. ANd then you haven't even started coding python yet.

JD

  • Hero Member
  • *****
  • Posts: 1730
Re: Is Lazarus Dying, in part, for Lack of Easy SQL Connectivity?
« Reply #27 on: July 04, 2018, 04:44:54 pm »
But even just getting some proper, working wxwidget or gtk dlls to go with the python wrapper can already be horrible experience. ANd then you haven't even started coding python yet.

Yes I agree. That was my first attempt at making a GUI for my C++ applications. Luckily for me I discovered Delphi/Lazarus and the rest is history. I tried wxPython a little but I quickly abandoned it.

JD
Windows (10, 7) - Lazarus 1.8/FPC 3.0.4, NewPascal, Delphi
Linux Mint Cinnamon  - Lazarus 1.8/FPC 3.0.4, NewPascal

Indy 10.6 series; mORMot; Zeos 7.2.1; SQLite, Firebird, PostgreSQL & MariaDB; VirtualTreeView 5.5.3 R1

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6579
Re: Is Lazarus Dying, in part, for Lack of Easy SQL Connectivity?
« Reply #28 on: July 04, 2018, 04:57:17 pm »
Well, till 2003-5 Lazarus used GTK(1), also on Windows . I'm really glad that era is gone.

Thaddy

  • Hero Member
  • *****
  • Posts: 7130
Re: Is Lazarus Dying, in part, for Lack of Easy SQL Connectivity?
« Reply #29 on: July 04, 2018, 04:57:43 pm »
Guido van Rossum is guilty of ruining my space bar before the warranty runs out... They should make an exemption for keyboards when using Python.
But as I stated before: I like Python a lot and use it all the time for shorts and modelling. Just not for GUI applications.
« Last Edit: July 04, 2018, 05:05:31 pm by Thaddy »
inline variables like in D10.3 are a bit like Brexit: if you are given the wrong information it sounds like a good idea. Every kid loves candy, but it makes you fat and your teeth will disappear.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus