| 832 | } |
| 833 | |
| 834 | static cell_t SQL_TQuery(IPluginContext *pContext, const cell_t *params) |
| 835 | { |
| 836 | IDatabase *db = NULL; |
| 837 | HandleError err; |
| 838 | |
| 839 | if ((err = g_DBMan.ReadHandle(params[1], DBHandle_Database, (void **)&db)) |
| 840 | != HandleError_None) |
| 841 | { |
| 842 | return pContext->ThrowNativeError("Invalid database Handle %x (error: %d)", params[1], err); |
| 843 | } |
| 844 | |
| 845 | if (!db->GetDriver()->IsThreadSafe()) |
| 846 | { |
| 847 | return pContext->ThrowNativeError("Driver \"%s\" is not thread safe!", db->GetDriver()->GetIdentifier()); |
| 848 | } |
| 849 | |
| 850 | IPluginFunction *pf = pContext->GetFunctionById(params[2]); |
| 851 | if (!pf) |
| 852 | { |
| 853 | return pContext->ThrowNativeError("Function id %x is invalid", params[2]); |
| 854 | } |
| 855 | |
| 856 | char *query; |
| 857 | pContext->LocalToString(params[3], &query); |
| 858 | |
| 859 | cell_t data = params[4]; |
| 860 | PrioQueueLevel level = PrioQueue_Normal; |
| 861 | if (params[5] == (cell_t)PrioQueue_High) |
| 862 | { |
| 863 | level = PrioQueue_High; |
| 864 | } else if (params[5] == (cell_t)PrioQueue_Low) { |
| 865 | level = PrioQueue_Low; |
| 866 | } |
| 867 | |
| 868 | IPlugin *pPlugin = scripts->FindPluginByContext(pContext); |
| 869 | |
| 870 | TQueryOp *op = new TQueryOp(db, pf, query, data); |
| 871 | if (pPlugin->GetProperty("DisallowDBThreads", NULL) |
| 872 | || !g_DBMan.AddToThreadQueue(op, level)) |
| 873 | { |
| 874 | /* Do everything right now */ |
| 875 | op->RunThreadPart(); |
| 876 | op->RunThinkPart(); |
| 877 | op->Destroy(); |
| 878 | } |
| 879 | |
| 880 | return 1; |
| 881 | } |
| 882 | |
| 883 | static cell_t SQL_LockDatabase(IPluginContext *pContext, const cell_t *params) |
| 884 | { |
nothing calls this directly
no test coverage detected