def _basic_query(sql): """ 执行查询的sql的基本过程 """ con = getConn() try: with con.cursor() as cursor: cursor.execute(sql) result = cursor.fetchall() except Exception as ex: print(sql) print("Error:{}".format(ex)) return [] return result
def _basic_execute(sql): """ 执行非查询sql的基本过程 """ con = getConn() try: with con.cursor() as cursor: cursor.execute(sql) con.commit() except Exception as ex: con.rollback() print(sql) print("Error:{}".format(ex)) return False return True
@Author: Victor Chen @File : DaoEasyNews.py @Description: 为EasyNews实体类提供的数据修改的操作类 ''' import pymysql from datetime import datetime import time from utils.annotations import threadLock from dao.DaoConfig import getConn from entity.EasyNews import EasyNews conn = getConn() @threadLock def insert(easyNews): try: with conn.cursor() as cursor: sql = "INSERT INTO `posts`(`postsNewsId`,`postsType`,`postsTitle`,`postsPublishTime`,`postsMain`) " \ + "VALUES('"+ easyNews.newsId +"',1,'"+ easyNews.title +"','"+ easyNews.publishTime +"','"+ easyNews.content +"')" cursor.execute(sql) # commit conn.commit() except Exception as e: conn.rollback()