tvplanit: Add VpRESTserverDaemon and VpRESTserverRegister to mORMot example. Extend mORMot demo to connect to AWS (Amazon web service) server. (These are additions by DonAlfredo).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5126 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-09-03 15:09:35 +00:00
parent ab1d9ee4dc
commit ace4b5ee45
13 changed files with 522 additions and 26 deletions

View File

@ -26,6 +26,7 @@
<RunParams> <RunParams>
<local> <local>
<FormatVersion Value="1"/> <FormatVersion Value="1"/>
<LaunchingApplication PathPlusParams="localhost"/>
</local> </local>
</RunParams> </RunParams>
<RequiredPackages Count="3"> <RequiredPackages Count="3">

View File

@ -9,17 +9,19 @@ uses
type type
{ TDemoDM } { TDemoDM }
TDemoDM = class(TDataModule) TDemoDM = class(TDataModule)
Timer1: TTimer; Timer1: TTimer;
procedure Timer1Timer(Sender: TObject); procedure Timer1Timer(Sender: TObject);
private private
FNoServer: Boolean; FHostIP: String;
procedure ReadCmdLine; procedure ReadCmdLine;
public public
Datastore: TVpmORMotDatastore; Datastore: TVpmORMotDatastore;
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy;
end; end;
var var
@ -29,6 +31,11 @@ implementation
{$R *.lfm} {$R *.lfm}
const
// IP address of AWS (amazon web service) tvplanit demoserver
AWS_HOST_IP = '54.194.211.233';
constructor TDemoDM.Create(AOwner: TComponent); constructor TDemoDM.Create(AOwner: TComponent);
begin begin
inherited; inherited;
@ -39,12 +46,14 @@ begin
with Datastore do with Datastore do
begin begin
// if the HostIP is set, it will look for a running server on this IP address when connecting.
// leave blank (comment out) for a local (and private) database
if FNoServer then // if the HostIP is set, it will look for a running server on this IP
HostIP := '' else // address when connecting.
HostIP := 'localhost'; // leave blank (comment out) for a local (and private) database
HostIP := FHostIP;
HostPort := '8888';
EnableLogging := True;
Directory := 'data'; Directory := 'data';
Connected := true; Connected := true;
@ -58,18 +67,29 @@ begin
Timer1.Enabled := true; Timer1.Enabled := true;
end; end;
destructor TDemoDM.Destroy;
begin
Timer1.Enabled := false;
inherited;
end;
{ Use to commandline to switch between different servers.
- noserver --> don't use server, for a local (and private) database)
- localhost --> use server on local system
- (empty) --> use AWS (amazon web service) tvplanit demo server
- else --> specify ip address of server }
procedure TDemoDM.ReadCmdLine; procedure TDemoDM.ReadCmdLine;
var var
s: String; s: String;
i: Integer; i: Integer;
begin begin
FHostIP := AWS_HOST_IP;
for i:=1 to ParamCount do begin for i:=1 to ParamCount do begin
s := lowercase(ParamStr(i)); s := lowercase(ParamStr(i));
if (s[1] = '-') or (s[1] = '/') then begin if s = 'noserver' then
Delete(s, 1, 1); FHostIP := ''
if s = 'noserver' then else
FNoServer := true; FHostIP := s;
end;
end; end;
end; end;

View File

@ -80,7 +80,6 @@
</Target> </Target>
<SearchPaths> <SearchPaths>
<IncludeFiles Value="$(ProjOutDir);..\mormot\mORMotSourceHere;..\..\source"/> <IncludeFiles Value="$(ProjOutDir);..\mormot\mORMotSourceHere;..\..\source"/>
<Libraries Value="..\mormot\mORMotSourceHere\fpc-win32"/>
<OtherUnitFiles Value="..\mormot;..\mormot\mORMotSourceHere;..\mormot\mORMotSourceHere\SQLite3"/> <OtherUnitFiles Value="..\mormot;..\mormot\mORMotSourceHere;..\mormot\mORMotSourceHere\SQLite3"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths> </SearchPaths>

View File

