#1 Re: mORMot 1 » no added person httpserver please help » 2014-08-23 08:10:43

Thanks
forgot to write "arestserver.CreateMissingTables;"

#2 mORMot 1 » no added person httpserver please help » 2014-08-22 14:54:40

muabbet
Replies: 2

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.

#4 mORMot 1 » Mormot framework Firedac (Firebird) Connection Help » 2014-08-21 10:39:11

muabbet
Replies: 2

How can i get Customer list to dbgrid?
How can i get Selected record in dbgrid ?
How can i add new customer and get last id from generator?

TYPE
  TSQLCustomer = class(TSQLRecord)
  private
    fCUSTOMERID:INTEGER;
    fCUSTOMERCODE: RawUTF8;
    fNAME: RawUTF8;
  published
    property CUSTOMERID: INTEGER read fCUSTOMERID write fCUSTOMERID;
    property CUSTOMERCODE: RawUTF8 read fCUSTOMERCODE write fCUSTOMERCODE;
    property NAME: RawUTF8 read fNAME write fNAME;
  end;

procedure TForm1.Button1Click(Sender: TObject);
VAR
tcustomer :TSQLcustomer;
FCONNECTION:TSQLDBFireDACConnectionProperties;
fcon:TSQLDBFireDACConnection;
fModel: TSQLModel;
fClient: TSQLRestClientDB;
dbserver:TSQLRestServerDB;
table: TSQLTable;
TN:TRawUTF8Array;
  I: Integer;
begin
TFDPhysFBDriverLink.Create(Application).VendorLib := ExtractFilePath(Application.ExeName)+'fbclient.dll';
fconnection := TSQLDBFireDACConnectionProperties.Create(FIREDAC_PROVIDER[dFirebird],'E:\depo\DELPHI_XE5\kodlar\HalStokluFirebird\2014\DATABASE.fdb','SYSDBA','masterkey'); 
FCON:=TSQLDBFireDACConnection.Create(FCONNECTION);
FCON.Connect; 
//CONNECTİON SUCCESS
fModel := TSQLModel.Create([TSQLcustomer]);
VirtualTableExternalRegister(fModel, TSQLcustomer, fConnection, 'customer');
//HELP CREATE DBSERVER  CODE AND GET CUSTOMERLIST to dbgrid(datasource)

END;

Board footer

Powered by FluxBB