sprockets/src/main/java/net/sf/sprockets/content/SQLiteContentProvider.java
private Sql elements(int op, Uri uri, String[] proj, String sel, String[] args, String order) {
        MutableSql sql = translate(uri);
        if (sql == null) {
            sql = Sql.create();
        }
        if (sql.table() == null) {
            sql.table(uri.getPathSegments().get(0));
        }
        if (sql.notifyUri() == null && op != SELECT) {
            sql.notifyUri(uri.buildUpon().path(sql.table()).clearQuery().fragment(null).build());
        }
        if (op != INSERT) { // run the query and return the cursor
            String from = sql.join() != null ? sql.table() + ' ' + sql.join() : sql.table();
            if ((sql.sel() == null || sql.args() == null) && uri.getPathSegments().size() == 2) {
                try { // filter on ID if URI in /table/id format
                    long id = ContentUris.parseId(uri);
                    if (id > 0) {
                        if (sql.sel() == null) {
                            sql.sel("rowid = ?");
                        }
                        if (sql.args() == null) {
                            sql.args(String.valueOf(id));
                        }
                    }
                } catch (NumberFormatException e) { // last segment not a number
                }
            }
            if (sel != null) { // append caller values
                sql.sel(DatabaseUtils.concatenateWhere(sql.sel(), sel));
            }
            if (args != null) {
                sql.args(DatabaseUtils.appendSelectionArgs(sql.args(), args));
            }
            String groupBy = uri.getQueryParameter(GROUP_BY);
            if (groupBy != null) { // prefer caller's value
                sql.groupBy(groupBy);
            }
            String having = uri.getQueryParameter(HAVING);
            if (having != null) {
                sql.having(having);
            }
            if (order != null) {
                sql.orderBy(order);
            }
            String limit = uri.getQueryParameter(LIMIT);
            if (limit != null) {
                sql.limit(limit);
            }
            sql.mResult = mHelper.getReadableDatabase()
                    .query(from, proj, sql.sel(), sql.args(), sql.groupBy(), sql.having(),
                            sql.orderBy(), sql.limit());
        }
        return sql;
    }
private Sql elements(int op, Uri uri, String[] proj, String sel, String[] args, String order) {
        MutableSql sql = translate(uri);
        if (sql == null) {
            sql = Sql.create();
        }
        if (sql.table() == null) {
            sql.table(uri.getPathSegments().get(0));
        }
        if (sql.notifyUri() == null && op != SELECT) {
            sql.notifyUri(uri.buildUpon().path(sql.table()).clearQuery().fragment(null).build());
        }
        if (op != INSERT) { // run the query and return the cursor
            String from = sql.join() != null ? sql.table() + ' ' + sql.join() : sql.table();
            if ((sql.sel() == null || sql.args() == null) && uri.getPathSegments().size() == 2) {
                try { // filter on ID if URI in /table/id format
                    long id = ContentUris.parseId(uri);
                    if (id > 0) {
                        if (sql.sel() == null) {
                            sql.sel("rowid = ?");
                        }
                        if (sql.args() == null) {
                            sql.args(String.valueOf(id));
                        }
                    }
                } catch (NumberFormatException e) { // last segment not a number
                }
            }
            if (sel != null) { // append caller values
                sql.sel(DatabaseUtils.concatenateWhere(sql.sel(), sel));
            }
            if (args != null) {
                sql.args(DatabaseUtils.appendSelectionArgs(sql.args(), args));
            }
            String groupBy = uri.getQueryParameter(GROUP_BY);
            if (groupBy != null) { // prefer caller's value
                sql.groupBy(groupBy);
            }
            String having = uri.getQueryParameter(HAVING);
            if (having != null) {
                sql.having(having);
            }
            if (order != null) {
                sql.orderBy(order);
            }
            String limit = uri.getQueryParameter(LIMIT);
            if (limit != null) {
                sql.limit(limit);
            }
            sql.mResult = mHelper.getReadableDatabase()
                    .query(from, proj, sql.sel(), sql.args(), sql.groupBy(), sql.having(),
                            sql.orderBy(), sql.limit());
        }
        return sql;
    }
private Sql elements ( int op , Uri uri , String [ ] proj , String sel , String [ ] args , String order ) { MutableSql sql = translate ( uri ) ; if ( sql == null ) { sql = Sql . create ( ) ; } if ( sql . table ( ) == null ) { sql . table ( uri . getPathSegments ( ) . get ( 0 ) ) ; } if ( sql . notifyUri ( ) == null && op != SELECT ) { sql . notifyUri ( uri . buildUpon ( ) . path ( sql . table ( ) ) . clearQuery ( ) . fragment ( null ) . build ( ) ) ; } if ( op != INSERT ) { // run the query and return the cursor String from = sql . join ( ) != null ? sql . table ( ) + ' ' + sql . join ( ) : sql . table ( ) ; if ( ( sql . sel ( ) == null || sql . args ( ) == null ) && uri . getPathSegments ( ) . size ( ) == 2 ) { try { // filter on ID if URI in /table/id format long id = ContentUris . parseId ( uri ) ; if ( id > 0 ) { if ( sql . sel ( ) == null ) { sql . sel ( "rowid = ?" ) ; } if ( sql . args ( ) == null ) { sql . args ( String . valueOf ( id ) ) ; } } } catch ( NumberFormatException e ) { // last segment not a number } } if ( sel != null ) { // append caller values sql . sel ( DatabaseUtils . concatenateWhere ( sql . sel ( ) , sel ) ) ; } if ( args != null ) { sql . args ( DatabaseUtils . appendSelectionArgs ( sql . args ( ) , args ) ) ; } String groupBy = uri . getQueryParameter ( GROUP_BY ) ; if ( groupBy != null ) { // prefer caller's value sql . groupBy ( groupBy ) ; } String having = uri . getQueryParameter ( HAVING ) ; if ( having != null ) { sql . having ( having ) ; } if ( order != null ) { sql . orderBy ( order ) ; } String limit = uri . getQueryParameter ( LIMIT ) ; if ( limit != null ) { sql . limit ( limit ) ; } sql . mResult = mHelper . getReadableDatabase ( ) . query ( from , proj , sql . sel ( ) , sql . args ( ) , sql . groupBy ( ) , sql . having ( ) , sql . orderBy ( ) , sql . limit ( ) ) ; } return sql ; }
Get the updated SQL elements for the URI and, when not inserting, a cursor with the query
results.
Get the updated SQL elements for the URI and when not inserting a cursor with the query results .