You are not logged in.
Pages: 1
Hello,
The orm field is set type as below:
TTestColor = (Red,Green,Blue);
TTestColors = set of TTestColor;
TTestOrm = class(Torm)
FColors: TTestColors;
property
Colors: TTestColors read FColors write FColors;
end;
....
LTestOrm.Colors := Red + Blue;
then Is it possible to select the set field which included set value?
Likewise "Select Colors from TestOrm where colors in [Red]"
OK.
I can use the IDocList;
LDocList: IDocList;
LDocList := DocList(LUtf8);
LDocList.Len; // = 2
Thanx ab.
Then, to use the TDynArray with JSON Objects, how to set the init function?
LDynArr.LoadFromJSON(LUtf8); ==> LDynArr.Count = 0
--------------------------------------------------------------------------
LDynArr.Init(TypeInfo(TVariantDynArray), LDynUtf8);
LDynArr.LoadFromJSON(LUtf8); ==> still LDynArr.Count = 0
Is there any option to use JSON Object Array using TDynArray feature?
Hello.
Please review below code: Delphi XE5, windows10, latest version mormot2
LJson := '[{"Task":12,"PO":"aa"},{"Task":12,"PO":"bb"}]';
LDynArr.Init(TypeInfo(TRawUTF8DynArray), LDynUtf8);
LDynArr.LoadFromJson(PUTF8Char(LJson));
Check(LDynArr.Count > 0) ==> count is 0
Give me some advice.
Hi, ab
Is there a any way to use it by passing the table name as a parameter?
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?
Thank you chaa.
It works on your code.
...
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.
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?
I just want to know how to use THttpClientSocket.Post() with THttpMultiPartStream parameter.
So, DataType is as Mime Type.
Thanks ab.
Hi,
What values can be entered into the TTHttpClientSocketRequestParams.DataType field?
Please give some example.
OS: windows 10
Delphi : XE5
ZeosLib : 7.3
SQL : "show variables like '''version''"
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.
Could you give me advise any other way to json array value to set record variant field?
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?
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?
It works well.
Thanks ab.
My system's code page is 949.
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?
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;
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
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?
My circumstance is win10, XE5 and mormot2 3606.
And the result is LMyClass.c1.str = ''.
I don't understand what is problem.
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.
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.
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?
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?
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.
It works.
Thank you.
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.
Try as below:
Orders := TOrders.CreateAndFillPrepare(db, 'SSDNo like ?', ['%'+Trim(edtQueryParam.Text)+'%']);
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?
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?
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?
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?
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(...).
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
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!
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.
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.
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?
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 ?
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?
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.
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?
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.
I have solved above problem as:
Doc := Coll.AggregateDoc('{ $sort : { _id: 1 } }, { $limit : 1 }',[]);
not $natural but _id.
Thanks.
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.
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.
Pages: 1