Skip to content

cursor.getInt() method can't return the right value of column that defined as TEXT #244

Closed

Description

@CoconutByte

When the column is defined as TEXT,I found that cursor.getInt() method can't return the right value of that column.

I repreduced this issue with the SQLCipher for Android test suite.
Condition: the value of the text should be larger than 10
Procedure:Change the value of the 'a' column from 5 to 500 in the TextAsIntegerTest.java file, then run the Tests,and the Text as integer Test will be failed.
It seems that corsor.getInt() just return the value of the first character in the Text.

Sqlcipher version:3.5.1

screenshot_2016-01-30-15-14-04
.

Activity

  1. developernotes commented on Jul 6, 2016

    @developernotes
    Member

    Hello @liuzhihuinb,

    Thank you for clarifying the issue. I have just pushed up some changes to address this, including new binaries within the SQLCipher for Android test suite. Would you give those a try and let me know your results? Thanks!

  2. CoconutByte commented on Jul 7, 2016

    @CoconutByte
    Author

    Hi @developernotes
    I have tried the latest SQLCipher for Android test suite.Every test works very well and the result is OK.
    I think this issue had been solved.Thanks for your correction.
    Waiting for the release.

  3. jcb316733855 commented on Jul 22, 2016

    @jcb316733855

    i have met the same issue, the save value is 1, but the query result is 10, if the column define as Integer this will ok

  4. developernotes commented on Jul 22, 2016

    @developernotes
    Member

    Hello @jcb316733855

    What version of SQLCipher for Android are you using? We addressed this issue in the 3.5.2 release.

  5. jcb316733855 commented on Jul 23, 2016

    @jcb316733855

    the version is 3.5.2

  6. developernotes commented on Jul 25, 2016

    @developernotes
    Member

    Hi @jcb316733855

    Are you able to reproduce it with the test suite? It appears to work correctly for me:

    screen shot 2016-07-25 at 8 54 20 am

  7. draak567 commented on Jul 25, 2016

    @draak567

    This issue still happens for us as well. We have a large database with about 45 columns. One of them (I think the 5th? 6th?) is a TEXT column but getInt() on it doesn't work correctly.

  8. developernotes commented on Jul 25, 2016

    @developernotes
    Member

    Hello @draak567

    Would you create a reproducible test in the test suite so we can further investigate? The tests that we have for this specific issue are unable to highlight the behavior you are seeing. Thanks!

  9. draak567 commented on Jul 25, 2016

    @draak567

    I'm actually having great difficulty creating a test case - no matter what I try, in the test the correct value is returned from the row. Interestingly enough, getBlob() returns the same bytes on both the test and the real app - but the real app has some stuff appended to the end of the number (for example, if the column value is the string "15", getInt() returns 157 but getBlob() returns the correct UTF-16 bytes for the string "15" [49, 0, 53, 0]).

    The best I can think is that this is some UTF-16 conversion issue and in the main app there's some locale changes being done by the app that are not being done in the test. I noticed that in CursorWindow.cpp there's two different ways that a string is being generated:

    in getLong_native, a Java String is being generated from the field data by the single line:

    jstring data = env->NewString((const jchar*)window->offsetToPtr(field.data.buffer.offset), (jsize)size);

    but in getString_native, the following code is used:

          jchar * buf = (jchar *)window->offsetToPtr(field.data.buffer.offset);
          jclass strClass = env->FindClass("java/lang/String"); 
          jmethodID ctorID = env->GetMethodID(strClass, "<init>", "([BLjava/lang/String;)V"); 
          jstring encoding = env->NewStringUTF("UTF-16LE");
          jbyteArray bytes = env->NewByteArray(size); 
          env->SetByteArrayRegion(bytes, 0, size, (jbyte*)buf);
          return (jstring)env->NewObject(strClass, ctorID, bytes, encoding);
    

    I'm not sure why the code is different, since both instances are supposed to be used to create a Java String from the field data. The final use of the string is different of course, one is returned to the caller and one is used to extract UTF-8 characters and then discarded.

    I suspect this is where the discrepancy is occurring but I don't have the setup right now to do NDK debugging to confirm.

  10. developernotes commented on Jul 26, 2016

    @developernotes
    Member

    Hello @draak567

    We believe we may have pinpointed the issue, however not having a test scenario makes it difficult to verify. Would you mind contacting us directly at support@zetetic.net and we can provide you with a direct build to test on your end? Thanks!

  11. CoconutByte commented on Jul 27, 2016

    @CoconutByte
    Author

    Hi @developernotes
    I reproduced this issue with the following code in the test suite.The Text as Integer test will be failed

    database.execSQL("create table t1(a TEXT,b TEXT);");
    database.execSQL("insert into t1(a,b) values(500,500);");
    Cursor cursor = database.rawQuery("select * from t1;", new String[]{});
    if(cursor != null){
    cursor.moveToFirst();
    long value = cursor.getLong(0);
    return value == 500;
    }

  12. developernotes commented on Jul 27, 2016

    @developernotes
    Member

    Hello @liuzhihuinb, @draak567,

    Thank you for your help diagnosing this specific over read issue. We had addressed the issue in the source and published a new version, 3.5.3. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions