Commit fe521c11 authored by Pavel Vainerman's avatar Pavel Vainerman

(PGSQL): предварительная версия

parent 627ea7d9
%def_enable docs %def_enable docs
%def_enable mysql %def_enable mysql
%def_enable sqlite %def_enable sqlite
%def_enable postgresql %def_enable pgsql
%def_enable python %def_enable python
%def_enable rrd %def_enable rrd
%def_enable io %def_enable io
...@@ -43,7 +43,7 @@ BuildRequires: libMySQL-devel ...@@ -43,7 +43,7 @@ BuildRequires: libMySQL-devel
BuildRequires: libsqlite3-devel BuildRequires: libsqlite3-devel
%endif %endif
%if_enabled postgresql %if_enabled pgsql
BuildRequires: postgresql9.3-devel libpq5.6-devel BuildRequires: postgresql9.3-devel libpq5.6-devel
%endif %endif
...@@ -180,21 +180,21 @@ Requires: %name-extension-common = %version-%release ...@@ -180,21 +180,21 @@ Requires: %name-extension-common = %version-%release
Libraries needed to develop for uniset SQLite Libraries needed to develop for uniset SQLite
%endif %endif
%if_enabled postgresql %if_enabled pgsql
%package extension-postgresql %package extension-pgsql
Group: Development/Databases Group: Development/Databases
Summary: PostgreSQL-dbserver implementatioin for UniSet Summary: PostgreSQL-dbserver implementatioin for UniSet
Requires: %name-extension-common = %version-%release Requires: %name-extension-common = %version-%release
%description extension-postgresql %description extension-pgsql
PostgreSQL dbserver for %name PostgreSQL dbserver for %name
%package extension-postgresql-devel %package extension-pgsql-devel
Group: Development/Databases Group: Development/Databases
Summary: Libraries needed to develop for uniset PostgreSQL Summary: Libraries needed to develop for uniset PostgreSQL
Requires: %name-extension-common-devel = %version-%release Requires: %name-extension-common-devel = %version-%release
%description extension-postgresql-devel %description extension-pgsql-devel
Libraries needed to develop for uniset PostgreSQL Libraries needed to develop for uniset PostgreSQL
%endif %endif
...@@ -264,7 +264,7 @@ SharedMemoryPlus extension ('all in one') for libuniset ...@@ -264,7 +264,7 @@ SharedMemoryPlus extension ('all in one') for libuniset
%build %build
%autoreconf %autoreconf
%configure %{subst_enable doc} %{subst_enable mysql} %{subst_enable sqlite} %{subst_enable postgresql} %{subst_enable python} %{subst_enable rrd} %{subst_enable io} %{subst_enable logicproc} %{subst_enable tests} %configure %{subst_enable doc} %{subst_enable mysql} %{subst_enable sqlite} %{subst_enable pgsql} %{subst_enable python} %{subst_enable rrd} %{subst_enable io} %{subst_enable logicproc} %{subst_enable tests}
%make %make
%install %install
...@@ -315,8 +315,8 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname ...@@ -315,8 +315,8 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
%if_enabled sqlite %if_enabled sqlite
%_includedir/%oname/sqlite/ %_includedir/%oname/sqlite/
%endif %endif
%if_enabled postgresql %if_enabled pgsql
%_includedir/%oname/postgresql/ %_includedir/%oname/pgsql/
%endif %endif
%_libdir/libUniSet2.so %_libdir/libUniSet2.so
...@@ -341,12 +341,12 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname ...@@ -341,12 +341,12 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
%_pkgconfigdir/libUniSet2SQLite.pc %_pkgconfigdir/libUniSet2SQLite.pc
%endif %endif
%if_enabled postgresql %if_enabled pgsql
%files extension-postgresql %files extension-pgsql
%_bindir/%oname-postgresql-*dbserver %_bindir/%oname-pgsql-*dbserver
%_libdir/*-postgresql.so* %_libdir/*-pgsql.so*
%files extension-postgresql-devel %files extension-pgsql-devel
%_pkgconfigdir/libUniSet2PostgreSQL.pc %_pkgconfigdir/libUniSet2PostgreSQL.pc
%endif %endif
......
...@@ -81,6 +81,23 @@ fi ...@@ -81,6 +81,23 @@ fi
AM_CONDITIONAL(DISABLE_MYSQL, test ${buildmysql} = false) AM_CONDITIONAL(DISABLE_MYSQL, test ${buildmysql} = false)
#check pgsql support
AC_MSG_CHECKING([postgresql support])
buildpgsql=true
AC_ARG_ENABLE(pgsql, AC_HELP_STRING([--disable-pgsql], [disable PostgreSQL support]),
[ if test $enableval = yes; then buildpgsql=true; else buildpgsql=false; fi],[ buildpgsql=true; ])
if test ${buildpgsql} = true; then
AC_MSG_RESULT([enabled])
PKG_CHECK_MODULES(PGSQL,libpq)
AC_SUBST(PGSQL_LIBS)
AC_SUBST(PGSQL_CFLAGS)
else
AC_MSG_RESULT([disabled])
fi
AM_CONDITIONAL(DISABLE_PGSQL, test ${buildpgsql} = false)
#check rrd support #check rrd support
AC_MSG_CHECKING([rrd support]) AC_MSG_CHECKING([rrd support])
...@@ -330,6 +347,8 @@ AC_CONFIG_FILES([Makefile ...@@ -330,6 +347,8 @@ AC_CONFIG_FILES([Makefile
extensions/DBServer-MySQL/libUniSet2MySQL.pc extensions/DBServer-MySQL/libUniSet2MySQL.pc
extensions/DBServer-SQLite/Makefile extensions/DBServer-SQLite/Makefile
extensions/DBServer-SQLite/libUniSet2SQLite.pc extensions/DBServer-SQLite/libUniSet2SQLite.pc
extensions/DBServer-PostgreSQL/Makefile
extensions/DBServer-PostgreSQL/libUniSet2PostgreSQL.pc
extensions/IOControl/Makefile extensions/IOControl/Makefile
extensions/IOControl/libUniSet2IOControl.pc extensions/IOControl/libUniSet2IOControl.pc
extensions/ModbusMaster/Makefile extensions/ModbusMaster/Makefile
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
using namespace UniSetTypes; using namespace UniSetTypes;
using namespace std; using namespace std;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#define dblog if( ulog()->debugging(DBLogInfoLevel) ) (*(ulog().get()))[DBLogInfoLevel] #define dblog if( ulog()->debugging(DBLogInfoLevel) ) ulog()->debug(DBLogInfoLevel)
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
DBServer_MySQL::DBServer_MySQL(ObjectId id): DBServer_MySQL::DBServer_MySQL(ObjectId id):
DBServer(id), DBServer(id),
......
...@@ -12,11 +12,10 @@ ...@@ -12,11 +12,10 @@
using namespace UniSetTypes; using namespace UniSetTypes;
using namespace std; using namespace std;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
const Debug::type DBLEVEL = Debug::LEVEL1; #define dblog if( ulog()->debugging(DBLogInfoLevel) ) ulog()->debug(DBLogInfoLevel)
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
DBServer_PostgreSQL::DBServer_PostgreSQL(ObjectId id): DBServer_PostgreSQL::DBServer_PostgreSQL(ObjectId id, const std::string& prefix ):
DBServer(id), DBServer(id),
db(new PostgreSQLInterface()),
PingTime(300000), PingTime(300000),
ReconnectTime(180000), ReconnectTime(180000),
connect_ok(false), connect_ok(false),
...@@ -24,6 +23,8 @@ DBServer_PostgreSQL::DBServer_PostgreSQL(ObjectId id): ...@@ -24,6 +23,8 @@ DBServer_PostgreSQL::DBServer_PostgreSQL(ObjectId id):
qbufSize(200), qbufSize(200),
lastRemove(false) lastRemove(false)
{ {
db = make_shared<PostgreSQLInterface>();
if( getId() == DefaultObjectId ) if( getId() == DefaultObjectId )
{ {
ostringstream msg; ostringstream msg;
...@@ -34,7 +35,6 @@ DBServer_PostgreSQL::DBServer_PostgreSQL(ObjectId id): ...@@ -34,7 +35,6 @@ DBServer_PostgreSQL::DBServer_PostgreSQL(ObjectId id):
DBServer_PostgreSQL::DBServer_PostgreSQL(): DBServer_PostgreSQL::DBServer_PostgreSQL():
DBServer(uniset_conf()->getDBServer()), DBServer(uniset_conf()->getDBServer()),
db(new PostgreSQLInterface()),
PingTime(300000), PingTime(300000),
ReconnectTime(180000), ReconnectTime(180000),
connect_ok(false), connect_ok(false),
...@@ -42,6 +42,7 @@ DBServer_PostgreSQL::DBServer_PostgreSQL(): ...@@ -42,6 +42,7 @@ DBServer_PostgreSQL::DBServer_PostgreSQL():
qbufSize(200), qbufSize(200),
lastRemove(false) lastRemove(false)
{ {
db = make_shared<PostgreSQLInterface>();
// init(); // init();
if( getId() == DefaultObjectId ) if( getId() == DefaultObjectId )
{ {
...@@ -53,12 +54,8 @@ DBServer_PostgreSQL::DBServer_PostgreSQL(): ...@@ -53,12 +54,8 @@ DBServer_PostgreSQL::DBServer_PostgreSQL():
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
DBServer_PostgreSQL::~DBServer_PostgreSQL() DBServer_PostgreSQL::~DBServer_PostgreSQL()
{ {
if( db != NULL ) if( db )
{
db->freeResult();
db->close(); db->close();
delete db;
}
} }
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
void DBServer_PostgreSQL::sysCommand( const UniSetTypes::SystemMessage* sm ) void DBServer_PostgreSQL::sysCommand( const UniSetTypes::SystemMessage* sm )
...@@ -71,7 +68,6 @@ void DBServer_PostgreSQL::sysCommand( const UniSetTypes::SystemMessage* sm ) ...@@ -71,7 +68,6 @@ void DBServer_PostgreSQL::sysCommand( const UniSetTypes::SystemMessage* sm )
case SystemMessage::Finish: case SystemMessage::Finish:
{ {
activate = false; activate = false;
db->freeResult();
db->close(); db->close();
} }
break; break;
...@@ -103,32 +99,27 @@ void DBServer_PostgreSQL::confirmInfo( const UniSetTypes::ConfirmMessage* cem ) ...@@ -103,32 +99,27 @@ void DBServer_PostgreSQL::confirmInfo( const UniSetTypes::ConfirmMessage* cem )
<< " AND time='" << timeToString(cem->time, ":") <<" '" << " AND time='" << timeToString(cem->time, ":") <<" '"
<< " AND time_usec='" << cem->time_usec <<" '"; << " AND time_usec='" << cem->time_usec <<" '";
if( ulog.debugging(DBLEVEL) ) dblog << myname << "(update_confirm): " << data.str() << endl;
ulog[DBLEVEL] << myname << "(update_confirm): " << data.str() << endl;
if( !writeToBase(data.str()) ) if( !writeToBase(data.str()) )
{ {
if( ulog.debugging(Debug::CRIT) ) ucrit << myname << "(update_confirm): db error: "<< db->error() << endl;
ulog[Debug::CRIT] << myname << "(update_confirm): db error: "<< db->error() << endl;
db->freeResult(); db->freeResult();
} }
} }
catch( Exception& ex ) catch( const Exception& ex )
{ {
if( ulog.debugging(Debug::CRIT) ) ucrit << myname << "(update_confirm): " << ex << endl;
ulog[Debug::CRIT] << myname << "(update_confirm): " << ex << endl;
} }
catch( ... ) catch( ... )
{ {
if( ulog.debugging(Debug::CRIT) ) ucrit << myname << "(update_confirm): catch..." << endl;
ulog[Debug::CRIT] << myname << "(update_confirm): catch..." << endl;
} }
} }
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
bool DBServer_PostgreSQL::writeToBase( const string& query ) bool DBServer_PostgreSQL::writeToBase( const string& query )
{ {
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(writeToBase): " << query << endl;
ulog[DBLogInfoLevel] << myname << "(writeToBase): " << query << endl;
if( !db || !connect_ok ) if( !db || !connect_ok )
{ {
...@@ -143,8 +134,7 @@ bool DBServer_PostgreSQL::writeToBase( const string& query ) ...@@ -143,8 +134,7 @@ bool DBServer_PostgreSQL::writeToBase( const string& query )
qlost = qbuf.front(); qlost = qbuf.front();
qbuf.pop(); qbuf.pop();
if( ulog.debugging(Debug::CRIT) ) ucrit << myname << "(writeToBase): DB not connected! buffer(" << qbufSize
ulog[Debug::CRIT] << myname << "(writeToBase): DB not connected! buffer(" << qbufSize
<< ") overflow! lost query: " << qlost << endl; << ") overflow! lost query: " << qlost << endl;
} }
...@@ -173,12 +163,7 @@ void DBServer_PostgreSQL::flushBuffer() ...@@ -173,12 +163,7 @@ void DBServer_PostgreSQL::flushBuffer()
{ {
if(!db->insertAndSaveRowid( qbuf.front() )) if(!db->insertAndSaveRowid( qbuf.front() ))
{ {
if(ulog.debugging(Debug::CRIT) ) ucrit << myname << "(writeToBase): error: " << db->error() << " lost query: " << qbuf.front() << endl;
{
string err(db->error());
ulog[Debug::CRIT] << myname << "(writeToBase): error: " << err <<
" lost query: " << qbuf.front() << endl;
}
} }
qbuf.pop(); qbuf.pop();
...@@ -210,31 +195,28 @@ void DBServer_PostgreSQL::sensorInfo( const UniSetTypes::SensorMessage *si ) ...@@ -210,31 +195,28 @@ void DBServer_PostgreSQL::sensorInfo( const UniSetTypes::SensorMessage *si )
<< si->value << "," // value << si->value << "," // value
<< si->node << ")"; // node << si->node << ")"; // node
if( ulog.debugging(DBLEVEL) ) dblog << myname << "(insert_main_history): " << data.str() << endl;
ulog[DBLEVEL] << myname << "(insert_main_history): " << data.str() << endl;
if( !writeToBase(data.str()) ) if( !writeToBase(data.str()) )
{ {
if( ulog.debugging(Debug::CRIT) ) ucrit << myname << "(insert) sensor msg error: "<< db->error() << endl;
ulog[Debug::CRIT] << myname << "(insert) sensor msg error: "<< db->error() << endl;
db->freeResult(); db->freeResult();
} }
} }
catch( Exception& ex ) catch( const Exception& ex )
{ {
ulog[Debug::CRIT] << myname << "(insert_main_history): " << ex << endl; ucrit << myname << "(insert_main_history): " << ex << endl;
} }
catch( ... ) catch( ... )
{ {
ulog[Debug::CRIT] << myname << "(insert_main_history): catch ..." << endl; ucrit << myname << "(insert_main_history): catch ..." << endl;
} }
} }
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
void DBServer_PostgreSQL::init_dbserver() void DBServer_PostgreSQL::init_dbserver()
{ {
DBServer::init_dbserver(); DBServer::init_dbserver();
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(init): ..." << endl;
ulog[DBLogInfoLevel] << myname << "(init): ..." << endl;
if( connect_ok ) if( connect_ok )
{ {
...@@ -260,7 +242,7 @@ void DBServer_PostgreSQL::init_dbserver() ...@@ -260,7 +242,7 @@ void DBServer_PostgreSQL::init_dbserver()
UniXML::iterator it(node); UniXML::iterator it(node);
ulog[DBLogInfoLevel] << myname << "(init): init connection.." << endl; dblog << myname << "(init): init connection.." << endl;
string dbname(conf->getProp(node,"dbname")); string dbname(conf->getProp(node,"dbname"));
string dbnode(conf->getProp(node,"dbnode")); string dbnode(conf->getProp(node,"dbnode"));
string user(conf->getProp(node,"dbuser")); string user(conf->getProp(node,"dbuser"));
...@@ -283,27 +265,19 @@ void DBServer_PostgreSQL::init_dbserver() ...@@ -283,27 +265,19 @@ void DBServer_PostgreSQL::init_dbserver()
if( dbnode.empty() ) if( dbnode.empty() )
dbnode = "localhost"; dbnode = "localhost";
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(init): connect dbnode=" << dbnode
ulog[DBLogInfoLevel] << myname << "(init): connect dbnode=" << dbnode
<< "\tdbname=" << dbname << "\tdbname=" << dbname
<< " pingTime=" << PingTime << " pingTime=" << PingTime
<< " ReconnectTime=" << ReconnectTime << endl; << " ReconnectTime=" << ReconnectTime << endl;
if( !db->connect(dbnode, user, password, dbname) ) if( !db->connect(dbnode, user, password, dbname) )
{ {
// ostringstream err; uwarn << myname << "(init): DB connection error: " << db->error() << endl;
if( ulog.debugging(Debug::CRIT) )
ulog[Debug::CRIT] << myname
<< "(init): DB connection error: "
<< db->error() << endl;
// throw Exception( string(myname+"(init): не смогли создать соединение с БД "+db->error()) );
askTimer(DBServer_PostgreSQL::ReconnectTimer,ReconnectTime); askTimer(DBServer_PostgreSQL::ReconnectTimer,ReconnectTime);
} }
else else
{ {
cout<<"DB CONNECT OK"<<endl; dblog << myname << "(init): connect [OK]" << endl;
if( ulog.debugging(DBLogInfoLevel) )
ulog[DBLogInfoLevel] << myname << "(init): connect [OK]" << endl;
connect_ok = true; connect_ok = true;
askTimer(DBServer_PostgreSQL::ReconnectTimer,0); askTimer(DBServer_PostgreSQL::ReconnectTimer,0);
askTimer(DBServer_PostgreSQL::PingTimer,PingTime); askTimer(DBServer_PostgreSQL::PingTimer,PingTime);
...@@ -314,15 +288,14 @@ void DBServer_PostgreSQL::init_dbserver() ...@@ -314,15 +288,14 @@ void DBServer_PostgreSQL::init_dbserver()
} }
} }
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
void DBServer_PostgreSQL::createTables( PostgreSQLInterface *db ) void DBServer_PostgreSQL::createTables( std::shared_ptr<PostgreSQLInterface>& db )
{ {
auto conf = uniset_conf(); auto conf = uniset_conf();
UniXML_iterator it( conf->getNode("Tables") ); UniXML_iterator it( conf->getNode("Tables") );
if(!it) if(!it)
{ {
if( ulog.debugging(Debug::CRIT) ) ucrit << myname << ": section <Tables> not found.."<< endl;
ulog[Debug::CRIT] << myname << ": section <Tables> not found.."<< endl;
throw Exception(); throw Exception();
} }
...@@ -330,12 +303,13 @@ void DBServer_PostgreSQL::createTables( PostgreSQLInterface *db ) ...@@ -330,12 +303,13 @@ void DBServer_PostgreSQL::createTables( PostgreSQLInterface *db )
{ {
if( it.getName() != "comment" ) if( it.getName() != "comment" )
{ {
if( ulog.debugging(DBLogInfoLevel) ) ucrit << myname << "(createTables): create " << it.getName() << endl;
ulog[DBLogInfoLevel] << myname << "(createTables): create " << it.getName() << endl;
ostringstream query; ostringstream query;
query << "CREATE TABLE " << conf->getProp(it,"name") << "(" << conf->getProp(it,"create") << ")"; query << "CREATE TABLE " << conf->getProp(it,"name") << "(" << conf->getProp(it,"create") << ")";
if( !db->query(query.str()) && ulog.debugging(Debug::CRIT) ) if( !db->query(query.str()) )
ulog[Debug::CRIT] << myname << "(createTables): error: \t\t" << db->error() << endl; {
ucrit << myname << "(createTables): error: \t\t" << db->error() << endl;
}
} }
} }
} }
...@@ -348,8 +322,7 @@ void DBServer_PostgreSQL::timerInfo( const UniSetTypes::TimerMessage* tm ) ...@@ -348,8 +322,7 @@ void DBServer_PostgreSQL::timerInfo( const UniSetTypes::TimerMessage* tm )
{ {
if( !db->ping() ) if( !db->ping() )
{ {
if( ulog.debugging(Debug::WARN) ) uwarn << myname << "(timerInfo): DB lost connection.." << endl;
ulog[Debug::WARN] << myname << "(timerInfo): DB lost connection.." << endl;
connect_ok = false; connect_ok = false;
askTimer(DBServer_PostgreSQL::PingTimer,0); askTimer(DBServer_PostgreSQL::PingTimer,0);
askTimer(DBServer_PostgreSQL::ReconnectTimer,ReconnectTime); askTimer(DBServer_PostgreSQL::ReconnectTimer,ReconnectTime);
...@@ -357,16 +330,14 @@ void DBServer_PostgreSQL::timerInfo( const UniSetTypes::TimerMessage* tm ) ...@@ -357,16 +330,14 @@ void DBServer_PostgreSQL::timerInfo( const UniSetTypes::TimerMessage* tm )
else else
{ {
connect_ok = true; connect_ok = true;
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(timerInfo): DB ping ok" << endl;
ulog[DBLogInfoLevel] << myname << "(timerInfo): DB ping ok" << endl;
} }
} }
break; break;
case DBServer_PostgreSQL::ReconnectTimer: case DBServer_PostgreSQL::ReconnectTimer:
{ {
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(timerInfo): reconnect timer" << endl;
ulog[DBLogInfoLevel] << myname << "(timerInfo): reconnect timer" << endl;
if( db->isConnection() ) if( db->isConnection() )
{ {
if( db->ping() ) if( db->ping() )
...@@ -403,3 +374,33 @@ void DBServer_PostgreSQL::sigterm( int signo ) ...@@ -403,3 +374,33 @@ void DBServer_PostgreSQL::sigterm( int signo )
DBServer::sigterm(signo); DBServer::sigterm(signo);
} }
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
std::shared_ptr<DBServer_PostgreSQL> DBServer_PostgreSQL::init_dbserver( int argc, const char* const* argv,
const std::string& prefix )
{
auto conf = uniset_conf();
ObjectId ID = conf->getDBServer();
string name = conf->getArgParam("--" + prefix + "-name","");
if( !name.empty() )
{
ObjectId ID = conf->getObjectID(name);
if( ID == UniSetTypes::DefaultObjectId )
{
ucrit << "(DBServer_PostgreSQL): Unknown ObjectID for '" << name << endl;
return 0;
}
}
uinfo << "(DBServer_PostgreSQL): name = " << name << "(" << ID << ")" << endl;
return make_shared<DBServer_PostgreSQL>(ID,prefix);
}
// -----------------------------------------------------------------------------
void DBServer_PostgreSQL::help_print( int argc, const char* const* argv )
{
auto conf = uniset_conf();
cout << "Default: prefix='pgsql'" << endl;
cout << "--prefix-name objectID - ObjectID. Default: 'conf->getDBServer()'" << endl;
}
// -----------------------------------------------------------------------------
...@@ -11,16 +11,22 @@ class DBServer_PostgreSQL: ...@@ -11,16 +11,22 @@ class DBServer_PostgreSQL:
public DBServer public DBServer
{ {
public: public:
DBServer_PostgreSQL( UniSetTypes::ObjectId id ); DBServer_PostgreSQL( UniSetTypes::ObjectId id, const std::string& prefix );
DBServer_PostgreSQL(); DBServer_PostgreSQL();
~DBServer_PostgreSQL(); virtual ~DBServer_PostgreSQL();
static const Debug::type DBLogInfoLevel = Debug::LEVEL9; static const Debug::type DBLogInfoLevel = Debug::LEVEL9;
/*! глобальная функция для инициализации объекта */
static std::shared_ptr<DBServer_PostgreSQL> init_dbserver( int argc, const char* const* argv, const std::string& prefix="pgsql" );
/*! глобальная функция для вывода help-а */
static void help_print( int argc, const char* const* argv );
protected: protected:
typedef std::map<int, std::string> DBTableMap; typedef std::map<int, std::string> DBTableMap;
virtual void initDB(PostgreSQLInterface *db){}; virtual void initDB( std::shared_ptr<PostgreSQLInterface>& db ){};
virtual void initDBTableMap(DBTableMap& tblMap){}; virtual void initDBTableMap(DBTableMap& tblMap){};
virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override; virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override;
...@@ -31,7 +37,7 @@ class DBServer_PostgreSQL: ...@@ -31,7 +37,7 @@ class DBServer_PostgreSQL:
bool writeToBase( const string& query ); bool writeToBase( const string& query );
virtual void init_dbserver(); virtual void init_dbserver();
void createTables( PostgreSQLInterface* db ); void createTables( std::shared_ptr<PostgreSQLInterface>& db );
inline const char* tblName(int key) inline const char* tblName(int key)
{ {
...@@ -45,7 +51,7 @@ class DBServer_PostgreSQL: ...@@ -45,7 +51,7 @@ class DBServer_PostgreSQL:
lastNumberOfTimer lastNumberOfTimer
}; };
PostgreSQLInterface *db; std::shared_ptr<PostgreSQLInterface> db;
int PingTime; int PingTime;
int ReconnectTime; int ReconnectTime;
bool connect_ok; /*! признак наличия соеднинения с сервером БД */ bool connect_ok; /*! признак наличия соеднинения с сервером БД */
......
...@@ -4,25 +4,25 @@ else ...@@ -4,25 +4,25 @@ else
UPGSQL_VER=@LIBVER@ UPGSQL_VER=@LIBVER@
lib_LTLIBRARIES = libUniSet2-postgresql.la lib_LTLIBRARIES = libUniSet2-pgsql.la
libUniSet2_postgresql_la_LDFLAGS = -version-info $(UPGSQL_VER) libUniSet2_pgsql_la_LDFLAGS = -version-info $(UPGSQL_VER)
libUniSet2_postgresql_la_SOURCES = PostgreSQLInterface.cc DBServer_PostgreSQL.cc libUniSet2_pgsql_la_SOURCES = PostgreSQLInterface.cc DBServer_PostgreSQL.cc
libUniSet2_postgresql_la_LIBADD = $(top_builddir)/lib/libUniSet2.la $(POSTGRESQL_LIBS) libUniSet2_pgsql_la_LIBADD = $(top_builddir)/lib/libUniSet2.la $(PGSQL_LIBS)
libUniSet2_postgresql_la_CXXFLAGS = $(POSTGRESQL_CFLAGS) libUniSet2_pgsql_la_CXXFLAGS = $(PGSQL_CFLAGS)
bin_PROGRAMS = @PACKAGE@-postgresql-dbserver bin_PROGRAMS = @PACKAGE@-pgsql-dbserver
@PACKAGE@_postgresql_dbserver_LDADD = libUniSet2-postgresql.la $(top_builddir)/lib/libUniSet2.la $(POSTGRESQL_LIBS) @PACKAGE@_pgsql_dbserver_LDADD = libUniSet2-pgsql.la $(top_builddir)/lib/libUniSet2.la $(PGSQL_LIBS)
@PACKAGE@_postgresql_dbserver_CXXFLAGS = $(POSTGRESQL_CFLAGS) @PACKAGE@_pgsql_dbserver_CXXFLAGS = $(PGSQL_CFLAGS)
@PACKAGE@_postgresql_dbserver_SOURCES = main.cc @PACKAGE@_pgsql_dbserver_SOURCES = main.cc
noinst_PROGRAMS = postgresql-test noinst_PROGRAMS = pgsql-test
postgresql_test_LDADD = libUniSet2-postgresql.la $(top_builddir)/lib/libUniSet2.la $(POSTGRESQL_LIBS) pgsql_test_LDADD = libUniSet2-pgsql.la $(top_builddir)/lib/libUniSet2.la $(PGSQL_LIBS)
postgresql_test_CXXFLAGS = $(POSTGRESQL_CFLAGS) pgsql_test_CXXFLAGS = $(PGSQL_CFLAGS)
postgresql_test_SOURCES = test.cc pgsql_test_SOURCES = test.cc
# install # install
devel_include_HEADERS = *.h devel_include_HEADERS = *.h
devel_includedir = $(includedir)/@PACKAGE@/postgresql devel_includedir = $(includedir)/@PACKAGE@/pgsql
pkgconfigdir = $(libdir)/pkgconfig pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libUniSet2PostgreSQL.pc pkgconfig_DATA = libUniSet2PostgreSQL.pc
......
...@@ -10,6 +10,7 @@ using namespace UniSetTypes; ...@@ -10,6 +10,7 @@ using namespace UniSetTypes;
PostgreSQLInterface::PostgreSQLInterface(): PostgreSQLInterface::PostgreSQLInterface():
db(0), db(0),
result(0),
lastQ(""), lastQ(""),
lastE(""), lastE(""),
queryok(false), queryok(false),
......
...@@ -7,5 +7,5 @@ Name: libUniSet2PostgreSQL ...@@ -7,5 +7,5 @@ Name: libUniSet2PostgreSQL
Description: Support library for libUniSet2PostgreSQL Description: Support library for libUniSet2PostgreSQL
Requires: libUniSet2 libpq Requires: libUniSet2 libpq
Version: @VERSION@ Version: @VERSION@
Libs: -L${libdir} -lUniSet2-postgresql Libs: -L${libdir} -lUniSet2-pgsql
Cflags: -I${includedir}/@PACKAGE@ -I${includedir}/@PACKAGE@/postgresql Cflags: -I${includedir}/@PACKAGE@ -I${includedir}/@PACKAGE@/pgsql
...@@ -6,63 +6,34 @@ ...@@ -6,63 +6,34 @@
using namespace UniSetTypes; using namespace UniSetTypes;
using namespace std; using namespace std;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
static void short_usage()
{
cout << "Usage: uniset-mysql-dbserver [--name ObjectId] [--confile configure.xml]\n";
}
// --------------------------------------------------------------------------
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
try try
{ {
if( argc > 1 && !strcmp(argv[1],"--help") ) if( argc > 1 && !strcmp(argv[1],"--help") )
{ {
short_usage(); DBServer_PostgreSQL::help_print(argc,argv);
return 0; return 0;
} }
auto conf = uniset_init(argc,argv,"configure.xml"); auto conf = uniset_init(argc,argv,"configure.xml");
ObjectId ID = conf->getDBServer(); auto dbs = DBServer_PostgreSQL::init_dbserver(argc,argv);
auto act = UniSetActivator::Instance();
// определяем ID объекта act->add(dbs);
string name = conf->getArgParam("--name");
if( !name.empty())
{
if( ID != UniSetTypes::DefaultObjectId )
{
ulog.warn() << "(DBServer::main): переопределяем ID заданнй в "
<< conf->getConfFileName() << endl;
}
ID = conf->oind->getIdByName(conf->getServicesSection()+"/"+name);
if( ID == UniSetTypes::DefaultObjectId )
{
cerr << "(DBServer::main): идентификатор '" << name
<< "' не найден в конф. файле!"
<< " в секции " << conf->getServicesSection() << endl;
return 1;
}
}
else if( ID == UniSetTypes::DefaultObjectId )
{
cerr << "(DBServer::main): Не удалось определить ИДЕНТИФИКАТОР сервера" << endl;
short_usage();
return 1;
}
DBServer_PostgreSQL dbs(ID);
UniSetActivatorPtr act = UniSetActivator::Instance();
act->addObject(static_cast<class UniSetObject*>(&dbs));
act->run(false); act->run(false);
} }
catch(Exception& ex) catch( const Exception& ex )
{
cerr << "(DBServer_PosgreSQL::main): " << ex << endl;
}
catch( std::exception& ex )
{ {
cerr << "(DBServer::main): " << ex << endl; cerr << "(DBServer_PosgreSQL::main): " << ex.what() << endl;
} }
catch(...) catch(...)
{ {
cerr << "(DBServer::main): catch ..." << endl; cerr << "(DBServer_PosgreSQL::main): catch ..." << endl;
} }
return 0; return 0;
......
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
ulimit -Sc 1000000 ulimit -Sc 1000000
uniset2-start.sh -f ./uniset2-postgresql-dbserver --confile test.xml --name DBServer1 \ uniset2-start.sh -f ./uniset2-pgsql-dbserver --confile test.xml --name DBServer1 \
--ulog-add-levels info,crit,warn,level9,system \ --ulog-add-levels info,crit,warn,level9,system \
--dbserver-buffer-size 100 --dbserver-buffer-size 100
...@@ -44,7 +44,7 @@ int main(int argc, char** argv) ...@@ -44,7 +44,7 @@ int main(int argc, char** argv)
db.close(); db.close();
} }
catch( Exception& ex ) catch( const Exception& ex )
{ {
cerr << "(test): " << ex << endl; cerr << "(test): " << ex << endl;
} }
......
...@@ -19,6 +19,14 @@ extensions/DBServer-SQLite/SQLiteInterface.cc ...@@ -19,6 +19,14 @@ extensions/DBServer-SQLite/SQLiteInterface.cc
extensions/DBServer-SQLite/SQLiteInterface.h extensions/DBServer-SQLite/SQLiteInterface.h
extensions/DBServer-SQLite/test.cc extensions/DBServer-SQLite/test.cc
extensions/DBServer-SQLite/test.xml extensions/DBServer-SQLite/test.xml
extensions/DBServer-PostgreSQL/DBServer_PostgreSQL.cc
extensions/DBServer-PostgreSQL/DBServer_PostgreSQL.h
extensions/DBServer-PostgreSQL/libUniSet2PostgreSQL.pc.in
extensions/DBServer-PostgreSQL/main.cc
extensions/DBServer-PostgreSQL/Makefile.am
extensions/DBServer-PostgreSQL/PostgreSQLInterface.cc
extensions/DBServer-PostgreSQL/PostgreSQLInterface.h
extensions/DBServer-PostgreSQL/test.cc
extensions/include/Calibration.h extensions/include/Calibration.h
extensions/include/ComediInterface.h extensions/include/ComediInterface.h
extensions/include/DigitalFilter.h extensions/include/DigitalFilter.h
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment