How to run .sql script file in c++? - c++

I want to execute a script file of mysql in my code, written in c++. How i can do it ?

You can always use the system function to call the mysql program to do it for you.

Well, if you want the optimal solution, simply iterate over each line (your SQL file shall have only ONE command for each line) using the standard C++ file handlings.
You simply pass each line to the MySQL library calls. This is what I do for my SQLite initialization scripts.
You can even add a very minimal comment support (like --) and skip any line starting with those characters.

Related

Run Python script inside C++ with Python.h

I'm currently aware of this turotial, but I don't see anything in the tutorial that just simply runs a script. If I have a file pySolve.py how can I just call it to be executed inside of my code? No input is required as the C++ end generates all files needed before calling the python solve script.
You need to call PyRun_File or one of its variants. And of course first you must call Py_Initialize. You can see example usage of these functions in my open-source project here: https://github.com/jzwinck/pccl/blob/master/run.cpp

Use User Input/Text File as Code

Is it possible to treat user input as lines of code in C++?
Or write it to a text file, then run that as c++ code?
I'm writing my own version of matlab, and right now it can do a lot of the numerical stuff, but only if I write the commands in like a script in main. Is there a way I could do it like matlab's command line?
Yes, there are many libraries that allow for scripting like Lua or Chaiscript which will allow you to take a file of code and execute it. There's also the advantage of being able to make changes to the code and not having to recompile each time.

How to set the sqlite parameters using C++

I need to set some parameters in sqlite like turning the headers on: (.headers ON), setting the output mode to csv : (.mode csv) and I require this to be done with C++ instead of the sqlite command line tool.
Can I know whether it is possible or not, and if possible, how to achieve this (using example)?
Thanks
The dot commands are conveniences of the sqlite command line tool. They are not available using the API. CSV is quite easy to build yourself, though.

What is the easiest way to change sections order of INI file in C++

I'm trying to read an INI file and write another INI file with the sections order changed.
Does Windows API have tools for this kind of INI file processing? Are there open-source solutions that are preferred? Or should I try to attempt to parse it manually?
Windows has its own INI functions for C. But since you mentioned C++ try Feather INI. Program Options is another from Boost.
As noted in the comment, you can use winapi functions to do this. GetPrivateProfileSectionNames returns the names of the sections in the .ini file. Which you can then iterate and call GetPrivateProfileSection() to get the content of each section.

Reading output from the command line

I'm trying to write a simple GUI for Wget. I'm looking for advice on how to read information from the command line output that Wget generates when it is doing a run. I'd like to update that download information real time to a list box or some equivalent. The GUI will be in Visual Basic. I know programs like WinWget do this, and their source code is available, but I don't know the language that's written in well enough to find what I'm looking for.
tl;dr: I need to update a list box real time with command line output.
There are two ways to use the output of one console application for the input of an other:
The first way is to use the | operator; for example:
dir |more
The second way is to write the data into a file and process it later.
dir > data.txt