From 66bac18558c8765d30ccf6caaca3738130ed410d Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Fri, 7 Jan 2022 11:39:13 -0500 Subject: [PATCH] fix(core): avoid SQL aggregate function when testing table existence --- Main/SOGo.m | 6 +++--- SOPE/GDLContentStore/EOAdaptorChannel+GCS.m | 2 +- SOPE/GDLContentStore/GCSAlarmsFolder.m | 4 ++-- SOPE/GDLContentStore/GCSSessionsFolder.m | 6 ++---- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Main/SOGo.m b/Main/SOGo.m index 8504f8509e..beef82a474 100644 --- a/Main/SOGo.m +++ b/Main/SOGo.m @@ -1,5 +1,5 @@ /* - Copyright (C) 2005-2016 Inverse inc. + Copyright (C) 2005-2022 Inverse inc. This file is part of SOGo @@ -199,7 +199,7 @@ - (void) _checkTableWithCM: (GCSChannelManager *) cm /* FIXME: make use of [EOChannelAdaptor describeTableNames] instead */ tableName = [url lastPathComponent]; if ([tc evaluateExpressionX: - [NSString stringWithFormat: @"SELECT count(*) FROM %@", + [NSString stringWithFormat: @"SELECT 1 FROM %@ WHERE 1 = 2", tableName]]) { // We re-acquire the channel in case it was abruptly closed between statements @@ -232,7 +232,7 @@ - (void) _checkQuickTableWithTypeName: typeName tableName = [NSString stringWithFormat: @"sogo_quick_%@", typeName]; driver = [url substringToIndex: [url rangeOfString: @":"].location]; - sql = [NSString stringWithFormat: @"SELECT count(*) FROM %@", + sql = [NSString stringWithFormat: @"SELECT 1 FROM %@ WHERE 1 = 2", tableName]; if ([channel evaluateExpressionX: sql]) { diff --git a/SOPE/GDLContentStore/EOAdaptorChannel+GCS.m b/SOPE/GDLContentStore/EOAdaptorChannel+GCS.m index 649d19383a..8be7b7b486 100644 --- a/SOPE/GDLContentStore/EOAdaptorChannel+GCS.m +++ b/SOPE/GDLContentStore/EOAdaptorChannel+GCS.m @@ -39,7 +39,7 @@ - (BOOL) tableExistsWithName: (NSString *) tableName didOpen = YES; } - sql = [NSString stringWithFormat: @"SELECT COUNT(*) FROM %@ WHERE 1 = 2", + sql = [NSString stringWithFormat: @"SELECT 1 FROM %@ WHERE 1 = 2", tableName]; ex = [self evaluateExpressionX: sql]; [self cancelFetch]; diff --git a/SOPE/GDLContentStore/GCSAlarmsFolder.m b/SOPE/GDLContentStore/GCSAlarmsFolder.m index 8114770318..d207270093 100644 --- a/SOPE/GDLContentStore/GCSAlarmsFolder.m +++ b/SOPE/GDLContentStore/GCSAlarmsFolder.m @@ -1,6 +1,6 @@ /* GCSAlarmsFolder.m - this file is part of SOGo * - * Copyright (C) 2010-2016 Inverse inc. + * Copyright (C) 2010-2022 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -182,7 +182,7 @@ - (void) createFolderIfNotExists queries = [tc specialQueries]; - sql = [NSString stringWithFormat: @"SELECT count(*) FROM %@", + sql = [NSString stringWithFormat: @"SELECT 1 FROM %@ WHERE 1 = 2", [self _storeTableName]]; if ([tc evaluateExpressionX: sql]) { diff --git a/SOPE/GDLContentStore/GCSSessionsFolder.m b/SOPE/GDLContentStore/GCSSessionsFolder.m index 734a7b6926..b550ec974b 100644 --- a/SOPE/GDLContentStore/GCSSessionsFolder.m +++ b/SOPE/GDLContentStore/GCSSessionsFolder.m @@ -1,8 +1,6 @@ /* GCSSessionsFolder.m - this file is part of SOGo * - * Copyright (C) 2010-2011 Inverse inc. - * - * Author: Ludovic Marcotte + * Copyright (C) 2010-2022 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -181,7 +179,7 @@ - (void) createFolderIfNotExists queries = [tc specialQueries]; - sql = [NSString stringWithFormat: @"SELECT count(*) FROM %@", tableName]; + sql = [NSString stringWithFormat: @"SELECT 1 FROM %@ WHERE 1 = 2", tableName]; if ([tc evaluateExpressionX: sql]) { sql = [queries createSessionsFolderWithName: tableName];