/// some common definitions shared by both client and server side
unit ServerIntf;
interface
uses
SynCommons, mORMot;
type
TRemoteSQLEngine = (rseOleDB, rseODBC, rseOracle, rseSQlite3, rseJet, rseMSSQL, resMySQL);
IRemoteSQL = interface(IInvokable)
['{051C8EC8-921D-4248-88E8-489E3B869F50}']
function Execute(const aSQL: RawUTF8; aExpectResults, aExpanded: Boolean): RawJSON;
//执行多条语句
function MulExecute(const QSQL: TRawUTF8DynArray; aExpectResults: Boolean): Boolean;
end;
ICalculator = interface(IInvokable)
['{9A60C8ED-CEB2-4E09-87D4-4A16F496E5FE}']
function Add(a, b: integer): integer;
function GetQuery(vData :RawUTF8): RawUTF8;
end;
IQueryData = interface(IInvokable)
['{B1793EB7-764D-4B8E-8012-BA13D188493A}']
function GetQueryReslt(vData: RawUTF8): RawUTF8;
//function ExecSql(SqlStr: string): RawUTF8;
end;
const
ROOT_NAME = 'root';
PORT_NAME = '888';
APPLICATION_NAME = 'RestService';
implementation
initialization
// so that we could use directly ICalculator instead of TypeInfo(ICalculator)
TInterfaceFactory.RegisterInterfaces([TypeInfo(ICalculator)]);
TInterfaceFactory.RegisterInterfaces([TypeInfo(IQueryData)]);
TInterfaceFactory.RegisterInterfaces([TypeInfo(IRemoteSQL)]);
end.
unit ServerMethod;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, ServerIntf, Dialogs,
SynCommons, SynLog, mORMot, mORMotDB, mORMotHttpServer, SynDB,
SynDBZeos, DB;
type
TServiceCalculator = class(TInterfacedObject, ICalculator)
public
function Add(a, b: integer): integer;
function GetQuery(vData: RawUTF8): RawUTF8;
end;
TServiceQueryData = class(TInterfacedObject, IQueryData)
public