@ -1,7 +1,16 @@
program mormotdemo; program mormotdemo;
{ IMPORTANT NOTE:
If compilation aborts with an error that libkernel32a, libgcc.a and libmsvcrt.a
cannot be found then do a rebuild ("Run" / "Build"). Or add the corresponding
folder to the library path of the project, the obj files are in folder
mORMotSourceHere/fpc-win32, etc. }
{ commandline parameters: { commandline parameters:
-noserver ---> run without server, otherwise HostIP is localhost } - noserver ---> run without server
- localhost ---> server ip is localhost
- empty ---> server is tvplanit demo server on Amazon Web Services
- xxx.xxx.xxx.xxx ---> ip address for server connection. }
{$mode objfpc}{$H+} {$mode objfpc}{$H+}

View File

@ -4,7 +4,7 @@ interface
{$I Synopse.inc} {$I Synopse.inc}
{.$define USEWRAPPERS} {$define USEWRAPPERS}
uses uses
SysUtils, SysUtils,
@ -72,7 +72,7 @@ begin
// define the log level // define the log level
with TSQLLog.Family do begin with TSQLLog.Family do begin
Level := LOG_VERBOSE; // LOG_STACKTRACE; Level := LOG_VERBOSE; // LOG_STACKTRACE;
DestinationPath := fRootFolder+'..\log\'; DestinationPath := fRootFolder+'..'+DirectorySeparator+'log'+DirectorySeparator;
if not FileExists(DestinationPath) then if not FileExists(DestinationPath) then
CreateDir(DestinationPath); CreateDir(DestinationPath);
PerThreadLog := ptIdentifiedInOnFile; PerThreadLog := ptIdentifiedInOnFile;

View File

@ -25,7 +25,7 @@
<VersionInfo> <VersionInfo>
<StringTable ProductVersion=""/> <StringTable ProductVersion=""/>
</VersionInfo> </VersionInfo>
<BuildModes Count="2"> <BuildModes Count="3">
<Item1 Name="Default" Default="True"/> <Item1 Name="Default" Default="True"/>
<Item2 Name="LinuxARM"> <Item2 Name="LinuxARM">
<CompilerOptions> <CompilerOptions>
@ -45,6 +45,24 @@
</CodeGeneration> </CodeGeneration>
</CompilerOptions> </CompilerOptions>
</Item2> </Item2>
<Item3 Name="Linuxx64">
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="VpRESTserver"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);mORMotSourceHere"/>
<OtherUnitFiles Value="mORMotSourceHere;mORMotSourceHere\SQLite3"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<CodeGeneration>
<TargetCPU Value="x86_64"/>
<TargetOS Value="linux"/>
</CodeGeneration>
</CompilerOptions>
</Item3>
</BuildModes> </BuildModes>
<PublishOptions> <PublishOptions>
<Version Value="2"/> <Version Value="2"/>

View File

