Read Blob object from DB and convert to System.Collection.Generic.List type of object.
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Read Blob object from DB and convert to System.Collection.Generic.List type of object.
I have scenario where database field stores a System.Collection.Generic.List of Double object. Now I want to read a BLOB object from database field and convert it to list of Array or any type collection in Test Complete. I have written following routine and getting null value when reading a field from record set. Can any body help how to read blob object?
function TestBlob() { var serverName = "ServerName"; var dbName = "databaseName"; Conn = new ActiveXObject("ADODB.Connection"); Conn.ConnectionString = "Driver={SQL Server};Server=" + serverName + ";Database=" + dbName + ";Trusted_Connection=True;"; Conn.Open(); var adoCmd = new ActiveXObject("ADODB.Command"); adoCmd.ActiveConnection = Conn; adoCmd.CommandType = adCmdText; adoCmd.CommandText = "Select * from scan"; var rs = adoCmd.Execute(); //Table Field "slices" is type of varbinary // and holds the Blob object of System.Collections.Generic.List of Doubles. rs.MoveFirst(); var blob = rs.Fields("slices").Value; // Always returns null. //How can I get coverted Blob object to List of Array, I have tried to test following statement. //I have doubt that it will not work. var objList = Aliases.appName.AppDomain("appUI.exe").dotNET.System_Collections_Generic.List_1.zctor_3(blob); }
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Rather than "Value", you might want to use the GetChunk method. What you'll need to do is get the ActualSize of the field and then use GetChunk to retrieve it. I've not tested this but it might look something like this:
rs.MoveFirst(); var blobSize = rs.Fields("slices").ActualSize; var blob = rs.Fields("slices").GetChunk(blobSize);
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sample code example for Robert's reply:
/Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Now I have gotten Blob object.
Second Issue is to Cast the Blob object in some list/dictionary type object of JavaScript for traversing. As I told you we have stored blob object type of System.Collection.Generic.List of Double.
I have found the following description of System.Collection.Generic.List that takes the "<CLRType> collection" object. I don't know how to define <CLRType> collection object.
Description: System.Collection.Generic.List`1 zctor_3(<CLRType> collection);
So far code looks like and I get type Mismatch error.
rs.MoveFirst(); var blobSize = rs.Fields("slices").ActualSize; var blob = rs.Fields("slices").GetChunk(blobSize); var objList = Aliases.appName.AppDomain("appUI.exe").dotNET.System_Collections_Generic.List_1.zctor_3(blob); // Gives "Type Mismatch Error"
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
if your Blob is an image, it's not a collection. A collection is an object that has fields and properties and items. At least, that's my understanding.
I don't know the specific collection object you are trying to use so I can't help you further.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No Blob is not an image, it's an serialized object of System.Collections.Generic.List.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am not absolutely sure, but I think that you should:
-- Register relevant (system.dll?) .Net assembly in dotNet Bridge in TestComplete and
-- Use something like
var objList = dotNET.Syst
in your code.
As a result, objList variable should contain deserialized list of doubles that cannot be used 'as is' in your test code and must be converted to array or delimited string or something like that that can be iterated and used in JScript.
/Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you ask the developers what code they are using to serialize the list into the DB? This should give you the best idea of how to do the opposite.
Maybe you need to use BinaryFormatter.Deserialize as shown here:
http://stackoverflow.com/questions/2949666/deserialize-stream-to-listt-or-any-other-type
http://stackoverflow.com/questions/26383711/serialize-deserialize-a-list-of-objects-using-binaryform...
http://stackoverflow.com/questions/18876229/serializing-and-deserializing-a-listlistobject-with-bina...
http://stackoverflow.com/questions/33724860/deserialize-list-of-objects-from-a-file-to-be-displayed
Maybe you need to read the DB using .NET classes and not ADO, so that the blob data type is compatible with .NET.
I'd suggest writing the deserialization code in C#/VB.NET in Visual Studio first. Once you have the code that works, you can port it to TestComplete, or you can compile the .NET code into an assembly/class library and call it from TestComplete via dotNET.
Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
System.Collection.Generic.List included in mscorlib.dll and it is already available in Test Complete.
I think I have to deserialize the object but not sure how to do it.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
As it was suggested by @HKosova, you should figure-out what is returned from Blob - this may be some string/base64 encoded string/xml/etc. Then you should find corresponding List constructor and use it to deserialize the returning value.
However, as it was also suggested by Helen, it may be easier/more convenient to create a simple .Net assembly with one function that will receive Blob ID and database connection string as input parameters, get Blob from the database, deserialize it and return the list as, say, CrLf-delimited string. I believe that you can easily get the above code from your developers.
/Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
