Exemplo n.º 1
0
        protected FbCommand BuildCommand(FbConnection connection, object[] restrictions)
        {
            DataView collections = FbMetaDataCollections.GetSchema().DefaultView;

            collections.RowFilter = "CollectionName = '" + this.schemaName + "'";

            if (collections.Count == 0)
            {
                throw new NotSupportedException("Unsupported collection name.");
            }

            if (restrictions != null &&
                restrictions.Length > (int)collections[0]["NumberOfRestrictions"])
            {
                throw new InvalidOperationException("The number of specified restrictions is not valid.");
            }

            DataView restriction = FbRestrictions.GetSchema().DefaultView;

            restriction.RowFilter = "CollectionName = '" + this.schemaName + "'";

            if (restriction.Count != (int)collections[0]["NumberOfRestrictions"])
            {
                throw new InvalidOperationException("Incorrect restriction definitions.");
            }

            StringBuilder builder = this.GetCommandText(restrictions);
            FbCommand     schema  = connection.CreateCommand();

            schema.CommandText = builder.ToString();

            if (connection.InnerConnection.HasActiveTransaction)
            {
                schema.Transaction = connection.InnerConnection.ActiveTransaction;
            }

            if (restrictions != null && restrictions.Length > 0)
            {
                // Add parameters
                int index = 0;

                for (int i = 0; i < restrictions.Length; i++)
                {
                    string rname = restriction[i]["RestrictionDefault"].ToString().ToLower(CultureInfo.CurrentCulture);
                    if (restrictions[i] != null &&
                        !rname.EndsWith("_catalog") &&
                        !rname.EndsWith("_schema") &&
                        rname != "table_type")
                    {
                        string pname = String.Format(CultureInfo.CurrentCulture, "@p{0}", index++);

                        FbParameter p = schema.Parameters.Add(pname, restrictions[i].ToString());
                        p.FbDbType = FbDbType.VarChar;
                        p.Size     = 255;
                    }
                }
            }

            return(schema);
        }
Exemplo n.º 2
0
        public static DataTable GetSchema(
            FbConnection connection,
            string collectionName,
            object[] restrictions)
        {
            FbDbSchema returnSchema = null;

            switch (collectionName.ToLower(CultureInfo.CurrentCulture))
            {
            case "charactersets":
                returnSchema = new FbCharacterSets();
                break;

            case "checkconstraints":
                returnSchema = new FbCheckConstraints();
                break;

            case "checkconstraintsbytable":
                returnSchema = new FbChecksByTable();
                break;

            case "collations":
                returnSchema = new FbCollations();
                break;

            case "columns":
                returnSchema = new FbColumns();
                break;

            case "columnprivileges":
                returnSchema = new FbColumnPrivileges();
                break;

            case "datatypes":
                return(FbDataTypes.GetSchema());

            case "domains":
                returnSchema = new FbDomains();
                break;

            case "foreignkeys":
                returnSchema = new FbForeignKeys();
                break;

            case "functions":
                returnSchema = new FbFunctions();
                break;

            case "generators":
                returnSchema = new FbGenerators();
                break;

            case "indexes":
                returnSchema = new FbIndexes();
                break;

            case "metadatacollections":
                return(FbMetaDataCollections.GetSchema());

            case "primarykeys":
                returnSchema = new FbPrimaryKeys();
                break;

            case "procedures":
                returnSchema = new FbProcedures();
                break;

            case "procedureparameters":
                returnSchema = new FbProcedureParameters();
                break;

            case "procedureprivileges":
                returnSchema = new FbProcedurePrivilegesSchema();
                break;

            case "restrictions":
                return(FbRestrictions.GetSchema());

            case "roles":
                returnSchema = new FbRoles();
                break;

            case "tables":
                returnSchema = new FbTables();
                break;

            case "tableconstraints":
                returnSchema = new FbTableConstraints();
                break;

            case "tableprivileges":
                returnSchema = new FbTablePrivileges();
                break;

            case "triggers":
                returnSchema = new FbTriggers();
                break;

            case "uniquekeys":
                returnSchema = new FbUniqueKeys();
                break;

            case "viewcolumnusage":
                returnSchema = new FbViewColumnUsage();
                break;

            case "views":
                returnSchema = new FbViews();
                break;

            case "viewprivileges":
                returnSchema = new FbViewPrivileges();
                break;

            default:
                throw new NotSupportedException("The specified metadata collection is not supported.");
            }

            return(returnSchema.GetSchema(connection, restrictions));
        }