本文整理汇总了C#中IDbCommand.Prepare方法的典型用法代码示例。如果您正苦于以下问题:C# IDbCommand.Prepare方法的具体用法?C# IDbCommand.Prepare怎么用?C# IDbCommand.Prepare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbCommand
的用法示例。
在下文中一共展示了IDbCommand.Prepare方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DbPreparedCommand
public DbPreparedCommand([NotNull] IDbConnection connection, [CanBeNull] IDbTransaction transaction, [NotNull] string sql, [CanBeNull] object parameters)
{
_Command = connection.CreateCommand();
_Command.Transaction = transaction;
_Command.CommandText = sql;
_PropertiesAndParameters = CreateParameterMapping(_Command, parameters);
AssignParameters(parameters);
_Command.Prepare();
}
示例2: ExecuteReader
static IDataReader ExecuteReader(IDbCommand sql)
{
IDataReader result = null;
using (var db = CreateConnection())
{
db.Open();
sql.Connection = db;
sql.Prepare();
result = sql.ExecuteReader();
db.Close();
}
return result;
}
示例3: ExecuteNonQuery
static int ExecuteNonQuery(IDbCommand sql)
{
var result = -1;
using (var db = CreateConnection())
{
db.Open();
sql.Connection = db;
sql.Prepare();
sql.ExecuteNonQuery();
sql.CommandText = "SELECT last_insert_rowid()";
result = Int32.Parse(sql.ExecuteScalar().ToString());
db.Close();
}
return result;
}
示例4: Build
/// <summary>
/// Creates a database command object to execute
/// </summary>
/// <returns></returns>
public IDbCommand Build()
{
if (ConnectionIsActive())
throw new InvalidOperationException(string.Format("Database connection '{0}' is active; this state is invalid to execute the Build command", myConnectionString));
myConnection = NewConnection();
myConnection.ConnectionString = myConnectionString;
myConnection.Open();
myCommand = myConnection.CreateCommand();
myCommand.CommandType = CommandType.Text;
if (!string.IsNullOrEmpty(mySql))
myCommand.CommandText = mySql;
foreach (var param in Parameters)
myCommand.Parameters.Add(param.Value);
if (myServerPrepare)
myCommand.Prepare();
return myCommand;
}
示例5: ExecuteNonQuery
/// <summary>
///
/// </summary>
/// <param name="command"></param>
/// <returns></returns>
public bool ExecuteNonQuery(IDbCommand command)
{
bool returnValue = false;
if (command != null)
{
command.Prepare();
command.ExecuteNonQuery();
returnValue = true;
}
return returnValue;
}
示例6: PrepareCommand
public void PrepareCommand(IDbCommand command)
{
AdjustCommand(command);
OnBeforePrepare(command);
if (SupportsPreparingCommands && prepareSql)
{
command.Prepare();
}
}
示例7: PrepareCommand
public void PrepareCommand(IDbCommand command)
{
if (SupportsPreparingCommands && prepareSql)
{
command.Prepare();
}
}
示例8: Prepare
/// <summary>
/// Prepares the <see cref="IDbCommand"/> for execution in the database.
/// </summary>
/// <param name="command"></param>
/// <remarks>
/// This takes care of hooking the <see cref="IDbCommand"/> up to an <see cref="IDbConnection"/>
/// and <see cref="IDbTransaction"/> if one exists. It will call <c>Prepare</c> if the Driver
/// supports preparing commands.
/// </remarks>
private void Prepare( IDbCommand command )
{
try
{
Log( command );
if( command.Connection != null )
{
// make sure the commands connection is the same as the Sessions connection
// these can be different when the session is disconnected and then reconnected
if( command.Connection != session.Connection )
{
command.Connection = session.Connection;
}
}
else
{
command.Connection = session.Connection;
}
if( session.Transaction != null )
{
session.Transaction.Enlist( command );
}
if( factory.PrepareSql && factory.ConnectionProvider.Driver.SupportsPreparingCommands )
{
command.Prepare();
}
}
catch( InvalidOperationException ioe )
{
throw new ADOException(
"While preparing " + command.CommandText + " an error occurred"
, ioe );
}
}
示例9: InitializeConnection
void InitializeConnection()
{
if (cnc == null)
CreateNewConnection();
cnc.Open ();
selectCommand = cnc.CreateCommand ();
selectCommand.CommandText = selectCommandText;
selectCommand.Parameters.Add (CreateParam (selectCommand, DbType.String, "SessionID", String.Empty));
selectCommand.Parameters.Add (CreateParam (selectCommand, DbType.DateTime, "Expires", DateTime.MinValue ));
selectCommand.Parameters.Add (CreateParam (selectCommand, DbType.String, "AppPath", String.Empty));
selectCommand.Prepare ();
insertCommand = cnc.CreateCommand ();
insertCommand.CommandText = insertCommandText;
insertCommand.Parameters.Add (CreateParam (insertCommand, DbType.String, "SessionID", String.Empty));
insertCommand.Parameters.Add (CreateParam (insertCommand, DbType.String, "AppPath", String.Empty));
insertCommand.Parameters.Add (CreateParam (insertCommand, DbType.DateTime, "Created", DateTime.MinValue));
insertCommand.Parameters.Add (CreateParam (insertCommand, DbType.DateTime, "Expires", DateTime.MinValue));
insertCommand.Parameters.Add (CreateParam (insertCommand, DbType.Int32, "Timeout", 0));
insertCommand.Parameters.Add (CreateParam (insertCommand, DbType.Binary, "StaticObjectsData",new byte[0] ));
insertCommand.Parameters.Add (CreateParam (insertCommand, DbType.Binary, "SessionData",
new byte[0]));
insertCommand.Prepare();
updateCommand = cnc.CreateCommand ();
updateCommand.CommandText = updateCommandText;
updateCommand.Parameters.Add (CreateParam (updateCommand, DbType.String, "SessionID", String.Empty));
updateCommand.Parameters.Add (CreateParam (updateCommand, DbType.DateTime, "Expires", DateTime.MinValue));
updateCommand.Parameters.Add (CreateParam (updateCommand, DbType.Int32, "Timeout", 0));
updateCommand.Parameters.Add (CreateParam (updateCommand, DbType.Binary, "SessionData",
new byte[0]));
updateCommand.Prepare();
deleteCommand = cnc.CreateCommand ();
deleteCommand.CommandText = deleteCommandText;
deleteCommand.Parameters.Add (CreateParam (deleteCommand, DbType.String, "SessionID", String.Empty));
deleteCommand.Prepare();
}
示例10: ExecuteNonQuery
/// <summary>
/// Returns True if command executed successfully else false
/// </summary>
/// <param name="command">SqlCommand object</param>
/// <returns>True/False</returns>
public bool ExecuteNonQuery(IDbCommand command)
{
command.Prepare();
command.ExecuteNonQuery();
return true;
}