de.greenrobot.dao.internal.SqlUtils Java Examples

The following examples show how to use de.greenrobot.dao.internal.SqlUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserDao.java    From BrainPhaser with GNU General Public License v3.0 6 votes vote down vote up
public User loadDeep(Long key) {
    assertSinglePk();
    if (key == null) {
        return null;
    }

    StringBuilder builder = new StringBuilder(getSelectDeep());
    builder.append("WHERE ");
    SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
    String sql = builder.toString();
    
    String[] keyArray = new String[] { key.toString() };
    Cursor cursor = db.rawQuery(sql, keyArray);
    
    try {
        boolean available = cursor.moveToFirst();
        if (!available) {
            return null;
        } else if (!cursor.isLast()) {
            throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
        }
        return loadCurrentDeep(cursor, true);
    } finally {
        cursor.close();
    }
}
 
Example #2
Source File: QueryBuilder.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
public DeleteQuery buildDelete()
{
    String s = dao.getTablename();
    StringBuilder stringbuilder = new StringBuilder(SqlUtils.createSqlDelete(s, null));
    appendWhereClause(stringbuilder, tablePrefix);
    String s1 = stringbuilder.toString().replace((new StringBuilder()).append(tablePrefix).append(".'").toString(), (new StringBuilder()).append(s).append(".'").toString());
    if (LOG_SQL)
    {
        DaoLog.d((new StringBuilder()).append("Built SQL for delete query: ").append(s1).toString());
    }
    if (LOG_VALUES)
    {
        DaoLog.d((new StringBuilder()).append("Values for delete query: ").append(values).toString());
    }
    return DeleteQuery.create(dao, s1, values.toArray());
}
 
Example #3
Source File: AddressItemDao.java    From AndroidDatabaseLibraryComparison with MIT License 6 votes vote down vote up
public AddressItem loadDeep(Long key) {
    assertSinglePk();
    if (key == null) {
        return null;
    }

    StringBuilder builder = new StringBuilder(getSelectDeep());
    builder.append("WHERE ");
    SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
    String sql = builder.toString();
    
    String[] keyArray = new String[] { key.toString() };
    Cursor cursor = db.rawQuery(sql, keyArray);
    
    try {
        boolean available = cursor.moveToFirst();
        if (!available) {
            return null;
        } else if (!cursor.isLast()) {
            throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
        }
        return loadCurrentDeep(cursor, true);
    } finally {
        cursor.close();
    }
}
 
Example #4
Source File: ContactDao.java    From AndroidDatabaseLibraryComparison with MIT License 6 votes vote down vote up
public Contact loadDeep(Long key) {
    assertSinglePk();
    if (key == null) {
        return null;
    }

    StringBuilder builder = new StringBuilder(getSelectDeep());
    builder.append("WHERE ");
    SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
    String sql = builder.toString();
    
    String[] keyArray = new String[] { key.toString() };
    Cursor cursor = db.rawQuery(sql, keyArray);
    
    try {
        boolean available = cursor.moveToFirst();
        if (!available) {
            return null;
        } else if (!cursor.isLast()) {
            throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
        }
        return loadCurrentDeep(cursor, true);
    } finally {
        cursor.close();
    }
}
 
Example #5
Source File: alloperatorsDao.java    From RxJavaApp with Apache License 2.0 6 votes vote down vote up
public alloperators loadDeep(Long key) {
    assertSinglePk();
    if (key == null) {
        return null;
    }

    StringBuilder builder = new StringBuilder(getSelectDeep());
    builder.append("WHERE ");
    SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
    String sql = builder.toString();
    
    String[] keyArray = new String[] { key.toString() };
    Cursor cursor = db.rawQuery(sql, keyArray);
    
    try {
        boolean available = cursor.moveToFirst();
        if (!available) {
            return null;
        } else if (!cursor.isLast()) {
            throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
        }
        return loadCurrentDeep(cursor, true);
    } finally {
        cursor.close();
    }
}
 
