Link to home
Start Free TrialLog in
Avatar of rskelton75
rskelton75

asked on

Query flexibility with MFC

I will try to make this as clear as possible.   I'm trying to write an MFC application that can receive user input in the form of simple db queries and can return the appropriate records.  The tricky thing is that I want the user to be able to write these sql queries as if they have no knowledge of the structure of any Recordsets contained within the application...all they know about is the structure of the db itself.  I'm trying to achieve this without defining a particular Recordset for each possible subset of columns that will be retrieved with each query.  

MSDN states: For every distinct table, view, or stored procedure you wish to access, you typically define a class derived from CRecordset. (The exception is a database join, in which one recordset represents columns from two or more tables.)

My problem is that a user in this application may use a join or they may not.  They may reference every column from 3 different tables in their query, or they may just need one column from one table.  I'm trying to make this as free and simple as possible for the end user.  At first, when attempting to do this, the user sql statements were required to be bloated and contain every column in their select statements, and contain all possible join statement in a given recordset in order for the queries to be successful.  I'm trying to avoid this.

If this cannot be achieved using Recordsets, but can with another datastructure...or if it is possible using Recordsets...or if you have no idea what I'm talking about, your reponse would be greatly appreciated.
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

I think you will need to provide some sort of wizard where the user can select options at each stage.
eg Step 1) Do you want address, age, shoe size....
Then based on the selection adress they can enter name, age, town etc.  When they hit the ok you parse for entered info and build the SQL.
It sounds like you're attempting to rewrite Microsoft Query.
I was faced with the same issue and eventually gave up and introduced the users to MSQuery (MSQRY32.exe)

It would be great to find a way to "mask" MSQuery in order to disable certain features and enhance others.

My suggestion: use MSQuery and provide specific documentation to avoid runaway queries.
Avatar of rskelton75
rskelton75

ASKER

Thanks guys.

I think I stumbled across a solution on the codeguru.com site that pretty much covers what I'm trying to do.  You can check it out @:

http://codeguru.earthweb.com/mfc_database/dynamic_odbc_class.shtml

That article has proved to be very useful.
Looks cool.
If I understand it correctly it is a general class to encapsulate getting data without binding fields to variables.

From your question.
'The tricky thing is that I want the user to be able to write these sql queries as if they have no knowledge of the structure of any Recordsets contained within the application'


From my original comment
eg Step 1) Do you want address, age, shoe size....
Then based on the selection adress they can enter name, age, town etc.  When they hit the ok you parse for entered info and build the SQL.

How does the user know where the address, age, show size...  are stored?  How does the user know how the tables are linked together?  This class doesn't address any of those problems at all and they are by far the more complex problems you face.
Well...

fortunately, for this particular application it is assumed that the user knows the schema of the database, that's how it's possible for the user to perform these open queries in the first place, so here they know how tables are linked.

As far as returned records are concerned, this information just needs to be displayed in a coherent manner.  I would want to be able to do simple things such as sorting and organizing data in appropriate columns to display on screen, but no advanced calculations beyond that.  In the class posted above, it is possible to retrieve specific columns by name (the name in the actual db) as each record is returned, so I could store this result in whatever fashion I see fit.  So for basic reporting, this should be sufficient.

I do agree with you about the complex problems that you speak of however.  There is no automatic binding of record results and corresponding variables, fortunately I don't think it will be necessary.  I just need to display results in this instance.
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial