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.
rskelton75Asked:
Who is Participating?
 
Computer101Connect With a Mentor Commented:
PAQed, with points refunded (125)

Computer101
E-E Admin
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
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.
0
 
TriskelionCommented:
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.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
rskelton75Author Commented:
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.
0
 
TriskelionCommented:
Looks cool.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
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.
0
 
rskelton75Author Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.