How to add a column to a table using a query?
(1) By uwrp on 2020-04-01 11:16:17 [link] [source]
Hello there, I am writing a gamemode and I am using sqlite3 for saving. Now when I need to add a column that has a float value, I can not directly add that in the phpliteadmin interface. I can only add integers and text columns with phpliteadmin. The problem here is that I have to recreate the entire table just to add a float column. So currently I am looking for a way to add a float column to a table by using a query. This is what I've tried so far: ALTER TABLE CHARACTERS ADD BLOOD FLOAT NOT NULL DEFAULT 100.0 WITH VALUES ALTER TABLE CHARACTERS ADD BLOOD FLOAT DEFAULT 0.0 ALTER TABLE CHARACTERS ADD COLUMN BLOOD FLOAT DEFAULT 0.0 All 3 query's above gave me a really odd error: Error: That's right, the error was empty... Any help would be appreciated.
(2) By Clemens Ladisch (cladisch) on 2020-04-01 12:10:22 in reply to 1 [source]
Works for me:
sqlite> create table characters([...]); sqlite> ALTER TABLE CHARACTERS ADD BLOOD FLOAT DEFAULT 0.0; sqlite> .schema CREATE TABLE characters([...], BLOOD FLOAT DEFAULT 0.0);I suspect that phpliteadmin is not able to access the file, or that the database is locked by another program.
As for the error message, you have to complain to the phpliteadmin authors.
(3.1) By uwrp on 2020-04-01 12:42:55 edited from 3.0 in reply to 2 [link] [source]
phpliteadmin has it's problems indeed. What is another good solution to replace phpliteadmin? I've added a query on a console command and it added the column.