Skip to content

Commit 0b6f093

Browse files
committed
Merge branch 'fixups/tofutim'
2 parents 0de70e2 + 6225a6f commit 0b6f093

25 files changed

+165
-146
lines changed

Appveyor.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

SQLite.Net.OSS.sln

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -356,102 +356,6 @@ Global
356356
{3AB34E91-8E1A-442F-8E66-2494B371A890}.Release|Mixed Platforms.Build.0 = Release|Any CPU
357357
{3AB34E91-8E1A-442F-8E66-2494B371A890}.Release|x64.ActiveCfg = Release|Any CPU
358358
{3AB34E91-8E1A-442F-8E66-2494B371A890}.Release|x86.ActiveCfg = Release|Any CPU
359-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Ad-Hoc|Any CPU.ActiveCfg = Release|Any CPU
360-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Ad-Hoc|Any CPU.Build.0 = Release|Any CPU
361-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Ad-Hoc|ARM.ActiveCfg = Release|ARM
362-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Ad-Hoc|ARM.Build.0 = Release|ARM
363-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU
364-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Release|Any CPU
365-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Ad-Hoc|Mixed Platforms.ActiveCfg = Release|x86
366-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Ad-Hoc|Mixed Platforms.Build.0 = Release|x86
367-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Ad-Hoc|x64.ActiveCfg = Release|Any CPU
368-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Ad-Hoc|x86.ActiveCfg = Release|x86
369-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Ad-Hoc|x86.Build.0 = Release|x86
370-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.AppStore|Any CPU.ActiveCfg = Release|Any CPU
371-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.AppStore|Any CPU.Build.0 = Release|Any CPU
372-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.AppStore|ARM.ActiveCfg = Release|ARM
373-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.AppStore|ARM.Build.0 = Release|ARM
374-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.AppStore|iPhone.ActiveCfg = Release|Any CPU
375-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.AppStore|iPhoneSimulator.ActiveCfg = Release|Any CPU
376-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.AppStore|Mixed Platforms.ActiveCfg = Release|x86
377-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.AppStore|Mixed Platforms.Build.0 = Release|x86
378-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.AppStore|x64.ActiveCfg = Release|Any CPU
379-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.AppStore|x86.ActiveCfg = Release|x86
380-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.AppStore|x86.Build.0 = Release|x86
381-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
382-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
383-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Debug|ARM.ActiveCfg = Debug|ARM
384-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Debug|ARM.Build.0 = Debug|ARM
385-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Debug|iPhone.ActiveCfg = Debug|Any CPU
386-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
387-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
388-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Debug|Mixed Platforms.Build.0 = Debug|x86
389-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Debug|x64.ActiveCfg = Debug|Any CPU
390-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Debug|x86.ActiveCfg = Debug|x86
391-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Debug|x86.Build.0 = Debug|x86
392-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
393-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Release|Any CPU.Build.0 = Release|Any CPU
394-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Release|ARM.ActiveCfg = Release|ARM
395-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Release|ARM.Build.0 = Release|ARM
396-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Release|iPhone.ActiveCfg = Release|Any CPU
397-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
398-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Release|Mixed Platforms.ActiveCfg = Release|x86
399-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Release|Mixed Platforms.Build.0 = Release|x86
400-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Release|x64.ActiveCfg = Release|Any CPU
401-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Release|x86.ActiveCfg = Release|x86
402-
{38AF8105-65B6-4A14-A258-1137D9E40EF1}.Release|x86.Build.0 = Release|x86
403-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Ad-Hoc|Any CPU.ActiveCfg = Release|x86
404-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Ad-Hoc|ARM.ActiveCfg = Release|ARM
405-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Ad-Hoc|ARM.Build.0 = Release|ARM
406-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Ad-Hoc|ARM.Deploy.0 = Release|ARM
407-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Ad-Hoc|iPhone.ActiveCfg = Release|x86
408-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Release|x86
409-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Ad-Hoc|Mixed Platforms.ActiveCfg = Release|x86
410-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Ad-Hoc|Mixed Platforms.Build.0 = Release|x86
411-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Ad-Hoc|Mixed Platforms.Deploy.0 = Release|x86
412-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Ad-Hoc|x64.ActiveCfg = Release|x86
413-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Ad-Hoc|x86.ActiveCfg = Release|x86
414-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Ad-Hoc|x86.Build.0 = Release|x86
415-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Ad-Hoc|x86.Deploy.0 = Release|x86
416-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.AppStore|Any CPU.ActiveCfg = Release|x86
417-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.AppStore|ARM.ActiveCfg = Release|ARM
418-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.AppStore|ARM.Build.0 = Release|ARM
419-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.AppStore|ARM.Deploy.0 = Release|ARM
420-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.AppStore|iPhone.ActiveCfg = Release|x86
421-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.AppStore|iPhoneSimulator.ActiveCfg = Release|x86
422-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.AppStore|Mixed Platforms.ActiveCfg = Release|x86
423-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.AppStore|Mixed Platforms.Build.0 = Release|x86
424-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.AppStore|Mixed Platforms.Deploy.0 = Release|x86
425-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.AppStore|x64.ActiveCfg = Release|x86
426-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.AppStore|x86.ActiveCfg = Release|x86
427-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.AppStore|x86.Build.0 = Release|x86
428-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.AppStore|x86.Deploy.0 = Release|x86
429-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Debug|Any CPU.ActiveCfg = Debug|x86
430-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Debug|ARM.ActiveCfg = Debug|ARM
431-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Debug|ARM.Build.0 = Debug|ARM
432-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Debug|ARM.Deploy.0 = Debug|ARM
433-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Debug|iPhone.ActiveCfg = Debug|x86
434-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Debug|iPhoneSimulator.ActiveCfg = Debug|x86
435-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
436-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Debug|Mixed Platforms.Build.0 = Debug|x86
437-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Debug|Mixed Platforms.Deploy.0 = Debug|x86
438-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Debug|x64.ActiveCfg = Debug|x86
439-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Debug|x86.ActiveCfg = Debug|x86
440-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Debug|x86.Build.0 = Debug|x86
441-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Debug|x86.Deploy.0 = Debug|x86
442-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Release|Any CPU.ActiveCfg = Release|x86
443-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Release|ARM.ActiveCfg = Release|ARM
444-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Release|ARM.Build.0 = Release|ARM
445-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Release|ARM.Deploy.0 = Release|ARM
446-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Release|iPhone.ActiveCfg = Release|x86
447-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Release|iPhoneSimulator.ActiveCfg = Release|x86
448-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Release|Mixed Platforms.ActiveCfg = Release|x86
449-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Release|Mixed Platforms.Build.0 = Release|x86
450-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Release|Mixed Platforms.Deploy.0 = Release|x86
451-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Release|x64.ActiveCfg = Release|x86
452-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Release|x86.ActiveCfg = Release|x86
453-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Release|x86.Build.0 = Release|x86
454-
{46DF3E43-6B65-4C3D-8911-64FCC301040F}.Release|x86.Deploy.0 = Release|x86
455359
EndGlobalSection
456360
GlobalSection(SolutionProperties) = preSolution
457361
HideSolutionNode = FALSE
@@ -462,7 +366,5 @@ Global
462366
{F662E15A-8753-468E-A67E-3FCF45F12B89} = {59584026-7610-4CD5-A74E-D2B0A2E1CE87}
463367
{C129735F-5D4B-40BE-9410-F43E548FFF5E} = {0C4021EF-617B-4620-ADD3-A702B4F9FA86}
464368
{9E5D6B89-B69B-486B-9F7B-406BE8690589} = {49C7015B-F41A-47A6-8200-B925902E74E9}
465-
{38AF8105-65B6-4A14-A258-1137D9E40EF1} = {59584026-7610-4CD5-A74E-D2B0A2E1CE87}
466-
{46DF3E43-6B65-4C3D-8911-64FCC301040F} = {0C4021EF-617B-4620-ADD3-A702B4F9FA86}
467369
EndGlobalSection
468370
EndGlobal

appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build:
2+
project: SQLite.Net.OSS.sln

src/SQLite.Net.Async/SQLiteAsyncConnection.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,36 @@ public Task<T> ExecuteScalarAsync<T>(CancellationToken cancellationToken, [NotNu
547547
}, cancellationToken, _taskCreationOptions, _taskScheduler ?? TaskScheduler.Default);
548548
}
549549

550+
[PublicAPI]
551+
public Task ExecuteNonQueryAsync([NotNull] string sql, [NotNull] params object[] args)
552+
{
553+
return ExecuteNonQueryAsync(CancellationToken.None, sql, args);
554+
}
555+
556+
[PublicAPI]
557+
public Task ExecuteNonQueryAsync(CancellationToken cancellationToken, [NotNull] string sql, [NotNull] params object[] args)
558+
{
559+
if (sql == null)
560+
{
561+
throw new ArgumentNullException("sql");
562+
}
563+
if (args == null)
564+
{
565+
throw new ArgumentNullException("args");
566+
}
567+
return Task.Factory.StartNew(() =>
568+
{
569+
cancellationToken.ThrowIfCancellationRequested();
570+
var conn = GetConnection();
571+
using (conn.Lock())
572+
{
573+
cancellationToken.ThrowIfCancellationRequested();
574+
var command = conn.CreateCommand(sql, args);
575+
command.ExecuteNonQuery();
576+
}
577+
}, cancellationToken, _taskCreationOptions, _taskScheduler ?? TaskScheduler.Default);
578+
}
579+
550580
[PublicAPI]
551581
public Task<List<T>> QueryAsync<T>([NotNull] string sql, [NotNull] params object[] args)
552582
where T : class

