473,503 Members | 3,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Working with bytes.

I have been unable to solve a problem. I am working with MD5 signatures
trying to put these in a database. The MD5 signatures are not generated
using the python md5 module but an external application that is
producing the valid 16 byte signature formats. Anyway, these 16 byte
signatures are not nescarrally valid strings. How do I manipulate the
bytes? I need to concatenate the bytes with a SQL statement which is a
string. This works fine for most of the md5 signatures but some blow up
with a TypeError. Because there is a NULL byte or something else. So I
guess my ultimate question is how do I get a prepared SQL statement to
accept a series of bytes? How do I convert the bytes to a valid string
like:

'x%L9d\340\316\262\363\037\311\345<\262\357\215'

that can be concatenated?

Thanks

Jul 18 '05 #1
2 2284
Adam T. Gautier wrote:
I have been unable to solve a problem. I am working with MD5 signatures
trying to put these in a database. The MD5 signatures are not generated
using the python md5 module but an external application that is
producing the valid 16 byte signature formats. Anyway, these 16 byte
signatures are not nescarrally valid strings. How do I manipulate the
bytes? I need to concatenate the bytes with a SQL statement which is a
string. This works fine for most of the md5 signatures but some blow up
with a TypeError. Because there is a NULL byte or something else. So I
guess my ultimate question is how do I get a prepared SQL statement to
accept a series of bytes? How do I convert the bytes to a valid string
like:

'x%L9d\340\316\262\363\037\311\345<\262\357\215'

that can be concatenated?

Thanks

This should probably do:
cursor.execute('SELECT author from stored where md5 = ?', md5)

But you might consider changing your approach to store hex strings:
cursor.execute('SELECT author from stored where md5 = ?',
''.join(['%02x' % byte for byte in md5]))
--
-Scott David Daniels
Sc***********@Acm.Org
Jul 18 '05 #2
>>>>> "Adam T. Gautier" <ad**********@yahoo.com> (ATG) wrote:

ATG> I have been unable to solve a problem. I am working with MD5 signatures
ATG> trying to put these in a database. The MD5 signatures are not generated
ATG> using the python md5 module but an external application that is producing
ATG> the valid 16 byte signature formats. Anyway, these 16 byte signatures are
ATG> not nescarrally valid strings. How do I manipulate the bytes? I need to
ATG> concatenate the bytes with a SQL statement which is a string. This works
ATG> fine for most of the md5 signatures but some blow up with a TypeError.
ATG> Because there is a NULL byte or something else. So I guess my ultimate
ATG> question is how do I get a prepared SQL statement to accept a series of
ATG> bytes? How do I convert the bytes to a valid string like:

ATG> 'x%L9d\340\316\262\363\037\311\345<\262\357\215'

ATG> that can be concatenated?

Depends what the database accepts. If it supports BLOBs you could use
that. Otherwise convert them to hex, or base64.
See for example the the codecs module or the binascii module.

--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.***********@hccnet.nl
Jul 18 '05 #3

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

Similar topics

1
6029
by: Larry Menard | last post by:
Folks, I've written the world's simplest java UDF, and it is complaining that it can't load the method. The class seems OK, it's complaining about the method. The JDBC Sample UDFs (e.g.,...
7
14569
by: Alex | last post by:
Hello people, I have a code written in JAVA that creates field of bytes: byte uuid = new byte; Now I have to translate this line into C++. I'm working in VS 6.0. (unfortunately I have to)....
8
5032
by: den 2005 | last post by:
Hi everybody, I am not sure where to put this in this forum. So, I posted this at several topics. I created a class library that has two public methods Encrypt() and Decrypt(). I reference this...
4
3242
by: SpreadTooThin | last post by:
client: import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("192.168.1.101", 8080)) print 'Connected' s.send('ABCD') buffer = s.recv(4) print buffer s.send('exit')
6
3392
by: RaulAbHK | last post by:
Dear all, I guess this is a basic question with an easy answer but I am a beginner and I would much apreciate your feedbacks. Let's say I have a library with some functionality to perform some...
0
1298
by: George2 | last post by:
Hello everyone, I am using perfmon to watch the working set and virtual bytes, when I do a keyword search in SourceInsight. I found the value of working set is larger than virtual bytes when...
0
1573
by: George2 | last post by:
Hello everyone, From the definition of working set, it is a subset of virtual pages resident in physical memory -- from book Windows Internals. It means working set could not be larger than...
3
2572
by: PrabodhanP | last post by:
I have CSS based mouseover scrolling for divContent embeded in my webpage.It works fine in IE,but not working in mozilla-FF. It is located at the location.....
9
3200
by: RichG | last post by:
I'm working with a data stream of 8 bytes in an embedded application. In most cases the data is byte aligned so I can define a structure and then memcpy the data directly to the structure elements. ...
0
7192
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
7064
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
7261
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,...
1
6974
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
5559
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,...
1
4991
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...
0
4665
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...
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
369
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.