Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're supposed to close the Cursor objects to free some resources. The easiest thing to do here is to wrap your if in try/finally block:</p> <pre><code>try { if (cursor.moveToFirst()) { // blah blah blah } return null; } finally { cursor.close(); } </code></pre> <p>There are few other issues here:</p> <ol> <li>You are using rawQuery and you are not sanitizing and escaping the input. For example you'll get db exception if you pass the title with double quotes (") character. Use query() method and pass the title as a selection argument.</li> <li>The do/while block is useless, you always return the first row.</li> <li>If you always return the first row, why u no add LIMIT 1 to your query?</li> <li>Theoretically the order of columns returned by sqlite query is undefined, so you should not use hardcoded column indexes, instead you should get them using cursor.getColumnIndex[OrThrow] methods. It also prevents you from shooting yourself in a foot when you add a new column in the middle of the table definition, but you forget to update the indexes here.</li> <li>This is a static metod, and yet you get your database from mActivity instance. I don't know what is mActivity, but it looks suspicious.</li> <li>The DatabaseItem creation is an example of sad boilerplate code. Some time ago I've created a <a href="https://github.com/chalup/microorm" rel="nofollow">MicroOrm libary</a> which takes care of converting Cursor rows to Plain Java Objects and Plain Java Objects to ContentValues (if you need to save your POJO to db), and reduces this kind of boilerplate.</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload