Recent

Author Topic: SQLitePass - trouble adding column to table  (Read 5363 times)

victorhelsing

  • New Member
  • *
  • Posts: 14
SQLitePass - trouble adding column to table
« on: January 03, 2010, 11:49:10 pm »
I have just converted to using the SQLitePass package, which is very nice, but I am having trouble adding a column to a table, using the syntax:

SQLStr := Format ('BEGIN TRANSACTION; ALTER TABLE %s ADD COLUMN %s %s; COMMIT;',
                         [LocalDef.Name, RefDef.Name, FieldTypeStr]);
               if (NOT (FieldCreated)) then begin
               TempQuery.SQL.Text := SQLStr;
               TempQuery.Open;
               TempQuery.ApplyChanges;
               TempQuery.Close;                                     

This produces a line such as "... ALTER TABLE PROGRESSION ADD COLUMN Value; ..." which appears to execute without a problem, but when checking the database using another program (I am using the SQLite Manager addon for FireFox/Komodo Edit on Linux) I cannot find the new column in the database.

Not sure what I am doing wrong; is there something I need to do to write out the changes to the database file?

Thanks for the help.

cdbc

  • Sr. Member
  • ****
  • Posts: 274
    • http://www.cdbc.dk
Re: SQLitePass - trouble adding column to table
« Reply #1 on: January 04, 2010, 11:05:35 am »
Hi

Have you tried using 'TempQuery.ExecSql' instead of 'TempQuery.open' ?!?

Regards Benny
If it ain't broke, don't fix it ;)

Luc

  • New Member
  • *
  • Posts: 35
Re: SQLitePass - trouble adding column to table
« Reply #2 on: January 07, 2010, 07:28:10 pm »
Hi Victor,

Here is an example of creation and alteration of a table with the sqlitepass lib :

Code: [Select]
Procedure Something;
Const
CreateTableSQL =  'CREATE TABLE "NewTable" ([IntegerField1] INTEGER  NOT NULL, [IntegerField2] INTEGER  NOT NULL,'
                + '[TextField3] TEXT  NULL, [FloatField1] FLOAT  NULL);';
AlterTableSQL =   'ALTER TABLE "NewTable" ADD COLUMN [IntegerField5] INTEGER NULL;';
begin
With Db.Engine do
     begin
     Transaction.Start;
     ExecSQL(CreateTableSQL);
     ExecSQL(AlterTableSQL);
     Transaction.Commit;
     end;
end;

Where Db is an active TSqlitePassDatabase.
Hope it will help you
Regards.

Luc.
Win 10 (Running in Parallel VM - Mac OSX) - Lazarus 2.0.4 - i386-win32/win64

 

TinyPortal © 2005-2018