Put in the sqlite locker code for windows and unix
This commit is contained in:
parent
9d988fcafe
commit
a42c286d05
2 changed files with 250 additions and 208 deletions
|
|
@ -280,12 +280,15 @@ namespace SQLiteUnix
|
|||
/// </summary>
|
||||
/// <param name="ty">Type to reflect to a database table.</param>
|
||||
public int DropTable(Type ty)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
TableMapping map = GetMapping(ty);
|
||||
var query = string.Format("drop table if exists \"{0}\"", map.TableName);
|
||||
|
||||
return Execute(query);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a "create table if not exists" on the database. It also
|
||||
|
|
@ -312,6 +315,8 @@ namespace SQLiteUnix
|
|||
/// The number of entries added to the database schema.
|
||||
/// </returns>
|
||||
public int CreateTable(Type ty)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
if (_tables == null)
|
||||
{
|
||||
|
|
@ -379,6 +384,7 @@ namespace SQLiteUnix
|
|||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
public class ColumnInfo
|
||||
{
|
||||
|
|
@ -520,6 +526,8 @@ namespace SQLiteUnix
|
|||
}
|
||||
|
||||
public T ExecuteScalar<T>(string query, params object[] args)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
var cmd = CreateCommand(query, args);
|
||||
|
||||
|
|
@ -544,6 +552,7 @@ namespace SQLiteUnix
|
|||
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a SQLiteCommand given the command text (SQL) with arguments. Place a '?'
|
||||
|
|
@ -656,9 +665,12 @@ namespace SQLiteUnix
|
|||
/// queries into native SQL.
|
||||
/// </returns>
|
||||
public ITableQuery<T> Table<T>() where T : new()
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
return new SQLiteUnix.TableQuery<T>(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to retrieve an object with the given primary key from the table
|
||||
|
|
@ -969,6 +981,8 @@ namespace SQLiteUnix
|
|||
/// <see cref="Commit"/>.
|
||||
/// </param>
|
||||
public void RunInTransaction(Action action)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -982,6 +996,7 @@ namespace SQLiteUnix
|
|||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts all specified objects.
|
||||
|
|
@ -993,6 +1008,8 @@ namespace SQLiteUnix
|
|||
/// The number of rows added to the table.
|
||||
/// </returns>
|
||||
public int InsertAll(System.Collections.IEnumerable objects)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
var c = 0;
|
||||
RunInTransaction(() =>
|
||||
|
|
@ -1004,6 +1021,7 @@ namespace SQLiteUnix
|
|||
});
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts all specified objects.
|
||||
|
|
@ -1303,6 +1321,8 @@ namespace SQLiteUnix
|
|||
/// The number of rows deleted.
|
||||
/// </returns>
|
||||
public int Delete(object objectToDelete)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
var map = GetMapping(objectToDelete.GetType());
|
||||
var pk = map.PK;
|
||||
|
|
@ -1313,6 +1333,7 @@ namespace SQLiteUnix
|
|||
var q = string.Format("delete from \"{0}\" where \"{1}\" = ?", map.TableName, pk.Name);
|
||||
return Execute(q, pk.GetValue(objectToDelete));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the object with the specified primary key.
|
||||
|
|
|
|||
|
|
@ -290,12 +290,15 @@ namespace SQLiteWin32
|
|||
/// </summary>
|
||||
/// <param name="ty">Type to reflect to a database table.</param>
|
||||
public int DropTable(Type ty)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
TableMapping map = GetMapping(ty);
|
||||
var query = string.Format("drop table if exists \"{0}\"", map.TableName);
|
||||
|
||||
return Execute(query);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a "create table if not exists" on the database. It also
|
||||
|
|
@ -322,6 +325,8 @@ namespace SQLiteWin32
|
|||
/// The number of entries added to the database schema.
|
||||
/// </returns>
|
||||
public int CreateTable(Type ty)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
if (_tables == null)
|
||||
{
|
||||
|
|
@ -389,6 +394,7 @@ namespace SQLiteWin32
|
|||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
public class ColumnInfo
|
||||
{
|
||||
|
|
@ -530,6 +536,8 @@ namespace SQLiteWin32
|
|||
}
|
||||
|
||||
public T ExecuteScalar<T>(string query, params object[] args)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
var cmd = CreateCommand(query, args);
|
||||
|
||||
|
|
@ -554,6 +562,7 @@ namespace SQLiteWin32
|
|||
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a SQLiteCommand given the command text (SQL) with arguments. Place a '?'
|
||||
|
|
@ -664,9 +673,12 @@ namespace SQLiteWin32
|
|||
/// queries into native SQL.
|
||||
/// </returns>
|
||||
public ITableQuery<T> Table<T>() where T : new()
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
return new TableQuery<T>(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to retrieve an object with the given primary key from the table
|
||||
|
|
@ -977,6 +989,8 @@ namespace SQLiteWin32
|
|||
/// <see cref="Commit"/>.
|
||||
/// </param>
|
||||
public void RunInTransaction(Action action)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -990,6 +1004,7 @@ namespace SQLiteWin32
|
|||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts all specified objects.
|
||||
|
|
@ -1001,6 +1016,8 @@ namespace SQLiteWin32
|
|||
/// The number of rows added to the table.
|
||||
/// </returns>
|
||||
public int InsertAll(System.Collections.IEnumerable objects)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
var c = 0;
|
||||
RunInTransaction(() =>
|
||||
|
|
@ -1012,6 +1029,7 @@ namespace SQLiteWin32
|
|||
});
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts all specified objects.
|
||||
|
|
@ -1313,6 +1331,8 @@ namespace SQLiteWin32
|
|||
/// The number of rows deleted.
|
||||
/// </returns>
|
||||
public int Delete(object objectToDelete)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
var map = GetMapping(objectToDelete.GetType());
|
||||
var pk = map.PK;
|
||||
|
|
@ -1323,6 +1343,7 @@ namespace SQLiteWin32
|
|||
var q = string.Format("delete from \"{0}\" where \"{1}\" = ?", map.TableName, pk.Name);
|
||||
return Execute(q, pk.GetValue(objectToDelete));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the object with the specified primary key.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue