当前位置: 首页>>代码示例>>C#>>正文


C# SQLiteConnection.Execute方法代码示例

本文整理汇总了C#中SQLiteConnection.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection.Execute方法的具体用法?C# SQLiteConnection.Execute怎么用?C# SQLiteConnection.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SQLiteConnection的用法示例。


在下文中一共展示了SQLiteConnection.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Install

        public static void Install(SQLiteConnection connection, string schema)
        {
            if (connection == null) throw new ArgumentNullException("connection");

            Log.Info("Start installing Hangfire SQL objects...");

            var script = GetStringResource(
                typeof(SQLiteObjectsInstaller).Assembly,
                "Hangfire.SQLite.Install.sql");

            script = script.Replace("SET @TARGET_SCHEMA_VERSION = 5;", "SET @TARGET_SCHEMA_VERSION = " + RequiredSchemaVersion + ";");

            script = script.Replace("$(HangFireSchema)", !string.IsNullOrWhiteSpace(schema) ? schema : Constants.DefaultSchema);

            for (var i = 0; i < RetryAttempts; i++)
            {
                try
                {
                    connection.Execute(script);
                    break;
                }
                catch (SQLiteException ex)
                {
                    throw;
                }
            }

            Log.Info("Hangfire SQL objects installed.");
        }
开发者ID:AGRocks,项目名称:HangfireExtension,代码行数:29,代码来源:SQLiteObjectsInstaller.cs

示例2: Dispose

		public void Dispose()
		{
			using (var conn = new SQLiteConnection(m_csb.ConnectionString))
			{
				conn.Open();
				conn.Execute("create table Test (Id int primary key);");

				using (var trans = conn.BeginTransaction())
				{
					conn.Execute("insert into Test(Id) values(1)", transaction: trans);
				}

				using (var cmd = new SQLiteCommand(@"select count(Id) from Test", conn))
					Assert.AreEqual(0L, (long) cmd.ExecuteScalar());
			}
		}
开发者ID:sakurahoshi,项目名称:System.Data.SQLite,代码行数:16,代码来源:SqliteTransactionTests.cs

示例3: Clear

 public void Clear()
 {
     using (var c = new SQLiteConnection(platform, DbPath))
     {
         c.Execute("DELETE FROM BackgroundTrackItem");
     }
 }
开发者ID:robUx4,项目名称:vlc-winrt,代码行数:7,代码来源:BackgroundTrackDatabase.cs

示例4: Up

 public static void Up(SQLiteConnection dbConn)
 {
     var sql = "CREATE TABLE `ServerAccounts` (" +
               "`Id` INTEGER PRIMARY KEY AUTOINCREMENT, " +
               "`DeletedAt` DATETIME DEFAULT NULL, " +
               "`CreatedAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP," +
               "`ModifiedAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP," +
               "`ServerIdentifier` STRING NOT NULL," +
               "`LastBackupTime` DATETIME NOT NULL" +
               ");";
     
     dbConn.Execute(sql);
 }
开发者ID:bowmark,项目名称:allauth.desktop,代码行数:13,代码来源:Mig0001CreateInitialTables.cs

示例5: Up

        public static void Up(SQLiteConnection dbConn)
        {
            var sql = "CREATE TABLE `EntriesSharedSecretsRequests` (" +
                      "`Id` INTEGER PRIMARY KEY AUTOINCREMENT, " +
                      "`DeletedAt` DATETIME DEFAULT NULL, " +
                      "`CreatedAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP," +
                      "`ModifiedAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP," +
                      "`RequestMessageIdentifier` TEXT NOT NULL," +
                      "`ValidUntil` DATETIME NOT NULL," +
                      "`EntryId` INTEGER NOT NULL," +
                      "`EntrySecretId` INTEGER NOT NULL," +
                      "`Processed` INT NOT NULL DEFAULT 0," +
                      "`ProcessedAt` DATETIME DEFAULT NULL," +
                      "`ProcessedSuccess` INT NOT NULL DEFAULT 0" +
                      ");";

            dbConn.Execute(sql);
        }
开发者ID:bowmark,项目名称:allauth.desktop,代码行数:18,代码来源:Mig0002PendingSecretRequestsTable.cs

示例6: ReadOnly

		public void ReadOnly()
		{
			using (SQLiteConnection conn = new SQLiteConnection(m_csb.ConnectionString))
			{
				conn.Open();
				conn.Execute("create table Test (TestId int primary key);");
			}

			File.SetAttributes(m_path, FileAttributes.ReadOnly);

			using (SQLiteConnection conn = new SQLiteConnection(m_csb.ConnectionString))
			{
				try
				{
					conn.Open();
					Assert.Fail("Didn't throw exception");
				}
				catch (SQLiteException ex)
				{
					Assert.AreEqual((int) SQLiteErrorCode.ReadOnly, ex.ErrorCode);
				}
			}

			m_csb.ReadOnly = true;
			using (SQLiteConnection conn = new SQLiteConnection(m_csb.ConnectionString))
			{
				try
				{
					conn.Open();
				}
				catch (SQLiteException ex)
				{
					Assert.Fail("Threw exception: {0}", ex.Message);
				}
			}

			File.SetAttributes(m_path, FileAttributes.Normal);
			File.Delete(m_path);
		}
开发者ID:sakurahoshi,项目名称:System.Data.SQLite,代码行数:39,代码来源:SqliteTests.cs

示例7: DropAndCreateDatabase

        /// <summary>
        /// Drop and create database.
        /// </summary>
        /// <returns></returns>
        private async Task<bool> DropAndCreateDatabase()
        {
            await DeleteDatabase();

            using (dbConn = new SQLiteConnection(new SQLitePlatformWinRT(), App.DbPath))
            {
                dbConn.Execute("PRAGMA encoding='UTF-8'");

                dbConn.CreateTable<User>();
                dbConn.CreateTable<Sentence>();
                dbConn.CreateTable<Recording>();
                dbConn.CreateTable<Photo>();
                dbConn.CreateTable<MyOwnWord>();

                //create vw_mowlist
                string vw_mowlist = await Get_vw_mowlist();
                int i = dbConn.Execute(vw_mowlist);

            }

            return true;
        }
开发者ID:sutakjakub,项目名称:MyOwnWords,代码行数:26,代码来源:Seed.cs

示例8: ThreadProc2

		private void ThreadProc2(object state)
		{
			var barrier = (Barrier) state;
			using (var conn = new SQLiteConnection(m_csb.ConnectionString))
			{
				barrier.SignalAndWait();

				conn.Open();
				barrier.SignalAndWait();

				using (var trans = conn.BeginTransaction())
				{
					conn.Execute("select Id from Test", transaction: trans);
					conn.Execute("update Test set Id = 3;", transaction: trans);
					trans.Commit();
				}
			}
		}
开发者ID:sakurahoshi,项目名称:System.Data.SQLite,代码行数:18,代码来源:SqliteTransactionTests.cs

示例9: ConcurrentReads

		public void ConcurrentReads()
		{
			using (var conn = new SQLiteConnection(m_csb.ConnectionString))
			{
				conn.Open();
				conn.Execute("create table Test (Id int primary key);");
				conn.Execute("insert into Test(Id) values(1), (2), (3), (4), (5), (6), (7), (8), (9), (10);");
			}

			const int  c_threadCount = 8;
			using (var barrier = new Barrier(c_threadCount))
				Task.WaitAll(Enumerable.Range(0, c_threadCount).Select(x => Task.Run(() => ConcurrentReadTask(barrier))).ToArray());
		}
开发者ID:sakurahoshi,项目名称:System.Data.SQLite,代码行数:13,代码来源:SqliteTransactionTests.cs

