How to store integer-array in SQL-Database in a BLOB ( Binary large object )

  • Thread starter Thread starter Peter Stojkovic
  • Start date Start date
P

Peter Stojkovic

I want store an integer-array of 1000 Values in a blob in a SQL-database.

I will do this every 10 Seconds.

How can I do this ????

What datatypes a have to use ???


Thanks
for any help
Peter
 
The best way is to use an image type in your database (gives you 2gb of
datastorage).

After that.. use a BinaryFormatter to serialize the array to binary
saveable format...

Insert into blob...

why you wnat to use a blob confuses me, but to each his own...
 
CJ,
If its always an Integer array. I would consider using System.Buffer to
block copy the integer array to & from an array of Bytes.

Of course the BinaryFormatter is more flexible.

Hope this helps
Jay
 
Hey Jay,

Didn't know about that one. I was just going with the fastest/least
confusing way I could think of doing it with. =)

I have no idea why they want to do it, but I'm *assuming* (beware!) its
because he wants to maintain persistance in some way..

then again, I could be wrong.

-CJ
 
CJ,
I'm not sure what Peter's intent is either, I'm sure (hope at least) they
thought of the ramifications of storing arrays of integers in database
fields... I would have probably normalized the data into a child table...

Jay
 
Hi Jay,

I was so sure that you would give the answer on

Dim aByte() as Byte
aByte = myIntegerArray.EncodedByJay

That I did not, because it is something I always have to search for and have
the idea that you know it direct.

The rest would be peanuts (Can work fine in my opinion).

(When you have no direct answer than tell it, it is not that I am to lazy
for it)


Cor
 
As I understood, you would prefere a Image-type ,

I dont know what is a "image" type

I am using SQL-AnyWhere From SYBASE 9.01

There is no image-type available for a column

Peter
 
Peter,
An "image" type is a blob. For what ever SQl-AnyWhere's "blob" type is, you
can use the technique identified by CJ or I.

Hope this helps
Jay
 
Further note...

Image type is a 16 byte pointer to a 2 gig max data segment in the database.
The varBinary field only allows a max of 8000 bytes I believe.

which sucks except for passwords.

=)
 
Cor,
Why would I give a "bogus" answer? :-) Or is myIntegerArray a class that has
a EncodedByJay method on it?

The OP wants to put an integer array into a database, the two "better"
methods of doing this is binary serialization or System.Buffer.BlockCopy.
The third "better" method would be XML serialization. IMHO any other method
would be "more" work, hence not as "better", however these other methods may
be more what the OP needs, for example, the OP could use a loop & a string
builder to convert the array into a comma separated string, then store the
string in the database. To get the array out, he could use String.Split &
Integer.Parse in a loop...

I don't really see where Encoding would apply in this question per se. As
encoding usually entails changing from one format to another, such as
Unicode to ASCII. I don't really see that the OP wants to change the format
of the integers such as from Unicode to ASCII... (unless you meant integer
array to String & back, then I'm following you).

If you had an idea of how the OP could "encode" the integer array to be
stored, by all means give it.

Hope this helps
Jay
 
Hi Jay,
Why would I give a "bogus" answer? :-) Or is myIntegerArray a class that has
a EncodedByJay method on it?

I was a fool, I do not know why however in this thread I was thinking that
an integer was a byte, I hope that you understand that I know that it is
not.

Than because of your challenge I tried doing it. However I give up, the
result would have all in it I hate, unreadable trash made because it was a
challenge.

I could of course have serialized the integer array and than made from that
a blob, however that was something that was not my intention. I would have
made a bytearray of couples of 4 bytes.

:-)

Cor
 
Back
Top