我使用 ACRA 进行错误报告,在过去 30 天内,我收到了 6 个(我有成千上万的用户)崩溃报告,类似于以下内容:
android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 778)
at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:931)
at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)
at android.database.sqlite.SQLiteDatabase.replaceOrThrow(SQLiteDatabase.java:1411)
:
Run Code Online (Sandbox Code Playgroud)
这些发生在我的应用程序的各个部分。所有设备均为运行 Android 4.1.2 的三星设备。我怀疑是三星的错误,但我能做些什么来缓解这个问题吗?
我问这个问题是因为 StackOverflow 上的一些答案不是我要找的答案。我的问题是,在 Android 的早期版本(如 2.3)中,查询非常慢,并且我收到此消息。
我的错误信息
06:37:25.521: ERROR/CursorWindow(322): need to grow: mSize = 1048576, size = 45, freeSpace() = 43, numRows = 8928
07-12 06:37:25.521: ERROR/CursorWindow(322): not growing since there are already 8928 row(s), max size 1048576
我有 8928 行的原因是因为我正在做搜索建议,有人可以输入“t”并获得 8928 行或更大的行,这显然会冻结 Android 2.3。我无法限制我的搜索建议阈值,因为某些仅包含两个字符的结果可能有 20 个结果或 20000 个以上结果,具体取决于结果是什么。
此链接可能是获得答案的最佳位置。给定链接中的最后一个答案似乎很有希望,但是除非您这样做,否则无法获取行数,cursor.getCount()这需要您从大查询中获取行总数(例如 20000+ 结果),除非我'我想错了。有一些解决方法吗?您将如何在代码中执行此操作来解决 CursorWindow 问题?
如何在现有表 LOGIN 中添加列。这是我的示例代码。
这是我的 DataBaseAdapter 类:
public class DataBaseHelper extends SQLiteOpenHelper
{
public DataBaseHelper(Context context, String name,CursorFactory factory, int version)
{
super(context, name, factory, version);
}
// Called when no database exists in disk and the helper class needs
// to create a new one.
@Override
public void onCreate(SQLiteDatabase _db)
{
_db.execSQL(LoginDataBaseAdapter.DATABASE_CREATE);
}
// Called when there is a database version mismatch meaning that the version
// of the database on disk needs to be upgraded to the current version. …Run Code Online (Sandbox Code Playgroud) 我在 android 应用程序中有一个 SQLITE 数据库。为了提高应用程序性能,我想在将数据库添加到 Android 应用程序之前对其进行一些改进。
为了做到这一点:
我想删除/替换帐户表的名称字段中的特殊字符。这些特殊字符的 Unicode 范围为 8204-8207 (0x200C ~ 0x200F)。更新帐户表的正确 SQL 语法是什么?
我有一种情况,我想使用 Room 持久性库将数据插入 Master (store_master) 和 Mapping (store_mapping) 表中的一对多关系。我的实现如下:
@Entity(tableName = "store_master")
class Store {
@PrimaryKey(autoGenerate = true)
public var store_id: Int = 0
@SerializedName("name")
lateinit var store_name: String
}
@Entity(tableName = "store_mapping", foreignKeys = arrayOf(
ForeignKey(entity = Store::class,
parentColumns = arrayOf("store_id"),
childColumns = arrayOf("pic_id"),
onDelete = CASCADE)))
class StorePicture(@field:PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id") var id: Int,
@SerializedName("pic_id") var pic_id: Int?,
@SerializedName("image") var storage_picture: String?)
class StoreWithPictures {
@Embedded
var store: Store? = null
@Relation(parentColumn = "store_id",
entityColumn = …Run Code Online (Sandbox Code Playgroud) android android-sqlite android-room android-architecture-components android-jetpack
错误这一行:
mDataBase = SQLiteDatabase.openDatabase(dbPath, "123", null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
Run Code Online (Sandbox Code Playgroud)
打开数据库时。但怎么了?如何用密码打开数据库?谁能帮我?
error : net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master任何人都可以帮我解决它吗?提前致谢
import android.content.Context;
import android.database.SQLException;
//import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteOpenHelper;
import net.sqlcipher.database.SQLiteDatabase.CursorFactory;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.File;
import net.sqlcipher.database.SQLiteDatabase;
import android.app.Activity;
import android.os.Bundle;
public class DatabaseHelper extends SQLiteOpenHelper {
private static String TAG = DatabaseHelper.class.getName(); …Run Code Online (Sandbox Code Playgroud) 我在 Android O 上使用 Room 数据库,我不时遇到SQLiteDisckIOException,我尝试解决问题,但堆栈没有告诉我故障点在哪里。有人可以给我一些提示或如何解决此类问题以及这里的潜在问题是什么?我正在编写的应用程序将在位置更改时写入数据库,并且还有一些后台任务会在需要时定期更新数据库。
这是我看到的堆栈:
10-07 22:29:41.404 22214-22226/? E/DataBuffer: Internal data leak within a DataBuffer object detected! Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (internal object: com.google.android.gms.common.data.DataHolder@b0fef92)
10-07 22:29:41.405 22214-22226/? E/DataBuffer: Internal data leak within a DataBuffer object detected! Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (internal object: com.google.android.gms.common.data.DataHolder@db3ad63)
10-07 22:29:41.415 19847-19847/com.firsapp.testing E/Periodic: from PIM->onCreateOptionMenu
10-07 …Run Code Online (Sandbox Code Playgroud) 我需要在移动设备的内部存储或 SD 卡中对 SQLite 数据库进行离线备份。但我无能为力,这怎么可能。
我在 SO 上关注了许多线程,但他们建议将 DB 一个位置复制到另一个位置,这不适合我,也不适合Google Drive.
任何指导都是宝贵的。
我在玩 Room,在那里我找不到解决问题的方法。
下面是数据。
桌子
CREATE TABLE `Employee` (
`id` INTEGER NOT NULL,
`first_name` TEXT,
`last_name` TEXT,
PRIMARY KEY(`id`)
);
Run Code Online (Sandbox Code Playgroud)
表格数据
实体
@Entity(tableName = "Employee")
public class Employee {
@PrimaryKey
private int id;
@ColumnInfo(name = "first_name")
private String firstName;
@ColumnInfo(name = "last_name")
private String lastName;
..Getters & Setters..
}
Run Code Online (Sandbox Code Playgroud)
查询 1
@Query("Select * from Employee")
List<Employee> getEmployees();
Run Code Online (Sandbox Code Playgroud)
结果 成功
查询 2
@Query("Select first_name, last_name from Employee")
List<Employee> getEmployees();
Run Code Online (Sandbox Code Playgroud)
结果
错误:查询返回的列在 ***.Employee 中没有字段 [id],即使它们被注释为非空或原始。查询返回的列:[first_name, last_name]
如果我添加id到上面Query 2,它会起作用。
同样,如果我们 …
android android-sqlite android-room android-architecture-components
Android 上的 Room 具有一种机制,您可以通过该机制将数据库架构导出为 JSON,然后针对单元测试套件中导出的架构验证数据库迁移。我在具有多个主键的表上遇到了一个问题,其中在运行迁移后主键位置都是 1。然而,模式导出的 V1 和 V2 都以相同的顺序列出了主键。此外,导出到 JSON 的表架构包含[]索引的空列表 ( ),而内存测试数据库是使用索引的空值创建的。
我很好奇这是否是 Room 中的错误,或者我是否可能滥用测试框架。给定迁移中的唯一变化是添加了一个全新且不相关的表。这是我的测试代码:
@RunWith(RobolectricTestRunner::class)
class MigrationTest {
@Rule @JvmField
val helper: MigrationTestHelper = MigrationTestHelper(
InstrumentationRegistry.getInstrumentation(),
ApplicationDatabase::class.java.canonicalName,
FrameworkSQLiteOpenHelperFactory()
)
@Test
@Throws(IOException::class)
fun `Test migration from 1 to 2`() {
helper.createDatabase(TEST_DB, 1).apply {
close()
}
helper.runMigrationsAndValidate(TEST_DB, 2, true, MIGRATION_1_2)
}
companion object {
const val TEST_DB = "migration-test"
}
}
Run Code Online (Sandbox Code Playgroud)
运行此测试时,出现以下错误:
java.lang.IllegalStateException: Migration didn't properly handle: Foo
Expected: TableInfo{name='Foo', columns={bar=Column{name='bar', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=1, defaultValue='null'}, baz=Column{name='baz', …Run Code Online (Sandbox Code Playgroud) android-sqlite ×10
android ×8
android-room ×3
sqlite ×3
android-architecture-components ×2
database ×1
eclipse ×1
java ×1
sql ×1
sql-update ×1
sqlcipher ×1