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


C# SQLiteConnectionStringBuilder.ContainsKey方法代码示例

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


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

示例1: Open

		public override void Open()
		{
			VerifyNotDisposed();
			if (State != ConnectionState.Closed)
				throw new InvalidOperationException("Cannot Open when State is {0}.".FormatInvariant(State));

			var connectionStringBuilder = new SQLiteConnectionStringBuilder { ConnectionString = ConnectionString };
			m_dataSource = connectionStringBuilder.DataSource;
			if (string.IsNullOrEmpty(m_dataSource))
				throw new InvalidOperationException("Connection String Data Source must be set.");

			SQLiteOpenFlags openFlags = connectionStringBuilder.ReadOnly ? SQLiteOpenFlags.ReadOnly : SQLiteOpenFlags.ReadWrite;
			if (!connectionStringBuilder.FailIfMissing && !connectionStringBuilder.ReadOnly)
				openFlags |= SQLiteOpenFlags.Create;

			SetState(ConnectionState.Connecting);

			Match m = s_vfsRegex.Match(m_dataSource);
			string fileName = m.Groups["fileName"].Value;
			string vfsName = m.Groups["vfsName"].Value;
			var errorCode = NativeMethods.sqlite3_open_v2(ToNullTerminatedUtf8(fileName), out m_db, openFlags, string.IsNullOrEmpty(vfsName) ? null : ToNullTerminatedUtf8(vfsName));

			bool success = false;
			try
			{
				if (errorCode != SQLiteErrorCode.Ok)
				{
					SetState(ConnectionState.Broken);
					errorCode.ThrowOnError();
				}

				if (!string.IsNullOrEmpty(connectionStringBuilder.Password))
				{
					byte[] passwordBytes = Encoding.UTF8.GetBytes(connectionStringBuilder.Password);
					NativeMethods.sqlite3_key(m_db, passwordBytes, passwordBytes.Length).ThrowOnError();
				}

				bool allowOpenReadOnly = true;
#if MONOANDROID
				// opening read-only throws "EntryPointNotFoundException: sqlite3_db_readonly" on Android API 15 and below (JellyBean is API 16)
				allowOpenReadOnly = Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.JellyBean;
#endif
				if (allowOpenReadOnly)
				{
					int isReadOnly = NativeMethods.sqlite3_db_readonly(m_db, "main");
					if (isReadOnly == 1 && !connectionStringBuilder.ReadOnly)
						throw new SQLiteException(SQLiteErrorCode.ReadOnly);
				}

				if (connectionStringBuilder.CacheSize != 0)
					this.ExecuteNonQuery("pragma cache_size={0}".FormatInvariant(connectionStringBuilder.CacheSize));

				if (connectionStringBuilder.PageSize != 0)
					this.ExecuteNonQuery("pragma page_size={0}".FormatInvariant(connectionStringBuilder.PageSize));

				if (connectionStringBuilder.ContainsKey(SQLiteConnectionStringBuilder.MmapSizeKey))
					this.ExecuteNonQuery("pragma mmap_size={0}".FormatInvariant(connectionStringBuilder.MmapSize));

				if (connectionStringBuilder.ForeignKeys)
					this.ExecuteNonQuery("pragma foreign_keys = on");

				if (connectionStringBuilder.JournalMode != SQLiteJournalModeEnum.Default)
					this.ExecuteNonQuery("pragma journal_mode={0}".FormatInvariant(connectionStringBuilder.JournalMode));

				if (connectionStringBuilder.ContainsKey(SQLiteConnectionStringBuilder.SynchronousKey))
					this.ExecuteNonQuery("pragma synchronous={0}".FormatInvariant(connectionStringBuilder.SyncMode));

				if (connectionStringBuilder.TempStore != SQLiteTemporaryStore.Default)
					this.ExecuteNonQuery("pragma temp_store={0}".FormatInvariant(connectionStringBuilder.TempStore));

				if (m_statementCompleted != null)
					SetProfileCallback(s_profileCallback);

				SetState(ConnectionState.Open);
				success = true;
			}
			finally
			{
				if (!success)
					Utility.Dispose(ref m_db);
			}
		}
开发者ID:sakurahoshi,项目名称:System.Data.SQLite,代码行数:82,代码来源:SQLiteConnection.cs


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