0
CreateL()
{
_LIT(KSQLCountry, "CREATE TABLE Country(CountryID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,CountryName VARCHAR(45) NOT NULL,CountryCode VARCHAR(10) NOT NULL)");
User::LeaveIfError(iDatabase.Execute(KSQLCountry));
}

while creating table i want to declare for primary key and foreign key

which showing run time error (it crashes) during creation of table

what is right way to declare primary key

laalto
  • 150,114
  • 66
  • 286
  • 303
rahulm
  • 23
  • 3

3 Answers3

1

I don't know which DB are you using, but maybe this will help you

http://snippets.dzone.com/posts/show/1680

Try to use COUNTER data type instead of INTEGER and AUTOINCREMENT.

Another guess: isn't that AUTO_INCREMENT with underscore?

Lukasz Lysik
  • 10,462
  • 3
  • 51
  • 72
1

AUTO_INCREMENT is indeed with underscore, this is the error in that SQL

transient_loop
  • 5,984
  • 15
  • 58
  • 117
0

Seems like you're using the old legacy Symbian DBMS and not SQLite.

The old DBMS only supports a small subset of SQL. If my memory serves me well, that includes only some basic SELECT queries.

To create tables using the old DBMS, use the C++ API, e.g.

CDbColSet* columns = CDbColSet::NewLC();

TDbCol id(_L("CountryID"), EDbColInt32);
id.iAttributes = TDbCol::EAutoIncrement | TDbCol::ENotNull;
columns->AddL(id);               

columns->AddL(TDbCol(_L("CountryName"), EDbColText, 45));
columns->AddL(TDbCol(_L("CountryCode"), EDbColText, 10));

User::LeaveIfError(aDatabase.CreateTable(_L("Country"), *columns));

CleanupStack::PopAndDestroy(columns);

Or just use the more recent SQLite-backed RSqlDatabase API.

laalto
  • 150,114
  • 66
  • 286
  • 303