コード例 #1
0
ファイル: DBScript.cs プロジェクト: jschmer/dynasql
        /// <summary>
        /// Creates a return statement with the parameter in this script
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public DBStatement Return(DBParam param)
        {
            DBReturn ret = DBReturn.Return(param);

            this.Then(ret);
            return(ret);
        }
コード例 #2
0
        /// <summary>
        /// Creates and returns a new declaration of the parameter
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public static DBDeclaration Declare(DBParam param)
        {
            DBDelcarationRef dref = new DBDelcarationRef();

            dref.Parameter = param;
            return(dref);
        }
コード例 #3
0
ファイル: DBScript.cs プロジェクト: jschmer/dynasql
        /// <summary>
        /// creates a parameter Declaration in this script
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public DBScript Declare(DBParam param)
        {
            DBDeclaration dec = DBDeclaration.Declare(param);

            this.Then(dec);
            return(this);
        }
コード例 #4
0
        //
        // WithParam... methods
        //

        #region public DBExecQuery WithParam(DBParam param)

        /// <summary>
        /// Appends a parameter to this EXEC statement
        /// </summary>
        /// <param name="param">The parameter to append</param>
        /// <returns>Itself to support statement chaining</returns>
        public DBExecQuery WithParam(DBParam param)
        {
            if (null == param)
            {
                throw new ArgumentNullException("param");
            }

            this.Parameters.Add(param);
            return(this);
        }
コード例 #5
0
 protected override bool ReadAnInnerElement(System.Xml.XmlReader reader, XmlReaderContext context)
 {
     if (this.IsElementMatch(XmlHelper.SprocParams, reader, context))
     {
         DBParamList paramlist = new DBParamList();
         while (reader.Read())
         {
             if (IsElementMatch(XmlHelper.Parameter, reader, context))
             {
                 DBParam p = DBParam.Param();
                 p.ReadXml(reader, context);
                 if (context.Parameters.Contains(p.Name))
                 {
                     p = context.Parameters[p.Name];
                 }
                 else
                 {
                     context.Parameters.Add(p);
                 }
                 paramlist.Add(p);
             }
             else if (reader.NodeType == System.Xml.XmlNodeType.EndElement && reader.LocalName == XmlHelper.SprocParams)
             {
                 break;
             }
         }
         this.Parameters = paramlist;
         return(true);
     }
     else if (IsElementMatch(XmlHelper.Script, reader, context))
     {
         DBClause c = this.ReadNextInnerClause(reader.LocalName, reader, context);
         if (c is DBScript)
         {
             this.Script = (DBScript)c;
         }
         else
         {
             throw new System.Xml.XmlException("Inner content of a StoredProcedure must be a Script");
         }
         return(true);
     }
     return(base.ReadAnInnerElement(reader, context));
 }
