Home » Renegade Discussions » Mod Forum » MySQL with SSGM?
Re: MySQL with SSGM? [message #432893 is a reply to message #432883] |
Fri, 16 July 2010 21:47 |
|
reborn
Messages: 3231 Registered: September 2004 Location: uk - london
Karma:
|
General (3 Stars) |
|
|
TechnoBulldog wrote on Fri, 16 July 2010 20:48 | It's sad that the only reason I'm posting is because I have a problem.
I'm new to making c++ SSGM plugins and MySQL with c++. I'm trying to make a simple "!postnote" command that will add a player's name and message to a table in the database (I know someone is going to say "Why don't you use fstream or another io function?" It's because I want to experiment with databases). At the moment, I've been able to make it connect, but whenever it tries to execute a query, the server crashes. It doesn't seem to have any trouble with connecting to MySQL, I mean, if I use the correct username and password, it works fine, and when it's the incorrect username and password, it tells me there was an error. I only seem to have a problem when I try to execute a query, at which point, the server crashes without adding anything to the database. I also get 7 warnings when I compile it, all coming from "cppconn/exception.h". I made a simple console application using the same stuff and it worked fine.
I suppose my first question would be, is it possible to have MySQL in an SSGM plugin?
Second would be, is there an obvious reason it is crashing my server?
Toggle Spoiler
It is the same as the example plugin, except for the following changes.
Notes: I changed the "Treat Warnings As Errors" to no (/wx I think) and I removed /analyze because it was causing a warning. I'm using this for the MySQL client library and this for the c++ connector.
Compiler: MSVC++ 2008 Express
Linked Libraries: mysqlcppconn.lib libmysql.lib
Server Folder DLLs: libmysql.dll MSVCP90.dll MSVCR90.dll mysqlcppconn.dll
Edited Source:
Toggle Spoiler
class PostNoteCommand : public ChatCommandClass
{
void Triggered(int ID,const TokenClass &Text,int ChatType)
{
/* Text is a tokenized version of the command paramter.
Text[1] would get the first word after the command.
Text[0] would get everything after the command.
Text(3) would get word 3 and everything after it.
Text(2,4) would get words 2 through 4.
*/
try
{
std::string pName = Get_Player_Name_By_ID(ID);
con = driver->connect("tcp://127.0.0.1:3306", "admin", "****word");
// I'm not entirely sure what this does, but I'm guessing that it selects the database.
con->setSchema("renegade");
statement = con->createStatement();
std::string query = StrFormat("INSERT INTO messages(name, message) VALUES('%s', '%s')", pName, Text[0]);
// Will cause server to crash.
//statement->execute(query);
// Will cause server to crash.
//statement->executeQuery("INSERT INTO messages(name, message) VALUES('tester5', 'testing value')");
}
catch(sql::SQLException &e)
{
Console_Input("msg MySQL query failure...");
// error C2664: 'Console_Input' : cannot convert parameter 1 from 'std::string' to 'const char *'
// No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
//Console_Input(StrFormat("ppage %d MySQL Error: %%", ID, e.what()));
}
delete statement;
delete con;
}
};
ChatCommandRegistrant<PostNoteCommand> PostNoteCommandReg("!postnote", CHATTYPE_ALL, 1, GAMEMODE_ALL);
Build Output Window:
Toggle Spoiler
Compiling...
plugin.cpp
C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\include\cppconn/exception.h(47) : warning C4251: 'sql::SQLException::sql_state' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'sql::SQLException'
with
[
_Elem=char,
_Traits=std::char_traits,
_Ax=std::allocator
]
C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\include\cppconn/exception.h(79) : warning C4512: 'sql::SQLException' : assignment operator could not be generated
C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\include\cppconn/exception.h(41) : see declaration of 'sql::SQLException'
C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\include\cppconn/exception.h(88) : warning C4512: 'sql::MethodNotImplementedException' : assignment operator could not be generated
C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\include\cppconn/exception.h(81) : see declaration of 'sql::MethodNotImplementedException'
C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\include\cppconn/exception.h(97) : warning C4512: 'sql::InvalidArgumentException' : assignment operator could not be generated
C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\include\cppconn/exception.h(90) : see declaration of 'sql::InvalidArgumentException'
C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\include\cppconn/exception.h(106) : warning C4512: 'sql::InvalidInstanceException' : assignment operator could not be generated
C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\include\cppconn/exception.h(99) : see declaration of 'sql::InvalidInstanceException'
C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\include\cppconn/exception.h(116) : warning C4512: 'sql::NonScrollableException' : assignment operator could not be generated
C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\include\cppconn/exception.h(109) : see declaration of 'sql::NonScrollableException'
.\plugin.cpp(97) : warning C4101: 'e' : unreferenced local variable
Linking...
Searching libraries
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\ws2_32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\user32.lib:
Searching C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\lib\opt\mysqlcppconn.lib:
Searching C:\Program Files\MySQL\MySQL Connector C 6.0.2\lib\opt\libmysql.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\kernel32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\gdi32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\winspool.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\comdlg32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\advapi32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\shell32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\ole32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\oleaut32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\uuid.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\odbc32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\odbccp32.lib:
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\LIBCMT.lib:
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\OLDNAMES.lib:
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\libcpmt.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\ws2_32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\user32.lib:
Searching C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\lib\opt\mysqlcppconn.lib:
Searching C:\Program Files\MySQL\MySQL Connector C 6.0.2\lib\opt\libmysql.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\kernel32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\gdi32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\winspool.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\comdlg32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\advapi32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\shell32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\ole32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\oleaut32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\uuid.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\odbc32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\odbccp32.lib:
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\LIBCMT.lib:
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\OLDNAMES.lib:
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\libcpmt.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\ws2_32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\user32.lib:
Searching C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\lib\opt\mysqlcppconn.lib:
Searching C:\Program Files\MySQL\MySQL Connector C 6.0.2\lib\opt\libmysql.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\kernel32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\gdi32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\winspool.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\comdlg32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\advapi32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\shell32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\ole32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\oleaut32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\uuid.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\odbc32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\odbccp32.lib:
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\LIBCMT.lib:
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\OLDNAMES.lib:
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\libcpmt.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\ws2_32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\user32.lib:
Searching C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\lib\opt\mysqlcppconn.lib:
Searching C:\Program Files\MySQL\MySQL Connector C 6.0.2\lib\opt\libmysql.lib:
Finished searching libraries
Creating library .\bin/scripts.lib and object .\bin/scripts.exp
Searching libraries
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\ws2_32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\user32.lib:
Searching C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\lib\opt\mysqlcppconn.lib:
Searching C:\Program Files\MySQL\MySQL Connector C 6.0.2\lib\opt\libmysql.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\kernel32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\gdi32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\winspool.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\comdlg32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\advapi32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\shell32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\ole32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\oleaut32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\uuid.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\odbc32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\odbccp32.lib:
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\LIBCMT.lib:
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\OLDNAMES.lib:
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\libcpmt.lib:
Finished searching libraries
Generating code
Finished generating code
Searching libraries
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\ws2_32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\user32.lib:
Searching C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\lib\opt\mysqlcppconn.lib:
Searching C:\Program Files\MySQL\MySQL Connector C 6.0.2\lib\opt\libmysql.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\kernel32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\gdi32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\winspool.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\comdlg32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\advapi32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\shell32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\ole32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\oleaut32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\uuid.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\odbc32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\odbccp32.lib:
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\LIBCMT.lib:
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\OLDNAMES.lib:
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\libcpmt.lib:
Finished searching libraries
Searching libraries
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\ws2_32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\user32.lib:
Searching C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\lib\opt\mysqlcppconn.lib:
Searching C:\Program Files\MySQL\MySQL Connector C 6.0.2\lib\opt\libmysql.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\kernel32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\gdi32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\winspool.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\comdlg32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\advapi32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\shell32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\ole32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\oleaut32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\uuid.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\odbc32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\odbccp32.lib:
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\LIBCMT.lib:
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\OLDNAMES.lib:
Searching C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\libcpmt.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\ws2_32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\user32.lib:
Searching C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\lib\opt\mysqlcppconn.lib:
Searching C:\Program Files\MySQL\MySQL Connector C 6.0.2\lib\opt\libmysql.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\kernel32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\gdi32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\winspool.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\comdlg32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\advapi32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\shell32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\ole32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\oleaut32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\uuid.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\odbc32.lib:
Searching C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\odbccp32.lib:
Finished searching libraries
Embedding manifest...
Creating browse information file...
Microsoft Browse Information Maintenance Utility Version 9.00.30729
Copyright (C) Microsoft Corporation. All rights reserved.
If I've made a stupid mistake somewhere, please point it out. If you think you might be able to help, but I left something out, let me know and I'll try to post the info. This is bugging me a lot haha. I also have a bad feeling this is the wrong place to post this...
|
Welcome to the forums. =]
The FDS can interact with databases, this shouldn't be a problem.
Infact, someone called "jnz" (an awesome chap) almost finished a bot that interacted with a database (before he decided to halt development), you can see the bot's code in this release, here: http://www.littlebigsite.co.uk/Misc/Files/Projects.rar
Sadly, I do not know much about database interaction and MySQL, so I cannot help much to be honest, although I would if I could...
If your console application worked fine, and it is connecting to the database fine, then I think we can assume it's the query itself that's causing an error?
I would be keen to see the console applications query...
Perhaps you could try a test query that does not rely on the player GameObject's, but just a normal string?
I am thinking there might be a possible cause in the below code, because you're using a std string, and it should be converted to a c string.
std::string query = StrFormat("INSERT INTO messages(name, message) VALUES('%s', '%s')", pName, Text[0]);
Should be:
std::string query = StrFormat("INSERT INTO messages(name, message) VALUES('%s', '%s')", pName.c_str(), Text[0]/*may also need to be concerted to a c string?*/);
I'm glad you did post this question because it's an excellent thread!
[Updated on: Fri, 16 July 2010 21:54] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sun Nov 24 17:37:34 MST 2024
Total time taken to generate the page: 0.00904 seconds
|