deprecate zmdbFetchOne in favor of zmDbRow
This commit is contained in:
parent
2fcdee87d9
commit
44f32f46b7
|
@ -117,7 +117,8 @@ void zmLoadConfig()
|
|||
|
||||
Debug( 1, "Fetching ZM_SERVER_ID For Name = %s", staticConfig.SERVER_NAME.c_str() );
|
||||
std::string sql = stringtf("SELECT Id FROM Servers WHERE Name='%s'", staticConfig.SERVER_NAME.c_str() );
|
||||
if ( MYSQL_ROW dbrow = zmDbFetchOne( sql.c_str() ) ) {
|
||||
zmDbRow dbrow;
|
||||
if ( dbrow.fetch( sql.c_str() ) ) {
|
||||
staticConfig.SERVER_ID = atoi(dbrow[0]);
|
||||
} else {
|
||||
Fatal("Can't get ServerId for Server %s", staticConfig.SERVER_NAME.c_str() );
|
||||
|
@ -128,7 +129,8 @@ void zmLoadConfig()
|
|||
Debug( 1, "Fetching ZM_SERVER_NAME For Id = %d", staticConfig.SERVER_ID );
|
||||
std::string sql = stringtf("SELECT Name FROM Servers WHERE Id='%d'", staticConfig.SERVER_ID );
|
||||
|
||||
if ( MYSQL_ROW dbrow = zmDbFetchOne( sql.c_str() ) ) {
|
||||
zmDbRow dbrow;
|
||||
if ( dbrow.fetch( sql.c_str() ) ) {
|
||||
staticConfig.SERVER_NAME = std::string(dbrow[0]);
|
||||
} else {
|
||||
Fatal("Can't get ServerName for Server ID %d", staticConfig.SERVER_ID );
|
||||
|
|
|
@ -95,20 +95,38 @@ MYSQL_RES * zmDbFetch( const char * query ) {
|
|||
return result;
|
||||
} // end MYSQL_RES * zmDbFetch( const char * query );
|
||||
|
||||
MYSQL_ROW zmDbFetchOne( const char *query ) {
|
||||
MYSQL_RES *result = zmDbFetch( query );
|
||||
int n_rows = mysql_num_rows( result );
|
||||
zmDbRow *zmDbFetchOne( const char *query ) {
|
||||
zmDbRow *row = new zmDbRow();
|
||||
if ( row->fetch( query ) ) {
|
||||
return row;
|
||||
}
|
||||
delete row;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MYSQL_RES *zmDbRow::fetch( const char *query ) {
|
||||
result_set = zmDbFetch( query );
|
||||
if ( ! result_set ) return result_set;
|
||||
|
||||
int n_rows = mysql_num_rows( result_set );
|
||||
if ( n_rows != 1 ) {
|
||||
Error( "Bogus number of lines return from query, %d returned for query %s.", n_rows, query );
|
||||
mysql_free_result( result );
|
||||
return NULL;
|
||||
mysql_free_result( result_set );
|
||||
result_set = NULL;
|
||||
return result_set;
|
||||
}
|
||||
|
||||
MYSQL_ROW dbrow = mysql_fetch_row( result );
|
||||
if ( ! dbrow ) {
|
||||
mysql_free_result( result );
|
||||
row = mysql_fetch_row( result_set );
|
||||
if ( ! row ) {
|
||||
mysql_free_result( result_set );
|
||||
result_set = NULL;
|
||||
Error("Error getting row from query %s. Error is %s", query, mysql_error( &dbconn ) );
|
||||
return NULL;
|
||||
} else {
|
||||
Debug(3, "Succes");
|
||||
}
|
||||
return dbrow;
|
||||
return result_set;
|
||||
}
|
||||
zmDbRow::~zmDbRow() {
|
||||
if ( result_set )
|
||||
mysql_free_result( result_set );
|
||||
}
|
||||
|
|
17
src/zm_db.h
17
src/zm_db.h
|
@ -22,6 +22,21 @@
|
|||
|
||||
#include <mysql/mysql.h>
|
||||
|
||||
class zmDbRow {
|
||||
private:
|
||||
MYSQL_RES *result_set;
|
||||
MYSQL_ROW row;
|
||||
public:
|
||||
zmDbRow() { result_set = NULL; row = NULL; };
|
||||
MYSQL_RES *fetch( const char *query );
|
||||
zmDbRow( MYSQL_RES *, MYSQL_ROW *row );
|
||||
~zmDbRow();
|
||||
|
||||
char *operator[](unsigned int index) const {
|
||||
return row[index];
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -33,7 +48,7 @@ void zmDbConnect();
|
|||
void zmDbClose();
|
||||
|
||||
MYSQL_RES * zmDbFetch( const char *query );
|
||||
MYSQL_ROW zmDbFetchOne( const char *query );
|
||||
zmDbRow *zmDbFetchOne( const char *query );
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
|
|
@ -594,8 +594,8 @@ int FfmpegCamera::CaptureAndRecord( Image &image, bool recording, char* event_fi
|
|||
|
||||
//Keep the last keyframe so we can establish immediate video
|
||||
if(packet.flags & AV_PKT_FLAG_KEY) {
|
||||
Debug(4, "Have keyframe");
|
||||
av_copy_packet(&lastKeyframePkt, &packet);
|
||||
//Debug(4, "Have keyframe");
|
||||
//av_copy_packet(&lastKeyframePkt, &packet);
|
||||
//TODO I think we need to store the key frame location for seeking as part of the event
|
||||
}
|
||||
|
||||
|
|
|
@ -1119,8 +1119,8 @@ void Monitor::DumpZoneImage( const char *zone_string ) {
|
|||
Debug(3, "Trying to load from event");
|
||||
// Grab the most revent event image
|
||||
std::string sql = stringtf( "SELECT MAX(Id) FROM Events WHERE MonitorId=%d AND Frames > 0", id );
|
||||
MYSQL_ROW eventid_row = zmDbFetchOne(sql.c_str() );
|
||||
if ( eventid_row ) {
|
||||
zmDbRow eventid_row;
|
||||
if ( eventid_row.fetch( sql.c_str() ) ) {
|
||||
int event_id = atoi( eventid_row[0] );
|
||||
|
||||
Debug( 3, "Got event %d", event_id );
|
||||
|
@ -2770,8 +2770,8 @@ int Monitor::LoadFfmpegMonitors( const char *file, Monitor **&monitors, Purpose
|
|||
Monitor *Monitor::Load( unsigned int p_id, bool load_zones, Purpose purpose ) {
|
||||
std::string sql = stringtf( "select Id, Name, ServerId, StorageId, Type, Function+0, Enabled, LinkedMonitors, Device, Channel, Format, V4LMultiBuffer, V4LCapturesPerFrame, Protocol, Method, Host, Port, Path, Options, User, Pass, Width, Height, Colours, Palette, Orientation+0, Deinterlacing, RTSPDescribe, SaveJPEGs, VideoWriter, EncoderParameters, RecordAudio, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, LabelSize, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, StreamReplayBuffer, AlarmFrameCount, SectionLength, FrameSkip, MotionFrameSkip, AnalysisFPS, AnalysisUpdateDelay, MaxFPS, AlarmMaxFPS, FPSReportInterval, RefBlendPerc, AlarmRefBlendPerc, TrackMotion, SignalCheckColour, Exif from Monitors where Id = %d", p_id );
|
||||
|
||||
MYSQL_ROW dbrow = zmDbFetchOne( sql.c_str() );
|
||||
if ( ! dbrow ) {
|
||||
zmDbRow dbrow;
|
||||
if ( ! dbrow.fetch( sql.c_str() ) ) {
|
||||
Error( "Can't use query result: %s", mysql_error( &dbconn ) );
|
||||
exit( mysql_errno( &dbconn ) );
|
||||
}
|
||||
|
|
|
@ -50,8 +50,8 @@ Storage::Storage( unsigned int p_id ) {
|
|||
char sql[ZM_SQL_SML_BUFSIZ];
|
||||
snprintf( sql, sizeof(sql), "SELECT Id, Name, Path from Storage WHERE Id=%d", p_id );
|
||||
Debug(1,"Loading Storage for %d using %s", p_id, sql );
|
||||
MYSQL_ROW dbrow = zmDbFetchOne( sql );
|
||||
if ( ! dbrow ) {
|
||||
zmDbRow dbrow;
|
||||
if ( ! dbrow.fetch( sql ) ) {
|
||||
Error( "Unable to load storage area for id %d: %s", p_id, mysql_error( &dbconn ) );
|
||||
} else {
|
||||
unsigned int index = 0;
|
||||
|
|
Loading…
Reference in New Issue