Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert double and float values to sqlite?

Tags:

android

sqlite

Following is my db creation code.

@Override     public void onCreate(SQLiteDatabase db) {         db.execSQL("CREATE TABLE " + TABLE_NAME + " (" +                  _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +                  TIME + " INTEGER, " +                  LONGI + " TEXT, "+                 LATI + " TEXT, "+                 SPEED + " TEXT, "+                 ACCU + " TEXT);");     } 

Then here goes the adding an data point code

private void addGeoDataEntry(double logi, double lati, float speed, float accu) {         SQLiteDatabase db = gpsDataHelper.getWritableDatabase();         ContentValues values = new ContentValues();         values.put(TIME, System.currentTimeMillis());         values.put(LONGI, logi+"");         values.put(LATI, lati+"");         values.put(SPEED, speed+"");         values.put(ACCU, accu+"");         db.insertOrThrow(TABLE_NAME, null, values);     } 

when I call

addGeoDataEntry(10.0,11.0,3.0f,1.1f); 

it gives the following error. How to fix this?

03-14 13:57:26.910: I/Database(27910): sqlite returned: error code = 1, msg = near "1.0": syntax error 
like image 282
dinesh707 Avatar asked Mar 14 '12 12:03

dinesh707


2 Answers

REAL is what you are looking for. Documentation of SQLite datatypes

like image 86
WarrenFaith Avatar answered Nov 04 '22 06:11

WarrenFaith


SQL Supports following types of affinities:

  • TEXT
  • NUMERIC
  • INTEGER
  • REAL
  • BLOB

If the declared type for a column contains any of these "REAL", "FLOAT", or "DOUBLE" then the column has 'REAL' affinity.

like image 43
Sandhu Avatar answered Nov 04 '22 08:11

Sandhu