zhaolei
9 days ago 921de2254ff5712a44ed8575ee8efe34252f6603
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Data;
using System.Data.Common;
using System.Threading;
using System.Threading.Tasks;
using PetaPoco.Core;
 
namespace PetaPoco.Providers
{
    public class SQLiteDatabaseProvider : DatabaseProvider
    {
        public override DbProviderFactory GetFactory()
            => GetFactory("System.Data.SQLite.SQLiteFactory, System.Data.SQLite", "Microsoft.Data.Sqlite.SqliteFactory, Microsoft.Data.Sqlite");
 
        public override object MapParameterValue(object value)
        {
            if (value is uint u)
                return (long) u;
 
            return base.MapParameterValue(value);
        }
 
        public override object ExecuteInsert(Database db, IDbCommand cmd, string primaryKeyName)
        {
            if (primaryKeyName != null)
            {
                cmd.CommandText += ";\nSELECT last_insert_rowid();";
                return ExecuteScalarHelper(db, cmd);
            }
 
            ExecuteNonQueryHelper(db, cmd);
            return -1;
        }
 
#if ASYNC
 
        public override async Task<object> ExecuteInsertAsync(CancellationToken cancellationToken, Database db, IDbCommand cmd, string primaryKeyName)
        {
            if (primaryKeyName != null)
            {
                cmd.CommandText += ";\nSELECT last_insert_rowid();";
                return await ExecuteScalarHelperAsync(cancellationToken, db, cmd);
            }
 
            await ExecuteNonQueryHelperAsync(cancellationToken, db, cmd);
            return -1;
        }
 
#endif
 
        public override string GetExistsSql()
            => "SELECT EXISTS (SELECT 1 FROM {0} WHERE {1})";
    }
}