2
votes

I get a strange behavior in my CPP application using the mysqlcpp library with sql::SQLString. When I create a ne SQLString, either from const char or std::string, it seems like the constructor malformes the content.

Here my code:

sql::SQLString hostname("jp-sys3");

//sql::SQLString hostname = sql::SQLString(settings->database().hostname());

sql::SQLString username = sql::SQLString(settings->database().username());

sql::SQLString password = sql::SQLString(settings->database().password());

When I initialize a variable of the SQLString with this literal or from my settings class (std::string), I see, when setting a break point (at line sql::SQLString username), that the content of hostname is something completely different E.g.

realStr="\b=8";

http://s24.postimg.org/w1ecbfbo5/breakpoint.png
But this differs from run to run.

At first I used pre-build libraries (1.1.3, x32) and later I built it from source (Visual Studio 2012 Update 2). This resulted in the same behavior. Debug build treats the char literal in the right way, the release build not.

Can anyone give a hint what`s going wrong here?

Debug link options:

/OUT:"D:\Projects\STGPanel\Debug\STGPanel.exe" /MANIFEST /NXCOMPAT /PDB:"D:\Projects\STGPanel\Debug\STGPanel.pdb" /DYNAMICBASE "SDL.lib" "SDLmain.lib" "SDL_ttf.lib" "mysqlcppconn.lib" "xerces-c_3.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG /MACHINE:X86 /INCREMENTAL:NO /PGD:"D:\Projects\STGPanel\Debug\STGPanel.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\STGPanel.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1 

Release link options:

/OUT:"D:\Projects\STGPanel\Release\STGPanel.exe" /MANIFEST /LTCG /NXCOMPAT /PDB:"D:\Projects\STGPanel\Release\STGPanel.pdb" /DYNAMICBASE "SDL.lib" "SDLmain.lib" "SDL_ttf.lib" "mysqlcppconn.lib" "xerces-c_3.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG /MACHINE:X86 /OPT:REF /SAFESEH /PGD:"D:\Projects\STGPanel\Release\STGPanel.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Release\STGPanel.exe.intermediate.manifest" /OPT:ICF /ERRORREPORT:PROMPT /NOLOGO /TLBID:1 
2

2 Answers

1
votes

I found finally the solution, this behavior was caused through the binarys downloaded from mysql. After rebuild with my Visual Studio version everything works as intended.

1
votes

Had a similar problem, it may help you one day :

It seems that mysqlcppconn (and more specificaly sql::SQLString) doesn't like std::string (keep crashing with a bad_alloc error). So make sure to pass char* and not std::string.

Don't work (will compile, but crash):

stmt->execute("INSERT INTO logs(time) VALUES (" + to_string(timestamp) + ")");

Do work :

string sqlRequest = "INSERT INTO logs(time) VALUES (" + to_string(timestamp) + ")";
stmt->execute(sqlRequest.c_str());