| 1431 | } |
| 1432 | |
| 1433 | static 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 | { |
nothing calls this directly
no test coverage detected