Lazarus

Programming => Databases => Topic started by: mdlueck on July 29, 2011, 07:36:23 pm

Title: Any sort of Persistence class framework for Lazarus?
Post by: mdlueck on July 29, 2011, 07:36:23 pm
A co-worker developed for the Object Rexx language a Persistence class architecture to remove writing of SQL queries from code we were developing and build the appropriate SQL on-the-fly.

It was built as an abstract class, and required a subclass to be created where the wiring of fields / datatypes took place, and nothing further.

I contributed to the effort the ability to join multiple tables together introducing JOIN statements to their architecture.

I am poised to start developing a client / server app with a MS SQL Server 2008 back-end and looks to be involving roughly 50 tables. Being new to Pascal, I do not think I can justify going off and creating a Persistence class architecture on my own.

Does something similar already exist for use with Lazarus?

I am thinking to at least ask… back in 2005 I envisioned a client/server Object Rexx RAD environment… barrowing RAD design from Borland’s Delphi, cross platform, OSS/FS. Unfortunately Object Rexx is still not ready enough… progress has been made in the language, but according to one core developer, “still not ready yet.”

Lazarus looks to me like a good realization of that vision. So setting off to learn Pascal.

P.S. It made use of Object Rexx's ability to dynamical create methods in classes on-the-fly. Getters / setters were defined on-the-fly perfectly matching up to the schema defined in the subclass to the abstract Persistence class.

It was also making use of Rexx’s interpret silver-bullet keyword… to build Rexx code on-the-fly and then execute it.  ;D

Title: Re: Any sort of Persistence class framework for Lazarus?
Post by: jctaborda on July 29, 2011, 10:10:22 pm
Hi mdlueck,

Take a look at tiopf. http://tiopf.sourceforge.net/ (http://tiopf.sourceforge.net/)

You can use the data dictionary tool from lazarus to create object classes and most of the code needed to create, read, update and save objects and lists of objects.

Hope it helps
Title: Re: Any sort of Persistence class framework for Lazarus?
Post by: BigChimp on July 30, 2011, 01:19:34 pm
And see here:
http://wiki.lazarus.freepascal.org/tiOPF (http://wiki.lazarus.freepascal.org/tiOPF)
Title: Re: Any sort of Persistence class framework for Lazarus?
Post by: mdlueck on July 30, 2011, 07:30:10 pm
Very slick! Thank you both!
Title: Re: Any sort of Persistence class framework for Lazarus?
Post by: mdlueck on August 01, 2011, 02:39:14 pm
Two questions, posted here as I am unable to connect to the tiOPF Support, I believe due to the odd port 8080.

1) I see listed that the SQL Server support is via "MSSQLServer via ADO". From the Lazarus DB pages, I never saw ADO listed. So is connecting via ADO preferable / reliable? I was aware of Zeoslib as a connection option to SQL Server: http://wiki.lazarus.freepascal.org/Lazarus_Database_Tutorial#Lazarus_and_MSSQL (http://wiki.lazarus.freepascal.org/Lazarus_Database_Tutorial#Lazarus_and_MSSQL) and I believe one of the other Lazarus drivers. I had not seen on other pages ADO even listed as a database connection type to use with Lazarus.

2) So the standard Lazarus DB controls... will they work with this Persistence class architecture? I cannot get a good indication what changes in how one develops client/server DB front ends if I add this Persistence class architecture to the configuration. Listed are tiopf database controls for Delphi, but Lazarus does not appear to be mentioned... or was it that Delphi controls needed to be replaced with alternate controls and Lazarus controls work with the Persistence class architecture?

TIA!
Title: Re: Any sort of Persistence class framework for Lazarus?
Post by: marcov on August 01, 2011, 05:57:47 pm
Two questions, posted here as I am unable to connect to the tiOPF Support, I believe due to the odd port 8080.

1) I see listed that the SQL Server support is via "MSSQLServer via ADO". From the Lazarus DB pages, I never saw ADO listed. So is connecting via ADO preferable / reliable? I was aware of Zeoslib as a connection option to SQL Server: http://wiki.lazarus.freepascal.org/Lazarus_Database_Tutorial#Lazarus_and_MSSQL (http://wiki.lazarus.freepascal.org/Lazarus_Database_Tutorial#Lazarus_and_MSSQL) and I believe one of the other Lazarus drivers. I had not seen on other pages ADO even listed as a database connection type to use with Lazarus.

1) Afaik ZEOS does not support ADO on Lazarus because the relevant oledb headers are missing
2) afaik the only connection to mssql is via ODBC.

Quote
2) So the standard Lazarus DB controls... will they work with this Persistence class architecture? I cannot get a good indication what changes in how one develops client/server DB front ends if I add this Persistence class architecture to the configuration. Listed are tiopf database controls for Delphi, but Lazarus does not appear to be mentioned... or was it that Delphi controls needed to be replaced with alternate controls and Lazarus controls work with the Persistence class architecture?

Such specialistic questions must be directed to tiopf directly.
 
Title: Re: Any sort of Persistence class framework for Lazarus?
Post by: mdlueck on August 01, 2011, 06:24:50 pm
2) afaik the only connection to mssql is via ODBC.

Would that be the "MSSQLServer via ADO" mentioned on the tiOPF site, or something else? Does ODBC = ADO?

Thanks!
Title: Re: Any sort of Persistence class framework for Lazarus?
Post by: jctaborda on August 01, 2011, 09:31:29 pm
Hi,

tiOPF can be used by lazarus and delphi, thus the reference to ado.
I saw people using zeos to connect to databases but I never used it with MSSQL so can't comment on that.

