#2 Re: mORMot 2 » Different behaviour in variant to json » 2024-11-11 16:11:52

Is it possible change value of element 0 of array v.a without deleting and adding again?

#3 Re: mORMot 2 » Different behaviour in variant to json » 2024-11-10 10:16:27

I found the problem. It seems it was my mistake:

var
  NewArray2: Variant;
begin
  ss := '{"a":["1"],"b":"2"}';
  NewArray2 := _Arr(['2']);
  V := _Json(ss);
  V.a := NewArray2;
  ShowMessage(TDocVariantData(V).ToJson);

or

  LDocDict := DocDict(ss);
  LDocDict['a'] := NewArray2;

#4 mORMot 2 » Different behaviour in variant to json » 2024-11-10 09:50:13

anouri
Replies: 5

Hi. mormot result : {"a":"[\"2\"]","b":"2"}
TJSONObject result: {"a":"["2"]","b":"2"}

when I remove line V.a := '["2"]' it is ok! After changing a property json changes.

var
  V: Variant;
  J: TJSONObject;
  NewArray: TJSONArray;
  ss: string;
begin
  ss := '{"a":["1"],"b":"2"}';

  V := _Json(ss);
  V.a := '["2"]';
  ShowMessage(TDocVariantData(V).ToJson);

  j := TJSONObject.ParseJSONValue(ss) as TJSONObject;
  NewArray := TJSONArray.Create;
  NewArray.Add('2');
  j.RemovePair('a').Free;
  j.AddPair('a', NewArray);
  ShowMessage(j.ToJSON);

#5 Re: mORMot 2 » How to reflect an existing database ? » 2024-10-03 10:25:11

I am using sql capabilties for generate DTO and classes. It is realy simple and flexible, maybe help some one (this is for mysql and can be implement for other dbms by changing sql):

select t.table_name,concat(group_concat(col order by ordinal_position separator ';\r\n'),';') table_create from (
select a.table_name,a.ordinal_position,concat(a.column_name,': ',
if(a.data_type in ('varchar','enum','text','char','time','varbinary','tinytext','set','mediumtext'),
if(a.is_nullable='YES','TNullableUtf8Text','RawUtf8'),
if(a.data_type in ('int','tinyint','mediumint','smallint'),
if(a.is_nullable='YES','TNullableInteger','integer'),
if(a.data_type in ('decimal'),
if(a.is_nullable='YES','TNullableCurrency','currency'),
if(a.data_type in ('bigint'),
if(a.is_nullable='YES','TNullableInteger','int64'),
if(a.data_type in ('timestamp','date','datetime'),
if(a.is_nullable='YES','TNullableDateTime','TDateTime'),
if(a.data_type in ('longblob','blob','mediumblob'),
if(a.is_nullable='YES','TNullableUtf8Text','RawUtf8'),
if(a.data_type in ('double','float'),'Double','unDefined')))))))
) col from information_schema.columns a
where table_schema='your_mysql_db_name') t
group by t.table_name;

#6 Re: mORMot 2 » Text encrypted with aes in mormot2 is not decrypted by tms aes » 2024-09-24 15:37:42

I think AES/GCM/NOPADDING used by tms and mormot uses pkc7 pasdding. and it is different

#7 Re: mORMot 2 » Text encrypted with aes in mormot2 is not decrypted by tms aes » 2024-09-24 13:36:30

I use encrypt method and same again ?
It is decrypted with motmot, but with another tool it gives no multi byte string error

var
  key: string;
  PlainText: string;
  akey : RawByteString;
  CryptCipher: ICryptCipher;
  dest: RawByteString;
  InputRawString: RawByteString;
  Bytes: TBytes;
begin
  PlainText := 'да, это работает. спасибо';
  Key := '12345678901234567890123456789012';
  akey := HexToBin(SHA256(Key));
  Bytes := TEncoding.UTF8.GetBytes(PlainText);
  SetString(InputRawString, PAnsiChar(PByte(Bytes)), Length(Bytes));
  CryptCipher := Encrypt('aes-256-gcm', Pointer(akey));
  CryptCipher.Process(InputRawString, dest, '');
  dest := BinToBase64(dest);
  Memo2.Text := dest;

