Solved

Query flexibility with MFC

Posted on 2003-12-02
9
221 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:rskelton75
  • 2
  • 2
  • 2
  • +1
9 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9873180
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
 
LVL 6

Expert Comment

by:Triskelion
ID: 9928465
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
 

Author Comment

by:rskelton75
ID: 9939525
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 6

Expert Comment

by:Triskelion
ID: 9939794
Looks cool.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9940360
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
 

Author Comment

by:rskelton75
ID: 9940504
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
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 11992046
PAQed, with points refunded (125)

Computer101
E-E Admin
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question