Changeset 189:42e67f73416f in livinglogic.python.orasql

Show
Ignore:
Timestamp:
02/21/07 13:47:30 (13 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Tags:
rel-1-16
Message:

Add a parameter unicode to various constructors and methods.
This parameter can be used to get strings (i.e. VARCHAR2 and
CLOBs) as unicode object instead of str objects.

Files:
3 modified

Legend:

Unmodified
Added
Removed
  • NEWS.xml

    r188 r189  
     1<section><title>Changes in 1.16 (released 02/21/2007)</title> 
     2<ulist> 
     3<item>A parameter <arg>unicode</arg> has been added to various constructors 
     4and methods. This parameter can be used to get strings (i.e. <lit>VARCHAR2</lit> 
     5and <lit>CLOB</lit>s) as <class>unicode</class> object instead of 
     6<class>str</class> objects.</item> 
     7</ulist> 
     8</section> 
     9 
     10 
    111<section><title>Changes in 1.15 (released 02/17/2007)</title> 
    212<ulist> 
  • setup.py

    r186 r189  
    4747args=dict( 
    4848    name="ll-orasql", 
    49     version="1.15", 
     49    version="1.16", 
    5050    description="Utilities for working with cx_Oracle", 
    5151    long_description=DESCRIPTION, 
  • src/ll/orasql/__init__.py

    r188 r189  
    108108        """ 
    109109        record = cls() 
     110        encoding = getattr(cursor.connection, "encoding", None) 
    110111        for (i, field) in enumerate(row): 
    111112            if isinstance(field, LOB) and (cursor.readlobs is True or (isinstance(cursor.readlobs, (int, long)) and field.size() <= cursor.readlobs)): 
    112113                field = field.read() 
     114            if isinstance(field, str) and cursor.unicode and encoding and cursor.description[i][1] is not BLOB: 
     115                field = field.decode(encoding) 
    113116            record[cursor.description[i][0]] = field 
    114117        return record 
     
    196199    def __init__(self, *args, **kwargs): 
    197200        """ 
    198         Create a new connection. In addition to the parameters supported 
    199         by <function>cx_Oracle.connect</function> the keyword argument 
    200         <arg>readlobs</arg> is supported. If <arg>readlobs</arg> is <lit>False</lit> 
     201        <par>Create a new connection. In addition to the parameters supported 
     202        by <function>cx_Oracle.connect</function> the following keyword arguments 
     203        are supported.</par> 
     204        <dlist> 
     205        <term><arg>readlobs</arg></term><item>If <arg>readlobs</arg> is <lit>False</lit> 
    201206        all cursor fetch return <class>LOB</class> objects as usual. If 
    202207        <arg>readlobs</arg> is an <class>int</class> (or <class>long</class>) 
    203208        <class>LOB</class>s with a maximum size of <arg>readlobs</arg> 
    204209        will be returned as strings. If <arg>readlobs</arg> is <lit>True</lit> 
    205         all <class>LOB</class>s will be returned as strings. 
    206         """ 
    207         if "readlobs" in kwargs: 
     210        all <class>LOB</class>s will be returned as strings.</item> 
     211        <term><arg>unicode</arg></term><item>If <arg>unicode</arg> is true, 
     212        strings (and <class>CLOB</class>s, if <arg>readlobs</arg> has the appropriate 
     213        value) will be returned as <class>unicode</class> objects (except for 
     214        <class>BLOB</class>s). Note that strings in the national character set 
     215        (and <class>NCLOB</class>s) are not supported).</item> 
     216        </dlist> 
     217        """ 
     218        if "readlobs" in kwargs or "unicode" in kwargs: 
    208219            kwargs = kwargs.copy() 
    209             self.readlobs = kwargs.pop("readlobs") 
     220            self.readlobs = kwargs.pop("readlobs", False) 
     221            self.unicode = kwargs.pop("unicode", False) 
    210222        else: 
    211223            self.readlobs = False 
     224            self.unicode = False 
    212225        super(Connection, self).__init__(*args, **kwargs) 
    213226 
     
    215228        return "%s@%s" % (self.username, self.tnsentry) 
    216229 
    217     def cursor(self, readlobs=None): 
     230    def cursor(self, readlobs=None, unicode=None): 
    218231        """ 
    219232        Return a new cursor for this connection. For the meaning 
    220         of <arg>readlobs</arg> see 
     233        of <arg>readlobs</arg> and <arg>unicode</arg> see 
    221234        <pyref method="__init__"><method>__init__</method></pyref>. 
    222235        """ 
    223         return Cursor(self, readlobs=readlobs) 
     236        return Cursor(self, readlobs=readlobs, unicode=unicode) 
    224237 
    225238    def __repr__(self): 
     
    495508    cursor will be returned as <pyref class="Record"><class>Record</class> objects. 
    496509    """ 
    497     def __init__(self, connection, readlobs=None): 
     510    def __init__(self, connection, readlobs=None, unicode=None): 
    498511        """ 
    499512        Return a new cursor for the connection <arg>connection</arg>. 
    500         For the meaning of <arg>readlobs</arg> see 
     513        For the meaning of <arg>readlobs</arg> and <arg>unicode</arg> see 
    501514        <pyref class="Connection" method="__init__"><class>Connection</class>s constructor</pyref>. 
    502515        """ 
     
    506519        else: 
    507520            self.readlobs = connection.readlobs 
     521        if unicode is not None: 
     522            self.unicode = unicode 
     523        else: 
     524            self.unicode = connection.unicode 
    508525         
    509526    def fetchone(self, type=Record):