Then you will missed the opportunity to distribute your software on any OS platform. Gambas's produced software only runs on Linux as far as I know and it also needs the Gambas runtime before your software will run on a Linux distro.
Yes I know. But I write software for my own firm, so that's not a problem. We work on Linux solely. And i had no "Pascal days", so for me FPC is a complete new language with much things I would have to learn from the ground up. At Gambas I'm much more "at home".
I will replace sqldb if that is the case. Can you give me hints on how to do SQL by hand? I mean you do the SQL queries in Gambas? Or call the SQL procedures/functions at the PG server? I am comfortable with SQL statements, since most business logic are in the DB anyway and PostgreSQL docs are excellent.
I f you have your business logic on the PG Server that is very good! In FPC you can use the class postgres to connect a Lazarus client to the server. How(?) I did not really figure out because I stopped my experiments with Lazarus. But there is the class postgres (and maybe postgres3) to look at it and there are examples in
/usr/share/fpcsrc/2.6.4/packages/postgres/examples
(on my linux computer)
which can be adopted.
So I only can tell, what I am doing in Gambas or other languages:
1) Build a static class (that is a singleton) to do only one connection per PG database at start of your program. This is your channel to talk to PG. In PGAdmin you have the server tools, there you can see the connections. If your program opens more than one you should know why, that is a source of deadlocks (maybe you used a control with SQLdb in parallel).
In Gambas I do this in a method (this is a static class/aka singleton):
Public DB As New Connection
Public Sub _init()
startconnection
End
Private Sub startconnection()
If Not PGdb.Opened Then
PGdb.Type = "postgresql"
PGdb.Host = "hostname"
PGdb.Name = "dbname"
PGdb.Login = "User"
PGdb.Password = "password"
PGdb.Open()
Endif
Catch
myownError.Handler
End
Ok, you have to rewrite this for FPC like in the example.
2)In your program send your query over this connection and receive the result (usually as array).
arrayresult = DB.exec("SELECT * FROM this WHERE ...")
3) Use the data in the array to fill your controls.
4) Write methods which send queries over the connection to update data in database when the user changed the data in the controls.
DB.exec("DELETE FROM this WHERE ...")
DB.exec("UPDATE this SET y = " & blah & " WHERE ...")
If you want to change a couple of things in the database at once, do it so:
DB.exec("BEGIN;")
send a couple of queries ...
DB.exec("COMMIT;")
Ok this is very basic, but ensures, that you get a rockstable client. For better stability use prepared statements (do not forget DEALLOCATE):
http://www.postgresql.org/docs/9.3/static/sql-prepare.htmlIf you work with larger tables, ensure that you use LIMIT if you query the data. Or use cursors:
http://www.postgresql.org/docs/9.3/static/plpgsql-cursors.htmlSo people using your client can scroll data.