本文整理汇总了C#中System.Data.SQLite.SQLiteConnection.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection.Execute方法的具体用法?C# SQLiteConnection.Execute怎么用?C# SQLiteConnection.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SQLite.SQLiteConnection
的用法示例。
在下文中一共展示了SQLiteConnection.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateSampleSchema
internal static void CreateSampleSchema(SQLiteConnection connection)
{
try { connection.Execute("DROP TABLE table1"); }
catch { }
try { connection.Execute("CREATE TABLE table1 (id integer primary key, name text)"); }
catch { }
}
示例2: btnClear_Click
private void btnClear_Click(object sender, EventArgs e)
{
using (var conn = new SQLiteConnection(Common.ConnectionString))
{
//清理无效远程主机
conn.Execute(
"DELETE FROM RemoteHost WHERE FParentId>0 AND FConectId NOT IN (SELECT FId FROM ConnectLib)");
//清理无效父级节点
conn.Execute(
"DELETE FROM RemoteHost WHERE FParentId=0 AND FId NOT IN (SELECT FParentId FROM RemoteHost)");
}
LoadHostConfig();
}
示例3: TestDapper
public void TestDapper()
{
var dataSource = @"test.sqlite";
SQLiteConnection.CreateFile(dataSource);
var builder = new SQLiteConnectionStringBuilder
{
DataSource = dataSource,
LegacyFormat = false,
Version = 3,
SyncMode = SynchronizationModes.Off,
JournalMode = SQLiteJournalModeEnum.Wal
};
using (var tran = new TransactionScope(TransactionScopeOption.Required))
using (var connection = new SQLiteConnection(builder.ToString()))
{
connection.Open();
CreateSampleSchema(connection);
try
{
connection.Execute("INSERT INTO table1 VALUES (@Id, @Name)", new { Id = 1, Name = "Name-1" });
connection.Execute("INSERT INTO table1 VALUES (@Id, @Name)", new { Id = 2, Name = "Name-2" });
connection.Execute("INSERT INTO table1 VALUES (@Id, @Name)", new { Id = 3, Name = "Name-3" });
dynamic dynamicObj = connection.Query("SELECT id, name FROM table1 LIMIT 1").FirstOrDefault();
Console.WriteLine("Id: {0}", dynamicObj.id);
Console.WriteLine("Name: {0}", dynamicObj.name);
var mappingObj = connection.Query<Table1>("SELECT id, name FROM table1 LIMIT 1").FirstOrDefault();
Console.WriteLine("Id: {0}", mappingObj.Id);
Console.WriteLine("Name: {0}", mappingObj.Name);
dynamic results = connection.Query("SELECT id, name FROM table1");
foreach (dynamic item in results)
{
Console.WriteLine(item);
}
tran.Complete();
}
catch
{
}
}
}
示例4: AddProfile
public void AddProfile(EmployeeProfile commandDto, string imgURL, string cartoonURL)
{
string user = System.Web.HttpContext.Current.User.Identity.Name;
using (DbConnection conn = new SQLiteConnection(ConfigurationManager.ConnectionStrings["reedDirectory"].ConnectionString))
{
conn.Open();
conn.Execute(
"insert into EmployeeProfile (Department, FirstName, ImageUrl, LastName, Role, Tags, CreatedBy, CreatedOn, IsSuperUser, Extension, CartoonURL, WindowsIdentity, emailaddress, SeatingFloor, seatNo) values " +
"(@Department, @FirstName, @ImageUrl, @LastName, @Role, @Tags, @CreatedBy, @CreatedOn, @IsSuperUser, @Extension, @CartoonURL, @WindowsIdentity, @emailAddress, @SeatingFloor, @seatNo)",
new
{
Department = commandDto.Department,
FirstName = commandDto.FirstName.Replace("'","''"),
ImageUrl = imgURL,
LastName = commandDto.LastName.Replace("'", "''"),
Role = commandDto.Role,
Tags = !string.IsNullOrEmpty(commandDto.Tags) ? commandDto.Tags.Replace("'", "''"): "",
CreatedBy = user.Remove(0, 11),
CreatedOn = commandDto.CreatedOn,
IsSuperUser = false,
Extension = !string.IsNullOrEmpty(commandDto.Extension) ? commandDto.Extension.Replace("'", "''") : "",
CartoonURL = cartoonURL,
windowsIdentity = user,
emailAddress = commandDto.EmailAddress,
SeatingFloor = commandDto.SeatingFloor,
seatNo = commandDto.SeatNo
});
conn.Close();
}
}
示例5: ClearLogs
private void ClearLogs()
{
using (var connection = new SQLiteConnection(ConnectionString))
{
connection.Execute("delete from Log");
}
}
示例6: Setup
public virtual void Setup()
{
string connectionString = string.Format("Data Source=.\\dapperTest_{0}.sqlite", Guid.NewGuid());
string[] connectionParts = connectionString.Split(';');
string file = connectionParts
.ToDictionary(k => k.Split('=')[0], v => v.Split('=')[1])
.Where(d => d.Key.Equals("Data Source", StringComparison.OrdinalIgnoreCase))
.Select(k => k.Value).Single();
if (File.Exists(file))
{
File.Delete(file);
}
SQLiteConnection connection = new SQLiteConnection(connectionString);
var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper<>), new List<Assembly>(), new SqliteDialect());
var sqlGenerator = new SqlGeneratorImpl(config);
Db = new Database(connection, sqlGenerator);
var files = new List<string>
{
ReadScriptFile("CreateAnimalTable"),
ReadScriptFile("CreateFooTable"),
ReadScriptFile("CreateMultikeyTable"),
ReadScriptFile("CreatePersonTable"),
ReadScriptFile("CreateCarTable")
};
foreach (var setupFile in files)
{
connection.Execute(setupFile);
}
}
示例7: ModuleConfigurations
public ModuleConfigurations()
{
db = new SQLiteConnection("Data Source=:memory:;Version=3;New=True");
//todo: create platy table
db.Open();
db.Execute("PRAGMA foreign_keys=ON");
}
示例8: Execute
public bool Execute(string connectionString, string sql)
{
using (var cnn = new SQLiteConnection(connectionString))
{
cnn.Open();
return cnn.Execute(sql) > 0;
}
}
示例9: LitePostRepository
public LitePostRepository()
{
using (var conn = new SQLiteConnection(Connectionstring))
{
conn.Open();
conn.Execute(@" create table IF NOT EXISTS Posts (Id INTEGER PRIMARY KEY, Title nvarchar(255), Content nvarchar(1000) not null) ");
}
}
示例10: CreateConnectionCore
protected override DbConnection CreateConnectionCore()
{
var con = new SQLiteConnection(ConnectionStringBuilder.CreateWithFullUri(
"file::memory:?cache=shared"));
con.Open();
con.Execute("PRAGMA case_sensitive_like=1");
return con;
}
示例11: btnSave_Click
private void btnSave_Click(object sender, System.EventArgs e)
{
if (InfoIsError()) return;
using (var conn = new SQLiteConnection(Common.ConnectionString))
{
if (IsModify)
{
conn.Execute("UPDATE RemoteHost SET [email protected],[email protected],[email protected],[email protected] WHERE [email protected]",
new { name = txtName.Text, connectId = cbIpAddress.SelectedValue, parentId = chIsParent.Checked ? 0 : cbParent.SelectedValue, sort = numSort.Text, id = RemoteHost.FId });
}
else
{
conn.Execute("INSERT INTO RemoteHost('FName','FConectId','FParentId','FSort') VALUES(@name,@connectId,@parentId,@sort)",
new { name = txtName.Text, connectId = cbIpAddress.SelectedValue, parentId = chIsParent.Checked ? 0 : cbParent.SelectedValue, sort = numSort.Text });
}
}
DialogResult = DialogResult.OK;
}
示例12: CreateDb
public void CreateDb()
{
using (var connection = new SQLiteConnection(ConnectionString))
{
var query = @"CREATE TABLE Init (Id INT NOT NULL)";
connection.Open();
connection.Execute(query);
}
}
示例13: SaveEvent
public static void SaveEvent(EventInfo eventInfo)
{
using (var conn = new SQLiteConnection(_connectionString))
{
var query = @" insert into EventInfo(WindowTitle, EventType)
values (@title, @type);";
conn.Open();
conn.Execute(query, new { title = eventInfo.WindowTitle, type = eventInfo.EventType }, null, null, null);
}
}
示例14: ModulesRepository
public ModulesRepository(SQLiteConnection database)
{
this.db = database;
lock(database) {
if (db.State == System.Data.ConnectionState.Closed)
{
db.Open();
}
}
db.Execute("PRAGMA foreign_keys=ON");
}
示例15: Set
public void Set(IContent content)
{
string connString = ConfigurationManager.ConnectionStrings["WilliamsonFamilyConnectionString"].ConnectionString;
//var connection = new ProfiledDbConnection(new SQLiteConnection(connString), MiniProfiler.Current);
using (var conn = new SQLiteConnection(connString))
{
conn.Open();
var contentExists = conn.Query<Content>("SELECT * FROM Content WHERE Token = @token", new { @token = content.Token }, null, true, null, null).FirstOrDefault();
if (contentExists == null)
conn.Execute("INSERT INTO Content (Token, Value) VALUES (@Token, @Value)", new { @token = content.Token, @value = content.Value }, null, null, null);
else
conn.Execute(@"
UPDATE Content
SET Token = @Token,
Value = @Value
WHERE ContentID = @ContentID", new { @token = content.Token, @value = content.Value, @ContentID = content.ContentID }, null, null, null);
conn.Close();
}
}