I have a Zope session variable that is set to None. When I update my MySQL database and set the value of one of my fields to the value of this session variable, the value is set to the string 'None'. Anyone encountered a similar problem? I would think that the None object would translate to the NULL database constant and not the string with value 'None'. Any help would be appreciated. Thanks. - Asad
if s == None: return s = "NULL" db.query("insert into <table> values ('%s')" % s) Cornel At 17:51 2/9/2005, you wrote:
I have a Zope session variable that is set to None. When I update my MySQL database and set the value of one of my fields to the value of this session variable, the value is set to the string 'None'. Anyone encountered a similar problem? I would think that the None object would translate to the NULL database constant and not the string with value 'None'. Any help would be appreciated. Thanks.
- Asad _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
On Wed, 9 Feb 2005 10:51:09 -0500 (EST), Asad Habib <ahabib@engin.umich.edu> wrote:
I have a Zope session variable that is set to None. When I update my MySQL database and set the value of one of my fields to the value of this session variable, the value is set to the string 'None'. Anyone encountered a similar problem? I would think that the None object would translate to the NULL database constant and not the string with value 'None'. Any help would be appreciated. Thanks.
You are correct that a Python None should be written to the database as NULL, and vice versa. I can only conclude that something in your application is converting None to 'None' (i.e. str(None)). If you are getting it out of a session variable, this seems likely. -- Computer interfaces should never be made of meat. Using GMail? Setting Reply-to address to <> disables this annoying feature.
Actually, I am not using str in this case at all. In fact, right before the Z SQL method is called, I have a <dtml-var> that displays the value of this session variable and the value is the None object not 'None'. I figured out that this conversion from object to str takes place inside the <dtml-sqlvar> tag used in this Z SQL method. The <dtml-sqlvar> tag converts the None object to a string because I am calling it with a type attribute set to the value 'string' (i.e. <dtml-sqlvar name="test" type="string">). - Asad On Wed, 9 Feb 2005, Andy Dustman wrote:
On Wed, 9 Feb 2005 10:51:09 -0500 (EST), Asad Habib <ahabib@engin.umich.edu> wrote:
I have a Zope session variable that is set to None. When I update my MySQL database and set the value of one of my fields to the value of this session variable, the value is set to the string 'None'. Anyone encountered a similar problem? I would think that the None object would translate to the NULL database constant and not the string with value 'None'. Any help would be appreciated. Thanks.
You are correct that a Python None should be written to the database as NULL, and vice versa. I can only conclude that something in your application is converting None to 'None' (i.e. str(None)). If you are getting it out of a session variable, this seems likely. -- Computer interfaces should never be made of meat.
Using GMail? Setting Reply-to address to <> disables this annoying feature. _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
On Thu, 10 Feb 2005 00:59:11 -0500 (EST), Asad Habib <ahabib@engin.umich.edu> wrote:
I figured out that this conversion from object to str takes place inside the <dtml-sqlvar> tag used in this Z SQL method. The <dtml-sqlvar> tag converts the None object to a string because I am calling it with a type attribute set to the value 'string' (i.e. <dtml-sqlvar name="test" type="string">).
In that case, you probably need to add the optional keyword to your <dtml-sqlvar> tag, and maybe use type="nb" as well (depends on your application). http://www.zope.org/Documentation/Guides/ZSQL-HTML/ZSQL.1.5.2.html -- Computer interfaces should never be made of meat. Using GMail? Setting Reply-to address to <> disables this annoying feature.
participants (3)
-
Andy Dustman -
Asad Habib -
Cornel Nitu