public string GetViewText(string connectionString, ViewSchema view)
        {
            ADOX.Catalog  catalog = GetCatalog(connectionString);
            ADOX.View     v       = catalog.Views[view.Name];
            ADODB.Command cmd     = v.Command as ADODB.Command;

            return(cmd != null ? cmd.CommandText : String.Empty);
        }
Esempio n. 2
0
 public ViewColumnSchema(ViewSchema view, string name, DbType dataType, string nativeType, int size, byte precision, int scale)
 {
     base._database   = view.Database;
     this._view       = view;
     base._name       = name;
     base._dataType   = dataType;
     base._nativeType = nativeType;
     base._size       = size;
     base._precision  = precision;
     base._scale      = scale;
 }
        public DataTable GetViewData(string connectionString, ViewSchema view)
        {
            string sql = string.Format("select * from '{0}'", view.Name);

            using (VistaDBConnection connection = GetConnection(connectionString))
                using (var adapter = new VistaDBDataAdapter(sql, connection))
                    using (var dataTable = new DataTable())
                    {
                        adapter.Fill(dataTable);
                        return(dataTable);
                    }
        }
Esempio n. 4
0
        public ViewColumnSchema[] GetViewColumns(string connectionString, ViewSchema view)
        {
            DataTable dt = GetSchemaData(connectionString,
                                         Columns,
                                         null /*restrictions[0] - catalog*/,
                                         null /*restrictions[1] - unused*/,
                                         view.Name /*restrictions[2] - table*/,
                                         null /*restrictions[3] - column*/);

            var extendedProperties = new List <ExtendedProperty>();
            var columns            = new ViewColumnSchema[dt.Rows.Count];
            int columnIndex        = 0;

            foreach (DataRow dr in dt.Rows)
            {
                string name        = (string)dr[ColumnsNameColumn];
                string nativeType  = dr.IsNull(ColumnsTypeColumn) ? "text" : (string)dr[ColumnsTypeColumn];
                DbType dbType      = DbTypeFromType(connectionString, nativeType);
                bool   allowDBNull = dr.IsNull(ColumnsNullableColumn) || (bool)dr[ColumnsNullableColumn];
                int    size        = dr.IsNull(ColumnsSize) ? 0 : (int)dr[ColumnsSize];
                int    precision   = dr.IsNull(ColumnsPrecision) ? 0 : (int)dr[ColumnsPrecision];
                int    scale       = dr.IsNull(ColumnsScale) ? 0 : (int)dr[ColumnsScale];

                int    ordinalPosition = dr.IsNull("ORDINAL_POSITION") ? 0 : (int)dr["ORDINAL_POSITION"];
                string edmType         = dr.IsNull("EDM_TYPE") ? "String" : (string)dr["EDM_TYPE"];
                bool   isAutoIncrement = !dr.IsNull("AUTOINCREMENT") && (bool)dr["AUTOINCREMENT"];
                bool   isUnique        = !dr.IsNull("UNIQUE") && (bool)dr["UNIQUE"];
                bool   hasDefault      = !dr.IsNull("COLUMN_HASDEFAULT") && (bool)dr["COLUMN_HASDEFAULT"];
                string columnDefault   = dr.IsNull("COLUMN_DEFAULT") ? string.Empty : (string)dr["COLUMN_DEFAULT"];
                string collation       = dr.IsNull("COLLATION_NAME") ? string.Empty : (string)dr["COLLATION_NAME"];

                extendedProperties.Clear();
                extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.Description, ""));
                extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.ObjectID, ordinalPosition));
                extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.IsIdentity, isAutoIncrement));
                extendedProperties.Add(ExtendedProperty.Readonly("CS_IsUnique", isUnique));     // Added for backwards compatibility.
                extendedProperties.Add(ExtendedProperty.Readonly("CS_HasDefault", hasDefault)); // Added for backwards compatibility.
                extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.DefaultValue, columnDefault));
                extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.Collation, collation));
                extendedProperties.Add(ExtendedProperty.Readonly(ExtendedPropertyNames.SystemType, edmType));
                extendedProperties.Add(ExtendedProperty.Readonly("CS_SQLiteType", edmType));  // Added for backwards compatibility.


                var col = new ViewColumnSchema(view, name, dbType, nativeType, size,
                                               Convert.ToByte(precision), scale, allowDBNull,
                                               extendedProperties.ToArray());

                columns[columnIndex++] = col;
            }

            return(columns);
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the columns for a given view.
        /// </summary>
        /// <param name="connectionString">The connection string used to connect to the target database.</param>
        /// <param name="view"></param>
        /// <returns></returns>
        public ViewColumnSchema[] GetViewColumns(string connectionString, ViewSchema view)
        {
            string commandText = string.Format("SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_OCTET_LENGTH, NUMERIC_PRECISION,"
                                               + " NUMERIC_SCALE, CASE IS_NULLABLE WHEN 'NO' THEN 0 ELSE 1 END IS_NULLABLE, COLUMN_TYPE"
                                               + " FROM INFORMATION_SCHEMA.COLUMNS "
                                               + "WHERE TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}'"
                                               + "ORDER BY ORDINAL_POSITION", view.Database.Name, view.Name);

            List <ViewColumnSchema> viewColumnSchema = new List <ViewColumnSchema>();

            using (DbConnection connection = CreateConnection(connectionString))
            {
                connection.Open();

                DbCommand command = connection.CreateCommand();
                command.CommandText = commandText;
                command.Connection  = connection;

                using (IDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    while (reader.Read())
                    {
                        string name       = reader.GetString(0);
                        string nativeType = reader.GetString(1);
                        long   longSize   = (reader.IsDBNull(2) == false) ? reader.GetInt64(2) : 0;
                        byte   precision  = ( byte )((reader.IsDBNull(3) == false) ? reader.GetInt32(3) : 0);
                        int    scale      = (reader.IsDBNull(4) == false) ? reader.GetInt32(4) : 0;
                        bool   isNullable = (reader.IsDBNull(5) == false) && reader.GetBoolean(5);
                        string columnType = reader.GetString(6);

                        int    size       = (longSize < int.MaxValue) ? (int)longSize : int.MaxValue;
                        bool   isUnsigned = (columnType.IndexOf("unsigned") > -1);
                        DbType type       = GetDbType(nativeType, isUnsigned);

                        viewColumnSchema.Add(new ViewColumnSchema(view, name, type, nativeType, size, precision, scale, isNullable));
                    }

                    if (!reader.IsClosed)
                    {
                        reader.Close();
                    }
                }

                if (connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                }
            }

            return(viewColumnSchema.ToArray());
        }
