Daniele Teti 2022-04-12 12:12:08 +02:00
parent f935895054
commit 0fac2dd2fa
7 changed files with 190 additions and 22 deletions

View File

@ -1,7 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{70BE99D7-37AE-4063-9A7C-4A9E9A5600D3}</ProjectGuid>
<ProjectVersion>19.1</ProjectVersion>
<ProjectVersion>19.4</ProjectVersion>
<FrameworkType>VCL</FrameworkType>
<MainSource>UsingServerInDLL.dpr</MainSource>
<Base>True</Base>
@ -104,10 +104,6 @@
<DesignClass>TWebModule</DesignClass>
</DCCReference>
<DCCReference Include="..\REST\CONTROLLERS\REST.MainController.pas"/>
<BuildConfiguration Include="Release">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
@ -115,6 +111,10 @@
<Key>Cfg_1</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
<BuildConfiguration Include="Release">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
</ItemGroup>
<ProjectExtensions>
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
@ -132,13 +132,13 @@
</Excluded_Packages>
</Delphi.Personality>
<Deployment Version="3">
<DeployFile LocalName="Win32\Debug\UsingServerInDLL.exe" Configuration="Debug" Class="ProjectOutput"/>
<DeployFile LocalName="..\bin\UsingServerInDLL.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>UsingServerInDLL.exe</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="Win32\Debug\UsingServerInDLL.exe" Configuration="Debug" Class="ProjectOutput"/>
<DeployClass Name="AdditionalDebugSymbols">
<Platform Name="iOSSimulator">
<Operation>1</Operation>
@ -151,6 +151,16 @@
<Operation>0</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidClasses">
<Platform Name="Android">
<RemoteDir>classes</RemoteDir>
<Operation>64</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>classes</RemoteDir>
<Operation>64</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidClassesDexFile">
<Platform Name="Android">
<RemoteDir>classes</RemoteDir>
@ -279,6 +289,16 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_LauncherIcon192">
<Platform Name="Android">
<RemoteDir>res\drawable-xxxhdpi</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-xxxhdpi</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_LauncherIcon36">
<Platform Name="Android">
<RemoteDir>res\drawable-ldpi</RemoteDir>
@ -442,6 +462,11 @@
<Operation>1</Operation>
<Extensions>.framework</Extensions>
</Platform>
<Platform Name="OSXARM64">
<RemoteDir>Contents\MacOS</RemoteDir>
<Operation>1</Operation>
<Extensions>.framework</Extensions>
</Platform>
<Platform Name="Win32">
<Operation>0</Operation>
</Platform>
@ -469,6 +494,11 @@
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="OSXARM64">
<RemoteDir>Contents\MacOS</RemoteDir>
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="Win32">
<Operation>0</Operation>
<Extensions>.dll;.bpl</Extensions>
@ -497,6 +527,11 @@
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="OSXARM64">
<RemoteDir>Contents\MacOS</RemoteDir>
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="Win32">
<Operation>0</Operation>
<Extensions>.bpl</Extensions>
@ -526,6 +561,10 @@
<RemoteDir>Contents\Resources\StartUp\</RemoteDir>
<Operation>0</Operation>
</Platform>
<Platform Name="OSXARM64">
<RemoteDir>Contents\Resources\StartUp\</RemoteDir>
<Operation>0</Operation>
</Platform>
<Platform Name="Win32">
<Operation>0</Operation>
</Platform>
@ -1107,6 +1146,10 @@
<RemoteDir>..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="OSXARM64">
<RemoteDir>..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="ProjectOSXEntitlements">
<Platform Name="OSX32">
@ -1117,6 +1160,10 @@
<RemoteDir>..\</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="OSXARM64">
<RemoteDir>..\</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="ProjectOSXInfoPList">
<Platform Name="OSX32">
@ -1127,6 +1174,10 @@
<RemoteDir>Contents</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="OSXARM64">
<RemoteDir>Contents</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="ProjectOSXResource">
<Platform Name="OSX32">
@ -1137,6 +1188,10 @@
<RemoteDir>Contents\Resources</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="OSXARM64">
<RemoteDir>Contents\Resources</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Required="true" Name="ProjectOutput">
<Platform Name="Android">
@ -1167,6 +1222,10 @@
<RemoteDir>Contents\MacOS</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="OSXARM64">
<RemoteDir>Contents\MacOS</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Win32">
<Operation>0</Operation>
</Platform>
@ -1205,16 +1264,17 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="iOSDevice64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Android" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Android64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="iOSDevice64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="iOSSimulator" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Linux64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="OSX32" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Android" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="OSX64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="iOSSimulator" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Android64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="OSXARM64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
</Deployment>
<Platforms>
<Platform value="Win32">True</Platform>

