本文整理汇总了C++中Database::Connect方法的典型用法代码示例。如果您正苦于以下问题:C++ Database::Connect方法的具体用法?C++ Database::Connect怎么用?C++ Database::Connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Database
的用法示例。
在下文中一共展示了Database::Connect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: db
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);
}
示例2: HandleInput
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(" ");
}
示例3: main
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);
}
}
示例4: main
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);
//.........这里部分代码省略.........