大佬教程收集整理的这篇文章主要介绍了如何使用 Xamarin Forms 中的 sqlite-net-pcl 从 sqlite3 db 的列中读取`uuid`,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个我无法控制的数据库架构(它是从我需要与之交互的桌面应用程序导出的 sqlite3 文件),其中包含某些列的 UUID。我在 Xamarin.Forms 应用程序中使用 sqlite-net-pcl
,但我不知道如何成功读取这些列。这是我尝试过的:
uuID
,并使用 SELEct count(disTinct uuIDcolumn) from myTable;
我已确认每行都有值。 (该列可以为空,这与下面的代码片段相关,但实际上所有行都具有非空值)namespace brahms.Model
{
[table("myTable")]
public class myTable
{
[column("uuIDcolumn")]
public GuID UUIDcolumn { get; }
[primaryKey,autoIncrement,NotNull]
[column("recordID")]
public int RecordID { get; set; }
}
}
@H_502_4@
database.query<myTable>()
查询获取对象,UUIDcolumn
总是等于 GuID.Empty
。Byte[]
;总是null
。String
;总是null
。UInt16[]
类型(GUID 可能存储为 16 位字的 blob,所以我也尝试了该类型)如何使用 uuID
读取 sqlite-net-pcl
类型列中的值?
我放弃了在 sqlite-net-pcl
中使用 ORM 功能并使用了这个查询:
db.executeScalar<byte[]>('SELEct hex(uuidcolumn) from myTable where recordid=1');
我得到的是 72 个字节,它似乎代表了 Guid 的字符串表示中的 36 个 ASCII 字符(经常有一个字符是 2D
,它是 -
ASCII 集)。所以我认为后备存储是一个 blob,但它存储了 Guid 的文本表示,这很奇怪,但我可以从这里重建 Guid。
使用 this answer 并将该 blob 作为字符串获取,我最终得到了这个实现:
public Guid GetUUIDcolumn()
{
String dbRep = _database.ExecuteScalar<String>("SELEct hex(uuidcolumn) from myTable where recordid = ?",RecordID);
if (dbRep == null || dbRep == String.Empty) return Guid.Empty;
var bytes = new byte[dbRep.Length / 2];
// each pair of bytes represents the ASCII code (in hexadecimal) for a character in the String representation of a Guid.
for (var i = 0; i < bytes.Length; i++)
{
bytes[i] = Convert.ToByte(dbRep.SubString(i * 2,2),16);
}
String asString = Encoding.ASCII.GetString(bytes);
return new Guid(asString);
}
以上是大佬教程为你收集整理的如何使用 Xamarin Forms 中的 sqlite-net-pcl 从 sqlite3 db 的列中读取`uuid`全部内容,希望文章能够帮你解决如何使用 Xamarin Forms 中的 sqlite-net-pcl 从 sqlite3 db 的列中读取`uuid`所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。