[Server]
type
TDm_Server = class(TDSServerModule)
SQLConnection1: TSQLConnection;
private
{ Private declarations }
public
function greeting(values : String) :String;
function GetTime : TDateTime;
function UserInsert( sParams : TParams ) : Boolean;
{ Public declarations }
end;
var
Dm_Server: TDm_Server;
function TDm_Server.greeting(values: String): String;
begin
Result := values + '입니다!!';
end;
function TDSUserModule.UserInsert(sParams: TParams): Boolean;
const
SQL = 'INSERT INTO %s (%s) VALUES (%s)';
var
sFields, sFieldsParam : TStringBuilder;
mySqlquery : TSQLQuery;
i : Integer;
begin
Result := False;
sFields := TStringBuilder.Create;
sFieldsParam := TStringBuilder.Create;
for i := 0 to sParams.Count - 1 do
begin
sFields.Append(sParams[i].Name);
sFieldsParam.Append(':'+sParams[i].Name);
if i<sParams.Count-1 then
begin
sFields.Append(',');
sFieldsParam.Append(',');
end;
end;
mySqlquery := TSQLQuery.Create(nil);
mySqlquery.SQLConnection := DMServerContainer.PBMConnection;
mySqlquery.CommandText := Format(SQL,[TABLE_NAME, sFields.ToString, sFieldsParam.ToString]);
mySqlquery.Params := sParams;
try
mySqlquery.ExecSQL();
Result := True;
finally
sFields.Free;
sFieldsParam.Free;
mySqlquery.Free;
end;
end;
--------------------------------------------------------
[Client]
1.
function TDm_ServerClient.greeting(values: String): String;
begin
if FgreetingCommand = nil then
begin
FgreetingCommand := FDBXConnection.CreateCommand;
FgreetingCommand.CommandType := TDBXCommandTypes.DSServerMethod;
FgreetingCommand.Text := 'TDm_Server.greeting';
FgreetingCommand.Prepare;
end;
FgreetingCommand.Parameters[0].Value.SetWideString(values);
FgreetingCommand.ExecuteUpdate;
Result := FgreetingCommand.Parameters[1].Value.GetWideString;
end;
function TDm_ServerClient.UserInsert(sParams: TParams): Boolean;
begin
if FUserInsertCommand = nil then
begin
FUserInsertCommand := FDBXConnection.CreateCommand;
FUserInsertCommand.CommandType := TDBXCommandTypes.DSServerMethod;
FUserInsertCommand.Text := 'TDm_Server.UserInsert';
FUserInsertCommand.Prepare;
end;
FUserInsertCommand.Parameters[0].Value.SetDBXReader(TDBXParamsReader.Create(sParams,FInstanceOwner), True);
FUserInsertCommand.ExecuteUpdate;
Result := FUserInsertCommand.Parameters[1].Value.GetBoolean;
end;
2.
procedure TForm1.SpeedButton3Click(Sender: TObject);
var
Params : TParams;
UserClient : TUserClient;
begin
UserClient := TDm_ServerClient.Create(PBMDataModule.PBMConnection.DBXConnection, False);
params := TParams.Create();
try
params.CreateParam(ftString, 'N_SANO', ptInput).Value := Edit1.Text;
params.CreateParam(ftString, 'S_HANDP', ptInput).Value := Edit6.Text;
params.CreateParam(ftString, 'S_TELNO', ptInput).Value := Edit5.Text;
params.CreateParam(ftString, 'S_ERTELNO', ptInput).Value := Edit7.Text;
params.CreateParam(ftString, 'S_EMAIL', ptInput).Value := Edit8.Text;
params.CreateParam(ftString, 'S_ZIPNO', ptInput).Value := Edit9.Text;
params.CreateParam(ftString, 'S_ADDR1', ptInput).Value := Edit10.Text;
params.CreateParam(ftString, 'S_ADDR2', ptInput).Value := Edit11.Text;
params.CreateParam(ftString, 'S_REMK', ptInput).Value := Edit12.Text;
params.CreateParam(ftString, 'S_USERID', ptInput).Value := Edit13.Text;
params.CreateParam(ftString, 'S_PASS', ptInput).Value := Edit14.Text;
params.CreateParam(ftString, 'N_FSANO', ptInput).Value := 'admin';
params.CreateParam(ftDateTime, 'D_FDATE', ptInput).Value := now;
params.CreateParam(ftString, 'N_SSANO', ptInput).Value := 'admin';
params.CreateParam(ftDateTime, 'D_SDATE', ptInput).Value := now;
UserClient.UserInsert(Params);
finally
Params.Free;
UserClient.Free;
end;
end;
procedure TMain_Client.Button1Click(Sender: TObject);
var
demo : TUserClient;
begin
demo := TDm_ServerClient.Create(SQLConnection1.DBXConnection);
try
ShowMessage(demo.greeting('demo OK!!'));
finally
Demo.Free;
end;
end;
--------------------------------------------------------------------------------------------------------------
소스는 위와같습니다.
DataSnap를 이용하여 3tire를 구현하고있습니다
[CLient]에서 2번에서 이벤트가 발송하면 1번으로 그리고 서버쪽으로 가서 값을 리턴합니다.
근데 문제는 greeting함수는 정상적으로 작동을하는데 Insert하는부분에서 에러가납니다.
"Project PBMClient.exe raised exception class TDBXError with message 'Remote error: Unexpected metadata type'."
이런방법 저런방법으로해봐도안됩니다.
도움이 절실합니다.
부탁드립니다.
추은날 감기조심하십시오..