Quoting and UnQuoting strings for Bytea
David Hughes <dfh-SSyVZMUXQxBawGkVQGIbBlpr/1R2p/[email protected]> Wed, 22 Nov 2006 11:44:45 +0000
| Newsgroups | gmane.comp.python.db.pypgsql.user |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--===============1820881236==
Content-Type: multipart/alternative;
boundary="------------070802040900000801070605"
This is a multi-part message in MIME format.
--------------070802040900000801070605
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Hello,
I'm in the process of extending an existing Python application that uses
pySqlite to use postgreSQL with pypgsql as an alternative dbms (for use
by up to 50 students simultaneously in a class) and nearly everything is
working just fine.
I'm using bytea columns to store binary strings that are mainly cPickled
strings and, in accordance with the pypgsql README I'm using:
PgQuoteBytea: Escapes a string, which can contain NUL characters, so
that it can used as an input to a bytea field.
PgUnQuoteBytea: Reverses the action of PgQuoteBytea().
But these don't seem to be completely symmetrical. The quote function
also encloses the whole string in single-quotes (why does it need to do
this?) and any embedded single-quote characters are escaped as two
single-quotes (documented as a security update in pypgsql 2.5) but
neither of these are reversed by the unquote function.
I can work round this by using an construct like:
sout = PgSQL.libpq.PgUnQuoteBytea(bstring.value).replace("''","'")[1:-1]
but I'd like to check, first, if it's really necessary to do this - I
may be doing something wrong somewhere, and second, is this a safe
solution in the general case?
--
Regards,
David Hughes
--------------070802040900000801070605
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<font size="-1"><font face="Arial">Hello,<br>
<br>
I'm in the process of extending an existing Python application that
uses pySqlite to use postgreSQL with pypgsql as an alternative dbms
(for use by up to 50 students simultaneously in a class) and nearly
everything is working just fine.<br>
<br>
I'm using bytea columns to store binary strings that are mainly
cPickled strings and, </font></font><font size="-1"><font face="Arial">in
accordance with the pypgsql README I'm using:<br>
<br>
PgQuoteBytea: Escapes a string, which can contain NUL characters, so
that it can used as an input to a bytea field.<br>
PgUnQuoteBytea: Reverses the action of PgQuoteBytea().<br>
<br>
But these don't seem to be completely symmetrical. The quote function
also encloses the whole string in single-quotes (why does it need to do
this?) and any embedded single-quote characters are escaped as two
single-quotes (documented as a security update in pypgsql 2.5) but
neither of these are reversed by the unquote function.<br>
<br>
I can work round this by using an construct like:<br>
<br>
sout = PgSQL.libpq.PgUnQuoteBytea(bstring.value).replace("''","'")[1:-1]<br>
<br>
but I'd like to check, first, if it's really necessary to do this - I
may be doing something wrong somewhere, and second, is this a safe
solution in the general case?<br>
<br>
--<br>
Regards,<br>
David Hughes<br>
</font></font><font size="-1"><font face="Arial"><br>
<br>
</font></font>
</body>
</html>
--------------070802040900000801070605--
--===============1820881236==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
--===============1820881236==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Pypgsql-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pypgsql-users
--===============1820881236==--