#8 Re: mORMot 2 » Text encrypted with aes in mormot2 is not decrypted by tms aes » 2024-09-24 10:30:50

It is correct in actual code and I forgot to add here:

Bytes := TEncoding.UTF8.GetBytes(PlainText);
before encryption

#9 Re: mORMot 2 » Text encrypted with aes in mormot2 is not decrypted by tms aes » 2024-09-24 09:55:49

I test result in online site like devglan. for same key and IV result is different.

#10 mORMot 2 » Text encrypted with aes in mormot2 is not decrypted by tms aes » 2024-09-24 08:45:41

anouri
Replies: 5
var
  PlainText: string;
  CipherText: RawByteString;
  Bytes: TBytes;
begin
  Key := GenerateRandomString(32);
  PlainText := 'да, это работает. спасибо';
  Bytes := TEncoding.UTF8.GetBytes(PlainText);
  akey := HexToBin(SHA256(Key));
  AES := TAesGcm.Create(pointer(akey)^, 256);
  try
    Bytes := AES.EncryptPkcs7(Bytes,  True);
    CipherText := TEncoding.ANSI.GetString(Bytes);
    Result := BinToBase64(CipherText);
  finally
    AES.Free;
  end;

Decrypt with mormot2 is ok and return original text properly.
other party tools like tms saye:
No mapping for the Unicode character in target multi-byte

#11 Re: mORMot 2 » How can I implement OAEP padding in RSA » 2024-09-24 08:38:46

Is there a future plan to implement OAEP ?

#13 Re: mORMot 2 » Group in telegram » 2024-09-24 05:56:15

We can add more managers to the group. If any of the people who are here and are approved by you, I can add them

#15 mORMot 2 » Group in telegram » 2024-09-07 08:13:14

anouri
Replies: 6

Many topics related to Delphi have groups in Telegram, and in this community, members who have knowledge guide the questions of newbies.
Do you think it is advisable to create such an international group for mormot?
If there is no prohibition, let's create a group

#16 Re: mORMot 2 » Aes gcm 256 » 2024-08-25 11:03:07

Actually, I was in the learning and testing phase. In actual programming, I created a function for encrypt and another for decrypt.
Thank you again for the valuable and great work you are doing

#17 Re: mORMot 2 » Aes gcm 256 » 2024-08-24 14:57:11

After making the suggested change, the same error occurred again. But by creating a new instance, the problem was solved!
Thanks. you are the best!

#18 mORMot 2 » Aes gcm 256 » 2024-08-24 13:08:29

anouri
Replies: 4

After 2 days I couldn't get this code to work properly:
error = Unexpected TAesGcm.Decrypt

var
  AES: TAesGcm;
  Key: AnsiString;
  PlainText: string;
  CipherText: RawUtf8;
  akey : RawByteString;
  s: RawByteString;
begin
  //Key := GenerateRandomString(32);
  Key := '12345678901234567890123456789012';
  akey := HexToBin(SHA256(Key));
  PlainText := '123';
  s := StringToUTF8(PlainText);
  AES := TAesGcm.Create(akey, 256);
  CipherText := BinToBase64(AES.EncryptPkcs7(s, True));

  s := StringToUTF8(CipherText);
  PlainText := AES.DecryptPkcs7(Base64ToBin(s), True);
  ShowMessage(UTF8ToString(PlainText));

#19 Re: mORMot 2 » How can I implement OAEP padding in RSA » 2024-08-24 07:22:29

It is requierment of taxpayer system.
Taxpayer document says:
After encryption of the bill, through the AES/GCM algorithm, the encrypted symmetric key and IV must be placed next to the encrypted bill. To encrypt the symmetric key, the asymmetric RSA-OAEP-SHA256 method must be used, which is obtained from the public key(s) of the taxpayer system with a length of 4096 bits. A valid intermediate center is used (the public key of the taxpayer system is obtained using the GET_SERVER_INFORMATION method).
C# example of this document is :
https://jsfiddle.net/8w2u3sex/

#21 mORMot 2 » How can I implement OAEP padding in RSA » 2024-08-23 23:22:22

anouri
Replies: 7

