MAIN DATABASE HANDLER CREATION
package com.example.viraj.grocery_list.Data;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.example.viraj.grocery_list.Model.Grocery;
import com.example.viraj.grocery_list.Util.Constants;
import java.net.PortUnreachableException;
import java.util.List;
public class DatabaseHandler extends SQLiteOpenHelper {
private Context ctx;
public DatabaseHandler(Context context) {
super(context, Constants.DB_NAME, null, Constants.DB_VERSION);
this.ctx = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_GROCERY_TABLE = "CREATE TABLE " + Constants.TABLE_NAME + "("
+ Constants.KEY_ID + "INTEGER PRIMARY KEY,"
+ Constants.KEY_GROCERY_ITEM + "TEXT,"
+ Constants.KEY_QTY_NUMBER + "TEXT,"
+ Constants.KEY_DATE_NAME + "LONG);";
db.execSQL(CREATE_GROCERY_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS" + Constants.TABLE_NAME);
onCreate(db);
}
//---------------CRUD OPERATION CREATE READ UPDATE DELETE
//===========GROCERY CLASS KO IMPORT KIYA ADD GROCERY
public void AddGrocery(Grocery grocery)
{
}
//==========================GET A GROCERY
private Grocery getgrocery(int id)
{
return null;
}
//==========================GET A-L-L GROCERIES
public List<Grocery> getAllGroceries()
{
return null;
}
//========================= UPDATE GROCRIES
public int updateGrocery(Grocery grocery)
{
return 0;
}
//=========================DELETE GROCERY
public void deleteGrocery(int id)
{
}
//=========================get count
public int getGroceriesCount()
{
return 0;
}
}
package com.example.viraj.grocery_list.Data;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.example.viraj.grocery_list.Model.Grocery;
import com.example.viraj.grocery_list.Util.Constants;
import java.net.PortUnreachableException;
import java.util.List;
public class DatabaseHandler extends SQLiteOpenHelper {
private Context ctx;
public DatabaseHandler(Context context) {
super(context, Constants.DB_NAME, null, Constants.DB_VERSION);
this.ctx = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_GROCERY_TABLE = "CREATE TABLE " + Constants.TABLE_NAME + "("
+ Constants.KEY_ID + "INTEGER PRIMARY KEY,"
+ Constants.KEY_GROCERY_ITEM + "TEXT,"
+ Constants.KEY_QTY_NUMBER + "TEXT,"
+ Constants.KEY_DATE_NAME + "LONG);";
db.execSQL(CREATE_GROCERY_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS" + Constants.TABLE_NAME);
onCreate(db);
}
//---------------CRUD OPERATION CREATE READ UPDATE DELETE
//===========GROCERY CLASS KO IMPORT KIYA ADD GROCERY
public void AddGrocery(Grocery grocery)
{
}
//==========================GET A GROCERY
private Grocery getgrocery(int id)
{
return null;
}
//==========================GET A-L-L GROCERIES
public List<Grocery> getAllGroceries()
{
return null;
}
//========================= UPDATE GROCRIES
public int updateGrocery(Grocery grocery)
{
return 0;
}
//=========================DELETE GROCERY
public void deleteGrocery(int id)
{
}
//=========================get count
public int getGroceriesCount()
{
return 0;
}
}
MAIN CONSTANTS
package com.example.viraj.grocery_list.Util;
import java.net.PortUnreachableException;
public class Constants {
//table creation
public static final int DB_VERSION = 1;
public static final String DB_NAME = "groceryListDB";
public static final String TABLE_NAME = "groceryTBL";
//TABLE COLOUMS
public static final String KEY_ID="id";
public static final String KEY_GROCERY_ITEM="grocery_item";
public static final String KEY_QTY_NUMBER="quantity_number";
public static final String KEY_DATE_NAME="date_added";
}
MAIN MODEL
package com.example.viraj.grocery_list.Model;
public class Grocery {
private String name;
private String quantity;
private String dateItemAdded;
private int id;
//firstgrocery class ka object kiya he
//second constructor
// third getter and setter method
//empty constructor
public Grocery() {
}
public Grocery(String name, String quantity, String dateItemAdded, int id) {
this.name = name;
this.quantity = quantity;
this.dateItemAdded = dateItemAdded;
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getQuantity() {
return quantity;
}
public void setQuantity(String quantity) {
this.quantity = quantity;
}
public String getDateItemAdded() {
return dateItemAdded;
}
public void setDateItemAdded(String dateItemAdded) {
this.dateItemAdded = dateItemAdded;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
0 comments:
Post a Comment