/**
* method that get category data from database table
*
*/
public ArrayList<String>getCategories(){
SQLiteDatabase database = this.getWritableDatabase();
ArrayList<String> results = new ArrayList<String>();
Cursor data = database.rawQuery("SELECT category_name from catalog2 where parent_id=0;",null);
if (data != null)
{
Log.d("database",database.toString());
if (data.moveToFirst())
{
do
{
String catagoryName = data.getString(data.getColumnIndex("category_name"));
Log.e("catagery name",""+catagoryName);
results.add(catagoryName );
} while (data.moveToNext());
}
data.close();
return results;
}
else
return null;
}
/**
* method that get sub-category from database table, here we passing categoryName which search in catlog2 table and returns category_id, from it we search all these data from catlog table ie [category_name,category_id,parent_id, is_leaf]
*
*/
public ArrayList<Category>getSubCategories( CharSequence categoryName){
ArrayList<Category> results = new ArrayList<Category>();
SQLiteDatabase database = this.getWritableDatabase();
String parent=null;
Cursor data = database.query("catalog2", new String[] {"category_id"},new String("category_name"+"=?"),new String[]{categoryName.toString()}, null, null, null);
if (data.moveToFirst())
{
{
parent = data.getString(data.getColumnIndex("category_id"));
Log.e("parent",""+parent);
}
}
data.close();
data = database.rawQuery("SELECT category_name,category_id,parent_id, is_leaf from catalog2 where parent_id="+parent,null);
if (data.moveToFirst())
{
do
{
String category_id=data.getString(data.getColumnIndex("category_id"));
String catagoryName = data.getString(data.getColumnIndex("category_name"));
String parent_id = data.getString(data.getColumnIndex("parent_id"));
String isleaf=data.getString(data.getColumnIndex("is_leaf"));
Category c=new Category();
c.category_name=catagoryName;
Log.e("catagoryName",""+catagoryName);
c.category_id=category_id;
c.is_leaf=isleaf;
c.parent_id=parent_id;
results.add(c);
} while (data.moveToNext());
}
data.close();
database.close();
return results;
}
Code for getting multiple table data :
/**
* method that get service provider profile from database table
*
*/
public ArrayList<ServiceProvider> getProviderProfiles(String profile_id){
ArrayList<ServiceProvider> profiles = new ArrayList<ServiceProvider>();
SQLiteDatabase database = this.getWritableDatabase();
ArrayList<UserComments> usercommentsList=new ArrayList<UserComments>();
UserComments userComments;
EmailIds emailid;
ArrayList<EmailIds> emailidList=new ArrayList<EmailIds>();
String sp_profileid=null;
Service1 service;
ArrayList<Service1> servicesList=new ArrayList<Service1>();
ArrayList<Phnos> PhnosList=new ArrayList<Phnos>();
Phnos pHno;
Log.e("nu_profileid",""+profile_id);
// Cursor data2 =database.rawQuery("SELECT * form nu_subscriptions where nu_profile_id="+profile_id,null);
Cursor data2 = database.query("nu_subscriptions", new String[] {"sp_profile_id"},new String("nu_profile_id"+"=?"),new String[]{profile_id.toString()}, null, null, null);
if (data2!= null)
{
// Log.d(TAG+"database",database.toString());
if (data2.moveToFirst()){
do{
sp_profileid=data2.getString(data2.getColumnIndex("sp_profile_id"));
Log.e("sp_profileid",""+sp_profileid);
//Cursor data1 = database.rawQuery("select profile_name,profile_des,country,city,profile_id,rating,is_online,acno,bankname, acname from SM_profile1 where profile_id="+sp_profileid, null);
Cursor data1=database.query("SM_profile1", new String[] {"profile_name","profile_des","country","city","profile_id","rating","is_online","acno","bankname", "acname"},new String("profile_id"+"=?"),new String[]{sp_profileid.toString()}, null, null, null);
Cursor data4 = database.query("SM_email_id1", new String[] {"email_id"},new String("profile_id"+"=?"),new String[]{sp_profileid.toString()}, null, null, null);
Cursor data5 = database.query("SM_phone_numbers", new String[] {"contact_number"},new String("profile_id"+"=?"),new String[]{sp_profileid.toString()}, null, null, null);
Cursor data3 = database.query("SM_user_comments1", new String[] {"user_comments"},new String("profile_id"+"=?"),new String[]{sp_profileid.toString()}, null, null, null);
Cursor data6 = database.query("nu_subscriptions", new String[] {"service_id","service_name" ,"service_charge","sp_profile_id"},new String("sp_profile_id"+"=?"),new String[]{sp_profileid.toString()}, null, null, null);
ServiceProvider pf=new ServiceProvider();
if (data6.moveToFirst()){
do{
// servicesList=new ArrayList<Service1>();
//servicesList.clear();
String service_id= data6.getString(data6.getColumnIndex("service_id"));
Log.e("service_id",""+service_id);
String service_name= data6.getString(data6.getColumnIndex("service_name"));
String sp_profile_id= data6.getString(data6.getColumnIndex("sp_profile_id"));
//String payment_timestamp= data2.getString(data2.getColumnIndex("payment_timestamp"));
String service_charge= data6.getString(data6.getColumnIndex("service_charge"));
service=new Service1();
service.service_id =service_id ;
service.service_charge = service_charge;
service.service_name= service_name;
service.sp_profile_id=sp_profile_id;
// service.service_des= service_des;
servicesList.add(service);
pf.serviceList=servicesList;
//pf.serviceList.clear();
Log.e(TAG,""+pf.serviceList.size());
for(int i=0;i<pf.serviceList.size();i++){
Log.e(TAG,pf.serviceList.get(i).service_id);
}
}while (data6.moveToNext());
}
if (data4.moveToFirst()){
String emailid1=data4.getString(data4.getColumnIndex("email_id"));
emailid=new EmailIds();
Log.e(" emailid", emailid1);
emailid.emailid =emailid1;
emailidList.add(emailid);
pf.email_idList=emailidList;
}
if (data5.moveToFirst()){
String contactnumber=data5.getString(data5.getColumnIndex("contact_number"));
pHno=new Phnos(null);
Log.e("contactnumber",contactnumber);
pHno.phno =contactnumber;
PhnosList.add(pHno);
pf.phnoList=PhnosList;
}
if (data3.moveToFirst())
{
String userComment1=data3.getString(data3.getColumnIndex("user_comments"));
userComments=new UserComments();
userComments.userComments = userComment1;
usercommentsList.add( userComments);
pf.usercommentsList=usercommentsList;
}
if (data1!= null)
{
Log.d(TAG+"database",database.toString());
if (data1.moveToFirst()){
//do{
Log.d(TAG,"am in curser data1");
String provider = data1.getString(data1.getColumnIndex("profile_name"));
String Country = data1.getString(data1.getColumnIndex("country"));
String profileid = data1.getString(data1.getColumnIndex("profile_id"));
String rating = data1.getString(data1.getColumnIndex("rating"));
String is_online= data1.getString(data1.getColumnIndex("is_online"));
// String usercomments=data1.getString(data1.getColumnIndex("usercomments"));
String acname=data1.getString(data1.getColumnIndex("acname"));
String bankname=data1.getString(data1.getColumnIndex("bankname"));
String acno=data1.getString(data1.getColumnIndex("acno"));
pf.country=Country;
Log.d("pf.country",pf.country);
pf.profile_id=profileid;
Log.d("profile_id",pf.profile_id);
pf.profile_name=provider;
Log.d("profile_name",pf.profile_name);
pf.is_online=is_online;
pf.acname=acname;
pf.acno=acno;
pf.bankname=bankname;
pf.rating=rating;
//pf.videoid=videoid;
// Log.d(TAG,pf.videoid);
//}while (data1.moveToNext());
}
//database.close();
}
profiles.add(pf);
}while (data2.moveToNext());
Log.e(TAG+"profiles size",""+profiles.size());
data2.close();
// data1.close();
}
}
return profiles;
}
No comments:
Post a Comment