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

Function SQL_ConnectEx

core/logic/smn_database.cpp:514–574  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

512}
513
514static cell_t SQL_ConnectEx(IPluginContext *pContext, const cell_t *params)
515{
516 IDBDriver *driver;
517 if (params[1] == BAD_HANDLE)
518 {
519 if ((driver = g_DBMan.GetDefaultDriver()) == NULL)
520 {
521 return pContext->ThrowNativeError("Could not find any default driver");
522 }
523 } else {
524 HandleError err;
525 if ((err = g_DBMan.ReadHandle(params[1], DBHandle_Driver, (void **)&driver))
526 != HandleError_None)
527 {
528 return pContext->ThrowNativeError("Invalid driver Handle %x (error: %d)", params[1], err);
529 }
530 }
531
532 char *host, *user, *pass, *database, *error;
533 size_t maxlength = (size_t)params[7];
534 bool persistent = params[8] ? true : false;
535 unsigned int port = params[9];
536 unsigned int maxTimeout = params[10];
537 pContext->LocalToString(params[2], &host);
538 pContext->LocalToString(params[3], &user);
539 pContext->LocalToString(params[4], &pass);
540 pContext->LocalToString(params[5], &database);
541 pContext->LocalToString(params[6], &error);
542
543 DatabaseInfo info;
544 info.database = database;
545 info.driver = driver->GetIdentifier();
546 info.host = host;
547 info.maxTimeout = maxTimeout;
548 info.pass = pass;
549 info.port = port;
550 info.user = user;
551
552 IDatabase *db = driver->Connect(&info, persistent, error, maxlength);
553
554 if (db)
555 {
556 Handle_t hndl = g_DBMan.CreateHandle(DBHandle_Database, db, pContext->GetIdentity());
557 if (!hndl)
558 {
559 db->Close();
560 return BAD_HANDLE;
561 }
562
563 /* HACK! Add us to the dependency list */
564 IExtension *pExt = g_Extensions.GetExtensionFromIdent(driver->GetIdentity());
565 if (pExt)
566 {
567 g_Extensions.BindChildPlugin(pExt, scripts->FindPluginByContext(pContext));
568 }
569
570 return hndl;
571 }

Callers

nothing calls this directly

Calls 10

GetDefaultDriverMethod · 0.80
GetExtensionFromIdentMethod · 0.80
BindChildPluginMethod · 0.80
ReadHandleMethod · 0.45
GetIdentifierMethod · 0.45
ConnectMethod · 0.45
CreateHandleMethod · 0.45
GetIdentityMethod · 0.45
CloseMethod · 0.45
FindPluginByContextMethod · 0.45

Tested by

no test coverage detected