Hi,
Can't find in documentation. I need:
OaepPadding
OaepHash = sha256

#22 Re: mORMot 2 » generate csr from privatekey and publickey » 2024-08-23 17:34:20

The problem is solved. thank you very much

#23 Re: mORMot 2 » generate csr from privatekey and publickey » 2024-08-22 08:49:43

There is a taxpayer system that requires the national code of individuals or the company's national ID in this field to produce a certificate in field 2.5.4.5.
Therefore, I have no choice and I have to fill this field so that I can send an invoice to the government taxpayer system. Is there no solution?

#24 Re: mORMot 2 » Serive server is nil » 2024-08-22 08:21:37

Thank you so much. this one worked: smile
aServer.ServiceRegister(TInvoiceService, [TypeInfo(IInvoiceService)], sicShared, '1');

#25 Re: mORMot 2 » Serive server is nil » 2024-08-22 06:12:55

[dcc32 Error] View.Server.pas(109): E2250 There is no overloaded version of 'ServiceRegister' that can be called with these arguments

#26 Re: mORMot 2 » Serive server is nil » 2024-08-21 13:41:02

I can't find anything wrong. Any suggestions?

#27 Re: mORMot 2 » Serive server is nil » 2024-08-21 09:57:33

unit Service.Invoice ;

TInvoiceService = class(TInjectableObjectRest, IInvoiceService)
public
constructor Create; overload;
function GetInvoiceList(const DateFr,DateTo: string): RawJson;


function TInvoiceService.GetInvoiceList(const DateFr,DateTo: string): RawJson;
begin
--   self.server is nil here
end;

constructor TInvoiceService.Create;
begin
  inherited Create;
end;

#28 mORMot 2 » Serive server is nil » 2024-08-21 08:59:38

anouri
Replies: 8

Hi,
I create custom server
TMyRest = class(TRestServerFullMemory)
and register service
aServer.ServiceRegister(InvoiceService, [TypeInfo(IInvoiceService)],'1');

but in serivce methods self.server (TRestServer) is nil!

#29 Re: mORMot 2 » Where do I start? » 2024-08-21 06:06:34

Hi mr TBO. property ConnectionPool is readonly property, how can I assgin connectionpool?
I passed it by TRestServer  constructor at the moment.

#30 Re: mORMot 2 » Where do I start? » 2024-08-15 14:50:12

thanks. but yo write "TSQL*ConnectionProperties is connection pool, not real db connection! Real db connection is TSQL*ConnectionProperties"
it is same!
TSQL*ConnectionProperties = TSQL*ConnectionProperties

#31 Re: mORMot 2 » generate csr from privatekey and publickey » 2024-08-15 14:47:22

But I do it with other third party component now.I want to change it to mormot.
CkCsr_SetSubjectField(csr,'2.5.4.5', pchar(Shenase) ,'UTF8String');

#32 Re: mORMot 2 » generate csr from privatekey and publickey » 2024-08-15 09:30:57

I was able to generate the csr file using the suggested method and with mormot.crypt.x509. But I can't fill the field 2.5.4.5 or serialnumber. There is no such field.

#33 Re: mORMot 2 » Where do I start? » 2024-08-15 08:02:47

ok
As you can see in the code above, I pass the dbconnection to the InvoiceService constructor. I inject connection by constructor to service, and I hold connection in fConnection defined inside service. I hope it is the right approach.
I am concerned about one thing. Is a connection shared between different threads created by mormot for other services or operations? Doesn't it cause a problem in Mormot being multi-thread?

#34 Re: mORMot 2 » Where do I start? » 2024-08-14 15:12:52

this is my code to connect to mysql database. There are 2 service, invoice and inventory.

procedure TfrmMain.btnStartClick(Sender: TObject);
begin
  StartServer('zdbc:mysql://localhost:3306/mysqldb?username=user;password=mypassword');
end;

