public TableKeySchema[] GetTableKeys(string connectionString, TableSchema table)
        {
            var keys               = new List <TableKeySchema>();
            var foreignColumns     = new List <string>();
            var primaryColumns     = new List <string>();
            var extendedProperties = new List <ExtendedProperty>();

            using (IVistaDBDatabase vistaDb = GetDatabase(connectionString))
            {
                if (vistaDb == null)
                {
                    return(keys.ToArray());
                }

                IVistaDBTableSchema vistaTable = vistaDb.TableSchema(table.Name);
                if (vistaTable == null)
                {
                    return(keys.ToArray());
                }

                foreach (IVistaDBRelationshipInformation vistaKey in vistaTable.ForeignKeys)
                {
                    foreignColumns.Clear();
                    foreignColumns.AddRange(vistaKey.ForeignKey.Split(
                                                new[] { ';' }, StringSplitOptions.RemoveEmptyEntries));

                    IVistaDBTableSchema vistaPrimaryTable = vistaDb.TableSchema(vistaKey.PrimaryTable);
                    if (vistaPrimaryTable == null)
                    {
                        continue;
                    }

                    primaryColumns.Clear();
                    //find primary key index
                    foreach (IVistaDBIndexInformation i in vistaPrimaryTable.Indexes)
                    {
                        if (i.Primary)
                        {
                            primaryColumns.AddRange(i.KeyExpression.Split(
                                                        new[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
                        }
                    }

                    extendedProperties.Clear();
                    extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.Description, vistaKey.Description));

                    var key = new TableKeySchema(
                        table.Database, vistaKey.Name,
                        foreignColumns.ToArray(),
                        string.Empty, vistaKey.ForeignTable,
                        primaryColumns.ToArray(),
                        string.Empty, vistaKey.PrimaryTable,
                        extendedProperties.ToArray());

                    keys.Add(key);
                }
            }

            return(keys.ToArray());
        }
示例#2
0
        DataTable IMyMetaPlugin.GetTables(string database)
        {
            DataTable        metaData = new DataTable();
            IVistaDBDatabase db       = null;

            try
            {
                metaData = context.CreateTablesDataTable();

                db = DDA.OpenDatabase(this.GetFullDatabaseName(),
                                      VistaDBDatabaseOpenMode.NonexclusiveReadOnly, "");

                ArrayList tables = db.EnumTables();

                foreach (string table in tables)
                {
                    IVistaDBTableSchema tblStructure = db.TableSchema(table);

                    DataRow row = metaData.NewRow();
                    metaData.Rows.Add(row);

                    row["TABLE_NAME"]  = tblStructure.Name;
                    row["DESCRIPTION"] = tblStructure.Description;
                }
            }
            finally
            {
                if (db != null)
                {
                    db.Close();
                }
            }

            return(metaData);
        }
        public TableSchema[] GetTables(string connectionString, DatabaseSchema database)
        {
            var tables             = new List <TableSchema>();
            var extendedProperties = new List <ExtendedProperty>();

            using (IVistaDBDatabase vistaDb = GetDatabase(connectionString))
            {
                if (vistaDb == null)
                {
                    return(tables.ToArray());
                }

                foreach (string tableName in vistaDb.GetTableNames())
                {
                    IVistaDBTableSchema table = vistaDb.TableSchema(tableName);
                    if (table == null)
                    {
                        continue;
                    }

                    extendedProperties.Clear();
                    extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.Description, table.Description));

                    var tableSchema = new TableSchema(database, table.Name, String.Empty, DateTime.MinValue, extendedProperties.ToArray());

                    tables.Add(tableSchema);
                }
            }

            return(tables.ToArray());
        }
        public PrimaryKeySchema GetTablePrimaryKey(string connectionString, TableSchema table)
        {
            using (IVistaDBDatabase vistaDb = GetDatabase(connectionString))
            {
                if (vistaDb == null)
                {
                    return(null);
                }

                IVistaDBTableSchema vistaTable = vistaDb.TableSchema(table.Name);
                if (vistaTable == null)
                {
                    return(null);
                }

                foreach (IVistaDBIndexInformation vistaIndex in vistaTable.Indexes)
                {
                    if (!vistaIndex.Primary)
                    {
                        continue;
                    }

                    var key = new PrimaryKeySchema(
                        table, vistaIndex.Name,
                        vistaIndex.KeyExpression.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries));

                    return(key);
                }
            }

            return(null);
        }
        public ColumnSchema[] GetTableColumns(string connectionString, TableSchema table)
        {
            var columns            = new List <ColumnSchema>();
            var extendedProperties = new List <ExtendedProperty>();

            using (IVistaDBDatabase vistaDb = GetDatabase(connectionString))
            {
                if (vistaDb == null)
                {
                    return(columns.ToArray());
                }

                IVistaDBTableSchema vistaTable = vistaDb.TableSchema(table.Name);
                if (vistaTable == null)
                {
                    return(columns.ToArray());
                }

                foreach (IVistaDBColumnAttributes vistaColumn in vistaTable)
                {
                    string nativeType = vistaColumn.Type.ToString();

                    extendedProperties.Clear();
                    extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.Description, vistaColumn.Description));
                    extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.ObjectID, vistaColumn.UniqueId));
                    extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.DefaultValue, ""));
                    extendedProperties.Add(ExtendedProperty.Readonly("CS_CodePage", vistaColumn.CodePage));
                    extendedProperties.Add(ExtendedProperty.Readonly("CS_Encrypted", vistaColumn.Encrypted));
                    extendedProperties.Add(ExtendedProperty.Readonly("CS_Packed", vistaColumn.Packed));
                    extendedProperties.Add(ExtendedProperty.Readonly("CS_ReadOnly", vistaColumn.ReadOnly));

                    bool isIdentity = false;
                    foreach (IVistaDBIdentityInformation identity in vistaTable.Identities)
                    {
                        isIdentity = (identity.ColumnName == vistaColumn.Name);
                        if (isIdentity)
                        {
                            break;
                        }
                    }

                    extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.IsIdentity, isIdentity));

                    var column = new ColumnSchema(table, vistaColumn.Name, GetDbType(nativeType),
                                                  nativeType, vistaColumn.MaxLength, 0, 0, vistaColumn.AllowNull,
                                                  extendedProperties.ToArray());

                    columns.Add(column);
                }
            }


            return(columns.ToArray());
        }
