python mysql 返回空_MySQL更新单元格后返回空值

我有点MySQL的问题。我编写了一个python脚本来记录点击率并处理重定向。我有一个表,其中对于给定的ip地址,有多个列,其中包括一个包含id列表的列。如果用户从未单击过图像(该行仍将存在),则该单元格包含一个空列表。在

请注意,在表中更新之前,列表是使用json序列化为字符串的。我知道这并不总是一个好的做法,但对我们的应用程序似乎是有效的。在

因此,在用户单击图像之前,可以查询sql表:sql = """select clicked_id from `""" + DBTABLE2 + """`

where ip='%s'"""%(ip_address,)

cur.execute(sql)

row = cur.fetchone()

if row:

ci = row['clicked_id']

print ci, type(ci)

clicked_id=json.loads(ci)

print clicked_id, type(clicked_id)

打印语句返回:

^{pr2}$

但是,在运行以下python脚本(成功运行)之后,输出就完全不同了。下面是python代码:#connecting to the mysql table

con = mysql.connect(host=DBHOST, user=DBUSERNAME, passwd=DBPASSWORD,

db=DBDATABASE, cursorclass=DictCursor)

cur = con.cursor()

#save the click through

sql = """select clicked_id from `""" + DBTABLE2 + """`

where ip='%s'"""%(ip_address,)

cur.execute(sql)

row = cur.fetchone()

if row:

clicked_id = row['clicked_id']

#decoding the data

clicked_id = json.loads(clicked_id)

else:

clicked_id=[]

#Updating the list

clicked_id = clicked_id.append(product_id)

#Encoding the data

clicked_id = json.dumps(clicked_id)

#Updating the mysql database

cur.execute("""update `"""+DBTABLE2+"""` set clicked_id='%s' where ip='%s'"""%(clicked_id,ip_address,))

#Getting the dst url

sql = """select url from `""" + DBTABLE + """`

where id='%s'"""%(product_id,)

cur.execute(sql)

row = cur.fetchone()

if row:

url = row['url']

再次检查表时,print语句返回:null

None

我不知道它为什么要这么做。。。我非常感谢你的帮助!在


版权声明:本文为weixin_34486033原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。