dabo Commit
Revision 2314
Date: 2006-10-05 08:36:40 -0700 (Thu, 05 Oct 2006)
Author: ed

Changed:
U   trunk/dabo/db/dDataSet.py

Log:
Added the Encoding property to the dDataSet class. Thanks to Simen Haugen for 
the code.


Diff:
Modified: trunk/dabo/db/dDataSet.py
===================================================================
--- trunk/dabo/db/dDataSet.py   2006-10-05 00:23:32 UTC (rev 2313)
+++ trunk/dabo/db/dDataSet.py   2006-10-05 15:36:40 UTC (rev 2314)
@@ -55,6 +55,7 @@
                # 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 +335,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)
                
@@ -385,10 +388,26 @@
 #              
 #              dt = time.clock()
 #              print "CONVERTED", dt-ft
-               
 
 
+       def _getEncoding(self):
+               return self._encoding
+       
+       def _setEncoding(self, encoding):
+               self._encoding = encoding
+               try:
+                       self._connection.text_factory = lambda s:unicode(s, 
self._encoding, "replace")
+               except AttributeError:
+                       # The connection has not yet been set, but it will once
+                       # queries is executed
+                       pass
+       
+       Encoding = property(_getEncoding, _setEncoding, None,
+                       """ Gets or sets the encoding """)
 
+
+
+
 # class DataSetOld(tuple):
 #      """ This class assumes that its contents are not ordinary tuples, but
 #      rather tuples consisting of dicts, where the dict keys are field names.




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

Reply via email to