Dan Matthew Lucas
Dan Matthew Lucas

Reputation: 31

Sqlite Database Error duplicate column name

Error Code : 1 (SQLITE_ERROR) Caused By : SQL(query) error or missing database.
    (duplicate column name: Floor (code 1)
while compiling: 
CREATE TABLE LocalizationInfo(_item INTEGER PRIMARY KEY, idINT,Floor TEXT, Floor HeightTEXT, Adress TEXT ,LatitudeTEXT, LongitudeTEXT, Altitude TEXT,Pressure TEXT) 

I tried to save my data i.e. Floor,Floor height, GPS data and Adress which was obtained from another activity to another which implements the SQLite data for saving,loading,editting and deletion. I am always receiving this error message when i try to add the data from the other activity to the database by clicking the list or post button which directs the user to the database.

Upvotes: 3

Views: 10460

Answers (4)

Sana Ebadi
Sana Ebadi

Reputation: 7220

may u do not set the value for rows/columns of the table Ex:

private static final String NEWS_PUBLISHER = "news_publisher";
  private static final String NEWS_CONTENT = "news_content";
  private static final String NEWS_DATE = "news_date";

maybe u set one name for all this ...

Upvotes: 0

MikeT
MikeT

Reputation: 56948

Your issue is that

CREATE TABLE LocalizationInfo(
    _item INTEGER PRIMARY KEY, 
    idINT,
    Floor TEXT, 
    Floor HeightTEXT, 
    Adress TEXT ,
    LatitudeTEXT, 
    LongitudeTEXT, 
    Altitude TEXT,
    Pressure TEXT
)
  1. has a space between Floor and Height (hence the duplicate column name when trying to create the table) and
  2. doesn't have a space between Height/Latitude and Longitude and TEXT and also between id and INT.

Just correcting 1 would end up creating columns (which would likely result in ongoing issues) :-

  • _item (as expected),
  • idINT (you probably want ID with a type of INTEGER),
  • Floor (as expected),
  • FloorHeightText (you probably want FloorHeight with a type of TEXT),
  • Adress (as expected),
  • LatitudeTEXT (you probably want Latitude with a type of TEXT),
  • LongitudeText (you probably want Longitude with a type of TEXT),
  • Altitude (as expected),
  • Pressure (as expected)

Try changing to use :-

CREATE TABLE LocalizationInfo(
    _item INTEGER PRIMARY KEY, 
    id INT,
    Floor TEXT, 
    FloorHeight TEXT, 
    Adress TEXT ,
    Latitude TEXT, 
    Longitude TEXT, 
    Altitude TEXT,
    Pressure TEXT
)

You will need to either delete/clear the App's data or uninstall the App and then rerun the App, as the onCreate method won't run because the database exists.

Upvotes: 2

S.Grain
S.Grain

Reputation: 182

I think your problem caused by using whitespace for your colum name Floor Height. It would be good idea that you should use underscore instead of whitespace for column names. You can define your column names like floor, floor_height, gps_data and address.

Upvotes: 2

jonrizz
jonrizz

Reputation: 94

try not to put space between Floor Height, if you want you can do _ ie. Floor_Height TEXT

Upvotes: 2

Related Questions