473,653 Members | 3,000 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How would you... (binary info in a table)


I have run into a challenge that I'm not sure how to best solve. I'd
appreciate any opinions or input.

I am working with a third party database. They are storing some data
that I need to use in a binary field. I've got the code to parse the
binary and reconstruct what I need. Unfortunately, there might be
multiple "entries" stored in a single binary field. a certain byte,
let's just say the first, will always be the count of "entries" in
this particular SQL entry.
An example:
then entry might be:
0x0100001234123 4
where 12341234 is the data entry that I will parse.
Another possible entry is:
0x0300001234123 4567856789ABC9A BC
The first byte indicates that there are three data values I want to
parse out:
12341234
56785678
9ABC9ABC
The portions of the binary I need are always the same length and there
may be from 1 to ~100 of them. (usually 1 if it matters.)

The big question:
How could a SQL query return an entry for each of the "entries" in the
binary field? For the second example I would want three entries in my
results, each row returning a different section of the binary data.
For the first, only one row. I'll be querying the set and expecting to
get back more results than the number of entries in the set.

I haven't really tried much with this yet, (other than some mental
calisthenics were I fell down onto the mat pretty hard), so just some
direction on where to begin would be helpful.
(Yes, I understand that the difficulty is that this data shouldn't be
stored this way, but there is not much I can do about that.)

Thanks...
James Fraser
jb**@concentric .net

Sep 11 '07 #1
4 1923
James Fraser (jb**@concentri c.net) writes:
But maybe I didn't think ahead far enough:
How can I run this SP or UDF on all of the rows in my original table.

I want the functionality of something like this:
SELECT * FROM my_fn ( inputtable.row1 binaryfield)
UNION
SELECT * FROM my_fn (inputtable.row 2binaryfield)
.
.
UNION
SELECT * FROM my_fn( inputtable.rowl astbinaryfield)

where the binary inputs are coming from the original table in the db.
I'm on SQL 2000, BTW. Right now, I have the feeling that a cursor is
the way out of this.
Yes, on SQL 2000 you are stuck with a cursor. SQL 2005 offers the APPLY
operator to address this.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Sep 15 '07 #2
On Sep 15, 2:35 am, Erland Sommarskog <esq...@sommars kog.sewrote:
...
Yes, on SQL 2000 you are stuck with a cursor. SQL 2005 offers the APPLY
operator to address this.

--
Erland Sommarskog, SQL Server MVP, esq...@sommarsk og.se
Thanks for the help and pointers!
James Fraser

Sep 16 '07 #3
James,

I don't think you need a cursor for this. If you create a
permanent table of integers (from 0 to the largest possible
number of items) or a table-valued function returning any
chosen range of integers, you can write this as a single
query. The example below should work, where
master..Nums(@f rom,@to) is a table-valued function returning
the table of integers between @from and @to.

create table Binaries (
b varbinary(max)
);
insert into Binaries values (0x010000123412 34);
insert into Binaries values (0x030000123412 34567856789ABC9 ABC);
go

declare @itemLen int; set @itemLen = 4;
declare @prefixLen int; set @prefixLen = 3;
select
substring(b,1+@ prefixLen+n*@it emLen,@itemLen) as Item
from Binaries
join master..Nums(0, 200) as Nums
on Nums.n < cast(substring( b,1,1) as tinyint)
go

-- drop table Binaries

Steve Kass
Drew University
www.stevekass.com
Erland Sommarskog wrote:
James Fraser (jb**@concentri c.net) writes:
>>But maybe I didn't think ahead far enough:
How can I run this SP or UDF on all of the rows in my original table.

I want the functionality of something like this:
SELECT * FROM my_fn ( inputtable.row1 binaryfield)
UNION
SELECT * FROM my_fn (inputtable.row 2binaryfield)
.
.
UNION
SELECT * FROM my_fn( inputtable.rowl astbinaryfield)

where the binary inputs are coming from the original table in the db.
I'm on SQL 2000, BTW. Right now, I have the feeling that a cursor is
the way out of this.