procedure TfrmMain.StartServer( aDbURI : RawUTF8 );
begin
  LogFamily := SQLite3Log.Family;
  LogFamily.Level := LOG_VERBOSE;
  LogFamily.PerThreadLog := ptIdentifiedInOnFile;

  MyModel := CreatePassakModel;

  aDbConnection := TSQLDBZEOSConnectionProperties.Create( aDbURI, '', '', '' );

  aPassakServer  := TRestServerFullMemory.Create(MyModel);
  InvoiceService := TInvoiceService.Create(aDbConnection);
  aPassakServer.ServiceRegister(InvoiceService, [TypeInfo(IInvoiceService)],'1');

  InventoryService := TInventoryService.Create(aDbConnection);
  aPassakServer.ServiceRegister(InventoryService, [TypeInfo(IInventoryService)],'2');

  aPassakServer.ServiceMethodRegister('reports', InvoiceService.testCallBack);

  AddToServerWrapperMethod(aPassakServer,['templates','templates']);

  aHTTPServer := TSQLHttpServer.Create( HttpPort, [aPassakServer], '+', HTTP_DEFAULT_MODE);

  aHttpServer.AccessControlAllowOrigin := '*'; // allow cross-site AJAX queries

  memLog.Lines.Add('Background server is running.'#10);
  memLog.Lines.Add('Cross-Platform wrappers are available at ' + HttpPort  + '/' +  HttpRoot );
end;

#35 Re: mORMot 2 » generate csr from privatekey and publickey » 2024-08-14 11:12:21

openssl disabled by default. I think mormot.crypt.x509 is better.

#36 Re: mORMot 2 » generate csr from privatekey and publickey » 2024-08-14 09:47:27

CryptCertOpenSsl[caaRS256] does not created and raise AV.
I tried CryptCertOpenSsl[caaRS256] := TCryptCertAlgo.Create('ES256');
and
CryptCertOpenSsl[caaRS256] := TCryptCertAlgo.Create('');
with no success !

#37 Re: mORMot 2 » Where do I start? » 2024-08-14 08:57:59

This is a big challenge in the beginning. I had the same problem. First, I tried to work on the documentation with Json and how to work with it in mormot using docvariant and doclist. Then I went back to the examples and was able to modify it to create a very basic web service. Then I tried to understand the interface  base service and method base service . And finally I worked a little with swagger.
Considering that in my existing database, the primary keys are narural key and compiste. I can't use orm. Because in Orm there must be a primary key for each table. So, I leave this section aside and use the functions that take the model and store it in the database by SQL.
The next step is how to call and share the interface for the client program. The power of mormot shows itself here. And how beautifully this work is implemented.
I'm still at the beginning of the journey, but I learned a lot within a month and I try to learn more every day.
I agree that it is much more difficult to start working with mormot than other frameworks.

It is natural that piloting a plane is more difficult than driving a car. But there are many unique possibilities here. Thanks to AB

#38 mORMot 2 » generate csr from privatekey and publickey » 2024-08-14 08:07:12

anouri
Replies: 10

Hi, ab
first of all I thank you for very powerful framework.

I want to generate csr file from private key and public key:

var
  pem: TCertPem;
  CryptCertFields: TCryptCertFields;  //record
  LPFields:  PCryptCertFields;
  priv: RawUtf8;
  csr: RawUtf8;
  CryptCertAlgo: TCryptCertAlgo;
begin
  CryptCertFields.Country := 'US';
  CryptCertFields.CommonName := 'aaaaa';
  CryptCertFields.EmailAddress := 'a@b.com';
  LPFields := @CryptCertFields;
  pem := Memo1.Lines.Text;
  priv := pem;
  //priv := '';

  CryptCertAlgo := TCryptCertAlgo.Create('aes-256-cfc');//what is algoname
  csr := CryptCertAlgo.CreateSelfSignedCsr('','', priv,[], LPFields);

raise an error : TCryptCertAlgo.Create('aes-256-cfc' does not support a custom private key.
I changed algoritm to
es-256-gcm
aes-256-ofb
aes-256-cbc
aes-256-ctr
with no success.

#39 Re: mORMot 2 » OrmTableDataSet.Close and OrmTableDataSet.Free is very slow » 2024-04-10 17:45:38

I know, but the interesting thing is why the speed is still low when datasource is set to nil. But when beginupdate is executed, the problem is solved.

#40 Re: mORMot 2 » OrmTableDataSet.Close and OrmTableDataSet.Free is very slow » 2024-04-05 09:49:14

I debugged it, closing is slow.

But you are right. I changed my code and sloved I don't khow why!!!!

    vwMain.BeginUpdate(); //cxgrid 
    //DataSource1.DataSet := nil;

#41 mORMot 2 » OrmTableDataSet.Close and OrmTableDataSet.Free is very slow » 2024-04-05 07:19:13

anouri
Replies: 4

Hello and thanks.
The following statements are very slow, for a json that has 300 records. It takes a few seconds:

  DataSource1.DataSet := nil;

  OrmTableDataSet.Close;
  OrmTableDataSet.Free;
  
  OrmTableDataSet := TOrmTableDataSet.CreateFromJson(nil , json);
 
  DataSource1.DataSet := OrmTableDataSet;

#42 Re: mORMot 2 » Beginner's questions... » 2024-04-02 19:43:53

Hi AB
many thanks to excellent mormot2 framework.
,what is the wrong with swagger :
(when I use TNullableUtf8Text)

Resolver error at paths./InvoiceService/Insert.post.parameters.0.schema.properties.AInvoice.properties.remarks.$ref
Could not resolve reference: Could not resolve pointer: /definitions/TNullableUtf8Text does not exist in document.

#43 Re: mORMot 2 » Beginner's questions... » 2024-03-04 21:40:31

Thank you.
Setter solved the problem. but i have alot of tables (600 tables), with many enum fields. I want to use existing database structure as possible.

procedure TOrmInvoice.SetSize(const Value: RawUtf8);
begin
  //xxlarge,xlarge,large,medium,small
  if Value = 'xxlarge' then
    FSize := '1'
  else if Value = 'xlarge' then
    FSize := '2'
  else if Value = 'large' then
    FSize := '3'
  else if Value = 'medium' then
    FSize := '4'
  else if Value = 'small' then
    FSize := '5';
end;

publish
  Size: RawUtf8;

field data type is enum('xxlarge','xlarge','large','medium','small');
I don't know where this conversion is happen. In orm level or Zeus level.

#44 Re: mORMot 2 » Beginner's questions... » 2024-03-04 11:37:38

I have truble in mormot + mysql + enum fields.
Imagine that the data type is enum('large','small') when entering information in the corresponding orm class, it should be written like this (Otherwise, the error "Data truncated for column 'column_name' will be generated):

Rec.size := '1';

That is, we must enter the enum index. While I used the enum text itself in the previous software:

query.fieldbyname('size').asstring := 'large';

The solution that comes to my mind is to find the corresponding index by a function based on the enum text and write like this:
Rec.size := Get_inum_index('large');

#45 Re: mORMot 2 » Beginner's questions... » 2024-03-03 08:42:30

Hi.
For reports I have very complex sql,what is the best way for executing this kind of sql?
Is it correct using :

function TReportService.Report: RawJson;
var
  MyComplexSql: RawUtf8;
begin
  MyComplexSql := 'my sql with left joins and subquery ...';
  Result := TRestServerDB(Self.Server).DB.ExecuteJson(MyComplexSql, True);
end;

#46 Re: mORMot 2 » Beginner's questions... » 2024-03-01 16:14:59

Hi AB. Thank you for very good mORMot framework.
This code work client side.
var
  OrmTable: TOrmTable;
  OrmTableDataSet: TOrmTableDataSet;
begin
  OrmTable := HttpClient.ExecuteList([],'select * from user limit 10');
  ShowMessage(OrmTable.RowCount.ToString);
  OrmTableDataSet := TOrmTableDataSet.Create(nil, OrmTable);

  DataSource1.DataSet := OrmTableDataSet;
end;


but in server side not working:Result is empty. I can't find why

procedure TUserService.List(var ATable: TOrmTable); //UserService is interface base service
begin
  ATable := Self.Server.ExecuteList([],'select * from user');
end;

#47 Re: mORMot 2 » Beginner's questions... » 2024-02-25 12:32:20

Hello . I want to check one of the demos related to mormot1 but TCQRSResult is missing in mormot2. What is its equivalent?

Board footer

Powered by FluxBB