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


C# TableSchema.IsKeyExist方法代码示例

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


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

示例1: GetIndexes

		private static List<IndexSchema> GetIndexes(DbConnection con, TableSchema eTable)
		{
			var aStore = new List<IndexSchema>();

			string[] restrict3 = {null, null, eTable.Name};
			string[] restrict4 = {null, null, eTable.Name, null};

			// INDEX_TYPE = 0 - ascending, 1 - descending
			restrict4[0] = null;
			restrict4[1] = null;
			restrict4[2] = eTable.Name;
			restrict4[3] = null;
			var dtShema = con.GetSchema("Indexes", restrict3);
			aStore.Clear();
			for (var x = 0; x < dtShema.Rows.Count; x++)
			{
				var cRow = dtShema.Rows[x];
				var cName = cRow["INDEX_NAME"].ToString();
				if (eTable.IsKeyExist(cName, ConstraintType.Unique) ||
					eTable.IsKeyExist(cName, ConstraintType.KeyPrimary) ||
					eTable.IsKeyExist(cName, ConstraintType.KeyForeign))
					continue;

				var eIndex = new IndexSchema();
				var columns = "";
				eIndex.Name = cName;
				eIndex.Unique = Convert.ToBoolean(cRow["IS_UNIQUE"], CultureInfo.InvariantCulture);
				if (cRow["INDEX_TYPE"] == DBNull.Value)
					eIndex.Sort = SortOrder.Ascending;
				else
					eIndex.Sort = Convert.ToInt32(cRow["INDEX_TYPE"], CultureInfo.InvariantCulture) == 0
									? SortOrder.Ascending
									: SortOrder.Descending;
				eIndex.IsActive = !Convert.ToBoolean(cRow["IS_INACTIVE"], CultureInfo.InvariantCulture);

				restrict4[3] = cName;
				var dtShemaCols = con.GetSchema("IndexColumns", restrict4);
				var dtv = dtShemaCols.DefaultView;
				//dtv.RowFilter = "INDEX_NAME = '" + cName + "'";
				dtv.Sort = "ORDINAL_POSITION ASC";
				for (var y = 0; y < dtv.Count; y++)
					columns += (dtv[y]["COLUMN_NAME"] + ", ");
				columns = columns.Remove(columns.Length - 2, 2);
				eIndex.Columns = columns;
				aStore.Add(eIndex);
			}
			return aStore;
		}
开发者ID:rsdn,项目名称:janus,代码行数:48,代码来源:FBSchemaLoader.cs

示例2: GetIndexes

		private static List<IndexSchema> GetIndexes(DbConnection con, TableSchema eTable)
		{
			var aStore = new List<IndexSchema>();
			var aHash = new List<string>();

			string[] restrict4 = {null, null, null, null};
			string[] restrict5 = {null, null, null, null, null};

			// INDEX_TYPE = 0 - ascending, 1 - descending
			restrict4[2] = eTable.Name;
			restrict5[2] = eTable.Name;
			var dtShema = con.GetSchema("Indexes", restrict4);
			aStore.Clear();
			aHash.Clear();
			for (var x = 0; x < dtShema.Rows.Count; x++)
			{
				var cRow = dtShema.Rows[x];
				var cName = cRow["INDEX_NAME"].ToString();
				if (eTable.IsKeyExist(cName, ConstraintType.Unique) ||
					eTable.IsKeyExist(cName, ConstraintType.KeyPrimary) ||
						eTable.IsKeyExist(cName, ConstraintType.KeyForeign) ||
							Convert.ToBoolean(cRow["PRIMARY_KEY"], CultureInfo.InvariantCulture))
					continue;
				if (aHash.Contains(cName))
					continue;
				var eIndex = new IndexSchema();
				var columns = String.Empty;
				aHash.Add(cName);
				eIndex.Name = cName;
				eIndex.Unique = Convert.ToBoolean(cRow["UNIQUE"], CultureInfo.InvariantCulture);
				if (cRow["TYPE"] == DBNull.Value)
					eIndex.Sort = SortOrder.Ascending;
				else
					eIndex.Sort = Convert.ToInt32(cRow["TYPE"], CultureInfo.InvariantCulture) == 0
						? SortOrder.Ascending
						: SortOrder.Descending;
				eIndex.IsActive = true;
				// !Convert.ToBoolean(cRow["IS_INACTIVE"], CultureInfo.InvariantCulture);

				restrict5[3] = cName;
				var dtIndexColumns = con.GetSchema("IndexColumns", restrict5);

				var first = true;
				for (var y = 0; y < dtIndexColumns.Rows.Count; y++)
				{
					if (first)
						first = false;
					else
						columns += ", ";

					columns += dtIndexColumns.Rows[y]["COLUMN_NAME"];
				}

				eIndex.Columns = columns;
				aStore.Add(eIndex);
			}
			return aStore;
		}
开发者ID:rsdn,项目名称:janus,代码行数:58,代码来源:SqliteSchemaLoader.cs

