#1 2014-08-22 14:54:40

muabbet
Member
Registered: 2014-08-20
Posts: 4

no added person httpserver please help

SERVER IS RUNNING BUT NO ADDED PERSON
PLEASE HELP
CLIENT OUTPUT

Add new person
Added Peson id :0
Name read from id0 from db =""
Press [ENTER] to quit

MY PERSON TABLE

CREATE TABLE PERSON (
  ID INTEGER NOT NULL,
  "NAME" VARCHAR(80) COLLATE PXW_TURK);

ALTER TABLE PERSON ADD PRIMARY KEY (ID);


SET TERM ^ ;

CREATE TRIGGER BI_PERSON_ID FOR PERSON
ACTIVE BEFORE INSERT
POSITION 0
AS
BEGIN
  IF (NEW.ID IS NULL) THEN
      NEW.ID = GEN_ID(PERSON_ID_GEN, 1);
END^

SET TERM ; ^



program Server;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  SynCommons,
  Mormot,
  mormotsqlite3,
  SynSQLite3Static,
  MormotDb,
  mormothttpserver,
  syndb,
  vcl.forms,
  syndbfiredac,
  FireDAC.Phys, FireDAC.Phys.IBBase,FireDAC.Phys.IB, FireDAC.Phys.FB,
  RestModel in 'RestModel.pas';
var
Aprops:TSQLDBFireDACConnectionProperties;
amodel:tsqlmodel;
arestserver:TSQLRestServerDB;
ahttpserver:TSQLHttpServer;
begin
  try
   TFDPhysFBDriverLink.Create(application).VendorLib:=ExtractFilePath(application.exename)+'fbclient.dll';
   aprops:=TSQLDBFireDACConnectionProperties.Create(firedac_provider[dfirebird],'E:\deneme.fdb','SYSDBA','masterkey');
   try
   amodel:=datamodel;
   try
   VirtualTableExternalRegisterAll(amodel,aprops);
   arestserver:=TSQLRestServerDB.Create(amodel,':memory:',false);
   try
   ahttpserver:=TSQLHttpServer.Create(server_port,[arestserver],'+',useHttpApiRegisteringURI);
    { TODO -oUser -cConsole Main : Insert code here }
    try
      ahttpserver.AccessControlAllowOrigin:='*';//allow cross site ajax queries
      writeln('Httpserver running'#10);
      write('Stop [enter] httpserver');
      readln;
    finally
      ahttpserver.Free;
    end;
   finally
     arestserver.Free;
   end;
   finally
     amodel.Free;
   end;
   finally
     aprops.Free;
   end;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
program Client;

{$APPTYPE CONSOLE}


uses
  sysutils,
  syncommons, //framework core
  mormot, //restful server orm
  mormothttpclient,//httpclient to mormot http server
  restmodel;
var
amodel:TSQLModel;
aclient:tsqlhttpclient;
aperson:tperson;
aid:integer;
begin
  amodel:=datamodel;
  try
    aclient:=TSQLHttpClient.Create('localhost',server_port,amodel);
    try
      writeln('Add new person');
      aperson := Tperson.Create;
      try
        aperson.name:='Name'+Int32ToUtf8(random(10000));
        aid:=aclient.Add(aperson,true);
      finally
        aperson.Free;
      end;
        writeln('Added Peson id :',aid);
        aperson:=tPerson.Create(aclient,aid);
        try
         writeln('Name read from id',aperson.ID,' from db ="'+aperson.name+'"');
        finally
          APERSON.Free;
        end;
    finally
      aclient.Free;
    end;
    write(#10'Press [ENTER] to quit');
    readln;
  finally
    amodel.Free;
  end;
  try
    { TODO -oUser -cConsole Main : Insert code here }
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Offline

#2 2014-08-22 20:08:31

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: no added person httpserver please help

You should let the ORM create the table and all needed indexes.
By running

arestserver.CreateMissingTables;

as explained in the doc and shown in the samples.

Using such a custom trigger is not compatible with how our ORM works.
If your table is already existing, you can map its fields if needed, but the primary key should not be computed on the DB side.
The ORM will compute the ID on its side.

Forget about writing the SQL our your side.
Use the ORM as designed.

Offline

#3 2014-08-23 08:10:43

muabbet
Member
Registered: 2014-08-20
Posts: 4

Re: no added person httpserver please help

Thanks
forgot to write "arestserver.CreateMissingTables;"

Offline

Board footer

Powered by FluxBB