Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static final String TAG = DBHelper.class.getSimpleName();
- public static final int DATEBASE_VERSION = 1;
- public static final String DATEBASE_NAME = "ContactDB";
- public static final String TABLE_CONTACT = "Contact";
- public static final String KEY_ID = "ID";
- public static final String KEY_NAME = "Name";
- public static final String KEY_LOGIN = "Login";
- public static final String KEY_PASS = "Pass";
- public static int countUser = 0;
- public DBHelper(Context context) {
- super(context, DATEBASE_NAME, null, DATEBASE_VERSION);
- }
- public static final String CREATE_TABLE_USERS = "CREATE TABLE " + TABLE_CONTACT + " ( "
- + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
- + KEY_NAME + " TEXT, "
- + KEY_LOGIN + " TEXT, "
- + KEY_PASS + " TEXT);";
- @Override
- public void onCreate(SQLiteDatabase db) {
- db.execSQL(CREATE_TABLE_USERS);
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACT);
- onCreate(db);
- }
- @Override
- public void addContact(Contact contact) {
- SQLiteDatabase db = this.getWritableDatabase();
- ContentValues value = new ContentValues();
- value.put(KEY_NAME, contact.getName());
- value.put(KEY_LOGIN, contact.getLogin());
- value.put(KEY_PASS, contact.getPass());
- Long id = db.insert(TABLE_CONTACT, null, value);
- db.close();
- Log.d(TAG, "user inserted" + id);
- countUser++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement