- 论坛徽章:
- 0
|
做web开发的话一般都自带ORM,不如django什么的。或者你可以自己封装.
比如我简单封装了update- def update(self, tablename, update_dict, condition_dict = {}, dry=False):
- sql = "UPDATE `%s` SET " % tablename
- for key in update_dict.iterkeys():
- sql += "`" + key + "` = %(" + key + ")s,"
-
- sql = sql[:-1]
-
- if len(condition_dict) > 0:
- sql += " WHERE "
- for key in condition_dict.iterkeys():
- sql += "`" + key + "` = %(" + key + ")s AND "
- if not update_dict.has_key(key):
- update_dict[key] = condition_dict[key]
-
- sql = sql[:-4]
-
- if dry:
- return sql, update_dict
- else:
- return self.operation(sql, update_dict)
复制代码 |
|