How can I set the encoding on the datasets? I use a lot of datasets 
individually (without bizobjs etc) in my application, and want them in a 
different encoding. Can you put in an Encoding parameter on the datasets like 
this:
 
>>> from dabo.db import dDataSet
>>> ds = dDataSet(({"lala":"æøå"},))
>>> ds
({'lala': '\xe6\xf8\xe5'},)
>>> ds.execute("select * from dataset")
Traceback (most recent call last):
  File "<input>", line 1, in ?
  File "c:\python24\lib\site-packages\Dabo-0.7a-py2.4.egg\dabo\db\dDataSet.py", 
line 357, in execute
    self._cursor.execute(sqlExpr, params)
OperationalError: Could not decode to UTF-8 column <unknown column name> with 
text æøå

A possible solution (it's what I use with regular sqlite, and it is working 
well):

>>> ds._connection.text_factory = lambda s: unicode(s, "latin1", "replace")
>>> ds.execute("select * from dataset")
({'lala': u'\xe6\xf8\xe5'},)
>>> print ds[0]["lala"]
æøå


patch:

--- dDataSet_old.py     2006-09-21 18:48:24.405785700 +0200
+++ dDataSet.py 2006-10-04 22:12:30.431109100 +0200
@@ -55,6 +55,8 @@
                # When filtering datasets, we need a reference to the dataset
                # this dataset was derived from.
                self._sourceDataSet = None
+
+               self._encoding = "utf8"
                
                # Register the converters
                sqlite.register_converter("memento", self._convert_memento)
@@ -334,6 +336,8 @@
                        self._connection = sqlite.connect(":memory:", 
                                        
detect_types=(sqlite.PARSE_DECLTYPES|sqlite.PARSE_COLNAMES), 
                                        isolation_level="EXCLUSIVE")
+                                       # Set to default encoding
+                                       self.Encoding(self._encoding)
                if self._cursor is None:
                        self._cursor = 
self._connection.cursor(factory=DictCursor)
                
@@ -386,7 +390,15 @@
 #              dt = time.clock()
 #              print "CONVERTED", dt-ft
                
+       def _getEncoding(self):
+               return self._encoding
+
+       def _setEncoding(self, encoding):
+               self._encoding = encoding
+               self._connection.text_factory = lambda s:unicode(s, 
self._encoding, "replace")
 
+       Encoding = property(_getEncoding, _setEncoding, None,
+                       """ Gets or sets the encoding """)
 
 
 # class DataSetOld(tuple):


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users

Reply via email to