Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to store SQL code for a C++ application?

Tags:

c++

sql

We have a C++ application that utilizes some basic APIs to send raw queries to a MS SQL Server. Scattered through the various translation units in our program, we have simple 1-2 line queries as C++ strings, and every now and then you'll see more complex queries that can be over 20 lines.

I can't help but think that the larger queries, specifically the 20+ line ones, should not be embedded in C++ code as constant strings. I want to propose pulling these out into separate text files that are loaded on-demand by the C++ application, however I'm not sure if this is the best approach.

What design choices are typical for situations like this? I definitely feel there needs to be improvement, I just don't know if moving the SQL queries out into data files (text files) is the best idea.

like image 814
void.pointer Avatar asked Oct 28 '25 04:10

void.pointer


1 Answers

You could make a DAL (Data Access Layer).

It would be the API that the rest of the program talks to. Then you can mess around and try anything and everything (Stored procedures, caching, etc.) without disturbing the main program.

like image 77
Steve Wellens Avatar answered Oct 29 '25 17:10

Steve Wellens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!