Example #6
Source File: operatorsDao.java    From RxJavaApp with Apache License 2.0 6 votes vote down vote up
public operators loadDeep(Long key) {
    assertSinglePk();
    if (key == null) {
        return null;
    }

    StringBuilder builder = new StringBuilder(getSelectDeep());
    builder.append("WHERE ");
    SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
    String sql = builder.toString();
    
    String[] keyArray = new String[] { key.toString() };
    Cursor cursor = db.rawQuery(sql, keyArray);
    
    try {
        boolean available = cursor.moveToFirst();
        if (!available) {
            return null;
        } else if (!cursor.isLast()) {
            throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
        }
        return loadCurrentDeep(cursor, true);
    } finally {
        cursor.close();
    }
}
 
Example #7
Source File: CollectEntityDao.java    From MeiZiNews with MIT License 6 votes vote down vote up
public CollectEntity loadDeep(Long key) {
    assertSinglePk();
    if (key == null) {
        return null;
    }

    StringBuilder builder = new StringBuilder(getSelectDeep());
    builder.append("WHERE ");
    SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
    String sql = builder.toString();
    
    String[] keyArray = new String[] { key.toString() };
    Cursor cursor = db.rawQuery(sql, keyArray);
    
    try {
        boolean available = cursor.moveToFirst();
        if (!available) {
            return null;
        } else if (!cursor.isLast()) {
            throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
        }
        return loadCurrentDeep(cursor, true);
    } finally {
        cursor.close();
    }
}
 
Example #8
Source File: StatisticsDao.java    From BrainPhaser with GNU General Public License v3.0 6 votes vote down vote up
public Statistics loadDeep(Long key) {
    assertSinglePk();
    if (key == null) {
        return null;
    }

    StringBuilder builder = new StringBuilder(getSelectDeep());
    builder.append("WHERE ");
    SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
    String sql = builder.toString();
    
    String[] keyArray = new String[] { key.toString() };
    Cursor cursor = db.rawQuery(sql, keyArray);
    
    try {
        boolean available = cursor.moveToFirst();
        if (!available) {
            return null;
        } else if (!cursor.isLast()) {
            throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
        }
        return loadCurrentDeep(cursor, true);
    } finally {
        cursor.close();
    }
}
 
Example #9
Source File: CompletionDao.java    From BrainPhaser with GNU General Public License v3.0 6 votes vote down vote up
public Completion loadDeep(Long key) {
    assertSinglePk();
    if (key == null) {
        return null;
    }

    StringBuilder builder = new StringBuilder(getSelectDeep());
    builder.append("WHERE ");
    SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
    String sql = builder.toString();
    
    String[] keyArray = new String[] { key.toString() };
    Cursor cursor = db.rawQuery(sql, keyArray);
    
    try {
        boolean available = cursor.moveToFirst();
        if (!available) {
            return null;
        } else if (!cursor.isLast()) {
            throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
        }
        return loadCurrentDeep(cursor, true);
    } finally {
        cursor.close();
    }
}
 
Example #10
Source File: CollectEntityDao.java    From MeiZiNews with MIT License 5 votes vote down vote up
protected String getSelectDeep() {
    if (selectDeep == null) {
        StringBuilder builder = new StringBuilder("SELECT ");
        SqlUtils.appendColumns(builder, "T", getAllColumns());
        builder.append(',');
        SqlUtils.appendColumns(builder, "T0", daoSession.getHtmlEntityDao().getAllColumns());
        builder.append(" FROM COLLECT_ENTITY T");
        builder.append(" LEFT JOIN HTML_ENTITY T0 ON T.\"HTML_ID\"=T0.\"_id\"");
        builder.append(' ');
        selectDeep = builder.toString();
    }
    return selectDeep;
}
 
Example #11
Source File: operatorsDao.java    From RxJavaApp with Apache License 2.0 5 votes vote down vote up
protected String getSelectDeep() {
    if (selectDeep == null) {
        StringBuilder builder = new StringBuilder("SELECT ");
        SqlUtils.appendColumns(builder, "T", getAllColumns());
        builder.append(',');
        SqlUtils.appendColumns(builder, "T0", daoSession.getAlloperatorsDao().getAllColumns());
        builder.append(" FROM OPERATORS T");
        builder.append(" LEFT JOIN ALLOPERATORS T0 ON T.\"OUTER_ID\"=T0.\"_id\"");
        builder.append(' ');
        selectDeep = builder.toString();
    }
    return selectDeep;
}
 
