本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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());
}
}
}
示例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;
}