系统间缓存字符串为 %Stream.GlobalCharacter

Intersystems Cache String as %Stream.GlobalCharacter

我正在尝试将相当长的字符串保存(并加载)到缓存 Class String(MAXLEN=1024000) 属性.

该字符串大约有 32,000 个字符长,而不是存储字符串内容(这是一个 JSON 对象的价值)它存储

2@%Stream.GlobalCharacter

当我尝试在我的 C# 程序中加载字符串内容时,我确实得到了上面的字符串,但我没有得到 JSON。通过缓存 Web 和终端界面查看 table 时,我也看到了上面的字符串。

我有另一个 JSON 字符串,它大约有 23,000 个字符长,可以毫无问题地保存和加载。

我知道 2@%Stream.GlobalCharacter 是一种存储数据的方式,但我希望能够轻松地 load/save 将其作为字符串。

更新

我正在尝试将数据保存在我的 C# ASP.Net 应用程序中,如下所示

sql = "INSERT INTO Namespace.Table ( Name, Active, Revision, Definition ) VALUES ( ?, 1, ?, ? )";

cC = new CacheCommand(sql, dbConn);
cC.Parameters.Add(new CacheParameter("name", formType)); // string
cC.Parameters.Add(new CacheParameter("revision", revision)); // int
cC.Parameters.Add(new CacheParameter("definition", formData)); // string

cC.ExecuteNonQuery();

我正在加载数据如下

string sql = "SELECT TOP 1 * FROM Namespace.Table WHERE Active = 1 AND Name = ? ORDER BY Revision DESC";
CacheCommand cC = new CacheCommand(sql, dbConn);
cC.Parameters.Add(new CacheParameter("name",formType));
CacheDataReader rdr = cC.ExecuteReader();
while(rdr.Read())
{
    string json = rdr["Definition"].ToString();
}

一直在与 Intersystems 交谈(感谢 Nicole),解决方案是将 属性 类型设置为 %Stream.GlobalCharacter 而不是 %String。

从 C# 的角度来看,它是无缝的,因为字符串会自动转换为它,您可以使用 .ToString() 方法再次获取字符串。

以下来自 Intersystems:

I've been looking into this a bit further and I have a theory about what is going on here. In certain versions of Caché I think that when inserting a string over a certain size (I believe 16k characters but I'm not exactly sure) into a Caché database via ODBC, it is automatically converted to a character stream. But since the property is defined as a %String on the server, the string literal "2@%Stream.GlobalCharacter" is stored in the database instead of the OREF pointing to the stream's contents. Then when you go to select the Definition value, it is just the string "2@%Stream.GlobalCharacter".