附加的有序参数,因为并非所有OLEDB提供程序都支持命名参数
本文关键字:参数 程序 支持 OLEDB 因为 | 更新日期: 2023-09-27 18:16:23
谁能解释一下下面的注释在下面的方法中是什么意思?
// Additional ordered parameters since not all OLEDB providers support named parameters
我不明白为什么附加参数包含相同的字段(SerialNumber)两次。
谢谢。
protected override void RecordActivation( ServerRequestContext context, ActivationLimit limit, ActivationProfile profile )
{
using( OleDbConnection conn = new OleDbConnection( ConnectionString ) )
{
conn.Open();
using( OleDbTransaction transaction = conn.BeginTransaction() )
{
using( OleDbCommand cmd = new OleDbCommand( String.Format(
@"IF EXISTS ( SELECT * FROM {0} WHERE SerialNumber = ? AND ReferenceId = ? )
UPDATE {0} SET ProfileHash = ?, DateActivated = ?, AllowNewMachine = 0 WHERE SerialNumber = ? AND ReferenceId = ?
ELSE
INSERT INTO {0} ( SerialNumber, DateActivated, ProfileHash, ReferenceId, AllowNewMachine ) VALUES ( ?, ?, ?, ?, 0 )", ActivationTableName ), conn, transaction ) )
{
cmd.Parameters.Add( new OleDbParameter( "SerialNumber", context.SerialNumber ) );
cmd.Parameters.Add( new OleDbParameter( "ReferenceId", profile.ReferenceId ) );
cmd.Parameters.Add( new OleDbParameter( "ProfileHash", profile.Hash ) );
cmd.Parameters.Add( new OleDbParameter( "DateActivated", DateTime.UtcNow ) );
// Additional ordered parameters since not all OLEDB providers support named parameters
cmd.Parameters.Add( new OleDbParameter( "SerialNumber", context.SerialNumber ) );
cmd.Parameters.Add( new OleDbParameter( "ReferenceId", profile.ReferenceId ) );
cmd.Parameters.Add( new OleDbParameter( "SerialNumber", context.SerialNumber ) );
cmd.Parameters.Add( new OleDbParameter( "DateActivated", DateTime.UtcNow ) );
cmd.Parameters.Add( new OleDbParameter( "ProfileHash", profile.Hash ) );
cmd.Parameters.Add( new OleDbParameter( "ReferenceId", profile.ReferenceId ) );
cmd.ExecuteNonQuery();
}
transaction.Commit();
}
}
}
re: 我不明白为什么附加参数包含相同的字段(SerialNumber)两次
因为它们在多个地方被使用。我在?s后面添加了#s,以帮助识别正在执行的语句中参数出现的位置:
@"IF EXISTS ( SELECT * FROM {0} WHERE
SerialNumber = ?1 AND ReferenceId = ?2 )
UPDATE {0} SET ProfileHash = ?3, DateActivated = ?4, AllowNewMachine = 0
WHERE SerialNumber = ?5 AND ReferenceId = ?6
ELSE
INSERT INTO {0} ( SerialNumber, DateActivated, ProfileHash, ReferenceId, AllowNewMachine )
VALUES ( ?7, ?8, ?9, ?a, 0 )", ActivationTableName ), conn, transaction ) )
{
cmd.Parameters.Add( new OleDbParameter( "SerialNumber", context.SerialNumber ) ); --1
cmd.Parameters.Add( new OleDbParameter( "ReferenceId", profile.ReferenceId ) ); --2
cmd.Parameters.Add( new OleDbParameter( "ProfileHash", profile.Hash ) );--3
cmd.Parameters.Add( new OleDbParameter( "DateActivated", DateTime.UtcNow ) ); --4
// Additional ordered parameters since not all OLEDB providers support named parameters
cmd.Parameters.Add( new OleDbParameter( "SerialNumber", context.SerialNumber ) ); --5
cmd.Parameters.Add( new OleDbParameter( "ReferenceId", profile.ReferenceId ) ); --6
cmd.Parameters.Add( new OleDbParameter( "SerialNumber", context.SerialNumber ) ); --7
cmd.Parameters.Add( new OleDbParameter( "DateActivated", DateTime.UtcNow ) ); --8
cmd.Parameters.Add( new OleDbParameter( "ProfileHash", profile.Hash ) ); --9
cmd.Parameters.Add( new OleDbParameter( "ReferenceId", profile.ReferenceId ) ); --a