4

I'm storing a PNG file that is converted into a bitmap that gets converted into Byte[] and stored MySQL database.

When I try and call an Item in the database I get the following error.

E/SQLiteQuery: exception: Row too big to fit into CursorWindow requiredPos=0, totalRows=1; query: SELECT * FROM myTable

Caused by: android.database.sqlite.SQLiteBlobTooBigException: Row too big to fit into CursorWindow requiredPos=0, totalRows=1

Is there a way to increase the size of the Cursor window to accept the byte[]?

@Dao
public interface MyDAO {

    @Query("SELECT * FROM myTable")
    LiveData<List<MyEntity>>getAllImages();
public class MyRepository {

    private MyDAO mMyDao;
    private LiveData<List<MyEntity>> mList;

    public MyRepository(Application application) {
        MyDatabase db = MyDatabase.getInstance(application);
        this.mMyDao = db.mMyDao();
        mList = mMyDao.getAllImages();
    }

    public LiveData<List<MyEntity>> getAllImages(){
        return mList;
    }

import java.util.List;

public class MainViewModel extends AndroidViewModel {

    private MyRepository mRepository;
    private LiveData<List<MyEntity>> mList;

    public MainViewModel(Application application) {
        super(application);
        mRepository = new MyRepository(application);
        mList = mRepository.getAllImages();
    }

    public LiveData<List<MyEntity>> getList() {
        return mList;
    }
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final MainViewModel myViewModel = ViewModelProviders.of(this).get(MainViewModel.class);


        Button btnLog = findViewById(R.id.btn_log);
        btnLog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d("MyLog", "update Log");
                myViewModel.getList().observe(MainActivity.this, new Observer<List<MyEntity>>() {
                    @Override
                    public void onChanged(List<MyEntity> myEntities) {

                        int listSize = myEntities.size();
                        Log.d("MyLog", "LiseSize " + listSize);
                        for(int i = 0; i < listSize; i++) {
                            Log.d("MyLog", "MyID " + myEntities.get(i).getID() +
                                    ", bitmap " + myEntities.get(i).getPHOTO());
                        }
                    }
                });
            }
        });

I was expecting to see the byte[] in the log cat

avery_larry
  • 2,069
  • 1
  • 5
  • 17
Shawn
  • 1,222
  • 1
  • 18
  • 41
  • 2
    you should store png as file and store location to that file in db instead. – Leo Chen Nov 27 '19 at 09:18
  • 1
    @LeoChen this is the usual comment on SO where someone suggests to work around an issue, but not solving the problem. Please give a feedback on the original question, or don't suggest anything – Alberto M Feb 11 '21 at 11:14
  • Any chance to solve this issue – Karthikkumar Jun 24 '21 at 07:49
  • The Byte[] size can get very large and there doesn't appear to be a way to reduce the size of the Byte[] or increase the size of the cursor. I ended up using @LeoChen recommendation of storing png file location in the database. – Shawn Jun 24 '21 at 17:57

0 Answers0