#1 2017-02-12 10:28:13

jbroussia
Member
From: France
Registered: 2011-04-09
Posts: 74

SQLite3: how to map properties to column names ?

Hi,

I have a SQLite3 table "Artists" with the following definition:

CREATE TABLE "artists" (
"ArtistId"  INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"Name"  TEXT
);

That DB is statically linked (using SynSQLite3Static) to my server app.

How do I map the "ArtistId" field to the "ID" field required by mORMot so that I can use this model to query the DB ?

TSQLartists = class(TSQLRecord)
  private
  	fName: RawUTF8;
  published
  	property Name: RawUTF8 read fName write fName;
  end;

I don't think this is supposed to work ? (gives me an access violation)

Model.Props[TSQLartists].ExternalDB.MapField('ID', 'ArtistId');

Last edited by jbroussia (2017-02-12 10:29:22)

Offline

#2 2017-02-12 12:59:39

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

Re: SQLite3: how to map properties to column names ?

Did you define your table as external?
Mapping only works on external tables.

Offline

#3 2017-02-12 19:04:50

jbroussia
Member
From: France
Registered: 2011-04-09
Posts: 74

Re: SQLite3: how to map properties to column names ?

OooooK, I think I have it working now... I was doing...

Model.Props[TSQLartists].ExternalDB.MapField('ID', 'ArtistId');
VirtualTableExternalRegisterAll(Model, DBConnProps);

instead of...

VirtualTableExternalRegisterAll(Model, DBConnProps);
Model.Props[TSQLartists].ExternalDB.MapField('ID', 'ArtistId');

Offline

Board footer

Powered by FluxBB