src/SQLite.Net.Platform.XamarinAndroid/SQLite.Net.Platform.XamarinAndroid.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<FileAlignment>512</FileAlignment>
1515
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
1616
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
17+
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
18+
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
1719
</PropertyGroup>
1820
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1921
<DebugSymbols>true</DebugSymbols>

src/SQLite.Net/PreparedSqlLiteInsertCommand.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using System;
2525
using JetBrains.Annotations;
2626
using SQLite.Net.Interop;
27+
using System.Diagnostics;
2728

2829
namespace SQLite.Net
2930
{
@@ -63,11 +64,12 @@ public void Dispose()
6364
Dispose(false);
6465
}
6566

67+
static readonly object _locker = new object();
68+
6669
[PublicAPI]
6770
public int ExecuteNonQuery(object[] source)
6871
{
6972
Connection.TraceListener.WriteLine("Executing: {0}", CommandText);
70-
7173
if (!Initialized)
7274
{
7375
Statement = Prepare();
@@ -84,7 +86,12 @@ public int ExecuteNonQuery(object[] source)
8486
Connection.StoreDateTimeAsTicks, Connection.Serializer);
8587
}
8688
}
87-
var r = sqlitePlatform.SQLiteApi.Step(Statement);
89+
90+
Result r;
91+
lock (_locker)
92+
{
93+
r = sqlitePlatform.SQLiteApi.Step(Statement);
94+
}
8895

8996
if (r == Result.Done)
9097
{
@@ -104,6 +111,7 @@ public int ExecuteNonQuery(object[] source)
104111
throw NotNullConstraintViolationException.New(r, sqlitePlatform.SQLiteApi.Errmsg16(Connection.Handle));
105112
}
106113
sqlitePlatform.SQLiteApi.Reset(Statement);
114+
107115
throw SQLiteException.New(r, r.ToString());
108116
}
109117

@@ -130,4 +138,4 @@ private void Dispose(bool disposing)
130138
}
131139
}
132140
}
133-
}
141+
}

tests/AsyncTests.cs

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using PCLStorage;
99
using SQLite.Net.Async;
1010
using SQLite.Net.Attributes;
11+
using System.Diagnostics;
1112

1213

1314
namespace SQLite.Net.Tests
@@ -161,27 +162,54 @@ public async Task GetAsync()
161162
Assert.AreEqual(customer.Id, loaded.Id);
162163
}
163164

