0
votes

I am trying to save (and load) a reasonably long string to a Cache Class String(MAXLEN=1024000) Property.

The string is around 32,000 characters long and instead of storing the string contents (which is a JSON object for what it's worth) it stores

2@%Stream.GlobalCharacter

How data is saved

When I try to load the string content in my C# program I literally get the string above, I do not get the JSON. When viewing the table via the Cache web and terminal interfaces I see the above string as well.

I have another JSON string which is around 23,000 characters long and that saves and loads without issue.

I understand that 2@%Stream.GlobalCharacter is a way of storing data, but I would like to easily be able to load/save it as a string.

Update

I am attempting to save the data in my C# ASP.Net App as follows

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();

I am loading the data as follows

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();
}
1
It's a bit difficult to help, while I'm not sure how you save and load data, is it only .Net code, or COS too. Need some examples of code from both sides if possible. - DAiMor
Sorry, have updated question with C# code - CT14.IT
I'm not so familiar with .Net, but as I see you use ToString(), in this case you of course will get just class of this object. I think you should get this object before conversion to String. - DAiMor
That's a good idea, but I get the same via the Cache web interface too, so I believe it's being set on input, not output. (see the screenshot in the question) - CT14.IT
Not matter what you see at SMP, it is very pure SQL Explorer. And in fact it is really shows that this column contains an object. - DAiMor

1 Answers

0
votes

Have been speaking with Intersystems (thanks Nicole) and the solution is to set the property type to %Stream.GlobalCharacter instead of %String.

It's seamless from a C# perspective as a string is automatically converted to it and you can use the .ToString() method to get the string out again.

Below from 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".