示例#6
0
        List <string> IPlugin.GetPrimaryKeyColumns(string database, string table)
        {
            List <string>    primaryKeys = new List <string>();
            IVistaDBDatabase db          = null;

            try
            {
                using (VistaDBConnection cn = new VistaDBConnection(context.ConnectionString))
                {
                    db = DDA.OpenDatabase(this.GetFullDatabaseName(), VistaDBDatabaseOpenMode.NonexclusiveReadOnly, GetPassword(cn));
                }

                IVistaDBTableSchema tblStructure = db.TableSchema(table);

                string[] pks = null;
                if (tblStructure.Indexes.Contains("PrimaryKey"))
                {
                    pks = tblStructure.Indexes["PrimaryKey"].KeyExpression.Split(';');
                }
                else
                {
                    foreach (IVistaDBIndexInformation pk in tblStructure.Indexes)
                    {
                        if (pk.Primary)
                        {
                            pks = pk.KeyExpression.Split(';');
                            break;
                        }
                    }
                }

                if (pks != null)
                {
                    foreach (string pkColName in pks)
                    {
                        primaryKeys.Add(pkColName);
                    }
                }
            }
            finally
            {
                if (db != null)
                {
                    db.Close();
                }
            }

            return(primaryKeys);
        }
示例#7
0
        DataTable IPlugin.GetTableIndexes(string database, string table)
        {
            DataTable        metaData = new DataTable();
            IVistaDBDatabase db       = null;

            try
            {
                metaData = context.CreateIndexesDataTable();

                using (VistaDBConnection cn = new VistaDBConnection(context.ConnectionString))
                {
                    db = DDA.OpenDatabase(this.GetFullDatabaseName(), VistaDBDatabaseOpenMode.NonexclusiveReadOnly, GetPassword(cn));
                }

                ArrayList tables = db.EnumTables();

                IVistaDBTableSchema tblStructure = db.TableSchema(table);

                foreach (IVistaDBIndexInformation indexInfo in tblStructure.Indexes)
                {
                    string[] pks = indexInfo.KeyExpression.Split(';');

                    int index = 0;
                    foreach (string colName in pks)
                    {
                        DataRow row = metaData.NewRow();
                        metaData.Rows.Add(row);

                        row["TABLE_CATALOG"] = GetDatabaseName();
                        row["TABLE_NAME"]    = tblStructure.Name;
                        row["INDEX_CATALOG"] = GetDatabaseName();
                        row["INDEX_NAME"]    = indexInfo.Name;
                        row["UNIQUE"]        = indexInfo.Unique;
                        row["COLLATION"]     = indexInfo.KeyStructure[index++].Descending ? 2 : 1;
                        row["COLUMN_NAME"]   = colName;
                    }
                }
            }
            finally
            {
                if (db != null)
                {
                    db.Close();
                }
            }

            return(metaData);
        }
        public IndexSchema[] GetTableIndexes(string connectionString, TableSchema table)
        {
            var indexes            = new List <IndexSchema>();
            var memberColumns      = new List <string>();
            var extendedProperties = new List <ExtendedProperty>();

            using (IVistaDBDatabase vistaDb = GetDatabase(connectionString))
            {
                if (vistaDb == null)
                {
                    return(indexes.ToArray());
                }

                IVistaDBTableSchema vistaTable = vistaDb.TableSchema(table.Name);
                if (vistaTable == null)
                {
                    return(indexes.ToArray());
                }

                foreach (IVistaDBIndexInformation vistaIndex in vistaTable.Indexes)
                {
                    memberColumns.Clear();
                    foreach (IVistaDBKeyColumn keyColumn in vistaIndex.KeyStructure)
                    {
                        memberColumns.Add(vistaTable[keyColumn.RowIndex].Name);
                    }

                    extendedProperties.Clear();
                    extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.Description, vistaIndex.Description));
                    extendedProperties.Add(ExtendedProperty.Readonly("CS_FastTextSearch", vistaIndex.FullTextSearch));

                    var index = new IndexSchema(table, vistaIndex.Name, vistaIndex.Primary,
                                                vistaIndex.Unique, false,
                                                memberColumns.ToArray(),
                                                extendedProperties.ToArray());

                    indexes.Add(index);
                }
            }

            return(indexes.ToArray());
        }
