[Gambas-user] Sqlite, Delete field from table

Johny Provoost johny.provoost at ...27...
Mon Oct 19 18:11:14 CEST 2015


   Op 19-10-15 om 17:55 schreef Benoît Minisini:

Le 19/10/2015 17:38, Johny Provoost a écrit :

Hallo,

Is it possible to delete a field in a table from a SQLite database
through gambas code?

with
    FMain.tmpSQL = "ALTER TABLE " & FMain.lstTables.Text & " ADD " &
FieldNew.txtFieldname.Text & " " & FieldNew.cmbFieldType.Text
    FMain.openSQL = FMain.$hConnLocl.EXEC(FMain.tmpSQL)

I can add a new field, but if I replace " ADD " with DEL or DELETE, I
get errors.  I search the internet, but found nothing to delete directly
the field.

There's always a workaround through create tmp table, copy the fields to
save to it, delete the old table and rename the tmp table back to old
table.  But if it is can be done directly it is much easier.

If you can do that with a sqlite SQL request, then you can do that with 
Gambas and the Exec() method.

Then it's just a matter of reading the sqlite documentation:

[1]https://sqlite.org/lang_altertable.html

Apparently you can't remove a field with just a SQL request. You have to
follow your workaround as detailed in the SQLite documentation.

Regards,

   Thank you, I was 'afraid' of that.  I'm going for the workaround.

   --

   Vriendelijke Groeten

   Johny Provoost

   mailto: [2]johny.provoost at ...27...

   mailto: [3]johny.provoost at ...626...

   Website: [4]http://www.johnyprovoost.net

References

   1. https://sqlite.org/lang_altertable.html
   2. mailto:johny.provoost at ...27...
   3. mailto:johny.provoost at ...626...
   4. http://www.johnyprovoost.net/



More information about the User mailing list