Exemple #1
0
static int c_psql_read (void)
{
	int success = 0;
	int i;

	for (i = 0; i < databases_num; ++i) {
		c_psql_database_t *db = databases + i;

		int j;

		assert (NULL != db->database);

		if (0 != c_psql_check_connection (db))
			continue;

		for (j = 0; j < db->queries_num; ++j)
		{
			udb_query_t *q;

			q = db->queries[j];

			if ((0 != db->server_version)
				&& (udb_query_check_version (q, db->server_version) <= 0))
				continue;

			c_psql_exec_query (db, q);
		}

		++success;
	}

	if (! success)
		return -1;
	return 0;
} /* c_psql_read */
Exemple #2
0
static int c_psql_read (user_data_t *ud)
{
	c_psql_database_t *db;

	int success = 0;
	int i;

	if ((ud == NULL) || (ud->data == NULL)) {
		log_err ("c_psql_read: Invalid user data.");
		return -1;
	}

	db = ud->data;

	assert (NULL != db->database);
	assert (NULL != db->instance);
	assert (NULL != db->queries);

	pthread_mutex_lock (&db->db_lock);

	if (0 != c_psql_check_connection (db)) {
		pthread_mutex_unlock (&db->db_lock);
		return -1;
	}

	for (i = 0; i < db->queries_num; ++i)
	{
		udb_query_preparation_area_t *prep_area;
		udb_query_t *q;

		prep_area = db->q_prep_areas[i];
		q = db->queries[i];

		if ((0 != db->server_version)
				&& (udb_query_check_version (q, db->server_version) <= 0))
			continue;

		if (0 == c_psql_exec_query (db, q, prep_area))
			success = 1;
	}

	pthread_mutex_unlock (&db->db_lock);

	if (! success)
		return -1;
	return 0;
} /* c_psql_read */
Exemple #3
0
static int cdbi_read_database (user_data_t *ud) /* {{{ */
{
  cdbi_database_t *db = (cdbi_database_t *) ud->data;
  size_t i;
  int success;
  int status;

  unsigned int db_version;

  status = cdbi_connect_database (db);
  if (status != 0)
    return (status);
  assert (db->connection != NULL);

  db_version = dbi_conn_get_engine_version (db->connection);
  /* TODO: Complain if `db_version == 0' */

  success = 0;
  for (i = 0; i < db->queries_num; i++)
  {
    /* Check if we know the database's version and if so, if this query applies
     * to that version. */
    if ((db_version != 0)
        && (udb_query_check_version (db->queries[i], db_version) == 0))
      continue;

    status = cdbi_read_database_query (db,
        db->queries[i], db->q_prep_areas[i]);
    if (status == 0)
      success++;
  }

  if (success == 0)
  {
    ERROR ("dbi plugin: All queries failed for database `%s'.", db->name);
    return (-1);
  }

  return (0);
} /* }}} int cdbi_read_database */