رفتن به مطلب
انجمن اندروید ایران | آموزش برنامه نویسی اندروید و موبایل
  • android.png.1fab383bc8500cd93127cebc65b1dcab.png

مشکل در سرعت خوندن اطلاعات از دیتا بیس


پست های پیشنهاد شده

سلام 

من برای برنامم از دیتا بیس SQLite استفاده میکنم  و مقدار زیادی هم متن کوتا مثل SMS  هست که در یه لیست ویو نمایش داده میشه 

ولی یه مشکلی که به تازگی برام پیش اومده اینه که وقتی مقدار  رکورد های دیتا بیس زیاد میشه مثلا 200 تا رکورد ونمایش اونها در لیست ویو برنامه کند میشه و مطالب به کندی باز میشه بعضی وقت ها هم فقط 200 تا سطر در اکتیوتی که لیست  ویو هست به صورت خالی نمایش داده میشه و هیچ مطلبی میان لیست ویو نیست

یا حتی بعضی وقتها که مطالب هم نشون داده میشه با  چرخوندون گوشی , گوشی هنگ میکنه

ایا مشکا از سرعت دیتا بیسه ؟

فرمتی وجو داره که سرعت خوندن  اطلاعات بیشتر باشه ؟ منظورم مثل FAT32  با NFTS  ویندوز هست 

اگر هست چطور باید فرمت فایل دیتا بیس رو عوض کنم

ممنون میشم اگر منو راهنمایی کنید.

از برنامه  SQLite Expert Professional 3 استفاده میکنم

لینک ارسال
به اشتراک گذاری در سایت های دیگر

طبیعیه که با بالا رفتن حجم دیتابیس سرعت پایین میاد ، ولی نه با 200 تا رکود ، 2000 تا رکورد هم برای sqlite عدد کمی حساب میشه چه برسه به 200 تا

لینک ارسال
به اشتراک گذاری در سایت های دیگر

طبیعیه که با بالا رفتن حجم دیتابیس سرعت پایین میاد ، ولی نه با 200 تا رکود ، 2000 تا رکورد هم برای sqlite عدد کمی حساب میشه چه برسه به 200 تا

1000 تا رکورد دار البته

ولی اون لیست ویو که (مثلا  جک) خودش 160 تا رکود داره که برنامه اونجا دچار مشکل میشه

ولی لیست ویو ها  که مثلا 50 یا 60 تا رکورد داره همچین مشکلی نیست


اینم کد های دیتا بیسم 

package com.AppLike.office_help_me;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;


public class database extends SQLiteOpenHelper {

public final String path="data/data/com.AppLike.office_help_me/databases/";
public final String Name="database";
public SQLiteDatabase mydb;

private final Context mycontext;


public database(Context context) {
	super(context, "database", null, 1);
	mycontext=context;

}


@Override
public void onCreate(SQLiteDatabase arg0) {
	// TODO Auto-generated method stub

}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
	// TODO Auto-generated method stub

}


public void useable(){

	boolean checkdb=checkdb();

	if(checkdb){

	}else{

		this.getReadableDatabase();

		try{
		copydatabase();
		}catch(IOException e){
		}

	}



}

public void open(){

	mydb=SQLiteDatabase.openDatabase(path+Name, null, SQLiteDatabase.OPEN_READWRITE);

}

public void close(){
	mydb.close();
}

public boolean checkdb(){

	SQLiteDatabase db=null;
	try{	
	db=SQLiteDatabase.openDatabase(path+Name, null, SQLiteDatabase.OPEN_READONLY);
	}
	catch(SQLException e)
	{

	}
	//mydb.close();
	return db !=null ? true:false ;

}

public void copydatabase() throws IOException{
	OutputStream myOutput = new FileOutputStream(path+Name);
	byte[] buffer = new byte[1024];
	int length;
	InputStream myInput = mycontext.getAssets().open(Name);
	while ((length = myInput.read(buffer)) > 0) {
	myOutput.write(buffer, 0, length);
	}
	myInput.close();
	myOutput.flush();
	myOutput.close();
}



public String Display(int row,int field,String table){

	Cursor cu=mydb.rawQuery("select * from "+table, null);
	cu.moveToPosition(row);
	String s=cu.getString(field);
	return s;
}