@ -5,11 +5,18 @@ program VpRESTserver;
{$APPTYPE CONSOLE} {$APPTYPE CONSOLE}
{$endif} {$endif}
{$ifdef Linux}
{$ifdef FPC_CROSSCOMPILING}
{$linklib libc_nonshared.a}
{$endif}
{$endif}
{$I Synopse.inc} // define HASINLINE WITHLOG USETHREADPOOL ONLYUSEHTTPSOCKET {$I Synopse.inc} // define HASINLINE WITHLOG USETHREADPOOL ONLYUSEHTTPSOCKET
// first line after uses clause should be {$I SynDprUses.inc} for FastMM4 // first line after uses clause should be {$I SynDprUses.inc} for FastMM4
uses uses
{$I SynDprUses.inc} {$I SynDprUses.inc} // <--- has cthreads if needed
Classes, Classes,
SysUtils, SysUtils,
SynCommons, SynCommons,
@ -33,7 +40,7 @@ begin
try try
sleep(300); // let the HTTP server start (for the console log refresh) sleep(300); // let the HTTP server start (for the console log refresh)
writeln(#13#10'Background server is running at http://localhost:'+HTTP_PORT+#13#10+ writeln(#13#10'Background server is running at http://localhost:'+HTTP_PORT+#13#10+
// #13#10'Wrappers at http://localhost:'+HTTP_PORT+'/root/wrapper'+#13#10+ #13#10'Wrappers at http://localhost:'+HTTP_PORT+'/root/wrapper'+#13#10+
#13#10'Press [Enter] to close the server.'); #13#10'Press [Enter] to close the server.');
readln; readln;
finally finally

View File

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasUsesSectionForAllUnits Value="False"/>
<MainUnitHasCreateFormStatements Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="VpRESTserverDaemon"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
<Resources Count="6">
<Resource_0 FileName="mORMotSourceHere\CrossPlatform\templates\API.adoc.mustache" Type="RCDATA" ResourceName="API.ADOC"/>
<Resource_1 FileName="mORMotSourceHere\CrossPlatform\templates\CrossPlatform.pas.mustache" Type="RCDATA" ResourceName="CROSSPLATFORM.PAS"/>
<Resource_2 FileName="mORMotSourceHere\CrossPlatform\templates\Delphi.pas.mustache" Type="RCDATA" ResourceName="DELPHI.PAS"/>
<Resource_3 FileName="mORMotSourceHere\CrossPlatform\templates\FPC-mORMotInterfaces.pas.mustache" Type="RCDATA" ResourceName="FPC-MORMOTINTERFACES.PAS"/>
<Resource_4 FileName="mORMotSourceHere\CrossPlatform\templates\FPCServer-mORMotServer.pas.mustache" Type="RCDATA" ResourceName="FPCSERVER-MORMOTSERVER.PAS"/>
<Resource_5 FileName="mORMotSourceHere\CrossPlatform\templates\SmartMobileStudio.pas.mustache" Type="RCDATA" ResourceName="SMARTMOBILESTUDIO.PAS"/>
</Resources>
</General>
<i18n>
<EnableI18N LFM="False"/>
</i18n>
<VersionInfo>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
</RunParams>
<Units Count="3">
<Unit0>
<Filename Value="VpRESTserverDaemon.dpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
<Unit1>
<Filename Value="RESTData.pas"/>
<IsPartOfProject Value="True"/>
</Unit1>
<Unit2>
<Filename Value="RESTServerClass.pas"/>
<IsPartOfProject Value="True"/>
</Unit2>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="VpRESTserverDaemon"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);mORMotSourceHere"/>
<OtherUnitFiles Value="mORMotSourceHere;mORMotSourceHere\SQLite3"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
<SyntaxOptions>
<SyntaxMode Value="Delphi"/>
</SyntaxOptions>
</Parsing>
<Linking>
<Debugging>
<GenerateDebugInfo Value="False"/>
</Debugging>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
<Other>
<CustomOptions Value="-Cg-"/>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,139 @@
program VpRESTserverDaemon;
{$ifdef Linux}
{$ifdef FPC_CROSSCOMPILING}
{$linklib libc_nonshared.a}
{$endif}
{$endif}
{$I Synopse.inc} // define HASINLINE WITHLOG USETHREADPOOL ONLYUSEHTTPSOCKET
uses
{$I SynDprUses.inc} // <--- has cthreads if needed
Classes,
SysUtils,
SynLog,
mORMotHTTPServer,
daemonapp;
Type
TTestDaemon = Class(TCustomDaemon)
Private
fVpServer: TVpServer;
fHTTPServer: TSQLHttpServer;
public
Function Start : Boolean; override;
Function Stop : Boolean; override;
Function Pause : Boolean; override;
Function Continue : Boolean; override;
Function Execute : Boolean; override;
Function ShutDown : Boolean; override;
Function Install : Boolean; override;
Function UnInstall: boolean; override;
end;
{ TTestThread }
Procedure AWriteln(MSg : String; B : Boolean);
begin
Application.Log(etcustom,Msg+BoolToStr(B));
end;
{ TTestDaemon }
function TTestDaemon.Start: Boolean;
begin
Result:=inherited Start;
AWriteln('Daemon Start',Result);
AWriteln('Dir: '+GetAppConfigDir(False)+'data',True);
if not DirectoryExists(GetAppConfigDir(False))
then CreateDir(GetAppConfigDir(False));
fVpServer := TVpServer.Create(GetAppConfigDir(False)+'data','root');
fHTTPServer := TSQLHttpServer.Create(HTTP_PORT,fVpServer{$ifndef ONLYUSEHTTPSOCKET},'+',useHttpApiRegisteringURI{$endif});
fHTTPServer.AccessControlAllowOrigin := '*'; // allow cross-site AJAX queries
end;
function TTestDaemon.Stop: Boolean;
begin
Result:=inherited Stop;
AWriteln('Daemon Stop: ',Result);
FreeAndNil(fHTTPServer);
FreeAndNil(fVpServer);
end;
function TTestDaemon.Pause: Boolean;
begin
Result:=inherited Pause;
AWriteln('Daemon pause: ',Result);
end;
function TTestDaemon.Continue: Boolean;
begin
Result:=inherited Continue;
AWriteln('Daemon continue: ',Result);
end;
function TTestDaemon.Execute: Boolean;
begin
Result:=inherited Execute;
AWriteln('Daemon execute: ',Result);
end;
function TTestDaemon.ShutDown: Boolean;
begin
Result:=inherited ShutDown;
AWriteln('Daemon Shutdown: ',Result);
try
try
FreeAndNil(fHTTPServer);
except
end;
finally
FreeAndNil(fVpServer);
end;
end;
function TTestDaemon.Install: Boolean;
begin
Result:=inherited Install;
AWriteln('Daemon Install: ',Result);
end;
function TTestDaemon.UnInstall: boolean;
begin
Result:=inherited UnInstall;
AWriteln('Daemon UnInstall: ',Result);
end;
Type
{ TTestDaemonMapper }
TTestDaemonMapper = Class(TCustomDaemonMapper)
Constructor Create(AOwner : TComponent); override;
end;
{ TTestDaemonMapper }
constructor TTestDaemonMapper.Create(AOwner: TComponent);
Var
D : TDaemonDef;
begin
inherited Create(AOwner);
D:=DaemonDefs.Add as TDaemonDef;
D.DisplayName:='Test daemon';
D.Name:='TestDaemon';
D.DaemonClassName:='TTestDaemon';
//D.WinBindings.ServiceType:=stWin32;
end;
{$R *.res}
begin
RegisterDaemonClass(TTestDaemon);
RegisterDaemonMapper(TTestDaemonMapper);
Application.Run;
end.

