本文整理汇总了C#中SQLite.SQLiteConnection.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection.BeginTransaction方法的具体用法?C# SQLiteConnection.BeginTransaction怎么用?C# SQLiteConnection.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLite.SQLiteConnection
的用法示例。
在下文中一共展示了SQLiteConnection.BeginTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FetchRSSAsync
static async void FetchRSSAsync(Block completionBlock)
{
using (var wc = new WebClient()) {
string url = "http://forums.bignerdranch.com/smartfeed.php?limit=7_DAY&count_limit=25&sort_by=standard&feed_type=RSS2.0&feed_style=COMPACT"; // count_limit=10&
try {
string xmlData = await wc.DownloadStringTaskAsync(new Uri(url));
XDocument doc = XDocument.Parse(xmlData);
channel.parseXML(doc);
var allItems = doc.Descendants("item");
string dbPath = GetDBPath();
SQLiteConnection db;
db = new SQLiteConnection(dbPath);
db.BeginTransaction();
foreach (XElement current in allItems) {
RSSItem item = new RSSItem();
item.parseXML(current);
item.type = "post";
bool inItems = false;
foreach(RSSItem i in items) {
if (i.link == item.link)
inItems = true;
}
int index = 0;
if (!inItems) {
items.Insert(index++, item);
db.Insert(item);
if (db.Table<RSSItem>().Count() > 100) {
db.Query<RSSItem>("DELETE FROM RSSItems WHERE rowid IN (SELECT rowid FROM RSSItems ORDER BY rowid ASC LIMIT 1)");
}
Console.WriteLine("Items in table: {0} ItemID: {1}", db.Table<RSSItem>().Count(), item.ID);
}
}
db.Commit();
db.Close();
db = null;
completionBlock("success");
}
catch (WebException ex) {
Console.WriteLine("Exception: {0}", ex.Message);
completionBlock(ex.Message);
}
}
}
示例2: GetListOfBeacons
public List<Beacon> GetListOfBeacons()
{
lock (dbLock)
{
using (var sqlCon = new SQLiteConnection(DBPath))
{
sqlCon.Execute(Constants.DBClauseSyncOff);
sqlCon.BeginTransaction();
var data = sqlCon.Query<Beacon>("SELECT * FROM Beacon");
return data;
}
}
}
示例3: CreateTables
public static void CreateTables(SQLiteConnection db)
{
db.BeginTransaction();
db.CreateTable<DriveInformation>();
db.CreateTable<DirectoryInformation>();
db.CreateTable<FileInformation>();
db.CreateTable<FileAttributeInformation>();
db.CreateTable<FileAttribute>();
db.Execute("CREATE INDEX if not exists \"main\".\"ix_DirectoryInformation_driveid_path\" ON \"DirectoryInformation\" (\"DriveId\" ASC, \"Path\" ASC)");
db.Execute("CREATE INDEX if not exists \"main\".\"ix_FileInformation_driveid_directoryid\" ON \"FileInformation\" (\"DirectoryId\" ASC, \"DriveId\" ASC)");
db.Commit();
}
示例4: addAssetType
// public static bool saveChanges()
// {
// // Save to db
// string dbPath = GetDBPath();
// var db = new SQLiteConnection(dbPath);
// db.DeleteAll<BNRItem>();
// db.BeginTransaction();
// db.InsertAll(allItems);
// db.Commit();
// db.Close();
// return true;
// Archive method of saving
// // returns success or failure // For archiving method of saving
// string path = itemArchivePath(); // For archiving method of saving
// NSMutableArray newArray = new NSMutableArray(); // For archiving method of saving
// foreach (BNRItem item in allItems) { // For archiving method of saving
// newArray.Add(item); // For archiving method of saving
// } // For archiving method of saving
// return NSKeyedArchiver.ArchiveRootObjectToFile(newArray, path); // For archiving method of saving
// }
public static void addAssetType(string assetType)
{
string dbPath = GetDBPath();
SQLiteConnection db;
if (File.Exists(dbPath)) {
db = new SQLiteConnection(dbPath);
db.BeginTransaction();
var at = new BNRAssetType();
at.assetType = assetType;
allAssetTypes.Add(at);
db.Insert(at);
db.Commit();
db.Close();
}
}
示例5: Cache
private void Cache(IEnumerable<Scrobble> scrobbles)
{
using (var db = new SQLiteConnection(DatabasePath, SQLiteOpenFlags.ReadWrite))
{
var tableInfo = db.GetTableInfo(typeof (Scrobble).Name);
if (!tableInfo.Any())
{
db.CreateTable<Scrobble>();
}
db.BeginTransaction();
foreach (var scrobble in scrobbles)
{
db.Insert(scrobble);
}
db.Commit();
db.Close();
}
}
示例6: CleanUpDB
public void CleanUpDB()
{
lock (this.dbLock)
{
using (SQLiteConnection sqlCon = new SQLiteConnection(this.DBPath))
{
sqlCon.Execute(Constants.DBClauseSyncOff);
sqlCon.BeginTransaction();
try
{
sqlCon.Execute("DELETE FROM Beacon");
sqlCon.Commit();
sqlCon.Execute(Constants.DBClauseVacuum);
}
catch (Exception ex)
{
#if(DEBUG)
System.Diagnostics.Debug.WriteLine("Error in CleanUpDB! {0}--{1}", ex.Message, ex.StackTrace);
#endif
sqlCon.Rollback();
}
}
}
}
示例7: ProcessFolder
private static void ProcessFolder(SQLiteConnection db, DriveInformation drive, List<string> arrHeaders, DirectoryInfo directory)
{
try {
if (!directory.Exists)
return;
if (IgnoreFolder(directory)) {
return;
}
//go get the cached items for the folder.
var directoryId = DatabaseLookups.GetDirectoryId(db, drive, directory);
var cmd = db.CreateCommand("Select * from " + typeof(FileInformation).Name + " Where DriveId = ? AND DirectoryId = ?", drive.DriveId, directoryId);
var databaseFiles = cmd.ExecuteQuery<FileInformation>();
//obtain the file metadata for all of the files in the directory so we can determine if we care about this folder.
var processList = GetFilesToProcess(databaseFiles, arrHeaders, directory);
if (processList.Count > 0) {
db.BeginTransaction();
Shell32.Shell shell = new Shell32.Shell();
Shell32.Folder folder = shell.NameSpace(directory.FullName);
foreach (var item in processList) {
try {
var fi = item.FileInfo;
var headerList = new List<FileAttributeInformation>();
for (int i = 0; i < arrHeaders.Count; i++) {
var header = arrHeaders[i];
if (!IgnoreHeader(header)) {
var value = folder.GetDetailsOf(item.FolderItem, i);
if (!string.IsNullOrWhiteSpace(value)) {
headerList.Add(new FileAttributeInformation() {
AttributeId = DatabaseLookups.GetAttributeId(db, header),
Value = value
});
}
}
}
//this should have been already checked but we want to be safe.
if (fi.Exists) {
var fileInfo = databaseFiles.FirstOrDefault(info => info.FileName.Equals(fi.Name, StringComparison.OrdinalIgnoreCase));
if (fileInfo == null) {
fileInfo = new FileInformation() {
DriveId = drive.DriveId,
DirectoryId = directoryId,
FileName = fi.Name
};
SetFileInformation(fi, fileInfo);
db.Insert(fileInfo);
Console.WriteLine("Inserted:" + fi.FullName);
}
else {
SetFileInformation(fi, fileInfo);
db.Update(fileInfo);
var deleteCount = db.Execute("Delete from " + typeof(FileAttributeInformation).Name + " WHERE FileId = ?", fileInfo.FileId);
Console.WriteLine("Changed:" + fi.FullName);
}
//save the headers
headerList.ForEach(hl => hl.FileId = fileInfo.FileId);
db.InsertAll(headerList);
}
}
catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
}
db.Commit();
}
//see if we have any additional folders. If we get access denied it will throw an error
try {
foreach (var subDirectory in directory.GetDirectories()) {
ProcessFolder(db, drive, arrHeaders, subDirectory);
}
}
catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
}
catch (UnauthorizedAccessException) {
}
//.........这里部分代码省略.........
示例8: DeleteMessages
public void DeleteMessages(List<MessageDB> messages)
{
lock (this.dbLock)
{
using (SQLiteConnection sqlCon = new SQLiteConnection(this.DBPath))
{
sqlCon.Execute(WZConstants.DBClauseSyncOff);
sqlCon.BeginTransaction();
try
{
foreach (MessageDB eachMessageDB in messages)
{
eachMessageDB.MessageStepDBList.ForEach(step => {
sqlCon.Execute("DELETE FROM MessageStepDB WHERE StepID=?", step.StepGuid);
});
eachMessageDB.MessageRecipientDBList.ForEach(s => {
sqlCon.Execute("DELETE FROM MessageRecipientDB WHERE AccountGuid=? AND MessageGuid=?", s.AccountGuid, s.MessageGuid);
});
sqlCon.Execute("DELETE FROM MessageDB WHERE MessageGuid=?", eachMessageDB.MessageGuid);
}//end foreach
sqlCon.Commit();
} catch (Exception ex)
{
#if(DEBUG)
Console.WriteLine("Error in DeleteMessages! {0}--{1}", ex.Message, ex.StackTrace);
#endif
sqlCon.Rollback();
}//end try catch
}//end using sqlCon
}//end using lock
}
示例9: DeleteContentInfoIfExists
public void DeleteContentInfoIfExists(ContentInfo contentInfo)
{
lock (this.dbLock)
{
using (SQLiteConnection sqlCon = new SQLiteConnection(this.DBPath))
{
sqlCon.Execute(WZConstants.DBClauseSyncOff);
sqlCon.BeginTransaction();
try
{
ContentInfo contentInfoToDelete =
sqlCon.Query<ContentInfo>("SELECT * FROM ContentInfo WHERE ID=?", contentInfo.ID)
.FirstOrDefault();
if (null != contentInfoToDelete)
{
// Take care of the message first.
MessageDB messageDB = sqlCon.Query<MessageDB>("SELECT * FROM MessageDB WHERE ID=?", contentInfo.MessageDBID)
.FirstOrDefault();
if (messageDB.MessageID == default(Guid))
{
// Delete it, because the message has already been inserted from message create.
sqlCon.Execute("DELETE FROM MessageDB WHERE ID=?", messageDB.ID);
}//end if
sqlCon.Execute("DELETE FROM VoiceCache WHERE ContentInfoID=?", contentInfo.ID);
sqlCon.Execute("DELETE FROM PollingStepDBCache WHERE ContentInfoID=?", contentInfo.ID);
sqlCon.Execute("DELETE FROM MessageRecipientDBCache WHERE MessageDBID=?", messageDB.ID);
sqlCon.Execute("DELETE FROM MessageStepDBCache WHERE MessageDBID=?", messageDB.ID);
sqlCon.Execute("DELETE FROM ContentState WHERE ContentInfoID=?", contentInfo.ID);
sqlCon.Execute("DELETE FROM ContentInfo WHERE ID=?", contentInfo.ID);
}//end if
sqlCon.Commit();
} catch (Exception ex)
{
#if(DEBUG)
Console.WriteLine("Error deleting content info! {0}--{1}", ex.Message, ex.StackTrace);
#endif
sqlCon.Rollback();
}//end try catch
}//end using sqlCon
}//end lock
}
示例10: UpdateContentPackItemUsageDate
public void UpdateContentPackItemUsageDate(int contentPackItemID, DateTime dateTime)
{
lock (this.dbLock)
{
using (SQLiteConnection sqlCon = new SQLiteConnection(this.DBPath))
{
sqlCon.Execute(WZConstants.DBClauseSyncOff);
sqlCon.BeginTransaction();
try
{
sqlCon.Execute("UPDATE ContentPackItemDB SET LastDateTimeUsed=? WHERE ContentPackItemID=?", dateTime, contentPackItemID);
sqlCon.Commit();
} catch (Exception ex)
{
sqlCon.Rollback();
#if(DEBUG)
Console.WriteLine("Error updating content pack item date! {0}--{1}", ex.Message, ex.StackTrace);
#endif
}//end try catch
}//end using sqlCon
}//end lock
}
示例11: DeleteContacts
public void DeleteContacts(List<Guid> contactIDs)
{
lock (this.dbLock)
{
using (SQLiteConnection sqlCon = new SQLiteConnection(this.DBPath))
{
sqlCon.Execute(WZConstants.DBClauseSyncOff);
sqlCon.BeginTransaction();
try
{
foreach (Guid eachContactID in contactIDs)
{
string eachContactGuid = eachContactID.ToString();
// Delete ContactOAuthDB items
sqlCon.Execute("DELETE FROM ContactOAuthDB WHERE ContactGuid=?", eachContactGuid);
// Delete contact's user object
sqlCon.Execute("DELETE FROM UserDB WHERE AccountGuid IN (SELECT ContactAccountGuid FROM ContactDB WHERE ContactGuid=?)", eachContactGuid);
// Delete Contact object
sqlCon.Execute("DELETE FROM ContactDB WHERE ContactGuid=?", eachContactGuid);
}//end foreach
sqlCon.Commit();
} catch (Exception ex)
{
#if(DEBUG)
Console.WriteLine("Error in DeleteContacts! {0}--{1}", ex.Message, ex.StackTrace);
#endif
sqlCon.Rollback();
}//end try catch
}//end using sqlCon
}//end lock
}
示例12: InsertOrUpdateContentPackItems
public void InsertOrUpdateContentPackItems(List<ContentPackItemDB> contentPackItems)
{
lock (this.dbLock)
{
using (SQLiteConnection sqlCon = new SQLiteConnection(this.DBPath))
{
sqlCon.Execute(WZConstants.DBClauseSyncOff);
sqlCon.BeginTransaction();
try
{
Type contentPackItemType = typeof(ContentPackItemDB);
foreach (ContentPackItemDB eachContentPack in contentPackItems)
{
if (sqlCon.Execute("UPDATE ContentPackItemDB SET " +
"ContentItemTitle=?, " +
"ContentPackDataFile=?, " +
"ContentPackID=?, " +
"ContentPackItemIconFile=?, " +
"ContentPackItemID=?, " +
"LastDateTimeUsed=? " +
"WHERE ContentPackItemID=?",
eachContentPack.ContentItemTitle,
eachContentPack.ContentPackDataFile,
eachContentPack.ContentPackID,
eachContentPack.ContentPackItemIconFile,
eachContentPack.ContentPackItemID,
eachContentPack.LastDateTimeUsed,
eachContentPack.ContentPackItemID) == 0)
{
sqlCon.Insert(eachContentPack, contentPackItemType);
}//end foreach
}//end foreach
sqlCon.Commit();
} catch (Exception ex)
{
#if(DEBUG)
Console.WriteLine("Error in InsertNewContentPackItems! {0}--{1}", ex.Message, ex.StackTrace);
#endif
sqlCon.Rollback();
}//end try catch
}//end using sqlCon
}//end lock
}
示例13: InsertOrUpdateContentInfoItems
public void InsertOrUpdateContentInfoItems(List<ContentInfo> contentInfoItems)
{
lock (this.dbLock)
{
using (SQLiteConnection sqlCon = new SQLiteConnection(this.DBPath))
{
sqlCon.Execute(WZConstants.DBClauseSyncOff);
sqlCon.BeginTransaction();
try
{
Type messageDBType = typeof(MessageDB);
Type contentInfoType = typeof(ContentInfo);
Type voiceCacheType = typeof(VoiceCache);
Type pollingStepDBCacheType = typeof(PollingStepDBCache);
Type messageStepDBCacheType = typeof(MessageStepDBCache);
Type messageRecipientDBCacheType = typeof(MessageRecipientDBCache);
Type contentStateType = typeof(ContentState);
foreach (ContentInfo eachContentInfo in contentInfoItems)
{
if (sqlCon.Execute("UPDATE MessageDB SET " +
"MessageGuid=?, " +
"FromAccountGuid=?, " +
"IsOutgoing=?, " +
"MessageSent=? " +
"WHERE ID=?",
eachContentInfo.Message.MessageID.ToString(),
eachContentInfo.Message.FromAccountID.ToString(),
true,
eachContentInfo.Message.MessageSent,
eachContentInfo.MessageDBID) == 0)
{
MessageDB msgDB = MessageDB.ConvertFromMessage(eachContentInfo.Message);
sqlCon.Insert(msgDB, messageDBType);
eachContentInfo.MessageDBID = msgDB.ID;
}//end if
if (sqlCon.Execute("UPDATE ContentInfo SET " +
"MessageDBID=?, " +
"IsFailed=?, " +
"IsMessageCreateFailed=? " +
"WHERE ID=?",
eachContentInfo.MessageDBID,
eachContentInfo.IsFailed,
eachContentInfo.IsMessageCreateFailed,
eachContentInfo.ID) == 0)
{
sqlCon.Insert(eachContentInfo, contentInfoType);
}//end if
foreach (KeyValuePair<int, byte[]> eachVoiceCache in eachContentInfo.VoiceRecordings)
{
bool isSent = eachContentInfo.ContentState != null ?
!eachContentInfo.ContentState.VoiceIDQ.Contains(eachVoiceCache.Key) :
false;
if (sqlCon.Execute("UPDATE VoiceCache SET " +
"ContentInfoID=?, " +
"StepNumber=?, " +
"VoiceData=?, " +
"IsSent=? " +
"WHERE ContentInfoID=? AND StepNumber=?",
eachContentInfo.ID,
eachVoiceCache.Key,
eachVoiceCache.Value,
isSent,
eachContentInfo.ID,
eachVoiceCache.Key) == 0)
{
VoiceCache voiceCache = new VoiceCache();
voiceCache.ContentInfoID = eachContentInfo.ID;
voiceCache.StepNumber = eachVoiceCache.Key;
voiceCache.VoiceData = eachVoiceCache.Value;
voiceCache.IsSent = isSent;
sqlCon.Insert(voiceCache, voiceCacheType);
}//end if
}//end foreach
foreach (KeyValuePair<int, PollingStep> eachPollingStep in eachContentInfo.PollingSteps)
{
bool isSent = eachContentInfo.ContentState != null ?
!eachContentInfo.ContentState.PollingIDQ.Contains(eachPollingStep.Key) :
false;
//.........这里部分代码省略.........
示例14: InsertOrUpdateAnimation
public void InsertOrUpdateAnimation(AnimationInfo animationInfo)
{
lock (this.dbLock)
{
using (SQLiteConnection sqlCon = new SQLiteConnection(this.AnimationDBPath))
{
sqlCon.Execute(WZConstants.DBClauseSyncOff);
Type animationInfoType = typeof(AnimationInfo);
Type frameInfoType = typeof(FrameInfo);
Type layerInfoType = typeof(LayerInfo);
Type drInfoType = typeof(DrawingInfo);
Type trInfoType = typeof(TransitionInfo);
Type trSettingsType = typeof(TransitionEffectSettings);
Type brushItemType = typeof(BrushItem);
Type audioItemType = typeof(AnimationAudioInfo);
sqlCon.BeginTransaction();
try
{
//
// AnimationInfo
//
if (sqlCon.Execute("UPDATE AnimationInfo SET " +
"MessageGuid=?, " +
"StepNumber=?, " +
"CreatedOn=?, " +
"OriginalCanvasSizeWidth=?, " +
"OriginalCanvasSizeHeight=?, " +
"IsEditing=?, " +
"IsSent=? " +
"WHERE DBID=?",
animationInfo.MessageGuid,
animationInfo.StepNumber,
animationInfo.CreatedOn,
animationInfo.OriginalCanvasSizeWidth,
animationInfo.OriginalCanvasSizeHeight,
animationInfo.IsEditing,
animationInfo.IsSent,
animationInfo.DBID) == 0)
{
sqlCon.Insert(animationInfo, animationInfoType);
}//end if
foreach (FrameInfo eachFrameInfo in animationInfo.FrameItems.Values)
{
eachFrameInfo.AnimationDBID = animationInfo.DBID;
if (sqlCon.Execute("UPDATE FrameInfo SET " +
"ID=?, " +
"AnimationDBID=? " +
"WHERE DBID=?",
eachFrameInfo.ID,
eachFrameInfo.AnimationDBID,
eachFrameInfo.DBID) == 0)
{
sqlCon.Insert(eachFrameInfo, frameInfoType);
}//end if
foreach (LayerInfo eachLayerInfo in eachFrameInfo.Layers.Values)
{
eachLayerInfo.FrameDBID = eachFrameInfo.DBID;
if (sqlCon.Execute("UPDATE LayerInfo SET " +
"ID=?, " +
"FrameDBID=?, " +
"CanvasSizeWidth=?, " +
"CanvasSizeHeight=?, " +
"IsCanvasActive=? " +
"WHERE DBID=?",
eachLayerInfo.ID,
eachLayerInfo.FrameDBID,
eachLayerInfo.CanvasSizeWidth,
eachLayerInfo.CanvasSizeHeight,
eachLayerInfo.IsCanvasActive,
eachLayerInfo.DBID) == 0)
{
sqlCon.Insert(eachLayerInfo, layerInfoType);
}//end if
foreach (DrawingInfo eachDrawingInfo in eachLayerInfo.DrawingItems.Values)
{
eachDrawingInfo.LayerDBID = eachLayerInfo.DBID;
if (null != eachDrawingInfo.Brush)
{
if (sqlCon.Execute("UPDATE BrushItem SET " +
"Thickness=?, " +
//.........这里部分代码省略.........
示例15: CleanUpDB
public void CleanUpDB()
{
lock (this.dbLock)
{
using (SQLiteConnection sqlCon = new SQLiteConnection(this.DBPath))
{
sqlCon.Execute(WZConstants.DBClauseSyncOff);
sqlCon.BeginTransaction();
try
{
sqlCon.Execute("DELETE FROM UserDB");
sqlCon.Execute("DELETE FROM ContactDB");
sqlCon.Execute("DELETE FROM ContactOAuthDB");
sqlCon.Execute("DELETE FROM ContentPackDB");
sqlCon.Execute("DELETE FROM ContentPackItemDB");
sqlCon.Execute("DELETE FROM MessageDB");
sqlCon.Execute("DELETE FROM MessageStepDB");
sqlCon.Commit();
sqlCon.Execute(WZConstants.DBClauseVacuum);
} catch (Exception ex)
{
#if(DEBUG)
Console.WriteLine("Error in CleanUpDB! {0}--{1}", ex.Message, ex.StackTrace);
#endif
sqlCon.Rollback();
}//end try catch
}//end using sqlCon
}//end lock
}