<commit_before>﻿/*!
  \copyright (c) RDO-Team, 2012
  \file      general_db.cpp
  \authors   <NAME> (<EMAIL>)
  \authors   <NAME> (<EMAIL>)
  \date      15.11.2012
  \brief     Базовая работа с базой данных
  \indent    4T
*/

// ---------------------------------------------------------------------------- PCH
// ----------------------------------------------------------------------- INCLUDES
#include <QtSql\QtSql>
#include <QtSql\QSqlError>
#include <iostream>
#include <boost\foreach.hpp>
// ----------------------------------------------------------------------- SYNOPSIS
#include "simulator\compiler\parser\src\db\general_db.h"
#include "utils\rdodebug.h"
// --------------------------------------------------------------------------------

GeneralDB::GeneralDB(const QString& hostName, const QString& databaseName, const QString& userName, const QString& password, const int& port)
	: m_hostName    (hostName    )
	, m_databaseName(databaseName)
	, m_userName    (userName    )
	, m_password    (password    )
	, m_port        (port        )
{
	initDB();
}

GeneralDB::GeneralDB()
{
	setDefParams();
	initDB      ();
}

GeneralDB::~GeneralDB()
{
	m_db.close();
}

void GeneralDB::insertRow(const QString& tableName, const QString& qRow)
{
	queryExec("INSERT INTO " + tableName + " VALUES(" + qRow + ");");
}

void GeneralDB::queryExec(const QueryList& query)
{
	BOOST_FOREACH(const QString& queryItem, query)
	{
		queryExec(queryItem);
	}
}

void GeneralDB::queryExec(const QString& query)
{
	std::cout << query.toStdString() << "..." << std::endl;

	m_db.exec(query);

	QSqlError lastError = m_db.lastError();
	switch (lastError.type())
	{
	case QSqlError::NoError:
		std::cout << query.toStdString() << "... ok" << std::endl;
		break;

	default:
		std::cerr << query.toStdString() << "... failed: " << lastError.text().toStdString() << std::endl;
		break;
	}
}

int GeneralDB::queryExecIndex(const QString& table)
{
	QSqlQuery query;
	query.exec(QString("select max(id) as alt from %1;")
		.arg(table ));
	query.next();
	int index = query.value(query.record().indexOf("alt")).toInt();
	m_context = index;
	return index;
}

void GeneralDB::pushContext(int context)
{
	m_context = context<int>;
}

IDB::bany GeneralDB::popContext()
{
	ASSERT(!m_context.empty());
	bany i = m_context;<commit_msg> - фикс error'а<commit_after>﻿/*!
  \copyright (c) RDO-Team, 2012
  \file      general_db.cpp
  \authors   <NAME> (<EMAIL>)
  \authors   <NAME> (<EMAIL>)
  \date      15.11.2012
  \brief     Базовая работа с базой данных
  \indent    4T
*/

// ---------------------------------------------------------------------------- PCH
// ----------------------------------------------------------------------- INCLUDES
#include <QtSql\QtSql>
#include <QtSql\QSqlError>
#include <iostream>
#include <boost\foreach.hpp>
// ----------------------------------------------------------------------- SYNOPSIS
#include "simulator\compiler\parser\src\db\general_db.h"
#include "utils\rdodebug.h"
// --------------------------------------------------------------------------------

GeneralDB::GeneralDB(const QString& hostName, const QString& databaseName, const QString& userName, const QString& password, const int& port)
	: m_hostName    (hostName    )
	, m_databaseName(databaseName)
	, m_userName    (userName    )
	, m_password    (password    )
	, m_port        (port        )
{
	initDB();
}

GeneralDB::GeneralDB()
{
	setDefParams();
	initDB      ();
}

GeneralDB::~GeneralDB()
{
	m_db.close();
}

void GeneralDB::insertRow(const QString& tableName, const QString& qRow)
{
	queryExec("INSERT INTO " + tableName + " VALUES(" + qRow + ");");
}

void GeneralDB::queryExec(const QueryList& query)
{
	BOOST_FOREACH(const QString& queryItem, query)
	{
		queryExec(queryItem);
	}
}

void GeneralDB::queryExec(const QString& query)
{
	std::cout << query.toStdString() << "..." << std::endl;

	m_db.exec(query);

	QSqlError lastError = m_db.lastError();
	switch (lastError.type())
	{
	case QSqlError::NoError:
		std::cout << query.toStdString() << "... ok" << std::endl;
		break;

	default:
		std::cerr << query.toStdString() << "... failed: " << lastError.text().toStdString() << std::endl;
		break;
	}
}

int GeneralDB::queryExecIndex(const QString& table)
{
	QSqlQuery query;
	query.exec(QString("select max(id) as alt from %1;")
		.arg(table ));
	query.next();
	int index = query.value(query.record().indexOf("alt")).toInt();
	m_context = index;
	return index;
}

void GeneralDB::pushContext(int context)
{
	m_context = context;
}

IDB::bany GeneralDB::popContext()
{
	ASSERT(!m_context.empty());
	bany i = m_context;
{'fraction_non_alphanumeric': 0.27590701716272, 'fraction_numerical': 0.006082989354768629, 'mean_word_length': 2.2862241256245537, 'pattern_counts': {'":': 0, '<': 60, '<?xml version=': 0, '>': 20, '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': '6961045', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1483, 'n_words': 297}