Exemple #1
0
		/// <summary>
		/// Creates a new <see cref="KCommandQuery"/> instance associated with this link object, and sets the initial
		/// contents of the From clause by parsing the command object given, and associating it to a given alias.
		/// </summary>
		/// <param name="link">The link the comand will be associated to.</param>
		/// <param name="command">The command object.</param>
		/// <param name="alias">The alias.</param>
		/// <returns>The new created command.</returns>
		public static KCommandQuery From( this IKLink link, IKCommand command, Func<dynamic, object> alias )
		{
			var cmd = link.Query().From( command, alias );
			return cmd;
		}
Exemple #2
0
		/// <summary>
		/// Appends to the Select clause the contents obtained by parsing the command object given, and associating
		/// it to a given alias.
		/// </summary>
		/// <param name="command">The command object.</param>
		/// <param name="alias">The alias.</param>
		/// <returns>This command, to allow it to permit it to be used in a fluent syntax fashion.</returns>
		public virtual KCommandQuery Select( IKCommand command, Func<dynamic, object> alias )
		{
			if( command == null ) throw new ArgumentNullException( "command", "Command specification cannot be null." );
			if( alias == null ) throw new ArgumentNullException( "alias", "Alias specification cannot be null." );

			string main = Parser.Parse( command, pars: Parameters );
			string nick = Parser.Parse( alias );
			nick = nick.Validated( "Alias", invalidChars: TypeHelper.InvalidNameChars );

			string str = string.Format( "( {0} ) AS {1}", main, nick );
			_TextSelect = _TextSelect == null
				? string.Format( "{0}", str )
				: string.Format( "{0}, {1}", _TextSelect, str );

			return this;
		}
Exemple #3
0
		internal KSurrogate( IKCommand command, bool iterable )
		{
			DEBUG.IndentLine( "\n-- KSurrogate( Iterable={0}, Command={1} )", iterable, command == null ? "null" : command.ToString() );

			if( ( _Command = command ) == null ) throw new ArgumentNullException( "command", "Command cannot be null." );
			if( _Command.Link == null ) throw new ArgumentException( "Command's link is null." );
			_Link = _Command.Link as KLinkDirect; if( _Link == null ) throw new ArgumentException( "Command's link is not a direct link." );

			Invoke( iterable );

			DEBUG.Unindent();
		}
Exemple #4
0
		protected virtual void Dispose( bool disposing )
		{
			DEBUG.IndentLine( "\n-- KSurrogate.Dispose( Disposing={0} ) - This={1}", disposing, this );

			if( _DataReader != null ) {
				if( !_DataReader.IsClosed ) _DataReader.Close();
				_DataReader.Dispose();
				_DataReader = null;
			}
			if( _Link != null ) {
				if( _LinkOpenedBySurrogate ) _Link.DbClose();
				_Link = null;
			}

			_Schema = null; // It might be in use elsewhere
			_Command = null;

			DEBUG.Unindent();
		}
Exemple #5
0
		protected virtual string ParseCommand( IKCommand node, KParameterList pars = null )
		{
			// Getting the command's text...
			string str = node.CommandText( iterable: false ); // Avoiding spurious "OUTPUT XXX" statements

			// If there are parameters to transform, but cannot store them, it is an error
			if( node.Parameters.Count != 0 && pars == null )
				throw new InvalidOperationException( "Cannot parse IKCommand because the receiving parameters collection is null." );

			// Transforming the parameters using names compatible with this command string and context
			foreach( var parameter in node.Parameters ) {
				KParameter neo = pars.Insert( parameter.Value );
				str = str.Replace( parameter.Name, neo.Name );
			}

			return str;
		}