You are not logged in.
Renaming table/field name in Object definition just create new table/field. Changing field type, say change Integer to RawUTF8, gave nothing happen at all.
What is the correct way to do this? I read from other post someone execute "Alter Table" before CreateMissingTables(). Is it the correct way? Thanks!
Last edited by chula (2014-07-24 09:08:44)
Offline
If you use SQLite as the backend databae, SQLite itself doesn't support renaming a field.
Assume you have TSQLOldTable, now create a new class called TSQLNewTable with the new field definitions, call CreateMissingTables(); Then read old records from TSQLOldTable and add to TSQLNewTable;
drop tale TSQLOldTable.
Then change all references to TSQLOldTable in your code to TSQLNewTable.
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
If you use SQLite as the backend databae, SQLite itself doesn't support renaming a field.
Assume you have TSQLOldTable, now create a new class called TSQLNewTable with the new field definitions, call CreateMissingTables(); Then read old records from TSQLOldTable and add to TSQLNewTable;
drop tale TSQLOldTable.
Then change all references to TSQLOldTable in your code to TSQLNewTable.
Very thanks!
As I am new to the framework, do I have to copy the table by looping read/write progress, or there is a more effective way provided from the framework?
Offline
This is a sqlite limitation.
I see. Thanks!
Offline
edwinsn wrote:If you use SQLite as the backend databae, SQLite itself doesn't support renaming a field.
Assume you have TSQLOldTable, now create a new class called TSQLNewTable with the new field definitions, call CreateMissingTables(); Then read old records from TSQLOldTable and add to TSQLNewTable;
drop tale TSQLOldTable.
Then change all references to TSQLOldTable in your code to TSQLNewTable.
Very thanks!
As I am new to the framework, do I have to copy the table by looping read/write progress, or there is a more effective way provided from the framework?
Maybe execute a raw "insert into...select" SQL statement using EngineExecute() is faster and less of a hassle. Just an idea, I don't remember the details, please google yourself.
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
Yes, SQLite3 has the INSERT INTO .... SELECT syntax.
See http://www.sqlite.org/lang_insert.html
You have also the CREATE TABLE .. AS SELECT statement.
See http://www.sqlite.org/lang_createtable.html
Then DROP the previous table, and run ALTER TABLE ... RENAME TO ... to replace the previous table.
It should be faster to use those kind of syntax.
But only for Sqlite3 backend.
If you use external databases, pure CRUD / ORM within a BATCH process (and a transaction) is preferred.
And could be only slightly slower.
Ensure you create the TRIGGERs and INDEXs after having populated the new database.
It is most of the time faster to do so.
Offline