0

my android application uses SQLITE. when i try to retrieve data from a certain table, everything works fine except for one column in particular which is of type varchar and holds a huge text (base64 string which will be coverted to a file).

when i try to retrieve any other column from this table, the retrieval is successful, but on this column i get the error:

 java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow.  Make sure the   
  Cursor is initialized correctly before accessing data from it.

Here is my code:

    String Filequery= "Select FileName from Hyperlinks_GVT where Taskcode='"+currentTaskCode+"' 
                        and Name='"+tempItem.getText()+"'";
                  Log.d(TAG,"Query is: "+Filequery);
                try {
                    cursor3 = MainActivity.myDataBase.rawQuery(Filequery, null);
                    String Data="";
                    byte[] btData;
                    if (cursor3 != null && cursor3.moveToFirst()){
                        do {
                         Data=cursor3.getString(cursor3.getColumnIndex("FileName"));
                        } while (cursor3.moveToNext());
                    }
                    cursor3.close();

the table:

CREATE TABLE [Hyperlinks_GVT](
[ID]  integer PRIMARY KEY AUTOINCREMENT NOT NULL,
[Taskcode] [int] NOT NULL,
[TaskYear] [int] NOT NULL,
[Name] [varchar](100) NOT NULL,
[FileName] [varchar] NOT NULL,
[Notes] [varchar](200) NOT NULL,
[UserID] [nvarchar](50) NOT NULL,
[CreationDT] [varchar](100)  NOT NULL)

FIleName is the column with the large data NOTE: when i execute the query in Firefox using SQLITE Manager, the query retrieves the results, so the query is fine and has no errors. any help would be appreciated.

Rashad.Z
  • 2,494
  • 2
  • 27
  • 58
  • try with hardcoded small text in FileNamem, and check does it work or not – Anand Phadke Dec 10 '14 at 08:39
  • it works fine with small text – Rashad.Z Dec 10 '14 at 08:46
  • should i change the column type?. though i dont think it is a problem because the column is holding the data as i said and can be viewed in SQLITE manager so the code is the problem i think – Rashad.Z Dec 10 '14 at 08:49
  • Who gave a -1 and why. am i not clear about the problem and that i tried solving it before i asked?! – Rashad.Z Dec 10 '14 at 08:54
  • A blob would need less storage space, but with sufficiently large files, this does not matter. In any case, large strings and blobs behave identically. – CL. Dec 10 '14 at 09:22

1 Answers1

-1

TRY THIS: change the datatype of filename from varchar to TEXT.

Rajat Mehra
  • 1,462
  • 14
  • 19
  • I tried that, and now i have an extra error saying:12-10 11:15:26.104: W/CursorWindow(11911): Window is full: requested allocation 3382005 bytes, free space 2096708 bytes, window size 2097152 bytes – Rashad.Z Dec 10 '14 at 09:17
  • So i guess i can't retrieve that much data at the same time:/? – Rashad.Z Dec 10 '14 at 09:19
  • Now your data is loaded into cursor but window is full. Try to use different device which has better memory management. – Rajat Mehra Dec 10 '14 at 09:20