Result Schema Caching
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 RWDBSelector or RWDBOSql objects 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 object’s environment handle by using the RWDBDatabase::environmentHandle() method.
*use the cacheResultSchemas() method on RWDBEnvironmentHandle to indicate that result set schemas should be cached.
Example 17 – Result schema caching
 
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.
NOTE: Do not use schema caching for databases that might change the schema of their objects while the application is running.
Using schema caching may result in undefined behavior if the schema of a database table being used changes while the program is running. By default, result schema caching is turned off since some applications work with tables whose schema may change.