2

I'm working in an old Delphi 7 project and trying to get my bearings in it. I had heard that TADOTables are bad because they pull down entire tables. However I am looking at one bit of code and I'm wondering if it does the same thing. All it does is set the values of some fields and then do tbl.Post and possibly does the tbl.Insert command before it if applicable. (sorry, I'm not the most experienced in Delphi)

Anyway, so should TADOTables be completely phased out or should they only be replaced when doing select * statements from them practically and they're OK for inserts and updates?

Earlz
  • 62,085
  • 98
  • 303
  • 499

1 Answers1

4

ADOTables have to pull most (or all, depending on configuration) data from the server, so you're loading many rows of data simply to do an insert/edit and post.

Unless you're dealing with small, local databases (eg., Access database on the local machine), you're better off getting away from table-based data and moving to INSERT/UPDATE set-based operations.

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • if you dont need to display the current data, you could use a statement like: `Select * FROM table WHERE 0 = 1` which wont pull any records – Simon Aug 16 '11 at 02:26
  • 2
    @Simon: TADOTable doesn't accept SQL. I'm not sure I understand your comment. – Ken White Aug 16 '11 at 02:40
  • 2
    @Simon: the Idea is good, but it cant be used with TADOTable, you will need a Query for that. – CloudyMarble Aug 16 '11 at 03:45
  • 1
    Sorry, you are correct. Im always using a TQuery instead of TTable. – Simon Aug 16 '11 at 03:55
  • On this note, whats is the better method? using a TCommand and building Update SQL statements (of course padding and escaping backslashes etc) or using the TQuery and letting it do the padding/escaping itself? – Simon Aug 16 '11 at 04:09
  • @Simon: Neither. :) You use either one, using parameterized values, and let the database driver handle the padding/escaping/value formatting (eg., use `ParamByName('YourDateField').AsDateTime := SomeDelphiDateValue;` and let the driver decide how the date needs to be formatted for the DB. This makes it easier when you have to change databases later, and makes sure you don't get burned by SQL injection. – Ken White Aug 16 '11 at 11:06