diff --git a/src/EFCore.Jet.Data/JetCommand.cs b/src/EFCore.Jet.Data/JetCommand.cs index 7d537d1..98205ac 100644 --- a/src/EFCore.Jet.Data/JetCommand.cs +++ b/src/EFCore.Jet.Data/JetCommand.cs @@ -25,7 +25,7 @@ namespace EntityFrameworkCore.Jet.Data private static readonly Regex _outerSelectTopValueRegularExpression = new Regex(@"(?<=^\s*select\s+top\s+)\d+(?=\s)", RegexOptions.IgnoreCase); private static readonly Regex _outerSelectSkipValueOrParameterRegularExpression = new Regex(@"(?<=^\s*select)\s+skip\s+(?@\w+|\?|\d+)(?=\s)", RegexOptions.IgnoreCase); private static readonly Regex _selectRowCountRegularExpression = new Regex(@"^\s*select\s*@@rowcount\s*;?\s*$", RegexOptions.IgnoreCase); - private static readonly Regex _ifStatementRegex = new Regex(@"^\s*if\s*(?not)?\s*exists\s*\((?.+)\)\s*then\s*(?.*)$", RegexOptions.IgnoreCase); + private static readonly Regex _ifStatementRegex = new Regex(@"^\s*if\s*(?not)?\s*exists\s*\((?.+)\)\s*then\s*(?.*)$", RegexOptions.IgnoreCase | RegexOptions.Singleline); protected JetCommand(JetCommand source) { diff --git a/test/EFCore.Jet.Data.Tests/ExistsTest.cs b/test/EFCore.Jet.Data.Tests/ExistsTest.cs new file mode 100644 index 0000000..7fcb852 --- /dev/null +++ b/test/EFCore.Jet.Data.Tests/ExistsTest.cs @@ -0,0 +1,38 @@ +using System.Data.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace EntityFrameworkCore.Jet.Data.Tests +{ + [TestClass] + public class ExistsTest + { + private const string StoreName = nameof(ExistsTest) + ".accdb"; + + private JetConnection _connection; + + [TestInitialize] + public void Setup() + { + _connection = Helpers.CreateAndOpenDatabase(StoreName); + } + + [TestCleanup] + public void TearDown() + { + _connection?.Close(); + Helpers.DeleteDatabase(StoreName); + } + + [TestMethod] + public void IfExists() + { + using var command = _connection.CreateCommand( + @"IF NOT EXISTS (SELECT * FROM `INFORMATION_SCHEMA.TABLES` WHERE `TABLE_NAME` = '__EFMigrationsHistory') THEN CREATE TABLE `__EFMigrationsHistory` ( + `MigrationId` varchar(150) NOT NULL, + `ProductVersion` varchar(32) NOT NULL, + CONSTRAINT `PK___EFMigrationsHistory` PRIMARY KEY (`MigrationId`) +)"); + command.ExecuteNonQuery(); + } + } +} \ No newline at end of file