Skip to content

Commit

Permalink
fix(core): avoid SQL aggregate function when testing table existence
Browse files Browse the repository at this point in the history
  • Loading branch information
cgx committed Jan 7, 2022
1 parent b817048 commit 66bac18
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
6 changes: 3 additions & 3 deletions 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])
{
Expand Down
2 changes: 1 addition & 1 deletion SOPE/GDLContentStore/EOAdaptorChannel+GCS.m
Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions 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
Expand Down Expand Up @@ -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])
{
Expand Down
6 changes: 2 additions & 4 deletions 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 <lmarcotte@inverse.ca>
* 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
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 66bac18

Please sign in to comment.