最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python使用sqlalchemy實現(xiàn)連接數(shù)據(jù)庫的幫助類

 更新時間:2024年02月15日 07:26:28   作者:搬磚的詩人Z  
這篇文章主要為大家詳細介紹了Python如何使用sqlalchemy實現(xiàn)連接數(shù)據(jù)庫的幫助類,文中的示例代碼講解詳細,具有一定的借鑒價值,需要的可以參考下

python使用 sqlalchemy連接數(shù)據(jù)庫幫助類

實現(xiàn)代碼

import mysql.connector

class MySqlHelper(object):
    """操作數(shù)據(jù)庫幫助類"""

    def __init__(self):
        #self.host = "localhost"
        #self.user = "root"
        #self.password = "xinshiyun@123"
        #self.database = "deliverunion_callcenter"
        self.host = "192.168.60.156"
        self.user = "root"
        self.password = "root"
        self.database = "deliverunion_callcenter"
        try:
            self.mydb = mysql.connector.connect(host=self.host,
                        user=self.user,
                        passwd=self.password,
                        database=self.database,
                        connect_timeout=10)
                        #database=self.database,
                        #auth_plugin='mysql_native_password')
            self.mycursor = self.mydb.cursor()
        except Exception as e:
            print('MySql Error : %d %s' % (e.args[0],e.args[1]))


    #不帶參數(shù)的查詢
    def select(self,mysql):
        try:
            self.mycursor.execute(mysql)
            values = self.mycursor.fetchall()
            return values
        except Exception as e:
            print ('select Error : %d %s' % (e.args[0],e.args[1]))
            return []
        finally:
            self.mycursor.close()
            self.mydb.close()

    #帶參數(shù)的查詢
    def select2(self,mysql,na):
        try:
            self.mycursor.execute(mysql,na)
            values = self.mycursor.fetchall()
            return values
        except Exception as e:
            print ('select2 Error : %d %s' % (e.args[0],e.args[1]))
            return []
        finally:
            self.mycursor.close()
            self.mydb.close()

    #更新
    def Update(self,mysql,na):
         try:
            self.mycursor.execute(mysql,na)
            self.mydb.commit()
            row = self.mycursor.rowcount
            if row > 0:
                return True
            else:
                return False
         except Exception as e:
            print ('Update Error : %d %s' % (e.args[0],e.args[1]))
            return False
          
         finally:
            self.mycursor.close()
            self.mydb.close()

    #插入數(shù)據(jù)
    def Insert(self,mysql,na):
         try:
            self.mycursor.execute(mysql,na)
            self.mydb.commit()
            row = self.mycursor.rowcount
            if row > 0:
                return True
            else:
                return False
         except Exception as e:
            print('Insert Error : %d %s' % (e.args[0],e.args[1]))
            return False
          
         finally:
            self.mycursor.close()
            self.mydb.close()

使用數(shù)據(jù):

from DAL import MySqlHelper
from Entity import TaskPoolEntity
import datetime

class TaskPoolDAL(object):
    """操作數(shù)據(jù)庫t_du_guiji_task"""

    sqlHelper = MySqlHelper.MySqlHelper()

    #查詢所有的任務(wù)
    def selectTasks():
        TaskPoolDAL.sqlHelper = MySqlHelper.MySqlHelper()
        sql='select * from  t_du_guiji_task'
        values= TaskPoolDAL.sqlHelper.select(sql)
        data=[]
        for item in values:
           selectTask = TaskPoolEntity.TaskPoolEntity(item)
           data.append(selectTask)

        return data

以上就是Python使用sqlalchemy實現(xiàn)連接數(shù)據(jù)庫的幫助類的詳細內(nèi)容,更多關(guān)于Python sqlalchemy連接數(shù)據(jù)庫的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • python pandas 組內(nèi)排序、單組排序、標(biāo)號的實例

    python pandas 組內(nèi)排序、單組排序、標(biāo)號的實例

    下面小編就為大家分享一篇python pandas 組內(nèi)排序、單組排序、標(biāo)號的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-04-04
  • python中int與str互轉(zhuǎn)方法

    python中int與str互轉(zhuǎn)方法

    最近學(xué)習(xí)python中的數(shù)據(jù)類型時,難免聯(lián)想到j(luò)ava中的基本型數(shù)據(jù)類型與引用型數(shù)據(jù)類型。接下來通過本文給大家介紹python中int與str互轉(zhuǎn),需要的朋友可以參考下
    2018-07-07
  • Python 限定函數(shù)參數(shù)的類型及默認值方式

    Python 限定函數(shù)參數(shù)的類型及默認值方式

    今天小編就為大家分享一篇Python 限定函數(shù)參數(shù)的類型及默認值方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • node命令行服務(wù)器(http-server)和跨域的實現(xiàn)

    node命令行服務(wù)器(http-server)和跨域的實現(xiàn)

    本文主要介紹了node命令行服務(wù)器(http-server)和跨域的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • Django組件之cookie與session的使用方法

    Django組件之cookie與session的使用方法

    這篇文章主要介紹了Django組件之cookie與session的使用方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-01-01
  • 使用python獲取csv文本的某行或某列數(shù)據(jù)的實例

    使用python獲取csv文本的某行或某列數(shù)據(jù)的實例

    下面小編就為大家分享一篇使用python獲取csv文本的某行或某列數(shù)據(jù)的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-04-04
  • python 爬取微信文章

    python 爬取微信文章

    本文給大家分享的是使用python通過搜狗入口,爬取微信文章的小程序,非常的簡單實用,有需要的小伙伴可以參考下
    2016-01-01
  • Python正則表達式使用指南

    Python正則表達式使用指南

    正則表達式(Regular Expression, 簡稱 regex)是處理字符串和文本的強大工具,它使用特定的語法定義一組規(guī)則,通過這些規(guī)則可以對文本進行匹配、查找、替換等操作,本文將詳細介紹 Python 中如何使用正則表達式,需要的朋友可以參考下
    2024-11-11
  • numpy 數(shù)組拷貝地址所引起的同步替換問題

    numpy 數(shù)組拷貝地址所引起的同步替換問題

    本文主要介紹了numpy 數(shù)組拷貝地址所引起的同步替換問題,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • python 使用socket傳輸圖片視頻等文件的實現(xiàn)方式

    python 使用socket傳輸圖片視頻等文件的實現(xiàn)方式

    這篇文章主要介紹了python 使用socket傳輸圖片視頻等文件的實現(xiàn)方式,本文給出了實例代碼,需要的朋友可以參考下
    2019-08-08

最新評論

涪陵区| 宁陕县| 西盟| 双桥区| 葵青区| 霸州市| 东丰县| 万年县| 揭阳市| 开远市| 永福县| 平舆县| 雅江县| 乌苏市| 南充市| 贞丰县| 武宁县| 孟州市| 海兴县| 和田县| 台前县| 浙江省| 淳安县| 谢通门县| 贡山| 方城县| 丰宁| 临沭县| 阳高县| 长葛市| 芮城县| 连平县| 绥德县| 交口县| 雷州市| 工布江达县| 广安市| 辛集市| 婺源县| 化州市| 云安县|