#1 Re: mORMot 1 » Infra Sample » 2016-03-29 17:54:13

Hello
Also tried to use the units
dddToolsAdminDB.pas
dddToolsAdminLog.pas
dddToolsAdminMain.pas
Without success, we need an example.
Thanks.

#2 mORMot 1 » Http Status 0 and not 200 on MVC » 2015-10-26 15:52:15

fabioquestor
Replies: 0

hello ab

On 30 - MVC Server\

http://localhost:8092/blog/Default

because this status http returning 0 Finished
this causes problem in ajax?

should not return 200 OK?

and blog.css comes right from the get 200 OK

thank FabioQuestor

#4 Re: mORMot 1 » TMVCApplication function : TMVCAction with param array » 2015-06-30 19:28:22

source original

function TSQLRestServerURIContext.GetInputAsTDocVariant: variant;
var i: integer;
    v: variant;
    MultiPart: TMultiPartDynArray;
begin
  VarClear(result);
  FillInput;
  if fInput<>nil then begin
    with TDocVariantData(result) do begin
      InitFast;
      for i := 0 to (length(fInput) shr 1)-1 do begin
        GetVariantFromJSON(pointer(fInput[i*2+1]),false,v,@JSON_OPTIONS[true]);
        AddValue(fInput[i*2],v);
      end;
    end;
  end else
  if InputAsMultiPart(MultiPart) then
    with TDocVariantData(result) do begin
      InitFast;
      for i := 0 to high(MultiPart) do
        with MultiPart[i] do
          if ContentType=TEXT_CONTENT_TYPE then begin
            RawUTF8ToVariant(Content,v);
            AddValue(Name,v); // append as regular "Name":"TextValue" field
          end else // append binary file as an object, with Base64-encoded data
            AddValue(Name,_ObjFast(['data',BinToBase64(Content),
              'filename',FileName,'contenttype',ContentType]));
    end;
end;

changer source

function TSQLRestServerURIContext.GetInputAsTDocVariant: variant;
var i,
    APos: integer;
    v,
    vresult: variant;
    MultiPart: TMultiPartDynArray;
    AObjectName,
    AParName: RawUTF8;
    AFoundObject: Boolean;
begin
  AObjectName := '';
  VarClear(vresult);
  FillInput;
  if fInput<>nil then begin

    AFoundObject := False;
    APos := pos('.', fInput[0]);
    if (APos > 0) then begin
      AObjectName := Copy(fInput[0], 1, APos - 1);
      for i := 0 to (length(fInput) shr 1)-1 do begin
        AParName := fInput[i*2];
        APos := pos('.', AParName);
        if (APos > 0) and (AObjectName = Copy(AParName, 1, APos - 1)) then begin
          AFoundObject := True;
        end else begin
          AFoundObject := False;
          continue;
        end;
      end;
    end;

    with TDocVariantData(vresult) do begin
      InitFast;
      for i := 0 to (length(fInput) shr 1)-1 do begin
        GetVariantFromJSON(pointer(fInput[i*2+1]),false,v,@JSON_OPTIONS[true]);
        AParName := fInput[i*2];

        if AFoundObject then
          AParName := Copy(AParName, APos + 1, MaxInt);

        AddValue(AParName,v);
      end;
    end;
  end else
  if InputAsMultiPart(MultiPart) then
    with TDocVariantData(vresult) do begin
      InitFast;
      for i := 0 to high(MultiPart) do
        with MultiPart[i] do
          if ContentType=TEXT_CONTENT_TYPE then begin
            RawUTF8ToVariant(Content,v);
            AddValue(Name,v); // append as regular "Name":"TextValue" field
          end else // append binary file as an object, with Base64-encoded data
            AddValue(Name,_ObjFast(['data',BinToBase64(Content),
              'filename',FileName,'contenttype',ContentType]));
    end;
  if AFoundObject then begin
    VarClear(result);
    with TDocVariantData(result) do begin
      InitFast;
      AddValue(AObjectName,vresult);
    end;
  end else
    result := vresult;
end;

input

p.a1=5&p.a2=dfasdfa

before change

{"p.a1":5,"p.a2":"dfasdfa"}

after change

{"p":{"a1":5,"a2":"dfasdfa"}}

