當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。