Example #12
Source File: alloperatorsDao.java    From RxJavaApp with Apache License 2.0 5 votes vote down vote up
protected String getSelectDeep() {
    if (selectDeep == null) {
        StringBuilder builder = new StringBuilder("SELECT ");
        SqlUtils.appendColumns(builder, "T", getAllColumns());
        builder.append(',');
        SqlUtils.appendColumns(builder, "T0", daoSession.getOperatorsDao().getAllColumns());
        builder.append(" FROM ALLOPERATORS T");
        builder.append(" LEFT JOIN OPERATORS T0 ON T.\"OPERATORS_ID\"=T0.\"_id\"");
        builder.append(' ');
        selectDeep = builder.toString();
    }
    return selectDeep;
}
 
Example #13
Source File: StatisticsDao.java    From BrainPhaser with GNU General Public License v3.0 5 votes vote down vote up
protected String getSelectDeep() {
    if (selectDeep == null) {
        StringBuilder builder = new StringBuilder("SELECT ");
        SqlUtils.appendColumns(builder, "T", getAllColumns());
        builder.append(',');
        SqlUtils.appendColumns(builder, "T0", daoSession.getChallengeDao().getAllColumns());
        builder.append(" FROM STATISTICS T");
        builder.append(" LEFT JOIN CHALLENGE T0 ON T.\"CHALLENGE_ID\"=T0.\"_id\"");
        builder.append(' ');
        selectDeep = builder.toString();
    }
    return selectDeep;
}
 
Example #14
Source File: ContactDao.java    From AndroidDatabaseLibraryComparison with MIT License 5 votes vote down vote up
protected String getSelectDeep() {
    if (selectDeep == null) {
        StringBuilder builder = new StringBuilder("SELECT ");
        SqlUtils.appendColumns(builder, "T", getAllColumns());
        builder.append(',');
        SqlUtils.appendColumns(builder, "T0", daoSession.getAddressBookDao().getAllColumns());
        builder.append(" FROM CONTACT T");
        builder.append(" LEFT JOIN ADDRESS_BOOK T0 ON T.'_id'=T0.'_id'");
        builder.append(' ');
        selectDeep = builder.toString();
    }
    return selectDeep;
}
 
Example #15
Source File: AddressItemDao.java    From AndroidDatabaseLibraryComparison with MIT License 5 votes vote down vote up
protected String getSelectDeep() {
    if (selectDeep == null) {
        StringBuilder builder = new StringBuilder("SELECT ");
        SqlUtils.appendColumns(builder, "T", getAllColumns());
        builder.append(',');
        SqlUtils.appendColumns(builder, "T0", daoSession.getAddressBookDao().getAllColumns());
        builder.append(" FROM ADDRESS_ITEM T");
        builder.append(" LEFT JOIN ADDRESS_BOOK T0 ON T.'_id'=T0.'_id'");
        builder.append(' ');
        selectDeep = builder.toString();
    }
    return selectDeep;
}
 
Example #16
Source File: CompletionDao.java    From BrainPhaser with GNU General Public License v3.0 5 votes vote down vote up
protected String getSelectDeep() {
    if (selectDeep == null) {
        StringBuilder builder = new StringBuilder("SELECT ");
        SqlUtils.appendColumns(builder, "T", getAllColumns());
        builder.append(',');
        SqlUtils.appendColumns(builder, "T0", daoSession.getChallengeDao().getAllColumns());
        builder.append(" FROM COMPLETION T");
        builder.append(" LEFT JOIN CHALLENGE T0 ON T.\"CHALLENGE_ID\"=T0.\"_id\"");
        builder.append(' ');
        selectDeep = builder.toString();
    }
    return selectDeep;
}
 
Example #17
Source File: QueryBuilder.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public CountQuery buildCount()
{
    StringBuilder stringbuilder = new StringBuilder(SqlUtils.createSqlSelectCountStar(dao.getTablename(), tablePrefix));
    appendWhereClause(stringbuilder, tablePrefix);
    String s = stringbuilder.toString();
    if (LOG_SQL)
    {
        DaoLog.d((new StringBuilder()).append("Built SQL for count query: ").append(s).toString());
    }
    if (LOG_VALUES)
    {
        DaoLog.d((new StringBuilder()).append("Values for count query: ").append(values).toString());
    }
    return CountQuery.create(dao, s, values.toArray());
}
 
