Data problem

Aaron Bingham bingham at cenix-bioscience.com
Wed Dec 15 11:33:22 EST 2004


Jeffrey Maitland wrote:
> I am using the MySQLdb module and I am writing to a MySQL database.
> 
> My write statement is something like.
> 
> cursor.execute(“INSERT INTO Data(Name, X, Y, Z, Data)
> 
>                        VALUES('%s', '%s', '%s', '%f', '%f', '%f', 
> '%s')""" %
> 
>                                    (name, high_x, high_y, high_z, data))

This is not causing your problem, but why not take advantage of the 
DB-API value substitution support, e.g.:

cursor.execute("""INSERT INTO Data(Name, X, Y, Z, Data)

                        VALUES(%s, %f, %f, %f, %s)""",
                (name, high_x, high_y, high_z, data))

This will take care of correctly escaping and quoting strings and 
formatting floats for you automatically.

> I can write the data to a file as a check and all  variables are showing 
> correctly. However when I extract the data from the database the X, Y 
> are not coming out with the same number that “should be going” into the 
> database but the Z is.  Any Ideas?

My first guess would be that the X and Y fields in the DB are actually 
defined as integers, not floats, but you probably already checked that.

Regards,

-- 
--------------------------------------------------------------------
Aaron Bingham
Application Developer
Cenix BioScience GmbH
--------------------------------------------------------------------




More information about the Python-list mailing list