165+
164166
[Test]
165167
public async Task StressAsync()
166168
{
169+
const int defaultBusyTimeout = 100;
170+
167171
SQLiteAsyncConnection globalConn = GetAsyncConnection();
168172

173+
// see http://stackoverflow.com/questions/12004426/sqlite-returns-sqlite-busy-in-wal-mode
174+
var journalMode = await globalConn.ExecuteScalarAsync<string>("PRAGMA journal_mode = wal"); // = wal");
175+
Debug.WriteLine("journal_mode: " + journalMode);
176+
//var synchronous = await globalConn.ExecuteScalarAsync<string>("PRAGMA synchronous"); // 2 = FULL
177+
//Debug.WriteLine("synchronous: " + synchronous);
178+
//var pageSize = await globalConn.ExecuteScalarAsync<string>("PRAGMA page_size"); // 1024 default
179+
//Debug.WriteLine("page_size: " + pageSize);
180+
var busyTimeout = await globalConn.ExecuteScalarAsync<string>(
181+
string.Format("PRAGMA busy_timeout = {0}", defaultBusyTimeout));
182+
Debug.WriteLine("busy_timeout: " + busyTimeout);
183+
169184
await globalConn.CreateTableAsync<Customer>();
170185

171186
int n = 500;
172187
var errors = new List<string>();
173188
var tasks = new List<Task>();
174189
for (int i = 0; i < n; i++)
175190
{
176-
tasks.Add(Task.Factory.StartNew(async delegate
191+
int taskId = i;
192+
193+
tasks.Add(Task.Run(async () =>
177194
{
195+
string taskStep = "";
196+
178197
try
179198
{
199+
taskStep = "CONNECT";
180200
SQLiteAsyncConnection conn = GetAsyncConnection();
201+
202+
// each connection retains the global journal_mode but somehow resets busy_timeout to 100
203+
busyTimeout = await globalConn.ExecuteScalarAsync<string>(
204+
string.Format("PRAGMA busy_timeout = {0}", defaultBusyTimeout));
205+
// Debug.WriteLine("busy_timeout: " + busyTimeout);
206+
181207
var obj = new Customer
182208
{
183-
FirstName = i.ToString(),
209+
FirstName = taskId.ToString(),
184210
};
211+
212+
taskStep = "INSERT";
185213
await conn.InsertAsync(obj);
186214

187215
if (obj.Id == 0)
@@ -191,6 +219,8 @@ public async Task StressAsync()
191219
errors.Add("Bad Id");
192220
}
193221
}
222+
223+
taskStep = "SELECT";
194224
var obj3 = await (from c in conn.Table<Customer>() where c.Id == obj.Id select c).ToListAsync();
195225
Customer obj2 = obj3.FirstOrDefault();
196226
if (obj2 == null)
@@ -200,22 +230,35 @@ public async Task StressAsync()
200230
errors.Add("Failed query");
201231
}
202232
}
233+
234+
// Debug.WriteLine("task {0} with id {1} and name {2}", taskId, obj.Id, obj.FirstName);
203235
}
204236
catch (Exception ex)
205237
{
206238
lock (errors)
207239
{
208-
errors.Add(ex.Message);
240+
errors.Add(string.Format("{0}: {1}", taskStep, ex.Message));
209241
}
210242
}
211243
}));
212244
}
213245

214246
await Task.WhenAll(tasks);
247+
Assert.AreEqual(n, tasks.Where(t => t.IsCompleted).Count());
248+
249+
//int j = 0;
250+
//foreach (var error in errors)
251+
//{
252+
// Debug.WriteLine("{0} {1}", j++, error);
253+
//}
254+
255+
Assert.AreEqual(0, errors.Count, "Error in task runs");
256+
215257
int count = await globalConn.Table<Customer>().CountAsync();
258+
Assert.AreEqual(n, count, "Not enough items in table");
216259

217-
Assert.AreEqual(0, errors.Count);
218-
Assert.AreEqual(n, count);
260+
// TODO: get out of wal mode - currently fails with 'database is locked'
261+
// journalMode = await globalConn.ExecuteScalarAsync<string>("PRAGMA journal_mode = delete");
219262
}
220263

221264
[Test]
@@ -1079,4 +1122,4 @@ public async Task TestGetMappingAsync()
10791122
Assert.AreEqual("AGoodColumnName", mapping.Columns[1].Name);
10801123
}
10811124
}
1082-
}
1125+
}

0 commit comments

Comments
 (0)