BigQueryTransaction Class
Represents a SQL transaction to be made in the Google BigQuery database.
The following example creates a
BigQueryConnection and a
BigQueryTransaction. It also demonstrates how to use the
BigQueryConnection.BeginTransaction,
Commit, and
Rollback methods.
|
|---|
public static void RunBigQueryTransaction(string myConnString) {
using (BigQueryConnection bigQueryConnection = new BigQueryConnection(myConnString)) {
bigQueryConnection.Open();
// Start a local transaction
BigQueryTransaction myTrans = bigQueryConnection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
BigQueryCommand bigQueryCommand = bigQueryConnection.CreateCommand();
try {
bigQueryCommand.CommandText = "INSERT INTO Dept(DeptNo, DName) Values(52, 'DEVELOPMENT')";
bigQueryCommand.ExecuteNonQuery();
bigQueryCommand.CommandText = "INSERT INTO Dept(DeptNo, DName) Values(62, 'PRODUCTION')";
bigQueryCommand.ExecuteNonQuery();
myTrans.Commit();
Console.WriteLine("Both records are written to database.");
}
catch (Exception e) {
myTrans.Rollback();
Console.WriteLine(e.ToString());
Console.WriteLine("Neither record was written to database.");
}
finally {
bigQueryCommand.Dispose();
myTrans.Dispose();
}
}
} |
|
|---|
Public Shared Sub RunBigQueryTransaction(myConnString As String)
Using bigQueryConnection As New BigQueryConnection(myConnString)
bigQueryConnection.Open()
' Start a local transaction
Dim myTrans As BigQueryTransaction = bigQueryConnection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted)
Dim bigQueryCommand As BigQueryCommand = bigQueryConnection.CreateCommand()
Try
bigQueryCommand.CommandText = "INSERT INTO Dept(DeptNo, DName) Values(52, 'DEVELOPMENT')"
bigQueryCommand.ExecuteNonQuery()
bigQueryCommand.CommandText = "INSERT INTO Dept(DeptNo, DName) Values(62, 'PRODUCTION')"
bigQueryCommand.ExecuteNonQuery()
myTrans.Commit()
Console.WriteLine("Both records are written to database.")
Catch e As Exception
myTrans.Rollback()
Console.WriteLine(e.ToString())
Console.WriteLine("Neither record was written to database.")
Finally
bigQueryCommand.Dispose()
myTrans.Dispose()
End Try
End Using
End Sub |