我正在从SQLite获取数据库锁定异常仅用于某些查询.
下面是我的代码:当我执行任何select语句时,它工作正常.
当我在JobsTable 上执行任何写语句时,它也可以正常工作.
这很好用:
ExecuteNonQuery("DELETE FROM Jobs WHERE id=1");
Run Code Online (Sandbox Code Playgroud)
但是,如果我正在执行对Employees表的查询,它会抛出数据库被锁定的异常.
抛出异常:
ExecuteNonQuery("DELETE FROM Employees WHERE id=1");
Run Code Online (Sandbox Code Playgroud)
以下是我的功能:
public bool OpenConnection()
{
if (Con == null)
{
Con = new SQLiteConnection(ConnectionString);
}
if (Con.State == ConnectionState.Closed)
{
Con.Open();
//Cmd = new SQLiteCommand("PRAGMA FOREIGN_KEYS=ON", Con);
//Cmd.ExecuteNonQuery();
//Cmd.Dispose();
//Cmd=null;
return true;
}
if (IsConnectionBusy())
{
Msg.Log(new Exception("Connection busy"));
}
return false;
}
public Boolean CloseConnection()
{
if (Con != null && Con.State …Run Code Online (Sandbox Code Playgroud) 我正在调查SQLite作为存储引擎,并且很想知道SQLite是否在读取时锁定数据库文件.
我担心读取性能,因为我计划的项目写入很少,但许多读取.如果数据库确实锁定了,是否可以采取措施(例如内存缓存)来缓解这个问题?
我在Android设备上创建了一个SQLite数据库.程序可以读/写数据库,因此显然已经创建了数据库文件.SQLiteDatabase.mPath设置为
db.mPath = "/data/data/dev.client.android/databases/clientDB.db"
Run Code Online (Sandbox Code Playgroud)
但是当我浏览设备上的目录时,我找不到文件clientDB.db.我查看了数据目录,但似乎是空的.
有谁知道这里有什么不对吗?
Oracle最近向SQLite发布了Berkeley DB后端.我碰巧有一个数百兆字节的SQLite数据库,可以从"改进的性能,并发性,可伸缩性和可靠性"中获益,但Oracle的网站似乎缺乏对这些改进的任何测量.有没有人在这里做过一些基准测试?
我想在我的应用程序中创建一个SQLite数据库,其中包含三个表,我将数据添加到表中,稍后将使用它们.
但我喜欢保留数据库,好像当第一次安装应用程序时,它会检查数据库是否存在,如果存在则更新它,否则创建新数据库.
我正在创建一个DB类来方便我的应用程序,所以我不会为我的数据库创建创建一个活动.
如果有可能的建议,请与我分享
我有一张表,其中包含一些记录,其中包括姓名,评级等字段.
我首先要根据评级限制结果排序到20,然后在此结果集上希望进一步根据名称应用排序.
我知道要排序我们需要使用像这样的查询
Select * from table order by rating Desc limit 20
Run Code Online (Sandbox Code Playgroud)
但是在这个结果集上如何应用另一个级别的排序?如何在一个sqlite语句中组合这两种类型?
我生成一个SQLite表(在java中):
create table participants (ROWID INTEGER PRIMARY KEY AUTOINCREMENT, col1,col2);
Run Code Online (Sandbox Code Playgroud)
之后我尝试使用INSERT命令添加行:
insert into participants values ("bla","blub");
Run Code Online (Sandbox Code Playgroud)
我收到错误:
java.sql.SQLException: table participants has 3 columns but 2 values were supplied
Run Code Online (Sandbox Code Playgroud)
我以为行ID会自动生成,但似乎我错过了任何东西.
我试过另一个解决方案
PreparedStatement prep = conn.prepareStatement("insert into participants values (?,?,?);");
Integer n = null;
prep.setInt(1,n);
prep.setString(2, "bla");
prep.setString(3, "blub");
prep.addBatch();
prep.executeBatch();
Run Code Online (Sandbox Code Playgroud)
结果我收到了"prep.setInt(1,n);"的空指针异常.
你看到了错吗?
我想检查记录是否存在.
这是我尝试过的:
MainActivity.class
public void onTextChanged(CharSequence s, int start, int before, int count) {
System.out.println("Ontext changed " + new String(s.toString()));
strDocumentFrom = s.toString();
if(s.toString().isEmpty()){
} else {
try{
strTransactionDate = dbHelper.getTransactionDateByDocumentNumber(strDocumentFrom);
//strTotalAmount = dbHelper.getTotalAmountByDocumentNumber(strDocumentFrom);
//strVan = dbHelper.getVanByDocumentNumber(strDocumentFrom);
//etTransactionDate.setText(strTransactionDate);
//etTotalAmount.setText(strTotalAmount);
//Log.d("Van", "" + strVan);
//etVan.setText(strVan);
} catch (SQLiteException e) {
e.printStackTrace();
Toast.makeText(ReceivingStocksHeader.this,
"Document number does not exist.", Toast.LENGTH_SHORT).show();
}
}
Run Code Online (Sandbox Code Playgroud)
DBHelper.class
// TODO DISPLAYING RECORDS TO TRANSRCVHEADER
public String getTransactionDateByDocumentNumber(String strDocumentNumber){
String[] columns = new String[]{KEY_TRANSACTIONDATE};
Cursor c = myDataBase.query(TBL_INTRANS,
columns, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用SQLite实体框架.我将问题集成到我的主应用程序中时遇到了问题,因此我从头开始进行了一些测试,完全按照http://brice-lambson.blogspot.com/2012/10/entity-framework-on-sqlite.html上的说明进行操作.
毕竟说完了,运行项目时出现以下错误:
没有为ADO.NET提供程序找到具有不变名称"System.Data.SQLite"的实体框架提供程序.确保提供程序已在应用程序配置文件的"entityFramework"部分中注册.有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=260882.
我的app.config看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<add name="SQLite Data Provider"
invariant="System.Data.SQLite"
description="Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="ChinookContext"
connectionString=
"Data Source=|DataDirectory|Chinook_Sqlite_AutoIncrementPKs.sqlite"
providerName="System.Data.SQLite" />
</connectionStrings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
然后我看到他关于实体框架6的帖子.虽然这不是我得到的确切错误,但我尝试通过NuGet安装他更新的提供程序.错误消失了,但取而代之的是:
无法加载文件或程序集'System.Data.SQLite.Linq,Version = 2.0.88.0,Culture = neutral,PublicKeyToken = db937bc2d44ff139'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040) …
我有两个主要问题.
我的android应用程序中有一个数据库.我用java创建它
class as follows.
public DataBaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public DataBaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, DatabaseErrorHandler errorHandler) {
super(context, name, factory, version, errorHandler);
}
@Override
public void onCreate(SQLiteDatabase db) {
// creating required tables
db.execSQL(CREATE_TABLE_QUOTES);
db.execSQL(CREATE_TABLE_FILTERS);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// on upgrade drop older tables
db.execSQL("DROP TABLE IF EXISTS " + TABLE_QUOTES);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_QUOTES);
// create new …Run Code Online (Sandbox Code Playgroud) sqlite ×10
android ×4
.net ×2
c# ×2
database ×2
ado.net ×1
android-file ×1
benchmarking ×1
berkeley-db ×1
java ×1
sorting ×1
sql ×1