#1 2015-09-17 12:05:34

cypriotcalm
Member
Registered: 2015-02-18
Posts: 122

field as auto-increment for a MySQL table

Hi Ab,

is it possible to define a field as auto-increment within mORMot? Or should I exceute a custom SQL like "ALTER TABLE <fieldname> auto_increment" after a table was created?

Thank you!

Offline

#2 2015-09-17 14:16:48

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

Re: field as auto-increment for a MySQL table

There is no such feature built yet in the framework.
And I doubt there would be any soon.

IMHO such auto-increment fields should be part of the business logic, not handled of the storage layer.

If you trick at database level, you would not be able to switch from MySQL to another DB.

If you want an auto-incremented field, the TSQLRecord.ID would be one, available on all target databases.

Offline

#3 2015-09-17 14:44:30

cypriotcalm
Member
Registered: 2015-02-18
Posts: 122

Re: field as auto-increment for a MySQL table

ab wrote:

...
If you want an auto-incremented field, the TSQLRecord.ID would be one, available on all target databases.

What dou you mean?

Maybe we don't understand each other ;-) I explain my use case:

In generel, I want to have a possibility the mORMot framework define TSQLRecord.ID as an auto-increment ID.

I have en external DB. There are many tables which have the auto-increment ID.

I define the class and let mORMot create the corresponding table:

TMyTable = class(TSQLRecord)
published
  Field1: string;
  Field2: string;
end;
...
fServer.CreateMissingTables();
...

The table "mytable" is created, but the ID field is not auto_increment. I know that not all database support this functionality.

Maybe I repeat myself, but would it make sense to have something like:

  fServer.CreateMissingTables(0, [SetAutoIncrement4TSQLRecordID]);

Sorry for bothering you, maybe it's nonsense what I propose, but anyway ;-)

And thank you for your help!

Offline

Board footer

Powered by FluxBB