gboolean SMSDDBI_GetBool(GSM_SMSDConfig * Config, SQL_result *res, unsigned int field) { unsigned int type; const char *value; int num; field++; type = dbi_result_get_field_type_idx(res->dbi, field); switch (type) { case DBI_TYPE_INTEGER: case DBI_TYPE_DECIMAL: #ifdef DBI_TYPE_XDECIMAL case DBI_TYPE_XDECIMAL: #endif num = SMSDDBI_GetNumber(Config, res, field); if (num == -1) { return -1; } else if (num == 0) { return FALSE; } else { return TRUE; } case DBI_TYPE_STRING: value = dbi_result_get_string_idx(res->dbi, field); return GSM_StringToBool(value); case DBI_TYPE_ERROR: default: SMSD_Log(DEBUG_ERROR, Config, "Wrong field type for boolean from DBI: %d", type); return -1; } }
gboolean SMSDMySQL_GetBool(GSM_SMSDConfig * Config, SQL_result *res, unsigned int field) { const char *value = res->my.row[field]; if(atoi(value) > 0){ return TRUE; } return GSM_StringToBool(value); }
gboolean SMSDODBC_GetBool(GSM_SMSDConfig * Config, SQL_result *res, unsigned int field) { long long intval; const char * charval; /* Try to get numeric value first */ intval = SMSDODBC_GetNumber(Config, res, field); if (intval == -1) { /* If that fails, fall back to string and parse it */ charval = SMSDODBC_GetString(Config, res, field); return GSM_StringToBool(charval); } return intval ? TRUE : FALSE; }
gboolean SMSDPgSQL_GetBool(GSM_SMSDConfig * Config, SQL_result *res, unsigned int field) { const char *value; value = PQgetvalue(res->pg.res, res->pg.iter, field); return GSM_StringToBool(value); }