sorry the few sources thought, but I'm in a hurry.

it can be better and integer, or change to a different concept, provided it is nome.property


this works with this sources

function TnWebMVCMenu.CadastroSalvar3(const p: variant): TMVCAction;
begin
  GotoView(result,'Cadastro',
    ['pp1',p.a1,
     'pp2',p.a2])
end;

#5 Re: mORMot 1 » TMVCApplication function : TMVCAction with param array » 2015-06-30 17:49:44

But like putting a json array as value?

		<form class="form-horizontal" action="CadastroSalvar2" method="post">
		  <div class="form-group">
			<label for="input1" class="col-sm-2 control-label">ID</label>
			<div class="col-sm-3">
			  <input type="number" class="form-control" id="input1" name="p[1]" placeholder="ID" value="1">
			</div>
			<div class="col-sm-1">
			  <input class="btn btn-default" type="button" value="...">
			</div>
			<div class="col-sm-6">
			  <input type="number" class="form-control" id="input1" placeholder="ID" value="1">
			</div>
		  </div>
				  <div class="form-group">
			<label for="input2" class="col-sm-2 control-label">Descricao</label>
			<div class="col-sm-3">
			  <input type="text" class="form-control" id="input2" name="p[2]" placeholder="Descricao" value="teste 1">
			</div>
			<div class="col-sm-1">
			  <input class="btn btn-default" type="button" value="...">
			</div>
			<div class="col-sm-6">
			  <input type="text" class="form-control" id="input2" placeholder="Descricao" value="teste 1">
			</div>
		  </div>
				  <div class="form-group">
			<label for="input3" class="col-sm-2 control-label">Preco</label>
			<div class="col-sm-3">
			  <input type="number" class="form-control" id="input3" name="p[3]" placeholder="Preco" value="10.5">
			</div>
			<div class="col-sm-1">
			  <input class="btn btn-default" type="button" value="...">
			</div>
			<div class="col-sm-6">
			  <input type="number" class="form-control" id="input3" placeholder="Preco" value="10.5">
			</div>
		  </div>
		  
		  <div class="form-group">
			<div class="col-sm-offset-2 col-sm-10">
			  <button type="submit" class="btn btn-default">Salvar</button>
			</div>
		  </div>
		</form>	  

For

function TnWebMVCMenu.CadastroSalvar2(const p: TRawUtf8DynArray): TMVCAction;
begin
  GotoView(result,'Cadastro',
    ['pp1',p[0],
     'pp2',p[0]])
end;

But don´t go


I tried so well.

...
name="p.a1" 
...
name="p.a2" 
...
name="p.a3" 
...

For

function TnWebMVCMenu.CadastroSalvar3(const p: variant): TMVCAction;
begin
  GotoView(result,'Cadastro',
    ['pp1',p.a1,
     'pp2',p.a2])
end;

Neither.

Request Payload
p={"a1":1,"a2":"dfasdfa"}

Thus it works for CadastroSalvar3, but I do not know how to do post the form to do so.

#6 Re: mORMot 1 » TMVCApplication function : TMVCAction with param array » 2015-06-30 01:21:49

don't

only first param:

function TnWebMVCMenu.CadastroSalvar3(const p: variant): TMVCAction;
begin
  GotoView(result,'Cadastro',
    ['pp1',p])
end;

{"ClassName":"EMVCException","Address":"0B91DB80","Message":"TMVCRendererFromViews.CommandRunMethod: InWebMVCMenu.CadastroSalvar2() execution error","context":"TMVCRendererFromViews.ExecuteCommand"}

function TnWebMVCMenu.CadastroSalvar2(const p: TRawUtf8DynArray): TMVCAction;
begin
  GotoView(result,'Cadastro',
    ['pp1',p[0]])
end;

