没有这个表android_metadata,有什么问题?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2528489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:11:36  来源:igfitidea点击:

No such table android_metadata, what's the problem?

androidsqlite

提问by user275788

I am copying a pre-existing database to /data/data/packagename/databasesusing code learned from using-your-own-sqlite-database-in-android-applications

我正在将预先存在的数据库复制到/data/data/packagename/databases使用从using-your-own-sqlite-database-in-android-applications中学到的代码

After copying, I recieve the following log message on opening the database:

复制后,我在打开数据库时收到以下日志消息:

No such table android_metadata

没有这样的表 android_metadata

Do I need to create a table named android_metadata? And what the values do i need insert into this database table

我需要创建一个名为 android_metadata 的表吗?我需要将哪些值插入到这个数据库表中

Thanks very much

非常感谢

回答by foryou

Actually, with a bit more reading, I have discovered that I need to use the SQLiteDatabase.NO_LOCALIZED_COLLATORSflag when calling SQLiteDatabase.openDatabase()- this no longer causes the problem.

实际上,通过更多阅读,我发现我需要SQLiteDatabase.NO_LOCALIZED_COLLATORS在调用时使用标志 SQLiteDatabase.openDatabase()- 这不再导致问题。

回答by dIvYaNsH sInGh

Use

SQLiteDatabase.openDatabase(dbPath, null,SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.CREATE_IF_NECESSARY);

or

或者

SQLiteDatabase.openDatabase(dbPath, null,SQLiteDatabase.OPEN_READWRITE);

回答by Janusz

It seems that for some reason android requires every database to have a table called android_metadata that includes at least one locale. The reigndesignblog you mentioned tells you how to create the table and prefill it with a locale.

似乎出于某种原因,android 要求每个数据库都有一个名为 android_metadata 的表,其中至少包含一个语言环境。您提到的ruledesign博客告诉您如何创建表并用语言环境预填充它。

Check if your database contains this table and if the table has some content.

检查您的数据库是否包含此表以及该表是否包含某些内容。

回答by hrehman

When you copy database from your assets directory for example, then you must have android_metadata table created in it already. This table should have two columns:

例如,当您从资产目录复制数据库时,您必须已经在其中创建了 android_metadata 表。这个表应该有两列:

_id = an integer value
locale = en

回答by Jan Berkel

it might also just be file permissions - the error message is misleading. first you need to find out the user id of the app (this is assuming you have root access):

它也可能只是文件权限 - 错误消息具有误导性。首先,您需要找出应用程序的用户 ID(假设您具有 root 访问权限):

$ adb shell grep <packagename> /data/system/packages.xml

output should look like:

输出应如下所示:

<package name="com.fsck.k9" codePath="/data/app/com.fsck.k9-1.apk" 
nativeLibraryPath="/data/data/com.fsck.k9/lib" 
flags="0" ft="1306ecac340" it="1306ecac9d2" ut="1306ecac9d2"
version="14001" userId="10002">

userId here is 10002.

这里的用户 ID 是 10002。

then fix permissions:

然后修复权限:

$ adb shell chown -R 10002:10002 /data/data/<packagename>

回答by Vishal Khakhkhar

I am already using as given in that link for a long time..

我已经在该链接中使用了很长时间了..

It works.. Checkout your DB again the table created or not ?

它有效.. 再次检查您的数据库是否创建了表?

I prefer to install SQLite Manager plugin in firefox for sqlite database operation.. after completing all process as mentioned in the same link..

我更喜欢在firefox中安装SQLite Manager插件以进行sqlite数据库操作..在完成同一个链接中提到的所有过程后..

Checkout http://www.devx.com/wireless/Article/40842/1954.

结帐http://www.devx.com/wireless/Article/40842/1954

It contains all database operations.

它包含所有数据库操作。

回答by Christian

In my case, I have discovered that this error will happen if I leave an open transactionleft.

就我而言,我发现如果我离开open transaction左边会发生这个错误。

In other words: If you forget to commitor rollbacka transaction, in the next time you enter in your application, this error raises up.

换句话说:如果您忘记commitrollback交易,在您下次进入您的应用程序时,会出现此错误。