-2

I am using the following code (in B4A) to delete an old CUSTOMERS table and then rename a new version of it. However, I always end up with a blank (new) CUSTOMERS table. If I don't do the rename the CUSTOMERS_NEW table is perfectly ok with the correct number of rows (1825).

sqlOBT.ExecNonQuery("DROP TABLE customers")                                     
sqlOBT.ExecNonQuery("ALTER TABLE newcustomers RENAME TO customers")
sqlobt.close

I am puzzled as to why it doesn't work.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215

1 Answers1

1

SQLite can be quite particular with its table naming conventions. You could try:

sqlOBT.ExecNonQuery("ALTER TABLE 'newcustomers' RENAME TO 'customers'")

Additionally, you may need to sandwich your ALTER TABLE command with a BEGIN/COMMIT TRANSACTION command. Using sqlite3, your code may look something like this:

sqlOBT.ExecNonQuery("BEGIN TRANSACTION")
sqlOBT.ExecNonQuery("ALTER TABLE 'newcustomers' RENAME TO 'customers'")
sqlOBT.ExecNonQuery("COMMIT TRANSACTION")

In python I understand this to be the case since the sqlite3 module automatically opens transactions in certain cases but not others. The documentation can be found here.

T. Pubz
  • 11
  • 5