sqlwrap.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:coquery 作者: gkunter 项目源码 文件源码
def has_database(self, db_name):
        """
        Check if the database 'db_name' exists on the current connection.

        Parameters
        ----------
        db_name : str
            The name of the database

        Returns
        -------
        b : bool
            True if the database exists, or False otherwise.
        """
        if self.db_type == SQL_MYSQL:
            with self.engine.connect() as connection:
                results = connection.execute("SHOW DATABASES")
            try:
                for x in results:
                    if x[0] == db_name.split()[0]:
                        return db_name
            except pymysql.ProgrammingError as ex:
                warnings.warn(ex)
                raise ex
            return False
        elif self.db_type == SQL_SQLITE:
            return os.path.exists(SqlDB.sqlite_path(db_name))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号