Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make recursive query in SQLite?
    text
    copied!<p>if my data structure is like this </p> <pre><code>parentA -------parentAA --------------parentAAA ---------------------childA </code></pre> <p>if i can get "childA.name" . how can i know all the parent name till the top level. so it will be like this > <code>parentA/parentAA/parentAAA/childA</code></p> <p>what is the best way to do this ? </p> <p>i'm working with SQLite and JAVA/android .. thanks in adv.</p> <p><em><strong></em>__<em>_</em>__<em>_</em>__<em>_</em>___</strong> EDIT</p> <p>Okay guys, thanks for all of u . so i just make it by repeating "select query". BOTTOM-UP this is the method i create</p> <pre><code>public String getPath(int id, int type) { StringBuilder pathBuilder = new StringBuilder(); String sql = null; int parentId = 0; if (id == 0) { pathBuilder.insert(0, "/root/"); return pathBuilder.toString(); } if (type == LayerManagementActivity.PARENT) { do { sql = "SELECT id, name, parent_id from parents_table where id=" + id; Cursor c = mDatabase.rawQuery(sql, null); if (c.moveToFirst()) { parentId = c.getInt(2); id = c.getInt(0); pathBuilder.insert(0, "/" + c.getString(1)); c.close(); } id = parentId; } while (parentId != 0); pathBuilder.insert(0, "/root"); pathBuilder.append("/"); } else if (type == LayerManagementActivity.CHILD) { sql = "SELECT id, name, folder_id FROM childs_table WHERE id=" + id; Cursor c = mDatabase.rawQuery(sql, null); if (c.moveToFirst()) { pathBuilder.append(c.getString(1)); id = c.getInt(0); int folderId = c.getInt(2); String path = getPath(folderId, LayerManagementActivity.PARENT); pathBuilder.insert(0, path); } c.close(); } Log.d("crumb", pathBuilder.toString()); return pathBuilder.toString(); } </code></pre>
 

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