当前位置: 首页>>代码示例>>C#>>正文


C# DbParameter.Render方法代码示例

本文整理汇总了C#中DbParameter.Render方法的典型用法代码示例。如果您正苦于以下问题:C# DbParameter.Render方法的具体用法?C# DbParameter.Render怎么用?C# DbParameter.Render使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DbParameter的用法示例。


在下文中一共展示了DbParameter.Render方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderInsert

        /// <summary>
        /// Renders INSERT statement and code that retrieves the new ID.
        /// </summary>
        /// <param name="insert">INSERT statement that is being rendered.</param>
        /// <param name="nextSequence">Ignored. SQL Server doesn't use sequences.</param>
        /// <param name="dbms">Target DBMS. Different auto-id retrieval for SQL 7.0 then in newer versions.</param>
        /// <param name="output">StringBuilder to which the SQL code is appended.</param>
        /// <param name="parameters">SQL parameter collection to which the object's and its children's
        /// parameters are added. After the rendering is done the collection contains all parameters with unique names.</param>
        /// <returns>Parameter that contains the ID of the inserted row. <b>null</b> if auto-id field is not used.</returns>
        public DbParameter RenderInsert(InsertStatement insert, DbParameter nextSequence, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
        {
            // Renders INSERT statements for DBMSs that support an auto-identity fields.
            // Auto-id field may or may not be in the column-value list.
            // If auto-incremented field is in the column-value list it will be skipped.
            // Table may have only one auto-identity field.
            // Method expects that all errors have been identified and processed in the caller.
            // Renders all fields except auto-id field; thus -1 if auto-id is contained in the column-value list.
            int numberOfFieldsToRender = GetTotalNumberOfFieldsToRender(insert);

            AppendInsertIntoTableName(insert, dbms, output);
            if (numberOfFieldsToRender > 0)
            {
                AppendBracketsWithAllFieldsExceptAutoId(insert, dbms, output, numberOfFieldsToRender);
                AppendValuesForAllFieldsExceptAutoId(insert, dbms, output, parameters, numberOfFieldsToRender);
            }
            else
            {
                AppendDefaultValuesExpression(output);
            }

            DbParameter autoId = null;
            if (HasAutoIdField(insert.Table))
            {
                autoId = new DbParameter("___newAutoIdentity___", DbType.Int32) { Direction = ParameterDirection.Output };
                if (dbms == DbmsType.SqlServer_7)
                {
                    // @@IDENTITY
                    output.Append(" ; set ");
                    autoId.Render(dbms, output, parameters);
                    output.Append(" = @@IDENTITY");
                }
                else
                {
                    // scope_identity()
                    output.Append(" ; set ");
                    autoId.Render(dbms, output, parameters);
                    output.Append(" = scope_identity()");
                }

                // BatchQuery (if ever implemented) reads this value to assign new ID value to InsertStatement.RetrievedData property.
                //insert.NewIdOutputParameterIndexAfterRenderCompleted = parameters.Count - 1;
            }

            // Return auto-id DB parameter. Callers require it to retrieve the new ID value.
            return autoId;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:57,代码来源:SqlServerInserter.cs

示例2: RenderInsert

        public DbParameter RenderInsert(InsertStatement insert, DbParameter nextSequence, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
        {
            // Auto ID: sequence if it is defined, or NULL and hope that a trigger will take care of auto ID field.
            IDbColumn autoIdField = GetAutoIdField(insert.Table);
            bool hasAutoIdField = (autoIdField != null);
            bool autoIdIsAlreadyInInsertList = IsAutoIdFieldInColumnValueList(insert);
            bool mustAppendAutoIdField = (hasAutoIdField && !autoIdIsAlreadyInInsertList);

            AppendInsertIntoTableName(insert, dbms, output);
            AppendColumnListInBrackets(insert, dbms, output, autoIdField, mustAppendAutoIdField);
            RenderValueListAndNextSequenceExpression(insert, dbms, output, parameters, autoIdField, mustAppendAutoIdField);

            if (autoIdField != null && nextSequence != null)
            {
                // RETURNING id
                output.Append(" RETURNING ");
                autoIdField.RenderColumnName(dbms, output);
                output.Append(" INTO ");
                nextSequence.Render(dbms, output, parameters);
            }

            return nextSequence;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:23,代码来源:OracleInserter.cs


注:本文中的DbParameter.Render方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。