Esempio n. 6
0
        public override bool Equals(object obj)
        {
            // This item is obfuscated and can not be translated.
            ViewSchema schema = obj as ViewSchema;

            if (schema == null || !schema.Database.Equals(this.Database) || !(schema.Owner == this.Owner) || !(schema.Name == this.Name))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Esempio n. 7
0
        public string GetViewText(string connectionString, ViewSchema view)
        {
            DataTable dataTable = GetSchemaData(connectionString,
                                                Views,
                                                null /*restrictions[0] - catalog*/,
                                                null /*restrictions[1] - unused*/,
                                                view.Name /*restrictions[2] - view*/);

            if (dataTable.Rows.Count != 1)
            {
                throw new ArgumentException(string.Format("Unexpected number of rows in Views collection for view {0}", view.Name));
            }

            return((string)dataTable.Rows[0][ViewsTextColumn]);
        }
        public DataTable GetViewData(string connectionString, ViewSchema view)
        {
            DataTable dataTable;

            using (NpgsqlConnection npgsqlConnection = new NpgsqlConnection(connectionString))
            {
                dataTable = new DataTable(view.Name);
                string text = string.Format("SELECT * FROM {0}", view.Name);
                using (NpgsqlDataAdapter npgsqlDataAdapter = new NpgsqlDataAdapter(text, npgsqlConnection))
                {
                    npgsqlDataAdapter.Fill(dataTable);
                }
                if (npgsqlConnection.State != ConnectionState.Closed)
                {
                    npgsqlConnection.Close();
                }
            }
            return(dataTable);
        }
        public string GetViewText(string connectionString, ViewSchema view)
        {
            string sql = string.Format("select VIEW_DEFINITION from GetViews() where VIEW_NAME = '{0}'", view.Name);

            using (VistaDBConnection connection = GetConnection(connectionString))
                using (var adapter = new VistaDBDataAdapter(sql, connection))
                    using (var table = new DataTable())
                    {
                        adapter.Fill(table);

                        foreach (DataRow row in table.Rows)
                        {
                            string definition = row[0].ToString();
                            return(definition);
                        }
                    }

            return(string.Empty);
        }
        public string GetViewText(string connectionString, ViewSchema view)
        {
            string result;

            using (NpgsqlConnection npgsqlConnection = new NpgsqlConnection(connectionString))
            {
                npgsqlConnection.Open();
                string text = string.Format("select view_definition from information_schema.views where table_schema='public' and table_name = '{0}'", view.Name);
                using (NpgsqlCommand npgsqlCommand = new NpgsqlCommand(text, npgsqlConnection))
                {
                    result = (string)npgsqlCommand.ExecuteScalar();
                }
                if (npgsqlConnection.State != ConnectionState.Closed)
                {
                    npgsqlConnection.Close();
                }
            }
            return(result);
        }
Esempio n. 11
0
        public ViewColumnSchema[] GetViewColumns(string connectionString, ViewSchema view)
        {
            string str = string.Format("SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_OCTET_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE, CASE IS_NULLABLE WHEN 'NO' THEN 0 ELSE 1 END IS_NULLABLE, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}'ORDER BY ORDINAL_POSITION", view.Database.Name, view.Name);
            List <ViewColumnSchema> list = new List <ViewColumnSchema>();

            using (DbConnection connection = CreateConnection(connectionString))
            {
                connection.Open();
                DbCommand command = connection.CreateCommand();
                command.CommandText = str;
                command.Connection  = connection;
                using (IDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    while (reader.Read())
                    {
                        string name        = reader.GetString(0);
                        string str3        = reader.GetString(1);
                        long   num         = !reader.IsDBNull(2) ? reader.GetInt64(2) : 0L;
                        byte   precision   = !reader.IsDBNull(3) ? ((byte)reader.GetInt32(3)) : ((byte)0);
                        int    scale       = !reader.IsDBNull(4) ? reader.GetInt32(4) : 0;
                        bool   allowDBNull = !reader.IsDBNull(5) && reader.GetBoolean(5);
                        string str4        = reader.GetString(6);
                        int    size        = (num < 0x7fffffffL) ? ((int)num) : 0x7fffffff;
                        bool   isUnsigned  = str4.IndexOf("unsigned") > -1;
                        DbType dbType      = GetDbType(str3, isUnsigned);
                        list.Add(new ViewColumnSchema(view, name, dbType, str3, size, precision, scale, allowDBNull));
                    }
                    if (!reader.IsClosed)
                    {
                        reader.Close();
                    }
                }
                if (connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                }
            }
            return(list.ToArray());
        }
Esempio n. 12
0
        public ViewColumnSchema[] GetViewColumns(string connectionString, ViewSchema view)
        {
            string commandText           = string.Format("SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_OCTET_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE, CASE IS_NULLABLE WHEN 'NO' THEN 0 ELSE 1 END IS_NULLABLE, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}'ORDER BY ORDINAL_POSITION", view.Database.Name, view.Name);
            List <ViewColumnSchema> list = new List <ViewColumnSchema>();

            using (DbConnection dbConnection = CreateConnection(connectionString))
            {
                dbConnection.Open();
                DbCommand dbCommand = dbConnection.CreateCommand();
                dbCommand.CommandText = commandText;
                dbCommand.Connection  = dbConnection;
                using (IDataReader dataReader = dbCommand.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    while (dataReader.Read())
                    {
                        string @string     = dataReader.GetString(0);
                        string string2     = dataReader.GetString(1);
                        long   num         = (!dataReader.IsDBNull(2)) ? dataReader.GetInt64(2) : 0L;
                        byte   precision   = (byte)((!dataReader.IsDBNull(3)) ? dataReader.GetInt32(3) : 0);
                        int    scale       = (!dataReader.IsDBNull(4)) ? dataReader.GetInt32(4) : 0;
                        bool   allowDBNull = !dataReader.IsDBNull(5) && dataReader.GetBoolean(5);
                        string string3     = dataReader.GetString(6);
                        int    size        = (num < 2147483647L) ? ((int)num) : int.MaxValue;
                        bool   isUnsigned  = string3.IndexOf("unsigned") > -1;
                        DbType dbType      = string2.ToDbType(isUnsigned);
                        list.Add(new ViewColumnSchema(view, @string, dbType, string2, size, precision, scale, allowDBNull));
                    }
                    if (!dataReader.IsClosed)
                    {
                        dataReader.Close();
                    }
                }
                if (dbConnection.State != ConnectionState.Closed)
                {
                    dbConnection.Close();
                }
            }
            return(list.ToArray());
        }
        public ViewColumnSchema[] GetViewColumns(string connectionString, ViewSchema view)
        {
            List <ViewColumnSchema> list = new List <ViewColumnSchema>();

            using (NpgsqlConnection npgsqlConnection = new NpgsqlConnection(connectionString))
            {
                npgsqlConnection.Open();
                string text = string.Format("SELECT column_name, is_nullable, character_maximum_length, numeric_precision, numeric_scale, data_type, udt_name FROM information_schema.columns WHERE table_schema='public' AND table_name='{0}' ORDER BY ordinal_position", view.Name);
                using (NpgsqlCommand npgsqlCommand = new NpgsqlCommand(text, npgsqlConnection))
                {
                    using (NpgsqlDataReader npgsqlDataReader = npgsqlCommand.ExecuteReader(CommandBehavior.CloseConnection))
                    {
                        while (npgsqlDataReader.Read())
                        {
                            bool   allowDBNull = npgsqlDataReader.IsDBNull(1) || npgsqlDataReader.GetString(1) == "YES";
                            int    size        = npgsqlDataReader.IsDBNull(2) ? 0 : npgsqlDataReader.GetInt32(2);
                            byte   precision   = (byte)(npgsqlDataReader.IsDBNull(3) ? 0 : npgsqlDataReader.GetInt32(3));
                            int    scale       = npgsqlDataReader.IsDBNull(4) ? 0 : npgsqlDataReader.GetInt32(4);
                            string text2       = npgsqlDataReader.IsDBNull(5) ? string.Empty : npgsqlDataReader.GetString(5);
                            string type        = npgsqlDataReader.IsDBNull(6) ? string.Empty : npgsqlDataReader.GetString(6);
                            list.Add(new ViewColumnSchema(view, npgsqlDataReader.GetString(0), PostgreSQLSchemaProvider.GetDbType(type), text2, size, precision, scale, allowDBNull, new ExtendedProperty[]
                            {
                                new ExtendedProperty("NpgsqlDbType", PostgreSQLSchemaProvider.GetNativeDbType(text2), DbType.String)
                            }));
                        }
                        if (!npgsqlDataReader.IsClosed)
                        {
                            npgsqlDataReader.Close();
                        }
                    }
                }
                if (npgsqlConnection.State != ConnectionState.Closed)
                {
                    npgsqlConnection.Close();
                }
            }
            return(list.ToArray());
        }
Esempio n. 14
0
        public DataTable GetViewData(string connectionString, ViewSchema view)
        {
            DbProviderFactory factory = CreateDbProviderFactory();

            using (DbConnection connection = factory.CreateConnection())
            {
                connection.ConnectionString = connectionString;
                connection.Open();

                using (DbCommand command = connection.CreateCommand())
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText = string.Format("SELECT * FROM {0};", view.Name);

                    var dataAdapter = factory.CreateDataAdapter();
                    dataAdapter.SelectCommand = command;

                    var dataSet = new DataSet();
                    dataAdapter.Fill(dataSet);

                    return(dataSet.Tables[0]);
                }
            }
        }
