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
aae6b3f4
Commit
aae6b3f4
authored
Sep 27, 2021
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
supported c++17 (require c++17)
parent
5fad4d4c
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
61 additions
and
34 deletions
+61
-34
README.md
README.md
+2
-1
libuniset2.spec
conf/libuniset2.spec
+1
-1
configure.ac
configure.ac
+1
-1
DBServer_PostgreSQL.cc
extensions/DBServer-PostgreSQL/DBServer_PostgreSQL.cc
+1
-1
DBServer_PostgreSQL.h
extensions/DBServer-PostgreSQL/DBServer_PostgreSQL.h
+3
-2
Makefile.am
extensions/DBServer-PostgreSQL/Makefile.am
+12
-12
PostgreSQLInterface.cc
extensions/DBServer-PostgreSQL/PostgreSQLInterface.cc
+10
-13
PostgreSQLInterface.h
extensions/DBServer-PostgreSQL/PostgreSQLInterface.h
+2
-1
libUniSet2PostgreSQL.pc.in
extensions/DBServer-PostgreSQL/libUniSet2PostgreSQL.pc.in
+1
-1
test.cc
extensions/DBServer-PostgreSQL/test.cc
+1
-1
docker-compose.yml
extensions/DBServer-PostgreSQL/tests/docker-compose.yml
+17
-0
db_create_example.sql
...ostgreSQL/tests/entrypoint-initdb.d/db_create_example.sql
+10
-0
No files found.
README.md
View file @
aae6b3f4
...
...
@@ -23,7 +23,8 @@ with open source third-party libraries. UniSet provides the consistent interface
add-on components and third-party libraries. Python wrapper helps in using the library
in python scripts.
libuniset requires minimum C++11
libuniset requires minimum C++11 (without pqxx support)
libuniset requires C++17 for pqxx support
More information:
*
[
RU
]
https://habr.com/post/278535/
...
...
conf/libuniset2.spec
View file @
aae6b3f4
...
...
@@ -63,7 +63,7 @@ BuildRequires: libsqlite3-devel
%endif
%if_enabled pgsql
BuildRequires: libpqxx-devel
BuildRequires: libpqxx-devel
>= 7.6.0
%endif
%if_enabled rrd
...
...
configure.ac
View file @
aae6b3f4
...
...
@@ -485,7 +485,7 @@ CXX_EXTRA_FLAGS="-Wnon-virtual-dtor -Woverloaded-virtual -Woverflow -D_GLIBCXX_U
# export
LDFLAGS="$LDFLAGS ${OMNI_LIBS} ${XML_LIBS} ${SIGC_LIBS} ${COV_LIBS} ${POCO_LIBS} ${EV_LIBS}"
# all developer liked options add to autogen.sh, please
CXXFLAGS="-I\$(top_builddir)/include $CXXFLAGS -funsigned-char -g -DCATCH_VERSION_MAJOR=${CATCH_VERSION_MAJOR} -D_GNU_SOURCE ${REST_API_CFLAGS} ${COMPORT_485F_CFLAGS} ${OMNI_CFLAGS} ${XML_CFLAGS} ${SIGC_CFLAGS} ${COV_CFLAGS} ${POCO_CFLAGS} ${EV_CFLAGS} $CXX_EXTRA_FLAGS"
CXXFLAGS="-
std=c++17 -
I\$(top_builddir)/include $CXXFLAGS -funsigned-char -g -DCATCH_VERSION_MAJOR=${CATCH_VERSION_MAJOR} -D_GNU_SOURCE ${REST_API_CFLAGS} ${COMPORT_485F_CFLAGS} ${OMNI_CFLAGS} ${XML_CFLAGS} ${SIGC_CFLAGS} ${COV_CFLAGS} ${POCO_CFLAGS} ${EV_CFLAGS} $CXX_EXTRA_FLAGS"
AC_SUBST(LDFLAGS)
AC_SUBST(CXXFLAGS)
...
...
extensions/DBServer-PostgreSQL/DBServer_PostgreSQL.cc
View file @
aae6b3f4
...
...
@@ -271,7 +271,7 @@ void DBServer_PostgreSQL::addRecord( const PostgreSQLInterface::Record&& rec )
}
//--------------------------------------------------------------------------------------------
bool
DBServer_PostgreSQL
::
writeInsertBufferToDB
(
const
std
::
string
&
tableName
,
const
std
::
vector
<
std
::
string
>&
colNames
,
const
std
::
initializer_list
<
std
::
string_view
>
colNames
,
const
InsertBuffer
&
wbuf
)
{
return
db
->
copy
(
tableName
,
colNames
,
wbuf
);
...
...
extensions/DBServer-PostgreSQL/DBServer_PostgreSQL.h
View file @
aae6b3f4
...
...
@@ -17,6 +17,7 @@
#ifndef DBServer_PostgreSQL_H_
#define DBServer_PostgreSQL_H_
// --------------------------------------------------------------------------
#include <string_view>
#include <unordered_map>
#include <queue>
#include "UniSetTypes.h"
...
...
@@ -113,13 +114,13 @@ namespace uniset
void
flushBuffer
();
// writeBuffer
const
std
::
vector
<
std
::
string
>
tblcols
=
{
"date"
,
"time"
,
"time_usec"
,
"sensor_id"
,
"value"
,
"node"
};
const
std
::
initializer_list
<
std
::
string_view
>
tblcols
=
{
"date"
,
"time"
,
"time_usec"
,
"sensor_id"
,
"value"
,
"node"
};
typedef
std
::
vector
<
PostgreSQLInterface
::
Record
>
InsertBuffer
;
void
flushInsertBuffer
();
virtual
void
addRecord
(
const
PostgreSQLInterface
::
Record
&&
rec
);
virtual
bool
writeInsertBufferToDB
(
const
std
::
string
&
table
,
const
std
::
vector
<
std
::
string
>&
colname
,
const
std
::
initializer_list
<
std
::
string_view
>
colname
,
const
InsertBuffer
&
ibuf
);
private
:
...
...
extensions/DBServer-PostgreSQL/Makefile.am
View file @
aae6b3f4
if
ENABLE_PGSQL
UPGSQL_VER
=
@LIBVER@
lib_LTLIBRARIES
=
libUniSet2-pgsql.la
lib_LTLIBRARIES
=
libUniSet2-pgsql.la
libUniSet2_pgsql_la_LDFLAGS
=
-version-info
$(UPGSQL_VER)
libUniSet2_pgsql_la_SOURCES
=
PostgreSQLInterface.cc DBServer_PostgreSQL.cc
libUniSet2_pgsql_la_LIBADD
=
$(top_builddir)
/lib/libUniSet2.la
$(PGSQL_LIBS)
libUniSet2_pgsql_la_CXXFLAGS
=
-std
=
c++11
$(PGSQL_CFLAGS)
libUniSet2_pgsql_la_SOURCES
=
PostgreSQLInterface.cc DBServer_PostgreSQL.cc
libUniSet2_pgsql_la_LIBADD
=
$(top_builddir)
/lib/libUniSet2.la
$(PGSQL_LIBS)
libUniSet2_pgsql_la_CXXFLAGS
=
$(PGSQL_CFLAGS)
bin_PROGRAMS
=
@PACKAGE@-pgsql-dbserver
@PACKAGE@
_pgsql_dbserver_LDADD
=
libUniSet2-pgsql.la
$(top_builddir)
/lib/libUniSet2.la
$(PGSQL_LIBS)
@PACKAGE@
_pgsql_dbserver_CXXFLAGS
=
-std
=
c++11
$(PGSQL_CFLAGS)
@PACKAGE@
_pgsql_dbserver_SOURCES
=
main.cc
bin_PROGRAMS
=
@PACKAGE@-pgsql-dbserver
@PACKAGE@
_pgsql_dbserver_LDADD
=
libUniSet2-pgsql.la
$(top_builddir)
/lib/libUniSet2.la
$(PGSQL_LIBS)
@PACKAGE@
_pgsql_dbserver_CXXFLAGS
=
$(PGSQL_CFLAGS)
@PACKAGE@
_pgsql_dbserver_SOURCES
=
main.cc
noinst_PROGRAMS
=
pgsql-test
pgsql_test_LDADD
=
libUniSet2-pgsql.la
$(top_builddir)
/lib/libUniSet2.la
$(PGSQL_LIBS)
pgsql_test_CXXFLAGS
=
-std
=
c++11
$(PGSQL_CFLAGS)
pgsql_test_SOURCES
=
test.cc
noinst_PROGRAMS
=
pgsql-test
pgsql_test_LDADD
=
libUniSet2-pgsql.la
$(top_builddir)
/lib/libUniSet2.la
$(PGSQL_LIBS)
pgsql_test_CXXFLAGS
=
$(PGSQL_CFLAGS)
pgsql_test_SOURCES
=
test.cc
# install
devel_include_HEADERS
=
*
.h
...
...
extensions/DBServer-PostgreSQL/PostgreSQLInterface.cc
View file @
aae6b3f4
...
...
@@ -54,7 +54,7 @@ bool PostgreSQLInterface::ping() const
try
{
// pqxx doesn't work with unique_ptr (
nontransaction
n
(
*
(
db
.
get
()))
;
nontransaction
n
{
*
(
db
.
get
())}
;
n
.
exec
(
"select 1;"
);
return
true
;
}
...
...
@@ -105,14 +105,14 @@ bool PostgreSQLInterface::close()
{
if
(
db
)
{
db
->
disconnect
();
db
->
close
();
db
.
reset
();
}
return
true
;
}
// -----------------------------------------------------------------------------------------
bool
PostgreSQLInterface
::
copy
(
const
std
::
string
&
tblname
,
const
std
::
vector
<
std
::
string
>&
cols
,
bool
PostgreSQLInterface
::
copy
(
const
std
::
string
&
tblname
,
const
std
::
initializer_list
<
std
::
string_view
>&
cols
,
const
PostgreSQLInterface
::
Data
&
data
)
{
if
(
!
db
)
...
...
@@ -123,17 +123,14 @@ bool PostgreSQLInterface::copy( const std::string& tblname, const std::vector<st
try
{
// pqxx doesn't work with unique_ptr
work
w
(
*
(
db
.
get
())
);
tablewriter
t
(
w
,
tblname
,
cols
.
begin
(),
cols
.
end
());
t
.
reserve
(
data
.
size
());
pqxx
::
work
tx
{
*
(
db
.
get
())
};
auto
t
{
pqxx
::
stream_to
::
table
(
tx
,
{
tblname
},
cols
)};
for
(
const
auto
&
d
:
data
)
t
.
push_back
(
d
.
begin
(),
d
.
end
())
;
t
<<
d
;
t
.
complete
();
w
.
commit
();
tx
.
commit
();
return
true
;
}
catch
(
const
std
::
exception
&
e
)
...
...
@@ -208,7 +205,7 @@ DBResult PostgreSQLInterface::query( const string& q )
try
{
// pqxx doesn't work with unique_ptr
nontransaction
n
(
*
(
db
.
get
()))
;
nontransaction
n
{
*
(
db
.
get
())}
;
lastQ
=
q
;
/* Execute SQL query */
result
res
(
n
.
exec
(
q
)
);
...
...
@@ -261,11 +258,11 @@ DBResult PostgreSQLInterface::makeResult( const pqxx::result& res )
{
DBResult
result
;
for
(
result
::
const_iterator
c
=
res
.
begin
();
c
!=
res
.
end
();
++
c
)
for
(
const
auto
&
c
:
res
)
{
DBResult
::
COL
col
;
for
(
pqxx
::
result
::
tuple
::
const_iterator
i
=
c
.
begin
();
i
!=
c
.
end
();
i
++
)
for
(
const
auto
&
i
:
c
)
{
if
(
i
.
is_null
()
)
col
.
push_back
(
""
);
...
...
extensions/DBServer-PostgreSQL/PostgreSQLInterface.h
View file @
aae6b3f4
...
...
@@ -18,6 +18,7 @@
#define PostgreSQLInterface_H_
// ---------------------------------------------------------------------------
#include <string>
#include <string_view>
#include <list>
#include <vector>
#include <queue>
...
...
@@ -58,7 +59,7 @@ namespace uniset
typedef
std
::
vector
<
Record
>
Data
;
// fast insert: Use COPY..from SDTIN..
bool
copy
(
const
std
::
string
&
tblname
,
const
std
::
vector
<
std
::
string
>&
cols
,
const
Data
&
data
);
bool
copy
(
const
std
::
string
&
tblname
,
const
std
::
initializer_list
<
std
::
string_view
>&
cols
,
const
Data
&
data
);
virtual
const
std
::
string
error
()
override
;
...
...
extensions/DBServer-PostgreSQL/libUniSet2PostgreSQL.pc.in
View file @
aae6b3f4
...
...
@@ -8,4 +8,4 @@ Description: Support library for libUniSet2PostgreSQL
Requires: libUniSet2 libpqxx
Version: @VERSION@
Libs: -L${libdir} -lUniSet2-pgsql
Cflags: -
std=c++11 -
I${includedir}/@PACKAGE@ -I${includedir}/@PACKAGE@/extensions/pgsql
Cflags: -I${includedir}/@PACKAGE@ -I${includedir}/@PACKAGE@/extensions/pgsql
extensions/DBServer-PostgreSQL/test.cc
View file @
aae6b3f4
...
...
@@ -64,7 +64,7 @@ int main(int argc, char** argv)
if
(
ver
==
3
)
{
std
::
vector
<
std
::
string
>
cols
=
{
"date"
,
"time"
,
"time_usec"
,
"sensor_id"
,
"value"
,
"node"
};
std
::
initializer_list
<
std
::
string_view
>
cols
{
"date"
,
"time"
,
"time_usec"
,
"sensor_id"
,
"value"
,
"node"
};
PostgreSQLInterface
::
Data
data
;
for
(
size_t
i
=
0
;
i
<
num
;
i
++
)
...
...
extensions/DBServer-PostgreSQL/tests/docker-compose.yml
0 → 100644
View file @
aae6b3f4
version
:
'
3.2'
services
:
pghost
:
image
:
postgres:12.0-alpine
volumes
:
-
./pg_data:/var/lib/postgresql/data/pg_data
-
./entrypoint-initdb.d:/docker-entrypoint-initdb.d
cap_add
:
-
ALL
environment
:
-
"
PGDATA=/var/lib/postgresql/data/pg_data"
-
"
POSTGRES_PASSWORD=dbadmin"
-
"
POSTGRES_USER=dbadmin"
-
"
POSTGRES_DB=test-db"
ports
:
-
5432:5432
tty
:
true
extensions/DBServer-PostgreSQL/tests/entrypoint-initdb.d/db_create_example.sql
0 → 100644
View file @
aae6b3f4
CREATE
TABLE
main_history
(
id
BIGSERIAL
PRIMARY
KEY
NOT
NULL
,
date
date
NOT
NULL
,
time
time
NOT
NULL
,
time_usec
int
NOT
NULL
CHECK
(
time_usec
>=
0
),
sensor_id
int
NOT
NULL
,
value
double
precision
NOT
NULL
,
node
int
NOT
NULL
,
confirm
int
DEFAULT
NULL
);
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