logo       


Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: [psycopg] #12: psycopg2 use buffer for binary columns: msg#00047

Subject: Re: [psycopg] #12: psycopg2 use buffer for binary columns
#12: psycopg2 use buffer for binary columns
----------------------+-----------------------------------------------------
       Id:  12        |      Status:  new                             
Component:  psycopg2  |    Modified:  Sat 16 Apr 2005 08:20:34 PM CEST
 Severity:  normal    |   Milestone:  PSYCOPG 2.0 beta1               
 Priority:  normal    |     Version:  1.99.13                         
    Owner:  fog       |    Reporter:  fog                             
----------------------+-----------------------------------------------------
Old description:

> the attached patch makes psycopg2 return a buffer object for bytea
> columns. There are two advantages for this:
>
> - - It provides for transparent DB -> Python -> DB round trips for
> bytea columns. Without this patch, psycopg returns a 'str' object for
> bytea columns. This string cannot be passed directly back to
> cursor.execute(), as psycopg assumes strings are intended for a
> character column and therefore strips out null bytes. The solution
> was to wrap it into psycopg.Binary, but is not transparent as you
> need to know the column is binary. With the patch, psycopg returns a
> 'buffer' object for bytea columns, which is already recognized by
> psycopg and assumed to be going into a binary column.
> - - It is faster. No extra copy is needed to generate the Python
> string. Using the buffer interface, Python code can directly access
> the low-level buffer returned by PQunescapeBytea.
>
> The implementation introduces a new C-level Python type called
> "chunk". A chunk basically holds a memory area, and makes sure it is
> freed at object destruction. The chunk exports the buffer interface
> (PyBufferProcs), and is wrapped in a real Python buffer object using
> PyBuffer_FromObject(). This different from the implementation hint by
> Federico in the comment in typecast.c:
>
> {{{
>    /* TODO: using a PyBuffer would make this a zero-copy operation but
> we'll
>       need to define our own buffer-derived object to keep a reference to
> the
>       memory area: does it buy it? */
> }}}
>
> I think this implementation is a bit simpler, as it doesn't involve
> subclassing builtin types and it doesn't export any new types to the
> end user.

New description:

 the attached patch makes psycopg2 return a buffer object for bytea
 columns. There are two advantages for this:

  * It provides for transparent DB -> Python -> DB round trips for
 bytea columns. Without this patch, psycopg returns a 'str' object for
 bytea columns. This string cannot be passed directly back to
 cursor.execute(), as psycopg assumes strings are intended for a
 character column and therefore strips out null bytes. The solution
 was to wrap it into psycopg.Binary, but is not transparent as you
 need to know the column is binary. With the patch, psycopg returns a
 'buffer' object for bytea columns, which is already recognized by
 psycopg and assumed to be going into a binary column.

  * It is faster. No extra copy is needed to generate the Python
 string. Using the buffer interface, Python code can directly access
 the low-level buffer returned by PQunescapeBytea.

 The implementation introduces a new C-level Python type called
 "chunk". A chunk basically holds a memory area, and makes sure it is
 freed at object destruction. The chunk exports the buffer interface
 (PyBufferProcs), and is wrapped in a real Python buffer object using
 PyBuffer_FromObject(). This different from the implementation hint by
 Federico in the comment in typecast.c:

 {{{
    /* TODO: using a PyBuffer would make this a zero-copy operation but
 we'll
       need to define our own buffer-derived object to keep a reference to
 the
       memory area: does it buy it? */
 }}}

 I think this implementation is a bit simpler, as it doesn't involve
 subclassing builtin types and it doesn't export any new types to the
 end user.

-- 
Ticket URL: <http://initd.org/tracker/psycopg/ticket/12>
psycopg <http://initd.org/>
psycopg
_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/+sw@xxxxxxxxxxxxxxxx
http://lists.initd.org/mailman/listinfo/psycopg
Ruby Jobs
Java Jobs
Jobs in California
more...
what
job title, keywords
where
city, state, zip
jobs by job search
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
encryption.gpg....    ietf.rfc822/199...    freebsd.devel.i...    lang.haskell.li...    mail.squirrelma...    web.zope.plone....    yellowdog.gener...    text.xml.xalan....    recreation.phot...    kde.devel.educa...    hardware.bus.ca...    printing.ghosts...    voip.peering/20...    assembly/2006-0...    org.user-groups...    culture.interne...    network.i2p/200...    boot-loaders.ya...    xfree86.render/...    qnx.openqnx.dev...    jakarta.velocit...    user-groups.pal...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe