HighDots Forums  

output values being converted?

Ruby On Rails Talk Ruby On Rails programming language mailing list


Discuss output values being converted? in the Ruby On Rails Talk forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Matt Harrison
 
Posts: n/a

Default output values being converted? - 11-06-2009 , 07:06 PM






Hi all,

I've got a c++ program that inserts data into a mysql database, its a
32 length varchar column in question that contains sha256 hashes such as

018cf0b47256973ab6f08a720208c28c34d85722

Unfortunately, when I come to read this in rails and print out the hash in a
view, it prints out a short integer like 847.

I've tried it in irb, I can see the hash correctly as the return value of a
..find, but it still comes out wrong when I print it directly:

=> @hash = FileHash.find(:first)
Quote:
#<FileHash id: 423, hash: "018cf0b47256973ab6f08a720208c28c34d85722", size: 1393
=> @hash.size
1393
=> @hash.hash
847
I can't think what would be causing this, I've never come across anything
quite like this before. I'm not using any unusual encodings or anything, at
least, I'm using the same a I always have without problems.

Hope someone can shed light on this.

Thanks

Matt

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #2  
Old   
Matt Harrison
 
Posts: n/a

Default Re: output values being converted? - 11-06-2009 , 07:21 PM






On Sat, Nov 07, 2009 at 12:06:07AM +0000, Matt Harrison wrote:
Quote:
Hi all,

I've got a c++ program that inserts data into a mysql database, its a
32 length varchar column in question that contains sha256 hashes such as

018cf0b47256973ab6f08a720208c28c34d85722

Unfortunately, when I come to read this in rails and print out the hash in a
view, it prints out a short integer like 847.

I've tried it in irb, I can see the hash correctly as the return value of a
.find, but it still comes out wrong when I print it directly:

=> @hash = FileHash.find(:first)
#<FileHash id: 423, hash: "018cf0b47256973ab6f08a720208c28c34d85722", size: 1393
=> @hash.size
1393
=> @hash.hash
847

I can't think what would be causing this, I've never come across anything
quite like this before. I'm not using any unusual encodings or anything, at
least, I'm using the same a I always have without problems.

Hope someone can shed light on this.

Thanks

Matt
Well to answer my own question yet again:

It turns out that hash is a method defined by activerecord already. I
originally had problems naming my model Hash so I changed it to FileHash. I
didn't realise that hash was a method as well as a class.

Changing the column name in the db, rails and the c++ app has fixed the
problem

Matt

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #3  
Old   
Rob Biedenharn
 
Posts: n/a

Default Re: output values being converted? - 11-06-2009 , 09:51 PM



On Nov 6, 2009, at 7:21 PM, Matt Harrison wrote:
Quote:
On Sat, Nov 07, 2009 at 12:06:07AM +0000, Matt Harrison wrote:

Hi all,

I've got a c++ program that inserts data into a mysql database, its a
32 length varchar column in question that contains sha256 hashes
such as

018cf0b47256973ab6f08a720208c28c34d85722

Unfortunately, when I come to read this in rails and print out the
hash in a
view, it prints out a short integer like 847.

I've tried it in irb, I can see the hash correctly as the return
value of a
.find, but it still comes out wrong when I print it directly:

=> @hash = FileHash.find(:first)
#<FileHash id: 423, hash:
"018cf0b47256973ab6f08a720208c28c34d85722", size: 1393
=> @hash.size
1393
=> @hash.hash
847

I can't think what would be causing this, I've never come across
anything
quite like this before. I'm not using any unusual encodings or
anything, at
least, I'm using the same a I always have without problems.

Hope someone can shed light on this.

Thanks

Matt

Well to answer my own question yet again:

It turns out that hash is a method defined by activerecord already. I
originally had problems naming my model Hash so I changed it to
FileHash. I
didn't realise that hash was a method as well as a class.

Changing the column name in the db, rails and the c++ app has fixed
the
problem

Matt

You could have also accessed the original column as:

@hash['hash']

which forces the name 'hash' to be treated as an attribute name of the
model.

FYI, you also run into the same kind of problem with other names that
conflict with exiting methods.

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob (AT) AgileConsultingLLC (DOT) com




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #4  
Old   
Frederick Cheung
 
Posts: n/a

Default Re: output values being converted? - 11-07-2009 , 05:16 AM



On Nov 7, 12:21*am, Matt Harrison <iwasinnamuk... (AT) genestate (DOT) com>
wrote:
Quote:
On Sat, Nov 07, 2009 at 12:06:07AM +0000, Matt Harrison wrote:

It turns out that hash is a method defined by activerecord already. I
originally had problems naming my model Hash so I changed it to FileHash. I
didn't realise that hash was a method as well as a class.

Changing the column name in the db, rails and the c++ app has fixed the
problem
All objects in ruby have a hash method for which the following
statement should hold

a.hash != b.hash => a!=b

Among other things it is used when you use something as a key in a
Hash.

Fred
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.