示例3: GetIndexes

		private static List<IndexSchema> GetIndexes(SqlConnection con, TableSchema eTable)
		{
			var indexes = new List<IndexSchema>();
			var aHash = new Dictionary<string, bool>();
			string[] restrict4 = {null, null, null, null};

			// Indexes
			restrict4[0] = null;
			restrict4[1] = null;
			restrict4[2] = eTable.Name;
			restrict4[3] = null;
			var dtShema = SqlSchemaFactory.GetSchema(con, "Indexes", restrict4);
			for (var i = 0; i < dtShema.Rows.Count; i++)
			{
				var row = dtShema.Rows[i];
				if (Convert.ToBoolean(row["IS_STATISTICS"], CultureInfo.InvariantCulture) ||
					Convert.ToBoolean(row["IS_AUTOSTATISTICS"], CultureInfo.InvariantCulture) ||
					Convert.ToBoolean(row["IS_HYPOTTETICAL"], CultureInfo.InvariantCulture))
					continue;

				var cName = row["INDEX_NAME"].ToString();
				if (eTable.IsKeyExist(cName, ConstraintType.Unique) ||
					eTable.IsKeyExist(cName, ConstraintType.KeyPrimary) ||
					eTable.IsKeyExist(cName, ConstraintType.KeyForeign))
					continue;

				if (aHash.ContainsKey(cName))
					continue;
				var eIndex = new IndexSchema();
				aHash.Add(cName, true);
				eIndex.Name = cName;
				eIndex.Unique = Convert.ToBoolean(row["IS_UNIQUE"], CultureInfo.InvariantCulture);
				eIndex.Clustered = Convert.ToBoolean(row["IS_CLUSTERED"], CultureInfo.InvariantCulture);
				//eIndex.isActive = !Convert.ToBoolean(cRow["IS_INACTIVE"], CultureInfo.InvariantCulture);

				var dtv = dtShema.DefaultView;
				dtv.RowFilter = string.Format("INDEX_NAME = '{0}'", cName);
				dtv.Sort = "COLUMN_ORDINAL_POSITION ASC";

				var columns = "";
				for (var y = 0; y < dtv.Count; y++)
					columns += (dtv[y]["COLUMN_NAME"] +
								(Convert.ToBoolean(dtv[y]["IS_DESCENDING"], CultureInfo.InvariantCulture) ? " DESC" : "") +
								", ");
				columns = columns.Remove(columns.Length - 2, 2);
				eIndex.Columns = columns;
				indexes.Add(eIndex);
			}
			return indexes;
		}
开发者ID:rsdn,项目名称:janus,代码行数:50,代码来源:MssqlSchemaLoader.cs

示例4: LoadSchema

		public static DBSchema LoadSchema(string connStr)
		{
			var dbsc = new DBSchema();

			var catalog = (Catalog)new CatalogClass();
			var conn = new ConnectionClass();
			try
			{
				var csb = new JetConnectionStringBuilder(connStr);

				var keysList = new List<KeySchema>();
				var indexesList = new List<IndexSchema>();

				conn.Open(csb.ConnectionString, string.Empty, string.Empty, 0);
				catalog.ActiveConnection = conn;

				var slashPos = csb.DataSource.LastIndexOf(@"\");

				dbsc.Name = csb.DataSource.Substring(slashPos == -1 ? 0 : slashPos + 1);

				foreach (var xTable in GetTables(catalog))
				{
					keysList.Clear();
					indexesList.Clear();

					var eTable = new TableSchema
					{
						Name = xTable.Name,
						Columns = GetColumns(xTable).ToArray(),
						Keys = GetKeys(xTable).ToArray(),
						Indexes = GetIndexes(xTable).ToArray()
					};

					// Фильтрация ключей
					foreach (var key in eTable.Keys)
					{
						// Долбаный Аксес создает при создании внешних ключей уникальные индексы.
						if (key.KeyType == ConstraintType.KeyForeign && !eTable.IsIndexExist(key.Name))
							continue;
						if (key.KeyType == ConstraintType.Unique &&
							eTable.IsKeyExist(key.Name, ConstraintType.KeyForeign))
							continue;

						keysList.Add(key);
					}
					eTable.Keys = keysList.ToArray();

					// Фильтрация индексов
					foreach (var index in eTable.Indexes)
					{
						if (eTable.IsKeyExist(index.Name, ConstraintType.Unique) ||
							eTable.IsKeyExist(index.Name, ConstraintType.KeyPrimary) ||
								eTable.IsKeyExist(index.Name, ConstraintType.KeyForeign))
							continue;

						indexesList.Add(index);
					}
					eTable.Indexes = indexesList.ToArray();

					dbsc.Tables.Add(eTable);
				}
			}
			finally
			{
				Marshal.ReleaseComObject(conn);
				Marshal.ReleaseComObject(catalog);
			}

			return dbsc;
		}
开发者ID:rsdn,项目名称:janus,代码行数:70,代码来源:JetSchemaLoader.cs


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