public string GetViewText(string connectionString, ViewSchema view)
		{
			StringBuilder stringBuilder = new StringBuilder();
			string commandText = string.Format("Select smv.definition \r\nFROM sys.all_views AS v\r\n    JOIN sys.sql_modules AS smv \r\n        ON smv.object_id = v.object_id\r\n        where name='{0}'", view.Name);
			using (DbConnection dbConnection = MsSqlSchemaProvider.CreateConnection(connectionString))
			{
				dbConnection.Open();
				DbCommand dbCommand = dbConnection.CreateCommand();
				dbCommand.CommandText = commandText;
				dbCommand.Connection = dbConnection;
				using (IDataReader dataReader = dbCommand.ExecuteReader(CommandBehavior.CloseConnection))
				{
					while (dataReader.Read())
					{
						stringBuilder.Append(dataReader.GetString(0));
					}
					if (!dataReader.IsClosed)
					{
						dataReader.Close();
					}
				}
				if (dbConnection.State != ConnectionState.Closed)
				{
					dbConnection.Close();
				}
			}
			return stringBuilder.ToString();
		}
Exemple #2
0
 public ViewColumnSchema(ViewSchema view, string name, DbType dataType, string nativeType, int size, int precision, int scale, bool allowDBNull)
 {
     this.database = view.Database;
     this.view = view;
     this.name = name;
     this.dataType = dataType;
     this.nativeType = nativeType;
     this.size = size;
     this.precision = precision;
     this.scale = scale;
     this.isAllowDBNull = allowDBNull;
     this.extendedProperties = new List<ExtendedProperty>();
 }
		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 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG = '{0}' AND TABLE_NAME = '{1}'ORDER BY ORDINAL_POSITION", view.Database.Name, view.Name);
			List<ViewColumnSchema> list = new List<ViewColumnSchema>();
			using (DbConnection dbConnection = MsSqlSchemaProvider.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)) ? ((long)dataReader.GetInt32(2)) : 0L;
                        int precision = (!dataReader.IsDBNull(3)) ? dataReader.GetByte(3) : 0;
						int scale = (!dataReader.IsDBNull(4)) ? dataReader.GetInt32(4) : 0;
						int ob = dataReader.GetInt32(5);
						bool allowDBNull = ob == 1;
						int size = (num < 2147483647L) ? ((int)num) : 2147483647;
						DbType dbType = MsSqlSchemaProvider.GetDbType(string2, false);
						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 DataTable GetViewData(string connectionString, ViewSchema view)
		{
			string commandText = string.Format("SELECT * FROM {0}", view.Name);
			DataSet dataSet = new DataSet();
			using (DbConnection dbConnection = MsSqlSchemaProvider.CreateConnection(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();
				}
			}
			DataTable result;
			if (dataSet.Tables.Count > 0)
			{
				result = dataSet.Tables[0];
			}
			else
			{
				result = new DataTable(view.Name);
			}
			return result;
		}
Exemple #5
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.extendedProperties = new List<ExtendedProperty>();
     this.extendedProperties.AddRange(extendedProperties);
 }