本文整理汇总了C#中Community.CsharpSqlite.SQLiteClient.SqliteConnection.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# SqliteConnection.BeginTransaction方法的具体用法?C# SqliteConnection.BeginTransaction怎么用?C# SqliteConnection.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Community.CsharpSqlite.SQLiteClient.SqliteConnection
的用法示例。
在下文中一共展示了SqliteConnection.BeginTransaction方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenDatabase
public static bool OpenDatabase(string dbFileName)
{
try
{
Log.log("Opening sqlite database connection: "+dbFileName);
string cs = string.Format("Version=3,uri=file:{0}", dbFileName);
connection = new SqliteConnection(cs);
connection.Open();
trans = connection.BeginTransaction();
return true;
}
catch (Exception e)
{
return false;
}
}
示例2: Save
//.........这里部分代码省略.........
par = cmd.CreateParameter();
par.ParameterName = "@publiceddate";
par.DbType = DbType.String;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@personalnote";
par.DbType = DbType.String;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@flagged";
par.DbType = DbType.Int32;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@found";
par.DbType = DbType.Int32;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@locked";
par.DbType = DbType.Int32;
cmd.Parameters.Add(par);
foreach (string s in custAttr)
{
par = cmd.CreateParameter();
par.ParameterName = string.Format("@_{0}", s);
par.DbType = DbType.String;
cmd.Parameters.Add(par);
}
cmd.Prepare();
StringBuilder sb = new StringBuilder();
using (DbTransaction trans = dbcon.BeginTransaction())
{
int index = 0;
int procStep = 0;
foreach (Framework.Data.Geocache gc in gclist)
{
index++;
procStep++;
if (!gc.Saved)
{
cmd.Parameters["@id"].Value = gc.ID ?? "";
cmd.Parameters["@code"].Value = gc.Code;
cmd.Parameters["@name"].Value = gc.Name ?? "";
cmd.Parameters["@datafromdate"].Value = gc.DataFromDate.ToUniversalTime().ToString("u");
cmd.Parameters["@lat"].Value = gc.Lat;
cmd.Parameters["@lon"].Value = gc.Lon;
cmd.Parameters["@disttocent"].Value = gc.DistanceToCenter;
cmd.Parameters["@angletocent"].Value = gc.AngleToCenter;
cmd.Parameters["@available"].Value = gc.Available ? 1 : 0;
cmd.Parameters["@archived"].Value = gc.Archived ? 1 : 0;
cmd.Parameters["@country"].Value = gc.Country ?? "";
cmd.Parameters["@state"].Value = gc.State ?? "";
cmd.Parameters["@cachetype"].Value = gc.GeocacheType == null ? -1 : gc.GeocacheType.ID;
cmd.Parameters["@placedby"].Value = gc.PlacedBy ?? "";
cmd.Parameters["@owner"].Value = gc.Owner ?? "";
cmd.Parameters["@ownerid"].Value = gc.OwnerId ?? "";
cmd.Parameters["@container"].Value = gc.Container == null ? -1 : gc.Container.ID;
cmd.Parameters["@terrain"].Value = gc.Terrain;
cmd.Parameters["@difficulty"].Value = gc.Difficulty;
if (forceFullData || gc.FullDataLoaded)
{
cmd.Parameters["@shortdescr"].Value = gc.ShortDescription ?? "";
cmd.Parameters["@shortdescrhtml"].Value = gc.ShortDescriptionInHtml ? 1 : 0;
示例3: T6_ThreadStart
private static void T6_ThreadStart(object data)
{
string commandt = String.Empty;
int i = (int)data;
try
{
int aValue = 100 + i;
int op = aValue % 2;
SqliteConnection con = new SqliteConnection();
con.ConnectionString = connstring_T6;
con.Open();
IDbCommand cmd = con.CreateCommand();
cmd = con.CreateCommand();
if (op == 0)
{
SqliteTransaction trans = (SqliteTransaction)con.BeginTransaction();
for (int j = 0; j < 5000; j++)
{
int rows;
int retry = 0;
cmd.CommandText = String.Format("INSERT INTO BTABLE ( A, B, C ) VALUES ({0},'threader', '1' )", (aValue * 10000) + j);
commandt = cmd.CommandText;
do
{
rows = cmd.ExecuteNonQuery();
if (rows == 0)
{
retry += 1; // Insert Failed
Console.WriteLine("retry {0}:{1}:{2}", retry, ((SqliteCommand)cmd).GetLastError(), cmd.CommandText);
Thread.Sleep(rnd.Next(50, 1000));
}
} while (rows == 0 && retry < 10);
}
trans.Commit();
}
else
{
cmd.CommandText = String.Format("Select * FROM ATABLE");
commandt = cmd.CommandText;
cmd.ExecuteReader();
}
}
catch (Exception ex)
{
Console.WriteLine(String.Format("Command {0} threw exception {1}", commandt, ex.Message));
}
}
示例4: ExportMethod
//.........这里部分代码省略.........
par = cmd.CreateParameter();
par.ParameterName = "@LonOriginal";
par.DbType = DbType.String;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@Status";
par.DbType = DbType.String;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@GcNote";
par.DbType = DbType.String;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@IsPremium";
par.DbType = DbType.Int32;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@FavPoints";
par.DbType = DbType.Int32;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@IsLite";
par.DbType = DbType.Int32;
cmd.Parameters.Add(par);
cmd.Prepare();
cmd2.Prepare();
cmd3.Prepare();
cmd4.Prepare();
cmd5.Prepare();
cmd6.Prepare();
cmd7.Prepare();
using (DbTransaction trans = dbcon.BeginTransaction())
{
int index = 0;
int procStep = 0;
foreach (Framework.Data.Geocache gc in _gcList)
{
cmd2.Parameters["@Code"].Value = gc.Code;
cmd2.Parameters["@LongDescription"].Value = gc.LongDescription ?? "";
cmd2.Parameters["@ShortDescription"].Value = gc.ShortDescription ?? "";
cmd2.Parameters["@Url"].Value = gc.Url ?? "";
cmd2.Parameters["@Hints"].Value = gc.EncodedHints ?? "";
cmd2.Parameters["@UserNote"].Value = string.IsNullOrEmpty(gc.Notes) ? "" : System.Web.HttpUtility.HtmlDecode(gc.Notes);
cmd.Parameters["@Code"].Value = gc.Code;
cmd.Parameters["@Name"].Value = gc.Name??"";
cmd.Parameters["@PlacedBy"].Value = gc.PlacedBy ?? "";
cmd.Parameters["@Archived"].Value = gc.Archived ? 1:0;
cmd.Parameters["@CacheId"].Value = gc.ID ?? "1";
cmd.Parameters["@CacheType"].Value = getCacheType(gc.GeocacheType);
cmd.Parameters["@Container"].Value = getContainer(gc.Container);
cmd.Parameters["@Country"].Value = gc.Country ?? "";
cmd.Parameters["@Difficulty"].Value = gc.Difficulty;
cmd.Parameters["@Found"].Value = gc.Found ? 1 : 0;
cmd.Parameters["@HasCorrected"].Value = (gc.CustomCoords || gc.ContainsCustomLatLon) ? 1 : 0;
cmd.Parameters["@HasUserNote"].Value = gc.ContainsNote ? 1 : 0;
cmd.Parameters["@LatOriginal"].Value = gc.Lat.ToString().Replace(',', '.');
cmd.Parameters["@LonOriginal"].Value = gc.Lon.ToString().Replace(',', '.');
if (gc.ContainsCustomLatLon)
{
cmd.Parameters["@Latitude"].Value = gc.CustomLat.ToString().Replace(',', '.');
cmd.Parameters["@Longitude"].Value = gc.CustomLon.ToString().Replace(',', '.');
}
else
示例5: MainPage
// Constructor
public MainPage()
{
InitializeComponent();
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
isf.DeleteFile("test.db");
using (SqliteConnection conn = new SqliteConnection("Version=3,uri=file:test.db"))
{
conn.Open();
using (SqliteCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "CREATE TABLE test ( [id] INTEGER PRIMARY KEY, [col] INTEGER UNIQUE, [col2] INTEGER, [col3] REAL, [col4] TEXT, [col5] BLOB)";
cmd.ExecuteNonQuery();
cmd.Transaction = conn.BeginTransaction();
cmd.CommandText = "INSERT INTO test(col, col2, col3, col4, col5) VALUES(@col, @col2, @col3, @col4, @col5);SELECT last_insert_rowid();";
cmd.Parameters.Add("@col", null);
cmd.Parameters.Add("@col2", null);
cmd.Parameters.Add("@col3", null);
cmd.Parameters.Add("@col4", null);
cmd.Parameters.Add("@col5", null);
DateTime start = DateTime.Now;
this.lstResult.Items.Add("Inserting 100 Rows with transaction");
for (int i = 0; i < 100; i++)
{
cmd.Parameters["@col"].Value = i;
cmd.Parameters["@col2"].Value = i;
cmd.Parameters["@col3"].Value = i * 0.515;
cmd.Parameters["@col4"].Value = "สวัสดี な. あ · か · さ · た · な · は · ま · や · ら · わ. 形容詞 hello " + i;
cmd.Parameters["@col5"].Value = Encoding.UTF8.GetBytes("สวัสดี");
object s = cmd.ExecuteScalar();
}
cmd.Transaction.Commit();
cmd.Transaction = null;
this.lstResult.Items.Add("Time taken :" + DateTime.Now.Subtract( start ).TotalMilliseconds + " ms.");
cmd.CommandText = "SELECT * FROM test";
using (SqliteDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
var bytes = (byte[])reader.GetValue(5);
this.lstResult.Items.Add(string.Format("{0},{1},{2},{3},{4}, {5}",
reader.GetInt32(0),
reader.GetInt32(1),
reader.GetInt32(2),
reader.GetDouble(3),
reader.GetString(4),
Encoding.UTF8.GetString(bytes, 0, bytes.Length)));
}
}
conn.Close();
}
}
}