if __name__ == '__main__': sql_insert = "INSERT INTO account (name,password) VALUES ('test42','test');" sql_insert1 = "INSERT INTO account (name,password) VALUES (%(name)s,%(password)s);" sql_update = "UPDATE account SET password= '******' WHERE name = 'test42';" sql_update1 = "UPDATE account SET password= %(password)s WHERE name = %(name)s;" sql_delete = "DELETE FROM account WHERE name = 'test';" # CAST(createtime AS CHAR) AS createtime --在MySQL端处理日期类型数据,将datetime类型转字符串后再返回 select_sql = "SELECT id, name, password,CAST(createtime AS CHAR) AS createtime FROM account;" select_sql1 = "SELECT id, name, password,CAST(createtime AS CHAR) AS createtime FROM account WHERE password=%(password)s;" print "====dbname: " + dbname print "==============sql_update=======================: \n" update(sql_update) print "==============sql_update1=======字典传参================: \n" account = Account() account.setName("test41") account.setPassword("testmodify") account_dict = {} account_dict["name"] = account.getName() account_dict["password"] = account.getPassword() print account_dict update(sql_update1, account_dict) print "==============fetchall select_sql1======字典传参=================: \n" fetchall(select_sql1, {'password': '******'})
select_sql = "SELECT id, name, password,CAST(createtime AS CHAR) AS createtime FROM account;" select_sql1 = "SELECT id, name, password,CAST(createtime AS CHAR) AS createtime FROM account WHERE password=%(password)s;" print "====dbname: " + dbname print "==============sql_delete=======================: \n" delete(sql_delete) print "==============sql_delete1=======字典传参================: \n" account = Account() account.setName("test121") account.setPassword("testmodify") account_dict = {} account_dict["name"] = account.getName() print account_dict delete(sql_delete1, account_dict) print "==============fetchall select_sql1=======================: \n" fetchall(select_sql) print "==============sql_delete1=======列表传参================: \n" account = Account() account.setName("test11") account.setPassword("testmodify") params = [] params.append(account.getName())