General
Remote Address:[::1]:8080
Request URL:http://localhost:8080/npmnGem/CadastroSalvar2
Request Method:POST
Status Code:500 Internal Server Error
Response Headers
view source
Accept-Encoding:synlz,gzip
Access-Control-Allow-Origin:
Content-Encoding:gzip
Content-Length:1372
Content-Type:text/html; charset=UTF-8
Date:Tue, 30 Jun 2015 01:15:45 GMT
Server:mORMot/1.18.1563 (Windows) Microsoft-HTTPAPI/2.0
Server-InternalState:0
X-Powered-By:Synopse mORMot 1.18.1563 http://synopse.info
Request Headers
view source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate
Accept-Language:pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:20
Content-Type:application/x-www-form-urlencoded
Host:localhost:8080
Origin:http://localhost:8080
Referer:http://localhost:8080/npmnGem/Cadastro?Scope={%22Class%22:%22TnGemDMUsuarioGrupoUsu%22}
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36
Form Data
view source
view URL encoded
p:1
p:teste 1
p:10.5

#7 mORMot 1 » TMVCApplication function : TMVCAction with param array » 2015-06-29 20:58:52

fabioquestor
Replies: 8

how can I make a function that I can spend an array parameter as it comes with named parameter. but I have dynamic parameters. each time I call the function with a different number of parameters, do not even know how to do on Delphi or in html.

example:

not

    function Login(const LogonName,PlainPassword: RawUTF8): TMVCAction;

yes

    function Login(const params: array of RawUTF8): TMVCAction;

not

    function CadastroSalvar(const p1, p2, p3, p4: RawUTF8): TMVCAction;

yes

    function CadastroSalvar(const p: TObjectList): TMVCAction;

Thanks

#9 Re: mORMot 1 » I need aSubURI in TMVCApplication.Default » 2015-06-26 17:38:21

Hello AB

Really the test 30 is working.

But in my not.

What I am doing is a facade layer to my legacy system.

I have the forms of records that would use the url: http: // localhost: 8080 / ntoCadastro / TnGemDMUsuarioGrupoUsu / default

and only have one TnWebServerHTMLCad = class (TSQLRestServerFullMemory)

registered with TnWebServerHTMLCad.Create (TSQLModel.Create ( 'ntoCadastro'));
constructor TnWebServerHTMLCad.Create(aModel: TSQLModel;
  aHandleUserAuthentication: boolean);
begin
  inherited;
  FMVC := TnWebMVCCad.Create;
  FMVC.Start(Self);
end;

procedure TnWebMVCCad.Start(aServer: TSQLRestServer);
var
  aViews: TMVCViewsMustache;
  params: TMVCViewsMustacheParameters;
  i: Integer;
  s: String;

begin
  inherited Start(aServer,TypeInfo(InWebMVCCad));

  fillchar(params,sizeof(params),0);
  params.ExtensionForNotExistingTemplate := '.html';
  params.Helpers := TSynMustache.HelpersGetStandardList;
  params.FileTimestampMonitorAfterSeconds := 5;
  params.Folder := ExeVersion.ProgramFilePath+'Views'+PathDelim+ClassName+PathDelim;

  aViews := TMVCViewsMustache.Create(
    fFactory.InterfaceTypeInfo, params,
  {$ifdef WITHLOG}
      fRestServer.LogClass) else
  aViews.fLogClass := fRestServer.LogClass;
  {$else}
      TSQLLog);
  {$endif}

  fMainRunners := TStringList.Create;;

  for i := 0 to FnActionListDireitos.ActionCount - 1 do
  begin
    if FnActionListDireitos.Actions I .Tag = 1 then
    begin
      s := FnActionListDireitos.Actions I .Name;
      if Pos('npmn', s) = 1 then
        s := Copy(s, 9, MaxInt);

      s := Copy(s, 4, MaxInt);

      if fMainRunners.IndexOf(s) < 0 then
      begin
        fMainRunners.AddObject(s,
          TMVCRunOnRestServer.Create(Self, nil, s, aViews).
            SetCache('Default',cacheRootIfNoSession,15));
      end;
    end;
  end;
end;

"TnGemDMUsuarioGrupoUsu" this is registration of name

By this accuracy to know this information in the method procedure TnWebMVCCad.Default (var Scope: variant);

not like to do http://localhost:8080/ntoCadastro/default?cad=TnGemDMUsuarioGrupoUsu

but it will be the way if not consequir access this information.


actually I do not know how I should structure the class or several classes, TMVCApplication because it would not work with all methods in a TMVCApplication, for this I am well structured.

I have more than 6,000 objects from registration, appointments, processes and reports.

but I will try to do without having to make an html for each object.

I wanted to have a class for each object type.

