summaryrefslogtreecommitdiff
path: root/sourcemod/scripting/gokz-localdb/db/setup_database.sp
blob: 49655414a64478303468bb205dc6709dd60c42ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
	Set up the connection to the local database.
*/



void DB_SetupDatabase()
{
	char error[255];
	gH_DB = SQL_Connect("gokz", true, error, sizeof(error));
	if (gH_DB == null)
	{
		SetFailState("Database connection failed. Error: \"%s\".", error);
	}

	char databaseType[8];
	SQL_ReadDriver(gH_DB, databaseType, sizeof(databaseType));
	if (strcmp(databaseType, "sqlite", false) == 0)
	{
		g_DBType = DatabaseType_SQLite;
	}
	else if (strcmp(databaseType, "mysql", false) == 0)
	{
		g_DBType = DatabaseType_MySQL;
	}
	else
	{
		SetFailState("Incompatible database driver. Use SQLite or MySQL.");
	}

	DB_CreateTables();

	Call_OnDatabaseConnect();
}