#1 Re: mORMot 2 » How to create table on db server with same schema » 2024-03-23 23:50:17

Hi, ab

Is there a any way to use it by passing the table name as a parameter?

#2 mORMot 2 » How to create table on db server with same schema » 2024-03-23 02:20:22

bigheart
Replies: 3

Hello,

I just want to create multiple tables using same schema.

The table name will be added the different prefix charater to prevent duplicate table names.

How to create the table using TRestServerDB?

#4 Re: mORMot 2 » THttpClientSocket.Post using THttpMultiPartStream » 2024-02-11 00:17:29

...
LParam.AddContent('text', text);
LParam.Flush;
lHttpResponse := lHttp.Post(LUri.Address, LParam, 'multipart/formdata');
...

The result is same, error code 400.

And i tried to use sendphoto method of the telegram bot API as blow:

...
LParam.AddContent('chat_id', FloatToStr(ChatID));
LParam.AddContent('bmp', 'image/bmp');
LParam.AddFileContent('photo', LPath, LFile);
//    LParam.AddFile('photo', LPath);
LParam.Flush();
lHttpResponse := lHttp.Post(LUri.Address, LParam, 'multipart/formdata');
...

And i received the result error code 400 : "Bad Request: there is no photo in the request"

I think, I don't seem to know how to use THttpMultiPartStream and THttpClientSocket.Post function.

Please give me some advice.

#5 mORMot 2 » THttpClientSocket.Post using THttpMultiPartStream » 2024-02-10 07:49:03

bigheart
Replies: 5

Hello,

I just try to communicate with telegram bot api sendmessage using THttpClientSocket.

  lHttp := THttpClientSocket.Create;
  LParam := THttpMultiPartStream.Create;

  lURL_TELEG := 'https://api.telegram.org/bot' + FToken + '/sendmessage';
  LUri.From(lURL_TELEG);
  lHttp.Open(LUri.Server, LUri.Port, nlTcp, 10000, LUri.Https);

  LParam.AddContent('chat_id', chat_id);
  LParam.AddContent('text', text);

  lHttpResponse := lHttp.Post(LUri.Address, LParam, 'multipart/formdata');

And I received the response error 400 which is "Bad Request: message text is empty".
But I checked that text = 'sample text' not empty.

Am i do right usage THttpClientSocket and THttpMultiPartStream?

#6 Re: mORMot 2 » Possible value for TTHttpClientSocketRequestParams.DataType » 2024-01-28 00:36:22

I just want to know how to use THttpClientSocket.Post() with THttpMultiPartStream parameter.

So, DataType is as Mime Type.

Thanks ab.

#7 mORMot 2 » Possible value for TTHttpClientSocketRequestParams.DataType » 2024-01-27 08:14:26

bigheart
Replies: 3

Hi,

What values can be entered into the TTHttpClientSocketRequestParams.DataType field?

Please give some example.

#8 Re: mORMot 2 » CreateMissingTables function return error for MySql » 2023-12-11 07:55:11

OS: windows 10
Delphi : XE5
ZeosLib : 7.3

SQL : "show variables like '''version''"

#9 mORMot 2 » CreateMissingTables function return error for MySql » 2023-12-11 06:55:24

bigheart
Replies: 3

Hello,

When i connect the DB and execute CreateMissingTables(), then error is returned as below:

  TMyOrm = class(TOrm)
  private
    FCode: RawUTF8;
    FCode_name: RawUTF8;
    FCheck_item: Boolean;
  published
    property Code: RawUTF8 index 10 read FCode write FCode;
    property Code_name: RawUTF8 index 80 read FCode_name write FCode_name;
    property Check_item: Boolean read FCheck_item write FCheck_item;
  end;

FConnectProp := TSQLDBZEOSConnectionProperties.Create(
    TSQLDBZEOSConnectionProperties.URI(dMySQL, FHostIp + ':' + FPort), FDBName, FUserId, FPasswd);
  
