3

I'm trying to retrieve a long string saved in my Room database table. But I'm observing that the DAO query only returns the first 5,000 characters of that string.

I can see the full 11,000 characters exists in the database after I dump it to my device and inspect it (using DB Browser for SQLite). The full untruncated text exists in both my ENTRIES table and my ENTRIES_content table.

Room entity:

//@Fts4(tokenizer = FtsOptions.TOKENIZER_UNICODE61)
@Fts4
@Entity(tableName = "ENTRIES")
public class Entry {
    private int rowid;

    @ColumnInfo(name = "date")
    private String date;

    @ColumnInfo(name = "entry")
    private String entryText;

    public String getEntryText() {
        return entryText;
    }
}

DAO:

@Dao
public interface EntriesDAO {
...
    @Query("SELECT *, rowid FROM ENTRIES WHERE date LIKE :date")
    Entry getEntryByDate(String date);
}

Entry is retrieved from the database using the ViewModel pattern, which calls the repository layer, which then finally calls the DAO method that I've shown above.

mEntriesViewModel = new ViewModelProvider(this, factory).get(EntriesViewModel.class);
...
Entry currentEntry = mEntriesViewModel.getEntryByDate(entryDate);
String entryText = currentEntry.getEntryText();
entryText.length(); // 5000

I've tried using the two alternative queries below but they both returned the same truncated text:

@Query("SELECT *, rowid FROM ENTRIES WHERE rowid = (SELECT rowid FROM ENTRIES WHERE date LIKE :date)")

@RawQuery
Entry getEntryByDateRaw(SupportSQLiteQuery query);
// Used with this 
//SupportSQLiteQuery query = new SimpleSQLiteQuery("SELECT * FROM ENTRIES WHERE date LIKE ?", new Object[]{ "%2024-01-01%" });
//return mEntriesViewModel.getEntryByDateRaw(query);
6
  • 1
    When you make the query, is there any error on Logcat? Maybe you have the 1MB limit. Commented Jun 18, 2024 at 1:11
  • @RafaelMoreira I can't see any errors in Logcat or any log messages relating to the database Commented Jun 18, 2024 at 1:34
  • "But I'm observing that the DAO query only returns the first 5,000 characters of that string" -- how exactly are you determining this? Your code does not demonstrate how you are calculating the length of anything. Commented Jun 18, 2024 at 12:08
  • @CommonsWare I've updated the question now to include that information. I'm using a view model factory, which isn't too common, but nothing exciting is happening there because I'm just using it to accept a second password argument in the view model Commented Jun 18, 2024 at 23:38
  • OK, that's strange. I thought that perhaps you were logging the string itself to Logcat; Logcat truncates output. Have you tried an experiment without the @Fts4 annotation? Commented Jun 19, 2024 at 0:05

1 Answer 1

1

I've finally worked it out. In one part of my code I was using the following:

editText.setInputType(InputType.TYPE_NULL);

This code internally checks whether the input type is a multi-line input type, either TYPE_CLASS_TEXT or TYPE_TEXT_FLAG_MULTI_LINE, if it isn't (and it's not in the case of TYPE_NULL), then it will apply setSingleLine(true).

And this call is what restricts the maximum text length to the 5000 that I was seeing:

public void setSingleLine (boolean singleLine) ... Note that due to performance reasons, by setting single line for the EditText, the maximum text length is set to 5000 if no other character limitation are applied.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.