From 9b76a16af4c163170c492abb53ca464306299eb4 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 12 Dec 2016 21:41:55 -0500 Subject: [PATCH 1/7] log failed sql when db insert fails. Also, don't permanently turn off db logging just for one failed insert --- src/zm_logger.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/zm_logger.cpp b/src/zm_logger.cpp index 9e28135ba..a26e7868e 100644 --- a/src/zm_logger.cpp +++ b/src/zm_logger.cpp @@ -618,8 +618,10 @@ void Logger::logPrint( bool hex, const char * const filepath, const int line, co snprintf( sql, sizeof(sql), "insert into Logs ( TimeKey, Component, ServerId, Pid, Level, Code, Message, File, Line ) values ( %ld.%06ld, '%s', %d, %d, %d, '%s', '%s', '%s', %d )", timeVal.tv_sec, timeVal.tv_usec, mId.c_str(), staticConfig.SERVER_ID, tid, level, classString, escapedString, file, line ); if ( mysql_query( &mDbConnection, sql ) ) { + Level tempDatabaseLevel = mDatabaseLevel; databaseLevel( NOLOG ); - Error( "Can't insert log entry: %s", mysql_error( &mDbConnection ) ); + Error( "Can't insert log entry: sql(%s) error(%s)", sql, mysql_error( &mDbConnection ) ); + databaseLevel(tempDatabaseLevel); } } if ( level <= mSyslogLevel ) From 1f6a6f97586da1b64b49e5e247eb5e801203056e Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 12 Dec 2016 21:43:07 -0500 Subject: [PATCH 2/7] fix whitespace --- src/zm_logger.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/zm_logger.cpp b/src/zm_logger.cpp index a26e7868e..997820c9a 100644 --- a/src/zm_logger.cpp +++ b/src/zm_logger.cpp @@ -619,10 +619,10 @@ void Logger::logPrint( bool hex, const char * const filepath, const int line, co if ( mysql_query( &mDbConnection, sql ) ) { Level tempDatabaseLevel = mDatabaseLevel; - databaseLevel( NOLOG ); - Error( "Can't insert log entry: sql(%s) error(%s)", sql, mysql_error( &mDbConnection ) ); - databaseLevel(tempDatabaseLevel); - } + databaseLevel( NOLOG ); + Error( "Can't insert log entry: sql(%s) error(%s)", sql, mysql_error( &mDbConnection ) ); + databaseLevel(tempDatabaseLevel); + } } if ( level <= mSyslogLevel ) { From 6fa3b25d2a576f2cc223ca9d1d54fcbf37ab511e Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 12 Dec 2016 21:44:03 -0500 Subject: [PATCH 3/7] fix whitespace --- src/zm_logger.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/zm_logger.cpp b/src/zm_logger.cpp index 997820c9a..b3db91d83 100644 --- a/src/zm_logger.cpp +++ b/src/zm_logger.cpp @@ -618,11 +618,11 @@ void Logger::logPrint( bool hex, const char * const filepath, const int line, co snprintf( sql, sizeof(sql), "insert into Logs ( TimeKey, Component, ServerId, Pid, Level, Code, Message, File, Line ) values ( %ld.%06ld, '%s', %d, %d, %d, '%s', '%s', '%s', %d )", timeVal.tv_sec, timeVal.tv_usec, mId.c_str(), staticConfig.SERVER_ID, tid, level, classString, escapedString, file, line ); if ( mysql_query( &mDbConnection, sql ) ) { - Level tempDatabaseLevel = mDatabaseLevel; - databaseLevel( NOLOG ); - Error( "Can't insert log entry: sql(%s) error(%s)", sql, mysql_error( &mDbConnection ) ); - databaseLevel(tempDatabaseLevel); - } + Level tempDatabaseLevel = mDatabaseLevel; + databaseLevel( NOLOG ); + Error( "Can't insert log entry: sql(%s) error(%s)", sql, mysql_error( &mDbConnection ) ); + databaseLevel(tempDatabaseLevel); + } } if ( level <= mSyslogLevel ) { From e058217a4b2543b5608a03dc2ffffb9cb1706d93 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 12 Dec 2016 21:55:32 -0500 Subject: [PATCH 4/7] add a db update script to update the Messages column to a TEXT type. --- db/zm_update-1.30.1.sql | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 db/zm_update-1.30.1.sql diff --git a/db/zm_update-1.30.1.sql b/db/zm_update-1.30.1.sql new file mode 100644 index 000000000..f3d5698d3 --- /dev/null +++ b/db/zm_update-1.30.1.sql @@ -0,0 +1,7 @@ +-- +-- This updates a 1.30.0 database to 1.30.1 +-- +-- Alter type of Messages column from VARCHAR(255) to TEXT +-- + +ALTER TABLE Logs MODIFY Message TEXT; From 5bd41fd65f2d5f25e9bfba2cc93b4818b9f28866 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 12 Dec 2016 21:56:17 -0500 Subject: [PATCH 5/7] db update script requires version bump to 1.30.1 --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 034552a83..7f3c3affd 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.30.0 +1.30.1 From 7063d218b970beac4b5c473d391fda92f0a66249 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 12 Dec 2016 22:08:34 -0500 Subject: [PATCH 6/7] bump version to 1.30.10 --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 7aec63116..2e0949ed3 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.30.9 +1.30.10 From eb5f0b370e82a564a6669d37d7fc3ad9b9a3e214 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 12 Dec 2016 22:23:56 -0500 Subject: [PATCH 7/7] fix type of Config.DefaultValue and add NOT NULL to Message --- db/zm_update-1.30.10.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/zm_update-1.30.10.sql b/db/zm_update-1.30.10.sql index 8ac0a5ade..651f52a55 100644 --- a/db/zm_update-1.30.10.sql +++ b/db/zm_update-1.30.10.sql @@ -3,4 +3,7 @@ -- Alter type of Messages column from VARCHAR(255) to TEXT -- -ALTER TABLE Logs MODIFY Message TEXT; +-- ALTER TABLE Logs ALTER Message DROP DEFAULT; +ALTER TABLE Logs MODIFY Message TEXT NOT NULL; + +ALTER TABLE Config MODIFY DefaultValue TEXT;