Unable to drop a Column in SQLite

I tried the code below and some variations without success…


SQL_Cmd = "ALTER TABLE " + Table_Name + " DROP " + Column_Name + ";"

Yes, the two variables are filed with the correct values…

PS: DROP TABLE works fine (instead of ALTER TABLE…) so, it is really the SQL_Cmd line that have a problem.

Ideas ?

Xojo 2021r2.1
Monterey 12.4

is there any error code that would help ?

I do not remember (I slept since yesterday evening). I check right now…

Apparently, I have other troubles; the first attempts says nothing (it may work), the second told me about … missing TABLE…

I reboot the laptop since yesterday.

I come back in a bunch of minutes (coffee to drink).

Now it delete the TABLE…

To better understand:

I have a button to drop the selected Column (Right ListBox): both ListBoxes must have a selected Row or the button stop.

BTW: the other background color is yellow (20%), but I see a white background instead…

SqLite does not support dropping a column. You have to create a copy of the table (along with its data), drop the original table, recreate the original without the column, and copy the data back (minus the column you’re dropping). Many sqlite tools do this for you behind the scenes, but in Xojo you have to do all the work yourself.

I saw that command in their documentation. Link: ALTER TABLE DROP …

You may be right, because I used at first www.w2Schools.com/sql/ information… then when it does not worked, I checked sqlite.org docs (doswnloaded yesterday afternoon).


SQL_Cmd = "ALTER TABLE Spare_Parts DROP COLUMN SRP;"

Get Syntax Error Near DROP.

Previous reports were because a debug line I add yesterday (and forgot since)… sorry.

It looks like the newest versions of sqlite support that syntax, but the version in use by Xojo does not. Xojo uses an older version of sqlite, which does not support that and will throw an error.

In 2022r1.1 SQLite version is 3.36
The current version on sqlite.org is 3.39 (2022-06-25).

Too bad.

Supported from 3 35 and patched in 3.35.5:

https://www.sqlite.org/releaselog/3_35_5.html

Thank You Steve.

It works with Xojo 2022r1.1 !

I forgot why I do not want to use that version, but my code works there !

I can go on with that project.

PS: I forgot to read the Release notes… :ukraine:

1 Like

This snippet misses the COLUMN.

SQL_Cmd = "ALTER TABLE " + Table_Name + " DROP COLUMN " + Column_Name + ";"

And yes, in older versions of the engine we renamed the old table to some temp name, recreated a new table with the new structure, copied the data from temp to the new one, and deleted the temp table.

Drop column (and engine 3.36) is present since Xojo 2021r3

Both works with last Xojo.

MessageBox("SQLite version = " + App.gDB.LibraryVersion)

I hate when I can not find the information I’m looking for in a few searches.

I searched for Xojo Sqlite version, I looked at the Release Notes for 2022r1 and 2022r1.1 and I can’t find the Sqlite version in the latest Xojo.

Does anyone know where to find that information on the documentation?

What’s “both”?

I guess this broken syntax doesn’t:

Both commands, in Sqlite ‘COLUMN’ is optional.

WITH AND WITHOUT COLUMN (and with the last Xojo).

@AlbertoD Read the entry above yours for the answer…

Thank you, Emile, but how new users, without Xojo installed can know which version of SQLite is part of the released Xojo? Is there a place in the documentation for that?

  • I can’t find it in the release notes
  • I can’t find it in the system requirements
  • I can’t find it in sqlite database documentation for Xojo

I’m used to search in Google for something, like ‘Xojo Sqlite Version’ and find the answer, but can’t find it this time.

I needed to check, and it’s really true for SQLITE: