Beispiel #1
0
int main(int argc, char **argv)
{
    dbDriver *driver;
    dbHandle handle;
    int stat;

    parse_command_line(argc, argv);

    driver = db_start_driver(parms.driver);
    if (driver == NULL)
	G_fatal_error(_("Unable to start driver <%s>"), parms.driver);

    db_init_handle(&handle);
    db_set_handle(&handle, parms.database, NULL);
    stat = db_create_database(driver, &handle);
    db_shutdown_driver(driver);

    exit(stat == DB_OK ? EXIT_SUCCESS : EXIT_FAILURE);
}
Beispiel #2
0
	/*****************************************************************************************************************************
		open

		Prepares the database for use. An existing database is opened or otherwise an empty database is created.

		If the database is openend a table _META with meta info is loaded into a dictionary _META. The dictionary key is the 
		code of the data element. A data element is either a tabel (dimension/event) or a field (characteristic/property). 
		The value of the dictionary is the MET_INFO structure. This structure contains meta data about the data element.

		If the database is created an empty table _META is created.

		The function calls virtual functions, db_,  which must be overriden by a derived class for a specific database implementation.  

	******************************************************************************************************************************/
	void ARAS::open(DBInfo dbInfo) {
		if (isopen)
			return;

		// store db information
		this->dbInfo = dbInfo;
		
		// open or create database
		// performs the database specific initialization code, the specific information to be used is stored in the struct DBInfo.
		db_init_database();
		// performs the database specific code to check whether a database alreay exists and open it. 
		if (db_open_database()) {
			// read _META table from database into dictionary _META
			TABLE values;
			db_select_table("_META", {"CODE","INFO"}, values);
			for (auto i : values)
				_META.insert(std::pair<std::string, META_INFO>(i[0], META_INFO(i[1])));
		}
		else {
			// performs the database specific code to create a new database based on DBInfo. 
			db_create_database();

			// create table _META: define the columns
			META_INFO imeta(data_type::DIM, 0, "_META", "", "", "_META", "CODE", 0, 0, 0, 0);
			META_INFO icode(data_type::STR, SIZE_META_CODE_MAX, "_META", "", "","_META", "", 0, 0, 1, 0);
			META_INFO idescs(data_type::STR, SIZE_DESCS_MAX, "_META", "", "", "_META", "", 0, 0, 0, 0);
			META_INFO idescl(data_type::STR, SIZE_DESCL_MAX, "_META", "", "", "_META", "", 0, 0, 0, 0);
			META_INFO iinfo(data_type::STR, 0, "_META", "", "", "_META", "",0, 0, 0, 0);

			// define the table
			META_TABLE meta = { { "_META", "Meta data", "Meta data", imeta }, { "CODE", "CODE", "CODE", icode }, { "DESCS", "Short Description", "Short Description", idescs }, { "DESCL", "Long Description", "Long Description", idescl }, { "INFO", "INFO", "INFO", iinfo } };

			// performs the database specific code to create a new table
			db_create_table(meta);

			// load the meta data into the dictionary and the database table _META
			for (auto i : meta)
				insert_meta(i);
		}
	}