View File

@ -63,8 +63,8 @@ const
type
TRQLFirebirdCompiler = class(TRQLCompiler)
protected
function GetLiteralBoolean(const Value: Boolean): String; virtual;
function RQLFilterToSQL(const aRQLFIlter: TRQLFilter): string; virtual;
function RQLSortToSQL(const aRQLSort: TRQLSort): string; virtual;
function RQLLimitToSQL(const aRQLLimit: TRQLLimit): string; virtual;
@ -93,6 +93,15 @@ begin
Result := inherited;
end;
function TRQLFirebirdCompiler.GetLiteralBoolean(const Value: Boolean): String;
begin
if Value then
begin
Exit('true');
end;
Exit('false');
end;
function TRQLFirebirdCompiler.RQLCustom2SQL(
const aRQLCustom: TRQLCustom): string;
begin
@ -129,9 +138,9 @@ begin
else if aRQLFIlter.RightValueType = vtBoolean then
begin
if SameText(aRQLFIlter.OpRight, 'true') then
lValue := '1'
lValue := GetLiteralBoolean(true)
else
lValue := '0';
lValue := GetLiteralBoolean(false);
end
else
lValue := aRQLFIlter.OpRight;

View File

@ -27,11 +27,14 @@ unit MVCFramework.RQL.AST2InterbaseSQL;
interface
uses
System.Generics.Defaults,
MVCFramework.RQL.Parser,
MVCFramework.RQL.AST2FirebirdSQL;
type
TRQLInterbaseCompiler = class(TRQLFirebirdCompiler)
protected
function GetLiteralBoolean(const Value: Boolean): String; override;
end;
implementation
@ -40,6 +43,17 @@ uses
System.SysUtils,
MVCFramework.ActiveRecord;
{ TRQLInterbaseCompiler }
function TRQLInterbaseCompiler.GetLiteralBoolean(const Value: Boolean): String;
begin
if Value then
begin
Exit('1');
end;
Exit('0');
end;
initialization
TRQLCompilerRegistry.Instance.RegisterCompiler('interbase', TRQLInterbaseCompiler);

View File

