You are not logged in.
Pages: 1
In my little test project running some regression tests, I found that fields that have the type "currency" will not be updated on the database.
I thought it should work with "currency" but in my case apparently not. If I change type "TPrice" to be of type "double" it works.
Am I doing something wrong or should I avoid type "currency"?
---- A crippled piece of the code i use ----
type
TPrice = type currency;
TDiscount = type double;
TWeight = type double;
-------------------------------------------------
TSQLRecordProduct = class(TSQLRecord)
protected
fweight: double; // TWeight
fdiscount: currency; // TDiscount
fPrice: double;//currency; // TPrice
published
property weight: double read fweight write fweight;
property discount: double read fdiscount write fdiscount;
property price: double read fPrice write fPrice;
end;
--------------------------------------------------
TProduct = class(TSynAutoCreateFields)
private
fWeight: TWeight;
fPrice: TPrice;
fDiscount: TDiscount;
public
constructor create(const aName: TProductName; const aWeight: TWeight; const aPrice: TPrice;
const aDiscount: TDiscount); overload;
published
property weight: TWeight read fWeight write fWeight;
property price: TPrice read fPrice write fPrice;
property discount: TDiscount read fDiscount write fDiscount;
end;
TProductObjArray = array of TProduct;
------------- part of server code --------
RestServer := TSQLRestExternalDBCreate( TSQLModel.Create([TSQLRecordProduct]),
RestServer.ServiceContainer.InjectResolver([TProductRepoFactory.Create(RestServer)],true);
---------------------- Test code below --------------------
var p1: TProduct;
p1 := TProduct.Create;
p1.weight := 12.3;
p1.price := 249.99;
p1.discount := 25;
aCQRSRes := cmd.Add(p1);
Check(cqrsSuccess = aCQRSRes);
Check(cqrsSuccess = cmd.Commit);
p1.price is not persisted.
Delphi-11, WIN10
Offline
I use Currency type and have no such problems.
Have you tried using directly just Currency everywhere (ie. don't use TPrice anywhere)? It should work that way.
Alternatively, don't create a new type for your Currency fields and just create an alias:
type
TPrice = Currency;
For the framework to process the property as you would expect, the property type needs to equal TypeInfo(Currency).
By using TPrice = type Currency; you have created a new type, so it is no longer the same type.
Last edited by trx (2020-03-16 12:58:16)
Offline
You are completely right, but it makes "currency" special any way as it works if you do: TPrice = double;
Thank's a lot!
Delphi-11, WIN10
Offline
I have the same problems with saving published properties of type currency after switching from mORMot1 to mORMot2 (mORMot2 from 04/04/2021) and interface based services. After updating to today's version of mORMot2 (GitHub commit 1341) currency works with SQLite3 for me without problems.
With best regards
Thomas
Offline
Pages: 1