0

Delphi XE では、「DataSnap サーバー」ウィザードを使用してクライアント サーバー アプリケーションを作成します。

この「Select * from TABLE」のようなSQLプロパティServerMethodUnitを定義するTSQLQuery

私も呼び出される関数を定義します。ChangeSQL例によってServerMethodUnitsql プロパティを変更するものSELECT * from TABLE where ID = 5

ChangeSQLを介してフォームクライアントアプリケーションを呼び出すTSQLServerMethodと、関数のプロパティがChangeSQL変更されますが、関数を離れると、新しいSQLコマンドは含まれていませんが、元のSQLがあります。SQLServerMethodUnitChangeSQLTSQLQuery

EDIT:コードサンプルの追加

「DataSnap サーバー」ウィザードを使用して、新しいクライアント サーバー アプリケーションを作成します。

ServerMethodsUnit

TSQLConnection私は自分のデータベースに入れました。I put a TSQLQuerycall MyQuery, with SQLproperty = 'Select * from client' I put a TDataSetProvidertoTSQLQuery

そして、次のような関数を定義します。

function TServerMethods1.ClientFiltrer (ID:integer):integer;
begin

// ------------------------------------------------ // この時点で、MyQuery.RecordCount = すべてのレコード (初回と次の両方) // --------------------------- ----------------------

if MyQuery.Active then
   MyQuery.close;

MyQuery.SQL.Clear;
MyQuery.SQL.Add(' SELECT * from CLIENT where ID = '+StrToInt (ID));
MyQuery.Open;
result := MyQuery.RecordCount; 
// ------------------------------------------------ 
// At this point, MyQuery.RecordCount = ONE record
// ------------------------------------------------ 

end;

そして、「DataSnap クライアント」で新しいアプリケーションを作成します

ClientModuleUni: を配置しClientDataSetMyClientDSwithRemoteServerProviderName自分のMyQueryプロバイダーに呼び出します。を指すTSQLServerMethod呼び出しを入れましたMyMethodClientFilterServerMethodsUnit

クライアントアプリケーションのフォームに 次に、ADataSourceと aDBGridを入れMyClientDsて開きます。Tbutton私はコードを入れましたOnClick

begin
  MyClientDs .Close;
  MyMethod .ParamByName('ID').Value := 5;
  MyMethod .ExecuteMethod;
  showmessage (MyMethod .ParamByName('ID').AsString);
  // AT THIS POINT, returned value is ONE.
  // I supposed that this Query had been filtered on 
  // the server and the client then show the filtered 
  // data, but it always shows the original query

  MyClientDs .Close;
end;

DBGridThe I see all records of Client Table, ALWAYS .

ClientTableボタンをクリックしてフィルターをかけてみましたが、DBGrid常にすべてのレコードが表示されます。

4

2 に答える 2

2

問題はここにあります:

MyQuery.SQL.Clear;
MyQuery.SQL.Add(' SELECT * from CLIENT where ID = '+StrToInt (ID));
MyQuery.Open;
result := MyQuery.RecordCount; 
// ------------------------------------------------ 
// At this point, MyQuery.RecordCount = ONE record
// ------------------------------------------------ 

ID を割り当てるStrToInt(ID)と、パラメーターは作成されません。したがって、後で「ParamByName」を実行して変更する場合、変更するパラメータはありません。

上記の行を次のように変更します

MyQuery.SQL.Text := `SELECT * FROM client WHERE ID  = :ID`;
MyQuery.ParamByName('ID').AsInteger := ID;
MyQuery.Open;

これで問題は解決するはずです。

于 2011-09-06T13:44:13.160 に答える
0

DSServerClass1.LifeCycleでこれに対する答え。

それは「呼び出し」でした。「セッション」に変更しました。

「invocation」を使用してサーバーとの接続が継続的に切断され、デフォルトに戻ります。

「呼び出し」を操作する方法を知っている人はいますか?

于 2011-09-06T18:47:47.003 に答える