FModel := TOrmModel.Create([TMyOrm]);
VirtualTableExternalRegisterAll(FModel, FConnectProp);

FOrmServer := TRestServerDB.Create(FStockBaseModel, SQLITE_MEMORY_DATABASE_NAME, False);

FOrmServer.CreateMissingTables(); <== Here is exception occurred 'Unknown MySQL data type!'

**) The actual return error funtion is ConvertMySQLHandleToSQLType() in ZDbcMySqlUtil.pas

Help me how to solve this problem.

#10 Re: mORMot 1 » Read Json value to record » 2022-12-09 08:47:26

Could you give me advise any other way to json array value to set record variant field?

#11 Re: mORMot 1 » Read Json value to record » 2022-12-09 08:23:41

The JsonData is from outside.

So i have to use dynamic array.

You mean that  array of double from json value can be stored in the record variant field using TDocVariantData?

#12 mORMot 1 » Read Json value to record » 2022-12-09 07:45:34

bigheart
Replies: 5

Hi,

In mormot2, how to read the json value and assign to record?

type
 TMyValue = packed record
   values: variant;
 end
 TMyValues = array of TMyValue;

 const JsonValues = '[{"values":[1,2,3]}]';

 var
   MyVal: TMyValues;
   DynArr: TDynArray;
 begin
   DynArr.Init(TypeInfo(TMyValues), MyVal);
   DynArr.LoadFromJSON(PUTF8(JsonValues);
  end;

After above function, MyVal is null.

How to load the jason array to variant field?

#15 mORMot 1 » What is the length(FAVICON_BINARY) » 2022-09-03 23:59:38

bigheart
Replies: 4

Hello,

in mormot.rest.http.server unit of mormot2, there is a code as below at 1568 line.

initialization
  assert(length(FAVICON_BINARY) = 510);

But in my environment (Win10, Delphi XE5) length(FAVICON_BINARY) is 491.

Please let me know which means the above assert(...) and why check the length?

#16 Re: mORMot 1 » How to access specific table in the db file » 2022-07-23 23:22:12

Hi, ab.

The TTest1 is defined in all of my sqlite files commonly.
Also, TTest2, TTest3 etc. is defined in each sqlite files with TTest1.

In this case, i just want to make a simple function to access only TTest1 over the db files without caring about other ORM like as TTest2, TTest3....

function SimpleAccessTest1(ADBFileName: string);
begin
   ...
   UpdateTest1(ADBFileName);
end;

#17 mORMot 1 » How to access specific table in the db file » 2022-07-23 07:30:05

bigheart
Replies: 3

Hello,

The sqlite3 DB file is created as below:

  TTest1 = class(TOrm)
       ...
  end;

  TTest2 = class(TOrm)
       ...
  end;

   ...

function CreateTestModel: TOrmModel;
begin
  result := TOrmModel.Create([TTest1, TTest2]);
end;
 

If i just know one table "TTest1", and have no information about "TTest2",
how can i access to the "TTest1" from the DB file?

Is there any function to access using table name in the DB file?

Please give me some advise.

Thanks in advance

#18 Re: mORMot 1 » JSONToObject problem in mormot2 » 2022-07-09 05:47:27

When debug, i got AV at function GetJsonPropName() of mormot.core.json.

P^ value is '"'

I think P^ should be instance pointer but it is string value.

function GetJsonPropName(var Json: PUtf8Char; Len: PInteger;
  NoJsonUnescape: boolean): PUtf8Char;
 ...

  if Len <> nil then
    Len^ := P - Name;
  P^ := #0; // ensure Name is #0 terminated <===== AV at here
  repeat
    inc(P);
    if P^ = #0 then
      exit;
  until P^ = ':';
  Json := P + 1;
  result := Name;
end;

Is there anyone to give me a hand?

#19 Re: mORMot 1 » JSONToObject problem in mormot2 » 2022-07-08 22:15:42

My circumstance is win10, XE5 and mormot2 3606.

And the result is LMyClass.c1.str = ''.

I don't  understand what is problem.

#20 mORMot 1 » JSONToObject problem in mormot2 » 2022-07-08 07:59:21

bigheart
Replies: 4

Hello.

I try to convert json to delphi nested object like below:

TOrm1 = class(TOrm)
  FStr: string;
published
  property str: string read FStr write FStr;
end;

TMyClass = class
  Fb: Boolean;
  Fc: TOrm1;
published
  property b1: Boolean read Fb write Fb;
  property c1 : Torm1 read Fc write Fc;
end;
....
  LMyClass := TMyClass.Create;
  Lutf8 := '{"b1": true, "c1": {"str": "abcd"}}';
  JsonToObject(LMyClass, Pointer(LUtf8), LValid, nil, JSONToOBJECT_TOLERANTOPTIONS);
  ShowMessage(LMyClass.c1.str); //<=== here

And i have  at Showmessage function.

   Result is LMyClass.c1.str = '' 

Could anyone please some advise to me how to use JSONToObject() with nested class?

Thanks in advance.

#21 mORMot 1 » Cann not debug into JsonDataProp function » 2022-06-17 02:57:44

bigheart
Replies: 1

Hello,

I have tested JsonToObject() in mormot2.

But i was not able to step into the JsonDataProp() in mormot.core.json using Delphi XE5 IDE debugger.

https://github.com/kuksundo/dev/blob/ma … onData.PNG

How can i add a break-point in this JsonDataProp() function?
And why debugging is not avalilable only this function?

Please give me some advise.

Thanks in advance.

#22 mORMot 1 » How to service website using THTTPApiServer » 2022-04-14 21:42:30

bigheart
Replies: 1

Hello,

I have created the simple web page using react.

How do i publish the web page using THttpApiServer?

Can you give me some advice to refer proper sample about this?

#23 mORMot 1 » How to get the text field from sqlite » 2019-07-05 11:39:30

bigheart
Replies: 2

Hello,

When i try to select RawUtf8 field from sqlite DB, the return is incorrect as below:

FText: RawUtf8 and the its contents as json array format like

["{\"Name\":\"DI_0065_0\",\"Description\":\"Something one\"}","{\"Name\":\"DI_0065_1\",\"Description\":\"Something two\"}"]

But the select using CreateAndFillPrepare function, result is blank.

How can i get the select from json array format string?

#24 mORMot 1 » Unsupported tkString is issued when RecordSaveJson is executed » 2019-05-10 08:56:32

bigheart
Replies: 1

Hi everyone,

I have some problem with mORMot.
Error is : TJSONCustomParseRTTI.CreateFromRTTI("TMyString") unspported tkString

Type
  TMyString = string[10];

TMyRec = record
 MyStr: TMyString;
end;

Var MyRec: TMyRec;

...

LUtf8 := RecordSaveJson(MyRec, TypeInfo(TMyRec)); <<=== Error throw here

How can i solve the above problem?

Thanks in advance.

#26 mORMot 1 » How to set subquery for sqlite in mORMot » 2018-04-20 02:30:43

bigheart
Replies: 2

Dear sir,

I'd like to query from sqlite as below:

  SELECT * FROM tracks WHERE bytes = (SELECT max(bytes) FROM tracks);

How to above query using TSQLRecord.CreateAndFillPrepare.

Thanks in advance.

#27 Re: mORMot 1 » how to use 'like' keyword for fuzzy query? » 2018-03-06 06:19:24

Try as below:

Orders := TOrders.CreateAndFillPrepare(db, 'SSDNo like ?', ['%'+Trim(edtQueryParam.Text)+'%']);

#28 mORMot 1 » How to unserialize from tsqlrecord.getJsonValues to TsqlRecord » 2017-09-20 12:06:34

bigheart
Replies: 0

Hi all,

I want to know how to retrieve the tsqlrecord fields data from json.

Json is made from tsqlrecord.getJsonValues.

TMyRec = packed record
  fdata: RawByteSting;
end;

TMyRecs = array of TMyRec;

TMySQL = class(TSQLRecord)
private
  ffiles: TMyRecs;
published
  files: TMyRecs read ffiles wirte ffiles;
end;
..........
var MySQL, YourSQL: TMYSQL;
     Lutf8: RawUtf8;
...
Lutf8 := MySQL.GetJSONValues(treu, true, soSelect);

**) Now how to fill the data to YourSQL from Lutf8?

