#1 2011-01-04 10:58:13

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Update table by TSQLRecord

Is there a way to update a Table by TSQLRecord. I have change one of my TSQLRecord object (I have added 2 field), is there a way to automatically update the table inside the database? Thanks

Offline

#2 2011-01-04 14:08:33

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

Re: Update table by TSQLRecord

If you added two published fields in your class type definition, they will be automatically added to an existing database.
When the framework open a database, it will check that all properties have their corresponding column in the database. If some column is missing, it is created by the framework.

So, in practice, you've nothing to do, no SQL to write or no method to call.
It's all automated by the framework.
That's the beauty of ORM!

Offline

#3 2011-01-04 15:10:19

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: Update table by TSQLRecord

This is fantastic! And if I delete a field or change a field type (for example from integer to string), what happens in this case?

Offline

#4 2011-01-04 21:07:43

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

Re: Update table by TSQLRecord

If you delete a field, it will stay in the database, and won't be accessed any more. There is no corresponding ALTER TABLE command in SQLite.

If you change a field type, it will break the database content. You should not do that, and instead create another type and do the conversion by hand. In this case, there is either no corresponding ALTER TABLE command in SQLite. From the SQLite point of view, the field type is not definitive: you can write a string into a field declared as an integer. But the framework will have problem in data conversion.

Offline

Board footer

Powered by FluxBB