#1 2015-06-08 15:22:05

Alvar Mayor
Member
Registered: 2015-06-05
Posts: 5

Cannot save to SQL Server table with FLOAT field

I'm learning mORMot.
I have a SQL Server 2008 R2 Database, named "test", with some tables,
I'm building a REST Server and a REST Client.
Rest Client loads one by one some tables into ClientDataset linked to a DBGrid, i edit values and save back to the server and the database.

One of these tables gives me problems: i can update and delete exixting records (inserted in SQL Server management studio), but i can't insert new records from my REST client app.
In the table in the database i always have only the records i inserted by management studio.

This is the table structure in SQL Server:
CREATE TABLE [dbo].[Prodotti](
    [ID] [bigint] IDENTITY(1,1) NOT NULL,
    [Descrizione] [nvarchar](20) NULL,
    [Prezzo] [float] NULL,
CONSTRAINT [PK_Prodotti] PRIMARY KEY CLUSTERED
(
    [ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]


This is the data model:

TProdotto = class(TSQLRecord)
  private
    fDescrizione: RawUTF8;
    fPrezzo: Double;
  published
    property Descrizione: RawUTF8 index 20 read fDescrizione write fDescrizione;
    property Prezzo:      Double           read fPrezzo      write fPrezzo;
  end;

This is the update code:

procedure TFMClient.BtnApplyCDS(aCDS:TClientDataSet;aCls:TSQLRecordClass;aMemo:TMemo);

var
  st   : TUpdateStatus;
  aRec : TProdotto;
  aID  : Integer;
  Ok   : Boolean;

begin
  if aCDS.ChangeCount > 0 then
  begin
    aCDS.DisableControls;
    aCDS.StatusFilter := [usModified, usInserted, usDeleted];

    fModel := DataModel;
    fClient := TSQLHttpClientWinHTTP.Create('localhost',SERVER_PORT,fModel);
    try
      while not aCDS.Eof do
      begin
        st := aCDS.UpdateStatus;
        case st of
          usModified : ...
                       end;
          usInserted : begin
                         aID := -1;
                         aRec := aCls.Create(fClient,aID);
                         aRec.Descrizione = aCDS.FieldByName('Descrizione').AsString;
                         aRec.Prezzo := aCDS.FieldByName('Prezzo').AsFloat;
                         try                           
                           aID := fClient.Add(aRec,true);
                         finally
                           aRec.Free;
                           aMemo.Lines.Add('Insert ID '+IntToStr(aID)+', Res = '+BoolToStr(aID > 0,True));
                         end;
                      end;
          usDeleted  : ...
                       end;
        end;
        aCDS.Next;
      end;
    finally
      aCDS.StatusFilter := [];
      if Assigned(fClient) then
        fClient.Free;
      if Assigned(fModel) then
        fModel.Free;
    end;
  end;
end;

This is an example of the sql sent by the REST server:
exec sp_executesql N'insert into dbo.Prodotti (ID,Descrizione,Prezzo) values (@P1,@P2,@P3)',N'@P1 bigint,@P2 nvarchar(4000),@P3 float',4,N'xxxx',45
go


Any idea?

Last edited by Alvar Mayor (2015-06-08 15:25:55)

Offline

#2 2015-06-08 15:31:20

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

Re: Cannot save to SQL Server table with FLOAT field

How do you connect to MS SQL Server?

What is the error message?

Offline

#3 2015-06-10 08:26:13

Alvar Mayor
Member
Registered: 2015-06-05
Posts: 5

Re: Cannot save to SQL Server table with FLOAT field

I connect to the server this way:
fProps := TOleDBMSSQLConnectionProperties.Create('WIN764\SQL2008','Test','sa','');

Debugging the SERVER (until now i debugged the CLIENT) i saw the error ... that was the ONLY table with ID as IDENTITY ...
Thank you for your help: without your question I would not debug the server, and I would not see the error.

Offline

Board footer

Powered by FluxBB