コード例 #1
0
ファイル: mysql.c プロジェクト: BackupTheBerlios/upwatch-svn
//*******************************************************************
// 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
ファイル: sql.c プロジェクト: rowhit/Tagsistant
/**
 * SQL callback. Return an integer from a query
 *
 * @param return_integer integer pointer cast to void* which holds the integer to be returned
 * @param result dbi_result pointer
 * @return 0 (always, due to SQLite policy, may change in the future)
 */
int tagsistant_return_integer(void *return_integer, dbi_result result)
{
	uint32_t *buffer = (uint32_t *) return_integer;
	*buffer = 0;

	unsigned int type = dbi_result_get_field_type_idx(result, 1);
	if (type == DBI_TYPE_INTEGER) {
		unsigned int size = dbi_result_get_field_attribs_idx(result, 1);
		unsigned int is_unsigned = size & DBI_INTEGER_UNSIGNED;
		size = size & DBI_INTEGER_SIZEMASK;
		switch (size) {
			case DBI_INTEGER_SIZE8:
				if (is_unsigned)
					*buffer = dbi_result_get_ulonglong_idx(result, 1);
				else
					*buffer = dbi_result_get_longlong_idx(result, 1);
				break;
			case DBI_INTEGER_SIZE4:
			case DBI_INTEGER_SIZE3:
				if (is_unsigned)
					*buffer = dbi_result_get_uint_idx(result, 1);
				else
					*buffer = dbi_result_get_int_idx(result, 1);
				break;
			case DBI_INTEGER_SIZE2:
				if (is_unsigned)
					*buffer = dbi_result_get_ushort_idx(result, 1);
				else
					*buffer = dbi_result_get_short_idx(result, 1);
				break;
			case DBI_INTEGER_SIZE1:
				if (is_unsigned)
					*buffer = dbi_result_get_uchar_idx(result, 1);
				else
					*buffer = dbi_result_get_char_idx(result, 1);
				break;
		}
	} else if (type == DBI_TYPE_DECIMAL) {
		return (0);
	} else if (type == DBI_TYPE_STRING) {
		const gchar *int_string = dbi_result_get_string_idx(result, 1);
		*buffer = atoi(int_string);
		dbg('s', LOG_INFO, "tagsistant_return_integer called on non integer field");
	}

	dbg('s', LOG_INFO, "Returning integer: %d", *buffer);

	return (0);
}
コード例 #3
0
ファイル: db_wrap_dbi.c プロジェクト: ageric/merlin
int dbiw_res_get_int64_ndx(db_wrap_result * self, unsigned int ndx, int64_t * val)
{
	RES_DECL(DB_WRAP_E_BAD_ARG);
	if (! val) return DB_WRAP_E_BAD_ARG;
	unsigned int const realIdx = ndx+1;
	//FIXME("Consolidate the duplicate code in get_int32_ndx() and here.");
#if 1
	/**
	   See this thread: http://www.mail-archive.com/[email protected]/msg00126.html
	*/
	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. */
		;
	/* MARKER("Attribute return=0x%x/%u\n",a, a); */
	/*assert(0);*/
	if (DBI_ATTRIBUTE_ERROR == a)
	{
		return DB_WRAP_E_CHECK_DB_ERROR;
	}
	else if (DBI_INTEGER_SIZE1 & a)
	{
		/* MARKER("SIZE1\n"); */
		*val =
			(a & DBI_DECIMAL_UNSIGNED)
			? dbi_result_get_uchar_idx(dbires, realIdx)
			: dbi_result_get_char_idx(dbires, realIdx)
			;
	}
	else if (DBI_INTEGER_SIZE2 & a)
	{
		/* MARKER("SIZE2\n"); */
		*val =
			(a & DBI_DECIMAL_UNSIGNED)
			? dbi_result_get_ushort_idx(dbires, realIdx)
			: dbi_result_get_short_idx(dbires, realIdx)
			;
	}
	else if (DBI_INTEGER_SIZE4 & a)
	{
		/*MARKER("SIZE4\n");*/
		*val =
			(a & DBI_DECIMAL_UNSIGNED)
			? dbi_result_get_uint_idx(dbires, realIdx)
			: dbi_result_get_int_idx(dbires, realIdx)
			;
	}
	else if (DBI_INTEGER_SIZE8 & a)
	{
		/* MARKER("SIZE8\n"); */
		*val =
			(a & DBI_DECIMAL_UNSIGNED)
			? dbi_result_get_ulonglong_idx(dbires, realIdx)
			: dbi_result_get_longlong_idx(dbires, realIdx)
			;
	}
	else
	{
		/**
		   libdbi Sqlite driver returns 0 for attributes for
		   the case of SELECT COUNT(*). i have no workaround
		   for this :(.
		*/
		return DB_WRAP_E_UNKNOWN_ERROR;
	}
#else
	//*val = dbi_result_get_int_idx(dbires, realIdx);
	//MARKER("val as int=%"PRIi64"\n",*val);
	//if (!*val)
	*val = dbi_result_get_longlong_idx(dbires, realIdx);
	//MARKER("val as longlong=%"PRIi64"\n",*val);
#endif
	return 0;
}
コード例 #4
0
ファイル: db_wrap_dbi.c プロジェクト: ageric/merlin
int dbiw_res_get_int32_ndx(db_wrap_result * self, unsigned int ndx, int32_t * val)
{
	RES_DECL(DB_WRAP_E_BAD_ARG);
	if (! val) return DB_WRAP_E_BAD_ARG;
	unsigned int const realIdx = ndx+1;
#if 1
	/**
	   See this thread: http://www.mail-archive.com/[email protected]/msg00126.html
	*/
	unsigned int const a = dbi_result_get_field_attrib_idx (dbires, realIdx,
			                                                 0/*DBI_INTEGER_UNSIGNED*/,
			                                                 0xff/*DBI_INTEGER_SIZE8*/)
		/* i can't find one bit of useful docs/examples for this function, so i'm kind of
		   guessing here. */
		;
	//MARKER("Attribute return=0x%x/%u\n",a, a);
	/*assert(0);*/
	/**
	   See this thread: http://www.mail-archive.com/[email protected]/msg00126.html
	*/
	if (DBI_ATTRIBUTE_ERROR == a)
	{
		return DB_WRAP_E_CHECK_DB_ERROR;
	}
#if 0
	else if (0 == a)
	{ /* HORRIBLE KLUDGE for sqlite driver!
	   But after testing, NONE of these return the value i'm expecting! */
		*val = dbi_result_get_short_idx(dbires, realIdx);
		if (!*val) *val = dbi_result_get_ushort_idx( dbires, realIdx );
		if (!*val) *val = dbi_result_get_int_idx( dbires, realIdx );
		if (!*val) *val = dbi_result_get_uint_idx( dbires, realIdx );
		if (!*val) *val = dbi_result_get_longlong_idx( dbires, realIdx );
		if (!*val) *val = dbi_result_get_ulonglong_idx( dbires, realIdx );
		//if (!*val) *val = dbi_result_get_double_idx( dbires, realIdx );
	}
#endif
	else if (DBI_INTEGER_SIZE1 & a)
	{
		/* MARKER("SIZE1\n"); */
		*val =
			(a & DBI_DECIMAL_UNSIGNED)
			? dbi_result_get_uchar_idx(dbires, realIdx)
			: dbi_result_get_char_idx(dbires, realIdx)
			;
	}
	else if (DBI_INTEGER_SIZE2 & a)
	{
		/* MARKER("SIZE2\n"); */
		*val =
			(a & DBI_DECIMAL_UNSIGNED)
			? dbi_result_get_ushort_idx(dbires, realIdx)
			: dbi_result_get_short_idx(dbires, realIdx)
			;
	}
	else if (DBI_INTEGER_SIZE4 & a)
	{
		/* MARKER("SIZE4\n"); */
		*val =
			(a & DBI_DECIMAL_UNSIGNED)
			? dbi_result_get_uint_idx(dbires, realIdx)
			: dbi_result_get_int_idx(dbires, realIdx)
			;
	}
	else if (DBI_INTEGER_SIZE8 & a)
	{
		/* MARKER("SIZE8\n"); */
		*val =
			(a & DBI_DECIMAL_UNSIGNED)
			? dbi_result_get_ulonglong_idx(dbires, realIdx)
			: dbi_result_get_longlong_idx(dbires, realIdx)
			;
	}
	else
	{
		/**
		   libdbi Sqlite driver returns 0 for attributes for
		   the case of SELECT COUNT(*). i have no workaround
		   for this :(.
		*/
		return DB_WRAP_E_UNKNOWN_ERROR;
	}
#else
	*val = dbi_result_get_int_idx(dbires, realIdx);
#endif
	return 0;
}
コード例 #5
0
ファイル: dbi_result.c プロジェクト: ystk/debian-libdbi
unsigned int dbi_result_get_ulong_idx(dbi_result Result, unsigned int fieldidx) {
  return dbi_result_get_uint_idx(Result, fieldidx);
}