Page 1 of 1

Database uniqueidentifier column

Posted: Thu Jan 12, 2017 5:39 pm
by Jamesnic7
Hi

New to the forum and Switch so forgive me if this is a stupid question.
I am trying to access from a script an SQL db column that is a type 'uniqueidentifier'.
The intention is to write it as privatedata for use later in the flow.
While SwitchScripter returns a value (although the text encoding looks wrong) Switch itself hangs and requires a restart.
Is there a way to deal with this data type within Switch or is it better to try a different approach?
Thanks for any advice

James

Re: Database uniqueidentifier column

Posted: Thu Jan 12, 2017 6:03 pm
by freddyp
Read the scripting documentation Scripting reference - Database module - Text encoding.

I have not tried but I would think that you will have to use getBinary for the uniqueidentifier type. As you can see in the documentation the return value of getBinary is a ByteArray object. You will have to convert that to a string in order to be able to add it to private data.

Re: Database uniqueidentifier column

Posted: Fri Jan 13, 2017 3:22 pm
by Jamesnic7
Hi

Thanks freddyp :D
Yes your spot on just did a check and this is BINARY.
I assume it should be possible to read and convert as suggested.
However I have a second table that uses the same field that I need to access.
Is it likely I will be able to use the (now String) Private data created to search or am I wasting my time because of the Data Type conversion?

Re: Database uniqueidentifier column

Posted: Fri Jan 13, 2017 5:06 pm
by freddyp
No, you are not wasting your time. You can create a ByteArray object from a string:

Code: Select all

var bin = new ByteArray(stringFromPrivateData);
You may have to experiment a bit with the text encoding, eg:

Code: Select all

var bin = new ByteArray(stringFromPrivateData,"UTF-8");
More on this in the documentation on ByteArray and text encoding.