Esempio n. 1
0
void TestDatabase::Test10AdHoc() {
	cout << __PRETTY_FUNCTION__ << endl;

	bool wasCaught = false;
	try {
		Database db ("localhost", "root", "", "sakila", 0, NULL, 0);
		db.Connect();

		AdhocStatement stmt(db, "SELECT EMAIL, CREATE_DATE FROM CUSTOMER WHERE CREATE_DATE = ?");

		Julian createDate(2006, 02, 14, 22, 04, 36, 0);
		stmt << Nullable<Julian>(createDate) << execute << fetch;

		UTASSERT(stmt.NumberOfReturnedRows() == 271);
	} catch (const DatabaseException &de) {
		cout << de << endl;
		wasCaught = true;
	} catch (const UTFail &fail) {
		throw;
	} catch (const JulianException &je) {
		cout << je.what() << endl;
		wasCaught = true;
	} catch (...) {
		cout << "random failure" << endl;
		wasCaught = true;
	}

	UTASSERT(! wasCaught);
}
Esempio n. 2
0
void DatabaseDemo::HandleInput(const String& input)
{
    // Echo input string to stdout
    Print(input);
    row_ = 0;
    if (input == "quit" || input == "exit")
        engine_->Exit();
    else if (input.StartsWith("set") || input.StartsWith("get"))
    {
        // We expect a key/value pair for 'set' command
        Vector<String> tokens = input.Substring(3).Split(' ');
        String setting = tokens.Size() ? tokens[0] : "";
        if (input.StartsWith("set") && tokens.Size() > 1)
        {
            if (setting == "maxrows")
                maxRows_ = Max(ToUInt(tokens[1]), 1U);
            else if (setting == "connstr")
            {
                String newConnectionString(input.Substring(input.Find(" ", input.Find("connstr")) + 1));
                Database* database = GetSubsystem<Database>();
                DbConnection* newConnection = database->Connect(newConnectionString);
                if (newConnection)
                {
                    database->Disconnect(connection_);
                    connection_ = newConnection;
                }
            }
        }
        if (tokens.Size())
        {
            if (setting == "maxrows")
                Print(ToString("maximum rows is set to %d", maxRows_));
            else if (setting == "connstr")
                Print(ToString("connection string is set to %s", connection_->GetConnectionString().CString()));
            else
                Print(ToString("Unrecognized setting: %s", setting.CString()));
        }
        else
            Print("Missing setting paramater. Recognized settings are: maxrows, connstr");
    }
    else
    {
        // In this sample demo we use the dbCursor event to loop through each row as it is being fetched
        // Regardless of this event is being used or not, all the fetched rows will be made available in the DbResult object,
        //   unless the dbCursor event handler has instructed to filter out the fetched row from the final result
        DbResult result = connection_->Execute(input, true);

        // Number of affected rows is only meaningful for DML statements like insert/update/delete
        if (result.GetNumAffectedRows() != -1)
            Print(ToString("Number of affected rows: %d", result.GetNumAffectedRows()));
    }
    Print(" ");
}
Esempio n. 3
0
void TestDatabase::Test12() {
	cout << __PRETTY_FUNCTION__ << endl;

	bool wasCaught = false;
	try {
		Database db ("localhost", "root", "", "sakila", 0, NULL, 0);
		db.Connect();

		bool stmtCaught = false;
		try {
			Statement stmt(db, "SELECT ADDRESS, ADDRESS2 FROM ADDRESS WHERE ADDRESS2 = ?");
			Nullable<string> addr1;
			Nullable<string> addr2;

			int count = 0;
			UTASSERT(stmt << addr2 << execute);
			while(stmt << fetch) {
				stmt >> addr1 >> addr2;
				UTASSERT(!addr2.HasValue());
				count++;
			}

			UTASSERT(count == 0);

		} catch (const DatabaseException &de) {
			cout << de << endl;
			stmtCaught = true;
		}

		UTASSERT(! stmtCaught);
	} catch (const DatabaseException &de) {
		cout << de << endl;
		wasCaught = true;
	} catch (const JulianException &je) {
		cout << je.what() << endl;
		wasCaught = true;
	} catch (const UTFail &fail) {
		throw;
	} catch (...) {
		cout << "random failure" << endl;
		wasCaught = true;
	}

	UTASSERT(! wasCaught);
}
Esempio n. 4
0
int main() {
	RegisterExecutablePlatform(ExePlatformQueryServ);
	set_exception_handler();

	Timer LFGuildExpireTimer(60000);

	Timer InterserverTimer(INTERSERVER_TIMER); // does auto-reconnect

	_log(QUERYSERV__INIT, "Starting EQEmu QueryServ.");

	if (!queryservconfig::LoadConfig()) {

		_log(QUERYSERV__INIT, "Loading server configuration failed.");

		return 1;
	}

	Config = queryservconfig::get();

	if(!load_log_settings(Config->LogSettingsFile.c_str()))
		_log(QUERYSERV__INIT, "Warning: Unable to read %s", Config->LogSettingsFile.c_str());
	else
		_log(QUERYSERV__INIT, "Log settings loaded from %s", Config->LogSettingsFile.c_str());

	WorldShortName = Config->ShortName;

	_log(QUERYSERV__INIT, "Connecting to MySQL...");

	if (!database.Connect(
		Config->QSDatabaseHost.c_str(),
		Config->QSDatabaseUsername.c_str(),
		Config->QSDatabasePassword.c_str(),
		Config->QSDatabaseDB.c_str(),
		Config->QSDatabasePort)) {
		_log(WORLD__INIT_ERR, "Cannot continue without a database connection.");
		return 1;
	}

	if (signal(SIGINT, CatchSignal) == SIG_ERR)	{
		_log(QUERYSERV__ERROR, "Could not set signal handler");
		return 1;
	}
	if (signal(SIGTERM, CatchSignal) == SIG_ERR)	{
		_log(QUERYSERV__ERROR, "Could not set signal handler");
		return 1;
	}

	worldserver = new WorldServer;

	worldserver->Connect();

	lfguildmanager.LoadDatabase();

	while(RunLoops) {

		Timer::SetCurrentTime();

		if(LFGuildExpireTimer.Check())
			lfguildmanager.ExpireEntries();

		if (InterserverTimer.Check()) {
			if (worldserver->TryReconnect() && (!worldserver->Connected()))
				worldserver->AsyncConnect();
		}
		worldserver->Process();

		timeout_manager.CheckTimeouts();

		Sleep(100);
	}
}
Esempio n. 5
0
File: ucs.cpp Progetto: Leere/Server
int main() {
	RegisterExecutablePlatform(ExePlatformUCS);
	set_exception_handler();

	// Check every minute for unused channels we can delete
	//
	Timer ChannelListProcessTimer(60000);

	Timer InterserverTimer(INTERSERVER_TIMER); // does auto-reconnect

	_log(UCS__INIT, "Starting EQEmu Universal Chat Server.");

	if (!ucsconfig::LoadConfig()) {

		_log(UCS__INIT, "Loading server configuration failed.");

		return 1;
	}

	Config = ucsconfig::get();

	if(!load_log_settings(Config->LogSettingsFile.c_str()))
		_log(UCS__INIT, "Warning: Unable to read %s", Config->LogSettingsFile.c_str());
	else
		_log(UCS__INIT, "Log settings loaded from %s", Config->LogSettingsFile.c_str());

	WorldShortName = Config->ShortName;

	_log(UCS__INIT, "Connecting to MySQL...");

	if (!database.Connect(
		Config->DatabaseHost.c_str(),
		Config->DatabaseUsername.c_str(),
		Config->DatabasePassword.c_str(),
		Config->DatabaseDB.c_str(),
		Config->DatabasePort)) {
		_log(WORLD__INIT_ERR, "Cannot continue without a database connection.");
		return 1;
	}

	char tmp[64];

	if (database.GetVariable("RuleSet", tmp, sizeof(tmp)-1)) {
		_log(WORLD__INIT, "Loading rule set '%s'", tmp);
		if(!RuleManager::Instance()->LoadRules(&database, tmp)) {
			_log(UCS__ERROR, "Failed to load ruleset '%s', falling back to defaults.", tmp);
		}
	} else {
		if(!RuleManager::Instance()->LoadRules(&database, "default")) {
			_log(UCS__INIT, "No rule set configured, using default rules");
		} else {
			_log(UCS__INIT, "Loaded default rule set 'default'", tmp);
		}
	}

	database.ExpireMail();

	if(Config->ChatPort != Config->MailPort)
	{
		_log(UCS__ERROR, "MailPort and CharPort must be the same in eqemu_config.xml for UCS.");
		exit(1);
	}

	CL = new Clientlist(Config->ChatPort);

	ChannelList = new ChatChannelList();

	database.LoadChatChannels();

	if (signal(SIGINT, CatchSignal) == SIG_ERR)	{
		_log(UCS__ERROR, "Could not set signal handler");
		return 1;
	}
	if (signal(SIGTERM, CatchSignal) == SIG_ERR)	{
		_log(UCS__ERROR, "Could not set signal handler");
		return 1;
	}

	worldserver = new WorldServer;

	worldserver->Connect();

	while(RunLoops) {

		Timer::SetCurrentTime();

		CL->Process();

		if(ChannelListProcessTimer.Check())
			ChannelList->Process();

		if (InterserverTimer.Check()) {
			if (worldserver->TryReconnect() && (!worldserver->Connected()))
				worldserver->AsyncConnect();
		}
		worldserver->Process();

		timeout_manager.CheckTimeouts();

		Sleep(100);
	}

	ChannelList->RemoveAllChannels();

	CL->CloseAllConnections();

}