tags:

views:

45

answers:

3

Hallo all,

I have a SQliteDatabase object db, i want to create a table in db with the following code

db.execSQL("CREATE TABLE IF NOT EXISTS "+ TABLE2_NAME + " (exer_nr INTEGER PRIMARY KEY ,exerText       varchar(250),answerA varchar(250),answerB varchar(250),answerC varchar(250),answerD varchar(250))");

An Error occur. Why? Is this too large? How can i fix it?

Another problem: I want to insert a row into the table, whose "exerText" column contains the following code as part of it's content.

main( )
{ int m=12, n=34;
printf("%d%d", m+ +,+ +n);
printf("%d%d\n",n+ +,+ +m);
}

An Error occur because of the "" and '' symbols in the code. How can i fix this problem ?

Thanks a lot

A: 

"CREATE TABLE IF NOT EXISTS" is sqlite3-only. Are you using sqlite2?

denpanosekai
It must be sqlite3, because the following code works correctly db.execSQL("CREATE TABLE IF NOT EXISTS "+ TABLE1_NAME+ (exam_nr INTEGER PRIMARY KEY AUTOINCREMENT,answer varchar(50))");
TianDong
A: 

Check to see if the table name you're passing has an embedded space. In any event, it would be better to put square brackets around the table name and better still to use a parameter to pass in the table name.

Jim Lamb
A: 

Not sure about Android at all, but following your comments, maybe Android version of sqlite has a limit on the row size. To check this, change the columns' length from 250 to 50 and see if it works.

Regarding the insert, you can solve the problem by doubling the character you use for quoting the values. So if you need to insert quote_'_and_double_quote_"_end, you do either of two ways:

INSERT INTO TABLE test_table (mytext) VALUES ('quote_''_and_double_quote_"_end');
INSERT INTO TABLE test_table (mytext) VALUES ("quote_'_and_double_quote_""_end");
van