First, please understand I don't know how to program in C<anything>, nor do I know SQL construct/queries.
Second, the geek scripting coding person I am would presume the following.
Write C++ app that opens sockets, sends text strings to specific SQL db port in SQL query format.
C++ app will expect response, keep socket open listening for that response.
As always in all languages, give reasonable timeout time in case db isn't responding.
The above is extremely simplified, but should at least give start to ideas.