当前位置: 首页>>代码示例>>Java>>正文


Java Database.rawQuery方法代码示例

本文整理汇总了Java中org.greenrobot.greendao.database.Database.rawQuery方法的典型用法代码示例。如果您正苦于以下问题:Java Database.rawQuery方法的具体用法?Java Database.rawQuery怎么用?Java Database.rawQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.greenrobot.greendao.database.Database的用法示例。


在下文中一共展示了Database.rawQuery方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isTableExists

import org.greenrobot.greendao.database.Database; //导入方法依赖的package包/类
private static boolean isTableExists(Database db, boolean isTemp, String tableName) {
    if (db == null || TextUtils.isEmpty(tableName)) {
        return false;
    }
    String dbName = isTemp ? SQLITE_TEMP_MASTER : SQLITE_MASTER;
    String sql = "SELECT COUNT(*) FROM " + dbName + " WHERE type = ? AND name = ?";
    Cursor cursor=null;
    int count = 0;
    try {
        cursor = db.rawQuery(sql, new String[]{"table", tableName});
        if (cursor == null || !cursor.moveToFirst()) {
            return false;
        }
        count = cursor.getInt(0);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return count > 0;
}
 
开发者ID:z-chu,项目名称:FriendBook,代码行数:23,代码来源:MigrationHelper.java

示例2: getColumns

import org.greenrobot.greendao.database.Database; //导入方法依赖的package包/类
private static List<String> getColumns(Database db, String tableName) {
    List<String> columns = null;
    Cursor cursor = null;
    try {
        cursor = db.rawQuery("SELECT * FROM " + tableName + " limit 0", null);
        if (null != cursor && cursor.getColumnCount() > 0) {
            columns = Arrays.asList(cursor.getColumnNames());
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cursor != null)
            cursor.close();
        if (null == columns)
            columns = new ArrayList<>();
    }
    return columns;
}
 
开发者ID:z-chu,项目名称:FriendBook,代码行数:19,代码来源:MigrationHelper.java

示例3: isTableExists

import org.greenrobot.greendao.database.Database; //导入方法依赖的package包/类
/**
 * 是否存在表X
 *
 * @param db
 * @param isTemp
 * @param tableName
 */
private boolean isTableExists(Database db, boolean isTemp, String tableName) {
    if (db == null || TextUtils.isEmpty(tableName)) {
        return false;
    }
    String dbName = isTemp ? SQLITE_TEMP_MASTER : SQLITE_MASTER;
    String sql = "SELECT COUNT(*) FROM " + dbName + " WHERE type = ? AND name = ?";
    Cursor cursor = null;
    int count = 0;
    try {
        cursor = db.rawQuery(sql, new String[]{"table", tableName});
        if (cursor == null || !cursor.moveToFirst()) {
            return false;
        }
        count = cursor.getInt(0);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return count > 0;
}
 
开发者ID:RockyQu,项目名称:MVVMFrames,代码行数:30,代码来源:MigrationHelper.java

示例4: getColumns

import org.greenrobot.greendao.database.Database; //导入方法依赖的package包/类
/**
 * 获取一张表的列名
 *
 * @param db
 * @param tableName
 */
private static List<String> getColumns(Database db, String tableName) {
    List<String> columns = null;
    Cursor cursor = null;
    try {
        cursor = db.rawQuery("SELECT * FROM " + tableName + " limit 0", null);
        if (null != cursor && cursor.getColumnCount() > 0) {
            columns = Arrays.asList(cursor.getColumnNames());
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cursor != null)
            cursor.close();
        if (null == columns)
            columns = new ArrayList<>();
    }
    return columns;
}
 
开发者ID:RockyQu,项目名称:MVVMFrames,代码行数:25,代码来源:MigrationHelper.java

示例5: getColumns

import org.greenrobot.greendao.database.Database; //导入方法依赖的package包/类
/**
 * 获取表列名集合
 **/
private static List<String> getColumns(Database db, String tableName) {
    List<String> columns = new ArrayList<>();
    Cursor cursor = null;
    try {
        cursor = db.rawQuery("SELECT * FROM " + tableName + " limit 1", null);
        if (cursor != null) {
            columns = new ArrayList<>(Arrays.asList(cursor.getColumnNames()));
        }
    } catch (Exception e) {
        Log.v(tableName, e.getMessage());
        e.printStackTrace();
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return columns;
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:21,代码来源:MigrationHelper.java

示例6: getColumns

import org.greenrobot.greendao.database.Database; //导入方法依赖的package包/类
private List<String> getColumns(Database db, String tableName) {
    List<String> columns = new ArrayList<>();
    Cursor cursor = null;
    try {
        cursor = db.rawQuery("SELECT * FROM " + tableName + " limit 1", null);
        if (cursor != null) {
            columns = new ArrayList<>(Arrays.asList(cursor.getColumnNames()));
        }
    } catch (Exception e) {
        Log.v(tableName, e.getMessage(), e);
        e.printStackTrace();
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return columns;
}
 
开发者ID:newbiechen1024,项目名称:NovelReader,代码行数:18,代码来源:Update2Helper.java

示例7: queryString

import org.greenrobot.greendao.database.Database; //导入方法依赖的package包/类
public static String queryString(Database db, String sql) {
    Cursor cursor = db.rawQuery(sql, null);
    try {
        assertTrue(cursor.moveToNext());
        return cursor.getString(0);
    } finally {
        cursor.close();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:EncryptedDbUtils.java

示例8: updateCollBook

import org.greenrobot.greendao.database.Database; //导入方法依赖的package包/类
private void updateCollBook(Database db) {
    Class<? extends AbstractDao<?, ?>> collBookClass = CollBookBeanDao.class;

    // 遍历查找本地文件,然后修改本地文件的数据
    DaoConfig daoConfig = new DaoConfig(db, collBookClass);
    String tableName = daoConfig.tablename;

    Cursor cursor = db.rawQuery("select _ID,IS_LOCAL from " + tableName, null);
    String id = null;
    String cover = null;
    String isLocal = null;

    StringBuilder updateSb = new StringBuilder();
    while (cursor.moveToNext()) {
        cover = cursor.getString(0);
        id = MD5Utils.strToMd5By16(cover);
        isLocal = cursor.getString(1);

        //如果是本地文件
        if (isLocal.equals("1")) {
            // 数据更新
            updateSb.append("UPDATE " + tableName + " SET ");
            updateSb.append("_ID=").append(String.format(QUOTE, id)).append(DIVIDER);
            updateSb.append("COVER=").append(String.format(QUOTE, cover)).append(" ");
            updateSb.append("WHERE _ID=").append(String.format(QUOTE,cover)).append(";");

            db.execSQL(updateSb.toString());
            updateSb.delete(0, updateSb.length());
        }
    }
}
 
开发者ID:newbiechen1024,项目名称:NovelReader,代码行数:32,代码来源:Update2Helper.java

示例9: checkTable

import org.greenrobot.greendao.database.Database; //导入方法依赖的package包/类
/**
 * 检测table是否存在
 * @param db
 * @param tableName
 */
private static Boolean checkTable(Database db,String  tableName){
    StringBuilder query = new StringBuilder();
    query.append("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='").append(tableName).append("'");
    Cursor c = db.rawQuery(query.toString(), null);
    if (c.moveToNext()){
        int count = c.getInt(0);
        if(count>0){
            return true;
        }
        return false;
    }
    return false;
}
 
开发者ID:yzzslow0,项目名称:Ec2m,代码行数:19,代码来源:MigrationHelper.java


注:本文中的org.greenrobot.greendao.database.Database.rawQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。