View File

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<UseDefaultCompilerOptions Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="VpRESTserverRegister"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<VersionInfo>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
</RunParams>
<Units Count="1">
<Unit0>
<Filename Value="VpRESTserverRegister.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="VpRESTserverRegister"/>
</Target>
<SearchPaths>
<IncludeFiles Value="mORMotSourceHere;$(ProjOutDir)"/>
<OtherUnitFiles Value="mORMotSourceHere;mORMotSourceHere\SQLite3"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,37 @@
{ in order to be able to use http.sys server for VpRESTserver.exe
under Vista or Seven, call first this program with Administrator rights
- you can unregister it later with command line parameter /delete }
program VpRESTserverRegister;
{$APPTYPE CONSOLE}
uses
{$I SynDprUses.inc} // use FastMM4 on older Delphi, or set FPC threads
SynCrtSock,
SysUtils;
const
REGSTR: array[boolean] of string = (
'Registration', 'Deletion');
{$R mORMotSourceHere\VistaAdm.res} // force elevation to Administrator under Vista/Seven
var delete: boolean;
procedure Call(const Root: SockString);
begin
writeln(REGSTR[delete],' of http://+:888/',root,'/ for http.sys');
writeln(THttpApiServer.AddUrlAuthorize(root,'888',false,'+',delete));
end;
begin
// test if we have to un-register the url
delete := (ParamCount=1) and SameText(ParamStr(1),'/DELETE');
// perform url (un)registration for http.sys
// (e.g. to be run as administrator under Windows Vista/Seven)
Call('root'); // for the TSQLModel as defined in RESTData.pas
// we're done
WriteLn('Done - Press ENTER to Exit');
ReadLn;
end.

View File

