Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

GUIDs returned as gibberish (ODBC/MS SQL)

by LaidBackWebSage (Acolyte)
on Oct 27, 2008 at 00:53 UTC ( #719681=perlquestion: print w/ replies, xml ) Need Help??
LaidBackWebSage has asked for the wisdom of the Perl Monks concerning the following question:

All, I am using Perl 5.8.8 on Ubuntu Server 8.04, with DBD::ODBC, and FreeTDS. The database is on a WinNT server, running MS SQL Server 2000. Here is my pseudo-query:
SELECT row_guid FROM table

What should come back is this:
DAD26152-1C43-11DD-BD0B-0800200C9A66

What does come back is this:
RaC 

Is perl somehow reading this as hex or something?

Do I need to (un)pack somehow?

Any help will be greatly appreciated.

Thanks!

Kevin J

Comment on GUIDs returned as gibberish (ODBC/MS SQL)
Select or Download Code
Re: GUIDs returned as gibberish (ODBC/MS SQL)
by graff (Chancellor) on Oct 27, 2008 at 01:36 UTC
    Here is my pseudo-query:
    SELECT row_guid FROM table
    

    What should come back is this:

    DAD26152-1C43-11DD-BD0B-0800200C9A66
    

    Have you sent the actual SQL query (as implemented in your script) using some other DB client, and made sure that it returns the string that you say you should be getting?

    Have you looked at the table definition to determine what sort of data field you are querying for? (Does the DB server happen to provide some "special" data type, is the field encrypted, might there be some DB-side function call that should be used in the query string to fetch the value correctly, etc?)

    I don't think we can say anything useful based on the information originally posted (unless someone else has actually seen something very similar...)

Re: GUIDs returned as gibberish (ODBC/MS SQL)
by CountZero (Bishop) on Oct 27, 2008 at 06:02 UTC
    It looks like an encoding issue.

    Something in the chain (database data, database server, client, DBD::ODBC, your program) thinks the data is in some multi-byte format 'Unidcode, UTF-16, ...) and rendering it as such.

    What happens if you read another field?

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: GUIDs returned as gibberish (ODBC/MS SQL)
by mje (Deacon) on Oct 27, 2008 at 09:19 UTC

    If you don't get anywhere resolving this and can put together a small example of your schema, an example row and an example of your perl I'll take a look at it.

Re: GUIDs returned as gibberish (ODBC/MS SQL)
by Krambambuli (Deacon) on Oct 27, 2008 at 09:31 UTC
    Are you sure the data put into the DB is OK...?

    The first 8 characters in your expected result string are

    DA D2 61 52

    which - read in reverse order - looks pretty much as some hex encoded values (0x52 = 'R', 0x61 = 'a', ... ) that would fit what you see, but then your expected '-' doesn't fit into the picture, so I'm unsure about what's what where.

    Krambambuli
    ---
Re: GUIDs returned as gibberish (ODBC/MS SQL)
by pKai (Priest) on Oct 27, 2008 at 11:15 UTC

    A GUID is at core a 128 bit number.

    The Wikipedia link above has all the information you need to convert between the binary and the text representation.

    A cpan search gives Data:GUID. But on first glance there is no method for a direct binary -> text conversion.

      print Data::GUID->best_guess($your_guid)->as_string
      should work...
      []s, HTH, Massa (κς,πμ,πλ)

        The "Data::GUID" module is what I needed.

        Many thanks!

        Kevin J

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://719681]
Approved by CardinalNumber
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (20)
As of 2014-09-22 14:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (196 votes), past polls