update connections

This commit is contained in:
Luke Pulverenti 2016-11-20 22:52:58 -05:00
parent 985c9111cf
commit 1dc080df8b
12 changed files with 693 additions and 557 deletions

View File

@ -27,6 +27,14 @@ namespace Emby.Server.Implementations.Activity
{
using (var connection = CreateConnection())
{
connection.ExecuteAll(string.Join(";", new[]
{
"pragma default_temp_store = memory",
"pragma default_synchronous=Normal",
"pragma temp_store = memory",
"pragma synchronous=Normal",
}));
string[] queries = {
"create table if not exists ActivityLogEntries (Id GUID PRIMARY KEY, Name TEXT, Overview TEXT, ShortOverview TEXT, Type TEXT, ItemId TEXT, UserId TEXT, DateCreated DATETIME, LogSeverity TEXT)",
@ -51,9 +59,9 @@ namespace Emby.Server.Implementations.Activity
throw new ArgumentNullException("entry");
}
using (WriteLock.Write())
using (var connection = CreateConnection())
{
using (var connection = CreateConnection())
using (WriteLock.Write())
{
connection.RunInTransaction(db =>
{
@ -79,9 +87,9 @@ namespace Emby.Server.Implementations.Activity
public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, int? startIndex, int? limit)
{
using (WriteLock.Read())
using (var connection = CreateConnection(true))
{
using (var connection = CreateConnection(true))
using (WriteLock.Read())
{
var commandText = BaseActivitySelectText;
var whereClauses = new List<string>();

View File

@ -30,11 +30,6 @@ namespace Emby.Server.Implementations.Data
get { return false; }
}
protected virtual bool EnableConnectionPooling
{
get { return true; }
}
static BaseSqliteRepository()
{
SQLite3.EnableSharedCache = false;
@ -45,7 +40,7 @@ namespace Emby.Server.Implementations.Data
private static bool _versionLogged;
protected virtual SQLiteDatabaseConnection CreateConnection(bool isReadOnly = false)
protected SQLiteDatabaseConnection CreateConnection(bool isReadOnly = false, Action<SQLiteDatabaseConnection> onConnect = null)
{
if (!_versionLogged)
{
@ -56,7 +51,7 @@ namespace Emby.Server.Implementations.Data
ConnectionFlags connectionFlags;
//isReadOnly = false;
isReadOnly = false;
if (isReadOnly)
{
@ -70,46 +65,40 @@ namespace Emby.Server.Implementations.Data
connectionFlags |= ConnectionFlags.ReadWrite;
}
if (EnableConnectionPooling)
{
connectionFlags |= ConnectionFlags.SharedCached;
}
else
{
connectionFlags |= ConnectionFlags.PrivateCache;
}
connectionFlags |= ConnectionFlags.SharedCached;
connectionFlags |= ConnectionFlags.NoMutex;
var db = SQLite3.Open(DbFilePath, connectionFlags, null);
var queries = new List<string>
{
"pragma default_temp_store = memory",
"pragma temp_store = memory",
"PRAGMA page_size=4096",
"PRAGMA journal_mode=WAL",
"PRAGMA temp_store=memory",
"PRAGMA synchronous=Normal",
"pragma synchronous=Normal",
//"PRAGMA cache size=-10000"
};
var cacheSize = CacheSize;
if (cacheSize.HasValue)
{
}
if (EnableExclusiveMode)
{
queries.Add("PRAGMA locking_mode=EXCLUSIVE");
}
//foreach (var query in queries)
//var cacheSize = CacheSize;
//if (cacheSize.HasValue)
//{
// db.Execute(query);
//}
db.ExecuteAll(string.Join(";", queries.ToArray()));
////foreach (var query in queries)
////{
//// db.Execute(query);
////}
using (WriteLock.Write())
{
db.ExecuteAll(string.Join(";", queries.ToArray()));
if (onConnect != null)
{
onConnect(db);
}
}
return db;
}
@ -122,11 +111,6 @@ namespace Emby.Server.Implementations.Data
}
}
protected virtual bool EnableExclusiveMode
{
get { return false; }
}
internal static void CheckOk(int rc)
{
string msg = "";

View File

@ -54,9 +54,17 @@ namespace Emby.Server.Implementations.Data
{
using (var connection = CreateConnection())
{
connection.ExecuteAll(string.Join(";", new[]
{
"pragma default_temp_store = memory",
"pragma default_synchronous=Normal",
"pragma temp_store = memory",
"pragma synchronous=Normal",
}));
string[] queries = {
"create table if not exists userdisplaypreferences (id GUID, userId GUID, client text, data BLOB)",
"create table if not exists userdisplaypreferences (id GUID, userId GUID, client text, data BLOB)",
"create unique index if not exists userdisplaypreferencesindex on userdisplaypreferences (id, userId, client)"
};
@ -86,9 +94,9 @@ namespace Emby.Server.Implementations.Data
cancellationToken.ThrowIfCancellationRequested();
using (WriteLock.Write())
using (var connection = CreateConnection())
{
using (var connection = CreateConnection())
using (WriteLock.Write())
{
connection.RunInTransaction(db =>
{
@ -130,9 +138,9 @@ namespace Emby.Server.Implementations.Data
cancellationToken.ThrowIfCancellationRequested();
using (WriteLock.Write())
using (var connection = CreateConnection())
{
using (var connection = CreateConnection())
using (WriteLock.Write())
{
connection.RunInTransaction(db =>
{
@ -162,9 +170,9 @@ namespace Emby.Server.Implementations.Data
var guidId = displayPreferencesId.GetMD5();
using (WriteLock.Read())
using (var connection = CreateConnection(true))
{
using (var connection = CreateConnection(true))
using (WriteLock.Read())
{
using (var statement = connection.PrepareStatement("select data from userdisplaypreferences where id = @id and userId=@userId and client=@client"))
{
@ -196,9 +204,9 @@ namespace Emby.Server.Implementations.Data
{
var list = new List<DisplayPreferences>();
using (WriteLock.Read())
using (var connection = CreateConnection(true))
{
using (var connection = CreateConnection(true))
using (WriteLock.Read())
{
using (var statement = connection.PrepareStatement("select data from userdisplaypreferences where userId=@userId"))
{

View File

@ -131,11 +131,13 @@ namespace Emby.Server.Implementations.Data
public static void Attach(IDatabaseConnection db, string path, string alias)
{
var commandText = string.Format("attach ? as {0};", alias);
var paramList = new List<object>();
paramList.Add(path);
var commandText = string.Format("attach @path as {0};", alias);
db.Execute(commandText, paramList.ToArray());
using (var statement = db.PrepareStatement(commandText))
{
statement.TryBind("@path", path);
statement.MoveNext();
}
}
public static bool IsDBNull(this IReadOnlyList<IResultSetValue> result, int index)

View File

@ -31,6 +31,14 @@ namespace Emby.Server.Implementations.Data
{
using (var connection = CreateConnection())
{
connection.ExecuteAll(string.Join(";", new[]
{
"pragma default_temp_store = memory",
"pragma default_synchronous=Normal",
"pragma temp_store = memory",
"pragma synchronous=Normal",
}));
string[] queries = {
"create table if not exists FileOrganizerResults (ResultId GUID PRIMARY KEY, OriginalPath TEXT, TargetPath TEXT, FileLength INT, OrganizationDate datetime, Status TEXT, OrganizationType TEXT, StatusMessage TEXT, ExtractedName TEXT, ExtractedYear int null, ExtractedSeasonNumber int null, ExtractedEpisodeNumber int null, ExtractedEndingEpisodeNumber, DuplicatePaths TEXT int null)",

File diff suppressed because it is too large Load Diff

View File

@ -14,19 +14,12 @@ namespace Emby.Server.Implementations.Data
{
public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository
{
private SQLiteDatabaseConnection _connection;
public SqliteUserDataRepository(ILogger logger, IApplicationPaths appPaths)
: base(logger)
{
DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db");
}
protected override bool EnableConnectionPooling
{
get { return false; }
}
/// <summary>
/// Gets the name of the repository
/// </summary>
@ -43,13 +36,24 @@ namespace Emby.Server.Implementations.Data
/// Opens the connection to the database
/// </summary>
/// <returns>Task.</returns>
public void Initialize(SQLiteDatabaseConnection connection, ReaderWriterLockSlim writeLock)
public void Initialize(ReaderWriterLockSlim writeLock)
{
WriteLock.Dispose();
WriteLock = writeLock;
_connection = connection;
string[] queries = {
using (var connection = CreateConnection())
{
connection.ExecuteAll(string.Join(";", new[]
{
"pragma default_temp_store = memory",
"pragma default_synchronous=Normal",
"pragma temp_store = memory",
"pragma synchronous=Normal",
}));
string[] queries = {
"PRAGMA locking_mode=NORMAL",
"create table if not exists UserDataDb.userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)",
@ -69,15 +73,16 @@ namespace Emby.Server.Implementations.Data
"pragma shrink_memory"
};
_connection.RunQueries(queries);
connection.RunQueries(queries);
connection.RunInTransaction(db =>
{
var existingColumnNames = GetColumnNames(db, "userdata");
connection.RunInTransaction(db =>
{
var existingColumnNames = GetColumnNames(db, "userdata");
AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames);
AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames);
});
AddColumn(db, "userdata", "AudioStreamIndex", "int", existingColumnNames);
AddColumn(db, "userdata", "SubtitleStreamIndex", "int", existingColumnNames);
});
}
}
/// <summary>
@ -139,18 +144,21 @@ namespace Emby.Server.Implementations.Data
{
cancellationToken.ThrowIfCancellationRequested();
using (WriteLock.Write())
using (var connection = CreateConnection())
{
_connection.RunInTransaction(db =>
using (WriteLock.Write())
{
SaveUserData(db, userId, key, userData);
});
connection.RunInTransaction(db =>
{
SaveUserData(db, userId, key, userData);
});
}
}
}
private void SaveUserData(IDatabaseConnection db, Guid userId, string key, UserItemData userData)
{
using (var statement = _connection.PrepareStatement("replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)"))
using (var statement = db.PrepareStatement("replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)"))
{
statement.TryBind("@UserId", userId.ToGuidParamValue());
statement.TryBind("@Key", key);
@ -207,15 +215,18 @@ namespace Emby.Server.Implementations.Data
{
cancellationToken.ThrowIfCancellationRequested();
using (WriteLock.Write())
using (var connection = CreateConnection())
{
_connection.RunInTransaction(db =>
using (WriteLock.Write())
{
foreach (var userItemData in userDataList)
connection.RunInTransaction(db =>
{
SaveUserData(db, userId, userItemData.Key, userItemData);
}
});
foreach (var userItemData in userDataList)
{
SaveUserData(db, userId, userItemData.Key, userItemData);
}
});
}
}
}
@ -241,16 +252,19 @@ namespace Emby.Server.Implementations.Data
throw new ArgumentNullException("key");
}
using (WriteLock.Write())
using (var connection = CreateConnection(true))
{
using (var statement = _connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key =@Key and userId=@UserId"))
using (WriteLock.Read())
{
statement.TryBind("@UserId", userId.ToGuidParamValue());
statement.TryBind("@Key", key);
foreach (var row in statement.ExecuteQuery())
using (var statement = connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key =@Key and userId=@UserId"))
{
return ReadRow(row);
statement.TryBind("@UserId", userId.ToGuidParamValue());
statement.TryBind("@Key", key);
foreach (var row in statement.ExecuteQuery())
{
return ReadRow(row);
}
}
}
}
@ -291,15 +305,18 @@ namespace Emby.Server.Implementations.Data
var list = new List<UserItemData>();
using (WriteLock.Write())
using (var connection = CreateConnection())
{
using (var statement = _connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=@UserId"))
using (WriteLock.Read())
{
statement.TryBind("@UserId", userId.ToGuidParamValue());
foreach (var row in statement.ExecuteQuery())
using (var statement = connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=@UserId"))
{
list.Add(ReadRow(row));
statement.TryBind("@UserId", userId.ToGuidParamValue());
foreach (var row in statement.ExecuteQuery())
{
list.Add(ReadRow(row));
}
}
}
}

View File

@ -50,6 +50,14 @@ namespace Emby.Server.Implementations.Data
{
using (var connection = CreateConnection())
{
connection.ExecuteAll(string.Join(";", new[]
{
"pragma default_temp_store = memory",
"pragma default_synchronous=Normal",
"pragma temp_store = memory",
"pragma synchronous=Normal",
}));
string[] queries = {
"create table if not exists users (guid GUID primary key, data BLOB)",
@ -83,9 +91,9 @@ namespace Emby.Server.Implementations.Data
cancellationToken.ThrowIfCancellationRequested();
using (WriteLock.Write())
using (var connection = CreateConnection())
{
using (var connection = CreateConnection())
using (WriteLock.Write())
{
connection.RunInTransaction(db =>
{
@ -108,9 +116,9 @@ namespace Emby.Server.Implementations.Data
{
var list = new List<User>();
using (WriteLock.Read())
using (var connection = CreateConnection(true))
{
using (var connection = CreateConnection(true))
using (WriteLock.Read())
{
foreach (var row in connection.Query("select guid,data from users"))
{
@ -146,9 +154,9 @@ namespace Emby.Server.Implementations.Data
cancellationToken.ThrowIfCancellationRequested();
using (WriteLock.Write())
using (var connection = CreateConnection())
{
using (var connection = CreateConnection())
using (WriteLock.Write())
{
connection.RunInTransaction(db =>
{

View File

@ -29,7 +29,16 @@ namespace Emby.Server.Implementations.Notifications
{
using (var connection = CreateConnection())
{
connection.ExecuteAll(string.Join(";", new[]
{
"pragma default_temp_store = memory",
"pragma default_synchronous=Normal",
"pragma temp_store = memory",
"pragma synchronous=Normal",
}));
string[] queries = {
"create table if not exists Notifications (Id GUID NOT NULL, UserId GUID NOT NULL, Date DATETIME NOT NULL, Name TEXT NOT NULL, Description TEXT NULL, Url TEXT NULL, Level TEXT NOT NULL, IsRead BOOLEAN NOT NULL, Category TEXT NOT NULL, RelatedId TEXT NULL, PRIMARY KEY (Id, UserId))",
"create index if not exists idx_Notifications1 on Notifications(Id)",
"create index if not exists idx_Notifications2 on Notifications(UserId)"
@ -103,9 +112,9 @@ namespace Emby.Server.Implementations.Notifications
{
var result = new NotificationsSummary();
using (WriteLock.Read())
using (var connection = CreateConnection(true))
{
using (var connection = CreateConnection(true))
using (WriteLock.Read())
{
using (var statement = connection.PrepareStatement("select Level from Notifications where UserId=@UserId and IsRead=@IsRead"))
{
@ -220,9 +229,9 @@ namespace Emby.Server.Implementations.Notifications
cancellationToken.ThrowIfCancellationRequested();
using (WriteLock.Write())
using (var connection = CreateConnection())
{
using (var connection = CreateConnection())
using (WriteLock.Write())
{
connection.RunInTransaction(conn =>
{
@ -283,9 +292,9 @@ namespace Emby.Server.Implementations.Notifications
{
cancellationToken.ThrowIfCancellationRequested();
using (WriteLock.Write())
using (var connection = CreateConnection())
{
using (var connection = CreateConnection())
using (WriteLock.Write())
{
connection.RunInTransaction(conn =>
{
@ -305,9 +314,9 @@ namespace Emby.Server.Implementations.Notifications
{
cancellationToken.ThrowIfCancellationRequested();
using (WriteLock.Write())
using (var connection = CreateConnection())
{
using (var connection = CreateConnection())
using (WriteLock.Write())
{
connection.RunInTransaction(conn =>
{

View File

@ -30,9 +30,17 @@ namespace Emby.Server.Implementations.Security
{
using (var connection = CreateConnection())
{
connection.ExecuteAll(string.Join(";", new[]
{
"pragma default_temp_store = memory",
"pragma default_synchronous=Normal",
"pragma temp_store = memory",
"pragma synchronous=Normal",
}));
string[] queries = {
"create table if not exists AccessTokens (Id GUID PRIMARY KEY, AccessToken TEXT NOT NULL, DeviceId TEXT, AppName TEXT, AppVersion TEXT, DeviceName TEXT, UserId TEXT, IsActive BIT, DateCreated DATETIME NOT NULL, DateRevoked DATETIME)",
"create table if not exists AccessTokens (Id GUID PRIMARY KEY, AccessToken TEXT NOT NULL, DeviceId TEXT, AppName TEXT, AppVersion TEXT, DeviceName TEXT, UserId TEXT, IsActive BIT, DateCreated DATETIME NOT NULL, DateRevoked DATETIME)",
"create index if not exists idx_AccessTokens on AccessTokens(Id)"
};
@ -63,9 +71,9 @@ namespace Emby.Server.Implementations.Security
cancellationToken.ThrowIfCancellationRequested();
using (WriteLock.Write())
using (var connection = CreateConnection())
{
using (var connection = CreateConnection())
using (WriteLock.Write())
{
connection.RunInTransaction(db =>
{
@ -200,28 +208,31 @@ namespace Emby.Server.Implementations.Security
var list = new List<AuthenticationInfo>();
using (var statement = connection.PrepareStatement(commandText))
using (WriteLock.Read())
{
BindAuthenticationQueryParams(query, statement);
foreach (var row in statement.ExecuteQuery())
using (var statement = connection.PrepareStatement(commandText))
{
list.Add(Get(row));
}
BindAuthenticationQueryParams(query, statement);
using (var totalCountStatement = connection.PrepareStatement("select count (Id) from AccessTokens" + whereTextWithoutPaging))
{
BindAuthenticationQueryParams(query, totalCountStatement);
var count = totalCountStatement.ExecuteQuery()
.SelectScalarInt()
.First();
return new QueryResult<AuthenticationInfo>()
foreach (var row in statement.ExecuteQuery())
{
Items = list.ToArray(),
TotalRecordCount = count
};
list.Add(Get(row));
}
using (var totalCountStatement = connection.PrepareStatement("select count (Id) from AccessTokens" + whereTextWithoutPaging))
{
BindAuthenticationQueryParams(query, totalCountStatement);
var count = totalCountStatement.ExecuteQuery()
.SelectScalarInt()
.First();
return new QueryResult<AuthenticationInfo>()
{
Items = list.ToArray(),
TotalRecordCount = count
};
}
}
}
}
@ -234,9 +245,9 @@ namespace Emby.Server.Implementations.Security
throw new ArgumentNullException("id");
}
using (WriteLock.Read())
using (var connection = CreateConnection(true))
{
using (var connection = CreateConnection(true))
using (WriteLock.Read())
{
var commandText = BaseSelectText + " where Id=@Id";

View File

@ -27,6 +27,14 @@ namespace Emby.Server.Implementations.Social
{
using (var connection = CreateConnection())
{
connection.ExecuteAll(string.Join(";", new[]
{
"pragma default_temp_store = memory",
"pragma default_synchronous=Normal",
"pragma temp_store = memory",
"pragma synchronous=Normal",
}));
string[] queries = {
"create table if not exists Shares (Id GUID, ItemId TEXT, UserId TEXT, ExpirationDate DateTime, PRIMARY KEY (Id))",
@ -50,9 +58,9 @@ namespace Emby.Server.Implementations.Social
throw new ArgumentNullException("info.Id");
}
using (WriteLock.Write())
using (var connection = CreateConnection())
{
using (var connection = CreateConnection())
using (WriteLock.Write())
{
connection.RunInTransaction(db =>
{
@ -75,9 +83,9 @@ namespace Emby.Server.Implementations.Social
throw new ArgumentNullException("id");
}
using (WriteLock.Read())
using (var connection = CreateConnection(true))
{
using (var connection = CreateConnection(true))
using (WriteLock.Read())
{
var commandText = "select Id, ItemId, UserId, ExpirationDate from Shares where id = ?";

View File

@ -43,6 +43,14 @@ namespace Emby.Server.Implementations.Sync
{
using (var connection = CreateConnection())
{
connection.ExecuteAll(string.Join(";", new[]
{
"pragma default_temp_store = memory",
"pragma default_synchronous=Normal",
"pragma temp_store = memory",
"pragma synchronous=Normal",
}));
string[] queries = {
"create table if not exists SyncJobs (Id GUID PRIMARY KEY, TargetId TEXT NOT NULL, Name TEXT NOT NULL, Profile TEXT, Quality TEXT, Bitrate INT, Status TEXT NOT NULL, Progress FLOAT, UserId TEXT NOT NULL, ItemIds TEXT NOT NULL, Category TEXT, ParentId TEXT, UnwatchedOnly BIT, ItemLimit INT, SyncNewContent BIT, DateCreated DateTime, DateLastModified DateTime, ItemCount int)",
@ -95,9 +103,9 @@ namespace Emby.Server.Implementations.Sync
throw new ArgumentNullException("id");
}
using (WriteLock.Read())
using (var connection = CreateConnection(true))
{
using (var connection = CreateConnection(true))
using (WriteLock.Read())
{
var commandText = BaseJobSelectText + " where Id=?";
var paramList = new List<object>();
@ -206,9 +214,9 @@ namespace Emby.Server.Implementations.Sync
CheckDisposed();
using (WriteLock.Write())
using (var connection = CreateConnection())
{
using (var connection = CreateConnection())
using (WriteLock.Write())
{
string commandText;
var paramList = new List<object>();
@ -259,9 +267,9 @@ namespace Emby.Server.Implementations.Sync
CheckDisposed();
using (WriteLock.Write())
using (var connection = CreateConnection())
{
using (var connection = CreateConnection())
using (WriteLock.Write())
{
connection.RunInTransaction(conn =>
{
@ -281,9 +289,9 @@ namespace Emby.Server.Implementations.Sync
CheckDisposed();
using (WriteLock.Read())
using (var connection = CreateConnection(true))
{
using (var connection = CreateConnection(true))
using (WriteLock.Read())
{
var commandText = BaseJobSelectText;
var paramList = new List<object>();
@ -379,11 +387,11 @@ namespace Emby.Server.Implementations.Sync
CheckDisposed();
using (WriteLock.Read())
{
var guid = new Guid(id);
var guid = new Guid(id);
using (var connection = CreateConnection(true))
using (var connection = CreateConnection(true))
{
using (WriteLock.Read())
{
var commandText = BaseJobItemSelectText + " where Id=?";
var paramList = new List<object>();
@ -407,9 +415,9 @@ namespace Emby.Server.Implementations.Sync
throw new ArgumentNullException("query");
}
using (WriteLock.Read())
using (var connection = CreateConnection(true))
{
using (var connection = CreateConnection(true))
using (WriteLock.Read())
{
var commandText = baseSelectText;
var paramList = new List<object>();
@ -487,30 +495,30 @@ namespace Emby.Server.Implementations.Sync
var now = DateTime.UtcNow;
using (WriteLock.Read())
using (var connection = CreateConnection(true))
{
using (var connection = CreateConnection(true))
var commandText = "select ItemId,Status,Progress from SyncJobItems";
var whereClauses = new List<string>();
if (!string.IsNullOrWhiteSpace(query.TargetId))
{
var commandText = "select ItemId,Status,Progress from SyncJobItems";
var whereClauses = new List<string>();
whereClauses.Add("TargetId=@TargetId");
}
if (!string.IsNullOrWhiteSpace(query.TargetId))
{
whereClauses.Add("TargetId=@TargetId");
}
if (query.Statuses.Length > 0)
{
var statuses = string.Join(",", query.Statuses.Select(i => "'" + i.ToString() + "'").ToArray());
if (query.Statuses.Length > 0)
{
var statuses = string.Join(",", query.Statuses.Select(i => "'" + i.ToString() + "'").ToArray());
whereClauses.Add(string.Format("Status in ({0})", statuses));
}
whereClauses.Add(string.Format("Status in ({0})", statuses));
}
if (whereClauses.Count > 0)
{
commandText += " where " + string.Join(" AND ", whereClauses.ToArray());
}
if (whereClauses.Count > 0)
{
commandText += " where " + string.Join(" AND ", whereClauses.ToArray());
}
using (WriteLock.Read())
{
using (var statement = connection.PrepareStatement(commandText))
{
if (!string.IsNullOrWhiteSpace(query.TargetId))
@ -664,9 +672,9 @@ namespace Emby.Server.Implementations.Sync
CheckDisposed();
using (WriteLock.Write())
using (var connection = CreateConnection())
{
using (var connection = CreateConnection())
using (WriteLock.Write())
{
string commandText;