diff options
author | Maxim Lipnin <v-maxlip@microsoft.com> | 2019-03-25 16:32:44 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2019-03-28 17:02:24 +0300 |
commit | 03e3608b878e4cad88b93c2636bb31d6e94a2e9a (patch) | |
tree | 1a4c593d73fc2577c331841dc2fe81a172057485 /mcs/class/Mono.Data.Sqlite | |
parent | b1a0ee371a0db60d83699e68ff476e53187b650f (diff) |
Move checks for empty command text to SqlCommand
Diffstat (limited to 'mcs/class/Mono.Data.Sqlite')
3 files changed, 45 insertions, 5 deletions
diff --git a/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteCommand.cs b/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteCommand.cs index 3e12cae6c2c..0f36e526cc6 100644 --- a/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteCommand.cs +++ b/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteCommand.cs @@ -503,6 +503,9 @@ namespace Mono.Data.Sqlite if (_cnn.State != ConnectionState.Open)
throw new InvalidOperationException("Database is not open");
+ if (string.IsNullOrWhiteSpace (CommandText))
+ throw new ArgumentException ("Empty SQL statement");
+
// If the version of the connection has changed, clear out any previous commands before starting
if (_cnn._version != _version)
{
diff --git a/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteDataReader.cs b/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteDataReader.cs index a74c2275390..eda2283684d 100644 --- a/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteDataReader.cs +++ b/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteDataReader.cs @@ -994,8 +994,6 @@ namespace Mono.Data.Sqlite public override bool Read()
{
CheckClosed();
- if (_activeStatement == null)
- throw new ArgumentException ("Empty SQL statement");
if (_readingState == -1) // First step was already done at the NextResult() level, so don't step again, just return true.
{
diff --git a/mcs/class/Mono.Data.Sqlite/Test/SqliteDataReaderTest.cs b/mcs/class/Mono.Data.Sqlite/Test/SqliteDataReaderTest.cs index 13eb9fb7ca3..a77236d8b53 100644 --- a/mcs/class/Mono.Data.Sqlite/Test/SqliteDataReaderTest.cs +++ b/mcs/class/Mono.Data.Sqlite/Test/SqliteDataReaderTest.cs @@ -66,9 +66,8 @@ namespace MonoTests.Mono.Data.Sqlite _conn.Open (); SqliteCommand cmd = (SqliteCommand) _conn.CreateCommand (); cmd.CommandText = string.Empty; - reader = cmd.ExecuteReader (); try { - reader.Read (); + reader = cmd.ExecuteReader (); Assert.Fail (); } catch (ArgumentException ex){ // expected this one @@ -77,7 +76,47 @@ namespace MonoTests.Mono.Data.Sqlite } } } - + + [Test] + public void NullStatementThrowsAgrumentException () + { + _conn.ConnectionString = _connectionString; + SqliteDataReader reader = null; + using (_conn) { + _conn.Open (); + SqliteCommand cmd = (SqliteCommand) _conn.CreateCommand (); + cmd.CommandText = null; + try { + reader = cmd.ExecuteReader (); + Assert.Fail (); + } catch (ArgumentException ex){ + // expected this one + } catch (Exception ex) { + Assert.Fail (); + } + } + } + + [Test] + public void WhitespaceOnlyStatementThrowsAgrumentException () + { + _conn.ConnectionString = _connectionString; + SqliteDataReader reader = null; + using (_conn) { + _conn.Open (); + SqliteCommand cmd = (SqliteCommand) _conn.CreateCommand (); + cmd.CommandText = " "; + try { + reader = cmd.ExecuteReader (); + Assert.Fail (); + } catch (ArgumentException ex){ + // expected this one + } catch (Exception ex) { + Assert.Fail (); + } + } + } + [Test] [Category ("NotWorking")] public void GetSchemaTableTest () |