SQLiteDatabase 绝地灬酷狼 2022-08-21 04:20 119阅读 0赞 List<AppInfo> appList = mAppInfoDBOptHelper.getMyInstalledAppInfos(); /\*\* \* 获取已安装的应用列表 \*/ public List<AppInfo> getMyInstalledAppInfos() \{ List<AppInfo> installedAppInfoList = new ArrayList<AppInfo>(); List<AppInfoEntity> appInfoList = new AppInfoDao(mContext).query( AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_INSTALL\_STATUS, Constant.INSTALLED\_STATUS); if (appInfoList != null && appInfoList.size() > 0) \{ for (AppInfoEntity installAppInfo : appInfoList) \{ String appId = installAppInfo.getAppId(); AppInfo appInfoTemp = new AppInfo(); if (appId != null) \{ detailAppInfo(appInfoTemp, installAppInfo); \} installedAppInfoList.add(appInfoTemp); \} \} return installedAppInfoList; \} /\*\* \* 指定数据表列名和列的值查询应用信息记录 \* \* @param whereColumn \* 表中的列名称 \* @param whereColumnValue \* 表中的列值 \* @return \*/ public synchronized List<AppInfoEntity> query(String whereColumn,String whereColumnValue) \{ List<AppInfoEntity> ret = null; if ((null == whereColumn) || (null == whereColumnValue)) \{ ILog.dPrint(TAG, "query parameter ERROR. " + " whereColumn=" + whereColumn + " whereColumn=" + whereColumnValue); return ret; \} SQLiteDatabase mDatabase = null; Cursor cursor = null; try \{ mDatabase = dbOpenHelper.getReadableDatabase(); // if(!mDatabase.isOpen())\{ // mDatabase.reopenReadWrite(); // \} while(mDatabase.isDbLockedByOtherThreads())\{ Thread.sleep(10); \} if (mDatabase != null) \{ cursor = mDatabase.rawQuery("select \* from " + AppStoreDataBaseHelper.APP\_INFO\_TABLE\_NAME + " where " + whereColumn + "=?" +" order by "+AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_ID, new String\[\] \{ whereColumnValue\}); if (null == cursor) \{ ILog.dPrint(TAG, "query() cursor is null"); \} else \{ int count = cursor.getCount(); if (count > 0) \{ ret = new ArrayList<AppInfoEntity>(); for (int i = 0; i < count; i++) \{ cursor.moveToNext(); AppInfoEntity retObj = cursor2Entity(cursor); ret.add(retObj); \} \} else \{ ILog.dPrint(TAG, "Can not find record in database by " + whereColumnValue + " and appInfoEntity"); \} \} \} else \{ ILog.dPrint(TAG, "You need open this database before get a record"); \} \} catch (IllegalStateException e) \{ ILog.ePrint(TAG, "IllegalStateException "); e.printStackTrace(); \} catch (Exception e) \{ e.printStackTrace(); \} finally \{ if (null != cursor) \{ cursor.close(); \} if (null != mDatabase) \{ dbOpenHelper.close(); \} \} return ret; \} private AppInfoEntity cursor2Entity(Cursor cursor) \{ AppInfoEntity ret = null; try \{ ret = new AppInfoEntity(); String\[\] fieldNames = new String\[\] \{ "id", "appId", "packageName", "typeName", "appName", "version", "versionCode", "size", "price", "language", "minSystem", "developer", "publishTime", "commentSize", "downloadTimes", "averageScore", "description", "installStatus", "updateStatus", "downloadStatus", "downloadOrder", "signCertId" \}; String\[\] tableCols = new String\[\] \{ AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_ID, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_APP\_ID, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_PACKAGE\_NAME, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_TYPE\_NAME, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_APP\_NAME, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_VERSION, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_VERSION\_CODE, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_SIZE, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_PRICE, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_LANGUAGE, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_MIN\_SYSTEM, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_DEVELOPER, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_PUBLISH\_TIME, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_COMMENT\_SIZE, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_DOWNLOAD\_TIMES, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_AVERAGE\_SCORE, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_DESCRIPTION, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_INSTALL\_STATUS, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_UPDATE\_STATUS, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_DOWNLOAD\_STATUS, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_DOWNLOAD\_TASK\_ORDER, AppStoreDataBaseHelper.APP\_INFO\_COLUMN\_SIGNCERTID \}; int\[\] propertyTypes = new int\[\] \{ AppStoreDataBaseHelper.LONG\_TYPE, AppStoreDataBaseHelper.STRING\_TYPE, AppStoreDataBaseHelper.STRING\_TYPE, AppStoreDataBaseHelper.STRING\_TYPE, AppStoreDataBaseHelper.STRING\_TYPE, AppStoreDataBaseHelper.STRING\_TYPE, AppStoreDataBaseHelper.STRING\_TYPE, AppStoreDataBaseHelper.LONG\_TYPE, AppStoreDataBaseHelper.DOUBLE\_TYPE, AppStoreDataBaseHelper.STRING\_TYPE, AppStoreDataBaseHelper.STRING\_TYPE, AppStoreDataBaseHelper.STRING\_TYPE, AppStoreDataBaseHelper.STRING\_TYPE, AppStoreDataBaseHelper.LONG\_TYPE, AppStoreDataBaseHelper.LONG\_TYPE, AppStoreDataBaseHelper.DOUBLE\_TYPE, AppStoreDataBaseHelper.STRING\_TYPE, AppStoreDataBaseHelper.STRING\_TYPE, AppStoreDataBaseHelper.STRING\_TYPE, AppStoreDataBaseHelper.STRING\_TYPE, AppStoreDataBaseHelper.LONG\_TYPE, AppStoreDataBaseHelper.STRING\_TYPE \}; AppStoreDataBaseHelper.cursor2Entity(ret, cursor, AppInfoEntity.class, fieldNames, tableCols, propertyTypes); \} catch (EntityConvertException e) \{ e.printStackTrace(); ret = null; \} catch (Exception e) \{ e.printStackTrace(); \} return ret; \} /\*\* \* @param entity \* 需要设置值的对象 \* @param cursor \* 数据库游标对象 \* @param clazz \* 需要设置值的对象的类型类对象 \* @param fieldNames \* 对象中的属性名数组 \* @param tableCols \* 数据库表中的字段数组 \* @param propertyTypes \* 对象中属性的类型数组 此三个参数必须,且数组长度必须一致 \* @throws EntityConvertException \*/ public static void cursor2Entity(Object entity, Cursor cursor, Class clazz, String\[\] fieldNames, String\[\] tableCols, int\[\] propertyTypes) throws EntityConvertException \{ if ((tableCols == null) || (fieldNames == null) || (propertyTypes == null)) \{ throw new EntityConvertException("must param is null!"); \} if ((tableCols.length != propertyTypes.length) || (tableCols.length != fieldNames.length)) \{ throw new EntityConvertException( "table Column counts not equal property length!"); \} for (int i = 0; i < tableCols.length; i++) \{ int index = cursor.getColumnIndex(tableCols\[i\]); if (index != -1) \{ int type = propertyTypes\[i\]; switch (type) \{ case BLOB\_TYPE: byte\[\] propertyVal1 = cursor.getBlob(index); setObjVal(entity, clazz, fieldNames\[i\], propertyVal1); break; case SHORT\_TYPE: short propertyVal2 = cursor.getShort(index); setObjVal(entity, clazz, fieldNames\[i\], propertyVal2); break; case INT\_TYPE: int propertyVal3 = cursor.getInt(index); setObjVal(entity, clazz, fieldNames\[i\], propertyVal3); break; case LONG\_TYPE: long propertyVal4 = cursor.getLong(index); setObjVal(entity, clazz, fieldNames\[i\], propertyVal4); break; case FLOAT\_TYPE: float propertyVal5 = cursor.getFloat(index); setObjVal(entity, clazz, fieldNames\[i\], propertyVal5); break; case DOUBLE\_TYPE: double propertyVal6 = cursor.getDouble(index); setObjVal(entity, clazz, fieldNames\[i\], propertyVal6); break; case STRING\_TYPE: String propertyVal7 = cursor.getString(index); setObjVal(entity, clazz, fieldNames\[i\], propertyVal7); break; \} \} \} \}
相关 android icursor 添加数据,Xamarin.Android 本地数据库 SQLiteDatabase 操作 usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingAndro 怼烎@/ 2022年10月05日 07:56/ 0 赞/ 73 阅读
相关 android自带数据库SQLiteDatabase基础使用 学习android有一段时间了,前几天学习了android内置的数据库SQLite的使用,学习了一下基础的增删改查,现在就总结一下。下面是总结的使用sql语句的的查看,至于不使 Love The Way You Lie/ 2022年09月21日 14:30/ 0 赞/ 498 阅读
相关 SQLiteDatabase List<AppInfo> appList = mAppInfoDBOptHelper.getMyInstalledAppInfos(); /\\ 绝地灬酷狼/ 2022年08月21日 04:20/ 0 赞/ 120 阅读
相关 Android 数据存储之SQLiteDatabase 上一篇文章总结了文件存储和SharedPreference两种存储方式,我们知道这两种存储方式都只适合存储数据结构简单的数据,当我们需要存储类似表格数据时,Android 内置 古城微笑少年丶/ 2022年06月18日 05:36/ 0 赞/ 203 阅读
相关 Android 中数据存储(File,SharedPreference,SqliteDatabase) 对于数据存储,android提供了三种方式: File SharedPreferences SQLite -------------------- F 待我称王封你为后i/ 2022年06月18日 00:52/ 0 赞/ 250 阅读
相关 SQLiteDatabase工具类(增删改查) SQLite 是一个软件库,实现了自给自足的、无服务器的、零配置的、事务性的 SQL 数据库引擎。SQLite 是在世界上最广泛部署的 SQL 数据库引擎。SQLit 梦里梦外;/ 2022年05月12日 05:36/ 0 赞/ 269 阅读
相关 attempt to re-open an already-closed object: SQLiteDatabase attempt to re-open an already-closed object: SQLiteDatabase: 原因:执行 sql 语句前调用了 sql.close 素颜马尾好姑娘i/ 2022年03月18日 05:11/ 0 赞/ 432 阅读
还没有评论,来说两句吧...