#29 mORMot 1 » How to make generated code CreateFromVariant from Cross wrapper » 2015-07-14 00:58:27

bigheart
Replies: 1

Hello.

I'm using mORMot with Firemonkey generated client code from crossplatform wrapper as blow:

function TMyService.GetData(out ACollect: TMyCollect): Boolean;
var res: TVariantDynArray;
begin
  fClient.CallRemoteService(self,'GetData',2, // raise EServiceException on error
    [],res);
  ACollect.Free; // avoid memory leak
  ACollect := TMyCollect.CreateFromVariant(res[0]);
  Result := res[1];
end;

But when compile the client code, undeclared id "CreateFromVariant" is issued.

How can i find or create the CreateFromVariant function?

#30 mORMot 1 » sicClientDriven mode not allowed with TServiceCustomAnswer result » 2015-07-01 03:23:19

bigheart
Replies: 1

Hello!

I am using interface based service with mORMot.

And when RestServer.ServiceRegister(...,sicClientDriven ),  the error message is displayed as below:

"TServiceFactoryServer.Create: IMyService.GetMyService sicClientDriven mode not allowed with TServiceCustomAnswer result"

Of course, MyService's interface function is declared like

 

function GetMyService: TServiceCustomAnswer;

Is it impossible to use sicClientDriven mode with return value's TServiceCustomAnswer?

