本文整理汇总了C#中DBConnection.ExecuteReaderCommand方法的典型用法代码示例。如果您正苦于以下问题:C# DBConnection.ExecuteReaderCommand方法的具体用法?C# DBConnection.ExecuteReaderCommand怎么用?C# DBConnection.ExecuteReaderCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBConnection
的用法示例。
在下文中一共展示了DBConnection.ExecuteReaderCommand方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <summary>
/// Executes this command using the specified database connection to get a data reader and then executes the specified method with the reader.
/// </summary>
public void Execute( DBConnection cn, Action<DbDataReader> readerMethod )
{
var command = cn.DatabaseInfo.CreateCommand();
command.CommandText =
"SELECT{0} {1} ".FormatWith(
cacheQueryInDatabase && cn.DatabaseInfo.QueryCacheHint.Any() ? " {0}".FormatWith( cn.DatabaseInfo.QueryCacheHint ) : "",
StringTools.ConcatenateWithDelimiter( ", ", selectExpressions.ToArray() ) ) + fromClause;
if( conditions.Any() ) {
command.CommandText += " WHERE ";
var first = true;
var paramNumber = 0;
foreach( var condition in conditions ) {
if( !first )
command.CommandText += " AND ";
first = false;
condition.AddToCommand( command, cn.DatabaseInfo, InlineUpdate.GetParamNameFromNumber( paramNumber++ ) );
}
}
command.CommandText = command.CommandText.ConcatenateWithSpace( orderByClause );
cn.ExecuteReaderCommand( command, readerMethod );
}
示例2: Generate
internal static void Generate( DBConnection cn, TextWriter writer, string baseNamespace, Database database )
{
writer.WriteLine( "namespace " + baseNamespace + "." + database.SecondaryDatabaseName + "Sequences {" );
var cmd = cn.DatabaseInfo.CreateCommand();
cmd.CommandText = "SELECT * FROM USER_SEQUENCES";
cn.ExecuteReaderCommand( cmd,
reader => {
while( reader.Read() ) {
var sequenceName = reader[ "SEQUENCE_NAME" ].ToString();
writer.WriteLine();
writer.WriteLine( "public class " + sequenceName + " {" );
writer.WriteLine( "public static decimal GetNextValue() {" );
writer.WriteLine( "DbCommand cmd = " + DataAccessStatics.GetConnectionExpression( database ) + ".DatabaseInfo.CreateCommand();" );
writer.WriteLine( "cmd.CommandText = \"SELECT " + sequenceName + ".NEXTVAL FROM DUAL\";" );
writer.WriteLine( "return (decimal)" + DataAccessStatics.GetConnectionExpression( database ) + ".ExecuteScalarCommand( cmd );" );
writer.WriteLine( "}" );
writer.WriteLine( "}" );
}
} );
writer.WriteLine();
writer.WriteLine( "}" );
}
示例3: deleteAndReCreateUser
private void deleteAndReCreateUser( DBConnection cn )
{
// Delete the existing user and schema.
deleteUser( cn );
// Re-create the user with the minimally required privileges.
executeLongRunningCommand( cn, "CREATE USER " + info.UserAndSchema + " IDENTIFIED BY " + info.Password + " ACCOUNT UNLOCK" );
// This allows the user to connect to the database.
executeLongRunningCommand( cn, "GRANT CREATE SESSION TO " + info.UserAndSchema );
// This overrides all tablespace quotas for this user, which default to 0 and therefore prevent the user from creating any tables or other objects.
executeLongRunningCommand( cn, "GRANT UNLIMITED TABLESPACE TO " + info.UserAndSchema );
executeLongRunningCommand( cn, "GRANT CREATE PROCEDURE TO " + info.UserAndSchema ); // Necessary for RLE Personnel secondary databases.
executeLongRunningCommand( cn, "GRANT CREATE SEQUENCE TO " + info.UserAndSchema );
executeLongRunningCommand( cn, "GRANT CREATE TABLE TO " + info.UserAndSchema );
executeLongRunningCommand( cn, "GRANT CREATE TRIGGER TO " + info.UserAndSchema ); // Necessary for RLE Personnel secondary databases.
executeLongRunningCommand( cn, "GRANT READ, WRITE ON DIRECTORY " + dataPumpOracleDirectoryName + " TO " + info.UserAndSchema );
// Get all tablespaces currently in the database.
var command = cn.DatabaseInfo.CreateCommand();
command.CommandText = "SELECT tablespace_name FROM dba_tablespaces";
var currentTableSpaces = new List<string>();
cn.ExecuteReaderCommand(
command,
reader => {
while( reader.Read() )
currentTableSpaces.Add( reader.GetString( 0 ).ToLower() );
} );
// Create necessary tablespaces that don't already exist.
foreach( var nonExistentTs in latestTableSpaces.Select( s => s.ToLower() ).Except( currentTableSpaces ) ) {
var tableSpaceFolderPath = EwlStatics.CombinePaths( ConfigurationStatics.RedStaplerFolderPath, "Oracle Tablespaces" );
Directory.CreateDirectory( tableSpaceFolderPath );
executeLongRunningCommand(
cn,
"CREATE TABLESPACE " + nonExistentTs + " DATAFILE '" + EwlStatics.CombinePaths( tableSpaceFolderPath, nonExistentTs + ".dbf" ) + "' SIZE 100M" );
}
}
示例4: ExecuteReader
/// <summary>
/// Executes this procedure against the specified database connection to get a data reader and then executes the specified method with the reader.
/// </summary>
public void ExecuteReader( DBConnection cn, Action<DbDataReader> readerMethod )
{
var cmd = cn.DatabaseInfo.CreateCommand();
setupDbCommand( cmd, cn.DatabaseInfo );
cn.ExecuteReaderCommand( cmd, readerMethod );
}