[ Pobierz całość w formacie PDF ]
., Alameda, CA www.sybex.com2874c14.qxd 7/2/01 4:34 PM Page 636636 Chapter 14 " Client/Server ProgrammingThe structure of the update statement depends on the UpdateMode property of the SQL-ClientDataSet component.Trying to use upWhereChanged or upWhereKeyOnly, however,causes an error, as the component is unable to determine which are the key records, and theprovider doesn t generate a correct update statement.In fact, it simply tries to update theupdate the record based on the specific field changed, without including the key field in thewhere statement:update EMPLOYEE setPHONE_EXT = ?wherePHONE_EXT = ?The update statement should rather be:update EMPLOYEE setPHONE_EXT = ?whereEMP_NO = ? andPHONE_EXT = ?How can we obtain the proper update call? Considering we cannot directly attach a com-ponent like the UpdateSQL (which is a BDE-only component), a simple solution would beto force the inclusion of the key field.This can be accomplished in the ClientDataSet archi-tecture by turning on the pfInKey flag of the ProviderOptions property of the source field.This can easily be accomplished in the DbxMulti example, after adding persistent fields forthe SQLDataSet component, but the problem is that the database library should locate thekey fields automatically.In the DbxSingle example, we have no control on the source datasetand its fields, so the only solution is to write the update statements in a totally custom way,with quite some effort.NOTEWe ll be able to discuss this type of problem again as we get into the details of the ClientDataSetcomponent, the Provider, the Resolver, and other technical details later in this chapter and inChapter 17.Accessing Database Metadata with SetSchemaInfoAll RDBMS systems use special-purpose tables (generally called system tables) for storingmetadata, such as the list of the tables, their fields, indexes, and constraints, and any othersystem information.As dbExpress provides a unified API for working with different SQLservers, it provides also a common way for accessing metadata.The TSQLDataSet compo-nent has a method, SetSchemaInfo, which fills the dataset with system information.ThisSetSchemaInfo method has three parameters:SchemaType indicates the type of information requested and includes stTables, stSysTables,stProcedures, stColumns, and stProcedureParams.Copyright ©2001 SYBEX, Inc., Alameda, CA www.sybex.com2874c14.qxd 7/2/01 4:34 PM Page 637The dbExpress Library 637SchemaObject indicates the object you are referring to, such as the name of the table forwhich you are requesting the columns.SchemaPattern is a filter, so that you can limit your request to tables, columns, or proce-dures starting with the given letters.This is very handy if you use prefixes to identifygroups of elements.For example, in the SchemaTest program, a button reads into the dataset all of the tables ofthe connected database:ClientDataSet1.Close;SQLDataSet1.SetSchemaInfo (stTables, , );ClientDataSet1.Open;The program uses the usual group of dataset provider, client dataset and data source com-ponent to display the resulting data in a grid, as you can see in Figure 14.10.After you reretrieved the tables, you can select a row of the grid and press the second button to see a listof the fields of this table:SQLDataSet1.SetSchemaInfo (stColumns, ClientDataSet1[ Table_Name ], );ClientDataSet1.Close;ClientDataSet1.Open;FI GURE 14.10:The SchemaTest exampleallows you to see the tablesof a database and thecolumns of a given table.Besides accessing database metadata, dbExpress provides a way to access to its own config-uration information, including the installed drivers and the configured connections.The unitDbConnAdmin defines a TConnectionAdmin class for this purpose, but the aim of this sup-port is probably limited to dbExpress add-on utilities for developers, as letting end usersaccess multiple databases in a totally dynamic way is not very common.Copyright ©2001 SYBEX, Inc., Alameda, CA www.sybex.com2874c14.qxd 7/2/01 4:34 PM Page 638638 Chapter 14 " Client/Server ProgrammingTIPThe DbxExplorer demo included in Delphi 6 shows how to access both dbExpress administra-tion files and schema information.Also check the help file under The structure of metadatadatasets within the section Developing database applications.A Round-Up on dbExpressAfter we ve delved a little more into the dbExpress architecture and SQL components, I cantry to add a few comments about this solution and its alternatives.On the whole, dbExpressprovides a much neater architecture, compared to the BDE
[ Pobierz całość w formacie PDF ]