Example #18
Source File: UserDao.java    From BrainPhaser with GNU General Public License v3.0 5 votes vote down vote up
protected String getSelectDeep() {
    if (selectDeep == null) {
        StringBuilder builder = new StringBuilder("SELECT ");
        SqlUtils.appendColumns(builder, "T", getAllColumns());
        builder.append(',');
        SqlUtils.appendColumns(builder, "T0", daoSession.getSettingsDao().getAllColumns());
        builder.append(" FROM USER T");
        builder.append(" LEFT JOIN SETTINGS T0 ON T.\"SETTINGS_ID\"=T0.\"_id\"");
        builder.append(' ');
        selectDeep = builder.toString();
    }
    return selectDeep;
}
 
Example #19
Source File: QueryBuilder.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public Query build()
{
    int i = -1;
    String s;
    StringBuilder stringbuilder;
    int j;
    if (joinBuilder == null || joinBuilder.length() == 0)
    {
        s = InternalQueryDaoAccess.getStatements(dao).getSelectAll();
    } else
    {
        s = SqlUtils.createSqlSelect(dao.getTablename(), tablePrefix, dao.getAllColumns());
    }
    stringbuilder = new StringBuilder(s);
    appendWhereClause(stringbuilder, tablePrefix);
    if (orderBuilder != null && orderBuilder.length() > 0)
    {
        stringbuilder.append(" ORDER BY ").append(orderBuilder);
    }
    String s1;
    if (limit != null)
    {
        stringbuilder.append(" LIMIT ?");
        values.add(limit);
        j = -1 + values.size();
    } else
    {
        j = i;
    }
    if (offset != null)
    {
        if (limit == null)
        {
            throw new IllegalStateException("Offset cannot be set without limit");
        }
        stringbuilder.append(" OFFSET ?");
        values.add(offset);
        i = -1 + values.size();
    }
    s1 = stringbuilder.toString();
    if (LOG_SQL)
    {
        DaoLog.d((new StringBuilder()).append("Built SQL for query: ").append(s1).toString());
    }
    if (LOG_VALUES)
    {
        DaoLog.d((new StringBuilder()).append("Values for query: ").append(values).toString());
    }
    return Query.create(dao, s1, values.toArray(), j, i);
}
 
Example #20
Source File: Property.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public transient WhereCondition in(Object aobj[])
{
    StringBuilder stringbuilder = new StringBuilder(" IN (");
    SqlUtils.appendPlaceholders(stringbuilder, aobj.length).append(')');
    return new de.greenrobot.dao.query.WhereCondition.PropertyCondition(this, stringbuilder.toString(), aobj);
}
 
Example #21
Source File: Property.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public transient WhereCondition notIn(Object aobj[])
{
    StringBuilder stringbuilder = new StringBuilder(" NOT IN (");
    SqlUtils.appendPlaceholders(stringbuilder, aobj.length).append(')');
    return new de.greenrobot.dao.query.WhereCondition.PropertyCondition(this, stringbuilder.toString(), aobj);
}
 
Example #22
Source File: AbstractDaoTestSinglePk.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
protected Cursor queryWithDummyColumnsInFront(int i, String s, Object obj)
{
    int j = 0;
    StringBuilder stringbuilder = new StringBuilder("SELECT ");
    for (int k = 0; k < i; k++)
    {
        stringbuilder.append(s).append(",");
    }

    SqlUtils.appendColumns(stringbuilder, "T", dao.getAllColumns()).append(" FROM ");
    stringbuilder.append(dao.getTablename()).append(" T");
    if (obj != null)
    {
        stringbuilder.append(" WHERE ");
        assertEquals(1, dao.getPkColumns().length);
        stringbuilder.append(dao.getPkColumns()[0]).append("=");
        DatabaseUtils.appendValueToSql(stringbuilder, obj);
    }
    String s1 = stringbuilder.toString();
    Cursor cursor = db.rawQuery(s1, null);
    assertTrue(cursor.moveToFirst());
    do
    {
        if (j >= i)
        {
            break;
        }
        try
        {
            assertEquals(s, cursor.getString(j));
        }
        catch (RuntimeException runtimeexception)
        {
            cursor.close();
            throw runtimeexception;
        }
        j++;
    } while (true);
    if (obj == null)
    {
        break MISSING_BLOCK_LABEL_198;
    }
    assertEquals(1, cursor.getCount());
    return cursor;
}