Esempio n. 15
0
        public DataTable GetViewData(string connectionString, ViewSchema view)
        {
            string  commandText = string.Format("SELECT * FROM {0}", view.Name);
            DataSet dataSet;

            using (DbConnection dbConnection = CreateConnection(connectionString))
            {
                dbConnection.ConnectionString = connectionString;
                dbConnection.Open();
                DbCommand dbCommand = dbConnection.CreateCommand();
                dbCommand.CommandText = commandText;
                dbCommand.Connection  = dbConnection;
                dataSet = this.ConvertDataReaderToDataSet(dbCommand.ExecuteReader());
                if (dbConnection.State != ConnectionState.Closed)
                {
                    dbConnection.Close();
                }
            }
            if (dataSet.Tables.Count > 0)
            {
                return(dataSet.Tables[0]);
            }
            return(new DataTable(view.Name));
        }
        public DataTable GetViewData(string connectionString, ViewSchema view)
        {
            string sqlstring = @"
                SELECT
                    *
                FROM
                    " + view.Name;

            ADODB.Connection cn = new ADODB.ConnectionClass();
            cn.Open(connectionString, null, null, 0);

            ADODB.Recordset rs = new ADODB.RecordsetClass();
            rs.Open(sqlstring, cn, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 0);

            OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
            DataTable        viewData    = new DataTable();

            dataAdapter.Fill(viewData, rs);

            rs.Close();
            cn.Close();

            return(viewData);
        }