コード例 #6
0
        protected override bool ReadAnInnerElement(System.Xml.XmlReader reader, XmlReaderContext context)
        {
            DBClause c = this.ReadNextInnerClause(this.XmlElementName, reader, context);

            if (c is DBParam)
            {
                DBParam p = (DBParam)c;
                if (context.Parameters.Contains(p.Name))
                {
                    p = context.Parameters[p.Name];
                }
                else
                {
                    context.Parameters.Add(p);
                }
                this.Parameter = p;
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #7
0
        /// <summary>
        ///  Adds an input/output parameter to the declaration of this StoredProcedure
        /// </summary>
        /// <param name="genericname"></param>
        /// <param name="type"></param>
        /// <param name="size"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        public DBCreateProcedureQuery WithParam(string genericname, DbType type, int size, ParameterDirection direction)
        {
            DBParam p = DBParam.Param(genericname, type, size, direction);

            return(this.WithParam(p));
        }
コード例 #8
0
        //
        // methods
        //

        #region public DBCreateProcedureQuery WithParam(DBParam parameter) + 4 overloads

        /// <summary>
        /// Adds an input/output parameter to the declaration of this StoredProcedure
        /// </summary>
        /// <param name="genericname"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public DBCreateProcedureQuery WithParam(string genericname, DbType type)
        {
            DBParam p = DBParam.Param(genericname, type);

            return(this.WithParam(p));
        }
コード例 #9
0
        /// <summary>
        /// Appends a new parameter to this EXEC statement with the type and the delegate
        /// method that will be evaulated at statement generation time to extract the value
        /// </summary>
        /// <param name="name">The name of the parameter</param>
        /// <param name="type">The DbType of the parameter</param>
        /// <param name="valueprovider">The delegate method that will return the value</param>
        /// <returns>Itself to support statement chaining</returns>
        public DBExecQuery WithParamDelegate(string name, System.Data.DbType type, ParamValue valueprovider)
        {
            DBParam p = DBParam.ParamWithDelegate(name, type, valueprovider);

            return(this.WithParam(p));
        }
コード例 #10
0
ファイル: DBInsertQuery.cs プロジェクト: jschmer/dynasql
        /// <summary>
        /// Specify a value for the correspoding column via a delegate method
        /// </summary>
        /// <param name="valueProvider">A (anonymous) delegate that returns an object when invoked</param>
        /// <returns>Itself so statements can be chained</returns>
        public DBInsertQuery Value(ParamValue valueProvider)
        {
            DBParam p = DBParam.ParamWithDelegate(valueProvider);

            return(Value(p));
        }
コード例 #11
0
        /// <summary>
        /// Appends a new parameter to this EXEC statement with the specified name and value.
        /// WARNING - specifying null or DBNull will make the DbType undiscoverable at runtime, and may cause execution errors
        /// </summary>
        /// <param name="name">The name of the parameter</param>
        /// <param name="value">The value of the parameter</param>
        /// <returns>Itself to support statement chaining</returns>
        public DBExecQuery WithParamValue(string name, object value)
        {
            DBParam p = DBParam.ParamWithValue(name, value);

            return(this.WithParam(p));
        }
コード例 #12
0
        /// <summary>
        /// Appends a new parameter to this EXEC statement of the specified type and with the specified value
        /// </summary>
        /// <param name="type">The DbType of the parameter</param>
        /// <param name="paramValue">The value of the parameter</param>
        /// <returns>Itself to support statement chaining</returns>
        public DBExecQuery WithParamValue(System.Data.DbType type, object paramValue)
        {
            DBParam p = DBParam.ParamWithValue(type, paramValue);

            return(this.WithParam(p));
        }
コード例 #13
0
        /// <summary>
        /// Appends a new parameter to this EXEC statement with the specified value.
        /// WARNING - specifying null or DBNull will make the DbType undiscoverable at runtime, and may cause execution errors
        /// </summary>
        /// <param name="paramValue">The value of the parameter</param>
        /// <returns>Itself to support statement chaining</returns>
        public DBExecQuery WithParamValue(object paramValue)
        {
            DBParam p = DBParam.ParamWithValue(paramValue);

            return(this.WithParam(p));
        }
コード例 #14
0
ファイル: DBScript.cs プロジェクト: jschmer/dynasql
        /// <summary>
        /// Creates a return statement with the parameter in this script
        /// </summary>
        /// <param name="paramName"></param>
        /// <returns></returns>
        public DBStatement Return(string paramName)
        {
            DBParam p = DBParam.Param(paramName);

            return(Return(p));
        }
コード例 #15
0
ファイル: DBScript.cs プロジェクト: jschmer/dynasql
        /// <summary>
        /// creates a parameter assignment statement in this script
        /// </summary>
        /// <param name="param"></param>
        /// <param name="clause"></param>
        /// <returns></returns>
        public DBScript Set(DBParam param, DBClause clause)
        {
            DBAssign assign = DBAssign.Set(param, clause);

            return(this.Set(assign));
        }
コード例 #16
0
 /// <summary>
 ///  Adds an input/output parameter to the declaration of this StoredProcedure
 /// </summary>
 /// <param name="parameter"></param>
 /// <returns></returns>
 public DBCreateProcedureQuery WithParam(DBParam parameter)
 {
     this.Parameters.Add(parameter);
     return(this);
 }
コード例 #17
0
        public DBExecQuery WithParamValue(string name, System.Data.DbType type, int length, object value)
        {
            DBParam p = DBParam.ParamWithValue(name, type, length, value);

            return(this.WithParam(p));
        }
コード例 #18
0
        /// <summary>
        /// Appends a new parameter to this EXEC statement with the delegate
        /// method that will be evaulated at statement generation time ot extract the value
        /// </summary>
        /// <param name="valueprovider">The delegate method that will return the value</param>
        /// <returns>Itself to support statement chaining</returns>
        public DBExecQuery WithParamDelegate(ParamValue valueprovider)
        {
            DBParam p = DBParam.ParamWithDelegate(valueprovider);

            return(this.WithParam(p));
        }
コード例 #19
0
        protected virtual DBClause DoRead(string element, XmlReader reader, XmlReaderContext context)
        {
            DBClause c = null;

            switch (element)
            {
            case (XmlHelper.Select):
                c = DBSelectQuery.Select();
                break;

            case (XmlHelper.Delete):
                c = DBDeleteQuery.Delete();
                break;

            case (XmlHelper.Update):
                c = DBUpdateQuery.Update();
                break;

            case (XmlHelper.Insert):
                c = DBInsertQuery.InsertInto();
                break;

            case (XmlHelper.Script):
                c = DBQuery.Script();
                break;

            case (XmlHelper.Use):
                c = DBUseQuery.Use();
                break;

            case (XmlHelper.Table):
                c = DBTable.Table();
                break;

            case (XmlHelper.Fields):
                c = DBSelectSet.Select();
                break;

            case (XmlHelper.AField):
                c = DBField.Field();
                break;

            case (XmlHelper.AllFields):
                c = DBField.AllFields();
                break;

            case (XmlHelper.From):
                c = DBTableSet.From();
                break;

            case (XmlHelper.Where):
                c = DBFilterSet.Where();
                break;

            case (XmlHelper.Group):
                c = DBGroupBySet.GroupBy();
                break;

            case (XmlHelper.Order):
                c = DBOrderSet.OrderBy();
                break;

            case (XmlHelper.Assignments):
                c = DBAssignSet.Assign();
                break;

            case (XmlHelper.Values):
                c = DBValueSet.Values();
                break;

            case (XmlHelper.Join):
                c = DBJoin.Join();
                break;

            case (XmlHelper.Function):
                c = DBFunction.Function();
                break;

            case (XmlHelper.Constant):
                c = DBConst.Null();
                break;

            case (XmlHelper.Top):
                c = DBTop.Top();
                break;

            case (XmlHelper.UnaryOp):
                c = DBComparison.Not();
                break;

            case (XmlHelper.Compare):
                c = DBComparison.Compare();
                break;

            case (XmlHelper.Between):
                c = DBComparison.Between();
                break;

            case (XmlHelper.Parameter):
                //parameter is a special case.
                //we add them to akeyed colection if they are not already registered
                //then at the end we set the values at the end
                string  name = reader.GetAttribute(XmlHelper.Name);
                DBParam aparam;
                if (context.Parameters.TryGetParameter(name, out aparam))
                {
                    c = aparam;
                }
                else
                {
                    aparam      = DBParam.Param();
                    aparam.Name = name;
                    context.Parameters.Add(aparam);
                    c = aparam;
                }
                break;

            case (XmlHelper.OrderBy):
                c = DBOrder.OrderBy();
                break;

            case (XmlHelper.Calculation):
                c = DBCalc.Calculate();
                break;

            case (XmlHelper.Aggregate):
                c = DBAggregate.Aggregate();
                break;

            case (XmlHelper.ValueGroup):
                c = DBValueGroup.Empty();
                break;

            case (XmlHelper.BooleanOperator):
                c = DBBooleanOp.Compare();
                break;

            case (XmlHelper.Assign):
                c = DBAssign.Assign();
                break;

            case (XmlHelper.InnerSelect):
                c = DBSubQuery.SubSelect();
                break;

            case (XmlHelper.Multiple):
                c = DBMultiComparisonRef.Many();
                break;

            case (XmlHelper.QueryOptionSet):
                c = new DBQueryHintOptionSet();
                break;

            case (XmlHelper.QueryOption):
                c = DBQueryHintOption.QueryOption();
                break;

            case (XmlHelper.CreateSproc):
                c = DBCreateProcedureQuery.CreateProcedure();
                break;

            case (XmlHelper.Declare):
                c = DBDeclaration.Declare();
                break;

            case (XmlHelper.CreateTable):
                c = DBCreateTableQuery.Table();
                break;

            case (XmlHelper.ColumnDefinition):
                c = DBColumn.Column();
                break;

            case (XmlHelper.PrimaryKey):
                c = DBPrimaryKey.PrimaryKey();
                break;

            case (XmlHelper.ForeignKey):
                c = DBForeignKey.ForeignKey();
                break;

            case (XmlHelper.CreateIndex):
                c = DBCreateIndexQuery.Index();
                break;

            case (XmlHelper.CreateView):
                c = DBCreateViewQuery.CreateView();
                break;

            case (XmlHelper.CreateSequence):
                c = DBCreateSequenceQuery.Sequence();
                break;

            case (XmlHelper.DropTable):
                c = DBDropTableQuery.DropTable();
                break;

            case (XmlHelper.DropIndex):
                c = DBDropIndexQuery.DropIndex();
                break;

            case (XmlHelper.DropView):
                c = DBDropViewQuery.DropView();
                break;

            case (XmlHelper.DropSproc):
                c = DBDropProcedureQuery.DropProcedure();
                break;

            case (XmlHelper.DropSequence):
                c = DBDropSequenceQuery.DropSequence();
                break;

            default:
                throw XmlHelper.CreateException("The XML data could not be deserialized because the element {1} was not recognised. {0}", reader, null, element);
            }

            if (c != null)
            {
                c.ReadXml(reader, context);
            }

            return(c);
        }
コード例 #20
0
ファイル: DBQuery.cs プロジェクト: jschmer/dynasql
        //
        // DBDecaration
        //

        #region public static DBDeclaration Declare(DBParam param)

        /// <summary>
        /// Creates a declaration statement e.g. DECLARE @p1 INT;
        /// </summary>
        /// <param name="param">The parameter to declare</param>
        /// <returns>The declaration</returns>
        public static DBDeclaration Declare(DBParam param)
        {
            return(DBDeclaration.Declare(param));
        }