How to use the pymysql.cursors function in PyMySQL

To help you get started, we’ve selected a few PyMySQL examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github michael-weinstein / dsNickFury3PlusOrchid / dsNickFury3PlusOrchid / ensemblDataConversion.py View on Github external
def getDatabase(self):
        import operator
        clusterSize = self.clusterSize
        import pymysql
        ensemblDb = pymysql.connect(host='ensembldb.ensembl.org',
                                    user='anonymous',
                                    password='',
                                    db='ensembl_website_88',
                                    charset='utf8mb4',
                                    cursorclass=pymysql.cursors.DictCursor)
        ensemblConnection = ensemblDb.cursor()
        query = "SELECT\
                    display_label, gene_autocomplete.stable_id, location, homo_sapiens_core_88_38.gene.biotype\
                 FROM\
                    gene_autocomplete, homo_sapiens_core_88_38.gene\
                 WHERE\
                    species = 'homo_sapiens' and gene_autocomplete.stable_id = homo_sapiens_core_88_38.gene.stable_id"        
        ensemblConnection.execute(query)
        rawConversionTable = ensemblConnection.fetchall()
        conversionTable = {}
        for item in rawConversionTable:
            locus = item["location"]
            contig, position = locus.split(":")
            start, end = position.split("-")
            start = int(start)
            end = int(end)
github NMGRL / pychron / pychron / dvc / pychrondata_transfer_helpers.py View on Github external
def load_import_request():
    import pymysql.cursors
    # Connect to the database
    connection = pymysql.connect(host='localhost',
                                 user=os.environ.get('DB_USER'),
                                 passwd=os.environ.get('DB_PWD'),
                                 db='labspy',
                                 cursorclass=pymysql.cursors.DictCursor)

    try:
        # connection is not autocommit by default. So you must commit to save
        # your changes.
        # connection.commit()

        with connection.cursor() as cursor:
            # Read a single record
            # sql = "SELECT `id`, `password` FROM `users` WHERE `email`=%s"
            # cursor.execute(sql, ('webmaster@python.org',))
            sql = '''SELECT * FROM importer_importrequest'''
            cursor.execute(sql)
            result = cursor.fetchone()

            runs = result['runlist_blob']
            expid = result['repository_identifier']
github stufisher / homie-control / devices / modules / mysql.py View on Github external
def __init__(self, user, pw, db, host='127.0.0.1'):
        self._conn = pymysql.connect(host=host, user=user, passwd=pw, db=db)
        self._conn.autocommit(1)
        self._conn.ping(True)

        self._cur = self._conn.cursor(pymysql.cursors.DictCursor)
github hequan2017 / autoops / tasks / views.py View on Github external
def sql_rb(user, password, host, port, sequence, backup_dbname):  ##   查询回滚语句的表格

    port_a = int(port)
    connection = pymysql.connect(host=host, port=port_a, user=user, password=password, db=backup_dbname, charset="utf8",
                                 cursorclass=pymysql.cursors.DictCursor)
    connection1 = pymysql.connect(host=host, port=port_a, user=user, password=password, db=backup_dbname,
                                  charset="utf8",
                                  cursorclass=pymysql.cursors.DictCursor)

    try:
        with connection.cursor() as cursor:

            sql = " select  tablename   from  {0}.{1}  where opid_time ='{2}' ;".format(backup_dbname,  '$_$inception_backup_information$_$',sequence)
            cursor.execute(sql)
            result = cursor.fetchone()
            connection.commit()
            connection.close()
        table = result['tablename']

        try:
            with connection1.cursor() as cursor1:
                sql = " select rollback_statement  from  {0}.{1}  where opid_time = '{2}' ;".format(backup_dbname, table,sequence)
                cursor1.execute(sql)
                result1 = cursor1.fetchone()
github LMFrank / CrawlerProject / fangtianxia_scrapy_redis / fangtianxia_scrapy / pipelines.py View on Github external
def from_settings(cls, settings):
        db_params = dict(
            host=settings['MYSQL_HOST'],
            database=settings['MYSQL_database'],
            user=settings['MYSQL_USER'],
            passwd=settings['MYSQL_PASSWORD'],
            port=settings['MYSQL_PORT'],
            charset='utf8mb4',
            use_unicode=True,
            cursorclass=pymysql.cursors.DictCursor
        )
        dbpool = adbapi.ConnectionPool('pymysql', **db_params)
        return cls(dbpool)
github ycg / mysql_web / tools_new / mysql_processlist_monitor.py View on Github external
def get_mysql_connection(host_name, port=3306, user="", password=""):
    if (connection_pools.get(host_name) == None):
        pool = PooledDB(creator=pymysql, mincached=2, maxcached=4, maxconnections=5,
                        host=host_name, port=port, user=user, passwd=password,
                        use_unicode=False, charset="utf8", cursorclass=pymysql.cursors.DictCursor, reset=False, autocommit=True)
        connection_pools[host_name] = pool
    return connection_pools[host_name].connection()
github magneticstain / Inquisition / lib / inquisit / Inquisit.py View on Github external
# check if connection already exists
        try:
            if self.inquisitionDbHandle:
                self.inquisitionDbHandle.close()
        except AttributeError:
            # sometimes the above statement does fail properly when inquisitionDbHandle == None
            # this is harmless; see Issue #66
            pass

        # regenerate conn
        self.inquisitionDbHandle = pymysql.connect(host=self.cfg['mysql_database']['db_host'],
                                                   port=int(self.cfg['mysql_database']['db_port']),
                                                   user=self.cfg['mysql_database']['db_user'],
                                                   password=self.cfg['mysql_database']['db_pass'],
                                                   db=self.cfg['mysql_database']['db_name'],
                                                   charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor)
        if self.inquisitionDbHandle:
            self.lgr.debug('database connection established [ SUCCESSFULLY ] for main inquisition database :: [ '
                           + self.cfg['mysql_database']['db_host'] + ':' + self.cfg['mysql_database']['db_port'] + ' ]')

            return True
        else:
            return False
github MartinThoma / hwrt / hwrt / datasets / __init__.py View on Github external
def insert_recording(hw):
    """Insert recording `hw` into database."""
    mysql = utils.get_mysql_cfg()
    connection = pymysql.connect(
        host=mysql["host"],
        user=mysql["user"],
        passwd=mysql["passwd"],
        db=mysql["db"],
        charset="utf8mb4",
        cursorclass=pymysql.cursors.DictCursor,
    )
    try:
        cursor = connection.cursor()
        sql = (
            "INSERT INTO `wm_raw_draw_data` ("
            "`user_id`, "
            "`data`, "
            "`md5data`, "
            "`creation_date`, "
            "`device_type`, "
            "`accepted_formula_id`, "
            "`secret`, "
            "`ip`, "
            "`segmentation`, "
            "`internal_id`, "
            "`description` "
github binderclip / code-snippets-python / packages / mysql_snippets / batch_insert_performance.py View on Github external
def main():
    connection = pymysql.connect(host='localhost',
                                 user='root',
                                 password='',
                                 db='testdb',
                                 charset='utf8mb4',
                                 cursorclass=pymysql.cursors.DictCursor)

    start = int(time.time())
    insert_to_mysql(connection, 10000, start)