本文整理汇总了C#中DbParameterCollection类的典型用法代码示例。如果您正苦于以下问题:C# DbParameterCollection类的具体用法?C# DbParameterCollection怎么用?C# DbParameterCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DbParameterCollection类属于命名空间,在下文中一共展示了DbParameterCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteQuery
/// <summary>
/// Creates and executes query using the given ConnectionProvider.
/// </summary>
/// <param name="conn">Connection provider.</param>
/// <param name="cmdText">Command text.</param>
/// <param name="parameters">Command parameters.</param>
/// <param name="cmdType">Command type (stored procedure or text).</param>
/// <param name="cmdTimeout">Set timeout for specified command.</param>
/// <param name="dataTableName">Name of the datatable that will be returned. May be null.</param>
/// <returns>DataTable containing retrieved data.</returns>
public static DataTable ExecuteQuery(IConnectionProvider conn, string cmdText, DbParameterCollection parameters, CommandType cmdType, string dataTableName, int cmdTimeout)
{
IDbCommand cmd = CreateCommand(conn.DBMS, cmdText, parameters, cmdType, cmdTimeout);
cmd.Connection = conn.Connection;
IDataAdapterBuilder builder = DbmsComponentFactory.GetComponent<IDataAdapterBuilder>(conn.DBMS);
IDataAdapter adapter = builder.BuildAdapter(cmd);
bool connIsOpennedLocally = EnsureOpenConnection(conn);
try
{
AssignExistingPendingTransactionToCommand(conn, cmd);
// Execute query.
DataSet data = new DataSet();
data.Locale = CultureInfo.InvariantCulture;
adapter.Fill(data);
PopulateOutputParameterValues(parameters, cmd);
DataTable table = (data.Tables.Count > 0)
? data.Tables[0]
: new DataTable() { Locale = CultureInfo.InvariantCulture };
if (!string.IsNullOrEmpty(dataTableName))
table.TableName = dataTableName;
return table;
}
finally
{
CloseConnectionIfLocal(conn, connIsOpennedLocally);
cmd.Dispose();
IDisposable disposableAdapter = adapter as IDisposable;
if (disposableAdapter != null)
disposableAdapter.Dispose();
}
}
示例2: 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>Ouput parameter that will contain the value retrieved by RETURNING clause.</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);
}
IDbColumn autoIdField = GetAutoIdField(insert.Table);
DbParameter autoId = null;
if (autoIdField != null)
{
// RETURNING id
output.Append(" RETURNING ");
autoIdField.RenderColumnName(dbms, output);
autoId = new DbParameter("?", DbType.Int32) { Direction = ParameterDirection.Output };
parameters.Add(autoId);
}
// Return auto-id DB parameter. Callers require it to retrieve the new ID value.
return autoId;
}
示例3: RenderSingleQuery
private static void RenderSingleQuery(SelectStatement select, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
{
// Either TOP or ORDER BY is used; but not both.
// SELECT ... FROM ...
// WHERE (ROWNUM <= @top) AND (@this.filter)
// GROUP BY ... HAVING ... ORDER BY ...
AppendSelectAndDistinctKeyWords(select, output);
AppendSelectList(select, dbms, output, parameters);
AppendFromClause(select, dbms, output);
// WHERE. We have made sure that if TOP is used then ORDER BY is not used.
if (select.Top > 0)
{
// WHERE ROWNUM <= this.top AND (this.filter).
output.Append(" WHERE ROWNUM <= " + select.Top.ToString(CultureInfo.InvariantCulture));
if (select.Where != null && !select.Where.IsEmpty)
{
output.Append(" AND (");
select.Where.Render(dbms, output, parameters);
output.Append(")");
}
}
else
{
AppenWhereWoRownum(select, dbms, output, parameters);
}
AppendGroupByClause(select, dbms, output, parameters);
AppendHavingClause(select, dbms, output, parameters);
AppendOrderByClause(select, dbms, output, parameters);
}
示例4: RenderInsert
/// <summary>
/// Renders INSERT statement.
/// </summary>
/// <param name="insert">INSERT statement that is being rendered.</param>
/// <param name="nextSequence">Ignored. SQLite 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><b>null</b> because automatically generated ID must be fetched via SELECT after INSERT.</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);
}
// Auto ID must be fetched via SELECT after INSERT.
DbParameter autoId = null;
return autoId;
}
示例5: AppendSelectList
private static void AppendSelectList(SelectStatement select, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
{
// Select list.
if (select.SelectList != null && select.SelectList.Count > 0)
select.SelectList.Render(dbms, output, parameters);
else
output.Append("*");
}
示例6: AppendWhereClause
private static void AppendWhereClause(SelectStatement select, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
{
// WHERE.
if (select.Where != null && !select.Where.IsEmpty)
{
output.Append(" WHERE ");
select.Where.Render(dbms, output, parameters);
}
}
示例7: PopulateOutputParameterValues
private static void PopulateOutputParameterValues(DbParameterCollection parameters, IDbCommand cmd)
{
// Fetch output values.
for (int paramIdx = 0; paramIdx < parameters.Count; paramIdx++)
{
if (parameters[paramIdx].Direction != ParameterDirection.Input)
parameters[paramIdx].Value = ((IDataParameter)cmd.Parameters[paramIdx]).Value;
}
}
示例8: AppendHavingClause
private static void AppendHavingClause(SelectStatement select, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
{
// HAVING.
if (select.Having != null && !select.Having.IsEmpty)
{
output.Append(" HAVING ");
select.Having.Render(dbms, output, parameters);
}
}
示例9: AppendGroupByClause
private static void AppendGroupByClause(SelectStatement select, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
{
// GROUP BY.
if (select.GroupBy != null && select.GroupBy.Fields.Count > 0)
{
output.Append(" ");
select.GroupBy.Render(dbms, output, parameters);
}
}
示例10: AppendWhere
private static void AppendWhere(SearchCondition where, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
{
bool hasFilter = (where != null) && !where.IsEmpty;
if (hasFilter)
{
output.Append(" WHERE ");
where.Render(dbms, output, parameters);
}
}
示例11: Render
public void Render(SelectStatement select, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
{
// Uses ROWNUM instead of TOP. If ORDER BY is used then current SELECT statement is rendered
// using sub-queries. ROWNUM is used in outer query.
bool orderByIsUsed = (select.OrderBy != null && select.OrderBy.Count > 0);
if (select.Top > 0 && orderByIsUsed)
RenderOrderByInSubQueryAndRownumInOuterQuery(select, dbms, output, parameters);
else
RenderSingleQuery(select, dbms, output, parameters);
}
示例12: RenderUpdate
/// <summary>Renders UPDATE statement.</summary>
public void RenderUpdate(UpdateStatement update, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
{
if (update.UpdateList == null || update.UpdateList.Count == 0)
throw new InvalidOperationException(Messages.SqlUpdater_SetListIsEmpty);
output.Append("UPDATE ");
update.Table.RenderTableName(dbms, output);
AppendUpdateList(update.UpdateList, dbms, output, parameters);
AppendRelations(update, dbms, output);
AppendWhere(update.Where, dbms, output, parameters);
}
示例13: BuildCommand
public IDbCommand BuildCommand(string cmdText, DbParameterCollection parameters, CommandType cmdType, int cmdTimeout)
{
IDbCommand cmd = new OracleCommand();
cmd.CommandText = cmdText;
cmd.CommandType = cmdType;
cmd.CommandTimeout = cmdTimeout;
foreach (DbParameter par in parameters)
cmd.Parameters.Add(ConvertToNativeParameter(par, cmdType));
return cmd;
}
示例14: Render
/// <summary>
/// Renders DELETE statement.
/// </summary>
/// <param name="delete">DELETE statement to render.</param>
/// <param name="dbms">Target DBMS.</param>
/// <param name="output">StringBuilder to which SQL 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>
public void Render(DeleteStatement delete, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
{
output.Append("DELETE FROM ");
delete.FromTable.RenderTableName(dbms, output);
if (delete.Where != null && !delete.Where.IsEmpty)
{
output.Append(" WHERE ");
delete.Where.Render(dbms, output, parameters);
}
}
示例15: Render
/// <summary>
/// Renders predicate as SQL statement.
/// </summary>
/// <param name="dbms">Target DBMS.</param>
/// <param name="output">StringBuilder to which SQL 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>
public override void Render(DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
{
output.Append("(");
if (Negate)
output.Append("NOT EXISTS (");
else
output.Append("EXISTS (");
PredicateItems[0].Render(dbms, output, parameters);
output.Append("))");
}