I have a few create statements that should be run when a database is first created in my Android application. They are formatted as such:
<string-array
name="uaDBcreates">
<item>
CREATE TABLE pos_locations (
_id INTEGER PRIMARY KEY,
location_name TEXT,
service_url TEXT,
latitude REAL DEFAULT 0,
longitude REAL DEFAULT 0
);
</item>
</string-array>
<string-array
name="uaDBInserts">
<item>
INSERT INTO urbanAgendaDB.pos_locations (
_id,
location_name,
service_url
latitude,
longitude )
VALUES (
000001,
OfficeTest,
http://myservice.com/DoStuff,
45.530315,
-73.569939);
</item>
</string-array>
Generally, is this the proper formatting for SQL statements that could be run in SQLite on Android (are thise likely to work)? More specifically, parts of the Android docs state SQL statements should not terminated with a semi-colon, while parts make no mention of semi-colons.
I haven’t used
INSERTstatements with a direct SQL syntax, only by means of theSQLDatabaseAPI; but from my experience I would say that yourCREATEstatement will work as written.As far as the API docs are concerned, it’s quite simple: use those statements with whatever method allows semicolons; strip semicolons if you need to use those same statements with methods that do not allow them at their end. (You may also work it the other way around: avoid semicolons in your statements, then add proper ending punctuation only when you use those statements with API methods requiring semicolons.)
However, I’m a bit baffled by the fact you are including your SQL statements in XML (not to mention that they are the only item in a
string-array). Typically, I’m used to see them in Java code, under the form ofStringconcatenations.