Only the first table is created in the creation of the created table statement

The credentials table is displayed in the adb shell. I checked logcat and did not seem to report a problem ...

   private static final String DATABASE_CREATE =
        "create table credentials (_id integer primary key autoincrement, "
                + "username text not null, password text not null, "
                + "lastupdate text);"
      + "create table user (_id integer primary key autoincrement, "
                + "firstname text not null, "
                + "lastname text not null);"
      + "create table phone (_phoneid integer primary key autoincrement, "
                + "userid integer not null, phonetype text not null, "
                + "phonenumber text not null);"
      + "create table email (_emailid integer primary key autoincrement, "
                + "userid integer not null, emailtype text not null, "
                + "emailaddress text not null);"
      + "create table address (_addressid integer primary key autoincrement,"
                + "userid integer not null, addresstype text not null, "
                + "address text not null);"
      + "create table instantmessaging (_imid integer primary key autoincrement, "
                + "userid integer not null, imtype text not null, "
                + "imaccount text not null);";

I cheated on this, and I bet it has a bit of a dumb syntax. Or at least I hope this is something trivial :-)

+5
source share
3 answers

I suggest that you use:

yourDB.execSQL("your statement");

If so, the Google documentation mentions the following:

Execute a single SQL statement, which is not a query. For example, CREATE TABLE, DELETE, INSERT, etc. Many statements, separated by: s are not supported. he takes a write lock

, create table .

+11

, , execSQL() 1 . .

, .

:

private static final String TABLE_1 =
    "create table credentials (_id integer primary key autoincrement, "
    + "username text not null, password text not null, "
    + "lastupdate text);";

private static final String TABLE_2 =
    "create table user (_id integer primary key autoincrement, "
    + "firstname text not null, "
    + "lastname text not null);";

private static final String TABLE_3 =
    "create table phone (_phoneid integer primary key autoincrement, "
    + "userid integer not null, phonetype text not null, "
    + "phonenumber text not null);";

private static final String TABLE_4 =
    "create table email (_emailid integer primary key autoincrement, "
    + "userid integer not null, emailtype text not null, "
    + "emailaddress text not null);";

private static final String TABLE_5 =
    "create table address (_addressid integer primary key autoincrement,"
    + "userid integer not null, addresstype text not null, "
    + "address text not null);";

private static final String TABLE_6 = 
    "create table instantmessaging (_imid integer primary key autoincrement, "
    + "userid integer not null, imtype text not null, "
    + "imaccount text not null);";

public void createTables(){
    db.execSQL(TABLE_1);
    db.execSQL(TABLE_2);
    db.execSQL(TABLE_3);
    db.execSQL(TABLE_4);
    db.execSQL(TABLE_5);
}
 db.execSQL(TABLE_6);
+5

Go Create Table

script

private static final String DATABASE_CREATE =
        "create table credentials (_id integer primary key autoincrement, "
                + "username text not null, password text not null, "
                + "lastupdate text); Go;"
      + "create table user (_id integer primary key autoincrement, "
                + "firstname text not null, "
                + "lastname text not null); Go;"
      + "create table phone (_phoneid integer primary key autoincrement, "
                + "userid integer not null, phonetype text not null, "
                + "phonenumber text not null); Go;"
      + "create table email (_emailid integer primary key autoincrement, "
                + "userid integer not null, emailtype text not null, "
                + "emailaddress text not null) Go;;"
      + "create table address (_addressid integer primary key autoincrement,"
                + "userid integer not null, addresstype text not null, "
                + "address text not null); Go;"
      + "create table instantmessaging (_imid integer primary key autoincrement, "
                + "userid integer not null, imtype text not null, "
                + "imaccount text not null); Go;";
-3

Source: https://habr.com/ru/post/1747515/


All Articles