示例#9
0
        DataTable IPlugin.GetTables(string database)
        {
            DataTable        metaData = new DataTable();
            IVistaDBDatabase db       = null;

            try
            {
                metaData = context.CreateTablesDataTable();

                using (VistaDBConnection cn = new VistaDBConnection(context.ConnectionString))
                {
                    db = DDA.OpenDatabase(this.GetFullDatabaseName(), VistaDBDatabaseOpenMode.NonexclusiveReadOnly, GetPassword(cn));
                }

                IVistaDBTableNameCollection tables = db.GetTableNames();

                foreach (string table in tables)
                {
                    IVistaDBTableSchema tblStructure = db.TableSchema(table);

                    DataRow row = metaData.NewRow();
                    metaData.Rows.Add(row);

                    row["TABLE_NAME"]  = tblStructure.Name;
                    row["DESCRIPTION"] = tblStructure.Description;
                }
            }
            finally
            {
                if (db != null)
                {
                    db.Close();
                }
            }

            return(metaData);
        }
示例#10
0
        DataTable IPlugin.GetForeignKeys(string database, string tableName)
        {
            DataTable        metaData = new DataTable();
            IVistaDBDatabase db       = null;

            try
            {
                metaData = context.CreateForeignKeysDataTable();

                using (VistaDBConnection cn = new VistaDBConnection(context.ConnectionString))
                {
                    db = DDA.OpenDatabase(this.GetFullDatabaseName(), VistaDBDatabaseOpenMode.NonexclusiveReadOnly, GetPassword(cn));
                }

                ArrayList tables = db.EnumTables();

                foreach (string table in tables)
                {
                    IVistaDBTableSchema tblStructure = db.TableSchema(table);

                    //==================================================================
                    // This works around a change that was made to the VistaDB provider
                    // It's ugly, we know
                    //==================================================================
                    IEnumerator enumerator = null;

                    if (useOldForeignKeyWay)
                    {
                        enumerator = tblStructure.ForeignKeys.GetEnumerator();
                    }
                    else
                    {
                        try
                        {
                            enumerator = tblStructure.ForeignKeys.Values.GetEnumerator();
                        }
                        catch
                        {
                            enumerator          = tblStructure.ForeignKeys.GetEnumerator();
                            useOldForeignKeyWay = true;
                        }
                    }

                    // Okay, now that the version issues are over we just use the 'enumerator'
                    while (enumerator.MoveNext())
                    {
                        IVistaDBRelationshipInformation relInfo = enumerator.Current as IVistaDBRelationshipInformation;

                        if (relInfo.ForeignTable != tableName && relInfo.PrimaryTable != tableName)
                        {
                            continue;
                        }

                        string fCols = relInfo.ForeignKey;
                        string pCols = String.Empty;

                        string primaryTbl = relInfo.PrimaryTable;
                        string pkName     = "";

                        using (IVistaDBTableSchema pkTableStruct = db.TableSchema(primaryTbl))
                        {
                            foreach (IVistaDBIndexInformation idxInfo in pkTableStruct.Indexes)
                            {
                                if (!idxInfo.Primary)
                                {
                                    continue;
                                }

                                pkName = idxInfo.Name;
                                pCols  = idxInfo.KeyExpression;
                                break;
                            }
                        }

                        string [] fColumns = fCols.Split(';');
                        string [] pColumns = pCols.Split(';');

                        for (int i = 0; i < fColumns.GetLength(0); i++)
                        {
                            DataRow row = metaData.NewRow();
                            metaData.Rows.Add(row);

                            row["PK_TABLE_CATALOG"] = GetDatabaseName();
                            row["PK_TABLE_SCHEMA"]  = DBNull.Value;
                            row["FK_TABLE_CATALOG"] = DBNull.Value;
                            row["FK_TABLE_SCHEMA"]  = DBNull.Value;
                            row["FK_TABLE_NAME"]    = tblStructure.Name;
                            row["PK_TABLE_NAME"]    = relInfo.PrimaryTable;
                            row["ORDINAL"]          = 0;
                            row["FK_NAME"]          = relInfo.Name;
                            row["PK_NAME"]          = pkName;
                            row["PK_COLUMN_NAME"]   = pColumns[i];
                            row["FK_COLUMN_NAME"]   = fColumns[i];

                            row["UPDATE_RULE"] = relInfo.UpdateIntegrity;
                            row["DELETE_RULE"] = relInfo.DeleteIntegrity;
                        }
                    }
                }
            }
            finally
            {
                if (db != null)
                {
                    db.Close();
                }
            }

            return(metaData);
        }
