Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
    @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()