Esempio n. 17
0
        public DataTable GetViewData(string connectionString, ViewSchema view)
        {
            DataSet set;
            string  str = string.Format("SELECT * FROM {0}", view.Name);

            using (DbConnection connection = CreateDbProviderFactory().CreateConnection())
            {
                connection.ConnectionString = connectionString;
                connection.Open();
                DbCommand command = connection.CreateCommand();
                command.CommandText = str;
                command.Connection  = connection;
                set = this.ConvertDataReaderToDataSet(command.ExecuteReader());
                if (connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                }
            }
            if (set.Tables.Count > 0)
            {
                return(set.Tables[0]);
            }
            return(new DataTable(view.Name));
        }
 public ViewColumnSchema[] GetViewColumns(string connectionString, ViewSchema view)
 {
     throw new NotSupportedException("GetViewColumns() is not supported with this provider.");
 }
Esempio n. 19
0
 public ViewColumnSchema(ViewSchema view, string name, DbType dataType, string nativeType, int size, byte precision, int scale, bool allowDBNull, ExtendedProperty[] extendedProperties) : this(view, name, dataType, nativeType, size, precision, scale, allowDBNull)
 {
     this._defaultExtendedProperties = extendedProperties;
     base._extendedProperties        = new ExtendedPropertyCollection(extendedProperties);
 }
 /// <summary>
 /// Gets the definition for a given view.
 /// </summary>
 /// <param name="connectionString">The connection string used to connect to the target database.</param>
 /// <param name="view"></param>
 /// <returns></returns>
 public string GetViewText(string connectionString, ViewSchema view)
 {
     return("");
 }
 /// <summary>
 /// Gets the data from a given view.
 /// </summary>
 /// <param name="connectionString">The connection string used to connect to the target database.</param>
 /// <param name="view"></param>
 /// <returns></returns>
 public DataTable GetViewData(string connectionString, ViewSchema view)
 {
     return(null);
 }
 /// <summary>
 /// Gets the columns for a given view.
 /// </summary>
 /// <param name="connectionString">The connection string used to connect to the target database.</param>
 /// <param name="view"></param>
 /// <returns></returns>
 public ViewColumnSchema[] GetViewColumns(string connectionString, ViewSchema view)
 {
     return(new ViewColumnSchema[0]);
 }