#31 mORMot 1 » Result is differ from ServiceRegister for sicShared and sicSingle » 2015-06-27 01:24:55

bigheart
Replies: 1

Hello!

When I execute from my code as below is OK:

//Server Side
RestServer :=  TSQLRestServerFullMemory(Model, JsonName, False, True);
RestServer.ServiceRegister(Client, [TypeInfo(IMyInterface)], sicShared);

//Client Sde
Client.ServiceRetister([TypeInfo(IMyInterface)], sicShared);

But not is OK as below

//Server Side
RestServer :=  TSQLRestServerFullMemory(Model, JsonName, False, True);
RestServer.ServiceRegister(Client, [TypeInfo(IMyInterface)], sicSingle); <=== Replace sicShared

//Client Sde
Client.ServiceRetister([TypeInfo(IMyInterface)], sicSingle);

Error message is displayed from Client Side just when above code is executed:

TServiceFactoryClient.Create(): server's IMyInterface contract differs from client's: expected["3625..."], received ["FAB6..."]

sicSingle or sicClientDriven is same result;

Only sicShared is OK.

What is the problem?

#32 Re: mORMot 1 » [mongoDB] How to use for dvArray kind of TDocVariant » 2014-10-10 08:55:25

LDoc contents are datetime and "a":"1" format data.

When debugging with "class procedure TDocVariant.GetSingleOrDefault" function in SynCommons.pas is excuted,

recursive call itself one time.

Trace into that function again,

TDocVariant(DocVariantArray).count is 5,

also TDocVariantData(DocVariantArray).Values[0] ~ TDocVariantData(DocVariantArray).Values[4] has exact data what i want.

But condition as "TDocVariant(DocVariantArray).count  <> 1" in GetSingleOrDefault(...) function,

result := default;

is excuted;

And next "result" is not assigned.

How can i have multiple data from AggregateDoc(...).

