def run_update_sql(sql): try: conn = db_pool.getConn() cursor = conn.cursor() count = cursor.execute(sql, ) conn.commit() db_pool.close(cursor, conn) except Exception as e: logger.error('runsql exception error %s ' % e)
def run_sql(sql): try: conn = db_pool.getConn() cursor = conn.cursor() count = cursor.execute(sql, ) conn.commit() db_pool.close(cursor, conn) except Exception as e: print(" runsql ...except error %s" % e.message)
def update_sql(sql): logger.info('[sql__update]....%s' % sql) try: conn = db_pool.getConn() cursor = conn.cursor() count = cursor.execute(sql, ) conn.commit() db_pool.close(cursor, conn) except Exception as e: print(" update_sql ...except error %s" % e.message)
def get_all_sql(sql): try: conn = db_pool.getConn() cursor = conn.cursor() count = cursor.execute(sql, ) conn.commit() list = cursor.fetchall() # 获取所有数据 db_pool.close(cursor, conn) return list except Exception as e: print(" get_all_sql ...except error %s" % e.message)
def get_one_sql(sql): try: conn = db_pool.getConn() cursor = conn.cursor() count = cursor.execute(sql, ) conn.commit() result = cursor.fetchone() # 获取一条数据 db_pool.close(cursor, conn) return result except Exception as e: print(" get_one_sql ...except error %s" % e.message)
def runsql(sql): logger.info('[sql]....%s' % sql) try: conn = db_pool.getConn() cursor = conn.cursor() count = cursor.execute(sql, ) conn.commit() db_pool.close(cursor, conn) # logger.info("----runsql-----",sql) except Exception as e: logger.info(" runsql ...except error %s" % e.message)
def runsql(sql): try: conn = db_pool.getConn() cursor = conn.cursor() count = cursor.execute(sql, ) LOGGER.info("ID of last record is %d" % int(cursor.lastrowid)) # 最后插入行的主键ID conn.commit() db_pool.close(cursor, conn) except Exception as e: LOGGER.error('runsql exception error %s ' % e.message)
def get_all_sql(sql): #logger.info('[get_all_sql]....%s' % sql) try: conn = db_pool.getConn() cursor = conn.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor) count = cursor.execute(sql, ) conn.commit() list = cursor.fetchall() # 获取所有数据 db_pool.close(cursor, conn) return list except Exception as e: print(" get_all_sql ...except error %s" % e.message)
def get_one_sql(sql): logger.info('[sql__get_one]....%s' % sql) try: conn = db_pool.getConn() cursor = conn.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor) count = cursor.execute(sql, ) conn.commit() result = cursor.fetchone() # 获取一条数据 db_pool.close(cursor, conn) return result except Exception as e: print(" get_one_sql ...except error %s" % e.message)
def run_insert_sql(sql): try: conn = db_pool.getConn() cursor = conn.cursor() count = cursor.execute(sql, ) id = cursor.fetchone()[0] print "ID of last record is ", id # 最后插入行的主键ID conn.commit() db_pool.close(cursor, conn) return id except Exception as e: logger.error('runsql exception error %s ' % e)