<commit_before>/*!
  \copyright (c) RDO-Team, 2012
  \file      main.cpp
  \authors     (<EMAIL>)
  \authors     (<EMAIL>)
  \date      05.11.2012
  \brief         
  \indent    4T
*/

// ---------------------------------------------------------------------------- PCH
// ----------------------------------------------------------------------- INCLUDES
#include <iostream>
#include <conio.h>
#include <QtSql\QtSql>
#include <QtCore\QCoreApplication>
// ----------------------------------------------------------------------- SYNOPSIS
#include "simulator\compiler\parser\src\db\general_db.h"
// --------------------------------------------------------------------------------

void dropDB()
{
	GeneralDB db("localhost", "postgres", "postgres", "rdo", 5432);
	db.queryExec("DROP DATABASE IF EXISTS rdo;");
	db.queryExec("CREATE DATABASE rdo;");
}

GeneralDB::QueryList generateCreateDBQuery()
{
	GeneralDB::QueryList queryList;

	queryList.push_back(
		"CREATE TABLE rtp("
		"id          serial,"
		"r_t_name    VARCHAR(40) NOT NULL,"
		"r_t_perm    boolean NOT NULL,"
		"PRIMARY KEY (id)"
		");");

	queryList.push_back(
		"CREATE TABLE list_of_types_of_params("
		"type_id     integer,"
		"table_id    integer NOT NULL,"
		"PRIMARY KEY (type_id)"
		");");

	queryList.push_back(
		"CREATE TABLE param_of_type("
		"id          serial,"
		"param_name  VARCHAR(40) NOT NULL,"
		"r_t_id      integer,"
		"type_id     integer NOT NULL,"
		"PRIMARY KEY (id,r_t_id),"
		"FOREIGN KEY (r_t_id) REFERENCES rtp(id),"
		"FOREIGN KEY (type_id) REFERENCES list_of_types_of_params"
		");");
//------------------------

//------------------------
	queryList.push_back("CREATE SEQUENCE type_of_param_seq;");

	queryList.push_back(
		"CREATE FUNCTION copy_type_id() RETURNS TRIGGER AS $trig$ "
		"BEGIN "
		"INSERT INTO list_of_types_of_params VALUES "
		"(NEW.id, NEW.tableoid); "
		"RETURN NULL; "
		"END; "
		"$trig$ LANGUAGE plpgsql; ");
//------------------------





//------------------------
	queryList.push_back(
		"CREATE TABLE real("
		"id          integer NOT NULL DEFAULT nextval('type_of_param_seq'),"
		"def_val     real,"
		"min         real,"
		"max         real,"
		"PRIMARY KEY (id)"
		");");

	queryList.push_back(
		"CREATE TRIGGER real_trig "
		"AFTER INSERT ON real "
		"FOR EACH ROW "
		"EXECUTE PROCEDURE copy_type_id();");
//------------------------

//------------------------
	queryList.push_back(
		"CREATE TABLE enum("
		"id          integer NOT NULL DEFAULT nextval('type_of_param_seq'),"
		"def_val     VARCHAR(40),"
		"PRIMARY KEY (id)"
		");");

	queryList.push_back(
		"CREATE TRIGGER enum_trig "
		"AFTER INSERT ON enum "
		"FOR EACH ROW "
		"EXECUTE PROCEDURE copy_type_id();");

	queryList.push_back(
		"CREATE TABLE enum_valid_value("
		"enum_id     integer,"
		"vv_id       serial,"
		"vv_str      VARCHAR(40) NOT NULL,"
		"vv_int      integer NOT NULL,"
		"PRIMARY KEY (enum_id, vv_id),"
		"FOREIGN KEY (enum_id) REFERENCES enum"
		");");
//------------------------

//------------------------
	queryList.push_back(
		"CREATE TABLE int("
		"id          integer NOT NULL DEFAULT nextval('type_of_param_seq'),"
		"def_val     integer,"
		"min         integer,"
		"max         integer,"
		"PRIMARY KEY (id)"
		");");

	queryList.push_back(
		"CREATE TRIGGER int_trig "
		"AFTER INSERT ON int "
		"FOR EACH ROW "
		"EXECUTE PROCEDURE copy_type_id();");

	return queryList;
}

void createDB()
{
	GeneralDB db;
	db.queryExec(generateCreateDBQuery());
}

int main(int argc, char *argv[])
{
	QCoreApplication app(argc, argv);

	dropDB  ();
	createDB();

	std::cout << "to be continued...\n";
	getch();
	return 0;
}
<commit_msg> - рефакторинг БД: переименование некоторых колонок<commit_after>/*!
  \copyright (c) RDO-Team, 2012
  \file      main.cpp
  \authors     (<EMAIL>)
  \authors     (<EMAIL>)
  \date      05.11.2012
  \brief         
  \indent    4T
*/

