Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the cause of mysqldb's Warning: Truncated incorrect DOUBLE value error?

I am getting many warnings of the same kind --

Warning: Truncated incorrect DOUBLE value: '512121500B'

-- but cannot figure out why.

The MySQL table dr_snapshot looks like this:

PremiseID char(10) Primary Key
cycle SMALLINT(6)
last_read DATETIME
reading INTEGER
DeviceID INTEGER

I want to delete many rows by PremiseID. Here is one in particular: '512121500B'.

Here is my Python function that deletes by PremiseID:

def delDrSnapRow(premiseID, db):
    sql_cmd = " ".join([
        "delete ",
        "from dr_snapshot ",
        "where PremiseID = " + str(premiseID) + " ; "])

    del_cur = db.cursor()
    rc = del_cur.execute(sql_cmd)
    del_cur.close()

    return rc

PremiseID is a string, not a double. What am I missing here?

Many thanks.

Edit

After modifying my delete procedure to use try: .. except, I am not seeing the warning. I believe I am not seeing the warning, because I'm not seeing the warning display -- print(e) -- in the except part.

I am left with the conclusion that the try: except somehow removed the error.

def delDrSnapRow(premiseID, db):
    sql_cmd = " ".join([
        "delete ",
        "from dr_snapshot ",
        "where PremiseID = " + "'" + premiseID + "' ; "])

    del_cur = db.cursor()

    try:
        rc = del_cur.execute(sql_cmd)

    except MySQLdb.Error, e:
        print "Error %d: %s" % (e.args[0], e.args[1])

    except MySQLdb.Warning, e:
        print(e)
        rc = del_cur.execute(sql_cmd)

    del_cur.close()

    return rc
like image 864
octopusgrabbus Avatar asked Aug 02 '12 15:08

octopusgrabbus


1 Answers

Look at this line "where PremiseID = " + str(premiseID) + " ; "])". The comparison is happening on different types and when MySQL compares different datatypes they are cast to DOUBLE internally before comparison. So you can try putting single quote around or cast around to solve the issue. So it's not try catch but the quotes which resolve the issue.

like image 159
Manisha Mahawar Avatar answered Sep 21 '22 02:09

Manisha Mahawar