473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Interesting Problem

Imagine a table in Microsoft Sql Server 2000 named Pictures with three
fields. A primary key ID(int), a Name(nvarchar) and a Picture(image)
field.

Lets put some records into the table. The first two fields as expected
would take an int and a string. The third field is of type image.
Instead of putting a bitmap in this field lets place an xml document
that has been streamed into a byte array. The xml document would
describe the Picture using say lines. If the picture was that of a
square we would have four lines in the xml document. You could think of
the xml document as something similar to vector graphics but the
details are not relevant. The important fact is that the contents of
the image field is NOT a bitmap but a binary stream of an xml document.

Now imagine we have a reporting tool like Crystal Reports that can be
used to report on this database table. Imagine we create a report by
using the three fields mentioned above. As far as Crystal is concerned
the first field is an int, the second a string and the third an image.
If our table had ten records and we preview the report we like to see
10 entries each consisting of an ID, Name and a Picture.

This can only happen if the image field contains a Bitmap, but as
mentioned above the field contains an xml document.

Now my question...

Can we write something in SQL Server 2000 (not 2005) to sit between the
table and Crystal Reports so to convert the XML document to a bitmap.
The restriction is that we cannot use anything but sql server itself.
The client in the above case has been Crystal Reports but it could be
anything.

I know SQL Server 2005 supports C# with access to the .NET framework
within the database. Unfortunately, I am not using SQL server 2005.

Some people have suggested the use of User Defined Functions and TSQL.
I like to know from the more experienced SQL Server people if what I am
trying to achieve is possible. Maybe it has not been done but is it
possible?

Any suggestions would be greatly appreciated...

Many Regards

Jul 23 '05 #1
5 1539
Translating an XML byte stream to a bitmap dynamically sounds like
something which is probably beyond pure TSQL. Even if it is possible
somehow, I suspect that the code would be complex and slow - TSQL isn't
really a general purpose language, and its support for manipulating
binary data is limited.

Having said that, there are a couple of ways you might be able to
approach this - extended stored procedures, and COM support. An
extended proc is an external DLL which can be called from TSQL, rather
like a more basic version of the .NET support in 2005. Alternatively,
you can use the sp_OA% procs to instantiate COM objects, so if your
logic can be written as a COM object, then you can use it from TSQL.
Check Books Online for more details on both these options.

Although I don't have much experience with extended procs, the COM
support is probably not a good solution, because of security and
performance issues. The best approach is almost certainly to do this in
client code, rather than the database - perhaps you can look at
embedding something in Crystal, instead of in the database?

Simon

Jul 23 '05 #2
Perhaps it would be possible to write an extended stored proc and call
that from a function. That of course assumes that Crystal Reports
provides some method of rendering a bitmap returned from a query.

I can't think of a good reason to do this in SQL Server. It's obviously
better suited for the client or middle-tier.

--
David Portas
SQL Server MVP
--

Jul 23 '05 #3
Hi Simon

Thanks for your suggestions. I think I like the Extented Stored
Procedure(xp) route more and I can certainly create a dll in C++ to
convert an XML document containing the description of the square to a
bitmap of the square (say 100x100 pixels by default). Once I add this
xp to sql server I need to attach it to my xml field in some way so
that when Crystal requests the content of the image field in the
Pictures table instead of it returning the binary array representing
the xml document it returns the on-the-fly generated bitmap.

Is there a way I could intervene in what sql sends to crystal in
respect to the Picture field using the xp? Do I need to use triggers?
Basically I am trying to fool crystal that the Picture field contains a
Bitmap. This needs to happen when the Crystal does a select I
suppose...

Probably its worth mentioning why I am trying to do this at all....

We have a drawing package that allows users to draw shapes. We can
store these as an XML document and restore them. Whats more we have a
control that can render these documents directly. Thus in order to
preview the XML document all that is needed is the control which is
self contained. The control also scales the preview of the shape.

We therefore can store the XML for this document in the database and
not worry about also storing a preview bitmap of the shape in the same
row. This means there is less danger of the preview bitmap field going
out of syn with the xml document and also avoids data redundancy. Whats
more preview bitmaps are fixed in size and dont scale well. This
approach solves all these problems.
However, as databases are often reported on and that Crystal Reports is
a leading reporting tool I like our database to work well with Crystal
when wanting to create reports that need the picture field (that
contains the xml document).

This is exactly why I need to the conversion at SQL as our customers
could do reporting directly from the database using Crystal Reports.
Embedding within Crystal is also not an option as the reporting tool
could change.

Many Thanks in Advance

Jul 23 '05 #4
Thanks Dave

Please look at my reply to Simon for reasons why I am trying to do
this...
Problem now is how to fool Crystal to get the Bitmap from the xp as
oppose the xml from the field...

Any comments would be appreciated...

Regards..

Jul 23 '05 #5
> Is there a way I could intervene in what sql sends to crystal in
respect to the Picture field using the xp? Do I need to use triggers?


You could call your XP from a user-defined function and return the
result as a binary column. Put the UDF in a view and query the view
from Crystal. There are no triggers on SELECT so this is the only
method I can think of.

--
David Portas
SQL Server MVP
--

Jul 23 '05 #6

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

Similar topics

56
by: Dave Vandervies | last post by:
I just fixed a bug that some of the correctness pedants around here may find useful as ammunition. The problem was that some code would, very occasionally, die with a segmentation violation...
23
by: Bruno R. Dias | last post by:
Perhaps it would be interesting to program a virtual machine simulating an ancient computer (such as the pdp-7). Then, it would be rather interesting to code for it (porting gcc to it maybe?). I...
7
by: David Sworder | last post by:
Hi, I'm developing an application that will support several thousand simultaneous connections on the server-side. I'm trying to maximize throughput. The client (WinForms) and server communicate...
1
by: Rakesh Roberts | last post by:
I think I have a very interesting cookie problem. I use form authentications on my application. Through out my application I started using a toggle control that persists its value for the session...
2
by: sasifiqbal | last post by:
Hi, One of my developers are facing an interesting problem regarding UserControl invalidation. The problem is: We have two forms in our application. Form A does nothing except loading of...
27
by: Frederick Gotham | last post by:
I thought it might be interesting to share experiences of tracking down a subtle or mysterious bug. I myself haven't much experience with tracking down bugs, but there's one in particular which...
6
by: per9000 | last post by:
An interesting/annoying problem. I created a small example to provoke an exception I keep getting. Basically I have a C-struct (Container) with a function-pointer in it. I perform repeated calls...
5
by: Will Honea | last post by:
I've hit an interesting trap trying to migrate data off an OS/2 server running version 7.2 (fp14) over to 8.2 on Linux. Seems that one table has a column defined in the DDL as "BIGINT NOT NULL...
11
by: onkar.n.mahajan | last post by:
Is it possible to from function call on fly in C programming language ? I am faced with an interesting problem in that I need to take function name and arguments on fly (actually from Database...
4
by: Andrew | last post by:
I am having an interesting namespace conflict. When we use a third party lib we create a company assembly for any descending classes to go in. I have simplified the problem into the example...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.