[sqlite] 트랜잭션의 롤백
아래의 코드는 트랜잭션 안에서 태이블의 모든 열들을 지운 뒤 그 결과를 확인하고 롤백을 한 뒤 다시 확인하여 그 차이를 비교한다.
SQLiteConnection Connection = new(@"data source = C:\test.db");
private void button1_Click(object sender, EventArgs e)
{
Connection.Open();
SQLiteTransaction transaction = Connection.BeginTransaction();
SQLiteCommand command = new(Connection);
command.CommandText = "delete from testtable";
command.ExecuteNonQuery();
command.CommandText = "select count(*) from testtable";
Text = command.ExecuteScalar().ToString(); // 0
transaction.Rollback();
button1.Text = command.ExecuteScalar().ToString(); // 1
command.Dispose();
transaction.Dispose();
Connection.Close();
}
ExecuteScalar는 하나의 값을 object 타입으로 반환한다. 위 예제에서는 열들의 개수를 정수로 구한다. 대이터배이스에서 스캐일러는 일반적으로 여러 칼럼들과 열들에 대비하여 하나의 무언가를 뜻한다.