本文整理汇总了C#中IDbCommand类的典型用法代码示例。如果您正苦于以下问题:C# IDbCommand类的具体用法?C# IDbCommand怎么用?C# IDbCommand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IDbCommand类属于命名空间,在下文中一共展示了IDbCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateRowUpdatedEvent
protected override RowUpdatedEventArgs CreateRowUpdatedEvent(DataRow dataRow, IDbCommand command,
StatementType statementType,
DataTableMapping tableMapping)
{
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "CreateRowUpdatedEvent");
return new NpgsqlRowUpdatedEventArgs(dataRow, command, statementType, tableMapping);
}
示例2: BuildCommand
public static void BuildCommand(IDbCommand cmd, string sql, params object[] parameters)
{
if (cmd == null) throw new ArgumentNullException("cmd");
if (String.IsNullOrEmpty(sql)) throw new ArgumentNullException("sql");
if (parameters == null)
{
parameters = new object[0];
}
cmd.CommandText = new Regex(" *[\r\n]+ *").Replace(sql, " ");
var parameterNames = FindUniqueParameters(sql);
if (parameterNames.Count != parameters.Length)
{
throw new MicrOrmException(String.Format("Parameter count mismatch. {0} in the SQL string, {1} supplied", parameterNames.Count, parameters.Length));
}
for (var i = 0; i < parameters.Length; i++)
{
if (!parameterNames.ContainsKey(i))
{
throw new MicrOrmException(String.Format("Parameter ordinal mismatch. Parameter with ordinal {0} is missing in the SQL string", i));
}
var dbParameter = cmd.CreateParameter();
dbParameter.ParameterName = parameterNames[i];
dbParameter.Value = parameters[i];
cmd.Parameters.Add(dbParameter);
}
}
示例3: AddParameter
public static void AddParameter(IDbCommand dbCommand, string nombre, object value)
{
IDbDataParameter dbDataParameter=dbCommand.CreateParameter ();
dbDataParameter.ParameterName = nombre;
dbDataParameter.Value = value;
dbCommand.Parameters.Add (dbDataParameter);
}
示例4: GetDataAdapter
public override System.Data.IDataAdapter GetDataAdapter(IDbCommand cmd)
{
SqlCommand sqlCmd = (SqlCommand)cmd;
SqlDataAdapter sqlAdpt = new SqlDataAdapter(sqlCmd);
return sqlAdpt;
}
示例5: Enlist
/// <summary>
/// Enlist the <see cref="IDbCommand"/> in the current <see cref="ITransaction"/>.
/// </summary>
/// <param name="command">The <see cref="IDbCommand"/> to enlist in this Transaction.</param>
/// <remarks>
/// <para>
/// This takes care of making sure the <see cref="IDbCommand"/>'s Transaction property
/// contains the correct <see cref="IDbTransaction"/> or <see langword="null" /> if there is no
/// Transaction for the ISession - ie <c>BeginTransaction()</c> not called.
/// </para>
/// <para>
/// This method may be called even when the transaction is disposed.
/// </para>
/// </remarks>
public void Enlist(IDbCommand command)
{
if (trans == null)
{
if (log.IsWarnEnabled)
{
if (command.Transaction != null)
{
log.Warn("set a nonnull IDbCommand.Transaction to null because the Session had no Transaction");
}
}
command.Transaction = null;
return;
}
else
{
if (log.IsWarnEnabled)
{
// got into here because the command was being initialized and had a null Transaction - probably
// don't need to be confused by that - just a normal part of initialization...
if (command.Transaction != null && command.Transaction != trans)
{
log.Warn("The IDbCommand had a different Transaction than the Session. This can occur when " +
"Disconnecting and Reconnecting Sessions because the PreparedCommand Cache is Session specific.");
}
}
log.Debug("Enlist Command");
command.Transaction = trans;
}
}
示例6: PrepareInsertCommand
private string PrepareInsertCommand(string sql, IDbCommand command, IEnumerable<Column> columns)
{
var parameterFactory = _adapter.ProviderHelper.GetCustomProvider<IDbParameterFactory>(_schemaProvider)
?? new GenericDbParameterFactory(command);
var columnLookup = columns.ToDictionary(c => c.QuotedName, c => c);
if (columnLookup.Count == 0) return PrepareCommand(sql, command);
int openParenIndex = sql.IndexOf('(');
int closeParenLength = sql.IndexOf(')') - openParenIndex;
var columnNameList = sql.Substring(openParenIndex, closeParenLength).Trim('(', ')').Split(',');
int index = 0;
var sqlBuilder = new StringBuilder();
foreach (var c in sql)
{
if (c == '?')
{
var column = columnLookup[columnNameList[index]];
var parameter = parameterFactory.CreateParameter(_schemaProvider.NameParameter("p" + index), column);
command.Parameters.Add(parameter);
sqlBuilder.Append(parameter.ParameterName);
index++;
}
else
{
sqlBuilder.Append(c);
}
}
return sqlBuilder.ToString();
}
示例7: DeriveParameters
/// <summary>
/// Populates the specified IDbCommand object's Parameters collection with
/// parameter information for the stored procedure specified in the IDbCommand.
/// </summary>
/// <remarks>
/// See the <see cref="DbManager.AddDataProvider(DataProviderBase)"/> method to find an example.
/// </remarks>
/// <seealso cref="DbManager.AddDataProvider(DataProviderBase)">AddDataManager Method</seealso>
/// <param name="command">The IDbCommand referencing the stored procedure for which the parameter information is to be derived. The derived parameters will be populated into the Parameters of this command.</param>
public override bool DeriveParameters(IDbCommand command)
{
// SQLiteCommandBuilder does not implement DeriveParameters.
// This is not surprising, since SQLite has no support for stored procs.
//
return false;
}
示例8: AttachParameter
public override void AttachParameter(IDbCommand command, IDbDataParameter parameter)
{
if (parameter.DbType == DbType.DateTime2)
parameter.DbType = DbType.DateTime;
base.AttachParameter(command, parameter);
}
示例9: Set
void SqlMapper.ICustomQueryParameter.AddParameter(IDbCommand command, string name)
{
var param = command.CreateParameter();
param.ParameterName = name;
Set(param, table, typeName);
command.Parameters.Add(param);
}
示例10: Set
public override void Set(IDbCommand cmd, object value, int index)
{
if (value is EnumStoredAsString && (EnumStoredAsString)value == EnumStoredAsString.Unspecified)
base.Set(cmd, null, index);
else
base.Set(cmd, value, index);
}
示例11: Initialize
public override void Initialize(IDatabaseEngine engine, IDbCommand command)
{
string innerParameterName = engine.GetParameterName(ParameterName);
sqlSnippet = sqlSnippet.Replace(REPLACEMENT_VALUE, innerParameterName);
_innerParameter = command.CreateParameter();
_innerParameter.ParameterName = innerParameterName;
}
示例12: Build
/// <summary>
/// Execute the command and take the first cell of each row to build an Enumerable of string
/// </summary>
/// <param name="cmd">A sql or mdx query to execute</param>
/// <returns>The first cell of row returned by the query</returns>
public virtual IEnumerable<string> Build(IDbCommand cmd)
{
var qe = new QueryEngineFactory().GetExecutor(cmd);
var ds = qe.Execute();
var list = Load(ds);
return list;
}
示例13: FormatSql
/// <summary>
/// Formats the SQL in a SQL-Server friendly way, with DECLARE statements for the parameters up top.
/// </summary>
public string FormatSql(string commandText, List<SqlTimingParameter> parameters, IDbCommand command = null)
{
StringBuilder buffer = new StringBuilder();
if (command != null && IncludeMetaData)
{
buffer.AppendLine("-- Command Type: " + command.CommandType);
buffer.AppendLine("-- Database: " + command.Connection.Database);
if (command.Transaction != null)
{
buffer.AppendLine("-- Command Transaction Iso Level: " + command.Transaction.IsolationLevel);
}
if (Transaction.Current != null)
{
// transactions issued by TransactionScope are not bound to the database command but exists globally
buffer.AppendLine("-- Transaction Scope Iso Level: " + Transaction.Current.IsolationLevel);
}
buffer.AppendLine();
}
string baseOutput = base.FormatSql(commandText, parameters, command);
buffer.Append(baseOutput);
return buffer.ToString();
}
示例14: ExecuteStartImpl
/// <summary>
/// Tracks when 'command' is started.
/// </summary>
/// <param name="command">The command.</param>
/// <param name="type">The type.</param>
public void ExecuteStartImpl(IDbCommand command, ExecuteType type)
{
var id = Tuple35.Create((object)command, type);
var sqlTiming = new SqlTiming(command, type, Profiler);
_inProgress[id] = sqlTiming;
}
示例15: IsXmlParameter
/// <summary>
/// Determines if a parameter is an XML type parameter.
/// </summary>
/// <param name="command">The related command object.</param>
/// <param name="parameter">The parameter to test.</param>
/// <returns>True if the parameter is an XML parameter.</returns>
public override bool IsXmlParameter(IDbCommand command, IDataParameter parameter)
{
if (parameter == null) throw new ArgumentNullException("parameter");
var op = (OracleParameter)parameter;
return op.OracleDbType == OracleDbType.XmlType;
}