alfonsodg / demo-web2py

Apache License 2.0
0 stars 0 forks source link

DAL not distinguishing between fields containing empty strings and NULL fields for MySQL databases. #155

Closed alfonsodg closed 10 years ago

alfonsodg commented 10 years ago

From Tech.Eds...@gmail.com on January 14, 2011 11:40:41

What steps will reproduce the problem? 1. Create a table having a field of type 'string'. Use the field name 'telephone' as an example.

  1. Insert a record having the field telephone=''.
  2. Retrieve the record and the field named 'telephone' in the Row object has the None object as its value. What is the expected output? What do you see instead? A NULL field in the database is represented as the None object in Python. An empty string in a database field is represented as a zero-length string in Python (""). The two cases should be distinct. What version of the product are you using? On what operating system? Using 1.91.6 on FreeBSD 8.1. Please provide any additional information below. I noticed this problem after upgrading web2py to 1.91.6.

A local module for MySQL database support (gluon.contrib.pymysql) was introduced in 1.90.1 and seems to be the source of the problem.

After some debugging, I made changed the following function (in gluon/contrib/pymysql/connections.py) to correct the problem. Notice the 'if' statement.

def read_length_coded_binary(self): """Read a 'Length Coded Binary' from the data buffer.

A 'Length Coded Binary' consists first of a length coded
(unsigned, positive) integer represented in 1-9 bytes followed by
that many bytes of binary data.  (For example "cat" would be "3cat".)
"""
length = self.read_coded_length()
if length is not None:           # was 'if length:'
  return self.read(length)

This resolves the problem that I am seeing. Whether it is the proper fix or not I will leave to your decision.

Original issue: http://code.google.com/p/web2py/issues/detail?id=157

alfonsodg commented 10 years ago

From massimo....@gmail.com on January 26, 2011 20:51:34

This is fixed in trunk

alfonsodg commented 10 years ago

From massimo....@gmail.com on January 26, 2011 20:54:32

we upgraded pymysql and this should be fixed

Status: Fixed