@ -28,6 +28,8 @@
{$I Vp.INC} {$I Vp.INC}
{$I Synopse.inc}
unit VpmORMotDS; unit VpmORMotDS;
interface interface
@ -60,6 +62,7 @@ type
FDatabase : TSQLRest; FDatabase : TSQLRest;
FModel : TSQLModel; FModel : TSQLModel;
FHostIP : string; FHostIP : string;
FHostPort : string;
FDirectory : string; FDirectory : string;
aSQLResourceTable : TSQLTable; aSQLResourceTable : TSQLTable;
@ -67,6 +70,8 @@ type
aSQLContactTable : TSQLTable; aSQLContactTable : TSQLTable;
aSQLTaskTable : TSQLTable; aSQLTaskTable : TSQLTable;
FEnableLogging : boolean;
procedure RefreshTable(aTable:TDataset); procedure RefreshTable(aTable:TDataset);
{ property getters } { property getters }
@ -79,6 +84,7 @@ type
{ property setters } { property setters }
procedure SetConnected(const Value: boolean); override; procedure SetConnected(const Value: boolean); override;
procedure SetHostIP(const Value: string); procedure SetHostIP(const Value: string);
procedure SetHostPort(const Value: string);
procedure SetDirectory(const Value: string); procedure SetDirectory(const Value: string);
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
@ -102,7 +108,9 @@ type
procedure PurgeTasks(Res: TVpResource); override; procedure PurgeTasks(Res: TVpResource); override;
property HostIP: string read FHostIP write SetHostIP; property HostIP: string read FHostIP write SetHostIP;
property HostPort: string read FHostPort write SetHostPort;
property Directory: string read FDirectory write SetDirectory; property Directory: string read FDirectory write SetDirectory;
property EnableLogging: boolean read FEnableLogging write FEnableLogging;
property CheckUpdate:boolean read CheckServer; property CheckUpdate:boolean read CheckServer;
end; end;
@ -116,6 +124,9 @@ uses
TypInfo, TypInfo,
{$endif} {$endif}
Variants, Variants,
{$ifdef WITHLOG}
SynLog,
{$endif}
SynSQLite3, SynSQLite3,
RESTdata; RESTdata;
@ -197,7 +208,9 @@ constructor TVpmORMotDataStore.Create(AOwner: TComponent);
begin begin
inherited; inherited;
FHostIP := ''; FHostIP := '';
FHostPort := HTTP_PORT;
FModel := DataModel; FModel := DataModel;
FEnableLogging := False;
end; end;
{=====} {=====}
@ -758,6 +771,7 @@ var
aFieldType : TSQLFieldType; aFieldType : TSQLFieldType;
i,j : integer; i,j : integer;
aDBFile : string; aDBFile : string;
ErrMsg : string;
begin begin
{ Don't do anything with live data until run time. } { Don't do anything with live data until run time. }
@ -778,17 +792,71 @@ begin
if Assigned(FDatabase) then FDatabase.Free; if Assigned(FDatabase) then FDatabase.Free;
if length(HostIP)>0 if length(HostIP)>0
then FDatabase:=TSQLHttpClient.Create(FHostIP,HTTP_PORT,FModel) then FDatabase:=TSQLHttpClient.Create(HostIP,HostPort,FModel)
else FDatabase:=TSQLRestServerDB.Create(FModel,aDBFile,True); else FDatabase:=TSQLRestServerDB.Create(FModel,aDBFile,True);
if FDatabase.InheritsFrom(TSQLRestClient) then if FDatabase.InheritsFrom(TSQLRestClientURI) then with (FDatabase AS TSQLRestClientURI) do
begin begin
if NOT TSQLHttpClient(FDatabase).SetUser('User','synopse') then
{$ifdef WITHLOG}
if FEnableLogging then
begin
with TSQLLog.Family do
begin
Level := LOG_VERBOSE; // LOG_STACKTRACE;
PerThreadLog := ptIdentifiedInOnFile;
end;
TSQLLog.Add.Log(sllInfo,'Going to contact server at IP:'+HostIP+' on port #'+HostPort);
end;
{$endif}
ErrMsg:=LastErrorMessage;
if Length(ErrMsg)>0 then
begin
FConnected:=False;
{$ifdef WITHLOG}
if FEnableLogging then TSQLLog.Add.Log(sllError,'Could not contact server due to: '+ErrMsg);
{$endif}
end;
if ServerTimeStamp=0 then
begin
FConnected:=False;
{$ifdef WITHLOG}
if FEnableLogging then TSQLLog.Add.Log(sllError,'Could not connect with server');
{$endif}
end;
if NOT ServerTimeStampSynchronize then
begin
FConnected:=False;
{$ifdef WITHLOG}
if FEnableLogging then TSQLLog.Add.Log(sllError,'Could not synchronize time with server');
{$endif}
end;
MaximumAuthentificationRetry:=5;
RetryOnceOnTimeout:=True;
if NOT SetUser('User','synopse') then
begin
FConnected:=False;
{$ifdef WITHLOG}
if FEnableLogging then TSQLLog.Add.Log(sllError,'Authentication failure');
{$endif}
end;
if NOT Connected then
begin begin
inherited SetConnected(False); inherited SetConnected(False);
FConnected:=False;
exit; exit;
end; end;
{$ifdef WITHLOG}
if FEnableLogging then TSQLLog.Add.Log(sllInfo,'Connected successfully with server at IP:'+HostIP+' on port #'+HostPort+' !!');
{$endif}
end; end;
if FDatabase.InheritsFrom(TSQLRestServer) then if FDatabase.InheritsFrom(TSQLRestServer) then
@ -810,9 +878,16 @@ begin
if aTable=nil then continue; if aTable=nil then continue;
// fill readonly table // fill readonly table
if j=0 case j of
then aSQLTable:=FDatabase.MultiFieldValues(aTable,'*','order by ID') 0:aSQLTable:=FDatabase.MultiFieldValues(aTable,'*','order by ID');
else aSQLTable:=FDatabase.MultiFieldValues(aTable,'*','%=?',['ResourceID'],[ResourceID]); 1:aSQLTable:=FDatabase.MultiFieldValues(
aTable,'*',
'(%=?) AND (%>=? AND %<=?) OR (RepeatCode>0 AND ?<=%)',
['ResourceID','StartTime','EndTime','RepeatRangeEnd'],
[ResourceID,DateTimeToSQL(FTimeRange.StartTime),DateTimeToSQL(FTimeRange.EndTime),DateTimeToSQL(FTimeRange.StartTime)]);
else
aSQLTable:=FDatabase.MultiFieldValues(aTable,'*','%=?',['ResourceID'],[ResourceID]);
end;
// tricky ... force set field size // tricky ... force set field size
for i := 0 to aSQLTable.FieldCount-1 do for i := 0 to aSQLTable.FieldCount-1 do
@ -843,6 +918,10 @@ begin
Load; Load;
{$ifdef WITHLOG}
if FEnableLogging then TSQLLog.Add.Log(sllInfo,'All data successfully loaded from database');
{$endif}
end else if Assigned(FDatabase) then FDatabase.Free; end else if Assigned(FDatabase) then FDatabase.Free;
end; end;
@ -855,6 +934,15 @@ begin
end; end;
end; end;
procedure TVpmORMotDataStore.SetHostPort(const Value: string);
begin
if FHostPort<>Value then
begin
FHostPort:=Value;
end;
end;
procedure TVpmORMotDataStore.SetDirectory(const Value: string); procedure TVpmORMotDataStore.SetDirectory(const Value: string);
begin begin
if Value = FDirectory then if Value = FDirectory then
@ -929,9 +1017,16 @@ begin
aSQLRecordClass:=aSQLTable.QueryRecordType; aSQLRecordClass:=aSQLTable.QueryRecordType;
aSQLTable.Free; aSQLTable.Free;
if aTable=ResourceTable if aTable=ResourceTable
then aSQLTable:=FDatabase.MultiFieldValues(aSQLRecordClass,'*','order by ID') then aSQLTable:=FDatabase.MultiFieldValues(aSQLRecordClass,'*','order by ID')
else aSQLTable:=FDatabase.MultiFieldValues(aSQLRecordClass,'*','%=?',['ResourceID'],[ResourceID]); else if aTable=EventsTable
then aSQLTable:=FDatabase.MultiFieldValues(
aSQLRecordClass,'*',
'(%=?) AND (%>=? AND %<=?) OR (RepeatCode>0 AND ?<=%)',
['ResourceID','StartTime','EndTime','RepeatRangeEnd'],
[ResourceID,DateTimeToSQL(FTimeRange.StartTime),DateTimeToSQL(FTimeRange.EndTime),DateTimeToSQL(FTimeRange.StartTime)])
else aSQLTable:=FDatabase.MultiFieldValues(aSQLRecordClass,'*','%=?',['ResourceID'],[ResourceID]);
TSynSQLTableDatasetWithLocate(aTable).Table:=aSQLTable; TSynSQLTableDatasetWithLocate(aTable).Table:=aSQLTable;

View File

@ -9,6 +9,7 @@ Table of contents
4. Version history 4. Version history
4.1 Release 1.03 4.1 Release 1.03
4.2 Release 1.04 4.2 Release 1.04
4.3 Release 1.05
============================================== ==============================================
@ -107,6 +108,12 @@ steps:
misc - Translate user interface in po files misc - Translate user interface in po files
misc - DPI-aware and translation-tolerant form layout misc - DPI-aware and translation-tolerant form layout
misc - Add new sample projects misc - Add new sample projects
4.3 Release 1.05
misc - Add mORMot datastore
5103 - Add drag and drop of events within DayView