/// <include file='Doc/en_EN/FbDataReader.xml' path='doc/class[@name="FbDataReader"]/method[@name="GetSchemaTable"]/*'/>
		public DataTable GetSchemaTable()
		{
			this.CheckState();

			if (this.schemaTable != null)
			{
				return this.schemaTable;
			}

			DataRow schemaRow;

			this.schemaTable = this.GetSchemaTableStructure();

			/* Prepare statement for schema	fields information	*/
			FbCommand schemaCmd = new FbCommand(
				this.GetSchemaCommandText(),
				this.command.Connection,
				this.command.ActiveTransaction);

			schemaCmd.Parameters.Add("@TABLE_NAME", FbDbType.Char, 31);
			schemaCmd.Parameters.Add("@COLUMN_NAME", FbDbType.Char, 31);
			schemaCmd.Prepare();

			schemaTable.BeginLoadData();
			for (int i = 0; i < this.fields.Count; i++)
			{
				bool isKeyColumn = false;
				bool isUnique	= false;
				bool isReadOnly = false;
				int precision	= 0;

				if (!this.fields[i].IsExpression())
				{
					/* Get Schema data for the field	*/
					schemaCmd.Parameters[0].Value = this.fields[i].Relation;
					schemaCmd.Parameters[1].Value = this.fields[i].Name;

					FbDataReader r = schemaCmd.ExecuteReader();

					if (r.Read())
					{
						isReadOnly = (this.IsReadOnly(r) || this.fields[i].IsExpression()) ? true : false;
						isKeyColumn = (r.GetInt32(2) == 1) ? true : false;
						isUnique = (r.GetInt32(3) == 1) ? true : false;
						precision = r.IsDBNull(4) ? -1 : r.GetInt32(4);
					}

					/* Close the Reader	*/
					r.Close();
				}

				/* Create new row for the Schema Table	*/
				schemaRow = schemaTable.NewRow();

				schemaRow["ColumnName"]		= this.GetName(i);
				schemaRow["ColumnOrdinal"]	= i;
				schemaRow["ColumnSize"]		= this.fields[i].GetSize();
				if (fields[i].IsDecimal())
				{
					schemaRow["NumericPrecision"] = schemaRow["ColumnSize"];
					if (precision > 0)
					{
						schemaRow["NumericPrecision"] = precision;
					}
					schemaRow["NumericScale"] = this.fields[i].NumericScale * (-1);
				}
				schemaRow["DataType"]		= this.GetFieldType(i);
				schemaRow["ProviderType"]	= this.GetProviderType(i);
				schemaRow["IsLong"]			= this.fields[i].IsLong();
				schemaRow["AllowDBNull"]	= this.fields[i].AllowDBNull();
				schemaRow["IsRowVersion"]	= false;
				schemaRow["IsAutoIncrement"] = false;
				schemaRow["IsReadOnly"]		= isReadOnly;
				schemaRow["IsKey"]			= isKeyColumn;
				schemaRow["IsUnique"]		= isUnique;
				schemaRow["IsAliased"]		= this.fields[i].IsAliased();
				schemaRow["IsExpression"]	= this.fields[i].IsExpression();
				schemaRow["BaseSchemaName"] = DBNull.Value;
				schemaRow["BaseCatalogName"] = DBNull.Value;
				schemaRow["BaseTableName"]	= this.fields[i].Relation;
				schemaRow["BaseColumnName"] = this.fields[i].Name;

				schemaTable.Rows.Add(schemaRow);

				/* Close statement	*/
				schemaCmd.Close();
			}
			schemaTable.EndLoadData();

			/* Dispose command	*/
			schemaCmd.Dispose();

			return schemaTable;
		}
Пример #2
0
        /// <include file='Doc/en_EN/FbDataReader.xml' path='doc/class[@name="FbDataReader"]/method[@name="GetSchemaTable"]/*'/>
        public DataTable GetSchemaTable()
        {
            this.CheckState();

            if (this.schemaTable != null)
            {
                return(this.schemaTable);
            }

            DataRow schemaRow;

            this.schemaTable = this.GetSchemaTableStructure();

            /* Prepare statement for schema	fields information	*/
            FbCommand schemaCmd = new FbCommand(
                this.GetSchemaCommandText(),
                this.command.Connection,
                this.command.ActiveTransaction);

            schemaCmd.Parameters.Add("@TABLE_NAME", FbDbType.Char, 31);
            schemaCmd.Parameters.Add("@COLUMN_NAME", FbDbType.Char, 31);
            schemaCmd.Prepare();

            schemaTable.BeginLoadData();
            for (int i = 0; i < this.fields.Count; i++)
            {
                bool isKeyColumn = false;
                bool isUnique    = false;
                bool isReadOnly  = false;
                int  precision   = 0;

                if (!this.fields[i].IsExpression())
                {
                    /* Get Schema data for the field	*/
                    schemaCmd.Parameters[0].Value = this.fields[i].Relation;
                    schemaCmd.Parameters[1].Value = this.fields[i].Name;

                    FbDataReader r = schemaCmd.ExecuteReader();

                    if (r.Read())
                    {
                        isReadOnly  = (this.IsReadOnly(r) || this.fields[i].IsExpression()) ? true : false;
                        isKeyColumn = (r.GetInt32(2) == 1) ? true : false;
                        isUnique    = (r.GetInt32(3) == 1) ? true : false;
                        precision   = r.IsDBNull(4) ? -1 : r.GetInt32(4);
                    }

                    /* Close the Reader	*/
                    r.Close();
                }

                /* Create new row for the Schema Table	*/
                schemaRow = schemaTable.NewRow();

                schemaRow["ColumnName"]    = this.GetName(i);
                schemaRow["ColumnOrdinal"] = i;
                schemaRow["ColumnSize"]    = this.fields[i].GetSize();
                if (fields[i].IsDecimal())
                {
                    schemaRow["NumericPrecision"] = schemaRow["ColumnSize"];
                    if (precision > 0)
                    {
                        schemaRow["NumericPrecision"] = precision;
                    }
                    schemaRow["NumericScale"] = this.fields[i].NumericScale * (-1);
                }
                schemaRow["DataType"]        = this.GetFieldType(i);
                schemaRow["ProviderType"]    = this.GetProviderType(i);
                schemaRow["IsLong"]          = this.fields[i].IsLong();
                schemaRow["AllowDBNull"]     = this.fields[i].AllowDBNull();
                schemaRow["IsRowVersion"]    = false;
                schemaRow["IsAutoIncrement"] = false;
                schemaRow["IsReadOnly"]      = isReadOnly;
                schemaRow["IsKey"]           = isKeyColumn;
                schemaRow["IsUnique"]        = isUnique;
                schemaRow["IsAliased"]       = this.fields[i].IsAliased();
                schemaRow["IsExpression"]    = this.fields[i].IsExpression();
                schemaRow["BaseSchemaName"]  = DBNull.Value;
                schemaRow["BaseCatalogName"] = DBNull.Value;
                schemaRow["BaseTableName"]   = this.fields[i].Relation;
                schemaRow["BaseColumnName"]  = this.fields[i].Name;

                schemaTable.Rows.Add(schemaRow);

                /* Close statement	*/
                schemaCmd.Close();
            }
            schemaTable.EndLoadData();

            /* Dispose command	*/
            schemaCmd.Dispose();

            return(schemaTable);
        }