⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractsharpqueryconnectionwrapper.cs

📁 c#源代码
💻 CS
📖 第 1 页 / 共 3 页
字号:
							restriction = null;
						}
					}
					
					newRestrictions[i] = restriction;			
				}
			}
			return newRestrictions;
		}		

		/// <summary>
		/// return a schema matching <code>restrictions</code>
		/// <param name="schema"> a <see cref=".SharpQuerySchemaEnum">SharpQuerySchemaEnum</see>.</param>
		/// <param name="restrictions"> Restrictions matching the schema</param>
		/// </summary>				
		protected abstract DataTable GetSchema( SharpQuerySchemaEnum schema, object[] restrictions );
		
		
//
// IConnection methods
//
		
		public SharpQuerySchemaClassCollection GetSchemaCatalogs( ISchemaClass schema )
		{
			SharpQuerySchemaClassCollection list = new SharpQuerySchemaClassCollection( );
			DataTable record = null;
			SharpQuerySchemaEnum schematype = SharpQuerySchemaEnum.Catalogs;
			object[] restrictions = new object[]{ schema.InternalName };
			
			try
			{
				record = this.GetSchema( schematype , restrictions );
	
				//TODO : add not supported schema code!
				
				if ( record != null )
				{					
					foreach (DataRow row in record.Rows )
					{
						list.Add( new SharpQueryCatalog( this, row["CATALOG_NAME"].ToString(), "", "", row["CATALOG_NAME"].ToString()) );
					}					
				}
			}
			catch( System.Exception )
			{	
				list.Add( new SharpQueryNotSupported(this, "" , "", "", "SharpQuerySchemaEnum.Catalogs") );
			}
			
			return list;
		}
		
		public SharpQuerySchemaClassCollection GetSchemaSchemas( ISchemaClass schema )
		{			
			SharpQuerySchemaClassCollection list = new SharpQuerySchemaClassCollection( );
			DataTable record = null;		
			SharpQuerySchemaEnum schematype = SharpQuerySchemaEnum.Schemata;
			object[] restrictions = new object[]{ schema.CatalogName, "", "" };
			
			try
			{
				record = this.GetSchema( schematype, restrictions );
				
				if ( record != null )
				{
					foreach (DataRow row in record.Rows )
					{
						list.Add( new SharpQuerySchema( this, row["CATALOG_NAME"].ToString(), row["SCHEMA_NAME"].ToString(), "", row["SCHEMA_NAME"].ToString()) );
					}

				}
			}
			catch( System.Exception )
			{		
				list.Add( new SharpQueryNotSupported(this, "" , "", "", "SharpQuerySchemaEnum.Schemata") );
			}
			
			return list;						
		}		
		
		public SharpQuerySchemaClassCollection GetSchemaTables( ISchemaClass schema )
		{			
			SharpQuerySchemaClassCollection list = new SharpQuerySchemaClassCollection( );
			DataTable record = null;
			SharpQuerySchemaEnum schematype = SharpQuerySchemaEnum.Tables;
			object[] restrictions = new object[]{ schema.CatalogName, schema.SchemaName, "", "TABLE" };
			
			try
			{
				record = this.GetSchema( schematype, restrictions );
				
				if ( record != null )
				{
					foreach (DataRow row in record.Rows )
					{
						list.Add( new SharpQueryTable( this, row["TABLE_CATALOG"].ToString(), row["TABLE_SCHEMA"].ToString(), "", row["TABLE_NAME"].ToString()) );
					}					
				}
			}
			catch( System.Exception )
			{		
				list.Add( new SharpQueryNotSupported(this, "" , "", "", "SharpQuerySchemaEnum.Tables") );
			}
			
			return list;
		}
		
		public SharpQuerySchemaClassCollection GetSchemaViews( ISchemaClass schema )
		{
			SharpQuerySchemaClassCollection list = new SharpQuerySchemaClassCollection( );
			DataTable record = null;		
			SharpQuerySchemaEnum schematype = SharpQuerySchemaEnum.Views;
			object[] restrictions = new object[]{ schema.CatalogName, schema.SchemaName, "", "VIEW" };
			
			try
			{
				record = this.GetSchema( schematype, restrictions );
				
				if ( record != null )
				{
					foreach (DataRow row in record.Rows )
					{
						list.Add( new SharpQueryView( this, row["TABLE_CATALOG"].ToString(), row["TABLE_SCHEMA"].ToString(), "", row["TABLE_NAME"].ToString()) );
					}					
				}
			}
			catch( System.Exception )
			{		
				list.Add( new SharpQueryNotSupported(this, "" , "", "", "SharpQuerySchemaEnum.Views") );
			}
			
			return list;
		}
		
		public SharpQuerySchemaClassCollection GetSchemaProcedures( ISchemaClass schema )
		{
			SharpQuerySchemaClassCollection list = new SharpQuerySchemaClassCollection( );
			DataTable record = null;		
			SharpQuerySchemaEnum schematype = SharpQuerySchemaEnum.Procedures;
			object[] restrictions = new object[]{ schema.CatalogName, schema.SchemaName, "", ""};
			
			try
			{
				record = this.GetSchema( schematype, restrictions );
				
				if ( record != null )
				{
					foreach (DataRow row in record.Rows )
					{
						list.Add( new SharpQueryProcedure( this, row["PROCEDURE_CATALOG"].ToString(), row["PROCEDURE_SCHEMA"].ToString(), "", row["PROCEDURE_NAME"].ToString().Split(';')[0] ) );
					}					
				}
			}
			catch( System.Exception )
			{		
				list.Add( new SharpQueryNotSupported(this, "" , "", "", "SharpQuerySchemaEnum.Procedures") );
			}
			
			return list;			
		}
		
		public SharpQuerySchemaClassCollection GetSchemaTableColumns( ISchemaClass schema )
		{
			SharpQuerySchemaClassCollection list = new SharpQuerySchemaClassCollection( );
			DataTable record = null;	
			SharpQuerySchemaEnum schematype = SharpQuerySchemaEnum.Columns;
			object[] restrictions = new object[]{ schema.CatalogName, schema.SchemaName, schema.InternalName, "" };
			
			try
			{
				record = this.GetSchema( schematype, restrictions );
				
				if ( record != null )
				{
					foreach (DataRow row in record.Rows )
					{
						list.Add( new SharpQueryColumn( this, schema.CatalogName, schema.SchemaName,schema.Name, row["COLUMN_NAME"].ToString()) );
					}					
				}
			}
			catch( System.Exception )
			{		
				list.Add( new SharpQueryNotSupported(this, "" , "", "", "SharpQuerySchemaEnum.Columns") );
			}
			
			return list;
		}
		
		public SharpQuerySchemaClassCollection GetSchemaViewColumns( ISchemaClass schema )
		{
			SharpQuerySchemaClassCollection list = new SharpQuerySchemaClassCollection( );
			DataTable record = null;		
			SharpQuerySchemaEnum schematype = SharpQuerySchemaEnum.ViewColumns;
			object[] restrictions = new object[]{ schema.CatalogName, schema.SchemaName, schema.InternalName, "" };
			
			try
			{
				record = this.GetSchema( schematype, restrictions );
				
				if ( record != null )
				{
					foreach (DataRow row in record.Rows )
					{
						list.Add( new SharpQueryColumn( this, schema.CatalogName, schema.SchemaName, schema.Name, row["COLUMN_NAME"].ToString()) );
					}					
				}
			}
			catch( System.Exception )
			{		
				list.Add( new SharpQueryNotSupported(this, "" , "", "", "SharpQuerySchemaEnum.Columns") );
			}
			
			return list;
		}		
		
		public SharpQuerySchemaClassCollection GetSchemaProcedureColumns( ISchemaClass schema )
		{
			SharpQuerySchemaClassCollection list = new SharpQuerySchemaClassCollection( );
			DataTable record = null;	
			SharpQuerySchemaEnum schematype = SharpQuerySchemaEnum.ProcedureColumns;
			object[] restrictions = new object[]{ schema.CatalogName, schema.SchemaName, schema.InternalName, "" };
			
			try
			{
				record = this.GetSchema( schematype, restrictions );
				
				if ( record != null )
				{
					foreach (DataRow row in record.Rows )
					{
						list.Add( new SharpQueryColumn( this, schema.CatalogName, schema.SchemaName, schema.Name, row["COLUMN_NAME"].ToString()) );
					}					
				}
			}
			catch( System.Exception)
			{		
				list.Add( new SharpQueryNotSupported(this, "" , "", "", "SharpQuerySchemaEnum.ProcedureColumns") );
			}
			
			return list;
		}
		
		public SharpQuerySchemaClassCollection GetSchemaProcedureParameters( ISchemaClass schema )
		{
			SharpQuerySchemaClassCollection list = new SharpQuerySchemaClassCollection( );
			DataTable record = null;		
			SharpQuerySchemaEnum schematype = SharpQuerySchemaEnum.ProcedureParameters;
			object[] restrictions = new object[]{ schema.CatalogName, schema.SchemaName, schema.InternalName, "" };
			
			try
			{
				record = this.GetSchema( schematype, restrictions );
				SharpQueryParameter par = null;
				if ( record != null )
				{
					foreach (DataRow row in record.Rows )
					{
						par = new SharpQueryParameter( this, schema.CatalogName, schema.SchemaName, schema.Name, row["PARAMETER_NAME"].ToString());
						par.DataType = StringToDbType( row["DATA_TYPE"].ToString() );
						par.Type     = StringToParamDirection( row["PARAMETER_TYPE"].ToString() );
						
						if ( par.Type != ParameterDirection.ReturnValue )
						{
							list.Add( par );
						}
					}									
				}
			}
			catch( System.Exception )
			{		
				list.Add( new SharpQueryNotSupported(this, "" , "", "", "SharpQuerySchemaEnum.ProcedureParameters") );
			}
			
			return list;
		}
		
		
		protected DbType StringToDbType( string value )
		{
			return IntToDbType( int.Parse( value ) );
		}
		
		protected DbType IntToDbType( int value )
		{
			DbType retValue;
			switch( value )
			{	
				case 129	: retValue = DbType.AnsiString; break;
				//case 1	: retValue = DbType.AnsiStringFixedLength; break;
				case 128	: retValue = DbType.Binary; break;
				case 11		: retValue = DbType.Boolean; break;
				case 17		: retValue = DbType.Byte; break;
				case 6		: retValue = DbType.Currency; break;
				case 7		:
				case 133	: retValue = DbType.Date; break;
				case 135	: retValue = DbType.DateTime; break;
				case 14		: retValue = DbType.Decimal; break;
				case 5		: retValue = DbType.Double; break;
				case 72		: retValue = DbType.Guid; break;
				case 2		: retValue = DbType.Int16; break;
				case 3		: retValue = DbType.Int32; break;
				case 20		: retValue = DbType.Int64; break;
				case 12		:
				case 132	: retValue = DbType.Object; break;
				case 16		: retValue = DbType.SByte; break;
				case 4		: retValue = DbType.Single; break;
				case 130	: retValue = DbType.String; break;
				case 8		: retValue = DbType.StringFixedLength; break;
				case 134	: retValue = DbType.Time; break;
				case 18		: retValue = DbType.UInt16; break;
				case 19		: retValue = DbType.UInt32; break;
				case 21		: retValue = DbType.UInt64; break;
				case 131	: retValue = DbType.VarNumeric; break;
				default : throw new ArgumentOutOfRangeException("value");				
			}
			
			return retValue;			
		}
		
		protected ParameterDirection StringToParamDirection( string value )
		{
			return 	IntToParamDirection( int.Parse( value ) );
		}
		
		protected ParameterDirection IntToParamDirection( int value )
		{
			ParameterDirection retValue;
			switch( value )
			{
				case 1 : retValue = ParameterDirection.Input; break;
				case 2 : retValue = ParameterDirection.InputOutput; break;
				case 3 : retValue = ParameterDirection.Output; break;
				case 4 : retValue = ParameterDirection.ReturnValue; break;
				default : throw new ArgumentOutOfRangeException("value");
				
			}
			
			return retValue;
		}
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -