Database Results Strategy
-
Folks, I mostly do systems programming but got suckered into writing an app for a business run by my brother. This is a POS system which is backed by SQL Server. I'm using WTL on the client and ODBC (because it seemed simple / straightforward) to communicate with the db. The question: there are a series of queries / reports that are run against the server. Exactly what is included in any individual report is variable -- eg a net sales report may or may not include gift certificates, employee discounts, etc. My question: what is the best strategy for passing query results around? They can be (1) displayed on screen, (2) saved to CSV, or (3) printed. I expect there may be future options in the future, such as blowing them directly into QuickBooks. Do people typically pass around the SQL statement handle and let the various consuming functions directly pull data via SQLFetch? That seems like a really bad idea. I currently have the SQL functions isolated and pull query results into an internal data structure -- vectors of structs right now. Unfortunately, I have to create structs for each query and pass around vectors. How do you deal with the fact that there are many optional fields -- just create an entry in the struct for each potential field? Also, what is the most convenient manner to deal with the fact that certain fields may be null? Are there better ways to do this? Thanks, Earl