#1 2014-08-28 14:08:27

Celso
Member
Registered: 2013-05-14
Posts: 55

Update

I have mapped field:

VirtualTableExternalRegister(aModel,
                                         TSQLCPU_USER,
                                         fProps,
                                         'CPU_USER');
            aModel.Props[TSQLCPU_USER].ExternalDB.MapField('ID','IDUSER');

When I try to update a record, shows an error that the IDUSER field does not exist.

v_user := TSQLCPU_USER.Create(frmDMServer.aServerDB,'IDUSER=?',[1]);
v_user.NAME := 'USER 2';
v_user.MOD_DATE := now;
v_user.MOD_USER := 9999;
frmDMServer.aServerDB.Update(v_user);

I need help to solve this

Offline

#2 2014-08-28 15:03:42

danielkuettner
Member
From: Germany
Registered: 2014-08-06
Posts: 330

Re: Update

I use it also with Firebird and it works fine.

I think when you map ID with IDUSER then you have to use ID and not IDUSER more.

Offline

#3 2014-08-28 15:25:19

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

Re: Update

Yes, on ORM side, i.e. from Delphi, you should use the TSQLCPU_USER fields, i.e. ID and not IDUSER.
Forget about the DB side! You are using an ORM! smile

You should have written:

v_user := TSQLCPU_USER.Create(frmDMServer.aServerDB,'ID=?',[1]);

The ORM will then compute and execute a SQL statement with the expected field, i.e. "SELECT * FROM CPU_USER WHERE IDUSER=?".
But you should not worry about the SQL, nor the table, any more.

Or even easier, and much more "mORMotish":

v_user := TSQLCPU_USER.Create(frmDMServer.aServerDB,1);

since you are reading one user per ID.

Offline

#4 2014-08-28 15:43:30

Celso
Member
Registered: 2013-05-14
Posts: 55

Re: Update

Thanks.

Offline

#5 2014-08-28 15:59:47

Celso
Member
Registered: 2013-05-14
Posts: 55

Re: Update

Another issue.
How do I that are not created index in my tables?
When I connect to my database, the system is creating some index's automatically, for example:

CREATE UNIQUE INDEX DESCENDING "NDXCPU_PROCESSIDPROCESS" ON "CPU_PROCESS Nord IDPROCESS" );

Offline

#6 2014-08-28 16:54:33

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

Re: Update

For a particular table, you can simply override the default class procedure TSQLRecord.InitializeTable() to do nothing (i.e. do not call inherited).

I've also just added a new "Option: TSQLInitializeTableOptions parameter" to TSQLRestServer.CreateMissingTables and TSQLRecord.InitializeTable methods, to tune underlying table creation (e.g. disable indexes creation).
See http://synopse.info/fossil/info/c7717b0ff9

  /// the possible options for TSQLRestServer.CreateMissingTables and
  // TSQLRecord.InitializeTable methods
  // - itoNoIndex4ID won't create the index for the main ID field
  // - itoNoIndex4UniqueField won't create indexes for "stored AS_UNIQUE" fields
  // - itoNoIndex4NestedRecord won't create indexes for TSQLRecord fields
  // - itoNoIndex4RecordReference won't create indexes for TRecordReference fields
  TSQLInitializeTableOption = (
    itoNoIndex4ID, itoNoIndex4UniqueField,
    itoNoIndex4NestedRecord, itoNoIndex4RecordReference);

  /// the options to be specified for TSQLRestServer.CreateMissingTables and
  // TSQLRecord.InitializeTable methods
  TSQLInitializeTableOptions = set of TSQLInitializeTableOption;

Offline

#7 2014-08-28 23:40:08

Celso
Member
Registered: 2013-05-14
Posts: 55

Re: Update

thanks

Offline

#8 2014-09-04 19:35:49

Celso
Member
Registered: 2013-05-14
Posts: 55

Re: Update

I am using TSQLRestClientURI with ExecuteList and Tclientdataset. Everything is working well, but I am facing a problem. When I delete a record by command TSQLRestClientURI.Delete , works perfectly when I give the command UpdateFromServer. The record does not appear in my grid. However when I exclude the registry directly from database, the record does not come out of my grid, even giving the command UpdateFromServer.

How do I that records are what really are in the database, regardless of whether form excluded by application or directly in the database?

Offline

#9 2014-09-04 19:55:41

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

Re: Update

You should not update the database directly, or the ORM gets unsynchronized.
If you write directly to the database, you need to disable the mORMot caches for the table.

Offline

#10 2014-09-04 21:57:59

Celso
Member
Registered: 2013-05-14
Posts: 55

Re: Update

thanks

Offline

Board footer

Powered by FluxBB