Esempio n. 1
0
/**
 * \brief initialize db
 */
int DelagentDBInit()
{
  char CMD[256];
  int rc;
 
  rc = create_db_repo_sysconf(0, "delagent");
  if (rc != 0)
  {
    printf("Database initialize ERROR!\n");
    DelagentClean();
    return -1;
  }
  DBConfFile = get_dbconf();

  memset(CMD, '\0', sizeof(CMD));
  //sprintf(CMD, "sh testInitDB.sh %s", get_db_name());
  sprintf(CMD, "sudo su postgres -c 'pg_restore -d %s ../testdata/testdb_all.tar'", get_db_name());
  printf("restore database command: %s\n", CMD);
  rc = system(CMD); 
  //if (rc != 0)
  //{
  //  printf("Database initialize ERROR!\n");
  //  DelagentClean();
  //  return -1; 
  //}

  return 0;
}
Esempio n. 2
0
Database* CatalogManager::GetDB(string db_name)
{
	for (auto db = dbs_.begin(); db != dbs_.end(); db++)
		if (db->get_db_name() == db_name) 
			return &(*db);    //some problem: exception?
	return NULL;
}
Esempio n. 3
0
/*
 * \brief  main test function
 */
int main( int argc, char *argv[] )
{
  create_db_repo_sysconf(1, "mimetype");
  DBConfFile = get_dbconf();

  int rc = focunit_main(argc, argv, "mimetype_Tests", suites) ;
  drop_db_repo_sysconf(get_db_name());
  return rc;
}
Esempio n. 4
0
File: misc.c Progetto: colinet/sqlix
/*
 * current_database()
 *	Expose the current database to the user
 */
datum_t current_database(PG_FUNC_ARGS)
{
	struct name* db;

	db = (struct name*) palloc(NAMEDATALEN);

	namestrcpy(db, get_db_name(current_db_id));
	RET_NAME(db);
}
Esempio n. 5
0
/*
 * calculate size of database in all tablespaces
 */
static int64 calculate_database_size(oid_t dbOid)
{
	int64 totalsize;
	DIR *dirdesc;
	struct dirent *direntry;
	char dirpath[MAX_PG_PATH];
	char pathname[MAX_PG_PATH];
	acl_result_e aclresult;

	/* User must have connect privilege for target database */
	aclresult = db_acl_check(dbOid, get_uid(), ACL_CONNECT);
	if (aclresult != ACLCHECK_OK)
		aclcheck_error(aclresult, ACL_KIND_DATABASE, get_db_name(dbOid));

	/* Shared storage in pg_global is not counted */

	/* Include pg_default storage */
	snprintf(pathname, MAX_PG_PATH, "base/%u", dbOid);
	totalsize = db_dir_size(pathname);

	/* scan_pl the non-default tablespaces */
	snprintf(dirpath, MAX_PG_PATH, "pg_tblspc");
	dirdesc = alloc_dir(dirpath);
	if (!dirdesc)
		ereport(ERROR, (errcode_file_access(),
		errmsg("could not open tablespace directory \"%s\": %m", dirpath)));

	while ((direntry = read_dir(dirdesc, dirpath)) != NULL) {
		CHECK_FOR_INTERRUPTS();

		if (strcmp(direntry->d_name, ".") == 0
			|| strcmp(direntry->d_name, "..") == 0)
			continue;

		snprintf(pathname, MAX_PG_PATH, "pg_tblspc/%s/%s/%u", direntry->d_name,
			 TBS_VERSION_DIR, dbOid);
		totalsize += db_dir_size(pathname);
	}

	free_dir(dirdesc);

	/* Complain if we found no trace of the DB at all */
	if (!totalsize)
		ereport(ERROR,
			(E_UNDEFINED_DATABASE,
			 errmsg("database with OID %u does not exist", dbOid)));

	return totalsize;
}
Esempio n. 6
0
/**
 * \brief clean db
 */
int DelagentClean()
{
  drop_db_repo_sysconf(get_db_name());
  return 0;
}