@ -84,8 +84,17 @@ var
begin
if (aRQLFIlter.RightValueType = vtString) and (aRQLFIlter.Token <> tkContains) then
lValue := aRQLFIlter.OpRight.QuotedString('''')
else if aRQLFIlter.RightValueType = vtBoolean then
begin
if SameText(aRQLFIlter.OpRight, 'true') then
lValue := '1'
else
lValue := '0';
end
else
begin
lValue := aRQLFIlter.OpRight;
end;
lDBFieldName := GetDatabaseFieldName(aRQLFIlter.OpLeft, True);

View File

@ -1099,7 +1099,16 @@ begin
end;
ftInteger, ftSmallint, ftShortint, ftByte:
begin
aRTTIField.SetValue(AObject, AField.AsInteger);
// sqlite doesn't support boolean, so are identified as integers
// so we need to do some more checks...
if (aRTTIField.FieldType.TypeKind = tkEnumeration) and (aRTTIField.Name.ToLower.Contains('bool')) then
begin
aRTTIField.SetValue(AObject, AField.AsInteger = 1);
end
else
begin
aRTTIField.SetValue(AObject, AField.AsInteger);
end;
end;
ftLongWord, ftWord:
begin

View File

@ -72,6 +72,8 @@ type
[Test]
procedure TestRQL;
[Test]
procedure TestRQLWithBoolean;
[Test]
procedure TestRQLWithDateTime;
[Test]
procedure TestRQLLimit;
@ -1453,6 +1455,54 @@ begin
Assert.AreEqual(Int64(0), TMVCActiveRecord.Count<TCustomer>(RQL1));
end;
procedure TTestActiveRecordBase.TestRQLWithBoolean;
const
RQL1 = 'or(eq(City, "Rome"),eq(City, "London"))';
var
lBoolTable, lBoolValue2: TBoolTest;
begin
TMVCActiveRecord.DeleteAll(TBoolTest);
Assert.AreEqual(Int64(0), TMVCActiveRecord.Count(TBoolTest));
lBoolTable := TBoolTest.Create;
try
lBoolTable.BoolValue := True;
lBoolTable.Store;
lBoolValue2 := TMVCActiveRecord.SelectOneByRQL<TBoolTest>('eq(boolvalue, true)');
try
Assert.AreEqual(True, lBoolValue2.BoolValue);
finally
lBoolValue2.Free;
end;
lBoolTable.BoolValue := False;
lBoolTable.Store;
lBoolValue2 := TMVCActiveRecord.SelectOneByRQL<TBoolTest>('eq(boolvalue, false)');
try
Assert.AreEqual(False, lBoolValue2.BoolValue);
finally
lBoolValue2.Free;
end;
Assert.IsNull(TMVCActiveRecord.SelectOneByRQL<TBoolTest>('eq(boolvalue, true)', False));
finally
lBoolTable.Free;
end;
// LoadData;
// lCustomers := TMVCActiveRecord.SelectRQL<TCustomer>(RQL1, MAXINT);
// try
// Assert.AreEqual(240, lCustomers.Count);
// for var lCustomer in lCustomers do
// begin
// Assert.IsMatch('^(Rome|London)$', lCustomer.City);
// end;
// finally
// lCustomers.Free;
// end;
// TMVCActiveRecord.DeleteRQL(TCustomer, RQL1);
// Assert.AreEqual(Int64(0), TMVCActiveRecord.Count<TCustomer>(RQL1));
end;
procedure TTestActiveRecordBase.TestRQLLimit;
var
lCustomers: TObjectList<TCustomer>;

View File

@ -35,7 +35,7 @@ uses
FireDAC.Stan.Param, Data.DB, System.SysUtils;
const
SQLs_SQLITE: array [0 .. 4] of string =
SQLs_SQLITE: array [0 .. 5] of string =
('CREATE TABLE customers (id INTEGER NOT NULL, code varchar (20), description varchar (200), city varchar (200), note TEXT, rating INTEGER, creation_time TIME, creation_date date, PRIMARY KEY (id))',
'CREATE TABLE customers2 (id INTEGER NOT NULL, code varchar (20), description varchar (200), city varchar (200), note TEXT, rating INTEGER, creation_time TIME, creation_date date, PRIMARY KEY (id))',
'CREATE TABLE customers_with_code (code varchar (20) not null, description varchar (200), city varchar (200), note TEXT, rating INTEGER, PRIMARY KEY(code))',
@ -51,10 +51,11 @@ const
'"rating with spaces" INTEGER, ' +
'"creation_time with spaces" TEXT, ' +
'"creation_date with spaces" TEXT' +
') '
') ',
'CREATE TABLE booltest(id integer primary key AUTOINCREMENT, boolvalue integer)'
);
SQLs_FIREBIRD: array [0 .. 4] of string =
SQLs_FIREBIRD: array [0 .. 5] of string =
('CREATE TABLE customers (id integer generated by default as identity primary key, code varchar (20), description varchar (200), city varchar (200), note varchar(200), rating INTEGER, creation_time TIME, creation_date date)',
'CREATE TABLE customers2 (id integer generated by default as identity primary key,code varchar (20), description varchar (200), city varchar (200), note varchar(200), rating INTEGER, creation_time TIME, creation_date date)',
'CREATE TABLE customers_with_code (code varchar (20) not null, description varchar (200), city varchar (200), note varchar(200), rating INTEGER, PRIMARY KEY(code))',
@ -70,10 +71,11 @@ const
'"rating with spaces" INTEGER, ' +
'"creation_time with spaces" time, ' +
'"creation_date with spaces" date' +
') '
') ',
'CREATE TABLE booltest(id integer generated by default as identity primary key, boolvalue boolean)'
);
SQLs_POSTGRESQL: array [0 .. 4] of string =
SQLs_POSTGRESQL: array [0 .. 5] of string =
('CREATE TABLE customers (id integer generated by default as identity primary key, code varchar (20), description varchar (200), city varchar (200), note varchar(200), rating INTEGER, creation_time TIME, creation_date date)',
'CREATE TABLE customers2 (id integer generated by default as identity primary key,code varchar (20), description varchar (200), city varchar (200), note varchar(200), rating INTEGER, creation_time TIME, creation_date date)',
'CREATE TABLE customers_with_code (code varchar (20) not null, description varchar (200), city varchar (200), note varchar(200), rating INTEGER, PRIMARY KEY(code))',
@ -89,7 +91,8 @@ const
'"rating with spaces" int4 NULL, ' +
'"creation_time with spaces" time NULL, ' +
'"creation_date with spaces" date NULL' +
')'
')',
'CREATE TABLE booltest(id integer generated by default as identity primary key, boolvalue boolean)'
);
type
@ -352,6 +355,20 @@ type
property f_blob: TStream read ff_blob write ff_blob;
end;
[MVCTable('booltest')]
TBoolTest = class(TMVCActiveRecord)
private
[MVCTableField('id', [foPrimaryKey, foAutoGenerated])]
fID: NullableInt32;
[MVCTableField('boolvalue')]
fBoolValue: Boolean;
public
property ID: NullableInt32 read FID write fID;
property BoolValue: Boolean read FBoolValue write fBoolValue;
end;
TMyObject = class
private
FPropString: string;