示例#11
0
        DataTable IPlugin.GetTableColumns(string database, string table)
        {
            DataTable        metaData = new DataTable();
            IVistaDBDatabase db       = null;

            try
            {
                metaData = context.CreateColumnsDataTable();

                using (VistaDBConnection cn = new VistaDBConnection(context.ConnectionString))
                {
                    db = DDA.OpenDatabase(this.GetFullDatabaseName(), VistaDBDatabaseOpenMode.NonexclusiveReadOnly, GetPassword(cn));
                }

                ArrayList tables = db.EnumTables();

                IVistaDBTableSchema tblStructure = db.TableSchema(table);

                foreach (IVistaDBColumnAttributes c in tblStructure)
                {
                    string colName = c.Name;

                    string def = "";
                    if (tblStructure.Defaults.Contains(colName))
                    {
                        def = tblStructure.Defaults[colName].Expression;
                    }
                    int width     = c.MaxLength;                     //c.ColumnWidth;
                    int dec       = 0;                               //c.ColumnDecimals;
                    int length    = 0;
                    int octLength = width;

                    IVistaDBIdentityInformation identity = null;
                    if (tblStructure.Identities.Contains(colName))
                    {
                        identity = tblStructure.Identities[colName];
                    }

                    string[] pks = null;
                    if (tblStructure.Indexes.Contains("PrimaryKey"))
                    {
                        pks = tblStructure.Indexes["PrimaryKey"].KeyExpression.Split(';');
                    }
                    else
                    {
                        foreach (IVistaDBIndexInformation pk in tblStructure.Indexes)
                        {
                            if (pk.Primary)
                            {
                                pks = pk.KeyExpression.Split(';');
                                break;
                            }
                        }
                    }

                    System.Collections.Hashtable pkCols = null;
                    if (pks != null)
                    {
                        pkCols = new Hashtable();
                        foreach (string pkColName in pks)
                        {
                            pkCols[pkColName] = true;
                        }
                    }

                    switch (c.Type)
                    {
                    case VistaDBType.Char:
                    case VistaDBType.NChar:
                    case VistaDBType.NText:
                    case VistaDBType.NVarChar:
                    case VistaDBType.Text:
                    case VistaDBType.VarChar:
                        length = width;
                        width  = 0;
                        dec    = 0;
                        break;

                    case VistaDBType.Money:
                    case VistaDBType.Float:
                    case VistaDBType.Decimal:
                    case VistaDBType.Real:
                        break;

                    default:
                        width = 0;
                        dec   = 0;
                        break;
                    }

                    DataRow row = metaData.NewRow();
                    metaData.Rows.Add(row);

                    row["TABLE_NAME"]               = tblStructure.Name;
                    row["COLUMN_NAME"]              = c.Name;
                    row["ORDINAL_POSITION"]         = c.RowIndex;
                    row["IS_NULLABLE"]              = c.AllowNull;
                    row["COLUMN_HASDEFAULT"]        = def == string.Empty ? false : true;
                    row["COLUMN_DEFAULT"]           = def;
                    row["IS_AUTO_KEY"]              = identity == null ? false : true;
                    row["AUTO_KEY_SEED"]            = 1;
                    row["AUTO_KEY_INCREMENT"]       = identity == null ? 0 : Convert.ToInt32(identity.StepExpression);
                    row["TYPE_NAME"]                = c.Type.ToString();
                    row["NUMERIC_PRECISION"]        = width;
                    row["NUMERIC_SCALE"]            = dec;
                    row["CHARACTER_MAXIMUM_LENGTH"] = length;
                    row["CHARACTER_OCTET_LENGTH"]   = octLength;
                    row["DESCRIPTION"]              = c.Description;

                    string type = (string)row["TYPE_NAME"];
                    row["TYPE_NAME_COMPLETE"] = this.GetDataTypeNameComplete(type, length, (short)width, (short)dec);

                    if (c.Type == VistaDBType.Timestamp)
                    {
                        row["IS_COMPUTED"] = true;
                    }

                    row["IS_CONCURRENCY"] = type == "Timestamp" ? true : false;
                }
            }
            finally
            {
                if (db != null)
                {
                    db.Close();
                }
            }

            return(metaData);
        }
