标签: sqlite-net

SQLite.net表查询抛出NullReferenceException

我正在使用以下代码行来查询SQLite数据库中给定表的一些数据(平台是WP81,但我想这并不重要).

return await Connection.Table<WorkDay>().Where(wd => wd.Date >= @from && wd.Date <= to).ToListAsync().ConfigureAwait(false);
Run Code Online (Sandbox Code Playgroud)

当我执行我的代码时,我在Where子句中得到一个NullReferenceException.当我删除where条件时一切正常.

return await Connection.Table<WorkDay>().ToListAsync().ConfigureAwait(false);
Run Code Online (Sandbox Code Playgroud)

为了确保我的表中的所有条目都有效并且Date列中没有空值,我使用SQL工具查看SQLite数据库.

因为我无法调试lambda表达式,所以我有点坚持如何在这里找到问题.我的假设是由于异步处理而出现问题.

编辑: 这是异常的确切堆栈跟踪

{System.NullReferenceException: Object reference not set to an instance of an object.
   at SQLite.Net.TableQuery`1.CompileExpr(Expression expr, List`1 queryArgs)
   at SQLite.Net.TableQuery`1.CompileExpr(Expression expr, List`1 queryArgs)
   at SQLite.Net.TableQuery`1.CompileExpr(Expression expr, List`1 queryArgs)
   at SQLite.Net.TableQuery`1.GenerateCommand(String selectionList)
   at SQLite.Net.TableQuery`1.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at SQLite.Net.Async.AsyncTableQuery`1.<ToListAsync>b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at …
Run Code Online (Sandbox Code Playgroud)

c# sqlite async-await sqlite-net

8
推荐指数
1
解决办法
1972
查看次数

未找到 libSQLite.Interop Mac OS | M1

我在 M1 Pro 上使用 dotnet 6,并且正在努力使用 SQLite-Package。

System.DllNotFoundException: Unable to load shared library 'SQLite.Interop.dll' or one of its dependencies.

这是每当我尝试运行该应用程序时引发的错误。然而建筑工作正常。

.net sqlite-net apple-m1 .net-6.0

8
推荐指数
2
解决办法
2841
查看次数

sqlite-net中的SqliteDataReader在哪里?

我正在尝试移植使用本机Sqlite3并大量使用的iOS应用程序SqliteDataReader.在目标平台上,我使用SQLIte-Net(https://github.com/praeclarum/sqlite-net),并且SqliteDataReader类不存在.转换它的最佳选择是什么?读者的使用总是这样的代码:

SqliteConnection oConn = AppDelegateBase.MasterDatabase.CreateDBMSConnection();
using ( SqliteCommand oCmd = new SqliteCommand ( "SELECT * FROM ATable"), oConn ) )
using ( var oReader = oCmd.ExecuteReader (  ) )
{
  while ( oReader.Read (  ) )
  {
    int val = Convert.ToInt32(oReader["someColumn"]);
  }
  oReader.Close ();
}
Run Code Online (Sandbox Code Playgroud)

.net c# sqlite sqlite-net

7
推荐指数
1
解决办法
2309
查看次数

查询bool列始终返回false

我在我的项目中使用SQLite并连接到DB我使用sqlite-net库.我创建了一个模型:

internal class Product
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    public string Name { get; set; }

...

    public bool IsDefault { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

数据库中有一些记录 - 有些记录的IsDefault列值设置为true,有些记录为false.但是,当我尝试查询这样的记录时:

var result = dc.Table<Product>().ToArray();
Run Code Online (Sandbox Code Playgroud)

每条记录都将IsDefault设置为false.插入记录工作正常,但查询不行.

当我将列类型更改为bool时?在模型中,它返回null.

编辑----当我执行查询时,奇怪的是什么

var t = dc.Table<Product>().Where(i => i.IsDefault == true).ToArray();
Run Code Online (Sandbox Code Playgroud)

它返回正确的记录数,但即使如此,每个数组项都将IsDefault设置为false.

c# database sqlite sqlite-net

7
推荐指数
1
解决办法
1253
查看次数

SQLite-Net扩展两个实体之间的一对一和一对多关系

我正在使用SQLite-Net PCL和SQLite-Net扩展来开发使用Xamarin的应用程序.

在我的模型中,我有两个实体,让我们称它们为A和B,它们通过一对一和一对多的关系连接起来.例如,A与B具有一对一的关系,A与B具有一对多的关系.

是否可以用SQLite-Net扩展表达这种行为?

sqlite xamarin sqlite-net sqlite-net-extensions

7
推荐指数
1
解决办法
7155
查看次数

将SQLite-net升级到SQLite.net - 创建SQLiteConnection

我以前SQLiteConnection在我的共享项目中打开了以下内容:

var conn = new SQLiteConnection("MyDb.db3");
Run Code Online (Sandbox Code Playgroud)

构造函数已更改为以下签名:

    public SQLiteConnection(ISQLitePlatform sqlitePlatform, string databasePath, bool storeDateTimeAsTicks = true, IBlobSerializer serializer = null, IDictionary<string, TableMapping> tableMappings = null, IDictionary<Type, string> extraTypeMappings = null, IContractResolver resolver = null);
    public SQLiteConnection(ISQLitePlatform sqlitePlatform, string databasePath, SQLiteOpenFlags openFlags, bool storeDateTimeAsTicks = true, IBlobSerializer serializer = null, IDictionary<string, TableMapping> tableMappings = null, IDictionary<Type, string> extraTypeMappings = null, IContractResolver resolver = null);
Run Code Online (Sandbox Code Playgroud)

我无法找到有关如何在我的共享库中实现此功能的任何示例/文档.

database-connection xamarin sqlite-net

7
推荐指数
1
解决办法
3023
查看次数

将SQLite-NET与UWP结合使用

我从NuGet下载了软件包,但仍然没有SQLite.cs,SQLiteAsync.cs也没有添加到项目中,如果SQLite-NET仍然不支持VS 2015 RTM,还有其他可能的选择吗?

请注意,我尝试过SQLite.NET-PCL,但问题仍然存在.

sqlite sqlite-net windows-10 visual-studio-2015 uwp

7
推荐指数
1
解决办法
1万
查看次数

SQLite.Net 更新生成错误“它没有 PK”

我在使用 Xamarin 的 PCL 中使用 Lync 语法。

public class settings
{

    [PrimaryKey, AutoIncrement]
    public int ID { get; set; }

    public string user_name { get; set; }
    public string password { get; set; }
    public string server { get; set; }

}

void CreateTables()
{
    database.CreateTable<settings>();
}

void Insert()
{    
     settings s = new settings();
     s.server = "<none>"
     s.user_name = "";
     s.password = "";
     database.Insert(s)
}

void Update()
{
     settings s = database.Table<settings>().FirstOrDefault();
     s.server = server_address.Text;
     s.user_name = user_name.Text;
     s.password …
Run Code Online (Sandbox Code Playgroud)

xamarin sqlite-net

6
推荐指数
1
解决办法
3398
查看次数

System.Data.SQLite 和 sqlite-net-pcl 的区别

鉴于我已经阅读了Xamarin关于本地数据库的文档,我只是对此感到好奇。

sqlite-net-pcl是专为与XAMARIN?一起使用而设计的。我的意思是,如果他们都运行SQLite数据库引擎,那么假设我也可以使用System.Data.SQLiteNuGet 包是否安全?

SQLITE-NET-PCL NuGet Package

在此处输入图片说明

SYSTEM.DATA.SQLITE NuGet Package

在此处输入图片说明

会不会造成伤害?还是真的,而且只推荐使用这个sqlite-net-pcl插件?

希望有人能用这个来澄清我。

另外,我正在考虑Dapper ORM在我的Xamarin.Android项目中实现SQLite Database Engine. 我已经使这种方法适用于标准WinForm Apps. 所以也可以使用Xamarin.Android?

sqlite system.data.sqlite xamarin.android xamarin sqlite-net

6
推荐指数
1
解决办法
3818
查看次数

无法加载 DLL 'e_sqlite3':找不到指定的模块

我有一个 Xamarin Forms 解决方案。我添加了 sqlite-net-pcl 作为所有项目的参考。它在 Android 上运行良好,但在 Windows 8.1 和 Windows Phone 8.1 上崩溃。我有一个 IOS 项目,但我目前没有 OSX 来尝试它。

我在 Windows 项目中使用它来访问数据库:

using System.IO;
using SQLite;
using Xamarin.Forms;
using HelloXamarin.Windows;
using Windows.Storage;

[assembly: Dependency(typeof(SQLiteDb))]

namespace HelloXamarin.Windows
{
   public class SQLiteDb : ISQLiteDb
    {
        public SQLiteAsyncConnection GetConnection(string databaseName)
        {
            var documentsPath = ApplicationData.Current.LocalFolder.Path;
            var path = Path.Combine(documentsPath, databaseName);
            return new SQLiteAsyncConnection(path);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

以下是我的参考资料:

参考

尝试访问数据库时出现此异常:

“SQLite.SQLiteConnection”的类型初始值设定项引发异常。

无法加载 DLL 'e_sqlite3':找不到指定的模块。(来自 HRESULT 的异常:0x8007007E)

  • 在 SQLitePCL.SQLite3Provider_e_sqlite3.NativeMethods.sqlite3_win32_set_directory(UInt32 directoryType, String directoryPath)
  • 在 SQLitePCL.SQLite3Provider_e_sqlite3..ctor()
  • 在 SQLitePCL.Batteries_V2.Init() …

windows sqlite xamarin sqlite-net xamarin.forms

6
推荐指数
2
解决办法
5474
查看次数