static int sql_init(dbref player) { MYSQL *result; /* If we are already connected, drop and retry the connection, in * case for some reason the server went away. */ if (mysql_struct) sql_shutdown(player); /* Try to connect to the database host. If we have specified * localhost, use the Unix domain socket instead. */ mysql_init(mysql_struct); result = mysql_real_connect(mysql_struct, DB_HOST, DB_USER, DB_PASS, DB_BASE, 3306, DB_SOCKET, 0); if (!result) { STARTLOG(LOG_PROBLEMS, "SQL", "ERR"); log_text(unsafe_tprintf("DB connect by %s : ", player < 0 ? "SYSTEM" : Name(player))); log_text("Failed to connect to SQL database."); ENDLOG return -1; } else {
void do_sql_shutdown(dbref player, dbref cause, int key) { if (sql_shutdown(player) < 0) { notify(player, "Not connected to database"); } else { notify(player, "Database connection shutdown"); } }
int sql_init(dbref player, dbref cause, char *buff, char **bufc) { sqlite3 *sqlite; int retval; /* * Make sure we have valid config options. No need to check sql_host, * only the db. */ if (!mod_db_sql_config.db || !*mod_db_sql_config.db) return -1; /* * If we are already connected, drop and retry the connection, in * case for some reason the server went away. */ if (sqlite3_struct) sql_shutdown(0,0,NULL,NULL); retval = sqlite3_open(mod_db_sql_config.db, &sqlite); if (retval != SQLITE_OK) { log_write(LOG_ALWAYS, "SQL", "CONN", "Failed to open %s: %s", mod_db_sql_config.db, sqlite3_errmsg(sqlite)); return -1; } log_write(LOG_ALWAYS, "SQL", "CONN", "Opened SQLite3 file %s", mod_db_sql_config.db); sqlite3_struct = sqlite; mod_db_sql_config.socket = -1; return 1; }
int sql_init ( dbref player, dbref cause, char *buff, char **bufc ) { PGconn *pgsql; PGresult *result; char connect_string[CONNECT_STRING_SIZE]; /* * Make sure we have valid config options. */ if ( !mod_db_sql_config.host || !*mod_db_sql_config.host ) return -1; if ( !mod_db_sql_config.db || !*mod_db_sql_config.db ) return -1; /* * If we are already connected, drop and retry the connection, in * case for some reason the server went away. */ if ( pgsql_struct ) sql_shutdown ( 0, 0, NULL, NULL ); /* * Try to connect to the database host. If we have specified * localhost, use the Unix domain socket instead. */ snprintf ( connect_string, CONNECT_STRING_SIZE, "host = '%s' dbname = '%s' user = '******' password = '******'", mod_db_sql_config.host, mod_db_sql_config.db, mod_db_sql_config.username, mod_db_sql_config.password ); pgsql = PQconnectdb ( connect_string ); if ( !pgsql ) { log_write ( LOG_ALWAYS, "SQL", "CONN", "Failed connection to SQL server %s: %s", mod_db_sql_config.host, PQerrorMessage ( pgsql ) ); return -1; } log_write ( LOG_ALWAYS, "SQL", "CONN", "Connected to SQL server %s, SQL database selected: %s", PQhost ( pgsql ), PQdb ( pgsql ) ); pgsql_struct = pgsql; mod_db_sql_config.socket = PQsocket ( pgsql ); return 1; }
int sql_init() { PGconn *pgsql; PGresult *result; char connect_string[CONNECT_STRING_SIZE]; /* * Make sure we have valid config options. */ if (!mudconf.sql_host || !*mudconf.sql_host) return -1; if (!mudconf.sql_db || !*mudconf.sql_db) return -1; /* * If we are already connected, drop and retry the connection, in * case for some reason the server went away. */ if (pgsql_struct) sql_shutdown(); /* * Try to connect to the database host. If we have specified * localhost, use the Unix domain socket instead. */ snprintf(connect_string, CONNECT_STRING_SIZE, "host = '%s' dbname = '%s' user = '******' password = '******'", mudconf.sql_host, mudconf.sql_db, mudconf.sql_username, mudconf.sql_password); pgsql = PQconnectdb(connect_string); if (!pgsql) { STARTLOG(LOG_ALWAYS, "SQL", "CONN") log_printf("Failed connection to SQL server %s: %s", mudconf.sql_host, PQerrorMessage(pgsql)); ENDLOG return -1; }
/* Called immediatly after the main game loop exits. At this point * all databases and variables are still configured */ void local_shutdown(void) { #ifdef MYSQL_VERSION sql_shutdown(-1); #endif }
void mod_db_sql_do_disconnect(dbref player, dbref cause, int key) { sql_shutdown(player, cause, NULL, NULL); }