1

I have a small problem. Can anyone please tell me how to append String value after SQLite function in Insert Statement. Code line is below :

myDataBase.execSQL("INSERT INTO network_data (DateTime, Signal, GPSLat, GPSLong, NetLat, NetLong) VALUES (datetime() /*Here I want to append value "GMT"*/, '" +Signal+ "', '" +GPSLat+ "', '" +GPSLong+ "', '" +NetLat+ "', '" +NetLong+ "');");

I want to append value "GMT" after 'datetime()' function.

I want Output like : "12:05:05 09:24:00 GMT"

This is a SQLite function in Android.

MPelletier
  • 16,256
  • 15
  • 86
  • 137
Vipul Purohit
  • 9,807
  • 6
  • 53
  • 76

2 Answers2

1

In Sqlite you can concat any string (text) with "||" this symbol.. In you case try this one..

("INSERT INTO network_data (DateTime, Signal, GPSLat, GPSLong, NetLat, NetLong) VALUES (datetime()||' GMT', '" +Signal+ "', '" +GPSLat+ "', '" +GPSLong+ "', '" +NetLat+ "', '" +NetLong+ "');");
Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Sandeep
  • 2,573
  • 3
  • 21
  • 28
0

Im not an android developer but I'm pretty sure you can use StringBuilder. I guess it would look something like this:

StringBuilder builder = new StringBuilder(100);
builder.append("Your Insert string");
builder.append(10); //This would append an integer
builder.append("My end insert string");
String s = builder.toString(); //Feel free to use your new string :)

Reference: http://developer.android.com/reference/java/lang/StringBuilder.html

Majster
  • 3,611
  • 5
  • 38
  • 60
  • But I want to use SqlLite Function "datetime()" ??? It can only execute in Sql Query. – Vipul Purohit May 05 '12 at 09:33
  • 1
    Yes I see now. Not sure if you can append like that. One method would be to SELECT datetime() and then create an INSERT string or why not simply add "GMT" when using SELECT? – Majster May 05 '12 at 09:41