Jump to content
jdg

Database in Delphi

Recommended Posts

Good morning Praxis.  My first post here so go easy on me please.

I have recently upgraded from Delphi 4 to Delphi 10.4 - yes, a big leap indeed.  My previous database experience is with the BDE, so sadly now my knowledge has become obsolete.

I'm struggling to learn a new way.  Good code examples are proving difficult to find on line.

At this time I'm primarily interested in local client data interface.

 

Firstly - I would appreciate any recommendations on books that do a good job explaining how to use the database components in 10.4 please.

Secondly - what are your preferred database components?  I've been experimenting with IB components.  

 

Also, I'm getting some unexpected results from this simple exercise & can't figure out what's wrong.  Any help is appreciated.

I have IBConsole and have created an experimental database and some tables to use while feeling out coding with some TIBTable components.

I have a table of projects & a table of people & I'm wanting to create a relationship between projects in people in a third table.  As it stands now I'm only working with the first two tables, so disregard the table that holds the relationships.

In a data module I have a TIBDatabase & a TIBTransaction component, with two TIBTable & two TDataSource components.

I'm trying to read through the records in one of the tables & it's simply not working.

My contacts table has four records in it.

 

This code:

tblConts.open;
ShowMessage('tblConts Record count: ' + IntToStr(tblConts.RecordCount));

Shows a message that says I have one record.  I don't understand why I'm getting this incorrect result.  It should be four.

 

Also this code fails, never finding the first record.  I've tried it with the table filtered & unfiltered.

if tblConts.FindFirst then
  repeat
    ...
  until not tblConts.FindNext;

Any ideas?

 

Thanks in advance for any help.

 

 

 

 

 

 

Share this post


Link to post

Do you have tblConts linked in any way to other tables? Master/Detail?

Share this post


Link to post

Hi...:classic_cool:

Quote

I have recently upgraded from Delphi 4 to Delphi 10.4 - yes, a big leap indeed.

...wow. :classic_blink:

Quote

so sadly now my knowledge has become obsolete.

...better. :classic_tongue:

 

Questions:

We know IBConsole and IBDatabase ...but which database you use? Firebird or Interbase?

 

Tools:

Admintool: https://dbeaver.io/

...better than console. :classic_cool:

 

Tip:

Never use T???Table...only T???Query and SQL!

Share this post


Link to post
Guest

hi @jdg

 

1) you dont need any special third-part component. FireDAC works very well for many Database, be local or remote! Include:

  • BDE (Paradox file-tables), DBase (using ODBC drivers), and Interbase/Firebird and many others professional database!
    • of course, you stay on control to use any other suite!!!
  • FireDAC needs to works this components:
    • 1 FDxxxxWaitCursor
    • 1 FDConnection
    • 1FDxxxxPhys<<driver>>  -> IB/FB, ODBC, etc....
    • 1 FDxxxxxTransaction (if using READ-WRITE for any action) or 2 if using 1 to READ-ONLY (selects) e 1 to READ-WRITE (updates, delete, insert)
    • 1 FDxxxQUERY for accesss your datas
    • 1 Datasource as usual

 

2) as you already have 2 tables with the info stored, you need just have a key-field include in both tables, or if not, you can create a 3rd tables (as you said) to store this relationship (ID-third-table, ID-project, ID-peope.

----> this last option, stay as more flexible to create yourself relationship many-to-many, while if using only 2 tables you stay more restrict to one-by-one.

 

3) the relationship you can use IBConsole if PRO to create it, or same the IBExpert trial or not.

 

Master-Details in Sidney!

http://docwiki.embarcadero.com/RADStudio/Sydney/en/Master-Detail_Relationship_(M/D)

 

Now the main note: try forget old way, and learn new techs on programming

 

hug

 

Edited by Guest

Share this post


Link to post
3 hours ago, jdg said:

Firstly - I would appreciate any recommendations on books that do a good job explaining how to use the database components in 10.4 please.

The best book I think about is Delphi in Depth : Firedac by Cary Jensen

 

3 hours ago, jdg said:

Secondly - what are your preferred database components?  I've been experimenting with IB components. 

If your aim is FireBird don't use IB Components, well and even for Interbase Firedac is better.

Firedac is BDE like so the step between D4 and D10.4 is not so large (for this point and with Firedac)

3 hours ago, jdg said:

At this time I'm primarily interested in local client data interface

Ok, so in this case, should I suggest to use SQLite and a GUI like SQLite Studio

 

Share this post


Link to post
Guest
5 hours ago, jdg said:

My first post here so go easy on me please.

You'll be fine. Some of us are rather pragmatic, but most of us are really nice 🙂 !

 

FireDAC is the DAC (Data Access Component) included. But be aware, at 10.4.2 no sources in "professional". And Emba has announced that FireDAC will be "Enterprice" exclusive in the future (please correct me if i am wrong, you all). So for learning / hobby projects that may grow it is not a great start, IMHO.

 

I use IBObjects myself but that is 3d party proprietary stuff IB/FB only. But i am still content.

The BDE was a right out mess. If you are not invested in that "technology" (legacy deployed systems) then just skip it. BDE is in itself a workaround on a workaround from some other workaround and thus the worst stepping stone imaginable.

 

I wish i could point you to a stabile cheap multi-platform DAC but at that i fail.

Share this post


Link to post
10 hours ago, jdg said:

This code:


tblConts.open;
ShowMessage('tblConts Record count: ' + IntToStr(tblConts.RecordCount));

Shows a message that says I have one record.  I don't understand why I'm getting this incorrect result.  It should be four.

 

 

InterBase does not return a record count on a select statement (it always returns 42) because this is expensive to do.  So RecordCount reflects the number of records fetched to the client.  Just call FetchAll after open if you want an accurate RecordCount.

 

If you are going to loop through the records just loop till Eof.  RecordCount is not needed to work through the result set.

 

FindFirst and FindNext are when you are filtering a Dataset on the client side.

 

Share this post


Link to post
11 hours ago, Dany Marmur said:

 And Emba has announced that FireDAC will be "Enterprice" exclusive in the future (please correct me if i am wrong, you all).

Really ? IMHO, This would be a bad idea, if Firedac was not with Pro and Community (with no source is acceptable).

Another pack of free component is ZEOSLIB (also named ZEOSDBO), also BDE Like, can be installed on Community Edition  

Share this post


Link to post
12 hours ago, Dany Marmur said:

I wish i could point you to a stabile cheap multi-platform DAC but at that i fail.

Zeos of course

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×