#1 2015-07-14 18:55:50

restneophyte
Member
Registered: 2014-11-18
Posts: 26

CreateAndFillPrepare Hit and Miss

Using Delphi XE8 and the latest nightly build of mORMot, I have created a REST server in which I have the following TSQLRecord class defined:

  TCustomers = class(TSQLRecord)
  protected
    fCustomerID: Integer; 
    fCustomerStatus: Boolean; 
    fCustomerName: String; 
    fCustomerDate: TDateTime; 
  published
    property CustomerID: Integer read fCustomerID write fCustomerID;
    property CustomerStatus: Boolean read fCustomerStatus write fCustomerStatus;
    property CustomerName: String index 255 read fCustomerName write fCustomerName;
    property CustomerDate: TDateTime read fCustomerDate write fCustomerDate;
  end;

After generating my 'mORMotClient' unit, I created a REST client that will be using the 'TCustomers' type defined above.

If I run the following from within my client, the 'FillOne' is successful:

var
  iClient: TSQLRestClientHTTP;
  iCustomerSQLRecord: TCustomers;
begin
  iClient := GetClient('localhost');
  try
    // Let's locate the 'customer' record
    iCustomerSQLRecord := TCustomers.CreateAndFillPrepare(iClient, 'ID, CustomerID', 'ID = ?', [aCustomerID]);
    try
      if (iCustomerSQLRecord.FillOne) then
      begin
        ...
      end;
    finally
      iCustomerSQLRecord.Free;
    end;
  finally
    iClient.Free;
  end;

But if I run the following from within my client, the 'FillOne' is UNSUCCESSFUL:

var
  iClient: TSQLRestClientHTTP;
  iCustomerSQLRecord: TCustomers;
begin
  iClient := GetClient('localhost');
  try
    // Let's locate the 'customer' record
    iCustomerSQLRecord := TCustomers.CreateAndFillPrepare(iClient, 'ID, CustomerID, CustomerName, CustomerDate', 'ID = ?', [aCustomerID]);
    try
      if (iCustomerSQLRecord.FillOne) then
      begin
        ...
      end;
    finally
      iCustomerSQLRecord.Free;
    end;
  finally
    iClient.Free;
  end;

I must be doing something wrong. But I am unable to figure out what I am doing wrong. Any inputs would be greatly appreciated. Thanks.

Offline

#2 2015-07-14 19:28:54

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

Re: CreateAndFillPrepare Hit and Miss

Is the table available in the SQlite3 database file?

Enable the logs, and add detailed .map debug info, and run it again.

Also try to debug the server side, in TSQLRestServer.URI().

Offline

#3 2015-07-14 21:36:58

restneophyte
Member
Registered: 2014-11-18
Posts: 26

Re: CreateAndFillPrepare Hit and Miss

Thanks for your input.

After reading your recommendations, I realized that my original post was not complete and accurate. Indeed, I had forgotten to mention that my database is a 'mysql' one. I understand that the type of database used might not be relevant to my problem but I should not have forgotten to mention it in the first place.

I had also forgotten to mention that I had enabled the logs. However, at this point in time, I have not added a '.map' file to my application as I am still reading the documentation concerning these types of files.

Finally, when dealing with the "not successful" statement, the 'CreateAndFillPrepare' should have read:

iCustomerSQLRecord := TCustomers.CreateAndFillPrepare(iClient, 'ID, CustomerID, CustomerStatus, CustomerName, CustomerDate', 'ID = ?', [aCustomerID]);


It is when I noticed the missing 'CustomerStatus' from my supposedly unsuccessful 'CreateAndFillPrepare' statement that I found a solution to my problem. In my 'mysql' database 'CustomerStatus' was defined as a 'bit' field. As soon as I changed its type to 'tinyint,' everything worked as expected.

Offline

#4 2015-07-15 08:31:32

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

Re: CreateAndFillPrepare Hit and Miss

Happy you worked it out.

smile

Offline

Board footer

Powered by FluxBB