本文整理汇总了C#中Microsoft.Data.Sqlite.SqliteConnection.ExecuteNonQuery方法的典型用法代码示例。如果您正苦于以下问题:C# SqliteConnection.ExecuteNonQuery方法的具体用法?C# SqliteConnection.ExecuteNonQuery怎么用?C# SqliteConnection.ExecuteNonQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Data.Sqlite.SqliteConnection
的用法示例。
在下文中一共展示了SqliteConnection.ExecuteNonQuery方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SqliteTransaction
internal SqliteTransaction(SqliteConnection connection, IsolationLevel isolationLevel)
{
_connection = connection;
_isolationLevel = isolationLevel;
if (isolationLevel == IsolationLevel.ReadUncommitted)
{
if (connection.ConnectionStringBuilder.CacheMode != CacheMode.Shared)
{
throw new ArgumentException(Strings.FormatInvalidIsolationLevelForUnsharedCache(isolationLevel));
}
connection.ExecuteNonQuery("PRAGMA read_uncommitted = 1;");
}
else if (isolationLevel == IsolationLevel.Serializable)
{
connection.ExecuteNonQuery("PRAGMA read_uncommitted = 0;");
}
else if (isolationLevel != IsolationLevel.Unspecified)
{
throw new ArgumentException(Strings.FormatInvalidIsolationLevel(isolationLevel));
}
// TODO: Register transaction hooks to detect when a user manually completes a transaction created using this API
connection.ExecuteNonQuery("BEGIN;");
}
示例2: EnableExtensions_works
public void EnableExtensions_works()
{
using (var connection = new SqliteConnection("Data Source=:memory:"))
{
connection.Open();
var sql = "SELECT load_extension('unknown');";
var ex = Assert.Throws<SqliteException>(() => connection.ExecuteNonQuery(sql));
var originalError = ex.Message;
connection.EnableExtensions();
ex = Assert.Throws<SqliteException>(() => connection.ExecuteNonQuery(sql));
var enabledError = ex.Message;
connection.EnableExtensions(enable: false);
ex = Assert.Throws<SqliteException>(() => connection.ExecuteNonQuery(sql));
var disabledError = ex.Message;
Assert.NotEqual(originalError, enabledError);
Assert.Equal(originalError, disabledError);
}
}
示例3: Open_works_when_memory_shared
public void Open_works_when_memory_shared()
{
var connectionString = "Data Source=people;Mode=Memory;Cache=Shared";
using (var connection1 = new SqliteConnection(connectionString))
{
connection1.Open();
connection1.ExecuteNonQuery(
"CREATE TABLE Person (Name TEXT);" +
"INSERT INTO Person VALUES ('Waldo');");
using (var connection2 = new SqliteConnection(connectionString))
{
connection2.Open();
var name = connection2.ExecuteScalar<string>("SELECT Name FROM Person;");
Assert.Equal("Waldo", name);
}
}
}
示例4: Open_works_when_readonly
public void Open_works_when_readonly()
{
using (var connection = new SqliteConnection("Data Source=readonly.db"))
{
connection.Open();
if (connection.ExecuteScalar<long>("SELECT COUNT(*) FROM sqlite_master WHERE name = 'Idomic';") == 0)
{
connection.ExecuteNonQuery("CREATE TABLE Idomic (Word TEXT);");
}
}
using (var connection = new SqliteConnection("Data Source=readonly.db;Mode=ReadOnly"))
{
connection.Open();
var ex = Assert.Throws<SqliteException>(
() => connection.ExecuteNonQuery("INSERT INTO Idomic VALUES ('arimfexendrapuse');"));
Assert.Equal(SQLITE_READONLY, ex.SqliteErrorCode);
}
}
示例5: ExecuteReader_skips_DML_statements
public void ExecuteReader_skips_DML_statements()
{
using (var connection = new SqliteConnection("Data Source=:memory:"))
{
connection.Open();
connection.ExecuteNonQuery("CREATE TABLE Test(Value);");
var command = connection.CreateCommand();
command.CommandText = @"
INSERT INTO Test VALUES(1);
SELECT 1;";
using (var reader = command.ExecuteReader())
{
var hasData = reader.Read();
Assert.True(hasData);
Assert.Equal(1L, reader.GetInt64(0));
}
}
}
示例6: IsolationLevel_is_infered_when_unspecified
public void IsolationLevel_is_infered_when_unspecified()
{
using (var connection = new SqliteConnection("Data Source=:memory:"))
{
connection.Open();
connection.ExecuteNonQuery("PRAGMA read_uncommitted = 1;");
using (var transaction = connection.BeginTransaction())
{
Assert.Equal(IsolationLevel.ReadUncommitted, transaction.IsolationLevel);
}
}
}
示例7: CreateTestTable
private static void CreateTestTable(SqliteConnection connection)
{
connection.ExecuteNonQuery(@"
CREATE TABLE TestTable (
TestColumn INTEGER
)");
}
示例8: Dispose_works
public void Dispose_works()
{
using (var connection = new SqliteConnection("Data Source=:memory:"))
{
connection.Open();
CreateTestTable(connection);
using (var transaction = connection.BeginTransaction())
{
connection.ExecuteNonQuery("INSERT INTO TestTable VALUES (1);");
transaction.Dispose();
Assert.Null(connection.Transaction);
Assert.Null(transaction.Connection);
}
Assert.Equal(0L, connection.ExecuteScalar<long>("SELECT COUNT(*) FROM TestTable;"));
}
}