change the behaviour of StorageID. Now it will NOT NULL default 0 and a value of 0 means use ZM_EVENTS_PATH

This commit is contained in:
Isaac Connor 2016-09-14 09:31:57 -04:00
parent 07c12d0fae
commit 85b2ba73ab
5 changed files with 10 additions and 13 deletions

View File

@ -184,6 +184,7 @@ DROP TABLE IF EXISTS `Events`;
CREATE TABLE `Events` (
`Id` int(10) unsigned NOT NULL auto_increment,
`MonitorId` int(10) unsigned NOT NULL default '0',
`StorageId` smallint(5) unsigned default 0,
`Name` varchar(64) NOT NULL default '',
`Cause` varchar(32) NOT NULL default '',
`StartTime` datetime default NULL,
@ -323,7 +324,7 @@ CREATE TABLE `Monitors` (
`Id` int(10) unsigned NOT NULL auto_increment,
`Name` varchar(64) NOT NULL default '',
`ServerId` int(10) unsigned,
`StorageId` smallint(5) unsigned default NULL,
`StorageId` smallint(5) unsigned default 0,
`Type` enum('Local','Remote','File','Ffmpeg','Libvlc','cURL') NOT NULL default 'Local',
`Function` enum('None','Monitor','Modect','Record','Mocord','Nodect') NOT NULL default 'Monitor',
`Enabled` tinyint(3) unsigned NOT NULL default '1',

View File

@ -50,7 +50,7 @@ SET @s = (SELECT IF(
AND column_name = 'StorageId'
) > 0,
"SELECT 'Column StorageId exists in Events'",
"ALTER TABLE Events ADD `StorageId` smallint(5) unsigned AFTER `MonitorId`"
"ALTER TABLE Events ADD `StorageId` smallint(5) unsigned NOT NULL default 0 AFTER `MonitorId`"
));
PREPARE stmt FROM @s;

View File

@ -84,11 +84,7 @@ Event::Event( Monitor *p_monitor, struct timeval p_start_time, const std::string
static char sql[ZM_SQL_MED_BUFSIZ];
struct tm *stime = localtime( &start_time.tv_sec );
if ( storage->Id() ) {
snprintf( sql, sizeof(sql), "insert into Events ( MonitorId, StorageId, Name, StartTime, Width, Height, Cause, Notes, Videoed ) values ( %d, %d, 'New Event', from_unixtime( %ld ), %d, %d, '%s', '%s', %d )", monitor->Id(), storage->Id(), start_time.tv_sec, monitor->Width(), monitor->Height(), cause.c_str(), notes.c_str(), videoEvent );
} else {
snprintf( sql, sizeof(sql), "insert into Events ( MonitorId, StorageId, Name, StartTime, Width, Height, Cause, Notes, Videoed ) values ( %d, NULL, 'New Event', from_unixtime( %ld ), %d, %d, '%s', '%s', %d )", monitor->Id(), start_time.tv_sec, monitor->Width(), monitor->Height(), cause.c_str(), notes.c_str(), videoEvent );
}
if ( mysql_query( &dbconn, sql ) ) {
Error( "Can't insert event: %s. sql was (%s)", mysql_error( &dbconn ), sql );
exit( mysql_errno( &dbconn ) );

View File

@ -1858,7 +1858,7 @@ int Monitor::LoadLocalMonitors( const char *device, Monitor **&monitors, Purpose
int id = atoi(dbrow[col]); col++;
const char *name = dbrow[col]; col++;
unsigned int server_id = dbrow[col] ? atoi(dbrow[col]) : 0; col++;
unsigned int storage_id = dbrow[col] ? atoi(dbrow[col]) : 0; col++;
unsigned int storage_id = atoi(dbrow[col]); col++;
int function = atoi(dbrow[col]); col++;
int enabled = atoi(dbrow[col]); col++;
const char *linked_monitors = dbrow[col]; col++;
@ -2046,7 +2046,7 @@ int Monitor::LoadRemoteMonitors( const char *protocol, const char *host, const c
int id = atoi(dbrow[col]); col++;
std::string name = dbrow[col]; col++;
unsigned int server_id = dbrow[col] ? atoi(dbrow[col]) : 0; col++;
unsigned int storage_id = dbrow[col] ? atoi(dbrow[col]) : 0; col++;
unsigned int storage_id = atoi(dbrow[col]); col++;
int function = atoi(dbrow[col]); col++;
int enabled = atoi(dbrow[col]); col++;
const char *linked_monitors = dbrow[col]; col++;
@ -2229,7 +2229,7 @@ int Monitor::LoadFileMonitors( const char *file, Monitor **&monitors, Purpose pu
int id = atoi(dbrow[col]); col++;
const char *name = dbrow[col]; col++;
unsigned int server_id = dbrow[col] ? atoi(dbrow[col]) : 0; col++;
unsigned int storage_id = dbrow[col] ? atoi(dbrow[col]) : 0; col++;
unsigned int storage_id = atoi(dbrow[col]); col++;
int function = atoi(dbrow[col]); col++;
int enabled = atoi(dbrow[col]); col++;
const char *linked_monitors = dbrow[col]; col++;
@ -2381,7 +2381,7 @@ int Monitor::LoadFfmpegMonitors( const char *file, Monitor **&monitors, Purpose
int id = atoi(dbrow[col]); col++;
const char *name = dbrow[col]; col++;
unsigned int server_id = dbrow[col] ? atoi(dbrow[col]) : 0; col++;
unsigned int storage_id = dbrow[col] ? atoi(dbrow[col]) : 0; col++;
unsigned int storage_id = atoi(dbrow[col]); col++;
int function = atoi(dbrow[col]); col++;
int enabled = atoi(dbrow[col]); col++;
const char *linked_monitors = dbrow[col] ? dbrow[col] : ""; col++;
@ -2523,7 +2523,7 @@ Monitor *Monitor::Load( unsigned int p_id, bool load_zones, Purpose purpose ) {
unsigned int id = atoi(dbrow[col]); col++;
std::string name = dbrow[col]; col++;
unsigned int server_id = dbrow[col] ? atoi(dbrow[col]) : 0; col++;
unsigned int storage_id = dbrow[col] ? atoi(dbrow[col]) : 0; col++;
unsigned int storage_id = atoi(dbrow[col]); col++;
std::string type = dbrow[col]; col++;
int function = atoi(dbrow[col]); col++;
int enabled = atoi(dbrow[col]); col++;

View File

@ -1 +1 @@
1.30.6
1.30.7