わかりました、これは巻き毛です。私が書いていない Delphi コードに取り組んでいるのですが、非常に奇妙な問題に遭遇しています。ストアド プロシージャのパラメーターの 1 つが、null
確実に送信されているにもかかわらず、として送信されてい1
ます。
Delphi コードは、TADOQuery を使用してストアド プロシージャを実行します(匿名化)。
ADOQuery1.SQL.Text := "exec MyStoredProcedure :Foo,:Bar,:Baz,:Qux,:Smang,:Jimmy";
ADOQuery1.Parameters.ParamByName("Foo").Value := Integer(someFunction());
// other parameters all set similarly
ADOQuery1.ExecSQL;
Integer(SomeFunction())
現在、常に 1 を返します - デバッガーで確認しました。
ただし、ストアド プロシージャ (デバッグ目的で変更) では:
create procedure MyStoredProcedure (
@Foo int, @Bar int, @Baz int,
@Qux int, @Smang int, @Jimmy varchar(20)
) as begin
-- temp debug
if ( @Foo is null ) begin
insert into TempLog values ( "oh crap" )
end
-- do the rest of the stuff here..
end
TempLog
確かに「ああ、がらくた」で終わります(副次的な質問:ストアドプロシージャをデバッグするより良い方法があるに違いありません:それは何ですか?)。
プロファイラーからのトレースの例を次に示します。
exec [MYDB]..sp_procedure_params_rowset N'MyStoredProcedure',1,NULL,NULL
declare @p3 int
set @p3=NULL
exec sp_executesql
N'exec MyStoredProcedure @P1,@P2,@P3,@P4,@P5,@P6',
N'@P1 int OUTPUT,@P2 int,@P3 int,@P4 int,@P5 int,@P6 int',
@p3 output,1,1,1,0,200
select @p3
これは私には少し奇妙に見えます。@p3と@P3 を使用していることに注意してください。これが問題の原因になっている可能性はありますか?
もう 1 つの奇妙な点は、使用する TADOConnection に依存しているように見えることです。
プロジェクトは、別のアプリケーションから TADOConnection を渡される dll です。この接続を使用して、すべてのストアド プロシージャを呼び出します。
この接続を使用する代わりに、最初にこれを行います。
ConnectionNew := TADOQuery.Create(ConnectionOld.Owner);
ConnectionNew.ConnectionString := ConnectionOld.ConnectionString;
TADOQuery1.Connection := ConnectionNew;
その後、問題は発生しません!この状況からのトレースは次のとおりです。
exec [MYDB]..sp_procedure_params_rowset N'MyStoredProcedure',1,NULL,NULL
declare @p1 int
set @p1=64
exec sp_prepare @p1 output,
N'@P1 int,@P2 int,@P3 int,@P4 int,@P5 int,@P6 varchar(20)',
N'exec MyStoredProcedure @P1,@P2,@P3,@P4,@P5,@P6',
1
select @p1
SET FMTONLY ON exec sp_execute 64,0,0,0,0,0,' ' SET FMTONLY OFF
exec sp_unprepare 64
SET NO_BROWSETABLE OFF
exec sp_executesql
N'exec MyStoredProcedure @P1,@P2,@P3,@P4,@P5,@P6',
N'@P1 int,@P2 int,@P3 int,@P4 int,@P5 int,@P6 varchar(20)',
1,1,1,3,0,'400.00'
残念ながら、これは私が従うには少し多すぎます。これに影響を与える可能性のある TADOConnection オプションの種類は何ですか?
誰にもアイデアはありますか?
編集: 以下の更新(この質問をもう作りたくありませんでした:P)