示例#1
0
//*******************************************************************
// Get the results of the MySQL query into our probe_def structure
//*******************************************************************
static void mysql_set_def_fields(trx *t, struct probe_def *probedef, dbi_result result)
{
  struct mysql_def *def = (struct mysql_def *) probedef;

  if (dbi_result_next_row(result)) {
    def->ipaddress = dbi_result_get_string_copy_idx(result, 0);
    def->description = dbi_result_get_string_copy_idx(result, 1);
    def->server   = dbi_result_get_uint_idx(result, 2);
    def->yellow   = dbi_result_get_float_idx(result, 3);
    def->red      = dbi_result_get_float_idx(result, 4);
    def->contact  = dbi_result_get_float_idx(result, 5);
    if (dbi_result_get_string_idx(result, 6)) {
      strcpy(def->hide, dbi_result_get_string_idx(result, 6));
    } else {
      strcpy(def->hide, "no");
    }
    if (dbi_result_get_string_idx(result, 7)) {
      strcpy(def->email, dbi_result_get_string_idx(result, 7));
    } else {
      strcpy(def->email, "");
    }
    if (dbi_result_get_string_idx(result, 8)) {
      strcpy(def->sms, dbi_result_get_string_idx(result, 8));
    } else {
      strcpy(def->sms, "");
    }
    def->delay = dbi_result_get_uint_idx(result, 9);
    def->dbname = dbi_result_get_string_copy_idx(result, 10);
    def->dbuser = dbi_result_get_string_copy_idx(result, 11);
    def->dbpasswd = dbi_result_get_string_copy_idx(result, 12);
    def->query = dbi_result_get_string_copy_idx(result, 13);
  }
}
示例#2
0
int dbiw_res_get_double_ndx(db_wrap_result * self, unsigned int ndx, double * val)
{
	RES_DECL(DB_WRAP_E_BAD_ARG);
	if (! val) return DB_WRAP_E_BAD_ARG;
	unsigned int const realIdx = ndx+1;
	*val = 0.0;
	unsigned int const a = dbi_result_get_field_attrib_idx (dbires, realIdx, 0, 0xff);
	/* i can't find one bit of useful docs/examples for this function, so i'm kind of
	   guessing here. */
	;
	if (DBI_ATTRIBUTE_ERROR == a)
	{
		return DB_WRAP_E_CHECK_DB_ERROR;
	}
	else if (DBI_DECIMAL_SIZE4 & a)
	{
		/* MARKER("SIZE4\n"); */
		*val = dbi_result_get_float_idx(dbires, realIdx);
	}
	else if (DBI_DECIMAL_SIZE8 & a)
	{
		/* MARKER("SIZE8\n"); */
		*val = dbi_result_get_double_idx(dbires, realIdx);
	}
	return 0;
}
示例#3
0
static double rrd_fetch_dbi_double(dbi_result *result,int idx) {
  char *ptmp="";
  double value=DNAN;
  /* get the attributes for this filed */
  unsigned int attr=dbi_result_get_field_attribs_idx(result,idx);
  unsigned int type=dbi_result_get_field_type_idx(result,idx);
  /* return NAN if NULL */
  if(dbi_result_field_is_null_idx(result,idx)) { return DNAN; }
  /* do some conversions */
  switch (type) {
    case DBI_TYPE_STRING:
      ptmp=(char*)dbi_result_get_string_idx(result,idx);
      value=strtod(ptmp,NULL);
      break;
    case DBI_TYPE_INTEGER:
      if        (attr & DBI_INTEGER_SIZE1) { value=dbi_result_get_char_idx(result,idx);
      } else if (attr & DBI_INTEGER_SIZE2) { value=dbi_result_get_short_idx(result,idx);
      } else if (attr & DBI_INTEGER_SIZE3) { value=dbi_result_get_int_idx(result,idx);
      } else if (attr & DBI_INTEGER_SIZE4) { value=dbi_result_get_int_idx(result,idx);
      } else if (attr & DBI_INTEGER_SIZE8) { value=dbi_result_get_longlong_idx(result,idx);
      } else {                               value=DNAN;
        if (getenv("RRDDEBUGSQL")) { fprintf(stderr,"RRDDEBUGSQL: %li: column %i unsupported attribute flags %i for type INTEGER\n",time(NULL),idx,attr ); }
      }
      break;
    case DBI_TYPE_DECIMAL:
      if        (attr & DBI_DECIMAL_SIZE4) { value=dbi_result_get_float_idx(result,idx);
      } else if (attr & DBI_DECIMAL_SIZE8) { value=dbi_result_get_double_idx(result,idx);
      } else {                               value=DNAN;
        if (getenv("RRDDEBUGSQL")) { fprintf(stderr,"RRDDEBUGSQL: %li: column %i unsupported attribute flags %i for type DECIMAL\n",time(NULL),idx,attr ); }
      }
      break;
    case DBI_TYPE_BINARY:
      attr=dbi_result_get_field_length_idx(result,idx);
      ptmp=(char*)dbi_result_get_binary_copy_idx(result,idx);
      ptmp[attr-1]=0;
      /* check for "known" libdbi error */
      if (strncmp("ERROR",ptmp,5)==0) {
	if (!getenv("RRD_NO_LIBDBI_BUG_WARNING")) {
	  fprintf(stderr,"rrdtool_fetch_libDBI: you have possibly triggered a bug in libDBI by using a (TINY,MEDIUM,LONG) TEXT field with mysql\n  this may trigger a core dump in at least one version of libdbi\n  if you are not touched by this bug and you find this message annoying\n  please set the environment-variable RRD_NO_LIBDBI_BUG_WARNING to ignore this message\n");
	}
      }
      /* convert to number */
      value=strtod(ptmp,NULL);
      /* free pointer */
      free(ptmp);
      break;
    case DBI_TYPE_DATETIME:
       value=dbi_result_get_datetime_idx(result,idx);
       break;
    default:
      if (getenv("RRDDEBUGSQL")) { fprintf(stderr,"RRDDEBUGSQL: %li: column %i unsupported type: %i with attribute %i\n",time(NULL),idx,type,attr ); }
      value=DNAN;
      break;
  }
  return value;
}
示例#4
0
float dbi_result_get_float(dbi_result Result, const char *fieldname) {
  float ERROR = 0.0;
  dbi_error_flag errflag;
  unsigned int fieldidx;

  fieldidx = _find_field(RESULT, fieldname, &errflag);
  if (errflag != DBI_ERROR_NONE) {
    dbi_conn_t *conn = RESULT->conn;
    _error_handler(conn, DBI_ERROR_BADNAME);
    return ERROR;
  }
  return dbi_result_get_float_idx(Result, fieldidx+1);
}