Hello,

I am new to this mailinglist. I think I have to send my question here.   My
Name is Michael and I come from Germany. At the moment I develope a few
android apps for my study. 
Is it possbile to get the size of one stored row inside my sqlite database?



I tried the following, but it returns different sizes every time. But my
test data is the same so I think it should have the same size.



public long getObjectSize(MyData data)

    {

        if(getSize() == 0)
//because i don't want to divide by zero

        {

            insertOneFakeData(data);

        }

        long vorvorherdatasize = getDataSize();

        long checkdatasize;

        do
//this is for writing till the end of the current block size

        {

            insertOneFakeData(data);

            checkdatasize = getDataSize();

        }while(checkdatasize == vorvorherdatasize);

        //dataSize changed, so size-1 should be the number ob rows stored in
the old size.

        long vorhersize = getSize()-1;
//number of elements before next write

        long vorherdatasize = getDataSize();
//Size of the file before next write

        do

        {

            insertOneFakeData(data);

            checkdatasize = getDataSize();

        }while(checkdatasize == vorherdatasize);

        long nachherdatasize = checkdatasize;

        long nachhersize = getSize()-1;
//number of rows before new block was reserved

        long size = nachhersize - vorhersize;
//number of elements in the last block

        long datasize = vorherdatasize - vorvorherdatasize;
//datasize oft he last block

        long objectSize = datasize / size;                             //my
try to get the size of 1 row

        return objectSize;

    }



Only for completeness my other used methods:
public long getDataSize()    //returns size of file in which my database is
stored

      {

      SQLiteDatabase db = this.getWritableDatabase();

      db.getPath();

      long size = new File(db.getPath()).length();

      return size;

      }



    public long getSize() //returns number of rows in my database

    {

      Log.i("ESmartDataManager","getSize");

        SQLiteDatabase db = this.getWritableDatabase();

        Cursor cursor = db.rawQuery("SELECT " 

                  + _ID + ", " 

                  + CANID + ", " 

                  + RTR +", " 

                  + IDE + ", "

                  + DLC + ", " 

                  + TIMESTAMP + ", "

                  + DATA  

                  + " FROM " 

                  + FAKETABLE_NAME , null);       

      return cursor.getCount();

    }







Can you help me to get the size of 1 row? Is it possible?



Reply via email to