Click here to Skip to main content
15,388,688 members
Articles / Desktop Programming / MFC
Posted 15 Dec 2004


49 bookmarked

QuickQuery - a database querying tool

Rate me:
Please Sign up or sign in to vote.
4.74/5 (15 votes)
7 Feb 20053 min read
A tool for querying all types of databases.



QuickQuery is the second program I wrote on my own in C++, just to experiment. It was an attempt to make an app that could run queries on any type of database. This code was written using VC6 and has been run on Windows 2000 and XP.


I started off trying to make something that the rest of my company could use. I still use it every now and then, but not much. At the time, I was also trying to learn DirectX programming, so you'll see some of that in here, too. :)

Using the code

QuickQuery uses ODBC to run the queries and the CRecordset-derived classes from Microsoft's "catsets" source code. These sets are used to get the primary keys and columns of all the tables in the database. There is functionality there that I didn't implement, but that can still be used.

This program uses a CFormView and switches back and forth between that and a CListView view. By switching to the ListView, you can see all the tables in a database:

Table View

and double-clicking on a table will show you the columns and column types for that table.

Column View

This is done by clicking the double-arrow icon on the toolbar. I used this code that I found somewhere in my MSDN to switch views in a function of my app, called SwitchView():

CView* CQuickQueryApp::SwitchView(CView* pNewView)

    CView* pActiveView =
        ((CFrameWnd*) m_pMainWnd)->GetActiveView();

        // Exchange view window ID's so RecalcLayout() works.
        #ifndef _WIN32
        UINT temp = ::GetWindowWord(pActiveView->m_hWnd, GWW_ID);
        ::SetWindowWord(pActiveView->m_hWnd, GWW_ID,
                     ::GetWindowWord(pNewView->m_hWnd, GWW_ID));
        ::SetWindowWord(pNewView->m_hWnd, GWW_ID, temp);
        UINT temp = ::GetWindowLong(pActiveView->m_hWnd, GWL_ID);
        ::SetWindowLong(pActiveView->m_hWnd, GWL_ID,
                     ::GetWindowLong(pNewView->m_hWnd, GWL_ID));
        ::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp);

        ((CFrameWnd*) m_pMainWnd)->SetActiveView(pNewView);
        ((CFrameWnd*) m_pMainWnd)->RecalcLayout();
    catch(CException* err)
        pErrObject->HandleError(err," "," ");
        AfxMessageBox("Unhandled Error ");
    return pActiveView;

There is also a pretty generic 'Find' dialog that lets you search, when a ListView is active. It allows you to search by column. Although it should probably be a modeless dialog, at the time I made this project, I really didn't know how to do that. :)

Find Dialog

Queries can be saved, as well as the connection string to your last connection so that when you open a query, it connects you to the right database. Your last connection is also saved in the registry so that when you open QuickQuery, it will connect you to the last connection you had open before shutting down.

void CQuickQueryDoc::Serialize(CArchive& ar)
        if (ar.IsStoring())
            //if opening
            if(!m_view) //if view is not yet showing
                m_bSerializing = TRUE;

            //if view has been initialized already
    catch(CException* err)
        pErrObject->HandleError(err," "," ");
        AfxMessageBox("Unhandled Error");

Points of Interest

The 'About' dialog has a simple PictureBox control that I use to display a spinning Direct3D square, with my old company's logo texture-mapped onto the square. This was made using DirectX 8, but I have version 9 now, and it compiles just fine. Maybe even the DirectX code involved in the dialog will help somebody out! (I can hope, can't I?)

About QuickQuery

As I said, this was my second C++ project, not out of a tutorial, so please don't be too harsh. :)

There is a context-sensitive help file associated with QuickQuery that I never fully some of it works - some of it doesn't. You'll probably have to change the path to the help file for building purposes.

You are free to do whatever you want with this code. Like I said, it was my very first project, and I had actually forgot about it until I saw it in one of my old folders. If I were to do a project like this over from scratch, I'd use ADO, only using the ODBC function to get the connection string, as I have done since.

Known Issues

When running this program, after shutting down, I see a memory leak in the debug output, but I really have no idea where it is (or much desire to investigate).

This program is a lot larger than it needs to be, mostly because of bitmaps (I hope). There is a bug that occurs sometimes when switching views. Error-handling could be a lot better.


  • Posted 12/15/2004.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
Started off with vb6 Smile | :) and am self-taught at C++, FoxPro, DirectX, etc. I'm currently developing with VFP9 and C# in desktop apps, webservices, telephony apps.

Comments and Discussions

GeneralHOWTO: Enumerating Tables Pin[AT]Gmail5-Jul-06 10:08[AT]Gmail5-Jul-06 10:08 
GeneralRe: HOWTO: Enumerating Tables Pin
Christopher Elliott17-Jan-07 9:36
MemberChristopher Elliott17-Jan-07 9:36 
GeneralUNICODE RELEASE version Pin
transoft10-Mar-06 11:06
Membertransoft10-Mar-06 11:06 
GeneralRe: UNICODE RELEASE version Pin
BlackDice10-Mar-06 12:53
MemberBlackDice10-Mar-06 12:53 
GeneralRe: UNICODE RELEASE version Pin
transoft10-Mar-06 13:02
Membertransoft10-Mar-06 13:02 
GeneralRe: UNICODE RELEASE version Pin
BlackDice10-Mar-06 13:10
MemberBlackDice10-Mar-06 13:10 2003 error! Pin
liveboys6-Oct-05 17:11
Memberliveboys6-Oct-05 17:11 
GeneralRe: 2003 error! Pin
BlackDice7-Oct-05 3:49
MemberBlackDice7-Oct-05 3:49 
Generalremove direct 3d pls Pin
ViolaCase3-Apr-05 22:06
MemberViolaCase3-Apr-05 22:06 
Generalinability to compile &quot;module D3D8.dll&quot; statement Pin
bstrack17-Feb-05 15:55
Memberbstrack17-Feb-05 15:55 
GeneralRe: inability to compile &quot;module D3D8.dll&quot; statement Pin
BlackDice18-Feb-05 2:45
MemberBlackDice18-Feb-05 2:45 
GeneralRe: inability to compile &quot;module D3D8.dll&quot; statement Pin
bstrack18-Feb-05 3:22
Memberbstrack18-Feb-05 3:22 
GeneralC# version Pin
gxdata7-Feb-05 17:43
Membergxdata7-Feb-05 17:43 
QuestionHow to connect with Oracle Server? Pin
Shinde Vikram V.25-Dec-04 18:00
MemberShinde Vikram V.25-Dec-04 18:00 
AnswerRe: How to connect with Oracle Server? Pin
BlackDice27-Dec-04 2:30
MemberBlackDice27-Dec-04 2:30 
GeneralMemory Leak Pin
Jörgen Sigvardsson17-Dec-04 11:07
MemberJörgen Sigvardsson17-Dec-04 11:07 
GeneralRe: Memory Leak Pin
LAT5-Feb-06 1:02
MemberLAT5-Feb-06 1:02 
GeneralSource files missing Pin
doug33316-Dec-04 6:50
Memberdoug33316-Dec-04 6:50 
GeneralRe: Source files missing Pin
BlackDice16-Dec-04 9:34
MemberBlackDice16-Dec-04 9:34 
GeneralRe: Source files missing Pin
doug33316-Dec-04 11:41
Memberdoug33316-Dec-04 11:41 
GeneralRe: Source files missing Pin
BlackDice17-Dec-04 2:25
MemberBlackDice17-Dec-04 2:25 
GeneralHelp I've fallen and I can't get up Pin
c-sharp16-Dec-04 1:52
Memberc-sharp16-Dec-04 1:52 
GeneralRe: Help I've fallen and I can't get up Pin
BlackDice16-Dec-04 4:09
MemberBlackDice16-Dec-04 4:09 
GeneralRe: Help I've fallen and I can't get up Pin
c-sharp16-Dec-04 6:15
Memberc-sharp16-Dec-04 6:15 
GeneralRe: Help I've fallen and I can't get up Pin
BlackDice16-Dec-04 9:32
MemberBlackDice16-Dec-04 9:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.