diff --git a/db/zm_create.sql.in b/db/zm_create.sql.in index 5db3e66bb..a93437cda 100644 --- a/db/zm_create.sql.in +++ b/db/zm_create.sql.in @@ -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', diff --git a/db/zm_update-1.30.5.sql b/db/zm_update-1.30.5.sql index df5e4fcc1..79a84bfd6 100644 --- a/db/zm_update-1.30.5.sql +++ b/db/zm_update-1.30.5.sql @@ -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; diff --git a/src/zm_event.cpp b/src/zm_event.cpp index 709235aa6..e9ed27245 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -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 ); - } + 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 ); if ( mysql_query( &dbconn, sql ) ) { Error( "Can't insert event: %s. sql was (%s)", mysql_error( &dbconn ), sql ); exit( mysql_errno( &dbconn ) ); diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 398cf1b57..b246852ea 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -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++; diff --git a/version b/version index 8eead96fe..13bc3394f 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.30.6 +1.30.7