Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Lipnin <v-maxlip@microsoft.com>2019-03-21 16:58:20 +0300
committerMarek Safar <marek.safar@gmail.com>2019-03-28 17:02:24 +0300
commitb1a0ee371a0db60d83699e68ff476e53187b650f (patch)
tree2e3ae49ee166c856fdec9e39229e836d6b85944f /mcs/class/Mono.Data.Sqlite
parent8f99674718a05b77fff917cfaa9c87a523b56088 (diff)
Throw ArgumentException if there is no active statement during reading a row
Diffstat (limited to 'mcs/class/Mono.Data.Sqlite')
-rw-r--r--mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteDataReader.cs2
-rw-r--r--mcs/class/Mono.Data.Sqlite/Test/SqliteDataReaderTest.cs98
2 files changed, 61 insertions, 39 deletions
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 eda2283684d..a74c2275390 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,6 +994,8 @@ 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 99d4d0bd761..13eb9fb7ca3 100644
--- a/mcs/class/Mono.Data.Sqlite/Test/SqliteDataReaderTest.cs
+++ b/mcs/class/Mono.Data.Sqlite/Test/SqliteDataReaderTest.cs
@@ -41,45 +41,65 @@ using MonoTests.Helpers;
namespace MonoTests.Mono.Data.Sqlite
{
- [TestFixture]
- public class SqliteDataReaderTest
- {
- readonly static string _uri = TestResourceHelper.GetFullPathOfResource("Test/test.db");
- readonly static string _connectionString = "URI=file://" + _uri + ", version=3";
- SqliteConnection _conn = new SqliteConnection ();
+ [TestFixture]
+ public class SqliteDataReaderTest
+ {
+ readonly static string _uri = TestResourceHelper.GetFullPathOfResource("Test/test.db");
+ readonly static string _connectionString = "URI=file://" + _uri + ", version=3";
+ SqliteConnection _conn = new SqliteConnection ();
- [TestFixtureSetUp]
- public void FixtureSetUp ()
- {
- if (! File.Exists (_uri) || new FileInfo (_uri).Length == 0) {
- // ignore all tests
- Assert.Ignore ("#000 ignoring all fixtures. No database present");
- }
- }
-
-
- [Test]
- [Category ("NotWorking")]
- public void GetSchemaTableTest ()
- {
- _conn.ConnectionString = _connectionString;
- SqliteDataReader reader = null;
- using (_conn) {
- _conn.Open ();
- SqliteCommand cmd = (SqliteCommand) _conn.CreateCommand ();
- cmd.CommandText = "select * from test";
- reader = cmd.ExecuteReader ();
- try {
- DataTable dt = reader.GetSchemaTable ();
- Assert.IsNotNull (dt, "#GS1 should return valid table");
- Assert.IsTrue (dt.Rows.Count > 0, "#GS2 should return with rows ;-)");
- } finally {
- if (reader != null && !reader.IsClosed)
- reader.Close ();
- _conn.Close ();
- }
- }
- }
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ if (! File.Exists (_uri) || new FileInfo (_uri).Length == 0) {
+ // ignore all tests
+ Assert.Ignore ("#000 ignoring all fixtures. No database present");
+ }
+ }
+
+ [Test]
+ public void EmptyStatementThrowsAgrumentException ()
+ {
+ _conn.ConnectionString = _connectionString;
+ SqliteDataReader reader = null;
+ using (_conn) {
+ _conn.Open ();
+ SqliteCommand cmd = (SqliteCommand) _conn.CreateCommand ();
+ cmd.CommandText = string.Empty;
+ reader = cmd.ExecuteReader ();
+ try {
+ reader.Read ();
+ Assert.Fail ();
+ } catch (ArgumentException ex){
+ // expected this one
+ } catch (Exception ex) {
+ Assert.Fail ();
+ }
+ }
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void GetSchemaTableTest ()
+ {
+ _conn.ConnectionString = _connectionString;
+ SqliteDataReader reader = null;
+ using (_conn) {
+ _conn.Open ();
+ SqliteCommand cmd = (SqliteCommand) _conn.CreateCommand ();
+ cmd.CommandText = "select * from test";
+ reader = cmd.ExecuteReader ();
+ try {
+ DataTable dt = reader.GetSchemaTable ();
+ Assert.IsNotNull (dt, "#GS1 should return valid table");
+ Assert.IsTrue (dt.Rows.Count > 0, "#GS2 should return with rows ;-)");
+ } finally {
+ if (reader != null && !reader.IsClosed)
+ reader.Close ();
+ _conn.Close ();
+ }
+ }
+ }
[Test]
public void TypeOfNullInResultTest ()
@@ -301,5 +321,5 @@ namespace MonoTests.Mono.Data.Sqlite
}
}
}
- }
+ }
}