Question

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.

Was it helpful?

Solution

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+ "');");

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top