mardi 26 avril 2016

How do I set Python None to db3 Null

I have the following values In Python variables:

_sfwBIPMKEeCTfuMZpaDEBQ Atomic Warehouse Model None

These values are sent through a function and is being put into a db3 table like this:

INSERT INTO [PackageRoster] (PkgID, Package, PkgParentID) VALUES ('_sfwBIPMKEeCTfuMZpaDEBQ', 'Atomic Warehouse Model', 'None');

I do not want the string 'None' put into the table. I would like NULL. How do I tell Python to inject NULL instead of None?

Here's the function that works the statement (includes debug feature):

def StorePackage(PkgID, Package, PkgParentID):
    dbutils.ResetTable()
    conn = sqlite3.connect(dbutils.db)
    try:
        conn.execute("INSERT INTO " + dbutils.table + " (PkgID, Package, PkgParentID) VALUES ('" + PkgID + "', '" + Package + "', '" + PkgParentID + "');")
    except:
        print("INSERT INTO " + dbutils.table + " (PkgID, Package, PkgParentID) VALUES ('" + PkgID + "', '" + Package + "', '" + str(PkgParentID) + "');")
    conn.commit()

Thanks

Aucun commentaire:

Enregistrer un commentaire