6 #include "pol_global_config.h" 12 #include "../../bscript/berror.h" 13 #include "../../bscript/impstr.h" 14 #include "../../clib/logfacility.h" 15 #include "../../clib/refptr.h" 16 #include "../../clib/weakptr.h" 17 #include "../globals/network.h" 18 #include "../polsem.h" 19 #include "../sqlscrobj.h" 20 #include "../uoexec.h" 28 using namespace Module;
44 using namespace Bscript;
48 uoexec( static_cast<Core::
UOExecutor&>( exec ) )
55 const std::string host,
56 const std::string username,
57 const std::string password )
59 auto msg = [
uoexec, host, username, password]() {
60 std::unique_ptr<Core::BSQLConnection> sql;
65 if ( sql->getLastErrNo() )
77 else if ( !sql->connect( host.data(), username.data(), password.data() ) )
102 if ( !uoexec->suspend() )
104 DEBUGLOG <<
"Script Error in '" << uoexec->scriptname() <<
"' PC=" << uoexec->PC <<
": \n" 105 <<
"\tThe execution of this script can't be blocked!\n";
110 return new BLong( 0 );
115 const std::string db )
119 auto msg = [
uoexec, sqlRef, db]() {
120 if ( sqlRef ==
nullptr )
132 else if ( !sqlRef->select_db( db.c_str() ) )
157 if ( !uoexec->suspend() )
159 DEBUGLOG <<
"Script Error in '" << uoexec->scriptname() <<
"' PC=" << uoexec->PC <<
": \n" 160 <<
"\tThe execution of this script can't be blocked!\n";
164 return new BLong( 0 );
169 const std::string query,
174 if ( params !=
nullptr )
176 sharedParams = std::make_shared<Core::QueryParam>();
178 for (
unsigned i = 0; i < params->
ref_arr.size(); ++i )
182 if ( obj !=
nullptr )
183 sharedParams->insert( sharedParams->end(), obj->impptr()->
getStringRep() );
189 auto msg = [
uoexec, sqlRef, query, sharedParams]() {
190 if ( sqlRef ==
nullptr )
203 else if ( !sqlRef->query( query, sharedParams ) )
228 if ( !uoexec->suspend() )
230 DEBUGLOG <<
"Script Error in '" << uoexec->scriptname() <<
"' PC=" << uoexec->PC <<
": \n" 231 <<
"\tThe execution of this script can't be blocked!\n";
236 return new BLong( 0 );
244 if ( !host || !username || !password )
246 return new BError(
"Invalid parameters" );
258 return new BError(
"Invalid parameters" );
270 if ( !sql || !query )
272 return new BError(
"Invalid parameters" );
276 use_parameters ? params : nullptr );
285 return new BError(
"Invalid parameters" );
296 return new BError(
"Invalid parameters" );
298 if ( !result || !index )
300 return new BError(
"Invalid parameters" );
304 return new BError(
"Column does not exist" );
305 return new String( name );
315 return new BError(
"Invalid parameters" );
327 return new BError(
"Invalid parameters" );
337 return new BError(
"Invalid parameters" );
339 return new BLong( 1 );
348 return new BError(
"Invalid parameters" );
355 #define MF_NO_MYSQL( funcName ) \ 356 BObjectImp* SQLExecutorModule::funcName() \ 358 return new BError( "POL was not compiled with MySQL support." ); \
virtual std::string getStringRep() const =0
const char * field_name(unsigned int index) const
Bscript::BObjectImp * mf_NumRows()
std::vector< FunctionDef > FunctionTable
Bscript::BObjectImp * mf_Close()
Bscript::BObjectImp * mf_ConnectToDB()
bool getParam(unsigned param, int &value)
virtual std::string getStringRep() const POL_OVERRIDE
int affected_rows() const
BObjectImp * getParamImp(unsigned param)
std::unique_ptr< SQLService > sql_service
Bscript::BObjectImp * mf_Query()
SQLExecutorModule(Bscript::Executor &exec)
NetworkManager networkManager
std::shared_ptr< QueryParam > QueryParams
weak_ptr_owner< UOExecutor > weakptr
const String * getStringParam(unsigned param)
Bscript::BObjectImp * mf_NumFields()
Bscript::BObjectImp * mf_FetchRow()
Core::UOExecutor & uoexec
Bscript::BObjectImp * mf_AffectedRows()
Bscript::BObjectImp * mf_FieldName()
static Bscript::BObjectImp * background_query(weak_ptr< Core::UOExecutor > uoexec, Core::BSQLConnection *sql, const std::string query, const Bscript::ObjArray *params)
static Bscript::BObjectImp * background_connect(weak_ptr< Core::UOExecutor > uoexec, const std::string host, const std::string username, const std::string password)
bool getObjArrayParam(unsigned param, ObjArray *&pobjarr)
Bscript::BObjectImp * mf_SelectDb()
static Bscript::BObjectImp * background_select(weak_ptr< Core::UOExecutor > uoexec, Core::BSQLConnection *sql, const std::string db)