#33 Re: mORMot 1 » [mongoDB] How to use for dvArray kind of TDocVariant » 2014-10-02 09:13:58

I have executed as below:

var
  AQry: string;
  LDoc: variant;

  AQry := '{ aggregate: "COLLECTNAME",   pipeline: [{$sort:{_id:-1}},{$limit:5}], allowDiskUse: true}';
  FDB.RunCommand(BSONVariant(AQry), LDoc); 

with debugging LDoc, LDoc has a data, not null;

but

  showmessage(Utf8ToString(VariantToUtf8(LDoc.Value))); ===> "null" displayed

#34 mORMot 1 » [mongoDB] How to use for dvArray kind of TDocVariant » 2014-10-02 06:36:33

bigheart
Replies: 8

Hi!

I got some problem when using mORMot for TMongoCollection.AggregateDoc

  var
      LDoc: variant;
   
  LDoc:= Coll.AggregateDoc('{$sort:{_id:-1}},{$limit:1}', []); ===> single value is returned, OK!

but

  LDoc:= Coll.AggregateDoc('{$sort:{_id:-1}},{$limit:5}', []);  ===> multiple values are returned(5 values)

In this case, how to access the second value like: Lvar[1].value;

According to the manual:

  if LDoc._kind = ord(dvArray) then ===> error occured here that "Invalid variant type 0 invoke"
  begin
    showmessage(LDoc._(1));
  end;

Help me please!

#35 Re: mORMot 1 » [mongoDB] When using FindDocs function, "doc.VType = 275" error occur » 2014-09-17 06:50:52

I had already mORMot ver 1.18.

But I have updated from mORMotNightlyBuild.zip just before, So the problem is solevd.

Build number should be displayed as part of filename in the download site, i think.

Also, "Synopse mORMot Framework SAD 1.18.pdf" file should be modified as below at Page 884:

FindDocs('{name:?,age:{$gt,?}}',['John',21],res); ===> FindDocs('{name:?,age:{$gt:?}}',['John',21],res, Null);

Anyway thanks for your efforts and sharing.

#36 Re: mORMot 1 » [mongoDB] When using FindDocs function, "doc.VType = 275" error occur » 2014-09-17 05:29:36

I've solved the problem partially.

LColl.FindDocs('{V1:?}', ['6600'], ADocs); ===> Exception occured that "EBSONException : doc.VType = 275"
LColl.FindDocs('{V1:?}', ['6600'], ADocs, 'V1'); ===> Same above
LColl.FindDocs('{V1:?}', ['6600'], ADocs, 'NULL'); ===> **Succeed**

I don't know why succeeded.

#37 Re: mORMot 1 » [mongoDB] When using FindDocs function, "doc.VType = 275" error occur » 2014-09-16 23:14:16

Thanks your advice.

I've tried as:

    LColl.FindDocs('{V1:{$gt:?}}', ['6600'], ADocs);

Same error is occured.

Also as:

    LColl.FindDocs('{V1:?}', ['6600'], ADocs, 'V1'); ==> projcetion parmeter is 'V1'

Same thing.

I think that the problem is not the JSON format but the projection parameter type.

When and How to determine DocVariantType.VarType to 274 ?

And Why TVarData(doc).VType is 275 as different to DocVariantType.VarType?

===============================================

According to the code of TMongoRequest.BSONWriteParam() in synMongoDB.pas,
projection parameter treated as BSONVariantType, but when TBSONVariantData(projection).VBlob is null then typecast as TDocVariantData.
And exception occured.

How to aviod this problem?

#38 Re: mORMot 1 » [mongoDB] When using FindDocs function, "doc.VType = 275" error occur » 2014-09-16 08:53:47

Using Debug,  I can see that FindDocs function's argument "Projection" has 275 as VType in the TBSONVariant.FromBSONDocument().

And TMongoRequestQuery.Create()  -> BSONWriteParam() -> BSONWriteDoc() executed squentially.

