static cell_t SQL_FieldNumToName(IPluginContext *pContext, const cell_t *params) { IQuery *query; HandleError err; if ((err = ReadQueryHndl(params[1], pContext, &query)) != HandleError_None) { return pContext->ThrowNativeError("Invalid query Handle %x (error: %d)", params[1], err); } IResultSet *rs = query->GetResultSet(); if (!rs) { return pContext->ThrowNativeError("No current result set"); } unsigned int field = params[2]; const char *fldname; if ((fldname = rs->FieldNumToName(field)) == NULL) { return pContext->ThrowNativeError("Invalid field index %d", field); } pContext->StringToLocalUTF8(params[3], params[4], fldname, NULL); return 1; }
static cell AMX_NATIVE_CALL SQL_FieldNumToName(AMX *amx, cell *params) { AmxQueryInfo *qInfo = (AmxQueryInfo *)GetHandle(params[1], Handle_Query); if (!qInfo) { MF_LogError(amx, AMX_ERR_NATIVE, "Invalid query handle: %d", params[1]); return 0; } IResultSet *rs = qInfo->info.rs; if (!rs) { MF_LogError(amx, AMX_ERR_NATIVE, "No result set in this query!"); return 0; } unsigned int col = static_cast<unsigned int>(params[2]); const char *namewa = rs->FieldNumToName(col); if (!namewa) { MF_LogError(amx, AMX_ERR_NATIVE, "Invalid column: %d", col); return 0; } MF_SetAmxString(amx, params[3], namewa, params[4]); return 1; }
//native dbi_result(Result:_result, _field[], {Float,_}:... ); static cell AMX_NATIVE_CALL dbi_result(AMX *amx, cell *params) { oldresult_s *oldrs = (oldresult_s *)GetHandle(params[1], Handle_OldResult); if (!oldrs) { MF_LogError(amx, AMX_ERR_NATIVE, "Invalid DBI result handle %d", params[1]); return 0; } IResultSet *rs = oldrs->info.rs; if (rs->IsDone()) { return 0; } IResultRow *rr = rs->GetRow(); unsigned int num; bool found = false; unsigned int fields = rs->FieldCount(); int len; char *field = MF_GetAmxString(amx, params[2], 0, &len); for (unsigned int i=0; i<fields; i++) { if (strcmp(field, rs->FieldNumToName(i)) == 0) { num = i; found = true; break; } } if (!found) { MF_LogError(amx, AMX_ERR_NATIVE, "Unknown column \"%s\"", field); return 0; } cell stype = params[0] / sizeof(cell); const char *data = rr->GetString(num); if (!data) data = ""; switch (stype) { case 2: { return atoi(data); break; } case 3: { cell *destaddr = MF_GetAmxAddr(amx, params[3]); REAL fdata = atof(data); *destaddr = amx_ftoc(fdata); return 1; break; } case 4: { return MF_SetAmxString(amx, params[3], data, params[4]); break; } } /** never reach here */ return 0; }