For the user interface you can use the MGM pattern (Model GUI Mediator).
Basically you use normal controls and create a relationship between the model and the components.

uses tiBaseMediator......;

.....

 FMediator := TFormMediator.Create(Self);
    FMediator.AddProperty('Name', txtName);
    ....
    FMediator.Subject:= MyClient;
    FMediator.Active := True;

There are mediators for many common controls.

When you load an object, its properties value are displayed in the controls and every change you make are reflected to the underlaying object.

You validate data in the isValid method and if there is an error in your input, for example the color of the edit box changes.

There is a sample app included in tiopf/source/demos/lcl/Demo_21_AddressBook

Hope it helps a bit.
Title: Re: Any sort of Persistence class framework for Lazarus?
Post by: marcov on August 01, 2011, 10:24:21 pm
2) afaik the only connection to mssql is via ODBC.

Would that be the "MSSQLServer via ADO" mentioned on the tiOPF site, or something else? Does ODBC = ADO?

No that is not via ADO and ODBC is not ADO.

The ADO option mentioned IS available for ZEOS, but NOT for ZEOS with FPC.
Title: Re: Any sort of Persistence class framework for Lazarus?
Post by: Lacak2 on August 02, 2011, 08:24:13 am
2) afaik the only connection to mssql is via ODBC.
Yes ATM it is true.
But there is already registered in bug tracker new connection component special for MS SQL Server (and potentially also for Sybase servers)
It uses corss-platrform FreeTDS db-library or Microsoft Client DB-Library (ntwdblib.dll)
http://bugs.freepascal.org/view.php?id=17303
Title: Re: Any sort of Persistence class framework for Lazarus?
Post by: mdlueck on August 02, 2011, 04:55:07 pm
No that is not via ADO and ODBC is not ADO.

The ADO option mentioned IS available for ZEOS, but NOT for ZEOS with FPC.

All right, thank you for the clarification.

So I understand that "whatever" an ADO connection to SQL Server is, it is NOT the ODBC driver.

And ZEOS is not currently an option with FPC.

So what exactly is this "ADO" connection which is an option with FPC / Lazarus? Where do I see it / poke a stick at it?

What sort of installation requirements will the target computers have in order to run my Lazarus program which needs to access SQL Server?

I am thinking to hard code in the ID/pw for the database, have an Auth table inside the database my applicaiton uses, simply obtain the UserID from Windows, look up that ID in the Auth table, if found grant access based on the PermMask of the matching record found in the Auth table. If no matching record is found, grant no access and display a message instructing to visit someone with Auth Granting permissions.
Title: Re: Any sort of Persistence class framework for Lazarus?
Post by: BigChimp on August 02, 2011, 06:07:21 pm
mdlueck, if you're using SQL server, look into trusted authentication (there's another name for it that I forgot): this logs you onto the SQL server with your Active Directory (Windows) username.

Never heard about ADO support for FreePascal.
ADO could be http://en.wikipedia.org/wiki/ActiveX_Data_Objects (http://en.wikipedia.org/wiki/ActiveX_Data_Objects), or it may mean ADO.Net, a newer version. I don't know.

I'd really suggest you get in touch with Graeme Geldenhuys (tiOPF maintainer for FPC) via the tiOPF newsgroup server.
Title: Re: Any sort of Persistence class framework for Lazarus?
Post by: mdlueck on August 02, 2011, 06:54:06 pm
Thanks much, BigChimp.

(Puzzled look on my face...) Lazarus IS able to natively attache to SQL Server, correct? (Aside from the tiOPF framework)

I would think at the very least native Lazarus could connect to it via the ODBC driver.

I am new to dealing with SQL Server, coming from a DB2 and MySQL background.
Title: Re: Any sort of Persistence class framework for Lazarus?
Post by: BigChimp on August 02, 2011, 06:58:42 pm
Yeah, it works through ODBC, using the native sqldb components (have only written a small test app myself, but it works).

Actually, I'm interested in connecting to DB2 myself - so I'll probably go looking into connecting to DB2 LUW using ODBC...

PS: Do you happen to be an AS/400 guy by any chance? REXX+DB2=AS/400 or maybe mainframe???
Title: Re: Any sort of Persistence class framework for Lazarus?
Post by: mdlueck on August 02, 2011, 07:17:00 pm
PS: Do you happen to be an AS/400 guy by any chance? REXX+DB2=AS/400 or maybe mainframe???

DB2 Common Server, later renamed Universal Database. I have worked with it on OS/2, Windows, and open to trying it on Linux, versions since 2.x.

DB2/400 was a totally different animal, needed the... DRDA <sp?> software to connect to such servers from a PC client. DB2 on 400 was quite similar to DB2 on the mainframe, where DB2 Common Server was quite similar on Common Server platforms.

As for Rexx, there again "Common Server" platforms... OS/2, Windows, and Linux. Classic Rexx on OS/2, Object Rexx since 1.0.3.0, currently ooRexx 4.1.
Title: Re: Any sort of Persistence class framework for Lazarus?
Post by: BigChimp on August 03, 2011, 03:27:25 am
Ok, that's clear.

Going back to documentation: there's more documentation and tutorials that you can use; see this post: http://lazarus.freepascal.org/index.php/topic,13951.msg73547.html#msg73547 (http://lazarus.freepascal.org/index.php/topic,13951.msg73547.html#msg73547)
Title: Re: Any sort of Persistence class framework for Lazarus?
Post by: mdlueck on August 04, 2011, 05:04:21 pm
I just came across your reply above, BigChimp. Thank you.