From 12350407bfdb3cdf83be4a0c58bd12836d0ad9e6 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 8 Dec 2017 10:37:35 -0500 Subject: [PATCH] reconnet to db on error --- src/zm_event.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/zm_event.cpp b/src/zm_event.cpp index f59ce4c97..94bdc852f 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -485,10 +485,16 @@ void Event::AddFrame( Image *image, struct timeval timestamp, int score, Image * Debug( 1, "Adding frame %d of type \"%s\" to DB", frames, Event::frame_type_names[frame_type] ); static char sql[ZM_SQL_MED_BUFSIZ]; - snprintf( sql, sizeof(sql), "insert into Frames ( EventId, FrameId, Type, TimeStamp, Delta, Score ) values ( %d, %d, '%s', from_unixtime( %ld ), %s%ld.%02ld, %d )", id, frames, frame_type_names[frame_type], timestamp.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec, score ); - if ( mysql_query( &dbconn, sql ) ) { - Error( "Can't insert frame: %s", mysql_error( &dbconn ) ); - exit( mysql_errno( &dbconn ) ); + snprintf( sql, sizeof(sql), "INSERT INTO Frames ( EventId, FrameId, Type, TimeStamp, Delta, Score ) VALUES ( %d, %d, '%s', from_unixtime( %ld ), %s%ld.%02ld, %d )", id, frames, frame_type_names[frame_type], timestamp.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec, score ); + if ( mysql_query(&dbconn, sql) ) { + Error("Can't insert frame: (%s) reason:%s", sql, mysql_error(&dbconn)); + zmDbClose(); + if ( ! zmDbConnect() ) + exit(mysql_errno(&dbconn)); + if ( mysql_query(&dbconn, sql) ) { + Error("Can't insert frame: (%s) reason:%s", sql, mysql_error(&dbconn)); + exit(mysql_errno(&dbconn)); + } } last_db_frame = frames;