1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-25 17:17:02 +00:00

PetaPoco now defaults to SQLite, requires WHERE on exists calls

This commit is contained in:
kay.one 2011-06-19 22:08:58 -07:00
parent 852b1e9bb5
commit 907c508a70
3 changed files with 40 additions and 5 deletions

View file

@ -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 @@ public void Test_Storage_no_allowed()
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<QualityProfile>(id);
//Update
currentProfile.Cutoff = QualityTypes.Bluray720p;
mocker.Resolve<QualityProvider>().Update(currentProfile);
var updated = mocker.Resolve<QualityProvider>().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()
{

View file

@ -316,7 +316,7 @@ enum DBType
Oracle,
SQLite
}
DBType _dbType = DBType.SqlServer;
DBType _dbType = DBType.SQLite;
// Common initialization
private void CommonConstruct()
@ -1256,18 +1256,18 @@ public bool Exists<T>(string sql, params object[] args)
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;
}
}

View file

@ -80,7 +80,7 @@ public virtual EpisodeFile ImportFile(Series series, string filePath)
{
Logger.Trace("Importing file to database [{0}]", filePath);
if (_database.Exists<EpisodeFile>("Path =@0", Parser.NormalizePath(filePath)))
if (_database.Exists<EpisodeFile>("WHERE Path =@0", Parser.NormalizePath(filePath)))
{
Logger.Trace("[{0}] already exists in the database. skipping.", filePath);
return null;