我在 sqlite 表中有一个带有 \0 字符和文本字段的 UTF 字符串。
当我尝试将字符串插入表文本字段然后从数据库中读取它时,我注意到字符串值在 \0 字符后被截断。
问题:是否有可能在 sqlite 中保存/恢复这样的字符串而不会在\0之后丢失数据?
代码片段:
public static void IssueWith0Character()
{
const string sql = "DROP TABLE IF EXISTS SomeTable;" +
"CREATE TABLE SomeTable (SomeField TEXT not null);"
+ "INSERT INTO SomeTable (SomeField) Values ( :value )";
var csb = new SQLiteConnectionStringBuilder
{DataSource = "stringWithNull.db", Version = 3};
// string with '0' character
const string stringWithNull = "beforeNull\0afterNull";
using (var c = new SQLiteConnection(csb.ConnectionString))
{
c.Open();
using (var cmd …Run Code Online (Sandbox Code Playgroud)