Solved

Query flexibility with MFC

Posted on 2003-12-02
9
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
canBalance challenge 34 113
Use of condition with 'serial' in ansible 2 103
wordappend challenge 8 252
Problem to event 3 123
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

752 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