// ---------------------------------------------------------------------------- PCH
// ----------------------------------------------------------------------- INCLUDES
#include <iostream>
#include <conio.h>
#include <QtSql\QtSql>
#include <QtCore\QCoreApplication>
// ----------------------------------------------------------------------- SYNOPSIS
#include "simulator\compiler\parser\src\db\general_db.h"
// --------------------------------------------------------------------------------

void dropDB()
{
	GeneralDB db("localhost", "postgres", "postgres", "rdo", 5432);
	db.queryExec("DROP DATABASE IF EXISTS rdo;");
	db.queryExec("CREATE DATABASE rdo;");
}

GeneralDB::QueryList generateCreateDBQuery()
{
	GeneralDB::QueryList queryList;

	queryList.push_back(
		"CREATE TABLE rtp("
		"id       serial,"
		"rtp_name VARCHAR(40) NOT NULL,"
		"rtp_perm boolean NOT NULL,"
		"PRIMARY KEY (id)"
		");");

	queryList.push_back(
		"CREATE TABLE list_of_types_of_params("
		"type_id  integer,"
		"table_id integer NOT NULL,"
		"PRIMARY KEY (type_id)"
		");");

	queryList.push_back(
		"CREATE TABLE param_of_type("
		"id          serial,"
		"param_name  VARCHAR(40) NOT NULL,"
		"rtp_id      integer,"
		"type_id     integer NOT NULL,"
		"PRIMARY KEY (id,rtp_id),"
		"FOREIGN KEY (rtp_id) REFERENCES rtp(id),"
		"FOREIGN KEY (type_id) REFERENCES list_of_types_of_params"
		");");
//------------------------

//------------------------
	queryList.push_back("CREATE SEQUENCE type_of_param_seq;");

	queryList.push_back(
		"CREATE FUNCTION copy_type_id() RETURNS TRIGGER AS $trig$ "
		"BEGIN "
		"INSERT INTO list_of_types_of_params VALUES "
		"(NEW.id, NEW.tableoid); "
		"RETURN NULL; "
		"END; "
		"$trig$ LANGUAGE plpgsql; ");
//------------------------





//------------------------
	queryList.push_back(
		"CREATE TABLE real("
		"id          integer NOT NULL DEFAULT nextval('type_of_param_seq'),"
		"def_val     real,"
		"min         real,"
		"max         real,"
		"PRIMARY KEY (id)"
		");");

	queryList.push_back(
		"CREATE TRIGGER real_trig "
		"AFTER INSERT ON real "
		"FOR EACH ROW "
		"EXECUTE PROCEDURE copy_type_id();");
//------------------------

//------------------------
	queryList.push_back(
		"CREATE TABLE enum("
		"id          integer NOT NULL DEFAULT nextval('type_of_param_seq'),"
		"def_val     VARCHAR(40),"
		"PRIMARY KEY (id)"
		");");

	queryList.push_back(
		"CREATE TRIGGER enum_trig "
		"AFTER INSERT ON enum "
		"FOR EACH ROW "
		"EXECUTE PROCEDURE copy_type_id();");

	queryList.push_back(
		"CREATE TABLE enum_valid_value("
		"enum_id     integer,"
		"vv_id       serial,"
		"vv_str      VARCHAR(40) NOT NULL,"
		"vv_int      integer NOT NULL,"
		"PRIMARY KEY (enum_id, vv_id),"
		"FOREIGN KEY (enum_id) REFERENCES enum"
		");");
//------------------------

//------------------------
	queryList.push_back(
		"CREATE TABLE int("
		"id          integer NOT NULL DEFAULT nextval('type_of_param_seq'),"
		"def_val     integer,"
		"min         integer,"
		"max         integer,"
		"PRIMARY KEY (id)"
		");");

	queryList.push_back(
		"CREATE TRIGGER int_trig "
		"AFTER INSERT ON int "
		"FOR EACH ROW "
		"EXECUTE PROCEDURE copy_type_id();");

	return queryList;
}

void createDB()
{
	GeneralDB db;
	db.queryExec(generateCreateDBQuery());
}

int main(int argc, char *argv[])
{
	QCoreApplication app(argc, argv);

	dropDB  ();
	createDB();

	std::cout << "to be continued...\n";
	getch();
	return 0;
}

{'fraction_non_alphanumeric': 0.2505581089954038, 'fraction_numerical': 0.006828627708470125, 'mean_word_length': 1.7385832434376123, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4265094', 'n_tokens_mistral': 2892, 'n_tokens_neox': 2493, 'n_words': 557}