示例10: IndexedParameters

		public void IndexedParameters()
		{
			using (SQLiteConnection conn = new SQLiteConnection(m_csb.ConnectionString))
			{
				conn.Open();
				conn.Execute(@"create table Test (Id integer primary key, String text);");
				using (var cmd = new SQLiteCommand(@"insert into Test(Id, String) values(?, ?)", conn))
				{
					cmd.Parameters.Add(new SQLiteParameter { DbType = DbType.Int32, Value = 1 });
					cmd.Parameters.Add(new SQLiteParameter { DbType = DbType.String, Value = "test" });
					cmd.ExecuteNonQuery();
				}
				using (var reader = conn.ExecuteReader(@"select String from Test where Id = 1"))
				{
					Assert.IsTrue(reader.Read());
					Assert.AreEqual("test", reader.GetString(0));
				}
			}
		}
开发者ID:sakurahoshi,项目名称:System.Data.SQLite,代码行数:19,代码来源:SqliteTests.cs

示例11: ThreadProc1

		private void ThreadProc1(object state)
		{
			var barrier = (Barrier) state;
			using (var conn = new SQLiteConnection(m_csb.ConnectionString))
			{
				conn.Open();
				using (var trans = conn.BeginTransaction())
				{
					conn.Execute("select Id from Test", transaction: trans);
					barrier.SignalAndWait();

					conn.Execute("update Test set Id = 2;", transaction: trans);
					barrier.SignalAndWait();

					// give the other thread time to attempt begin the transaction, which will hang if both threads
					// try to write concurrently
					Thread.Sleep(TimeSpan.FromSeconds(2));
					trans.Commit();
				}
			}
		}
开发者ID:sakurahoshi,项目名称:System.Data.SQLite,代码行数:21,代码来源:SqliteTransactionTests.cs

示例12: DatabaseCleanUp

        // Same method used to clean up the
        // database.
        private void DatabaseCleanUp (SQLiteConnection cnn)
        {
            // TODO: temporal method to clear old
            // draft entries from DB. It should be removed
            // in next versions.
            cnn.Table <TimeEntryData> ().Delete (t => t.State == TimeEntryState.New);

            // TODO: temporal method to clear
            // data with wrong workspace defined.
            var user = cnn.Table <UserData> ().FirstOrDefault ();
            if (user != null && user.DefaultWorkspaceId != Guid.Empty) {
                var tableNames = new List<string>  { cnn.Table<TimeEntryData>().Table.TableName,
                                                     cnn.Table<ClientData>().Table.TableName,
                                                     cnn.Table<ProjectData>().Table.TableName,
                                                     cnn.Table<TagData>().Table.TableName,
                                                     cnn.Table<TaskData>().Table.TableName
                                                   };
                cnn.RunInTransaction (() =>  {
                    foreach (var tableName in tableNames) {
                        var q = string.Concat ("UPDATE ", tableName ," SET WorkspaceId = '", user.DefaultWorkspaceId ,"' WHERE WorkspaceId = '", Guid.Empty, "'");
                        cnn.Execute (q);
                    }
                });
            }
        }
开发者ID:eatskolnikov,项目名称:mobile,代码行数:27,代码来源:DataStoreTest.cs

示例13: Reset

        public static void Reset(SQLiteConnection connection, SQLiteConnection readModelConnection)
        {
            connection.CreateTable<AggregateEvent>();
            connection.CreateTable<AggregateIndex>();
            connection.CreateTable<AggregateSnapshot>();
            connection.CreateTable<PendingCommand>();
            connection.CreateTable<SyncState>();

            connection.Execute("delete from AggregateEvent");
            connection.Execute("delete from AggregateIndex");
            connection.Execute("delete from AggregateSnapshot");
            connection.Execute("delete from PendingCommand");
            connection.Execute("delete from SyncState");

            if (readModelConnection != null)
            {
                readModelConnection.CreateTable<ReadModelWorkItem>();
                readModelConnection.CreateTable<TransactionDataContract>();
                readModelConnection.Execute("delete from ReadModelWorkItem");
                readModelConnection.Execute("delete from TransactionDataContract");
            }
        }
