From c5c2d9414b728495a372b441e3e2f5e96f20cf14 Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Wed, 23 Jun 2010 17:14:38 +0000 Subject: [PATCH] Huge list protection implemented --- Builder/IISMainHandler/build.txt | 2 +- Builder/IISUploadHandler/build.txt | 2 +- Core/DB/IDBConnection.cs | 6 +++++- MySQLConnector/Connection.cs | 5 ++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index 8975db9..3d9983a 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -293 \ No newline at end of file +295 \ No newline at end of file diff --git a/Builder/IISUploadHandler/build.txt b/Builder/IISUploadHandler/build.txt index 410b14d..a5c750f 100644 --- a/Builder/IISUploadHandler/build.txt +++ b/Builder/IISUploadHandler/build.txt @@ -1 +1 @@ -25 \ No newline at end of file +27 \ No newline at end of file diff --git a/Core/DB/IDBConnection.cs b/Core/DB/IDBConnection.cs index d2a45b5..fdab8a3 100644 --- a/Core/DB/IDBConnection.cs +++ b/Core/DB/IDBConnection.cs @@ -8,7 +8,7 @@ namespace FLocal.Core.DB { List> LoadByIds(ITableSpec table, List ids); - List LoadIdsByConditions(ITableSpec table, conditions.AbstractCondition conditions, Diapasone diapasone, JoinSpec[] joins, SortSpec[] sorts); + List LoadIdsByConditions(ITableSpec table, conditions.AbstractCondition conditions, Diapasone diapasone, JoinSpec[] joins, SortSpec[] sorts, bool allowHugeLists); long GetCountByConditions(ITableSpec table, conditions.AbstractCondition conditions, JoinSpec[] joins); @@ -30,6 +30,10 @@ namespace FLocal.Core.DB { public static class IDBConnectionExtensions { + public static List LoadIdsByConditions(this IDBConnection connection, ITableSpec table, conditions.AbstractCondition conditions, Diapasone diapasone, JoinSpec[] joins, SortSpec[] sorts) { + return connection.LoadIdsByConditions(table, conditions, diapasone, joins, sorts, false); + } + public static List LoadIdsByConditions(this IDBConnection connection, ITableSpec table, conditions.AbstractCondition conditions, Diapasone diapasone, params JoinSpec[] joins) { return connection.LoadIdsByConditions(table, conditions, diapasone, joins, new SortSpec[] { new SortSpec(table.getIdSpec(), true) }); } diff --git a/MySQLConnector/Connection.cs b/MySQLConnector/Connection.cs index 67fb385..fc2c5a0 100644 --- a/MySQLConnector/Connection.cs +++ b/MySQLConnector/Connection.cs @@ -82,7 +82,7 @@ namespace FLocal.MySQLConnector { } } - public List LoadIdsByConditions(ITableSpec table, FLocal.Core.DB.conditions.AbstractCondition conditions, Diapasone diapasone, JoinSpec[] joins, SortSpec[] sorts) { + public List LoadIdsByConditions(ITableSpec table, FLocal.Core.DB.conditions.AbstractCondition conditions, Diapasone diapasone, JoinSpec[] joins, SortSpec[] sorts, bool allowHugeLists) { lock(this) { using(DbCommand command = this.connection.CreateCommand()) { @@ -132,6 +132,9 @@ namespace FLocal.MySQLConnector { return new List(); } else { diapasone.total = count; + if(diapasone.total > 1000 && diapasone.count < 0 && !allowHugeLists) { + throw new CriticalException("huge list"); + } string queryLimits = ""; if(diapasone.count >= 0) { queryLimits = "LIMIT " + diapasone.count + " OFFSET " + diapasone.start;