regent (REGistry of ENTerprises)
Ниже приведен код на С++, который с помощью open-source библиотеки RapidXML парсит данные ЕГРЮЛ из xml-файлов в указанной папке и помещает эти данные в связанную структуру в БД Oracle, где центральной сущностью этой связки является юридическое лицо.
#include "iostream"
#include "string"
#include "cstring"
#include "filesystem"
#include "fstream"
#include "vector"
#include "cpp/rapidxml-1.13/rapidxml.hpp"
#include "occi.h"
#include "exception"
#include "thread"
#include "sys/time.h"
#include "cmath"
using std::cout;
using std::string;
using std::endl;
using std::filesystem::directory_iterator;
using std::filesystem::path;
using std::ifstream;
using std::vector;
using std::istreambuf_iterator;
using rapidxml::xml_document;
using rapidxml::xml_node;
using rapidxml::xml_attribute;
using std::cerr;
using std::thread;
using std::move;
using oracle::occi::Environment;
using oracle::occi::Connection;
using oracle::occi::Statement;
using oracle::occi::SQLException;
using std::exception;
using oracle::occi::StatelessConnectionPool;
using oracle::occi::ConnectionPool;
using oracle::occi::Date;
using oracle::occi::Type;
#define TH_CNT 1000
Environment *env;
StatelessConnectionPool *scp;
string tag = "mc";
size_t number_of_files_in_directory(path path)
{
return std::distance(directory_iterator(path), directory_iterator{});
}
bool is_digits(const std::string &str)
{
return str.find_first_not_of("0123456789") == std::string::npos;
}
void labora_file(string file_name, int r_loading){
Connection *conn;
Statement *stmt;
Statement *stmt_1;
Statement *stmt_2;
Statement *stmt_3;
Statement *stmt_4;
Statement *stmt_5;
int r_loading_details;
int ent_i = 0;
Date sv_date;
Date reg_date;
Date pfr_date;
Date fss_date;
Date okved_date;
Date record_date;
Date doc_date;
Date edate(env,2222,12,31);
string fio = "";
string address = "";
string address_tail = "";
try{
conn = scp->getConnection(tag);
}
catch (exception &excp)
{
cerr << excp.what() << endl;
exit(EXIT_FAILURE);
}
stmt = conn->createStatement("INSERT INTO st_egrul_loading_details(n, r_st_egrul_loading, file_name, start_date, " \
"finish_date, status) VALUES (sq$st_egrul_loading_details.nextval,:1,:2,sysdate,null,1) RETURNING n INTO :3");
stmt->setInt(1,r_loading);
stmt->setString(2,file_name);
stmt->setInt(3,0);
stmt->executeUpdate();
r_loading_details = stmt->getInt(3);
conn->terminateStatement(stmt);
conn->commit();
//ent
stmt_1 = conn->createStatement("INSERT INTO st_egrul_enterprise(short_name, full_name, inn, kpp, ogrn, reg_org_code, reg_org_name, reg_org_date, " \
"pfr_no, pfr_date, pfr_name, fss_no, fss_date, fss_name, uk_title, uk_sum, gm_fio, gm_inn, gm_title, email, r_st_egrul_loading_details, " \
"address, rec_date, n) VALUES(:1, :2, :3, :4, :5, :6, :7, :8, :9, :10, :11, :12, :13, :14, :15, :16, :17, :18, :19, :20, :21, :22, :23, :24)");
//okveds
stmt_2 = conn->createStatement("INSERT INTO st_egrul_enterprise_okveds(r_st_egrul_enterprise, okved_code, is_main, r_st_egrul_loading_details, " \
"okved_title, rec_date) VALUES (:1, :2, :3, :4, :5, :6)");
stmt_2->setMaxIterations(1000);
stmt_2->setMaxParamSize(2,40);
stmt_2->setMaxParamSize(5,4000);
//founders
stmt_3 = conn->createStatement("INSERT INTO st_egrul_enterprise_founders(r_st_egrul_enterprise, r_st_egrul_loading_details, " \
"uch_name, uch_inn, uch_rate, uch_rate_percent) VALUES (:1,:2,:3,:4,:5,:6)");
stmt_3->setMaxIterations(1000);
stmt_3->setMaxParamSize(3,1000);
stmt_3->setMaxParamSize(4,10);
stmt_3->setMaxParamSize(5,15);
stmt_3->setMaxParamSize(6,3);
//egrul records
stmt_4 = conn->createStatement("INSERT INTO st_egrul_enterprise_records(r_st_egrul_enterprise, r_st_egrul_loading_details, " \
"rec_date, rec_grn, rec_content, rec_org, n) VALUES (:1,:2,:3,:4,:5,:6, :7)");
stmt_4->setMaxIterations(1000);
stmt_4->setMaxParamSize(4,20);
stmt_4->setMaxParamSize(5,250);
stmt_4->setMaxParamSize(6,250);
//record docs
stmt_5 = conn->createStatement("INSERT INTO st_egrul_enterprise_record_docs(r_st_egrul_enterprise_record, r_st_egrul_enterprise, " \
"r_st_egrul_loading_details, doc_name, doc_date) VALUES (:1,:2,:3,:4,:5)");
stmt_5->setMaxIterations(1000);
stmt_5->setMaxParamSize(4,250);
xml_document<> doc;
ifstream theFile(file_name);
vector buffer((istreambuf_iterator(theFile)), istreambuf_iterator());
buffer.push_back('\0');
doc.parse<0>(&buffer[0]);
xml_node<> *node;
xml_node<> *node2;
xml_node<> *node3;
xml_attribute<> *atr;
xml_node<> *egrul_node = doc.first_node("EGRUL");
if (egrul_node){
xml_node<> *ul_node = egrul_node->first_node("СвЮЛ");
while (ul_node){
//sv_date
atr = ul_node->first_attribute("ДатаВып");
if (atr){
sv_date.fromText(atr->value(), "YYYY-MM-DD", "", env);
stmt_1->setDate(23, sv_date);
}else{
break;
}
ent_i++;
stmt_1->setInt(24, ent_i);
//inn
atr = ul_node->first_attribute("ИНН");
if (atr){
stmt_1->setString(3, atr->value());
}else{
stmt_1->setString(3, "");
}
//kpp
atr = ul_node->first_attribute("КПП");
if (atr){
stmt_1->setString(4, atr->value());
}else{
stmt_1->setString(4, "");
}
//ogrn
atr = ul_node->first_attribute("ОГРН");
if (atr){
stmt_1->setString(5, atr->value());
}else{
stmt_1->setString(5, "");
}
//name of Ur Litso
node = ul_node->first_node("СвНаимЮЛ");
if(node){
//full_name
atr = node->first_attribute("НаимЮЛПолн");
if (atr){
stmt_1->setString(2, atr->value());
}else{
stmt_1->setString(2, "");
}
//short_name
node = node->first_node("СвНаимЮЛСокр");
if(node){
atr = node->first_attribute("НаимСокр");
if (atr){
stmt_1->setString(1, atr->value());
}else{
stmt_1->setString(1, "");
}
}else{
stmt_1->setString(1, "");
}
}else{
stmt_1->setString(1, "");
stmt_1->setString(2, "");
}//end of СвНаимЮЛ
//Reg Organization
node = ul_node->first_node("СвРегОрг");
if(node){
//Cod
atr = node->first_attribute("КодНО");
if (atr){
stmt_1->setString(6, atr->value());
}else{
stmt_1->setString(6, "");
}
//Name
atr = node->first_attribute("НаимНО");
if (atr){
stmt_1->setString(7, atr->value());
}else{
stmt_1->setString(7, "");
}
//Date
node = node->first_node("ГРНДата");
if(node){
atr = node->first_attribute("ДатаЗаписи");
if (atr){
reg_date.fromText(atr->value(), "YYYY-MM-DD", "", env);
stmt_1->setDate(8, reg_date);
}else{
stmt_1->setDate(8, edate);
////stmt_1->setString(8, "");
////stmt_1->setNull(8, (Type)SQLT_INT);
}
}else{
stmt_1->setDate(8, edate);
////stmt_1->setString(8, "");
}
//// stmt_1->setString(8, "");
}else{
stmt_1->setString(6, "");
stmt_1->setString(7, "");
stmt_1->setDate(8, edate);
////stmt_1->setString(8, "");
}//end of Reg_org
//PFR
node = ul_node->first_node("СвРегПФ");
if(node){
//No
atr = node->first_attribute("РегНомПФ");
if (atr){
stmt_1->setString(9, atr->value());
}else{
stmt_1->setString(9, "");
}
//Date
atr = node->first_attribute("ДатаРег");
if (atr){
pfr_date.fromText(atr->value(), "YYYY-MM-DD", "", env);
stmt_1->setDate(10, pfr_date);
}else{
stmt_1->setDate(10, edate);
////stmt_1->setString(10, "");
}
//Name
node = node->first_node("СвОргПФ");
if(node){
atr = node->first_attribute("НаимПФ");
if (atr){
stmt_1->setString(11, atr->value());
}else{
stmt_1->setString(11, "");
}
}else{
stmt_1->setString(11, "");
}
}else{
stmt_1->setString(9, "");
stmt_1->setDate(10, edate);
////stmt_1->setString(10, "");
stmt_1->setString(11, "");
}//end of PFR
//FSS
node = ul_node->first_node("СвРегФСС");
if(node){
//No
atr = node->first_attribute("РегНомФСС");
if (atr){
stmt_1->setString(12, atr->value());
}else{
stmt_1->setString(12, "");
}
//Date
atr = node->first_attribute("ДатаРег");
if (atr){
fss_date.fromText(atr->value(), "YYYY-MM-DD", "", env);
stmt_1->setDate(13, fss_date);
}else{
stmt_1->setDate(13, edate);
////stmt_1->setString(10, "");
}
//Name
node = node->first_node("СвОргФСС");
if(node){
atr = node->first_attribute("НаимФСС");
if (atr){
stmt_1->setString(14, atr->value());
}else{
stmt_1->setString(14, "");
}
}else{
stmt_1->setString(14, "");
}
}else{
stmt_1->setString(12, "");
stmt_1->setDate(13, edate);
////stmt_1->setString(10, "");
stmt_1->setString(14, "");
}//end of FSS
//UK
node = ul_node->first_node("СвУстКап");
if(node){
//Naim
atr = node->first_attribute("НаимВидКап");
if (atr){
stmt_1->setString(15, atr->value());
}else{
stmt_1->setString(15, "");
}
//Summa
atr = node->first_attribute("СумКап");
if (atr){
stmt_1->setString(16, atr->value());
}else{
stmt_1->setString(16, "");
}
}else{
stmt_1->setString(15, "");
stmt_1->setString(16, "");
}//end of UK
//GM
node = ul_node->first_node("СведДолжнФЛ");
if(node){
//fio+inn
node2 = node->first_node("СвФЛ");
if (node2){
fio = "";
atr = node2->first_attribute("Фамилия");
if (atr){
fio = fio + atr->value() + " ";
}
atr = node2->first_attribute("Имя");
if (atr){
fio = fio + atr->value() + " ";
}
atr = node2->first_attribute("Отчество");
if (atr){
fio = fio + atr->value() + " ";
}
stmt_1->setString(17, fio);
atr = node2->first_attribute("ИННФЛ");
if (atr){
stmt_1->setString(18, atr->value());
}else{
stmt_1->setString(18, "");
}
}else{
stmt_1->setString(17, "");
stmt_1->setString(18, "");
}
//title
node3 = node->first_node("СвДолжн");
if (node3){
atr = node3->first_attribute("НаимДолжн");
if (atr){
stmt_1->setString(19, atr->value());
}else{
stmt_1->setString(19, "");
}
}else{
stmt_1->setString(19, "");
}
}else{
stmt_1->setString(17, "");
stmt_1->setString(18, "");
stmt_1->setString(19, "");
}//end of GM
//email
node = ul_node->first_node("СвАдрЭлПочты");
if(node){
atr = node->first_attribute("E-mail");
if (atr){
stmt_1->setString(20, atr->value());
}else{
stmt_1->setString(20, "");
}
}else{
stmt_1->setString(20, "");
}//end of email
//set r_loading_details
stmt_1->setInt(21, r_loading_details);
//address
node = ul_node->first_node("СвАдресЮЛ");
if(node){
address = "";
node2 = node->first_node("СвАдрЮЛФИАС");
if (node2){
atr = node2->first_attribute("Индекс");
if (atr){
address = address + atr->value() + ", ";
}
node3 = node2->first_node("НаимРегион");
if (node3){
address = address + node3->value() + ", ";
}
node3 = node2->first_node("НаселенПункт");
if (node3){
atr = node3->first_attribute("Вид");
if (atr){
address = address + atr->value() + " ";
}
atr = node3->first_attribute("Наим");
if (atr){
address = address + atr->value() + ", ";
}
}
node3 = node2->first_node("ЭлУлДорСети");
if (node3){
atr = node3->first_attribute("Тип");
if (atr){
address = address + atr->value() + " ";
}
atr = node3->first_attribute("Наим");
if (atr){
address = address + atr->value() + ", ";
}
}
node3 = node2->first_node("Здание");
while (node3){
atr = node3->first_attribute("Тип");
if (atr){
address = address + atr->value() + " ";
}
atr = node3->first_attribute("Номер");
if (atr){
address = address + atr->value() + ", ";
}
node3 = node3->next_sibling("Здание");
}//end while
node3 = node2->first_node("ПомещЗдания");
if (node3){
atr = node3->first_attribute("Тип");
if (atr){
address = address + atr->value() + " ";
}
atr = node3->first_attribute("Номер");
if (atr){
address = address + atr->value() + ", ";
}
}
node3 = node2->first_node("ПомещКвартиры");
if (node3){
atr = node3->first_attribute("Тип");
if (atr){
address = address + atr->value() + " ";
}
atr = node3->first_attribute("Номер");
if (atr){
address = address + atr->value() + ", ";
}
}
stmt_1->setString(22, address);
}else{
node2 = node->first_node("АдресРФ");
if (node2){
atr = node2->first_attribute("Индекс");
if (atr){
address = address + atr->value() + ", ";
}
address_tail = "";
atr = node2->first_attribute("Дом");
if (atr){
string s1;
s1 = atr->value();
if (is_digits(s1)){
s1 = "Д. " + s1;
}
address_tail = address_tail + s1 + ", ";
}
atr = node2->first_attribute("Корпус");
if (atr){
address_tail = address_tail + "КОРП. " +atr->value() + ", ";
}
atr = node2->first_attribute("Кварт");
if (atr){
string s1;
s1 = atr->value();
if (is_digits(s1)){
s1 = "КВ. " + s1;
}
address_tail = address_tail + s1;
}
node3 = node2->first_node("Регион");
if (node3){
string name = "";
atr = node3->first_attribute("НаимРегион");
if (atr){
name = atr->value();
}
atr = node3->first_attribute("ТипРегион");
if (atr){
string s1;
s1 = atr->value();
if (s1.compare("ГОРОД")==0){
name = "Г. " + name;
}else{
if (s1.compare("РЕСПУБЛИКА")==0){
name = "РЕСПУБЛИКА " + name;
}else{
name = name + " " + s1;
}
}
}
address = address + name + ", ";
}
node3 = node2->first_node("Район");
if (node3){
atr = node3->first_attribute("ТипРайон");
if (atr){
address = address + atr->value() + " ";
}
atr = node3->first_attribute("НаимРайон");
if (atr){
address = address + atr->value() + ", ";
}
}
node3 = node2->first_node("НаселПункт");
if (node3){
atr = node3->first_attribute("ТипНаселПункт");
if (atr){
address = address + atr->value() + " ";
}
atr = node3->first_attribute("НаимНаселПункт");
if (atr){
address = address + atr->value() + ", ";
}
}
node3 = node2->first_node("Город");
if (node3){
atr = node3->first_attribute("ТипГород");
if (atr){
address = address + atr->value() + " ";
}
atr = node3->first_attribute("НаимГород");
if (atr){
address = address + atr->value() + ", ";
}
}
node3 = node2->first_node("Улица");
if (node3){
atr = node3->first_attribute("ТипУлица");
if (atr){
address = address + atr->value() + " ";
}
atr = node3->first_attribute("НаимУлица");
if (atr){
address = address + atr->value() + ", ";
}
}
address = address + address_tail;
stmt_1->setString(22, address);
}else{
stmt_1->setString(22, "");
}
}
}else{
stmt_1->setString(22, "");
}//end of address
//insert record about Ur Litso
stmt_1->executeUpdate();
//OKVEDS
stmt_2->setInt(1, ent_i);
stmt_2->setInt(4, r_loading_details);
node = ul_node->first_node("СвОКВЭД");
if(node){
node2 = node->first_node("СвОКВЭДОсн");
if(node2){
atr = node2->first_attribute("КодОКВЭД");
if (atr){
stmt_2->setString(2, atr->value());
}else{
stmt_2->setString(2, "0");
}
atr = node2->first_attribute("НаимОКВЭД");
if (atr){
stmt_2->setString(5, atr->value());
}else{
stmt_2->setString(5, "NO_NAME");
}
//
node3 = node2->first_node("ГРНДата");
if(node3){
atr = node3->first_attribute("ДатаЗаписи");
if(atr){
okved_date.fromText(atr->value(), "YYYY-MM-DD", "", env);
stmt_2->setDate(6, okved_date);
}else{
stmt_2->setDate(6, edate);
}
}else{
stmt_2->setDate(6, edate);
}
//
}else{
stmt_2->setString(2, "0");
stmt_2->setString(5, "NO_NAME");
stmt_2->setDate(6, edate);
}
stmt_2->setInt(3, 1);
//DOPs
node2 = node->first_node("СвОКВЭДДоп");
while(node2){
stmt_2->addIteration();
stmt_2->setInt(1, ent_i);
stmt_2->setInt(4, r_loading_details);
atr = node2->first_attribute("КодОКВЭД");
if (atr){
stmt_2->setString(2, atr->value());
}else{
stmt_2->setString(2, "0");
}
stmt_2->setInt(3, 0);
atr = node2->first_attribute("НаимОКВЭД");
if (atr){
stmt_2->setString(5, atr->value());
}else{
stmt_2->setString(5, "NO_NAME");
}
//
node3 = node2->first_node("ГРНДата");
if(node3){
atr = node3->first_attribute("ДатаЗаписи");
if(atr){
okved_date.fromText(atr->value(), "YYYY-MM-DD", "", env);
stmt_2->setDate(6, okved_date);
}else{
stmt_2->setDate(6, edate);
}
}else{
stmt_2->setDate(6, edate);
}
//
//next
node2 = node2->next_sibling("СвОКВЭДДоп");
}//end while Dop Kods
}else{
stmt_2->setString(2, "0");
stmt_2->setInt(3, 1);
stmt_2->setString(5, "NO_NAME");
stmt_2->setDate(6, edate);
}
stmt_2->executeUpdate();
//end of OKVEDS
//FOUNDERS
node = ul_node->first_node("СвУчредит");
if(node){
//FL
node2 = node->first_node("УчрФЛ");
while(node2){
stmt_3->setInt(1, ent_i);
stmt_3->setInt(2, r_loading_details);
node3 = node2->first_node("СвФЛ");
if (node3){
fio = "";
atr = node3->first_attribute("Фамилия");
if (atr){
fio = fio + atr->value() + " ";
}
atr = node3->first_attribute("Имя");
if (atr){
fio = fio + atr->value() + " ";
}
atr = node3->first_attribute("Отчество");
if (atr){
fio = fio + atr->value() + " ";
}
stmt_3->setString(3, fio);
atr = node3->first_attribute("ИННФЛ");
if (atr){
stmt_3->setString(4, atr->value());
}else{
stmt_3->setString(4, "");
}
}
//capital
node3 = node2->first_node("ДоляУстКап");
if(node3){
atr = node3->first_attribute("НоминСтоим");
if (atr){
stmt_3->setString(5, atr->value());
stmt_3->setString(6, "");
}else{
stmt_3->setString(5, "");
stmt_3->setString(6, "");
}
}else{
stmt_3->setString(5, "");
stmt_3->setString(6, "");
}
//next
node2 = node2->next_sibling("УчрФЛ");
if(node2){stmt_3->addIteration();}
}//end while
//UL-Ros
node2 = node->first_node("УчрЮЛРос");
while(node2){
stmt_3->setInt(1, ent_i);
stmt_3->setInt(2, r_loading_details);
node3 = node2->first_node("НаимИННЮЛ");
if (node3){
atr = node3->first_attribute("НаимЮЛПолн");
if (atr){
stmt_3->setString(3, atr->value());
}else{
stmt_3->setString(3, "");
}
atr = node3->first_attribute("ИНН");
if (atr){
stmt_3->setString(4, atr->value());
}else{
stmt_3->setString(4, "");
}
}
//capital
node3 = node2->first_node("ДоляУстКап");
if(node3){
atr = node3->first_attribute("НоминСтоим");
if (atr){
stmt_3->setString(5, atr->value());
stmt_3->setString(6, "");
}else{
stmt_3->setString(5, "");
stmt_3->setString(6, "");
}
}else{
stmt_3->setString(5, "");
stmt_3->setString(6, "");
}
//next
node2 = node2->next_sibling("УчрФЛ");
if(node2){stmt_3->addIteration();}
}//end while
//UL-In
node2 = node->first_node("УчрЮЛИн");
while(node2){
stmt_3->setInt(1, ent_i);
stmt_3->setInt(2, r_loading_details);
node3 = node2->first_node("НаимИННЮЛ");
if (node3){
atr = node3->first_attribute("НаимЮЛПолн");
if (atr){
stmt_3->setString(3, atr->value());
}else{
stmt_3->setString(3, "");
}
atr = node3->first_attribute("ИНН");
if (atr){
stmt_3->setString(4, atr->value());
}else{
stmt_3->setString(4, "");
}
}
//capital
node3 = node2->first_node("ДоляУстКап");
if(node3){
atr = node3->first_attribute("НоминСтоим");
if (atr){
stmt_3->setString(5, atr->value());
stmt_3->setString(6, "");
}else{
stmt_3->setString(5, "");
stmt_3->setString(6, "");
}
}else{
stmt_3->setString(5, "");
stmt_3->setString(6, "");
}
//next
node2 = node2->next_sibling("УчрФЛ");
if(node2){stmt_3->addIteration();}
}//end while
//UL-Sub'ekt of Ros Federation
node2 = node->first_node("УчрРФСубМО");
while(node2){
stmt_3->setInt(1, ent_i);
stmt_3->setInt(2, r_loading_details);
node3 = node2->first_node("ВидНаимУчр");
if (node3){
atr = node3->first_attribute("КодУчрРФСубМО");
if (atr){
string s1 = atr->value();
if (s1.compare("1")==0) {
stmt_3->setString(3, "РОССИЙСКАЯ ФЕДЕРАЦИЯ");
}else{
stmt_3->setString(3, s1);
}
}else{
stmt_3->setString(3, "");
}
}
stmt_3->setString(4, "");
//capital
node3 = node2->first_node("ДоляУстКап");
if(node3){
atr = node3->first_attribute("НоминСтоим");
if (atr){
stmt_3->setString(5, atr->value());
stmt_3->setString(6, "");
}else{
stmt_3->setString(5, "");
stmt_3->setString(6, "");
}
}else{
stmt_3->setString(5, "");
stmt_3->setString(6, "");
}
//next
node2 = node2->next_sibling("УчрРФСубМО");
if (node2) {stmt_3->addIteration();}
}//end while
stmt_3->executeUpdate();
}//end of FOUNDERS
//EGRUL records
int record_i = 0;
node = ul_node->first_node("СвЗапЕГРЮЛ");
while(node){
record_i++;
stmt_4->setInt(1, ent_i);
stmt_4->setInt(2, r_loading_details);
atr = node->first_attribute("ДатаЗап");
if (atr){
record_date.fromText(atr->value(), "YYYY-MM-DD", "", env);
stmt_4->setDate(3, record_date);
}else{
stmt_4->setDate(3, edate);
}
atr = node->first_attribute("ГРН");
if (atr){
stmt_4->setString(4, atr->value());
}else{
stmt_4->setString(4, "");
}
node2 = node->first_node("ВидЗап");
if(node2){
atr = node2->first_attribute("НаимВидЗап");
if (atr){
stmt_4->setString(5, atr->value());
}else{
stmt_4->setString(5, "");
}
}else{
stmt_4->setString(5, "");
}
node2 = node->first_node("СвРегОрг");
if(node2){
atr = node2->first_attribute("НаимНО");
if (atr){
stmt_4->setString(6, atr->value());
}else{
stmt_4->setString(6, "");
}
}else{
stmt_4->setString(6, "");
}
stmt_4->setInt(7, record_i);
//RECORD_DOCS
node2 = node->first_node("СведПредДок");
while(node2){
stmt_5->setInt(1, record_i);
stmt_5->setInt(2, ent_i);
stmt_5->setInt(3, r_loading_details);
node3 = node2->first_node("НаимДок");
if(node3){
stmt_5->setString(4, node3->value());
}else{
stmt_5->setString(4, "");
}
node3 = node2->first_node("ДатаДок");
if(node3){
doc_date.fromText(node3->value(), "YYYY-MM-DD", "", env);
stmt_5->setDate(5, doc_date);
}else{
stmt_5->setDate(5, edate);
}
node2 = node2->next_sibling("СведПредДок");
stmt_5->addIteration();
}//end while
//end od record_docs
node = node->next_sibling("СвЗапЕГРЮЛ");
if (node) {stmt_4->addIteration();}
}//end while
stmt_5->executeUpdate();
stmt_4->executeUpdate();
//next Ur Litso
ul_node = ul_node->next_sibling("СвЮЛ");
}//end while ULs
}
conn->terminateStatement(stmt_5);
conn->terminateStatement(stmt_4);
conn->terminateStatement(stmt_3);
conn->terminateStatement(stmt_2);
conn->terminateStatement(stmt_1);
stmt = conn->createStatement("UPDATE st_egrul_loading_details SET finish_date = sysdate, status = 2, ent_cnt = :1 WHERE n = :2");
stmt->setInt(1,ent_i);
stmt->setInt(2,r_loading_details);
stmt->executeUpdate();
conn->terminateStatement(stmt);
conn->commit();
scp->releaseConnection(conn, tag);
cout << file_name << endl;
return;
}
int main(int argc, char* argv[]){
struct timeval start, finish;
gettimeofday(&start, NULL);
if (argc < 2){
cerr << "Path is empty" << endl;
exit(EXIT_FAILURE);
}
string path = argv[1];
///cout << number_of_files_in_directory(path) << endl;
try{
env = Environment::createEnvironment(Environment::THREADED_MUTEXED);
scp = env->createStatelessConnectionPool(
"regent", "regent", "localhost:1521/orclcdb", 1000, 5, 10,
StatelessConnectionPool::HOMOGENEOUS );
}
catch (exception &excp)
{
cerr << excp.what() << endl;
return -1;
}
Connection *conn;
Statement *stmt;
int loading;
try{
conn = scp->getConnection(tag);
}
catch (exception &excp)
{
cerr << excp.what() << endl;
exit(EXIT_FAILURE);
}
stmt = conn->createStatement("INSERT INTO st_egrul_loading(n, start_date, finish_date, status) VALUES (sq$st_egrul_loading.nextval,sysdate,null,1) RETURNING n INTO :1");
stmt->setInt(1,0);
stmt->executeUpdate();
loading = stmt->getInt(1);
conn->terminateStatement(stmt);
conn->commit();
vector threads;
int i=0;
for (const auto & file : directory_iterator(path)){
thread thr(labora_file, file.path(), loading);
threads.emplace_back(move(thr));
i++;
if (i == TH_CNT){
cout << "Limit of Threads = " << TH_CNT << " is reached\n";
break;
}
}
for(auto & thr : threads) {
thr.join();
}
stmt = conn->createStatement("UPDATE st_egrul_loading SET finish_date = sysdate, status = 2 WHERE n = :1");
stmt->setInt(1,loading);
stmt->executeUpdate();
conn->terminateStatement(stmt);
conn->commit();
try{
scp->terminateConnection(conn);
env->terminateStatelessConnectionPool(scp);
Environment::terminateEnvironment(env);
}
catch (exception &excp)
{
cerr << excp.what() << endl;
return -1;
}
gettimeofday(&finish, NULL);
float delta = ((finish.tv_sec*1000000+finish.tv_usec)-(start.tv_sec*1000000 + start.tv_usec))/1000000.0;
cout << "\n\033[1;31m" << ceil(delta * 100.0) / 100.0 << "s\033[0m\n" << endl;
return 0;
}
sdmrnv, 2023-01-19 [1.595ms, r]