The main question is how to structure a MVC with many pages (6000+) ????

#10 mORMot 1 » I need aSubURI in TMVCApplication.Default » 2015-06-25 21:02:50

fabioquestor
Replies: 4

aSubURI is passed in TMVCRunOnRestServer.Create (aApplication: TMVCApplication;
   aRestServer: TSQLRestServer; const aSubURI: RawUTF8;
   aViews: TMVCViewsAbtract; aPublishOptions: TMVCPublishOptions);

I tried the tip in post http://synopse.info/forum/viewtopic.php?id=2136

  Result: = ServiceContext.Request.InHeader ['host'];

but me the av

debug tried but without success.

thank you

very good your framework

#11 Re: mORMot 1 » Table not Id: integer » 2014-05-20 19:54:49

thank you
I will be working

I've searched but have not found a ready system using mORMot, have to get me some?

A real life example.

Except mORMot\SQLite3\Samples\MainDemo\SynFile.dpr

PS I'm working on a mORMot DBExpress to drive, so I will send you complete.

#12 mORMot 1 » Table not Id: integer » 2014-05-20 16:55:51

fabioquestor
Replies: 6

Hello

I have a legacy base, with over 1000 tables , most with multiple primary key without ID , how can I do to use ORM ?
The only way is to convert the tables to have id?
example :

type
  / / / STATE Table
  / / - Type definition auto-generated by SynDBExplorer at 1:18 20/05/2014 13:44:50
  / / From STATE
  / / - Note que the ORM will add one missing ID field via:
  / / $ ALTER TABLE ADD STATE ID INTEGER
  TSQLSTATE = class ( TSQLRecord )
  protected
    fSTATEABBREVIATION : RawUTF8 ;
    fSTATENAME : RawUTF8 ;
    fSTATEBRAZIL : Boolean ;
    fCOUNTRYCODE : Int64 ;
  published
    / / / Match STATE.SIGLA STATE [ CHAR 2 0 0 ] * primary key
    property STATEABBREVIATION: RawUTF8 index 2 read fSTATEABBREVIATION write fSTATEABBREVIATION;
    / / / Match STATE.STATENAME [ VARCHAR 30 0 0 ]
    property STATENAME: RawUTF8 index 30 read fSTATENAME write fSTATENAME;
    / / / Match STATE.STATEBRAZIL [ CHAR 1 0 0 ]
    property STATEBRAZIL: Boolean index 1 read fSTATEBRAZIL write fSTATEBRAZIL;
    / / / Match STATE.COUNTRYCODE [ SMALLINT ] *
    property COUNTRYCODE: Int64 read fCOUNTRYCODE write fCOUNTRYCODE;
  end ;

Got any tips ?

#13 mORMot 1 » FireDac Problem with TDateTime and double » 2014-05-19 14:53:51

fabioquestor
Replies: 1
type
  TSQLmORMotTest = class(TSQLRecord)
  private
    fLAT: double;
    fDataInicio: TDateTime;
  published
    property LAT: double read fLAT write fLAT;
    property DataInicio: TDateTime read fDataInicio write fDataInicio;
  end;

...

use: TSQLDBFireDACConnectionProperties.Create(FIREDAC_PROVIDER[dFirebird],...);

...

var
  AmORMotTestAdd,
  AmORMotTestRet: TSQLmORMotTest;

begin

  AmORMotTestAdd := TSQLmORMotTest.Create;

  AmORMotTestAdd.LAT := 987.321;
  AmORMotTestAdd.DataInicio := EncodeDate(2014, 10, 7);

  AID := DBServer.Add(AmORMotTestAdd, True);

  AmORMotTestRet := TSQLmORMotTest.Create(DBServer, AID);

  CheckEquals(ObjectToJSON(AmORMotTestAdd), ObjectToJSON(AmORMotTestRet)); //error

end;

Solution:

{ SynDBDataset.TSQLDBDatasetStatementAbstract }

function TSQLDBDatasetStatementAbstract.ColumnTypeNativeToDB(aNativeType: TFieldType): TSQLDBFieldType;
begin
  ...
    ftSingle:
      result := SynCommons.ftCurrency;
    ftTimeStamp:
      result := SynCommons.ftDate;
  ...
end;

Board footer

Powered by FluxBB