本文整理汇总了C#中SQLite.SQLiteConnection.Rollback方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection.Rollback方法的具体用法?C# SQLiteConnection.Rollback怎么用?C# SQLiteConnection.Rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLite.SQLiteConnection
的用法示例。
在下文中一共展示了SQLiteConnection.Rollback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnCreate
protected override void OnCreate(Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button> (Resource.Id.myButton);
string folder = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);
var db = new SQLiteConnection (System. IO. Path. Combine (folder, "myDb. db"));
button.Click += delegate{
Person Person = new Person{ Name = FindViewById<EditText> (Resource.Id.editText1).Text };
int id = db.Insert(Person);
FindViewById<TextView> (Resource.Id.textView2).Text = "Inserted with success: id "+id;
};
Button deleteButton = FindViewById<Button> (Resource.Id.button2);
deleteButton.Click += delegate {
var DeletedId = db.Delete<Person> (Convert.ToInt32(FindViewById<EditText> (Resource.Id.editText1).Text));
FindViewById<TextView> (Resource.Id.textView2).Text = "Id " + Dele tedId + "Deleted With Success";
};
db.Commit();
db.Rollback();
}
示例2: 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();
}
}
}
}
示例3: InsertOrUpdateBeacon
public void InsertOrUpdateBeacon(Beacon beacon)
{
lock (dbLock)
{
using (var sqlcon = new SQLiteConnection(DBPath))
{
sqlcon.Execute(Constants.DBClauseSyncOff);
sqlcon.BeginTransaction();
try
{
if (sqlcon.Execute("UPDATE Beacon Set DeviceUUID=?," +
"DeviceDistance=?,Proximity=?,FirstSeen=?,LastSeen=?,WelcomeMessage=?,SignalStrength=?,Major=?,Minor=? WHERE DeviceUUID=?",
beacon.DeviceUUID, beacon.DeviceDistance, beacon.Proximity, beacon.FirstSeen, beacon.LastSeen, beacon.WelcomeMessage,
beacon.SignalStrength, beacon.Major, beacon.Minor, beacon.DeviceUUID) == 0)
sqlcon.Insert(beacon, typeof(Beacon));
sqlcon.Commit();
}
catch (Exception ex)
{
#if DEBUG
Console.WriteLine("Error in DeleteObject - {0}--{1}", ex.Message, ex.StackTrace);
#endif
sqlcon.Rollback();
}
}
}
}
示例4: DeletePollingStep
public void DeletePollingStep(PollingStepDB pollingStep)
{
lock (this.dbLock)
{
using (SQLiteConnection sqlCon = new SQLiteConnection(this.DBPath))
{
sqlCon.Execute(WZConstants.DBClauseSyncOff);
sqlCon.BeginTransaction();
try
{
sqlCon.Execute("DELETE FROM PollingStepDB WHERE MessageGuid=? AND StepNumber=?", pollingStep.MessageGuid, pollingStep.StepNumber);
sqlCon.Commit();
} catch (Exception ex)
{
Console.WriteLine("Error in DeletePollingStep! {0}--{1}", ex.Message, ex.StackTrace);
sqlCon.Rollback();
}//end try catch
}//end using sqlCon
}//end lock
}
示例5: DeleteContentPackItems
public void DeleteContentPackItems(List<ContentPackItemDB> items)
{
lock (this.dbLock)
{
using (SQLiteConnection sqlCon = new SQLiteConnection(this.DBPath))
{
sqlCon.Execute(WZConstants.DBClauseSyncOff);
sqlCon.BeginTransaction();
try
{
foreach (ContentPackItemDB eachPackItem in items)
{
sqlCon.Execute("DELETE FROM ContentPackItemDB WHERE ID=?", eachPackItem.ID);
}//end foreach
sqlCon.Commit();
} catch (Exception ex)
{
sqlCon.Rollback();
#if(DEBUG)
Console.WriteLine("Error deleting content pack item! {0}--{1}", ex.Message, ex.StackTrace);
#endif
}//end try catch
}//end using sqlCon
}//end lock
}
示例6: UpdateUserImage
public void UpdateUserImage(string accountGuid, byte[] imageBuffer)
{
lock (this.dbLock)
{
using (SQLiteConnection sqlCon = new SQLiteConnection(this.DBPath))
{
sqlCon.Execute(WZConstants.DBClauseSyncOff);
sqlCon.BeginTransaction();
try
{
sqlCon.Execute("UPDATE UserDB SET Picture=? WHERE AccountGuid=?", imageBuffer, accountGuid);
sqlCon.Commit();
} catch (Exception ex)
{
Console.WriteLine("Error in UpdateUserImage! {0}--{1}", ex.Message, ex.StackTrace);
sqlCon.Rollback();
}//end try catch
}//end using sqlCon
}//end lock
}
示例7: SaveAnimationUndoInfo
public void SaveAnimationUndoInfo(List<UndoInfo> undoInfo)
{
lock (this.dbLock)
{
using (SQLiteConnection sqlCon = new SQLiteConnection(this.AnimationDBPath))
{
sqlCon.Execute(WZConstants.DBClauseSyncOff);
sqlCon.BeginTransaction();
try
{
sqlCon.Execute("DELETE FROM UndoInfo");
sqlCon.InsertAll(undoInfo);
sqlCon.Commit();
} catch (Exception ex)
{
sqlCon.Rollback();
#if(DEBUG)
Console.WriteLine("Error inserting undo info objects! {0}--{1}", ex.Message, ex.StackTrace);
#endif
}//end try catch
}//end using sqlCon
}//end lock
}
示例8: RefreshContactsForOwner
/// <summary>
/// Deletes all contacts that belong to the owner and replaces them with the supplied contact list.
/// </summary>
/// <param name='withContacts'>
/// Contacts to replace the deleted ones with.
/// </param>
/// <param name='ownerAccountID'>
/// Owner account GUID. Normally, this should be the currently logged in user.
/// </param>
public void RefreshContactsForOwner(List<Contact> withContacts, string ownerAccountID)
{
lock (this.dbLock)
{
using (SQLiteConnection sqlCon = new SQLiteConnection(this.DBPath))
{
sqlCon.Execute(WZConstants.DBClauseSyncOff);
sqlCon.BeginTransaction();
try
{
// Delete all ContactOAuth items for owner
sqlCon.Execute("DELETE FROM ContactOAuthDB WHERE ContactGuid IN " +
"(SELECT ContactGuid FROM ContactDB WHERE OwnerAccountGuid=?)", ownerAccountID);
// Delete all Contacts for owner
sqlCon.Execute("DELETE FROM ContactDB WHERE OwnerAccountGuid=?", ownerAccountID);
// Insert contacts
Type contactDBType = typeof(ContactDB);
Type contactOAuthDBType = typeof(ContactOAuthDB);
Type userDBType = typeof(UserDB);
foreach (Contact eachContact in withContacts)
{
ContactDB contactDB = ContactDB.ConvertFromContact(eachContact);
sqlCon.Insert(contactDB, contactDBType);
// Insert the contact auth db item
contactDB.ContactOAuthItems.ForEach(s => {
sqlCon.Insert(s, contactOAuthDBType);
});
// Insert Or Update user object
UserDB contactUser = UserDB.ConvertFromUser(contactDB.ContactUser);
if (sqlCon.Execute("UPDATE UserDB SET " +
"AccountActive=?, " +
"AccountGuid=?, " +
"DateOfBirth=?, " +
"EmailAddress=?, " +
"FirstName=?, " +
"LastName=?, " +
"Password=?, " +
"Picture=?, " +
"PictureUrl=?, " +
"HasProfileImage=? " +
"WHERE AccountGuid=?",
contactUser.AccountActive,
contactUser.AccountGuid,
contactUser.DateOfBirth,
contactUser.EmailAddress,
contactUser.FirstName,
contactUser.LastName,
contactUser.Password,
contactUser.Picture,
contactUser.PictureURL,
contactUser.HasProfileImage,
contactUser.AccountGuid) == 0)
{
sqlCon.Insert(contactUser, userDBType);
}//end if
}//end foreach
sqlCon.Commit();
} catch (Exception ex)
{
sqlCon.Rollback();
#if(DEBUG)
Console.WriteLine("Error in RefreshContactsForOwner! {0}--{1}", ex.Message, ex.StackTrace);
#endif
}//end try catch
}//end using sqlCon
}//end lock
}
示例9: MarkMessageRead
public void MarkMessageRead(string messageGuid, string ownerAccountID)
{
#if(DEBUG)
Console.WriteLine("Will mark message read! {0}", messageGuid);
#endif
lock (this.dbLock)
{
using (SQLiteConnection sqlCon = new SQLiteConnection(this.DBPath))
{
sqlCon.Execute(WZConstants.DBClauseSyncOff);
sqlCon.BeginTransaction();
try
{
if (sqlCon.Execute("UPDATE MessageRecipientDB SET IsRead=? WHERE MessageGuid=? AND AccountGuid=?", true, messageGuid, ownerAccountID) == 0)
{
MessageRecipientDB msgRcp = new MessageRecipientDB()
{
AccountGuid = ownerAccountID,
MessageGuid = messageGuid,
IsRead = true
};
#if(DEBUG)
Console.WriteLine("Created a new message recipient! {0}", msgRcp);
#endif
sqlCon.Insert(msgRcp, typeof(MessageRecipientDB));
}//end if
sqlCon.Commit();
} catch (Exception ex)
{
#if(DEBUG)
Console.WriteLine("Error in MarkMessageRead! {0}--{1}", ex.Message, ex.StackTrace);
#endif
sqlCon.Rollback();
}//end try catch
}//end using sqlCon
}//end lock
}
示例10: 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
}
示例11: InsertNewPollingSteps
public void InsertNewPollingSteps(List<PollingStepDB> pollingSteps)
{
lock (this.dbLock)
{
using (SQLiteConnection sqlCon = new SQLiteConnection(this.DBPath))
{
sqlCon.Execute(WZConstants.DBClauseSyncOff);
sqlCon.BeginTransaction();
try
{
sqlCon.InsertAll(pollingSteps);
sqlCon.Commit();
} catch (Exception ex)
{
#if(DEBUG)
Console.WriteLine("Error in InsertNewPollingSteps! {0}--{1}", ex.Message, ex.StackTrace);
#endif
sqlCon.Rollback();
}//end try catch
}//end using sqlCon
}//end lock
}
示例12: InsertNewMessages
/// <summary>
/// Inserts newly received messages to the database.
/// </summary>
/// <param name='messageList'>
/// The newly received messages.
/// </param>
public void InsertNewMessages(List<Message> messageList)
{
lock (this.dbLock)
{
using (SQLiteConnection sqlCon = new SQLiteConnection(this.DBPath))
{
sqlCon.Execute(WZConstants.DBClauseSyncOff);
sqlCon.BeginTransaction();
try
{
Type messageDBType = typeof(MessageDB);
foreach (Message eachMessage in messageList)
{
MessageDB eachMessageDb = MessageDB.ConvertFromMessage(eachMessage);
sqlCon.Insert(eachMessageDb, messageDBType);
sqlCon.InsertAll(eachMessageDb.MessageStepDBList);
sqlCon.InsertAll(eachMessageDb.MessageRecipientDBList);
}//end foreach
sqlCon.Commit();
} catch (Exception ex)
{
#if(DEBUG)
Console.WriteLine("Error in InsertNewMessages! {0}--{1}", ex.Message, ex.StackTrace);
#endif
sqlCon.Rollback();
}//end try catch
}//end using sqlCon
}//end lock
}
示例13: InserOrUpdateContacts
//.........这里部分代码省略.........
try
{
Type contactDBType = typeof(ContactDB);
Type authDBType = typeof(ContactOAuthDB);
Type userDBType = typeof(UserDB);
foreach (Contact eachContact in contacts)
{
ContactDB contactDB = ContactDB.ConvertFromContact(eachContact);
// Insert or update ContactDB
if (sqlCon.Execute("UPDATE ContactDB SET " +
"Blocked=?, " +
"ContactAccountGuid=?, " +
"ContactGuid=?, " +
"OwnerAccountGuid=? " +
"WHERE ContactGuid=?",
contactDB.Blocked,
contactDB.ContactAccountGuid,
contactDB.ContactGuid,
contactDB.OwnerAccountGuid,
contactDB.ContactGuid) == 0)
{
sqlCon.Insert(contactDB, contactDBType);
}//end if
// Insert or update ContactOAuthItems
if (contactDB.ContactOAuthItems.Count > 0)
{
foreach (ContactOAuthDB eachAuthDB in contactDB.ContactOAuthItems)
{
if (sqlCon.Execute("UPDATE ContactOAuthDB SET " +
"ContactGuid=?, " +
"OAuthID=?, " +
"OAuthType=? " +
"WHERE ContactGuid=?",
contactDB.ContactGuid,
eachAuthDB.OAuthID,
eachAuthDB.OAuthType,
contactDB.ContactGuid) == 0)
{
sqlCon.Insert(eachAuthDB, authDBType);
}//end if
}//end foreach
}//end if
// Insert or update ContactUser
UserDB contactUser = UserDB.ConvertFromUser(contactDB.ContactUser);
if (sqlCon.Execute("UPDATE UserDB SET " +
"AccountActive=?, " +
"AccountGuid=?, " +
"DateOfBirth=?, " +
"EmailAddress=?, " +
"FirstName=?, " +
"LastName=?, " +
"Password=?, " +
"Picture=?, " +
"PictureUrl=?, " +
"HasProfileImage=? " +
"WHERE AccountGuid=?",
contactUser.AccountActive,
contactUser.AccountGuid,
contactUser.DateOfBirth,
contactUser.EmailAddress,
contactUser.FirstName,
contactUser.LastName,
contactUser.Password,
contactUser.Picture,
contactUser.PictureURL,
contactUser.HasProfileImage,
contactUser.AccountGuid) == 0)
{
sqlCon.Insert(contactUser, userDBType);
}//end if
}//end foreach
sqlCon.Commit();
} catch (Exception ex)
{
#if(DEBUG)
Console.WriteLine("Error in InsertOrUpdateContacts! {0}--{1}", ex.Message, ex.StackTrace);
#endif
sqlCon.Rollback();
}//end try catch
}//end using sqlCon
}//end lock
}
示例14: Update_Click
//.........这里部分代码省略.........
, [REGION] nvarchar(2147483647) NULL
, [OFFICE_PHONE] nvarchar(2147483647) NULL
, [INNER_PHONE] nvarchar(2147483647) NULL
, [PY] nvarchar(2147483647) NULL
, [CAR] nvarchar(2147483647) NULL
, CONSTRAINT [sqlite_autoindex_PERSON_1] PRIMARY KEY ([ID])
);";
command.ExecuteNonQuery();
conn.BeginTransaction();
foreach (var person in personList)
{
command.CommandText = string.Format(
@"INSERT INTO [PERSON]
([ID]
,[NAME]
,[DEPARTMENT]
,[MOBILE_PHONE]
,[VIRTUAL_PHONE]
,[POSITION]
,[REGION]
,[OFFICE_PHONE]
,[INNER_PHONE]
,[PY]
,[CAR])
VALUES
('{0}'
,'{1}'
,'{2}'
,'{3}'
,'{4}'
,'{5}'
,'{6}'
,'{7}'
,'{8}'
,'{9}'
,'{10}')",
person.ID,
person.NAME,
person.DEPARTMENT,
person.MOBILE_PHONE,
person.VIRTUAL_PHONE,
person.POSITION,
person.REGION,
person.OFFICE_PHONE,
person.INNER_PHONE,
person.PY,
person.CAR);
command.ExecuteNonQuery();
}
CurrentVersionTextBlock.Text = LatestVersionTextBlock.Text;
command.CommandText = "select count(ID) from PERSON";
int newDataCount = command.ExecuteScalar<int>();
MessageBox.Show(string.Format("新数据有{0}条", newDataCount));
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
settings["version"] = LatestVersionTextBlock.Text;
settings.Save();
conn.Commit();
MessageBox.Show("更新完毕");
}
catch (Exception ex)
{
conn.Rollback();
MessageBox.Show(ex.Message);
}
}
}
}
App.ViewModel.LoadData();
}
else
{
MessageBox.Show("无需更新");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
UpdateButton.IsEnabled = true;
UpdateButton.Content = "更新数据";
WebProgressBar.Visibility = Visibility.Collapsed;
}
}
示例15: DeleteContactForOwner
/// <summary>
/// Deletes the contact that belongs to the owner.
/// </summary>
/// <param name='contact'>
/// The contact to delete.
/// </param>
public void DeleteContactForOwner(ContactDB contact)
{
lock (this.dbLock)
{
using (SQLiteConnection sqlCon = new SQLiteConnection(this.DBPath))
{
sqlCon.Execute(WZConstants.DBClauseSyncOff);
sqlCon.BeginTransaction();
try
{
// Delete OAuths for the contact
sqlCon.Execute("DELETE FROM ContactOAuthDB WHERE ContactGuid=? AND " +
"ContactGuid IN (SELECT ContactGuid FROM ContactDB WHERE OwnerAccountGuid=?)",
contact.ContactGuid, contact.OwnerAccountGuid);
// Delete the Contact object
sqlCon.Execute("DELETE FROM ContactDB WHERE ContactGuid=? AND OwnerAccountGuid=?",
contact.ContactGuid, contact.OwnerAccountGuid);
//NOTE: No need to delete the user object for the contact (maybe).
// Delete the User object
// sqlCon.Execute("DELETE FROM UserDB WHERE AccountGuid=?", contact.ContactUser.AccountID.ToString());
sqlCon.Commit();
} catch (Exception ex)
{
sqlCon.Rollback();
#if(DEBUG)
Console.WriteLine("Error in DeleteContactForOwner! {0}--{1}", ex.Message, ex.StackTrace);
#endif
}//end try catch
}//end using sqlCon
}//end lock
}