dbTalk Databases Forums  

varbinary problem

comp.databases.sybase comp.databases.sybase


Discuss varbinary problem in the comp.databases.sybase forum.



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

Default varbinary problem - 04-06-2004 , 06:53 AM






Version: Sybase 12.5.1
I have a table with a varbinary(255) field.

When i try to insert this varbinary "0x0400010000" in my table, i can see
thet last two bytes are inesistent.

select my_field from my tables
go


I have this output:
0x040001

Why???How can i solve this problem???
Thanks in Advance.








Reply With Quote
  #2  
Old   
Carl Kayser
 
Posts: n/a

Default Re: varbinary problem - 04-06-2004 , 08:16 AM







select bintostr (my_field) from ... may solve your problem. I'm not sure
as to when this function became available.


"FCA" <marakaimbo (AT) libero (DOT) it> wrote

Quote:
Version: Sybase 12.5.1
I have a table with a varbinary(255) field.

When i try to insert this varbinary "0x0400010000" in my table, i can see
thet last two bytes are inesistent.

select my_field from my tables
go


I have this output:
0x040001

Why???How can i solve this problem???
Thanks in Advance.










Reply With Quote
  #3  
Old   
FCA
 
Posts: n/a

Default Re: varbinary problem - 04-06-2004 , 09:53 AM



Tahnk yuo "Carl Kayser"

But this is not my problem.
My problem is that, when I try to insert a virbinary that have last byte to
00 i have this situation:

insert into my_table select 0x0400010000
go

select * from my_table
go

my_field
---------
0x040001

where is 0000?



"Carl Kayser" <kayser_c (AT) bls (DOT) gov> wrote

Quote:
select bintostr (my_field) from ... may solve your problem. I'm not sure
as to when this function became available.


"FCA" <marakaimbo (AT) libero (DOT) it> wrote in message
news:c4u5jc$2l1cr2$1 (AT) ID-110320 (DOT) news.uni-berlin.de...
Version: Sybase 12.5.1
I have a table with a varbinary(255) field.

When i try to insert this varbinary "0x0400010000" in my table, i can
see
thet last two bytes are inesistent.

select my_field from my tables
go


I have this output:
0x040001

Why???How can i solve this problem???
Thanks in Advance.












Reply With Quote
  #4  
Old   
Michael Peppler
 
Posts: n/a

Default Re: varbinary problem - 04-06-2004 , 10:06 AM



On Tue, 06 Apr 2004 16:53:30 +0200, FCA wrote:

Quote:
Tahnk yuo "Carl Kayser"

But this is not my problem.
My problem is that, when I try to insert a virbinary that have last byte
to 00 i have this situation:

insert into my_table select 0x0400010000 go

select * from my_table
go

my_field
---------
0x040001

where is 0000?
It got truncated.

That "bug" has been around in Sybase since 4.0 - I remember hitting it
when storing a string of bytes as a varbinary and losing any trailing NULL
bytes. I worked around it by putting an end marker (I think I used 0x7f)
as the last byte of the string, and have my front end clean it up as
needed.

Personally I think this is a bug - a varbinary should store what you give
it, trailing null bytes included. You may want to open a case with Sybase
Tech Support.

Michael
--
Michael Peppler Data Migrations, Inc.
mpeppler (AT) peppler (DOT) org http://www.peppler.org/
Sybase T-SQL/OpenClient/OpenServer/C/Perl developer available for short or
long term contract positions - http://www.peppler.org/resume.html



Reply With Quote
  #5  
Old   
Rob Verschoor
 
Posts: n/a

Default Re: varbinary problem - 04-06-2004 , 10:11 AM




Since this is varbinary, the trailing eroes are suppressed by default --
they haven't not disappeared but they're just not displayed. In other words,
it's a formatting issue. Try doing a convert to binary(255) and you'll see
what I mean...

HTH,

Rob
-------------------------------------------------------------
Rob Verschoor

Certified Sybase Professional DBA for ASE 12.5/12.0/11.5/11.0
and Replication Server 12.5

Author of "Tips, Tricks & Recipes for Sybase ASE" and
"The Complete Sybase ASE Quick Reference Guide"
Online orders accepted at http://www.sypron.nl/shop

mailto:rob (AT) YOUR (DOT) SPAM.sypron.nl.NOT.FOR.ME
http://www.sypron.nl
Sypron B.V., P.O.Box 10695, 2501HR Den Haag, The Netherlands
-------------------------------------------------------------

"FCA" <marakaimbo (AT) libero (DOT) it> wrote

Quote:
Tahnk yuo "Carl Kayser"

But this is not my problem.
My problem is that, when I try to insert a virbinary that have last byte
to
00 i have this situation:

insert into my_table select 0x0400010000
go

select * from my_table
go

my_field
---------
0x040001

where is 0000?



"Carl Kayser" <kayser_c (AT) bls (DOT) gov> wrote in message
news:c4uajp$ats$1 (AT) blsnews (DOT) bls.gov...

select bintostr (my_field) from ... may solve your problem. I'm not
sure
as to when this function became available.


"FCA" <marakaimbo (AT) libero (DOT) it> wrote in message
news:c4u5jc$2l1cr2$1 (AT) ID-110320 (DOT) news.uni-berlin.de...
Version: Sybase 12.5.1
I have a table with a varbinary(255) field.

When i try to insert this varbinary "0x0400010000" in my table, i can
see
thet last two bytes are inesistent.

select my_field from my tables
go


I have this output:
0x040001

Why???How can i solve this problem???
Thanks in Advance.

















Reply With Quote
  #6  
Old   
Larry Coon
 
Posts: n/a

Default Re: varbinary problem - 04-06-2004 , 10:35 AM



FCA wrote:

Quote:
But this is not my problem.
My problem is that, when I try to insert a virbinary that have last byte to
00 i have this situation:
Can you use binary in place of varbinary?


Reply With Quote
  #7  
Old   
Bret Halford
 
Posts: n/a

Default Re: varbinary problem - 04-06-2004 , 04:58 PM



"FCA" <marakaimbo (AT) libero (DOT) it> wrote

Quote:
Version: Sybase 12.5.1
I have a table with a varbinary(255) field.

When i try to insert this varbinary "0x0400010000" in my table, i can see
thet last two bytes are inesistent.

select my_field from my tables
go


I have this output:
0x040001

Why???How can i solve this problem???
Thanks in Advance.

Why? Because that is the documented behavior. Please read the
ASE Reference Manual, Vol 1 on "Binary" datatypes.

"Treatment of trailing zeroes

All binary not null columns are padded with zeros to the full width of the column.
Trailing zeros are truncated in all varbinary data and in binary null columns, since
columns that accept null values must be treated as variable-length columns."

You can either assume that a bytes following this value are 0x00 or,
if the exact number of 0x00 bytes is important to you, append some non-zero
byte to the end of every binary value you store, i.e. instead of storing
"0x0400010000", store "0x0400010000ff" and have your application always strip
off the last byte.

-bret


Reply With Quote
  #8  
Old   
Bret Halford
 
Posts: n/a

Default Re: varbinary problem - 04-07-2004 , 10:36 AM



Michael Peppler <mpeppler (AT) peppler (DOT) org> wrote

Quote:
On Tue, 06 Apr 2004 16:53:30 +0200, FCA wrote:

Tahnk yuo "Carl Kayser"

But this is not my problem.
My problem is that, when I try to insert a virbinary that have last byte
to 00 i have this situation:

insert into my_table select 0x0400010000 go

select * from my_table
go

my_field
---------
0x040001

where is 0000?

It got truncated.

That "bug" has been around in Sybase since 4.0 - I remember hitting it
when storing a string of bytes as a varbinary and losing any trailing NULL
bytes. I worked around it by putting an end marker (I think I used 0x7f)
as the last byte of the string, and have my front end clean it up as
needed.

Personally I think this is a bug - a varbinary should store what you give
it, trailing null bytes included. You may want to open a case with Sybase
Tech Support.

Michael
If you do, indicate that you are expressing an interest in seeing
feature request CR 290256 implemented. This request is for char and
binary
datatypes that neither strip trailing spaces and nulls nor pad the
value with spaces and nulls.

-bret


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.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.