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
fee860f2
Commit
fee860f2
authored
Dec 26, 2012
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(SQLite): первая версия реализации uniset-sqlite-dbserver
parent
5b23e1a6
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
24 additions
and
31 deletions
+24
-31
test.xml
conf/test.xml
+1
-1
DBServer_SQLite.cc
extensions/DBServer-SQLite/DBServer_SQLite.cc
+5
-30
SQLiteInterface.cc
extensions/DBServer-SQLite/SQLiteInterface.cc
+5
-0
SQLiteInterface.h
extensions/DBServer-SQLite/SQLiteInterface.h
+1
-0
start_fg.sh
extensions/DBServer-SQLite/start_fg.sh
+8
-0
stop.sh
extensions/DBServer-SQLite/stop.sh
+2
-0
test.xml
extensions/DBServer-SQLite/test.xml
+2
-0
No files found.
conf/test.xml
View file @
fee860f2
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
<RouteList>
<RouteList>
</RouteList>
</RouteList>
</LocalInfoServer>
</LocalInfoServer>
<LocalDBServer
dbname=
"UNISET_PLC"
dbpass=
"dbadmin"
dbuser=
"dbadmin"
name=
"DBServer"
pingTime=
"60000"
reconnectTime=
"30000"
/>
<LocalDBServer
db
file=
"test.db"
db
name=
"UNISET_PLC"
dbpass=
"dbadmin"
dbuser=
"dbadmin"
name=
"DBServer"
pingTime=
"60000"
reconnectTime=
"30000"
/>
<LocalPrintServer
checkTime=
"5000"
device=
"/dev/lp0"
/>
<LocalPrintServer
checkTime=
"5000"
device=
"/dev/lp0"
/>
</Services>
</Services>
</UniSet>
</UniSet>
...
...
extensions/DBServer-SQLite/DBServer_SQLite.cc
View file @
fee860f2
...
@@ -239,22 +239,11 @@ void DBServer_SQLite::flushBuffer()
...
@@ -239,22 +239,11 @@ void DBServer_SQLite::flushBuffer()
// Сперва пробуем очистить всё что накопилось в очереди до этого...
// Сперва пробуем очистить всё что накопилось в очереди до этого...
while
(
!
qbuf
.
empty
()
)
while
(
!
qbuf
.
empty
()
)
{
{
#if 0
if
(
!
db
->
insert
(
qbuf
.
front
())
&&
unideb
.
debugging
(
Debug
::
CRIT
)
)
db->query( qbuf.front() );
// Дело в том что на INSERT И UPDATE запросы
// db->query() может возвращать false и надо самому
// отдельно проверять действительно ли произошла ошибка
// см. SQLiteInterface::query.
string err(db->error());
if( err.empty() )
db->freeResult();
else if( unideb.debugging(Debug::CRIT) )
{
{
unideb[Debug::CRIT] << myname << "(writeToBase): error: " <<
err
<<
unideb
[
Debug
::
CRIT
]
<<
myname
<<
"(writeToBase): error: "
<<
db
->
error
()
<<
" lost query: "
<<
qbuf
.
front
()
<<
endl
;
" lost query: "
<<
qbuf
.
front
()
<<
endl
;
}
}
#endif
qbuf
.
pop
();
qbuf
.
pop
();
}
}
}
}
...
@@ -331,10 +320,7 @@ void DBServer_SQLite::init_dbserver()
...
@@ -331,10 +320,7 @@ void DBServer_SQLite::init_dbserver()
UniXML
::
iterator
it
(
node
);
UniXML
::
iterator
it
(
node
);
unideb
[
DBLogInfoLevel
]
<<
myname
<<
"(init): init connection.."
<<
endl
;
unideb
[
DBLogInfoLevel
]
<<
myname
<<
"(init): init connection.."
<<
endl
;
string
dbname
(
conf
->
getProp
(
node
,
"dbname"
));
string
dbfile
(
conf
->
getProp
(
node
,
"dbfile"
));
string
dbnode
(
conf
->
getProp
(
node
,
"dbnode"
));
string
user
(
conf
->
getProp
(
node
,
"dbuser"
));
string
password
(
conf
->
getProp
(
node
,
"dbpass"
));
tblMap
[
UniSetTypes
::
Message
::
SensorInfo
]
=
"main_history"
;
tblMap
[
UniSetTypes
::
Message
::
SensorInfo
]
=
"main_history"
;
tblMap
[
UniSetTypes
::
Message
::
Confirm
]
=
"main_history"
;
tblMap
[
UniSetTypes
::
Message
::
Confirm
]
=
"main_history"
;
...
@@ -350,17 +336,12 @@ void DBServer_SQLite::init_dbserver()
...
@@ -350,17 +336,12 @@ void DBServer_SQLite::init_dbserver()
else
else
lastRemove
=
false
;
lastRemove
=
false
;
if
(
dbnode
.
empty
()
)
dbnode
=
"localhost"
;
if
(
unideb
.
debugging
(
DBLogInfoLevel
)
)
if
(
unideb
.
debugging
(
DBLogInfoLevel
)
)
unideb
[
DBLogInfoLevel
]
<<
myname
<<
"(init): connect dbnode="
<<
dbnode
unideb
[
DBLogInfoLevel
]
<<
myname
<<
"(init): connect dbfile="
<<
dbfile
<<
"
\t
dbname="
<<
dbname
<<
" pingTime="
<<
PingTime
<<
" pingTime="
<<
PingTime
<<
" ReconnectTime="
<<
ReconnectTime
<<
endl
;
<<
" ReconnectTime="
<<
ReconnectTime
<<
endl
;
#if 0
if
(
!
db
->
connect
(
dbfile
,
false
)
)
if( !db->connect(dbnode, user, password, dbname) )
{
{
// ostringstream err;
// ostringstream err;
if
(
unideb
.
debugging
(
Debug
::
CRIT
)
)
if
(
unideb
.
debugging
(
Debug
::
CRIT
)
)
...
@@ -382,8 +363,6 @@ void DBServer_SQLite::init_dbserver()
...
@@ -382,8 +363,6 @@ void DBServer_SQLite::init_dbserver()
initDBTableMap
(
tblMap
);
initDBTableMap
(
tblMap
);
flushBuffer
();
flushBuffer
();
}
}
#endif
}
}
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
void
DBServer_SQLite
::
createTables
(
SQLiteInterface
*
db
)
void
DBServer_SQLite
::
createTables
(
SQLiteInterface
*
db
)
...
@@ -416,7 +395,6 @@ void DBServer_SQLite::timerInfo( UniSetTypes::TimerMessage* tm )
...
@@ -416,7 +395,6 @@ void DBServer_SQLite::timerInfo( UniSetTypes::TimerMessage* tm )
{
{
case
DBServer_SQLite
:
:
PingTimer
:
case
DBServer_SQLite
:
:
PingTimer
:
{
{
#if 0
if
(
!
db
->
ping
()
)
if
(
!
db
->
ping
()
)
{
{
if
(
unideb
.
debugging
(
Debug
::
WARN
)
)
if
(
unideb
.
debugging
(
Debug
::
WARN
)
)
...
@@ -431,7 +409,6 @@ void DBServer_SQLite::timerInfo( UniSetTypes::TimerMessage* tm )
...
@@ -431,7 +409,6 @@ void DBServer_SQLite::timerInfo( UniSetTypes::TimerMessage* tm )
if
(
unideb
.
debugging
(
DBLogInfoLevel
)
)
if
(
unideb
.
debugging
(
DBLogInfoLevel
)
)
unideb
[
DBLogInfoLevel
]
<<
myname
<<
"(timerInfo): DB ping ok"
<<
endl
;
unideb
[
DBLogInfoLevel
]
<<
myname
<<
"(timerInfo): DB ping ok"
<<
endl
;
}
}
#endif
}
}
break
;
break
;
...
@@ -441,14 +418,12 @@ void DBServer_SQLite::timerInfo( UniSetTypes::TimerMessage* tm )
...
@@ -441,14 +418,12 @@ void DBServer_SQLite::timerInfo( UniSetTypes::TimerMessage* tm )
unideb
[
DBLogInfoLevel
]
<<
myname
<<
"(timerInfo): reconnect timer"
<<
endl
;
unideb
[
DBLogInfoLevel
]
<<
myname
<<
"(timerInfo): reconnect timer"
<<
endl
;
if
(
db
->
isConnection
()
)
if
(
db
->
isConnection
()
)
{
{
#if 0
if
(
db
->
ping
()
)
if
(
db
->
ping
()
)
{
{
connect_ok
=
true
;
connect_ok
=
true
;
askTimer
(
DBServer_SQLite
::
ReconnectTimer
,
0
);
askTimer
(
DBServer_SQLite
::
ReconnectTimer
,
0
);
askTimer
(
DBServer_SQLite
::
PingTimer
,
PingTime
);
askTimer
(
DBServer_SQLite
::
PingTimer
,
PingTime
);
}
}
#endif
connect_ok
=
false
;
connect_ok
=
false
;
if
(
unideb
.
debugging
(
Debug
::
WARN
)
)
if
(
unideb
.
debugging
(
Debug
::
WARN
)
)
unideb
[
Debug
::
WARN
]
<<
myname
<<
"(timerInfo): DB no connection.."
<<
endl
;
unideb
[
Debug
::
WARN
]
<<
myname
<<
"(timerInfo): DB no connection.."
<<
endl
;
...
...
extensions/DBServer-SQLite/SQLiteInterface.cc
View file @
fee860f2
...
@@ -49,6 +49,11 @@ SQLiteInterface::~SQLiteInterface()
...
@@ -49,6 +49,11 @@ SQLiteInterface::~SQLiteInterface()
}
}
// -----------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------
bool
SQLiteInterface
::
ping
()
{
return
db
&&
(
sqlite3_db_status
(
db
,
0
,
NULL
,
NULL
,
0
)
==
SQLITE_OK
);
}
// -----------------------------------------------------------------------------------------
bool
SQLiteInterface
::
connect
(
const
string
dbfile
,
bool
create
)
bool
SQLiteInterface
::
connect
(
const
string
dbfile
,
bool
create
)
{
{
// т.к. sqlite3 по умолчанию, создаёт файл при открытии, то проверим "сами"
// т.к. sqlite3 по умолчанию, создаёт файл при открытии, то проверим "сами"
...
...
extensions/DBServer-SQLite/SQLiteInterface.h
View file @
fee860f2
...
@@ -43,6 +43,7 @@ class SQLiteInterface
...
@@ -43,6 +43,7 @@ class SQLiteInterface
bool
connect
(
const
std
::
string
dbfile
,
bool
create
=
false
);
bool
connect
(
const
std
::
string
dbfile
,
bool
create
=
false
);
bool
close
();
bool
close
();
bool
isConnection
();
bool
isConnection
();
bool
ping
();
// проверка доступности БД
inline
void
setOperationTimeout
(
timeout_t
msec
){
opTimeout
=
msec
;
}
inline
void
setOperationTimeout
(
timeout_t
msec
){
opTimeout
=
msec
;
}
inline
timeout_t
getOperationTimeout
(){
return
opTimeout
;
}
inline
timeout_t
getOperationTimeout
(){
return
opTimeout
;
}
...
...
extensions/DBServer-SQLite/start_fg.sh
0 → 100755
View file @
fee860f2
#!/bin/sh
ulimit
-Sc
1000000
uniset-start.sh
-f
./uniset-sqlite-dbserver
--confile
test.xml
--name
DBServer1
\
--unideb-add-levels
info,crit,warn,level9,system
\
--dbserver-buffer-size
100
extensions/DBServer-SQLite/stop.sh
0 → 120000
View file @
fee860f2
/usr/bin/uniset-stop.sh
\ No newline at end of file
extensions/DBServer-SQLite/test.xml
0 → 120000
View file @
fee860f2
../../conf/test.xml
\ No newline at end of file
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