From 539f495dbea611a8a74221d315802c781b1b9269 Mon Sep 17 00:00:00 2001 From: ta264 Date: Mon, 20 Jul 2020 21:02:09 +0100 Subject: [PATCH] Fixed: SqliteSchemaDumper with separate Primary Key clause --- .../SqliteSchemaDumperTests/SqliteSchemaDumperFixture.cs | 6 ++++++ .../Datastore/Migration/Framework/SqliteSyntaxReader.cs | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core.Test/Datastore/SqliteSchemaDumperTests/SqliteSchemaDumperFixture.cs b/src/NzbDrone.Core.Test/Datastore/SqliteSchemaDumperTests/SqliteSchemaDumperFixture.cs index 64efa19ba..b1ecba40f 100644 --- a/src/NzbDrone.Core.Test/Datastore/SqliteSchemaDumperTests/SqliteSchemaDumperFixture.cs +++ b/src/NzbDrone.Core.Test/Datastore/SqliteSchemaDumperTests/SqliteSchemaDumperFixture.cs @@ -25,6 +25,12 @@ namespace NzbDrone.Core.Test.Datastore.SqliteSchemaDumperTests [TestCase(@"CREATE TABLE ""Test """"Table"" (""My""""Id"" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT)", "Test \"Table", "My\"Id")] [TestCase(@"CREATE TABLE [Test Table] ([My Id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT)", "Test Table", "My Id")] [TestCase(@" CREATE TABLE `Test ``Table` ( `My`` Id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT ) ", "Test `Table", "My` Id")] + [TestCase(@"CREATE TABLE IF NOT EXISTS ""Test Table"" ( + ""MyId"" INTEGER NOT NULL, + PRIMARY KEY(""MyId"" AUTOINCREMENT) +);", + "Test Table", + "MyId")] public void should_parse_table_language_flavors(string sql, string tableName, string columnName) { var result = Subject.ReadTableSchema(sql); diff --git a/src/NzbDrone.Core/Datastore/Migration/Framework/SqliteSyntaxReader.cs b/src/NzbDrone.Core/Datastore/Migration/Framework/SqliteSyntaxReader.cs index 6c76fbdc1..77d53175c 100644 --- a/src/NzbDrone.Core/Datastore/Migration/Framework/SqliteSyntaxReader.cs +++ b/src/NzbDrone.Core/Datastore/Migration/Framework/SqliteSyntaxReader.cs @@ -154,12 +154,12 @@ namespace NzbDrone.Core.Datastore.Migration.Framework { var start = Index; var end = start + 1; - while (end < Buffer.Length && (char.IsLetter(Buffer[end]) || char.IsNumber(Buffer[end]) || Buffer[end] == '_' || Buffer[end] == '(')) + while (end < Buffer.Length && (char.IsLetter(Buffer[end]) || char.IsNumber(Buffer[end]) || Buffer[end] == '_')) { end++; } - if (end >= Buffer.Length || Buffer[end] == ',' || Buffer[end] == ')' || char.IsWhiteSpace(Buffer[end])) + if (end >= Buffer.Length || Buffer[end] == ',' || Buffer[end] == ')' || Buffer[end] == '(' || char.IsWhiteSpace(Buffer[end])) { Index = end; }