Jump to content

Create New Column (SQLite)


undefined

Recommended Posts

This code create column if the column is already exists. But I want to create column if not exists. How can i fix it?

Edit: I tryed these but these give syntax error.

dbExec(database, "ALTER TABLE IF NOT EXISTS table_name ADD column_name data_type DEFAULT "..value) 
dbExec(database, "ALTER TABLE table_name ADD IF NOT EXISTS column_name data_type DEFAULT "..value) 

Link to comment
if not dbPoll(dbQuery(database, "SELECT column_name  FROM table_name"), -1) then 
    dbExec(database, "ALTER TABLE table_name ADD column_name data_type DEFAULT "..value) 
end 

I'm solved my problem with this code. It's add new column if the column not exists but it's give warning while adding column. Eventually it work! :lol:

If you have not given warning code, I'll wait! :roll:

Link to comment

What are you trying to achieve here? Altering a table should only occur once, I don't see the point of checking each time.

The first line does not check if the column exists or not. It checks if results were returned (even if empty) or not.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...