From 907c508a70b6ef20accbe3fc8ad88672b4a8b974 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 19 Jun 2011 22:08:58 -0700 Subject: [PATCH] PetaPoco now defaults to SQLite, requires WHERE on exists calls --- NzbDrone.Core.Test/QualityProfileTest.cs | 35 ++++++++++++++++++++ NzbDrone.Core/Datastore/PetaPoco/PetaPoco.cs | 8 ++--- NzbDrone.Core/Providers/DiskScanProvider.cs | 2 +- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/NzbDrone.Core.Test/QualityProfileTest.cs b/NzbDrone.Core.Test/QualityProfileTest.cs index f1b04f53c..af617b935 100644 --- a/NzbDrone.Core.Test/QualityProfileTest.cs +++ b/NzbDrone.Core.Test/QualityProfileTest.cs @@ -1,9 +1,11 @@ // ReSharper disable RedundantUsingDirective using System; using System.Collections.Generic; +using AutoMoq; using FizzWare.NBuilder; using FluentAssertions; using NUnit.Framework; +using NzbDrone.Core.Providers; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; @@ -63,6 +65,39 @@ namespace NzbDrone.Core.Test fetch.Allowed.Should().HaveCount(0); } + + [Test] + public void Update_Success() + { + //Arrange + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + var testProfile = new QualityProfile + { + Name = Guid.NewGuid().ToString(), + Cutoff = QualityTypes.SDTV + }; + + //Act + var id = Convert.ToInt32(db.Insert(testProfile)); + var currentProfile = db.SingleOrDefault(id); + + + //Update + currentProfile.Cutoff = QualityTypes.Bluray720p; + mocker.Resolve().Update(currentProfile); + + var updated = mocker.Resolve().Get(currentProfile.QualityProfileId); + + //Assert + updated.Name.Should().Be(currentProfile.Name); + updated.Cutoff.Should().Be(QualityTypes.Bluray720p); + updated.AllowedString.Should().Be(currentProfile.AllowedString); + + } + [Test] public void Test_Series_Quality() { diff --git a/NzbDrone.Core/Datastore/PetaPoco/PetaPoco.cs b/NzbDrone.Core/Datastore/PetaPoco/PetaPoco.cs index 0d040ef12..dd96d0737 100644 --- a/NzbDrone.Core/Datastore/PetaPoco/PetaPoco.cs +++ b/NzbDrone.Core/Datastore/PetaPoco/PetaPoco.cs @@ -316,7 +316,7 @@ namespace PetaPoco Oracle, SQLite } - DBType _dbType = DBType.SqlServer; + DBType _dbType = DBType.SQLite; // Common initialization private void CommonConstruct() @@ -1256,18 +1256,18 @@ namespace PetaPoco case DBType.SQLite: case DBType.MySql: { - existsTemplate = "SELECT EXISTS (SELECT 1 FROM {0} WHERE {1})"; + existsTemplate = "SELECT EXISTS (SELECT 1 FROM {0} {1})"; break; } case DBType.SqlServer: { - existsTemplate = "IF EXISTS (SELECT 1 FROM {0} WHERE {1}) SELECT 1 ELSE SELECT 0"; + existsTemplate = "IF EXISTS (SELECT 1 FROM {0} {1}) SELECT 1 ELSE SELECT 0"; break; } default: { - existsTemplate = "SELECT COUNT(*) FROM {0} WHERE {1}"; + existsTemplate = "SELECT COUNT(*) FROM {0} {1}"; break; } } diff --git a/NzbDrone.Core/Providers/DiskScanProvider.cs b/NzbDrone.Core/Providers/DiskScanProvider.cs index 49a491129..7db6809b5 100644 --- a/NzbDrone.Core/Providers/DiskScanProvider.cs +++ b/NzbDrone.Core/Providers/DiskScanProvider.cs @@ -80,7 +80,7 @@ namespace NzbDrone.Core.Providers { Logger.Trace("Importing file to database [{0}]", filePath); - if (_database.Exists("Path =@0", Parser.NormalizePath(filePath))) + if (_database.Exists("WHERE Path =@0", Parser.NormalizePath(filePath))) { Logger.Trace("[{0}] already exists in the database. skipping.", filePath); return null;