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
73899959
Commit
73899959
authored
Nov 21, 2012
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(DBServer): Переработан под текущий используеммый в проектах формат таблиц.
parent
962bc54b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
165 deletions
+66
-165
DBServer_MySQL.cc
extensions/DBServer-MySQL/DBServer_MySQL.cc
+23
-103
DBServer_MySQL.h
extensions/DBServer-MySQL/DBServer_MySQL.h
+43
-57
db_create.sql
extensions/DBServer-MySQL/db_create.sql
+0
-0
db_rotate.sql
extensions/DBServer-MySQL/db_rotate.sql
+0
-5
No files found.
extensions/DBServer-MySQL/DBServer_MySQL.cc
View file @
73899959
...
@@ -162,71 +162,18 @@ void DBServer_MySQL::parse( UniSetTypes::DBMessage* dbm )
...
@@ -162,71 +162,18 @@ void DBServer_MySQL::parse( UniSetTypes::DBMessage* dbm )
}
}
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
void
DBServer_MySQL
::
parse
(
UniSetTypes
::
InfoMessage
*
im
)
{
string
message
(
im
->
message
);
if
(
message
.
empty
()
&&
im
->
infocode
!=
DefaultMessageCode
)
message
=
conf
->
mi
->
getMessage
(
im
->
infocode
);
if
(
!
message
.
empty
()
)
message
=
db
->
addslashes
(
message
);
// Прежде чем формировать строку обязательно смотрите формат базы данных(порядок полей таблицы)!!!
ostringstream
ostr
;
ostr
<<
"INSERT INTO "
<<
tblName
(
im
->
type
);
ostr
<<
"(num,node,id,date,time,time_usec,code,text,haracter,type,confirm,causeid) VALUES("
;
ostr
<<
"NULL,'"
<<
im
->
node
<<
"','"
<<
im
->
id
;
ostr
<<
"','"
<<
ui
.
dateToString
(
im
->
tm
.
tv_sec
,
"/"
)
<<
"','"
<<
ui
.
timeToString
(
im
->
tm
.
tv_sec
,
":"
);
ostr
<<
"','"
<<
im
->
tm
.
tv_usec
;
ostr
<<
"','"
<<
im
->
infocode
<<
"','"
<<
message
<<
"','"
<<
im
->
character
;
ostr
<<
"','"
<<
im
->
type
<<
"','0','0')"
;
if
(
!
writeToBase
(
ostr
.
str
())
)
{
unideb
[
Debug
::
CRIT
]
<<
myname
<<
"(insert): info msg error: "
<<
db
->
error
()
<<
endl
;
// db->freeResult();
}
}
//--------------------------------------------------------------------------------------------
void
DBServer_MySQL
::
parse
(
UniSetTypes
::
AlarmMessage
*
am
)
{
string
message
(
am
->
message
);
if
(
message
.
empty
()
&&
am
->
alarmcode
!=
DefaultMessageCode
)
message
=
conf
->
mi
->
getMessage
(
am
->
alarmcode
);
if
(
!
message
.
empty
()
)
message
=
db
->
addslashes
(
message
);
// Прежде чем формировать строку обязательно смотрите формат базы данных(порядок полей таблицы)!!!
ostringstream
ostr
;
ostr
<<
"INSERT INTO "
<<
tblName
(
am
->
type
);
ostr
<<
"(num,node,id,date,time,time_usec,code,text,haracter,type,confirm,causeid) VALUES("
;
ostr
<<
"NULL,'"
<<
am
->
node
<<
"','"
<<
am
->
id
;
ostr
<<
"','"
<<
ui
.
dateToString
(
am
->
tm
.
tv_sec
,
"/"
)
<<
"','"
<<
ui
.
timeToString
(
am
->
tm
.
tv_sec
,
":"
)
<<
"','"
<<
am
->
tm
.
tv_usec
;
ostr
<<
"','"
<<
am
->
alarmcode
<<
"','"
<<
message
;
ostr
<<
"','"
<<
am
->
character
<<
"','"
<<
am
->
type
<<
"',0,'"
<<
am
->
causecode
<<
"')"
;
if
(
!
writeToBase
(
ostr
.
str
())
)
{
unideb
[
Debug
::
CRIT
]
<<
myname
<<
"(insert): alarm msg error: "
<<
db
->
error
()
<<
endl
;
// db->freeResult();
}
}
//--------------------------------------------------------------------------------------------
void
DBServer_MySQL
::
parse
(
UniSetTypes
::
ConfirmMessage
*
cem
)
void
DBServer_MySQL
::
parse
(
UniSetTypes
::
ConfirmMessage
*
cem
)
{
{
try
try
{
{
ostringstream
data
;
ostringstream
data
;
data
<<
"UPDATE main_history SET confirm='"
<<
cem
->
confirm
<<
"'"
;
data
<<
"UPDATE "
<<
tblName
(
cem
->
type
)
data
<<
" WHERE sensor_id='"
<<
cem
->
sensor_id
<<
"'"
;
<<
" SET confirm='"
<<
cem
->
confirm
<<
"'"
data
<<
" AND date='"
<<
ui
.
dateToString
(
cem
->
time
,
"-"
)
<<
" '"
;
<<
" WHERE sensor_id='"
<<
cem
->
sensor_id
<<
"'"
data
<<
" AND time='"
<<
ui
.
timeToString
(
cem
->
time
,
":"
)
<<
" '"
;
<<
" AND date='"
<<
ui
.
dateToString
(
cem
->
time
,
"-"
)
<<
" '"
data
<<
" AND time_usec='"
<<
cem
->
time_usec
<<
" '"
;
<<
" AND time='"
<<
ui
.
timeToString
(
cem
->
time
,
":"
)
<<
" '"
<<
" AND time_usec='"
<<
cem
->
time_usec
<<
" '"
;
if
(
unideb
.
debugging
(
DBLEVEL
)
)
if
(
unideb
.
debugging
(
DBLEVEL
)
)
unideb
[
DBLEVEL
]
<<
myname
<<
"(update_confirm): "
<<
data
.
str
()
<<
endl
;
unideb
[
DBLEVEL
]
<<
myname
<<
"(update_confirm): "
<<
data
.
str
()
<<
endl
;
...
@@ -335,43 +282,20 @@ void DBServer_MySQL::parse( UniSetTypes::SensorMessage *si )
...
@@ -335,43 +282,20 @@ void DBServer_MySQL::parse( UniSetTypes::SensorMessage *si )
// см. DBTABLE AnalogSensors, DigitalSensors
// см. DBTABLE AnalogSensors, DigitalSensors
ostringstream
data
;
ostringstream
data
;
data
<<
" VALUES( "
;
data
<<
"INSERT INTO "
<<
tblName
(
si
->
type
)
// Поля таблицы
<<
"(date, time, time_usec, sensor_id, value, node) VALUES( '"
data
<<
"NULL,'"
<<
si
->
node
<<
"','"
;
// num, node
// Поля таблицы
data
<<
si
->
id
<<
"','"
;
// id (sensorid)
<<
ui
.
dateToString
(
si
->
sm_tv_sec
,
"-"
)
<<
"','"
// date
data
<<
ui
.
dateToString
(
si
->
sm_tv_sec
,
"/"
)
<<
"','"
;
// date
<<
ui
.
timeToString
(
si
->
sm_tv_sec
,
":"
)
<<
"','"
// time
data
<<
ui
.
timeToString
(
si
->
sm_tv_sec
,
":"
)
<<
"','"
;
// time
<<
si
->
sm_tv_usec
<<
"',"
// time_usec
data
<<
si
->
sm_tv_usec
<<
"','"
;
// time_usec
<<
si
->
id
<<
","
// sensor_id
<<
si
->
value
<<
","
// value
<<
si
->
node
<<
")"
;
// node
// data << ui.dateToString(si->tm.tv_sec) << "','"; // date
if
(
unideb
.
debugging
(
DBLEVEL
)
)
// data << ui.timeToString(si->tm.tv_sec) << "','"; // time
unideb
[
DBLEVEL
]
<<
myname
<<
"(insert_main_history): "
<<
data
.
str
()
<<
endl
;
// data << si->tm.tv_usec << "','"; // time_usec
string
table
;
switch
(
si
->
sensor_type
)
{
case
UniversalIO
:
:
DigitalInput
:
case
UniversalIO
:
:
DigitalOutput
:
table
=
"DigitalSensors(num,node,id,date,time,time_usec,state)"
;
data
<<
si
->
state
;
// state
break
;
case
UniversalIO
:
:
AnalogInput
:
case
UniversalIO
:
:
AnalogOutput
:
table
=
"AnalogSensors(num,node,id,date,time,time_usec,value)"
;
data
<<
si
->
value
;
// value
break
;
default
:
unideb
[
Debug
::
WARN
]
<<
myname
<<
"(log sensor): Unknown iotype='"
<<
si
->
sensor_type
<<
"'.. ignore SensorMessage..."
<<
endl
;
return
;
}
data
<<
"')"
;
if
(
!
writeToBase
(
"INSERT INTO "
+
table
+
data
.
str
())
)
if
(
!
writeToBase
(
data
.
str
())
)
{
{
if
(
unideb
.
debugging
(
Debug
::
CRIT
)
)
if
(
unideb
.
debugging
(
Debug
::
CRIT
)
)
unideb
[
Debug
::
CRIT
]
<<
myname
<<
"(insert) sensor msg error: "
<<
db
->
error
()
<<
endl
;
unideb
[
Debug
::
CRIT
]
<<
myname
<<
"(insert) sensor msg error: "
<<
db
->
error
()
<<
endl
;
...
@@ -380,15 +304,12 @@ void DBServer_MySQL::parse( UniSetTypes::SensorMessage *si )
...
@@ -380,15 +304,12 @@ void DBServer_MySQL::parse( UniSetTypes::SensorMessage *si )
}
}
catch
(
Exception
&
ex
)
catch
(
Exception
&
ex
)
{
{
if
(
unideb
.
debugging
(
Debug
::
CRIT
)
)
unideb
[
Debug
::
CRIT
]
<<
myname
<<
"(insert_main_history): "
<<
ex
<<
endl
;
unideb
[
Debug
::
CRIT
]
<<
myname
<<
"(parse SensorMessage): "
<<
ex
<<
endl
;
}
}
catch
(
...
)
catch
(
...
)
{
{
if
(
unideb
.
debugging
(
Debug
::
CRIT
)
)
unideb
[
Debug
::
CRIT
]
<<
myname
<<
"(insert_main_history): catch ..."
<<
endl
;
unideb
[
Debug
::
CRIT
]
<<
myname
<<
"(parse SensorMessage): catch..."
<<
endl
;
}
}
}
}
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
void
DBServer_MySQL
::
init_dbserver
()
void
DBServer_MySQL
::
init_dbserver
()
...
@@ -425,9 +346,8 @@ void DBServer_MySQL::init_dbserver()
...
@@ -425,9 +346,8 @@ void DBServer_MySQL::init_dbserver()
string
user
(
conf
->
getProp
(
node
,
"dbuser"
));
string
user
(
conf
->
getProp
(
node
,
"dbuser"
));
string
password
(
conf
->
getProp
(
node
,
"dbpass"
));
string
password
(
conf
->
getProp
(
node
,
"dbpass"
));
tblMap
[
UniSetTypes
::
Message
::
Info
]
=
"Messages"
;
tblMap
[
UniSetTypes
::
Message
::
SensorInfo
]
=
"main_history"
;
tblMap
[
UniSetTypes
::
Message
::
Alarm
]
=
"Messages"
;
tblMap
[
UniSetTypes
::
Message
::
Confirm
]
=
"main_history"
;
tblMap
[
UniSetTypes
::
Message
::
SensorInfo
]
=
"AnalogSensors"
;
PingTime
=
conf
->
getIntProp
(
node
,
"pingTime"
);
PingTime
=
conf
->
getIntProp
(
node
,
"pingTime"
);
ReconnectTime
=
conf
->
getIntProp
(
node
,
"reconnectTime"
);
ReconnectTime
=
conf
->
getIntProp
(
node
,
"reconnectTime"
);
...
...
extensions/DBServer-MySQL/DBServer_MySQL.h
View file @
73899959
...
@@ -85,63 +85,51 @@
...
@@ -85,63 +85,51 @@
\section sec_DBS_Tables Таблицы MySQL
\section sec_DBS_Tables Таблицы MySQL
К основным таблицам относятся следующие:
К основным таблицам относятся следующие:
\code
\code
DROP TABLE IF EXISTS `main_history`;
DROP TABLE IF EXISTS ObjectsMap;
CREATE TABLE `main_history` (
CREATE TABLE ObjectsMap (
`id` int(11) NOT NULL AUTO_INCREMENT,
name varchar(80) NOT NULL default '',
`date` date NOT NULL,
rep_name varchar(80) default NULL,
`time` time NOT NULL,
id int(4) NOT NULL default '0',
`time_usec` int(10) unsigned NOT NULL,
msg int(1) default 0,
`sensor_id` int(10) unsigned NOT NULL,
PRIMARY KEY (id),
`value` double NOT NULL,
KEY rep_name (rep_name),
`node` int(10) unsigned NOT NULL,
KEY msg (msg)
`confirm` int(11) DEFAULT NULL,
) TYPE=MyISAM;
PRIMARY KEY (`id`),
KEY `main_history_sensor_id` (`sensor_id`),
CONSTRAINT `sensor_id_refs_id_3d679168` FOREIGN KEY (`sensor_id`) REFERENCES `main_sensor` (`id`)
DROP TABLE IF EXISTS AnalogSensors;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE AnalogSensors (
num int(11) NOT NULL auto_increment,
DROP TABLE IF EXISTS `main_emergencylog`;
node int(3) default NULL,
CREATE TABLE `main_emergencylog` (
id int(4) default NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
date date NOT NULL default '0000-00-00',
`date` date NOT NULL,
time time NOT NULL default '00:00:00',
`time` time NOT NULL,
time_usec int(3) unsigned default '0',
`time_usec` int(10) unsigned NOT NULL,
value int(6) default NULL,
`type_id` int(10) unsigned NOT NULL,
PRIMARY KEY (num),
PRIMARY KEY (`id`),
KEY date (date,time,time_usec),
KEY `main_emergencylog_type_id` (`type_id`),
KEY node (node,id)
CONSTRAINT `type_id_refs_id_a3133ca` FOREIGN KEY (`type_id`) REFERENCES `main_emergencytype` (`id`)
) TYPE=MyISAM;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
DROP TABLE IF EXISTS `main_emergencyrecords`;
-- Table structure for table `DigitalSensors`
CREATE TABLE `main_emergencyrecords` (
--
`id` int(11) NOT NULL AUTO_INCREMENT,
DROP TABLE IF EXISTS DigitalSensors;
`date` date NOT NULL,
CREATE TABLE DigitalSensors (
`time` time NOT NULL,
num int(11) NOT NULL auto_increment,
`time_usec` int(10) unsigned NOT NULL,
node int(3) default NULL,
`log_id` int(11) NOT NULL,
id int(4) default NULL,
`sensor_id` int(10) unsigned NOT NULL,
date date NOT NULL default '0000-00-00',
`value` double NOT NULL,
time time NOT NULL default '00:00:00',
PRIMARY KEY (`id`),
time_usec int(3) unsigned default '0',
KEY `main_emergencyrecords_log_id` (`log_id`),
state char(1) default NULL,
KEY `main_emergencyrecords_sensor_id` (`sensor_id`),
confirm time NOT NULL default '00:00:00',
CONSTRAINT `log_id_refs_id_77a37ea9` FOREIGN KEY (`log_id`) REFERENCES `main_emergencylog` (`id`),
PRIMARY KEY (num),
CONSTRAINT `sensor_id_refs_id_436bab5e` FOREIGN KEY (`sensor_id`) REFERENCES `main_sensor` (`id`)
KEY date (date,time,time_usec),
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
KEY node (node,id),
KEY confirm(confirm)
) TYPE=MyISAM;
DROP TABLE IF EXISTS SensorsThreshold;
CREATE TABLE SensorsThreshold (
sid int(11) NOT NULL default '0',
alarm int(8) NOT NULL default '0',
warning int(8) NOT NULL default '0'
) TYPE=MyISAM;
\endcode
\endcode
*/
*/
class
DBServer_MySQL
:
class
DBServer_MySQL
:
public
DBServer
public
DBServer
...
@@ -166,8 +154,6 @@ class DBServer_MySQL:
...
@@ -166,8 +154,6 @@ class DBServer_MySQL:
// Функции обработки пришедших сообщений
// Функции обработки пришедших сообщений
virtual
void
parse
(
UniSetTypes
::
SensorMessage
*
sm
);
virtual
void
parse
(
UniSetTypes
::
SensorMessage
*
sm
);
virtual
void
parse
(
UniSetTypes
::
DBMessage
*
dbmsg
);
virtual
void
parse
(
UniSetTypes
::
DBMessage
*
dbmsg
);
virtual
void
parse
(
UniSetTypes
::
InfoMessage
*
imsg
);
virtual
void
parse
(
UniSetTypes
::
AlarmMessage
*
amsg
);
virtual
void
parse
(
UniSetTypes
::
ConfirmMessage
*
cmsg
);
virtual
void
parse
(
UniSetTypes
::
ConfirmMessage
*
cmsg
);
bool
writeToBase
(
const
string
&
query
);
bool
writeToBase
(
const
string
&
query
);
...
...
extensions/DBServer-MySQL/db_create.sql
View file @
73899959
This diff is collapsed.
Click to expand it.
extensions/DBServer-MySQL/db_rotate.sql
deleted
100644 → 0
View file @
962bc54b
DELETE
FROM
DigitalSensors
WHERE
date
<
к
TE_SUB
(
NOW
(),
INTERVAL
10
DAY
);
DELETE
FROM
AnalogSensors
WHERE
date
<
к
TE_SUB
(
NOW
(),
INTERVAL
10
DAY
);
DELETE
FROM
Messages
WHERE
date
<
к
TE_SUB
(
NOW
(),
INTERVAL
10
DAY
);
DELETE
FROM
RSChannel
WHERE
date
<
к
TE_SUB
(
NOW
(),
INTERVAL
10
DAY
);
DELETE
FROM
Network
WHERE
date
<
к
TE_SUB
(
NOW
(),
INTERVAL
10
DAY
);
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