public static AccessDataType ConvertAdoxToAccessDataType(Interop.AdoxDataType adoxType) { Interop.AdoxDataType type = adoxType; if (type <= Interop.AdoxDataType.UnsignedTinyInt) { switch (type) { case Interop.AdoxDataType.SmallInt: return AccessDataType.Integer; case Interop.AdoxDataType.Integer: return AccessDataType.LongInteger; case Interop.AdoxDataType.Single: return AccessDataType.Single; case Interop.AdoxDataType.Double: return AccessDataType.Double; case Interop.AdoxDataType.Currency: return AccessDataType.Currency; case Interop.AdoxDataType.Date: return AccessDataType.DateTime; case Interop.AdoxDataType.BSTR: case ((Interop.AdoxDataType) 9): case (Interop.AdoxDataType.BSTR | Interop.AdoxDataType.SmallInt): goto Label_0087; case Interop.AdoxDataType.Boolean: return AccessDataType.YesNo; case Interop.AdoxDataType.UnsignedTinyInt: return AccessDataType.Byte; } } else if (type != Interop.AdoxDataType.GUID) { switch (type) { case Interop.AdoxDataType.VarWChar: return AccessDataType.Text; case Interop.AdoxDataType.LongVarWChar: return AccessDataType.Memo; case Interop.AdoxDataType.VarBinary: goto Label_0087; case Interop.AdoxDataType.LongVarBinary: return AccessDataType.OleObject; case Interop.AdoxDataType.Numeric: return AccessDataType.Decimal; } } else { return AccessDataType.ReplicationID; } Label_0087: throw new ArgumentException(); }
internal void Initialize(Interop.IColumn adoxColumn) { this.Name = adoxColumn.GetName(); Interop.IProperties properties = adoxColumn.GetProperties(); Interop.IProperty item = properties.GetItem("Nullable"); this.AllowNulls = (bool) item.GetValue(); this.DataType = Enum.GetName(typeof(AccessDataType), ConvertAdoxToAccessDataType((Interop.AdoxDataType) adoxColumn.GetType())); item = properties.GetItem("Default"); if (item.GetValue() != null) { this.DefaultValue = item.GetValue().ToString(); } item = properties.GetItem("Description"); this.Description = (string) item.GetValue(); item = properties.GetItem("Increment"); this.IdentityIncrement = (int) item.GetValue(); item = properties.GetItem("Seed"); this.IdentitySeed = (int) item.GetValue(); item = properties.GetItem("Autoincrement"); this.IsIdentity = (bool) item.GetValue(); item = properties.GetItem("Jet OLEDB:AutoGenerate"); this.AutoGenerate = (bool) item.GetValue(); this.NumericPrecision = adoxColumn.GetPrecision(); this.NumericScale = adoxColumn.GetNumericScale(); this.Size = adoxColumn.GetDefinedSize(); foreach (Microsoft.Matrix.Packages.DBAdmin.DBEngine.Key key in base.Table.Keys) { if (key.KeyType == KeyType.Primary) { if (key.ReferencedColumns.Get(this.Name) != null) { this.InPrimaryKey = true; } } else if (((key.KeyType == KeyType.Unique) && (key.ReferencedColumns.Count == 1)) && (key.ReferencedColumns.Get(this.Name) != null)) { this.IsUniqueKey = true; } } }
internal static void CreateTableInternal(Interop.ITable adoxTable, System.Collections.ICollection columns) { Interop.IColumns columns2 = adoxTable.GetColumns(); bool flag = false; foreach (AccessColumn column in columns) { AccessDataType accessDataType = AccessColumn.GetAccessDataType(column.DataType); columns2.Append(column.Name, (int) AccessColumn.ConvertAccessToAdoxDataType(accessDataType), AccessColumn.GetDefaultSize(accessDataType)); if (AccessColumn.SupportsSize(accessDataType)) { columns2.GetItem(column.Name).SetDefinedSize(column.Size); } if (AccessColumn.SupportsNumericPrecision(accessDataType)) { columns2.GetItem(column.Name).SetPrecision(column.NumericPrecision); } if (AccessColumn.SupportsNumericScale(accessDataType)) { columns2.GetItem(column.Name).SetNumericScale((byte) column.NumericScale); } if (AccessColumn.SupportsIdentity(accessDataType) && column.IsIdentity) { columns2.GetItem(column.Name).GetProperties().GetItem("Autoincrement").SetValue(column.IsIdentity); columns2.GetItem(column.Name).GetProperties().GetItem("Increment").SetValue(column.IdentityIncrement); columns2.GetItem(column.Name).GetProperties().GetItem("Seed").SetValue(column.IdentitySeed); } columns2.GetItem(column.Name).GetProperties().GetItem("Default").SetValue(column.DefaultValue); columns2.GetItem(column.Name).GetProperties().GetItem("Nullable").SetValue(column.AllowNulls); if (AccessColumn.SupportsAutoGenerate(accessDataType)) { columns2.GetItem(column.Name).GetProperties().GetItem("Jet OLEDB:AutoGenerate").SetValue(column.AutoGenerate); } columns2.GetItem(column.Name).GetProperties().GetItem("Description").SetValue(column.Description); flag |= column.InPrimaryKey; } Interop.IKeys keys = adoxTable.GetKeys(); if (flag) { Interop.IKey item = (Interop.IKey) new Interop.Key(); item.SetName("PK_" + Guid.NewGuid().ToString()); item.SetType(1); Interop.IColumns columns3 = item.GetColumns(); foreach (Microsoft.Matrix.Packages.DBAdmin.DBEngine.Column column2 in columns) { if (column2.InPrimaryKey) { columns3.Append(column2.Name, 0xca, 0); } } keys.Append(item, 1, Missing.Value, "", ""); } foreach (Microsoft.Matrix.Packages.DBAdmin.DBEngine.Column column3 in columns) { if (column3.IsUniqueKey) { Interop.IKey key2 = (Interop.IKey) new Interop.Key(); key2.SetType(3); key2.SetName("UQ_" + Guid.NewGuid().ToString()); key2.GetColumns().Append(column3.Name, 0xca, 0); keys.Append(key2, 1, Missing.Value, "", ""); } } }
private static Interop.ITable GetAdoxTable(Interop.ITables adoxTables, string name) { Interop.ITable item = null; int count = adoxTables.GetCount(); for (int i = 0; i < count; i++) { item = adoxTables.GetItem(i); if (item.GetName().ToLower() == name.ToLower()) { return item; } } return null; }
private static void DeleteInternal(Interop.ITables adoxTables, string name) { Interop.ITable adoxTable = GetAdoxTable(adoxTables, name); if (adoxTable != null) { Interop.IKeys keys = adoxTable.GetKeys(); keys.Refresh(); int count = keys.GetCount(); ArrayList list = new ArrayList(); for (int i = 0; i < count; i++) { Interop.IKey item = keys.GetItem(i); if (item.GetType() == 2) { list.Add(item.GetName()); } } foreach (string str in list) { keys.Delete(str); } int num3 = adoxTables.GetCount(); for (int j = 0; j < num3; j++) { Interop.IKeys keys2 = adoxTables.GetItem(j).GetKeys(); keys2.Refresh(); int num5 = keys2.GetCount(); ArrayList list2 = new ArrayList(); for (int k = 0; k < num5; k++) { Interop.IKey key2 = keys2.GetItem(k); if ((key2.GetType() == 2) && (key2.GetRelatedTable() == name)) { list2.Add(key2.GetName()); } } foreach (string str2 in list2) { keys2.Delete(str2); } } adoxTables.Delete(name); } }
internal void Initialize(Interop.ITable adoxTable) { base.SetName(adoxTable.GetName()); base.SetCreationDate((DateTime) adoxTable.GetDateCreated()); base.SetLastModifiedDate((DateTime) adoxTable.GetDateModified()); }
internal static void CloseAdoxCatalog(Interop.ICatalog adoxCatalog) { if (adoxCatalog != null) { Interop.IAdoConnection activeConnection = (Interop.IAdoConnection) adoxCatalog.GetActiveConnection(); activeConnection.Close(); adoxCatalog.SetActiveConnection(null); while (Marshal.ReleaseComObject(adoxCatalog) > 0) { } while (Marshal.ReleaseComObject(activeConnection) > 0) { } adoxCatalog = null; activeConnection = null; GC.Collect(); } }