User Tools

Site Tools


ado_example_suite.htm
Navigation:  Guide to Examples >====== ADO Example Suite ====== Previous pageReturn to chapter overviewNext page

This example applications and source for all ADO based examples are located in the \(CLARION ROOT)\EXAMPLES\ADO folder.

The following example programs, each demonstrating one or more features of the new ADO template set, are listed here:

ADOExample

This example application demonstrates how to setup an ADO connection using the ADO Support global extension template. The connection part is performed with an ADOlogin procedure, which will in turn call an ADOError handler (if necessary).

This application also shows the features of the ADO Browse Box (header sort, moving/hiding columns), the BrowseQBEList control template, ADOForm, and an ADOReport.

ADONorthW and ADOData

These applications are exactly the same as ADOExample application, except that they are using an EXE/DLL deployment strategy.

Connect

This is a small hand coded program that demonstrates how to use the classes to establish a connection with the ADO database.

The source code shows the following:

·That COMIniter will init the COM object.

·The creation of a Cconnection instance. If CConnection object is created properly, the Init() method is called (which is responsible to create the real ADO connection object).

If the Init() method returns with no error, it means that the Cconnection object has a valid reference to an ADO connection interface. It will then call the Connect method (which will pass the Connect string to the ADO connection interface and wait for the result).

If Connect returns the S_OK equate value, the connection is established with the database.

ConnErr

This is a small hand coded program that shows how to handle ADO connection errors. The code has an intentional mistake in the connection string and will redirect the code to the error handler when the connect method fails to connect.

The same steps are performed as in the Connect example above, except we know that an error will occur.

The Error handler procedure demonstrates the following:

·How to extract the Errors collection from a Cconnection object by using the Errors method.

·If that Errors collection has any error item in it, the GetCount method will return the number of errors in the parameter passed by reference to that method.

If the value is non-zero, we can extract each Error object from the Errors collection by using the Error method from the Errors object, and supplying the error index (numbered from 0 to Count ' 1).

·Once we have an Error object detected, we can extract the ADO error number and get a description of that error by calling the Number and Description methods.

After the above, a queue is populated with the error number and description.

It is important to note that one or more errors can be caused by a single event in ADO. This is why the error handler checks for the number of items present in the Errors Collection object.

SET

This small hand coded program demonstrates how to obtain an ADO result set once a connection is established with the database, and how to extract the different column value from a row.

·First a connection is made with the database. If the connection is ok, the code will branch to the CreateSet procedure and will create an ADO recordset object. The CreateSet procedure also shows how to use the TableMapper object and the Crecordset together.

The TableMapper and the Crecordset object are first created. Next, the Init method of the Crecordset object is called. This call will actually create the real ADO recordset object. If the recordset object is created successfully, the Crecordset object will have a valid reference to an ADO recordset interface.

·The program next calls PutCursorLocation with an adUseClient parameter because the programmer chooses to use a client side cursor. This method needs to be called before the open statement.

·Next, the code instructs the ADO mapper to match the columns from the CUSTOMER table to the corresponding queue field of the CustomerQ queue. Once the mapper knows where to assign values, we call the Map method which actually will perform those assignments.

·Finally, the source calls a routine (FillQ) to fill up the rest of the rows contained in the recordset. FillQ calls the MoveNext recordset method, and checks if the set has the EOF flag set to true by checking if bEOF value is '1 by calling the GetEOF method of the Crecordset object. If the set has still rows, the routine calls the Map method of the mapper and fills the queue.

ado_example_suite.htm.txt · Last modified: 2021/04/15 15:56 by 127.0.0.1