我正在寻找一段时间来回答我的问题,但我没有得到我需要的东西.我有一个带有ListView的应用程序,以及可以向DB添加新记录的表单.所以没有太多的疑问要做.
如何处理与db的连接?我应该在得到我想要的东西之后将其关闭,还是应该一直打开它直到应用程序关闭?我想知道在考虑性能和电池寿命时最好的方法是什么.
我正在开发一个Android应用程序,它在Android平台提供的内置SQLite中存储不同类型的数据.
在应用程序内部我放置了一个"同步"按钮,该按钮应该在本地SQLite数据库与我的服务器上的在线SQL Server数据库之间同步数据.
处理此问题的解决方法是什么?您可以在Google日历中找到此功能,您可以在其中查看手机上的日历活动,当您添加新活动和同步数据时,您也可以通过转到在线帐户查看更新的数据.
注意:我不想在线集中我的数据库,因为我还想让移动用户能够在没有互联网连接的情况下使用该应用程序.
我知道这已经讨论过但我想问一下目前的情况.我是否必须创建一个ContentProvider以将CursorLoader与sqlite数据库结合使用?
我发现
没有ContentProvider的CursorLoader用法
正如Emmby评论的那样,看起来正是我所希望的
因此提到了另一种解决方案
https://github.com/commonsguy/cwac-loaderex
还指出了一些缺点
当然,在使用LoaderManager时,我们希望获得它所引入的所有好处.所以我的问题是,如果有一种方法可以使用LoaderManager连接sqlite数据库,而无需实现内容提供程序,但具有它的所有好处.
谢谢
sqlite android android-contentprovider android-loadermanager
我正在阅读有关此问题的stackoverflow,但我仍然没有找到解决方案.我注意到有时,我的应用程序会抛出此错误:
java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.
at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:962)
at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:599)
at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:348)
at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894)
...
Run Code Online (Sandbox Code Playgroud)
我有一个名为DatabaseHelper.java的文件,使用这种方法获取它的实例:
public static DatabaseHelper getInstance(Context context) {
if (mInstance == null) {
mInstance = new DatabaseHelper(context.getApplicationContext());
}
return mInstance;
}
Run Code Online (Sandbox Code Playgroud)
然后我有像这样的方法(它在行cursor.moveToFirst()中崩溃与该错误).它几乎从不崩溃,但有时它会崩溃.
public Profile getProfile(long id) {
SQLiteDatabase db = this.getReadableDatabase();
String selectQuery = "SELECT * FROM " + TABLE_PROFILES + " WHERE " + KEY_PROFILES_ID + " = " + id;
Cursor cursor = db.rawQuery(selectQuery, null);
// looping …Run Code Online (Sandbox Code Playgroud) 我正在为iPhone开发,我正在寻找一个好的Cocoa/Objective-C库来处理SQLite.我不想使用标准的过程SQLite C API.我在Objective-C部分的sqlite.org上看到了选项,但我不确定在库API设计,稳定性和功能方面哪个是最好的.我想使用一些积极开发的东西,希望能够存在一段时间.任何人都有基于经验的建议吗?
谢谢
我有下表:
CREATE TABLE child(
id INTEGER PRIMARY KEY,
parent_id INTEGER CONSTRAINT parent_id REFERENCES parent(id),
description TEXT);
Run Code Online (Sandbox Code Playgroud)
如何删除约束?
我正在复制一个预先存在的数据库,/data/data/packagename/databases使用从using-your-own-sqlite-database-in-android-applications中学到的代码
复制后,我在打开数据库时收到以下日志消息:
没有这样的表android_metadata
我是否需要创建一个名为android_metadata的表?我需要将值插入此数据库表中
非常感谢
我正在使用这些query函数来为我的表构建SQL查询.有没有办法看到运行的实际查询?比如把它记在某个地方?
到目前为止,我能做的最好的事情是使用断点查看游标的成员mQuery.我喜欢自动输出查询.该会员当然不公开,也没有吸气剂.
仅供记录,这是接受答案的实现.
/**
* Implement the cursor factory in order to log the queries before returning
* the cursor
*
* @author Vincent @ MarvinLabs
*/
public class SQLiteCursorFactory implements CursorFactory {
private boolean debugQueries = false;
public SQLiteCursorFactory() {
this.debugQueries = false;
}
public SQLiteCursorFactory(boolean debugQueries) {
this.debugQueries = debugQueries;
}
@Override
public Cursor newCursor(SQLiteDatabase db, SQLiteCursorDriver masterQuery,
String editTable, SQLiteQuery query) {
if (debugQueries) {
Log.d("SQL", query.toString());
}
return new SQLiteCursor(db, masterQuery, editTable, query);
} …Run Code Online (Sandbox Code Playgroud) 去年,当我在他们的网站上检查SQLite时,建议的SQLite数据库大小为2千兆字节.但现在,我再也找不到这个建议了.
那么有没有人试图使用一个大于2千兆字节的SQLite数据库使用它的最新版本?SQLite的表现如何?
PS:我想创建一个移动应用程序,需要在本地工作的大数据库(例如存储维基百科文章).
我正在尝试创建一个从sqlite3数据库中获取数据的脚本,但我遇到了一个问题.
数据库中的字段是文本类型,包含html格式化文本.见下文
<html>
<head>
<title>Yahoo!</title>
</head>
<body>
<style type="text/css">
html {}
.yshortcuts {border-bottom:none !important;}
.ReadMsgBody {width:100%;}
.ExternalClass{width:100%;}
</style>
<table cellpadding="0" cellspacing="0" bgcolor="#ffffff">
<tr>
<td width="550" valign="top" align="left">
<table cellpadding="0" cellspacing="0" width="500">
<tr>
<td colspan="3"><img src="http://mail.yimg.com/nq/assets/sharedmessages/v1/us/logo.gif" width="292" height="51" style="display:block;" border="0" alt="Yahoo! Mail"></td>
</tr>
<tr>
<td rowspan="3" width="1" bgcolor="#c7c4ca"></td>
<td width="498" height="1" bgcolor="#c7c4ca"></td>
<td rowspan="3" width="1" bgcolor="#c7c4ca"></td>
</tr>
<tr>
<td width="498" valign="top" align="left">
<table cellpadding="0" cellspacing="0">
<tr>
<td width="498" bgcolor="#61399d" align="left" valign="top">
<table cellspacing="0" cellpadding="0"><tr><td height="24"></td></tr></table>
<div style="font-family:Arial, Helvetica, sans-serif;font-size:23px;line-height:27px;margin-bottom:10px;color:#ffffff;margin-left:15px;"><span style="color:#ffffff;text-decoration:none;font-weight:bold;line-height:27px;">Välkommen till …Run Code Online (Sandbox Code Playgroud) sqlite ×10
android ×6
database ×2
cocoa-touch ×1
constraints ×1
ddl ×1
iphone ×1
java ×1
logging ×1
objective-c ×1
python ×1
python-3.x ×1
singleton ×1
sql ×1