Solved

Query flexibility with MFC

Posted on 2003-12-02
9
204 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 6

Expert Comment

by:Triskelion
Comment Utility
Looks cool.
0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
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
Comment Utility
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
Comment Utility
PAQed, with points refunded (125)

Computer101
E-E Admin
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now