MCPcopy Create free account
hub / github.com/alliedmodders/sourcemod / SQL_ConnectCustom

Function SQL_ConnectCustom

core/logic/smn_database.cpp:1433–1495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1431}
1432
1433static cell_t SQL_ConnectCustom(IPluginContext *pContext, const cell_t *params)
1434{
1435 KeyValues *kv;
1436 HandleError err;
1437
1438 kv = g_pSM->ReadKeyValuesHandle(params[1], &err, false);
1439 if (kv == NULL)
1440 {
1441 return pContext->ThrowNativeError("Invalid KeyValues handle %x (error: %d)",
1442 params[1],
1443 err);
1444 }
1445
1446 DatabaseInfo info;
1447 bridge->GetDBInfoFromKeyValues(kv, &info);
1448
1449 IDBDriver *driver;
1450 if (info.driver[0] == '\0' || strcmp(info.driver, "default") == 0)
1451 {
1452 driver = g_DBMan.GetDefaultDriver();
1453 }
1454 else
1455 {
1456 driver = g_DBMan.FindOrLoadDriver(info.driver);
1457 }
1458
1459 if (driver == NULL)
1460 {
1461 char buffer[255];
1462
1463 g_pSM->Format(buffer, sizeof(buffer), "Could not find driver \"%s\"", info.driver);
1464 pContext->StringToLocalUTF8(params[2], params[3], buffer, NULL);
1465
1466 return BAD_HANDLE;
1467 }
1468
1469 char *buffer;
1470 IDatabase *db;
1471
1472 pContext->LocalToString(params[2], &buffer);
1473
1474 db = driver->Connect(&info, params[4] ? true : false, buffer, params[3]);
1475 if (db == NULL)
1476 {
1477 return BAD_HANDLE;
1478 }
1479
1480 Handle_t hndl = g_DBMan.CreateHandle(DBHandle_Database, db, pContext->GetIdentity());
1481 if (!hndl)
1482 {
1483 db->Close();
1484 return pContext->ThrowNativeError("Out of handles!");
1485 }
1486
1487 /* HACK! Add us to the dependency list */
1488 IExtension *pExt = g_Extensions.GetExtensionFromIdent(driver->GetIdentity());
1489 if (pExt)
1490 {

Callers

nothing calls this directly

Calls 11

ReadKeyValuesHandleMethod · 0.80
GetDefaultDriverMethod · 0.80
FindOrLoadDriverMethod · 0.80
FormatMethod · 0.80
GetExtensionFromIdentMethod · 0.80
BindChildPluginMethod · 0.80
ConnectMethod · 0.45
CreateHandleMethod · 0.45
GetIdentityMethod · 0.45
CloseMethod · 0.45
FindPluginByContextMethod · 0.45

Tested by

no test coverage detected