2010-05-28 2 views
3

"credentials"테이블이 adb 쉘에 표시됩니다. 나는 로그 캣을 확인했고이 문제를보고하지 않는 것 ...작성중인 테이블 작성 문의 첫 번째 테이블 만

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

나는이 쏟아져 봤는데 그 바보 같은 구문 오타를 내기! 또는, 적어도 나는 그것이 사소한 뭔가 ;-)

답변

-1

각 만들기 표 문

업데이트 스크립트

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;"; 
+0

흠, 그냥 시도하고 아직 운이 ... – Craig

+0

보다 진술보다는 하나의 결과가있을 수 있기 때문에 결과를보고 실행 해보십시오. –

4

내가 올바르게 기억 후 이동을 넣어 희망, 나는 비슷한 문제가 발생하여 execSQL() 또는 유사한 방법으로 호출 당 하나의 명령문 만 실행된다는 것을 발견했습니다. 모든 추가 명령문은 자동으로 무시됩니다.

단일 문자열 및 단일 호출보다는 각 구문을 별도의 문자열로 분리하여 개별적으로 실행 해보십시오. 예를 들어

:

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); 
7

난 당신이 사용하고 있다고 가정합니다

가 하나의 SQL 문을 실행

yourDB.execSQL("your statement"); 

그렇다면, 구글 문서는이 언급 검색어가 아닙니다. 예를 들어, CREATE TABLE, DELETE, INSERT 등. ;으로 분리 된 명령문은 이 지원되지 않습니다. 쓰기 잠금이 필요합니다.

따라서 각 create table 문을 조각화하고 각 테이블에 대해 쿼리를 반복해야합니다.

+0

그리고 세미콜론은 허용되지 않습니다. –

관련 문제