miniSql

创建
zgc123@gmail.com authored at 11/19/2023 1:40:15 AM
6136600
Tree
0 Parent(s)
Summary: 1 changed files with 82 additions and 0 deletions.
Added +82 -0
Added +82 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery.Tests/Query_wrapper_tests.cs b/minisqlquery-master/src/MiniSqlQuery.Tests/Query_wrapper_tests.cs
new file mode 100644
index 0000000..3a96a4a
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery.Tests/Query_wrapper_tests.cs
@@ -0,0 +1,82 @@
+#region License
+// Copyright 2005-2019 Paul Kohler (https://github.com/paulkohler/minisqlquery). All rights reserved.
+// This source code is made available under the terms of the GNU Lesser General Public License v3.0
+// https://github.com/paulkohler/minisqlquery/blob/master/LICENSE
+#endregion
+using MiniSqlQuery.Core;
+using NUnit.Framework;
+
+
+namespace MiniSqlQuery.Tests
+{
+    [TestFixture]
+    public class Query_wrapper_tests
+    {
+        [Test]
+        public void A_query_with_GOs_produces_multiple_Query_objects()
+        {
+            var batch = QueryBatch.Parse(@"-- test query...
+
+select 1
+
+
+GO 
+select foo
+from bar
+
+	go
+
+	insert into table 1 (name, desc)
+	values('a name like gogo', 'i want to GO now.')
+
+	GO
+
+select 3
+GO
+GO
+GO
+GO
+");
+            Assert.That(batch.Queries.Count, Is.EqualTo(4), "Empty queries should be ignored");
+            Assert.That(batch.Queries[0].Sql, Is.EqualTo(@"-- test query...
+
+select 1"));
+            Assert.That(batch.Queries[1].Sql, Is.EqualTo("select foo\r\nfrom bar"));
+            Assert.That(batch.Queries[2].Sql, Is.EqualTo(@"insert into table 1 (name, desc)
+	values('a name like gogo', 'i want to GO now.')"));
+            Assert.That(batch.Queries[3].Sql, Is.EqualTo("select 3"));
+        }
+
+        [Test]
+        public void No_single_query_produces_empty_batch()
+        {
+            var batch = QueryBatch.Parse("");
+            Assert.That(batch.Queries.Count, Is.EqualTo(0));
+        }
+
+        [Test]
+        [Ignore("Needs a fair bit of work to pass...")]
+        public void Batch_indicators_on_a_line_alone_cause_issues()
+        {
+            var batch = QueryBatch.Parse(@"-- issue...
+insert into table 1 (name, desc)
+values('foo', 'if the
+go
+is on a line by itself we have a problem...')");
+            Assert.That(batch.Queries.Count, Is.EqualTo(1), "This fails for now...");
+
+            // Basically there is no easy workaround short of writing an actual SQL 
+            // query parser... allow 'turn off batches' will do...
+
+            // A good comprimise would token parse taking string (and escaping) into account
+            // but even that would add up...
+        }
+
+        [Test]
+        public void A_single_query_produces_1_batch_with_1_Query()
+        {
+            var batch = QueryBatch.Parse("select 1");
+            Assert.That(batch.Queries.Count, Is.EqualTo(1));
+        }
+    }
+}
\ No newline at end of file