In BSONWriteDoc(),     

if TVarData(doc).VType<>DocVariantType.VarType then
      raise EBSONException.CreateFmt('doc.VType=%d',[TVarData(doc).VType]) else ===> Exception eraise here

TVarData(doc).VType is 275,
DocVariantType.VarType is 274.

waht's the meaning of 274 or 275 ?

#39 mORMot 1 » [mongoDB] When using FindDocs function, "doc.VType = 275" error occur » 2014-09-16 02:32:32

bigheart
Replies: 8

Hello!

I try to get the documents as "V1" value is greater than "6600" like below:

LColl := FDB.CollectionOrCreate[FMongoCollectionName];
SetLength(ADocs, LDocsCount);
LColl.FindDocs('{V1:{$gt, ?}}', ['6600'], ADocs);

but i've got error message as

"EBSONException : doc.VType = 275"

What's the problem?

#40 Re: mORMot 1 » How to directly access to TDocVariant variable » 2014-08-19 04:17:03

I'm so messy!.

Lutf8: RawUtf8;
Doc2: variant;
...
LUtf8 := VariantSaveJSon(Doc);
Doc2 := _Json(Lutf8);
writeln(Doc2.Value(2));  //<--V1's value 1 is displayed

but,

i := 2;
writeln(Doc2.Value(i));  //<-- Variant method calls not supported

The result is different when constant 2 and variable i for Doc2.value(x).

Please give me some hint.

#41 mORMot 1 » How to directly access to TDocVariant variable » 2014-08-19 01:55:48

bigheart
Replies: 2

Hello!

I got some document from MongoDB to TDocVariant like below:

[{"_id":{"$oid":"53D75BD3ACD063FD19EA3250"}, "STime":{"$date":"2014-08-18T08:30:30"}, "V1":"1", "V2":"2"}]

I could get the data "1" at TDocvariant variable Doc.V1 and i want to direct access the value as Doc.Value[x] for "V1".

but i have got error message:

"Variant method calls not supported"

What could i do access the value using index?

#42 Re: mORMot 1 » How to get the last inserted document in mongoDB with mORMot » 2014-08-18 06:45:00

I do make some device's monitoring program.

The device status data is saved using TMongoCollection.Insert method by client #1 program to MongoDB in every second.

And the client #2 query the saved data which last inserted document and display them to monitor.

I'm not just want a document ID but a last inserted data.

#43 Re: mORMot 1 » How to get the last inserted document in mongoDB with mORMot » 2014-08-18 05:50:40

I have solved above problem as:

Doc := Coll.AggregateDoc('{ $sort : { _id: 1 } }, { $limit : 1 }',[]);

not $natural but _id.

Thanks.

#44 Re: mORMot 1 » How to get the last inserted document in mongoDB with mORMot » 2014-08-18 02:25:31

Thanks for your advice.

But when i execute as below:

Doc := Coll.AggregateDoc('{ $sort : { $natural : 1 } }, { $limit : 1 }',[]);

Null is returned to Doc variable.

Of course, Doc := Coll.FindDoc(); is OK!

What is the problem for getting the document?

Give me more advice, please.

Thanks in advance.

#45 mORMot 1 » How to get the last inserted document in mongoDB with mORMot » 2014-08-01 04:24:28

bigheart
Replies: 5

Hi!

I'm using mOROot for my private project.

And i want to know how to fetch the latest document from mongoDB server with Direct Access synMongoDB

In googling, i can find some command for mongoDB

db.foo.find().sort({$natural:1}).limit(1);

How to implement above command to FindDoc or FindJSON like below:

Client := TMongoClient.Create('host');
DB := Client.Database['dbname'];

Coll := DB.CollectionOrCreate['collect'];
Coll.FindDoc('{ $sort: {_id : -1 } } ', []);

help me please.

Board footer

Powered by FluxBB