Yes, on SQL 2000 you are stuck with a cursor. SQL 2005 offers the APPLY
operator to address this.

Sep 16 '07 #4
On Sep 15, 11:20 pm, Steve Kass <sk...@drew.edu wrote:
James,

I don't think you need a cursor for this. If you create a
.. . . [ nice example using a number table deleted.]

I like what you're suggesting, but one detail that I thought would be
easy seems not to be. For each binary piece, my parsing function needs
to return three fields, of different datatypes.

When I first asked this question, I thought I could do something like
select * from my_parser_fn(se lect b from Binaries).

I could divide the parser into three copies, one for each field, but
they are inter-related, and I would like to keep that code in one
place.

This looks like another pointer towards a cursor. I can be proud
though, that in a year of part time SQL work, this will be my first
cursor. And I have a procedural language background, too. What will
happen once I fall off the wagon?

(Another complication that I discovered on some test runs and
inspections. Not all of the binary parts are really the same length. I
can get around this without much difficulty, I just need to parse some
headers a little more closely for each binary thing.)
Thanks again all for the help...
James Fraser
Sep 17 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1864
by: Ammar | last post by:
I don't want to extend the AD schema but need the hierarchical info on some groups (objectGuids that maintain the group). So I need to store the objectGuid of groups and accounts into the relational table in SQL. However, I don't know how to insert the objectGuid that are of type binary (!?) into the SQL table. Another question would be if I can cross-join the AD database with the
3
2848
by: tsunami | last post by:
hi all; I have an array and want to insert all the elements from this array to a binary search tree.That array is an object of the class of a stringtype which includes overloaded "< > = ==" functions and every other thing it needs. void InsertElementFromArray(StringType Array,int first element,int last element);
2
9300
by: bissatch | last post by:
Hi, I am trying to write script that is run when a form is submitted. The form contains an image input field and when submitted, the image is uploaded, resized and added as binary information to a db table. Please note, I am using a PostgreSQL database I have written all the code out below that deals with the submission processing:
20
3055
by: ishmael4 | last post by:
hello everyone! i have a problem with reading from binary file. i was googling and searching, but i just cant understand, why isnt this code working. i could use any help. here's the source code: --cut here-- typedef struct pkg_ { short int info; char* data;
3
7204
by: Randy | last post by:
I have heard that access 2003 has functions for dealing with Long Binary Data. Does anyone know if this is true? Background: I am using 2000 with a table linked to a SQL server. One of the fields is of type OLE Object. This table is populated from a website where excell spreadsheets are uploaded. But in the linked Access table instead of saying Excell spreadsheet in that field it says Long Binary Data, which can not be opened. My users on...
4
8702
by: hs | last post by:
Hi I am serializing a dataset using a binary formatter as follows: IFormatter formater = new BinaryFormatter(); formatter.Serialize(stream, ds); // ds=DataSet, stream=MemoryStream .... DataSet ds2 = (DataSet)formatter2.Deserialize(stream2); For the size of my DataSet, its taking 0.8 seconds to serialize and 2.3 seconds to deserialize.
10
2346
by: Fabuloussites | last post by:
I'm considering deploying an application that will us an IP address locaiton database provided by Ip2location.com... http://www.ip2location.net/ip2location-dotnet-component.aspx their .net component reads data from a binary file. I'm guess i'm wondering which of the two options would be best. 1) read data from the binary files (~27 mb or so) 2) or query a sql DB with the same info.
2
5558
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as I am trying to read from a binary archive using Boost serialization. I am new to this, and it is possible that I have not understood the usage. In the code below, the string "faultblock" seems to be causing the problem. The code crashes in the ia...
7
2904
by: eliben | last post by:
Hello, I'm interested in converting integers to a binary representation, string. I.e. a desired function would produce: dec2bin(13) ="1101" The other way is easily done in Python with the int() function. Perl has a very efficient way to do dec2bin, because its pack/unpack
0
8370
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8283
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8704
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8590
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5620
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4147
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.