In many applications, the schema of the database tables being queried does not change. Tables are designed when the application is designed, and the layout and structure remain the same while the program is running. In these cases, result schema caching may be enabled. Enabling result schema caching instructs the DB Interface Module not to fetch result schema information when re-executing a query. This can result in a performance gain if the same RWDBSelectors or RWDBOSqls are used repeatedly.
Result schema caching is managed by the RWDBEnvironmentHandle associated with the RWDBDatabase. To enable result schema caching, we must:
obtain the RWDBDatabase's environment handle by using the RWDBDatabase::environmentHandle() method.
use the cacheResultSchemas() method on RWDBEnvironmentHandle to indicate that result set schemas should be cached.
RWDBConnection c = aDb.connection(); RWDBEnvironmentHandle *envH = aDb.environmentHandle(); //1 envH->cacheResultSchemas(true); //2 RWDBSelector s = aDb.selector(); RWDBTable t = aDb.table("INVOICES"); s << t; RWDBResult r = s.execute(c); //3 RWDBResult r2= s.execute(c); //4 |
On //1, the environment handle is obtained from the RWDBDatabase. On //2, the schema cache is enabled. On //3, the selector is executed. On this execution, the result schema is fetched, because this RWDBSelector was not executed previously. On //4, however, the result schema obtained during //3 is reused. This reuse may result in a performance increase.
For applications that work with tables whose schema may change while the program runs, schema caching should not be used.
Do not use schema caching for tables whose schema may change during runtime.
Using schema caching may result in undefined behavior if the schema of a database table being used changes while the program runs. By default, result schema caching is off since some applications work with tables whose schema may change.
Copyright © Rogue Wave Software, Inc. All Rights Reserved.
The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.