Android Question Can I delete a field from a sqlite table?

Espinosa4

Active Member
Licensed User
Longtime User
Hello,
Anyone can help me please?
I'd like to delete a field from a sqlite table using code. Is it possible? I can't find info about this, sorry.

Thank you
Espinosa
 

eps

Expert
Licensed User
Longtime User
Upvote 0

Espinosa4

Active Member
Licensed User
Longtime User
Thanks eps. I'll try to looking for more info but reading your link it seems not supported.

Cheers
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
As you and eps surmised, I outlined below the sequential code steps to delete a column or columns (field) from a table:
B4X:
Dim TableOrig= "tblChemicals" , TableNew="tblChemicalsNew" As String

  SQL1.BeginTransaction
  'DELETE TABLE IF IT EXISTS
  txt="DROP TABLE IF EXISTS " & TableNew
  SQL1.ExecNonQuery(txt)

  'CREATE NEW TABLE WITH FEWER COLUMNS FROM ORIGINAL TABLE
  txt="CREATE TABLE IF NOT EXISTS " & TableNew & " AS SELECT Code, Chemical, Price, Unit " _
  & "FROM " & TableOrig
  SQL1.ExecNonQuery(txt)

  'DELETE ORIGINAL TABLE IF IT EXISTS
  txt="DROP TABLE IF EXISTS " & TableOrig
  SQL1.ExecNonQuery(txt)

  'RENAME NEW TABLE TO ORIGINAL TABLE NAME
  txt= "ALTER TABLE " & TableNew & " RENAME TO " & TableOrig
  SQL1.ExecNonQuery(txt)

  SQL1.TransactionSuccessful
  SQL1.EndTransaction
 
Upvote 0

Espinosa4

Active Member
Licensed User
Longtime User
Mahares, once again many many thanks for your help! A fantastic example!

Thanks to both for expending your time replying my question/s

Best regards
Espinosa
 
Upvote 0
Top