You are not logged in.
Pages: 1
Thanks ab!
sorry, I'll try again.
this link "http://synopse.info/forum/viewtopic.php?id=1500" has a reference to this property.
TSQLServerRest.ServerSideValidate := true;
The TSQLServerRest class, already had the ServerSideValidate property, if yes, why was excluded?
ok, now I understand. I'll need to use Delphi to my client app, and if I am working with client made with html / css / js, is it possible that my server app return me an error message if there was any violation in my restrictions?
it would be possible when making an insert / update / delete and there was no error return a message for example: {"success": "ok"} on error: {"error": "Message"}
I understand that I have to do to override TRecord.Validate class, as well I did. In fact I intend to do a review of the field "name" persona table, it not accepted short description.
I'm using as a basis the project "30 - MVC Server" -> MVCServer.dpr
The following model code. What else to do?
unit RESTModel;
interface
uses
SynCommons,
mORMot;
type
TPersona = class(TSQLRecord) // TSQLRecord has already ID: integer primary key
private
fName: RawUTF8;
public
function Validate(aRest: TSQLRest; const aFields: TSQLFieldBits=[0..MAX_SQLFIELDS-1];
aInvalidFieldIndex: PInteger=nil; aValidator: PSynValidate=nil): string; override;
published
/// ORM will create a NAME VARCHAR(80) column
property Name: RawUTF8 index 80 read fName write fName;
protected
end;
function DataModel: TSQLModel;
const
SERVER_ROOT = 'root';
SERVER_PORT = '888';
implementation
function TPersona.Validate(aRest: TSQLRest; const aFields: TSQLFieldBits=[0..MAX_SQLFIELDS-1];
aInvalidFieldIndex: PInteger=nil; aValidator: PSynValidate=nil): string;
var text :String;
begin
text := '';
// pseudo code
if length(name)<=5 then
text := '{"error":"should be above 5 characters"}';
result := UTF8ToString(text);
end;
function DataModel: TSQLModel;
begin
result := TSQLModel.Create([TPersona],SERVER_ROOT);
TPersona.AddFilterOrValidate('Name',TSynValidateText.Create('{"minlength": 5}'));
end;
end.
returning to the tests.
I used the Validate method of TSQLRecord class, doing override, code below:
...
TPersona = class(TSQLRecord)
private
fName: RawUTF8;
fEndereco: RawUTF8;
public
function Validate(aRest: TSQLRest; const aFields: TSQLFieldBits=[0..MAX_SQLFIELDS-1];
aInvalidFieldIndex: PInteger=nil; aValidator: PSynValidate=nil): string; override;
published
...
function TPersona.Validate(aRest: TSQLRest; const aFields: TSQLFieldBits=[0..MAX_SQLFIELDS-1];
aInvalidFieldIndex: PInteger=nil; aValidator: PSynValidate=nil): string;
var texto :String;
begin
texto := '{"error":"only test"}';
result := UTF8ToString(texto);
end;
at what time the validate method is called, I created a new record and did not return the message.
how to call the validate function.
I tried this code, also did not work, was recorded in the database with two characters
function DataModel: TSQLModel;
begin
result := TSQLModel.Create([TPersona],SERVER_ROOT);
TPersona.AddFilterOrValidate('Name',TSynValidateText.Create('{"minlength": 5, "MaxLength": 10}'));
end;
I found this code :
SQLRecordClasses[iClasses].AddFilterOrValidate(List^[iProps]^.Name,
TSynValidateText.Create(Format('{"MinLength":0,"MaxLength":%d}', [list^[iProps]^.Index])));
even putting this check is writing to the database, presenting no error.
function DataModel: TSQLModel;
begin
result := TSQLModel.Create([TPersona],SERVER_ROOT);
TPersona.AddFilterOrValidate('Name',TSynValidateText.Create(''));
end;
how can I use {"minlength": 5, "MaxLength": 10} in TSynValidateText, which syntax.
how to validate a field that is empty in app Restfull
I am passing this parameter : [{"id":8,"name":"aaaa"}, {"id":9,"name":"bbbb"}]
, but is only recorded the first record, how to record all.
URL : http://localhost:888/root/person
POST
CONTENT TYPE : application/json - [{"id":8,"name":"Chaves"}, {"id":9,"name":"Super"}]
I'm using httprequester to do my tests
congratulations to everyone for the great job they did, with little effort can insert, update and delete.
Not found in any language what the mormot offers.
I will test with Delphi xe5.
Thanks !
Unfortunately I will have to wait for the FPC RTTI
which projects in sample are compatible with fpc and are functional.
especially projects:
26 - RESTful ORM
28 - Simple RESTful ORM Server
30 - Server MVC
Thanks !
with MVCServer.dpr project have these errors:
MVCModel.pas(380,20) Error: Incompatible types: got "Pointer" expected "TPUtf8CharArray"
380,20 ====> fResults[f] := pointer(fFields[f]);
MVCModel.pas(387,36) Error: Incompatible types: got "PUTF8Char" expected "TPUtf8CharArray"
387,36 ====> fResults[r*fFieldCount+f] := P;
MVCModel.pas(541,80) Error: Incompatible type for arg no. 6: Got "<address of function(Pointer;Pointer):LongInt;Register>", expected "<procedure variable type of function(PUTF8Char;PUTF8Char):LongInt;Register>"
541,80 ====> AddSortedRawUTF8(tags,tagsCount,tagTable.GetU(r,meta_id),nil,-1,@StrIComp);
MVCModel.pas(579,77) Error: Incompatible type for arg no. 4: Got "<address of function(Pointer;Pointer):LongInt;Register>", expected "<procedure variable type of function(PUTF8Char;PUTF8Char):LongInt;Register>"
579,77 ====> pointer(tags),high(tags),tagTable.FieldBuffer(meta_id),@StrIComp);
the problem happens in the project "MainDemo" with this message: mORMoti18n.pas (2568.0) Fatal: Unexpected end of file
coincidentally both mORMoti18n.pas and SynDBZeos are commented, right?
sorry my english!
I'm new to the group.
I used fpc 3.1.1 and 1.5 Lazarus, I downloaded here: https://vdebris.wordpress.com/lazarus-2-7-1-snapshot/
Zeos 7.2
I use windows (32) - compiling example: 30 - MVC Server introduced this error in the compilation:
SynDBZEOS.pas (1170.0) Fatal: Unexpected end of file
Could someone give help to do?
Pages: 1