Delphi / ADO: what components? TADODataSet and TADOCommand or TADOQuery?

According to http://www.delphigroups.info/2/3/181838.html

The preferred approach with ADO components is to use TADODataSet and TADOCommand. TADOQuery (both TADOTable and TADOStoredProc) are provided for compatibility.

Use TADODataSet for SQL, which returns result sets, and TADOCommand for SQL is not.

I am an ignorant n00b - who is going to code a lot of ADO stuff. Is this statement correct?


Ps is there a good open source Windows program that will allow me to visualize and explore the contents of my databases?

What components should be used for something that returns / does not return a result?

+4
source share
4 answers

This statement is true. TADODataset and TADOCommand are direct interfaces to their own ADO objects and can perform all the tasks done by the other three that exist to facilitate porting the application written for the BDE (Borland Database Engine) with the implementation of a similar interface - they ultimately name the first two.

+6
source

And I will go half the opposite !; -)

There are times when TADOQuery is great for both tasks. If your query results in using TADOQuery.Acvite := True data, if you need to update \ insert \ delete, use TADOQuery.ExecSQL.

For example, you can write a query to UPDATE \ INSERT and SELECT records and do this in one component instead of introducing two.

 DECLARE @ID int, @Mode int, @SomeValue varchar(20) SET @ID = :ID SET @Mode = :Mode SET @SomeValue = :SomeValue IF (@Mode = 1) //INSERT BEGIN INSERT INTO dbo.YourTable(ID, SomeColumn) VALUES(@ID, @SomeValue) END ELSE IF (@Mode = 2) //UPDATE BEGIN UPDATE dbo.YourTable SET SomeValue = @SomeValue WHERE ID = @ID END ELSE IF (@Mode = 3) //DELETE BEGIN DELETE FROM dbo.YourTable WHERE ID = @ID END ELSE IF (@Mode = 4) //SELECT BEGIN IF (@ID = -1) //SELECT ALL BEGIN SELECT * FROM dbo.YourTable END ELSE BEGIN SELECT * FROM dbo.YourTable WHERE ID = @ID END END 

Just an example written now. I hope you understand.

+4
source

What database are you using. SqlBuddy is an open source environment for exploring the database.

+3
source

Here you have 2 different classifications, either depending on the nature of the SQL object (TADOTable, TADOQuery and TADOStoredProc) or the action / result (TADODataSet and TADOCommand) .
The historical approach of Delphi is the first, while ADO is by nature more relevant to the 2nd.

Both may be useful depending on what you want to do.

I recommend that you read the Delphi help on ADO components.
For example, you will find useful notes, for example: "ADOdb.TADODataSet and SQLExpr.TSQLDataSet have a CommandType property that allows you to specify whether they represent a table, query, or stored procedure. The names of properties and methods are most similar to data types of the query type, although TADODataSet allows specify an index, such as a data type table. "

If you are sure that you adhere to ADO and never need to change and transfer to other data layers, then go to the "ADO route" using TADODataSet and TADOCommand . You will get most of the ADO, and it will be easier to use MS documents and examples.

+3
source

Source: https://habr.com/ru/post/1311493/


All Articles