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

📄 abstractsharpqueryconnectionwrapper.cs

📁 全功能c#编译器
💻 CS
📖 第 1 页 / 共 3 页
字号:
				this.pEntities.Add( "TABLES", new SharpQuerySchemaClassCollection( new ISchemaClass[] { new SharpQueryTables(this, this.CatalogName, this.SchemaName, this.Name,  "TABLES") } ) );
				this.pEntities.Add( "VIEWS", new SharpQuerySchemaClassCollection( new ISchemaClass[] { new SharpQueryViews( this, this.CatalogName, this.SchemaName, this.Name,  "VIEWS" ) } ) );
				this.pEntities.Add( "PROCEDURES", new SharpQuerySchemaClassCollection( new ISchemaClass[] { new SharpQueryProcedures( this, this.CatalogName, this.SchemaName, this.Name,  "PROCEDURES" ) } ) );
			}			
		}
		
		///<summary>Refresh all dynamic properties of this connection</summary>
		public void Refresh()
		{			
			this.Clear();
						
			if ( this.IsOpen == true )
			{
				this.OnRefresh();				
			}
		}

		public void Clear()
		{	
			if (this.pEntities != null )
			{
				this.pEntities.Clear();
				
				//Let do the Garbage collector to clear the SharpQuerySchmaClassCollection childs.
				// It wil be do in a thread (by the garbage collector), it will be better								
			}			
		}
				
		///<summary>
		/// Execute a SQL command
		/// <param name="SQLText">
		/// SQL command to execute
		/// </param>
		/// <param name="rows">
		/// Maximum number of row to extract. If is "0" then all rows are extracted.
		/// </param>
		/// <returns> return a <see cref="System.Data.DataTable">DataTable</see>  
		///or a <see cref="System.Data.DataSet">DataSet</see> object.
		/// </returns>
		/// </summary>
		public abstract object ExecuteSQL( string SQLText, int rows);
		//TODO : Parameter param.
		
		///<summary>
		/// Execute a stocked procedure.
		/// <param name="schema">
		/// <see cref="SharpQuery.SchemaClass">SchemaClass</see> object.
		/// </param>
		/// <param name="rows">
		/// Maximum number of row to extract. If is "0" then all rows are extracted.
		/// </param>
		/// <returns> return a <see cref="System.Data.DataTable">DataTable</see>  
		///or a <see cref="System.Data.DataSet">DataSet</see> object.
		/// </returns>
		/// </summary>
		public abstract object ExecuteProcedure( ISchemaClass schema, int rows, SharpQuerySchemaClassCollection parameters );
		
		///<summary>
		/// Extract Data from a Table or a View
		/// <param name="schema">
		/// <see cref="SharpQuery.SchemaClass">SchemaClass</see> object.
		/// </param>
		/// <param name="rows">
		/// Maximum number of row to extract. If is "0" then all rows are extracted.
		/// </param>
		/// <returns> return a <see cref="System.Data.DataTable">DataTable</see>  
		///or a <see cref="System.Data.DataSet">DataSet</see> object.
		/// </returns>
		/// </summary>
		public object ExtractData( ISchemaClass schema, int rows )
		{
						
			if ( schema == null )
			{
				throw new System.ArgumentNullException("schema");
			}
			
			string SQLSelect = this.SELECT + " ";
			string SQLFrom  = this.FROM + " ";	
			SharpQuerySchemaClassCollection entitieslist = null;
			 			
			SQLFrom += schema.Name;			
			
			schema.Refresh();
			//we have only a table or view :o) //TODO : find a better way !
			foreach( DictionaryEntry DicEntry in schema.Entities )
			{
			  entitieslist = DicEntry.Value as SharpQuerySchemaClassCollection;
		      break;
			}
					
			if ( entitieslist == null )
			{
				throw new System.ArgumentNullException("entitieslist");
			}					
					
			foreach( ISchemaClass column in entitieslist )
			{
				SQLSelect += column.NormalizedName;
				SQLSelect += ",";
			}			
			
			SQLSelect = SQLSelect.TrimEnd( new Char[]{','} );
			if ( entitieslist.Count == 0) 
			{
				SQLSelect += "*";
			}
			SQLSelect += " ";
						
			return this.ExecuteSQL( SQLSelect + SQLFrom , 0);
		}
		
				
		///<summary>
		/// Update <see cref="System.Data.DataRow">row</see>'s fields into the current opened database.
		/// <param name="row">a <see cref="System.Data.DataRow">row</see> </param>
		/// <param name="schema"> a <see cref="SharpQuery.SchemaClass.ISchema">schema</see> </param> 
		/// <remarks> it use a transaction for each row, so it's a very long process 
		/// if you should update something like 10 000 lines ;o). It's used only by the DataView.
		/// If you need a better way write a "BatchUpdate" function
		/// </remarks>
		///</summary>
		public void UpDateRow( ISchemaClass schema, DataRow row )
		{
			if ( schema == null )
			{
				throw new System.ArgumentNullException("schema");
			}
			
			if ( row == null )
			{
				throw new System.ArgumentNullException("row");
			}
			
			string SQLUpdate = this.UPDATE + " ";
			string SQLWhere  = this.WHERE + " ";
			string SQLValues = this.SET + " ";
			
			SQLUpdate += schema.Name;
			SQLUpdate += " ";
			
			foreach( DataColumn column in row.Table.Columns )
			{
				if ( column.ReadOnly == false 
				     && column.AutoIncrement == false				   
				   )
				{
					SQLValues += schema.Name + "." + AbstractSharpQuerySchemaClass.CheckWhiteSpace(column.ColumnName);
					SQLValues += "=";
					if (  column.DataType.Equals( System.Type.GetType("System.String") )
					   || column.DataType.Equals( System.Type.GetType("System.Char") )
					   )
					{
						SQLValues +="'";
					}
					SQLValues += row[column.ColumnName];
					if (  column.DataType.Equals( System.Type.GetType("System.String") )
					   || column.DataType.Equals( System.Type.GetType("System.Char") )
					   )
					{
						SQLValues +="'";
					}	
					
					SQLValues += ",";
				}
				
				SQLWhere += SharpQuery.SchemaClass.AbstractSharpQuerySchemaClass.CheckWhiteSpace(column.ColumnName);
				SQLWhere += "=";
				if (  column.DataType.Equals( System.Type.GetType("System.String") )
				   || column.DataType.Equals( System.Type.GetType("System.Char") )
				   )
				{
					SQLWhere +="'";
				}				
				SQLWhere += row[column.ColumnName, DataRowVersion.Original];
				if (  column.DataType.Equals( System.Type.GetType("System.String") )
				   || column.DataType.Equals( System.Type.GetType("System.Char") )
				   )
				{
					SQLWhere +="'";
				}				
				
				if ( row.Table.Columns.IndexOf( column ) != (row.Table.Columns.Count -1) )
				{					
					SQLWhere  += " " + this.AND + " ";					
				}		
			}
			
			SQLValues =SQLValues.TrimEnd(new Char[]{','});
						
			this.ExecuteSQL( SQLUpdate + SQLValues + SQLWhere , 0);
			row.AcceptChanges();
		}
		
		///<summary>
		/// Delete <see cref="System.Data.DataRow">row</see> into the current opened database.
		/// <param name="row">a <see cref="System.Data.DataRow">row</see> </param>
		/// <param name="schema"> a <see cref="SharpQuery.SchemaClass.ISchema">schema</see> </param> 
		/// <remarks> it use a transaction for each row, so it's a very long process 
		/// if you should update something like 10 000 lines ;o). It's used only by the DataView.
		/// If you need a better way write a "BatchUpdate" function
		/// </remarks>
		///</summary>
		public void DeleteRow( ISchemaClass schema, DataRow row )
		{		
			if ( schema == null )
			{
				throw new System.ArgumentNullException("schema");
			}
			
			if ( row == null )
			{
				throw new System.ArgumentNullException("row");
			}
			
			string SQLDelete = this.DELETE + " ";
			string SQLWhere  = this.WHERE +" ";
			string SQLFrom 	 = this.FROM +" ";
			
			SQLFrom += schema.Name;
			SQLFrom += " ";
			
			foreach( DataColumn column in row.Table.Columns )
			{
				//SQLDelete += schema.Name + "." + column.ColumnName;
				
				SQLWhere += SharpQuery.SchemaClass.AbstractSharpQuerySchemaClass.CheckWhiteSpace(column.ColumnName);
				SQLWhere += "=";
				if (  column.DataType.Equals( System.Type.GetType("System.String") )
				   || column.DataType.Equals( System.Type.GetType("System.Char") )
				   )
				{
					SQLWhere +="'";
				}				
				SQLWhere += row[column.ColumnName, DataRowVersion.Original];
				if (  column.DataType.Equals( System.Type.GetType("System.String") )
				   || column.DataType.Equals( System.Type.GetType("System.Char") )
				   )
				{
					SQLWhere +="'";
				}				
				
				if ( row.Table.Columns.IndexOf( column ) != (row.Table.Columns.Count -1) )
				{
					//SQLDelete += ",";
					SQLWhere  += " " + this.AND + " ";					
				}		
				else
				{
					//SQLDelete += " ";
				}				
			}			
						
			this.ExecuteSQL( SQLDelete + SQLFrom + SQLWhere , 0);
			row.AcceptChanges();
		}		
		
		///<summary>
		/// Insert <see cref="System.Data.DataRow">row</see> into the current opened database.
		/// <param name="row">a <see cref="System.Data.DataRow">row</see> </param>
		/// <param name="schema"> a <see cref="SharpQuery.SchemaClass.ISchema">schema</see> </param> 
		/// <remarks> it use a transaction for each row, so it's a very long process 
		/// if you should update something like 10 000 lines ;o). It's used only by the DataView.
		/// If you need a better way write a "BatchUpdate" function
		/// </remarks>
		///</summary>
		public void InsertRow( ISchemaClass schema, DataRow row )
		{	
			if ( schema == null )
			{
				throw new System.ArgumentNullException("schema");
			}
			
			if ( row == null )
			{
				throw new System.ArgumentNullException("row");
			}			
			
			string SQLInsert = this.INSERINTO + " ";
			string SQLValues = this.VALUES +" (";
			
			SQLInsert += schema.Name;
			SQLInsert += " (";
			
			foreach( DataColumn column in row.Table.Columns )
			{				
				if ( column.ReadOnly == false 
				     && column.AutoIncrement == false				   
				   )
				{				
					SQLInsert += /*schema.Name + "." + //Full qualified name not supported by some provider*/ SharpQuery.SchemaClass.AbstractSharpQuerySchemaClass.CheckWhiteSpace(column.ColumnName);
					
					if (  column.DataType.Equals( System.Type.GetType("System.String") )
					   || column.DataType.Equals( System.Type.GetType("System.Char") )
					   )
					{
						SQLValues +="'";
					}				
					SQLValues += row[column.ColumnName, DataRowVersion.Current ];
					if (  column.DataType.Equals( System.Type.GetType("System.String") )
					   || column.DataType.Equals( System.Type.GetType("System.Char") )
					   )
					{
						SQLValues +="'";
					}	
					
					SQLValues  += ",";
					SQLInsert += ",";
				}				
			}
			
			SQLValues = SQLValues.TrimEnd(new Char[]{','});
			SQLInsert = SQLInsert.TrimEnd(new Char[]{','});
			
			SQLInsert += ") ";	
			SQLValues += ")";

						
			this.ExecuteSQL( SQLInsert + SQLValues, 0);
			row.AcceptChanges();
		}		
		
		///<summary> throw a exception if the <seealso cref='.AbstractSharpQueryConnectionWrapper.Connection'/> is <code>null</code> </summary>
		protected abstract void CheckConnectionObject();

		///<summary> each elements of the restrictions array which are an empty string is replaced with a <code>null</code> reference</summary>		
		protected object[] NormalizeRestrictions( object[] restrictions)
		{	
			object[] newRestrictions = null;
			
			if ( restrictions != null )
			{
				newRestrictions = new object[ restrictions.Length ];
				object restriction;
				
				for( int i = 0; i < restrictions.Length; i++)
				{
					restriction =  restrictions[i];
	
					if ( restriction != null )
					{
						if ( (restriction is string) && ( (restriction as string) == "") )
						{

⌨️ 快捷键说明

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