开发者ID:sgmunn,项目名称:Mobile.CQRS,代码行数:22,代码来源:SyncSample.cs

示例14: TypeConversion

		public void TypeConversion(string columnType, object value, params object[] typesAndValues)
		{
			using (SQLiteConnection conn = new SQLiteConnection(m_csb.ConnectionString))
			{
				conn.Open();
				conn.Execute(@"create table Test (Id integer primary key autoincrement, Value {0});".FormatInvariant(columnType));
				conn.Execute(@"insert into Test (Value) values(@value);", new { value });

				// test that GetValue returns the right value
				using (var reader = conn.ExecuteReader(@"select Value from Test"))
				{
					Assert.IsTrue(reader.Read());
					object actual = reader.GetValue(0);
					Assert.AreEqual(value ?? DBNull.Value, actual);
				}

				// test that each specified GetX method returns the right value
				foreach (var typeAndValue in GetTypesAndValues(typesAndValues))
				{
					using (var reader = conn.ExecuteReader(@"select Value from Test"))
					{
						Assert.IsTrue(reader.Read());
						var methodInfo = reader.GetType().GetMethod("Get" + typeAndValue.Key);
						object actual = methodInfo.Invoke(reader, new object[] { 0 });
						object expected = typeAndValue.Value ?? DBNull.Value;
						if (expected == DBNull.Value)
						{
							Assert.IsNull(actual);
						}
						else
						{
							Assert.AreEqual(expected, actual);
							Assert.AreEqual(expected.GetType(), actual.GetType());
						}
					}
				}

				// test that all other GetX methods throw
				foreach (var type in s_availableTypes.Except(GetTypesAndValues(typesAndValues).Select(x => x.Key)))
				{
					using (var reader = conn.ExecuteReader(@"select Value from Test"))
					{
						Assert.IsTrue(reader.Read());
						var methodInfo = reader.GetType().GetMethod("Get" + type);
						try
						{
							methodInfo.Invoke(reader, new object[] { 0 });
							Assert.Fail("No exception thrown for {0}".FormatInvariant(type));
						}
						catch (TargetInvocationException ex)
						{
							Assert.IsTrue(new[] { typeof(InvalidCastException), typeof(FormatException), typeof(OverflowException) }.Contains(ex.InnerException.GetType()));
						}
					}
				}
			}
		}
开发者ID:sakurahoshi,项目名称:System.Data.SQLite,代码行数:57,代码来源:SqliteTests.cs

示例15: Up

        public static void Up(SQLiteConnection dbConn)
        {
            var sql = "CREATE TABLE `CryptoKeys` (" +
                      "`Id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
                      "`DeletedAt` DATETIME DEFAULT NULL, " +
                      "`CreatedAt` DATETIME NOT NULL, " +
                      "`ModifiedAt` DATETIME NOT NULL, " +
                      "`OwnKey` INTEGER NOT NULL, " +
                      "`Trust` INTEGER NOT NULL, " +
                      "`PrivateKeyPem` TEXT NOT NULL, " +
                      "`PublicKeyPem` TEXT NOT NULL, " +
                      "`PublicKeyPemHash` TEXT NOT NULL" +
                      ");";
            dbConn.Execute(sql);

            sql = "CREATE TABLE `Entries` (" +
                  "`Id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
                  "`DeletedAt` DATETIME DEFAULT NULL, " +
                  "`CreatedAt` DATETIME NOT NULL, " +
                  "`ModifiedAt` DATETIME NOT NULL, " +
                  "`Identifier` TEXT NOT NULL, " +
                  "`LinkId` TEXT NOT NULL" +
                  ");";
            dbConn.Execute(sql);

            sql = "CREATE TABLE `EntriesSharedSecrets` (" +
                  "`Id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
                  "`DeletedAt` DATETIME DEFAULT NULL, " +
                  "`CreatedAt` DATETIME NOT NULL, " +
                  "`ModifiedAt` DATETIME NOT NULL, " +
                  "`EntryId` INTEGER NOT NULL, " +
                  "`SecretIdentifier` TEXT NOT NULL, " +
                  "`EntrySecretDataId` INTEGER NOT NULL, " +
                  "`ToBeDeleted` INTEGER NOT NULL " +
                  ");";
            dbConn.Execute(sql);

            sql = "CREATE TABLE `EntriesSharedSecretsData` (" +
                      "`Id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
                      "`DeletedAt` DATETIME DEFAULT NULL, " +
                      "`CreatedAt` DATETIME NOT NULL, " +
                      "`ModifiedAt` DATETIME NOT NULL, " +
                      "`ShareType` TEXT NOT NULL, " +
                      "`Secret` TEXT NOT NULL" +
                      ");";
            dbConn.Execute(sql);

            sql = "CREATE TABLE `EntriesSharedSecretsSync` (" +
                  "`Id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
                  "`DeletedAt` DATETIME DEFAULT NULL, " +
                  "`CreatedAt` DATETIME NOT NULL, " +
                  "`ModifiedAt` DATETIME NOT NULL, " +
                  "`EntrySecretId` INTEGER NOT NULL" +
                  ");";
            dbConn.Execute(sql);

            sql = "CREATE TABLE `Links` (" +
                  "`Id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
                  "`DeletedAt` DATETIME DEFAULT NULL, " +
                  "`CreatedAt` DATETIME NOT NULL, " +
                  "`ModifiedAt` DATETIME NOT NULL, " +
                  "`Identifier` TEXT NOT NULL" +
                  ");";
            dbConn.Execute(sql);

            sql = "CREATE TABLE `OtpAccounts` (" +
                  "`Id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
                  "`DeletedAt` DATETIME DEFAULT NULL, " +
                  "`CreatedAt` DATETIME NOT NULL, " +
                  "`ModifiedAt` DATETIME NOT NULL, " +
                  "`Type` TEXT NOT NULL, " +
                  "`Label` TEXT NOT NULL, " +
                  "`Issuer` TEXT NOT NULL, " +
                  "`Algorithm` TEXT NOT NULL, " +
                  "`Secret` TEXT NOT NULL, " +
                  "`Digits` INTEGER NOT NULL, " +
                  "`Counter` INTEGER NOT NULL, " +
                  "`Period` INTEGER NOT NULL" +
                  ");";
            dbConn.Execute(sql);

            sql = "CREATE TABLE `ServerAccountSettings` (" +
                  "`Id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
                  "`DeletedAt` DATETIME DEFAULT NULL, " +
                  "`CreatedAt` DATETIME NOT NULL, " +
                  "`ModifiedAt` DATETIME NOT NULL, " +
                  "`Identifier` TEXT NOT NULL, " +
                  "`Label` TEXT NOT NULL, " +
                  "`HttpsEnabled` INTEGER NOT NULL, " +
                  "`Host` TEXT NOT NULL, " +
                  "`Port` INTEGER NOT NULL, " +
                  "`ApiVersion` INTEGER NOT NULL, " +
                  "`UserIdentifier` TEXT NOT NULL, " +
                  "`DeviceIdentifier` TEXT NOT NULL, " +
                  "`OtpAccountId` INTEGER NOT NULL, " +
                  "`ApiKey` TEXT NOT NULL, " +
                  "`EmailAddress` TEXT NOT NULL, " +
                  "`ApiCryptoKeyId` INTEGER NOT NULL, " +
                  "`LinkedDeviceCryptoKeyId` INTEGER NOT NULL," +
                  "`BackupRecoveryPasswordHashSet` INTEGER NOT NULL," +
//.........这里部分代码省略.........
开发者ID:bowmark,项目名称:allauth.desktop,代码行数:101,代码来源:Mig0001CreateInitialTables.cs


注:本文中的SQLiteConnection.Execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。