public Integer count(String table,String field){

	Cursor cu=mydb.rawQuery("select * from "+table+" group by "+field, null);
	int s=cu.getCount();
	return s;
}



public String Season_display(String table,int row){

	Cursor cu=mydb.rawQuery("select * from "+table+" group by Seasone", null);
	cu.moveToPosition(row);
	String s=cu.getString(4);
	return s;
}


public String m_display(String table,int row){

	Cursor cu=mydb.rawQuery("select * from "+table+" group by Part", null);
	cu.moveToPosition(row);
	String s=cu.getString(5);
	return s;
}







public Integer S2_count(String table,String sea){

	Cursor cu=mydb.rawQuery("select * from "+table+" where Seasone='"+sea+"'", null);
	int s=cu.getCount();
	return s;
}

public String Story2_display(String table,int row,String sea2, int field){

	Cursor cu=mydb.rawQuery("select * from "+table+" where Seasone='"+sea2+"' group by ID + 'and' + Name", null);
	cu.moveToPosition(row);
	String s=cu.getString(field);
	return s;


}



public Integer Story_count(String table,String sea){

	Cursor cu=mydb.rawQuery("select * from "+table+" where Part='"+sea+"' group by Seasone", null);
	int s=cu.getCount();
	return s;
}


public String Story_display(String table,int row,String sea, int field){

	Cursor cu=mydb.rawQuery("select * from "+table+" where Part='"+sea+"' group by Seasone order by ID", null);
	cu.moveToPosition(row);
	String s=cu.getString(field);
	return s;
}

public Integer SS_count(String table,String sea){

	Cursor cu=mydb.rawQuery("select * from "+table+" where Seasone='"+sea+"' group by Name ", null);
	int s=cu.getCount();
	return s;
}


public void fav_update(String table,String sea, String name,String v){
	ContentValues cv=new ContentValues();
	cv.put("Fav", v);
	mydb.update(table, cv, "Seasone='"+sea+"' and Name='"+name+"'", null);


}

public Integer fav_count(String table){

	Cursor cu=mydb.rawQuery("select * from "+table+" where Fav=1 group by Name", null);
	int s=cu.getCount();
	return s;
}

public String fav_display(String table,int row,int field){

	Cursor cu=mydb.rawQuery("select * from "+table+" where Fav=1 group by Name", null);
	cu.moveToPosition(row);
	String s=cu.getString(field);
	return s;
}


public Integer count_serach(String word,String field){

	Cursor cu;
	if(field.equals("Name")){
		cu=mydb.rawQuery("select * from content where "+field+" Like '%"+word+"%' group by Name", null);
		cu=mydb.rawQuery("select * from job where "+field+" Like '%"+word+"%' group by Name", null);
	}else{
		cu=mydb.rawQuery("select * from content where "+field+" Like '%"+word+"%'", null);
		cu=mydb.rawQuery("select * from job where "+field+" Like '%"+word+"%'", null);
	}

	int s=cu.getCount();
	return s;
}


public String serach(int row,int col,String word,String field){

	Cursor cu;
	if(field.equals("Name")){
		cu=mydb.rawQuery("select * from content where "+field+" Like '%"+word+"%' group by Name", null);
		cu=mydb.rawQuery("select * from job where "+field+" Like '%"+word+"%' group by Name", null);
	}else{
		cu=mydb.rawQuery("select * from content where "+field+" Like '%"+word+"%'", null);
		cu=mydb.rawQuery("select * from job where "+field+" Like '%"+word+"%'", null);
	}


	cu.moveToPosition(row);
	String s=cu.getString(col);
	return s;
}




}


اگر بافر رو زیاد تر بگیرم درست میشه ؟

	public void copydatabase() throws IOException{
	OutputStream myOutput = new FileOutputStream(path+Name);
	byte[] buffer = new byte[1024];
	int length;
	InputStream myInput = mycontext.getAssets().open(Name);
	while ((length = myInput.read(buffer)) > 0) {
	myOutput.write(buffer, 0, length);
	}
	myInput.close();
	myOutput.flush();
	myOutput.close();
}

لینک ارسال
به اشتراک گذاری در سایت های دیگر

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...