Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 114911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:56:09+00:00 2026-05-11T02:56:09+00:00

In a C++ application that can use just about any relational database, what would

  • 0

In a C++ application that can use just about any relational database, what would be the best way of generating queries that can be easily extended to allow for a database engine’s eccentricities?

In other words, the code may need to retrieve data in a way that is not consistent among the various database engines. What’s the best way to design the code on the client side to generate queries in a way that will make supporting a new database engine a relatively painless affair.

For example, if I have (MFC)code that looks like this:

CString query = 'SELECT id FROM table' results = dbConnection->Query(query); 

and we decide to support some database that uses, um, ‘AVEC’ instead of ‘FROM’. Now whenever the user uses that database engine, this query will fail.

Options so far:

  • Worst option: have the code making the query check the database type.
  • Better option: Create query request method on the db connection object that takes a unique query ‘code’ and returns the appropriate query based on the database engine in use.
  • Betterer option: Create a query builder class that allows the caller to construct queries without using any SQL directly. Once the query is completed, caller can invoke a ‘Generate’ method which returns a query string approrpriate for the active database engine
  • Best option: ??

Note: The database engine itself is abstracted away through some thin layers of our own creation. It’s the queries themselves are the only remaining problem.

Solution:
I’ve decided to go with the ‘better’ option (query ‘selector’) for two reasons.

  1. Debugging: As mentioned below, debugging is going to be slightly easier with the selector approach since the queries are pre-built and listed out in a readable form in code.
  2. Flexibility: It occurred to me that there are some databases which might have vastly better and completely different ways of solving a particular query. For example, with Access I perform a complicated query on multiple tables each time because I have to, but on Sql Server I’d like to setup a view. Selecting from the view and from several tables are completely different queries (i think) and this query selector would handle it easily.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:56:10+00:00Added an answer on May 11, 2026 at 2:56 am

    I would think that what you would want to do, if you needed the ability to support multiple databases, would be to create a data provider interface (or abstract class) and associated concrete implementations. The data provider would need to support your standard query operators and other common, supported functionality required support your query operations (have a look at IEnumerable extension methods in .NET 3.5). Each concrete provider would then translate these into specific queries based on the target database engine.

    Essentially, what you do is create a database abstraction layer and have your code interact with it. If you can find one of these for C++, it would probably be worth buying instead of writing. You may also want to look for Inversion of Control (IoC) containers for C++ that would basically do this and more. I know of several for Java and C#, but I’m not familiar with any for C++.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 62k
  • Answers 62k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You cannot do this directly. Have a look in this… May 11, 2026 at 9:58 am
  • added an answer From the mysql manual: Note that all MySQL collations are… May 11, 2026 at 9:58 am
  • added an answer You should be able to use the following command-options in… May 11, 2026 at 9:58 am

Related Questions

In a C++ application that can use just about any relational database, what would
We host a C++ based WebServices application in IIS and we're finding that when
I am using an application in c++ that uses a special dprintf function to
I have a Windows application written in C++ that occasionally evaporates. I use the
Is there a class/example application for a message-only window that is in C++ Win32
I am looking at embedding Lua in a C++ application I am developing. My
I'm using GDI+ in a C++/MFC application and I just can't seem to avoid
I'm using libcurl in a Win32 C++ application. I have the curllib.vcproj project added
I want to access the call stack at runtime in a Native C++ application.
I am looking at embedding perl 5.10 in a large C++ application compiled with

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.