7

I am having an SQLite table and wish to set it with a default value for time being. how can I do that?

Below is my DatabaseHelper class code:

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {

    private static final String DATABASE_NAME="iFall.db";
    public static final String TIME="time";
    //public static final String STATUS="status";
    //public static final String MINES="loadmines";
    //public static final String OPENTILE="openTile";

    public DatabaseHelper(Context context)
    {
        super(context,DATABASE_NAME,null,1);
    }
    @Override
    public void onCreate(SQLiteDatabase arg0) {
        // TODO Auto-generated method stub
        //CREATE TABLE minesweeper(_id INTEGER PRIMARY KEY AUTOINCREMENT,userId TEXT
        arg0.execSQL("CREATE TABLE finalP(_id INTEGER PRIMARY KEY AUTOINCREMENT,time TEXT);");

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        db.execSQL("DROP TABLE IF EXISTS finalP");
        onCreate(db);
    }

}

I want to assign a default value say 50 to the column time.

1
  • 2
    Feel free to accept an answer if it was helpful. Commented May 11, 2011 at 17:52

2 Answers 2

17

I believe you can do this:

arg0.execSQL("CREATE TABLE finalP(_id INTEGER PRIMARY KEY AUTOINCREMENT,time TEXT DEFAULT \'50\');");

and it should work fine.

See the sqlite docs for column constraints. http://www.sqlite.org/syntaxdiagrams.html#column-constraint

Sign up to request clarification or add additional context in comments.

Comments

0

create table permission ( code boolean default 'false' ); it's for boolean type but you can use it for example for TEXT type

1 Comment

Add more detail in your answer and/or add link to official doc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.