From 57e1ca8909681d25382594c4b1da5cf754c9e6b3 Mon Sep 17 00:00:00 2001 From: vfilippov Date: Tue, 27 Nov 2012 10:47:15 +0000 Subject: [PATCH] Bug 113586 - Suppress UNSAFE STATEMENT warning git-svn-id: svn://svn.office.custis.ru/3rdparty/viewvc.org/trunk@1626 6955db30-a419-402b-8a0d-67ecbb4d7f56 --- lib/cvsdb.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/cvsdb.py b/lib/cvsdb.py index a2a992be..0eea8818 100644 --- a/lib/cvsdb.py +++ b/lib/cvsdb.py @@ -18,6 +18,7 @@ import cgi import vclib import dbi +import warnings ## Current commits database schema version number. ## @@ -384,13 +385,17 @@ class CheckinDatabase: cursor = self.db.cursor() try: - # MySQL-specific INSERT-or-UPDATE with ID retrieval - cursor.execute( - 'INSERT INTO '+commits_table+'('+','.join(i for i in props)+') VALUES ('+ - ', '.join('%s' for i in props)+') ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id), '+ - ', '.join(i+'=VALUES('+i+')' for i in props), - tuple(props[i] for i in props) - ) + with warnings.catch_warnings(): + # MySQL-specific INSERT-or-UPDATE with ID retrieval + # MySQL 5.5+ will say it's unsafe, really it isn't because + # we specify values only for one unique key + warnings.filterwarnings('ignore', 'ON DUPLICATE KEY UPDATE.*is unsafe') + cursor.execute( + 'INSERT INTO '+commits_table+'('+','.join(i for i in props)+') VALUES ('+ + ', '.join('%s' for i in props)+') ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id), '+ + ', '.join(i+'=VALUES('+i+')' for i in props), + tuple(props[i] for i in props) + ) commit_id = cursor.lastrowid if self.index_content: sphcur = self.sphinx.cursor()