示例#12
0
        DataTable IMyMetaPlugin.GetForeignKeys(string database, string tableName)
        {
            DataTable        metaData = new DataTable();
            IVistaDBDatabase db       = null;

            try
            {
                metaData = context.CreateForeignKeysDataTable();

                db = DDA.OpenDatabase(this.GetFullDatabaseName(),
                                      VistaDBDatabaseOpenMode.NonexclusiveReadOnly, "");

                ArrayList tables = db.EnumTables();

                foreach (string table in tables)
                {
                    IVistaDBTableSchema tblStructure = db.TableSchema(table);

                    foreach (IVistaDBRelationshipInformation relInfo in tblStructure.ForeignKeys)
                    {
                        if (relInfo.ForeignTable != tableName && relInfo.PrimaryTable != tableName)
                        {
                            continue;
                        }

                        string fCols = relInfo.ForeignKey;
                        string pCols = String.Empty;

                        string primaryTbl = relInfo.PrimaryTable;
                        string pkName     = "";

                        using (IVistaDBTableSchema pkTableStruct = db.TableSchema(primaryTbl))
                        {
                            foreach (IVistaDBIndexInformation idxInfo in pkTableStruct.Indexes)
                            {
                                if (!idxInfo.Primary)
                                {
                                    continue;
                                }

                                pkName = idxInfo.Name;
                                pCols  = idxInfo.KeyExpression;
                                break;
                            }
                        }

                        string [] fColumns = fCols.Split(';');
                        string [] pColumns = pCols.Split(';');

                        for (int i = 0; i < fColumns.GetLength(0); i++)
                        {
                            DataRow row = metaData.NewRow();
                            metaData.Rows.Add(row);

                            row["PK_TABLE_CATALOG"] = GetDatabaseName();
                            row["PK_TABLE_SCHEMA"]  = DBNull.Value;
                            row["FK_TABLE_CATALOG"] = DBNull.Value;
                            row["FK_TABLE_SCHEMA"]  = DBNull.Value;
                            row["FK_TABLE_NAME"]    = tblStructure.Name;
                            row["PK_TABLE_NAME"]    = relInfo.PrimaryTable;
                            row["ORDINAL"]          = 0;
                            row["FK_NAME"]          = relInfo.Name;
                            row["PK_NAME"]          = pkName;
                            row["PK_COLUMN_NAME"]   = pColumns[i];
                            row["FK_COLUMN_NAME"]   = fColumns[i];

                            row["UPDATE_RULE"] = relInfo.UpdateIntegrity;
                            row["DELETE_RULE"] = relInfo.DeleteIntegrity;
                        }
                    }
                }
            }
            finally
            {
                if (db != null)
                {
                    db.Close();
                }
            }

            return(metaData);
        }