/// <summary> /// Get a datatable with all tables primary keys. /// </summary> /// <param name="p_schema">Schema name.</param> /// <param name="p_table">Table name.</param> public override System.Data.DataTable QueryTablesPrimaryKeys(string p_schema, string p_table) { if (p_table == null) { System.Data.DataTable v_tables = this.QueryTables(false); System.Data.DataTable v_pk_all = new System.Data.DataTable(); v_pk_all.Columns.Add("constraint_name"); v_pk_all.Columns.Add("column_name"); v_pk_all.Columns.Add("table_name"); foreach (System.Data.DataRow v_tabletemp in v_tables.Rows) { System.Data.DataRow v_row; System.Data.DataTable v_pk = new System.Data.DataTable("TablePrimaryKeys"); v_pk.Columns.Add("constraint_name"); v_pk.Columns.Add("column_name"); v_pk.Columns.Add("table_name"); com.healthmarketscience.jackcess.Database v_database = com.healthmarketscience.jackcess.DatabaseBuilder.open(new java.io.File(this.v_connection.v_service)); com.healthmarketscience.jackcess.Table v_table = v_database.getTable(v_tabletemp["table_name"].ToString().Replace("[", "").Replace("]", "")); com.healthmarketscience.jackcess.Index v_index = v_table.getPrimaryKeyIndex(); java.util.List v_list = v_index.getColumns(); object[] v_obj = v_list.toArray(); foreach (object o in v_obj) { com.healthmarketscience.jackcess.Index.Column c = (com.healthmarketscience.jackcess.Index.Column)o; v_row = v_pk.NewRow(); v_row["constraint_name"] = v_index.getName(); v_row["column_name"] = c.getName(); v_row["table_name"] = v_tabletemp["table_name"].ToString(); v_pk.Rows.Add(v_row); } v_pk_all.Merge(v_pk); } return(v_pk_all); } else { System.Data.DataRow v_row; System.Data.DataTable v_pk = new System.Data.DataTable("TablePrimaryKeys"); v_pk.Columns.Add("constraint_name"); v_pk.Columns.Add("column_name"); v_pk.Columns.Add("table_name"); com.healthmarketscience.jackcess.Database v_database = com.healthmarketscience.jackcess.DatabaseBuilder.open(new java.io.File(this.v_connection.v_service)); com.healthmarketscience.jackcess.Table v_table = v_database.getTable(p_table.Replace("[", "").Replace("]", "")); com.healthmarketscience.jackcess.Index v_index = v_table.getPrimaryKeyIndex(); java.util.List v_list = v_index.getColumns(); object[] v_obj = v_list.toArray(); foreach (object o in v_obj) { com.healthmarketscience.jackcess.Index.Column c = (com.healthmarketscience.jackcess.Index.Column)o; v_row = v_pk.NewRow(); v_row["constraint_name"] = v_index.getName(); v_row["column_name"] = c.getName(); v_row["table_name"] = p_table; v_pk.Rows.Add(v_row); } return(v_pk); } }
/// <summary> /// Get a datatable with all tables indexes. /// </summary> /// <param name="p_table">Table name.</param> public override System.Data.DataTable QueryTablesIndexes(string p_table) { if (p_table == null) { System.Data.DataTable v_tables = this.QueryTables(false); System.Data.DataTable v_all_indexes = new System.Data.DataTable(); v_all_indexes.Columns.Add("table_name"); v_all_indexes.Columns.Add("index_name"); v_all_indexes.Columns.Add("column_name"); v_all_indexes.Columns.Add("uniqueness"); foreach (System.Data.DataRow v_tabletemp in v_tables.Rows) { System.Data.DataRow v_row; System.Data.DataTable v_indexes = new System.Data.DataTable("TableIndexes"); v_indexes.Columns.Add("table_name"); v_indexes.Columns.Add("index_name"); v_indexes.Columns.Add("column_name"); v_indexes.Columns.Add("uniqueness"); com.healthmarketscience.jackcess.Database v_database = com.healthmarketscience.jackcess.DatabaseBuilder.open(new java.io.File(this.v_connection.v_service)); com.healthmarketscience.jackcess.Table v_table = v_database.getTable(v_tabletemp["table_name"].ToString().Replace("[", "").Replace("]", "")); java.util.List v_list = v_table.getIndexes(); object[] v_obj = v_list.toArray(); foreach (object o in v_obj) { com.healthmarketscience.jackcess.Index v_index = (com.healthmarketscience.jackcess.Index)o; java.util.List v_list2 = v_index.getColumns(); object[] v_obj2 = v_list2.toArray(); foreach (object o2 in v_obj2) { com.healthmarketscience.jackcess.Index.Column c = (com.healthmarketscience.jackcess.Index.Column)o2; v_row = v_indexes.NewRow(); v_row["table_name"] = v_tabletemp["table_name"].ToString(); v_row["index_name"] = v_index.getName(); v_row["column_name"] = c.getName(); if (v_index.isUnique()) { v_row["uniqueness"] = "Unique"; } else { v_row["uniqueness"] = "Non Unique"; } v_indexes.Rows.Add(v_row); } } v_all_indexes.Merge(v_indexes); } return(v_all_indexes); } else { System.Data.DataRow v_row; System.Data.DataTable v_indexes = new System.Data.DataTable("TableIndexes"); v_indexes.Columns.Add("table_name"); v_indexes.Columns.Add("index_name"); v_indexes.Columns.Add("column_name"); v_indexes.Columns.Add("uniqueness"); com.healthmarketscience.jackcess.Database v_database = com.healthmarketscience.jackcess.DatabaseBuilder.open(new java.io.File(this.v_connection.v_service)); com.healthmarketscience.jackcess.Table v_table = v_database.getTable(p_table.Replace("[", "").Replace("]", "")); java.util.List v_list = v_table.getIndexes(); object[] v_obj = v_list.toArray(); foreach (object o in v_obj) { com.healthmarketscience.jackcess.Index v_index = (com.healthmarketscience.jackcess.Index)o; java.util.List v_list2 = v_index.getColumns(); object[] v_obj2 = v_list2.toArray(); foreach (object o2 in v_obj2) { com.healthmarketscience.jackcess.Index.Column c = (com.healthmarketscience.jackcess.Index.Column)o2; v_row = v_indexes.NewRow(); v_row["table_name"] = p_table; v_row["index_name"] = v_index.getName(); v_row["column_name"] = c.getName(); if (v_index.isUnique()) { v_row["uniqueness"] = "Unique"; } else { v_row["uniqueness"] = "Non Unique"; } v_indexes.Rows.Add(v_row); } } return(v_indexes); } }
/// <summary> /// Get a datatable with all tables foreign keys. /// </summary> /// <param name="p_table">Table name.</param> public override System.Data.DataTable QueryTablesForeignKeys(string p_table) { if (p_table == null) { System.Data.DataTable v_tables = this.QueryTables(false); System.Data.DataTable v_all_fks = new System.Data.DataTable(); v_all_fks.Columns.Add("table_name"); v_all_fks.Columns.Add("constraint_name"); v_all_fks.Columns.Add("r_table_name"); v_all_fks.Columns.Add("column_name"); v_all_fks.Columns.Add("r_column_name"); v_all_fks.Columns.Add("update_rule"); v_all_fks.Columns.Add("delete_rule"); foreach (System.Data.DataRow v_tabletemp in v_tables.Rows) { System.Data.DataRow v_row; System.Data.DataTable v_fks = new System.Data.DataTable("TableForeignKeys"); v_fks.Columns.Add("table_name"); v_fks.Columns.Add("constraint_name"); v_fks.Columns.Add("r_table_name"); v_fks.Columns.Add("column_name"); v_fks.Columns.Add("r_column_name"); v_fks.Columns.Add("update_rule"); v_fks.Columns.Add("delete_rule"); com.healthmarketscience.jackcess.Database v_database = com.healthmarketscience.jackcess.DatabaseBuilder.open(new java.io.File(this.v_connection.v_service)); com.healthmarketscience.jackcess.Table v_table = v_database.getTable(v_tabletemp["table_name"].ToString().Replace("[", "").Replace("]", "")); java.util.Set v_set = v_database.getTableNames(); object[] v_obj = v_set.toArray(); foreach (object v_tablename in v_obj) { com.healthmarketscience.jackcess.Table v_table2 = v_database.getTable((string)v_tablename); try { com.healthmarketscience.jackcess.Index v_index = v_table.getForeignKeyIndex(v_table2); if (!v_index.getName().StartsWith(".")) { com.healthmarketscience.jackcess.Index v_index2 = v_index.getReferencedIndex(); java.util.List v_list = v_index.getColumns(); object[] v_obj2 = v_list.toArray(); java.util.List v_list2 = v_index2.getColumns(); object[] v_obj3 = v_list2.toArray(); java.util.List v_list3 = v_database.getRelationships(v_table, v_table2); object[] v_obj4 = v_list3.toArray(); bool v_dcascade = false; bool v_ucascade = false; foreach (object o in v_obj4) { com.healthmarketscience.jackcess.Relationship r = (com.healthmarketscience.jackcess.Relationship)o; if (r.getName() == v_index.getName()) { v_dcascade = r.cascadeDeletes(); v_ucascade = r.cascadeUpdates(); } } int k = 0; foreach (object o in v_obj2) { com.healthmarketscience.jackcess.Index.Column c = (com.healthmarketscience.jackcess.Index.Column)o; com.healthmarketscience.jackcess.Index.Column c2 = (com.healthmarketscience.jackcess.Index.Column)v_obj3[k]; v_row = v_fks.NewRow(); v_row["table_name"] = v_tabletemp["table_name"].ToString(); v_row["constraint_name"] = v_index.getName(); v_row["r_table_name"] = (string)v_tablename; v_row["column_name"] = c.getName(); v_row["r_column_name"] = c2.getName(); if (v_ucascade) { v_row["update_rule"] = "CASCADE"; } else { v_row["update_rule"] = "SET NULL"; } if (v_dcascade) { v_row["delete_rule"] = "CASCADE"; } else { v_row["delete_rule"] = "SET NULL"; } v_fks.Rows.Add(v_row); k++; } } } catch (java.lang.IllegalArgumentException) { } } v_all_fks.Merge(v_fks); } return(v_all_fks); } else { System.Data.DataRow v_row; System.Data.DataTable v_fks = new System.Data.DataTable("TableForeignKeys"); v_fks.Columns.Add("table_name"); v_fks.Columns.Add("constraint_name"); v_fks.Columns.Add("r_table_name"); v_fks.Columns.Add("column_name"); v_fks.Columns.Add("r_column_name"); v_fks.Columns.Add("update_rule"); v_fks.Columns.Add("delete_rule"); com.healthmarketscience.jackcess.Database v_database = com.healthmarketscience.jackcess.DatabaseBuilder.open(new java.io.File(this.v_connection.v_service)); com.healthmarketscience.jackcess.Table v_table = v_database.getTable(p_table.Replace("[", "").Replace("]", "")); java.util.Set v_set = v_database.getTableNames(); object[] v_obj = v_set.toArray(); foreach (object v_tablename in v_obj) { com.healthmarketscience.jackcess.Table v_table2 = v_database.getTable((string)v_tablename); try { com.healthmarketscience.jackcess.Index v_index = v_table.getForeignKeyIndex(v_table2); if (!v_index.getName().StartsWith(".")) { com.healthmarketscience.jackcess.Index v_index2 = v_index.getReferencedIndex(); java.util.List v_list = v_index.getColumns(); object[] v_obj2 = v_list.toArray(); java.util.List v_list2 = v_index2.getColumns(); object[] v_obj3 = v_list2.toArray(); java.util.List v_list3 = v_database.getRelationships(v_table, v_table2); object[] v_obj4 = v_list3.toArray(); bool v_dcascade = false; bool v_ucascade = false; foreach (object o in v_obj4) { com.healthmarketscience.jackcess.Relationship r = (com.healthmarketscience.jackcess.Relationship)o; if (r.getName() == v_index.getName()) { v_dcascade = r.cascadeDeletes(); v_ucascade = r.cascadeUpdates(); } } int k = 0; foreach (object o in v_obj2) { com.healthmarketscience.jackcess.Index.Column c = (com.healthmarketscience.jackcess.Index.Column)o; com.healthmarketscience.jackcess.Index.Column c2 = (com.healthmarketscience.jackcess.Index.Column)v_obj3[k]; v_row = v_fks.NewRow(); v_row["table_name"] = p_table; v_row["constraint_name"] = v_index.getName(); v_row["r_table_name"] = (string)v_tablename; v_row["column_name"] = c.getName(); v_row["r_column_name"] = c2.getName(); if (v_ucascade) { v_row["update_rule"] = "CASCADE"; } else { v_row["update_rule"] = "SET NULL"; } if (v_dcascade) { v_row["delete_rule"] = "CASCADE"; } else { v_row["delete_rule"] = "SET NULL"; } v_fks.Rows.Add(v_row); k++; } } } catch (java.lang.IllegalArgumentException) { } } return(v_fks); } }