Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
fe521c11
Commit
fe521c11
authored
Apr 04, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(PGSQL): предварительная версия
parent
627ea7d9
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
149 additions
and
143 deletions
+149
-143
libuniset2.spec
conf/libuniset2.spec
+15
-15
configure.ac
configure.ac
+19
-0
DBServer_MySQL.cc
extensions/DBServer-MySQL/DBServer_MySQL.cc
+1
-1
DBServer_PostgreSQL.cc
extensions/DBServer-PostgreSQL/DBServer_PostgreSQL.cc
+64
-63
DBServer_PostgreSQL.h
extensions/DBServer-PostgreSQL/DBServer_PostgreSQL.h
+11
-5
Makefile.am
extensions/DBServer-PostgreSQL/Makefile.am
+16
-16
PostgreSQLInterface.cc
extensions/DBServer-PostgreSQL/PostgreSQLInterface.cc
+1
-0
libUniSet2PostgreSQL.pc.in
extensions/DBServer-PostgreSQL/libUniSet2PostgreSQL.pc.in
+2
-2
main.cc
extensions/DBServer-PostgreSQL/main.cc
+10
-39
start_fg.sh
extensions/DBServer-PostgreSQL/start_fg.sh
+1
-1
test.cc
extensions/DBServer-PostgreSQL/test.cc
+1
-1
uniset2.files
uniset2.files
+8
-0
No files found.
conf/libuniset2.spec
View file @
fe521c11
%def_enable docs
%def_enable mysql
%def_enable sqlite
%def_enable p
ostgre
sql
%def_enable p
g
sql
%def_enable python
%def_enable rrd
%def_enable io
...
...
@@ -43,7 +43,7 @@ BuildRequires: libMySQL-devel
BuildRequires: libsqlite3-devel
%endif
%if_enabled p
ostgre
sql
%if_enabled p
g
sql
BuildRequires: postgresql9.3-devel libpq5.6-devel
%endif
...
...
@@ -180,21 +180,21 @@ Requires: %name-extension-common = %version-%release
Libraries needed to develop for uniset SQLite
%endif
%if_enabled p
ostgre
sql
%package extension-p
ostgre
sql
%if_enabled p
g
sql
%package extension-p
g
sql
Group: Development/Databases
Summary: PostgreSQL-dbserver implementatioin for UniSet
Requires: %name-extension-common = %version-%release
%description extension-p
ostgre
sql
%description extension-p
g
sql
PostgreSQL dbserver for %name
%package extension-p
ostgre
sql-devel
%package extension-p
g
sql-devel
Group: Development/Databases
Summary: Libraries needed to develop for uniset PostgreSQL
Requires: %name-extension-common-devel = %version-%release
%description extension-p
ostgre
sql-devel
%description extension-p
g
sql-devel
Libraries needed to develop for uniset PostgreSQL
%endif
...
...
@@ -264,7 +264,7 @@ SharedMemoryPlus extension ('all in one') for libuniset
%build
%autoreconf
%configure %{subst_enable doc} %{subst_enable mysql} %{subst_enable sqlite} %{subst_enable p
ostgre
sql} %{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 p
g
sql} %{subst_enable python} %{subst_enable rrd} %{subst_enable io} %{subst_enable logicproc} %{subst_enable tests}
%make
%install
...
...
@@ -315,8 +315,8 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
%if_enabled sqlite
%_includedir/%oname/sqlite/
%endif
%if_enabled p
ostgre
sql
%_includedir/%oname/p
ostgre
sql/
%if_enabled p
g
sql
%_includedir/%oname/p
g
sql/
%endif
%_libdir/libUniSet2.so
...
...
@@ -341,12 +341,12 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
%_pkgconfigdir/libUniSet2SQLite.pc
%endif
%if_enabled p
ostgre
sql
%files extension-p
ostgre
sql
%_bindir/%oname-p
ostgre
sql-*dbserver
%_libdir/*-p
ostgre
sql.so*
%if_enabled p
g
sql
%files extension-p
g
sql
%_bindir/%oname-p
g
sql-*dbserver
%_libdir/*-p
g
sql.so*
%files extension-p
ostgre
sql-devel
%files extension-p
g
sql-devel
%_pkgconfigdir/libUniSet2PostgreSQL.pc
%endif
...
...
configure.ac
View file @
fe521c11
...
...
@@ -81,6 +81,23 @@ fi
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
AC_MSG_CHECKING([rrd support])
...
...
@@ -330,6 +347,8 @@ AC_CONFIG_FILES([Makefile
extensions/DBServer-MySQL/libUniSet2MySQL.pc
extensions/DBServer-SQLite/Makefile
extensions/DBServer-SQLite/libUniSet2SQLite.pc
extensions/DBServer-PostgreSQL/Makefile
extensions/DBServer-PostgreSQL/libUniSet2PostgreSQL.pc
extensions/IOControl/Makefile
extensions/IOControl/libUniSet2IOControl.pc
extensions/ModbusMaster/Makefile
...
...
extensions/DBServer-MySQL/DBServer_MySQL.cc
View file @
fe521c11
...
...
@@ -36,7 +36,7 @@
using
namespace
UniSetTypes
;
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
(
id
),
...
...
extensions/DBServer-PostgreSQL/DBServer_PostgreSQL.cc
View file @
fe521c11
...
...
@@ -12,11 +12,10 @@
using
namespace
UniSetTypes
;
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
),
db
(
new
PostgreSQLInterface
()),
PingTime
(
300000
),
ReconnectTime
(
180000
),
connect_ok
(
false
),
...
...
@@ -24,6 +23,8 @@ DBServer_PostgreSQL::DBServer_PostgreSQL(ObjectId id):
qbufSize
(
200
),
lastRemove
(
false
)
{
db
=
make_shared
<
PostgreSQLInterface
>
();
if
(
getId
()
==
DefaultObjectId
)
{
ostringstream
msg
;
...
...
@@ -34,7 +35,6 @@ DBServer_PostgreSQL::DBServer_PostgreSQL(ObjectId id):
DBServer_PostgreSQL
::
DBServer_PostgreSQL
()
:
DBServer
(
uniset_conf
()
->
getDBServer
()),
db
(
new
PostgreSQLInterface
()),
PingTime
(
300000
),
ReconnectTime
(
180000
),
connect_ok
(
false
),
...
...
@@ -42,6 +42,7 @@ DBServer_PostgreSQL::DBServer_PostgreSQL():
qbufSize
(
200
),
lastRemove
(
false
)
{
db
=
make_shared
<
PostgreSQLInterface
>
();
// init();
if
(
getId
()
==
DefaultObjectId
)
{
...
...
@@ -53,12 +54,8 @@ DBServer_PostgreSQL::DBServer_PostgreSQL():
//--------------------------------------------------------------------------------------------
DBServer_PostgreSQL
::~
DBServer_PostgreSQL
()
{
if
(
db
!=
NULL
)
{
db
->
freeResult
();
if
(
db
)
db
->
close
();
delete
db
;
}
}
//--------------------------------------------------------------------------------------------
void
DBServer_PostgreSQL
::
sysCommand
(
const
UniSetTypes
::
SystemMessage
*
sm
)
...
...
@@ -71,7 +68,6 @@ void DBServer_PostgreSQL::sysCommand( const UniSetTypes::SystemMessage* sm )
case
SystemMessage
:
:
Finish
:
{
activate
=
false
;
db
->
freeResult
();
db
->
close
();
}
break
;
...
...
@@ -103,32 +99,27 @@ void DBServer_PostgreSQL::confirmInfo( const UniSetTypes::ConfirmMessage* cem )
<<
" AND time='"
<<
timeToString
(
cem
->
time
,
":"
)
<<
" '"
<<
" AND time_usec='"
<<
cem
->
time_usec
<<
" '"
;
if
(
ulog
.
debugging
(
DBLEVEL
)
)
ulog
[
DBLEVEL
]
<<
myname
<<
"(update_confirm): "
<<
data
.
str
()
<<
endl
;
dblog
<<
myname
<<
"(update_confirm): "
<<
data
.
str
()
<<
endl
;
if
(
!
writeToBase
(
data
.
str
())
)
{
if
(
ulog
.
debugging
(
Debug
::
CRIT
)
)
ulog
[
Debug
::
CRIT
]
<<
myname
<<
"(update_confirm): db error: "
<<
db
->
error
()
<<
endl
;
ucrit
<<
myname
<<
"(update_confirm): db error: "
<<
db
->
error
()
<<
endl
;
db
->
freeResult
();
}
}
catch
(
Exception
&
ex
)
catch
(
const
Exception
&
ex
)
{
if
(
ulog
.
debugging
(
Debug
::
CRIT
)
)
ulog
[
Debug
::
CRIT
]
<<
myname
<<
"(update_confirm): "
<<
ex
<<
endl
;
ucrit
<<
myname
<<
"(update_confirm): "
<<
ex
<<
endl
;
}
catch
(
...
)
{
if
(
ulog
.
debugging
(
Debug
::
CRIT
)
)
ulog
[
Debug
::
CRIT
]
<<
myname
<<
"(update_confirm): catch..."
<<
endl
;
ucrit
<<
myname
<<
"(update_confirm): catch..."
<<
endl
;
}
}
//--------------------------------------------------------------------------------------------
bool
DBServer_PostgreSQL
::
writeToBase
(
const
string
&
query
)
{
if
(
ulog
.
debugging
(
DBLogInfoLevel
)
)
ulog
[
DBLogInfoLevel
]
<<
myname
<<
"(writeToBase): "
<<
query
<<
endl
;
dblog
<<
myname
<<
"(writeToBase): "
<<
query
<<
endl
;
if
(
!
db
||
!
connect_ok
)
{
...
...
@@ -143,8 +134,7 @@ bool DBServer_PostgreSQL::writeToBase( const string& query )
qlost
=
qbuf
.
front
();
qbuf
.
pop
();
if
(
ulog
.
debugging
(
Debug
::
CRIT
)
)
ulog
[
Debug
::
CRIT
]
<<
myname
<<
"(writeToBase): DB not connected! buffer("
<<
qbufSize
ucrit
<<
myname
<<
"(writeToBase): DB not connected! buffer("
<<
qbufSize
<<
") overflow! lost query: "
<<
qlost
<<
endl
;
}
...
...
@@ -173,12 +163,7 @@ void DBServer_PostgreSQL::flushBuffer()
{
if
(
!
db
->
insertAndSaveRowid
(
qbuf
.
front
()
))
{
if
(
ulog
.
debugging
(
Debug
::
CRIT
)
)
{
string
err
(
db
->
error
());
ulog
[
Debug
::
CRIT
]
<<
myname
<<
"(writeToBase): error: "
<<
err
<<
" lost query: "
<<
qbuf
.
front
()
<<
endl
;
}
ucrit
<<
myname
<<
"(writeToBase): error: "
<<
db
->
error
()
<<
" lost query: "
<<
qbuf
.
front
()
<<
endl
;
}
qbuf
.
pop
();
...
...
@@ -210,31 +195,28 @@ void DBServer_PostgreSQL::sensorInfo( const UniSetTypes::SensorMessage *si )
<<
si
->
value
<<
","
// value
<<
si
->
node
<<
")"
;
// node
if
(
ulog
.
debugging
(
DBLEVEL
)
)
ulog
[
DBLEVEL
]
<<
myname
<<
"(insert_main_history): "
<<
data
.
str
()
<<
endl
;
dblog
<<
myname
<<
"(insert_main_history): "
<<
data
.
str
()
<<
endl
;
if
(
!
writeToBase
(
data
.
str
())
)
{
if
(
ulog
.
debugging
(
Debug
::
CRIT
)
)
ulog
[
Debug
::
CRIT
]
<<
myname
<<
"(insert) sensor msg error: "
<<
db
->
error
()
<<
endl
;
ucrit
<<
myname
<<
"(insert) sensor msg error: "
<<
db
->
error
()
<<
endl
;
db
->
freeResult
();
}
}
catch
(
Exception
&
ex
)
catch
(
const
Exception
&
ex
)
{
u
log
[
Debug
::
CRIT
]
<<
myname
<<
"(insert_main_history): "
<<
ex
<<
endl
;
u
crit
<<
myname
<<
"(insert_main_history): "
<<
ex
<<
endl
;
}
catch
(
...
)
{
u
log
[
Debug
::
CRIT
]
<<
myname
<<
"(insert_main_history): catch ..."
<<
endl
;
u
crit
<<
myname
<<
"(insert_main_history): catch ..."
<<
endl
;
}
}
//--------------------------------------------------------------------------------------------
void
DBServer_PostgreSQL
::
init_dbserver
()
{
DBServer
::
init_dbserver
();
if
(
ulog
.
debugging
(
DBLogInfoLevel
)
)
ulog
[
DBLogInfoLevel
]
<<
myname
<<
"(init): ..."
<<
endl
;
dblog
<<
myname
<<
"(init): ..."
<<
endl
;
if
(
connect_ok
)
{
...
...
@@ -260,7 +242,7 @@ void DBServer_PostgreSQL::init_dbserver()
UniXML
::
iterator
it
(
node
);
ulog
[
DBLogInfoLevel
]
<<
myname
<<
"(init): init connection.."
<<
endl
;
dblog
<<
myname
<<
"(init): init connection.."
<<
endl
;
string
dbname
(
conf
->
getProp
(
node
,
"dbname"
));
string
dbnode
(
conf
->
getProp
(
node
,
"dbnode"
));
string
user
(
conf
->
getProp
(
node
,
"dbuser"
));
...
...
@@ -283,27 +265,19 @@ void DBServer_PostgreSQL::init_dbserver()
if
(
dbnode
.
empty
()
)
dbnode
=
"localhost"
;
if
(
ulog
.
debugging
(
DBLogInfoLevel
)
)
ulog
[
DBLogInfoLevel
]
<<
myname
<<
"(init): connect dbnode="
<<
dbnode
dblog
<<
myname
<<
"(init): connect dbnode="
<<
dbnode
<<
"
\t
dbname="
<<
dbname
<<
" pingTime="
<<
PingTime
<<
" ReconnectTime="
<<
ReconnectTime
<<
endl
;
if
(
!
db
->
connect
(
dbnode
,
user
,
password
,
dbname
)
)
{
// ostringstream err;
if
(
ulog
.
debugging
(
Debug
::
CRIT
)
)
ulog
[
Debug
::
CRIT
]
<<
myname
<<
"(init): DB connection error: "
<<
db
->
error
()
<<
endl
;
// throw Exception( string(myname+"(init): не смогли создать соединение с БД "+db->error()) );
uwarn
<<
myname
<<
"(init): DB connection error: "
<<
db
->
error
()
<<
endl
;
askTimer
(
DBServer_PostgreSQL
::
ReconnectTimer
,
ReconnectTime
);
}
else
{
cout
<<
"DB CONNECT OK"
<<
endl
;
if
(
ulog
.
debugging
(
DBLogInfoLevel
)
)
ulog
[
DBLogInfoLevel
]
<<
myname
<<
"(init): connect [OK]"
<<
endl
;
dblog
<<
myname
<<
"(init): connect [OK]"
<<
endl
;
connect_ok
=
true
;
askTimer
(
DBServer_PostgreSQL
::
ReconnectTimer
,
0
);
askTimer
(
DBServer_PostgreSQL
::
PingTimer
,
PingTime
);
...
...
@@ -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
();
UniXML_iterator
it
(
conf
->
getNode
(
"Tables"
)
);
if
(
!
it
)
{
if
(
ulog
.
debugging
(
Debug
::
CRIT
)
)
ulog
[
Debug
::
CRIT
]
<<
myname
<<
": section <Tables> not found.."
<<
endl
;
ucrit
<<
myname
<<
": section <Tables> not found.."
<<
endl
;
throw
Exception
();
}
...
...
@@ -330,12 +303,13 @@ void DBServer_PostgreSQL::createTables( PostgreSQLInterface *db )
{
if
(
it
.
getName
()
!=
"comment"
)
{
if
(
ulog
.
debugging
(
DBLogInfoLevel
)
)
ulog
[
DBLogInfoLevel
]
<<
myname
<<
"(createTables): create "
<<
it
.
getName
()
<<
endl
;
ucrit
<<
myname
<<
"(createTables): create "
<<
it
.
getName
()
<<
endl
;
ostringstream
query
;
query
<<
"CREATE TABLE "
<<
conf
->
getProp
(
it
,
"name"
)
<<
"("
<<
conf
->
getProp
(
it
,
"create"
)
<<
")"
;
if
(
!
db
->
query
(
query
.
str
())
&&
ulog
.
debugging
(
Debug
::
CRIT
)
)
ulog
[
Debug
::
CRIT
]
<<
myname
<<
"(createTables): error:
\t\t
"
<<
db
->
error
()
<<
endl
;
if
(
!
db
->
query
(
query
.
str
())
)
{
ucrit
<<
myname
<<
"(createTables): error:
\t\t
"
<<
db
->
error
()
<<
endl
;
}
}
}
}
...
...
@@ -348,8 +322,7 @@ void DBServer_PostgreSQL::timerInfo( const UniSetTypes::TimerMessage* tm )
{
if
(
!
db
->
ping
()
)
{
if
(
ulog
.
debugging
(
Debug
::
WARN
)
)
ulog
[
Debug
::
WARN
]
<<
myname
<<
"(timerInfo): DB lost connection.."
<<
endl
;
uwarn
<<
myname
<<
"(timerInfo): DB lost connection.."
<<
endl
;
connect_ok
=
false
;
askTimer
(
DBServer_PostgreSQL
::
PingTimer
,
0
);
askTimer
(
DBServer_PostgreSQL
::
ReconnectTimer
,
ReconnectTime
);
...
...
@@ -357,16 +330,14 @@ void DBServer_PostgreSQL::timerInfo( const UniSetTypes::TimerMessage* tm )
else
{
connect_ok
=
true
;
if
(
ulog
.
debugging
(
DBLogInfoLevel
)
)
ulog
[
DBLogInfoLevel
]
<<
myname
<<
"(timerInfo): DB ping ok"
<<
endl
;
dblog
<<
myname
<<
"(timerInfo): DB ping ok"
<<
endl
;
}
}
break
;
case
DBServer_PostgreSQL
:
:
ReconnectTimer
:
{
if
(
ulog
.
debugging
(
DBLogInfoLevel
)
)
ulog
[
DBLogInfoLevel
]
<<
myname
<<
"(timerInfo): reconnect timer"
<<
endl
;
dblog
<<
myname
<<
"(timerInfo): reconnect timer"
<<
endl
;
if
(
db
->
isConnection
()
)
{
if
(
db
->
ping
()
)
...
...
@@ -403,3 +374,33 @@ void DBServer_PostgreSQL::sigterm( int 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
;
}
// -----------------------------------------------------------------------------
extensions/DBServer-PostgreSQL/DBServer_PostgreSQL.h
View file @
fe521c11
...
...
@@ -11,16 +11,22 @@ class DBServer_PostgreSQL:
public
DBServer
{
public
:
DBServer_PostgreSQL
(
UniSetTypes
::
ObjectId
id
);
DBServer_PostgreSQL
(
UniSetTypes
::
ObjectId
id
,
const
std
::
string
&
prefix
);
DBServer_PostgreSQL
();
~
DBServer_PostgreSQL
();
virtual
~
DBServer_PostgreSQL
();
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
:
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
timerInfo
(
const
UniSetTypes
::
TimerMessage
*
tm
)
override
;
...
...
@@ -31,7 +37,7 @@ class DBServer_PostgreSQL:
bool
writeToBase
(
const
string
&
query
);
virtual
void
init_dbserver
();
void
createTables
(
PostgreSQLInterface
*
db
);
void
createTables
(
std
::
shared_ptr
<
PostgreSQLInterface
>&
db
);
inline
const
char
*
tblName
(
int
key
)
{
...
...
@@ -45,7 +51,7 @@ class DBServer_PostgreSQL:
lastNumberOfTimer
};
PostgreSQLInterface
*
db
;
std
::
shared_ptr
<
PostgreSQLInterface
>
db
;
int
PingTime
;
int
ReconnectTime
;
bool
connect_ok
;
/*! признак наличия соеднинения с сервером БД */
...
...
extensions/DBServer-PostgreSQL/Makefile.am
View file @
fe521c11
...
...
@@ -4,25 +4,25 @@ else
UPGSQL_VER
=
@LIBVER@
lib_LTLIBRARIES
=
libUniSet2-p
ostgre
sql.la
libUniSet2_p
ostgre
sql_la_LDFLAGS
=
-version-info
$(UPGSQL_VER)
libUniSet2_p
ostgre
sql_la_SOURCES
=
PostgreSQLInterface.cc DBServer_PostgreSQL.cc
libUniSet2_p
ostgresql_la_LIBADD
=
$(top_builddir)
/lib/libUniSet2.la
$(POSTGRE
SQL_LIBS)
libUniSet2_p
ostgresql_la_CXXFLAGS
=
$(POSTGRE
SQL_CFLAGS)
bin_PROGRAMS
=
@PACKAGE@-p
ostgre
sql-dbserver
@PACKAGE@
_p
ostgresql_dbserver_LDADD
=
libUniSet2-postgresql.la
$(top_builddir)
/lib/libUniSet2.la
$(POSTGRE
SQL_LIBS)
@PACKAGE@
_p
ostgresql_dbserver_CXXFLAGS
=
$(POSTGRE
SQL_CFLAGS)
@PACKAGE@
_p
ostgre
sql_dbserver_SOURCES
=
main.cc
noinst_PROGRAMS
=
p
ostgre
sql-test
p
ostgresql_test_LDADD
=
libUniSet2-postgresql.la
$(top_builddir)
/lib/libUniSet2.la
$(POSTGRE
SQL_LIBS)
p
ostgresql_test_CXXFLAGS
=
$(POSTGRE
SQL_CFLAGS)
p
ostgre
sql_test_SOURCES
=
test.cc
lib_LTLIBRARIES
=
libUniSet2-p
g
sql.la
libUniSet2_p
g
sql_la_LDFLAGS
=
-version-info
$(UPGSQL_VER)
libUniSet2_p
g
sql_la_SOURCES
=
PostgreSQLInterface.cc DBServer_PostgreSQL.cc
libUniSet2_p
gsql_la_LIBADD
=
$(top_builddir)
/lib/libUniSet2.la
$(PG
SQL_LIBS)
libUniSet2_p
gsql_la_CXXFLAGS
=
$(PG
SQL_CFLAGS)
bin_PROGRAMS
=
@PACKAGE@-p
g
sql-dbserver
@PACKAGE@
_p
gsql_dbserver_LDADD
=
libUniSet2-pgsql.la
$(top_builddir)
/lib/libUniSet2.la
$(PG
SQL_LIBS)
@PACKAGE@
_p
gsql_dbserver_CXXFLAGS
=
$(PG
SQL_CFLAGS)
@PACKAGE@
_p
g
sql_dbserver_SOURCES
=
main.cc
noinst_PROGRAMS
=
p
g
sql-test
p
gsql_test_LDADD
=
libUniSet2-pgsql.la
$(top_builddir)
/lib/libUniSet2.la
$(PG
SQL_LIBS)
p
gsql_test_CXXFLAGS
=
$(PG
SQL_CFLAGS)
p
g
sql_test_SOURCES
=
test.cc
# install
devel_include_HEADERS
=
*
.h
devel_includedir
=
$(includedir)
/@PACKAGE@/p
ostgre
sql
devel_includedir
=
$(includedir)
/@PACKAGE@/p
g
sql
pkgconfigdir
=
$(libdir)
/pkgconfig
pkgconfig_DATA
=
libUniSet2PostgreSQL.pc
...
...
extensions/DBServer-PostgreSQL/PostgreSQLInterface.cc
View file @
fe521c11
...
...
@@ -10,6 +10,7 @@ using namespace UniSetTypes;
PostgreSQLInterface
::
PostgreSQLInterface
()
:
db
(
0
),
result
(
0
),
lastQ
(
""
),
lastE
(
""
),
queryok
(
false
),
...
...
extensions/DBServer-PostgreSQL/libUniSet2PostgreSQL.pc.in
View file @
fe521c11
...
...
@@ -7,5 +7,5 @@ Name: libUniSet2PostgreSQL
Description: Support library for libUniSet2PostgreSQL
Requires: libUniSet2 libpq
Version: @VERSION@
Libs: -L${libdir} -lUniSet2-p
ostgre
sql
Cflags: -I${includedir}/@PACKAGE@ -I${includedir}/@PACKAGE@/p
ostgre
sql
Libs: -L${libdir} -lUniSet2-p
g
sql
Cflags: -I${includedir}/@PACKAGE@ -I${includedir}/@PACKAGE@/p
g
sql
extensions/DBServer-PostgreSQL/main.cc
View file @
fe521c11
...
...
@@ -6,63 +6,34 @@
using
namespace
UniSetTypes
;
using
namespace
std
;
// --------------------------------------------------------------------------
static
void
short_usage
()
{
cout
<<
"Usage: uniset-mysql-dbserver [--name ObjectId] [--confile configure.xml]
\n
"
;
}
// --------------------------------------------------------------------------
int
main
(
int
argc
,
char
**
argv
)
{
try
{
if
(
argc
>
1
&&
!
strcmp
(
argv
[
1
],
"--help"
)
)
{
short_usage
(
);
DBServer_PostgreSQL
::
help_print
(
argc
,
argv
);
return
0
;
}
auto
conf
=
uniset_init
(
argc
,
argv
,
"configure.xml"
);
ObjectId
ID
=
conf
->
getDBServer
();
// определяем ID объекта
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
;
}
auto
dbs
=
DBServer_PostgreSQL
::
init_dbserver
(
argc
,
argv
);
auto
act
=
UniSetActivator
::
Instance
();
act
->
add
(
dbs
);
act
->
run
(
false
);
}
else
if
(
ID
==
UniSetTypes
::
DefaultObjectId
)
catch
(
const
Exception
&
ex
)
{
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
);
cerr
<<
"(DBServer_PosgreSQL::main): "
<<
ex
<<
endl
;
}
catch
(
Exception
&
ex
)
catch
(
std
::
exception
&
ex
)
{
cerr
<<
"(DBServer
::main): "
<<
ex
<<
endl
;
cerr
<<
"(DBServer
_PosgreSQL::main): "
<<
ex
.
what
()
<<
endl
;
}
catch
(...)
{
cerr
<<
"(DBServer::main): catch ..."
<<
endl
;
cerr
<<
"(DBServer
_PosgreSQL
::main): catch ..."
<<
endl
;
}
return
0
;
...
...
extensions/DBServer-PostgreSQL/start_fg.sh
View file @
fe521c11
...
...
@@ -2,6 +2,6 @@
ulimit
-Sc
1000000
uniset2-start.sh
-f
./uniset2-p
ostgre
sql-dbserver
--confile
test.xml
--name
DBServer1
\
uniset2-start.sh
-f
./uniset2-p
g
sql-dbserver
--confile
test.xml
--name
DBServer1
\
--ulog-add-levels
info,crit,warn,level9,system
\
--dbserver-buffer-size
100
extensions/DBServer-PostgreSQL/test.cc
View file @
fe521c11
...
...
@@ -44,7 +44,7 @@ int main(int argc, char** argv)
db
.
close
();
}
catch
(
Exception
&
ex
)
catch
(
const
Exception
&
ex
)
{
cerr
<<
"(test): "
<<
ex
<<
endl
;
}
...
...
uniset2.files
View file @
fe521c11
...
...
@@ -19,6 +19,14 @@ extensions/DBServer-SQLite/SQLiteInterface.cc
extensions/DBServer-SQLite/SQLiteInterface.h
extensions/DBServer-SQLite/test.cc
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/ComediInterface.h
extensions/include/DigitalFilter.h
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment