Python pymysql.cursors.Cursor() Examples

The following are 8 code examples of pymysql.cursors.Cursor(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pymysql.cursors , or try the search function .
Example #1
Source File: test_issues.py    From ServerlessCrawler-VancouverRealState with MIT License 6 votes vote down vote up
def test_issue_491(self):
        """ Test warning propagation """
        conn = pymysql.connect(charset="utf8", **self.databases[0])

        with warnings.catch_warnings():
            # Ignore all warnings other than pymysql generated ones
            warnings.simplefilter("ignore")
            warnings.simplefilter("error", category=pymysql.Warning)

            # verify for both buffered and unbuffered cursor types
            for cursor_class in (cursors.Cursor, cursors.SSCursor):
                c = conn.cursor(cursor_class)
                try:
                    c.execute("SELECT CAST('124b' AS SIGNED)")
                    c.fetchall()
                except pymysql.Warning as e:
                    # Warnings should have errorcode and string message, just like exceptions
                    self.assertEqual(len(e.args), 2)
                    self.assertEqual(e.args[0], 1292)
                    self.assertTrue(isinstance(e.args[1], text_type))
                else:
                    self.fail("Should raise Warning")
                finally:
                    c.close() 
Example #2
Source File: map-string-ids.py    From dipper with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def get_xref_protein_gene_rel(cursor: Cursor, protein: str,
                              database: str, config: dict, taxon: str) -> str:
    select_database(cursor, database)
    find_gene_query = \
        config['queries']['protein2xref'].format("{}.{}".format(taxon, protein))
    cursor.execute(find_gene_query)
    query_res = cursor.fetchall()

    if len(query_res) > 1:
        logger.warn("Ambiguous protein to gene "
                    "mapping for {} {}".format(protein, query_res))
        gene = None
    elif len(query_res) == 0:
        logger.warn("No mapping for {}".format(protein))
        gene = None
    else:
        gene = query_res[0][1]
    return gene 
Example #3
Source File: test_issues.py    From satori with Apache License 2.0 6 votes vote down vote up
def test_issue_491(self):
        """ Test warning propagation """
        conn = pymysql.connect(charset="utf8", **self.databases[0])

        with warnings.catch_warnings():
            # Ignore all warnings other than pymysql generated ones
            warnings.simplefilter("ignore")
            warnings.simplefilter("error", category=pymysql.Warning)

            # verify for both buffered and unbuffered cursor types
            for cursor_class in (cursors.Cursor, cursors.SSCursor):
                c = conn.cursor(cursor_class)
                try:
                    c.execute("SELECT CAST('124b' AS SIGNED)")
                    c.fetchall()
                except pymysql.Warning as e:
                    # Warnings should have errorcode and string message, just like exceptions
                    self.assertEqual(len(e.args), 2)
                    self.assertEqual(e.args[0], 1292)
                    self.assertTrue(isinstance(e.args[1], text_type))
                else:
                    self.fail("Should raise Warning")
                finally:
                    c.close() 
Example #4
Source File: test_issues.py    From aws-servicebroker with Apache License 2.0 6 votes vote down vote up
def test_issue_491(self):
        """ Test warning propagation """
        conn = pymysql.connect(charset="utf8", **self.databases[0])

        with warnings.catch_warnings():
            # Ignore all warnings other than pymysql generated ones
            warnings.simplefilter("ignore")
            warnings.simplefilter("error", category=pymysql.Warning)

            # verify for both buffered and unbuffered cursor types
            for cursor_class in (cursors.Cursor, cursors.SSCursor):
                c = conn.cursor(cursor_class)
                try:
                    c.execute("SELECT CAST('124b' AS SIGNED)")
                    c.fetchall()
                except pymysql.Warning as e:
                    # Warnings should have errorcode and string message, just like exceptions
                    self.assertEqual(len(e.args), 2)
                    self.assertEqual(e.args[0], 1292)
                    self.assertTrue(isinstance(e.args[1], text_type))
                else:
                    self.fail("Should raise Warning")
                finally:
                    c.close() 
Example #5
Source File: test_issues.py    From scalyr-agent-2 with Apache License 2.0 6 votes vote down vote up
def test_issue_491(self):
        """ Test warning propagation """
        conn = pymysql.connect(charset="utf8", **self.databases[0])

        with warnings.catch_warnings():
            # Ignore all warnings other than pymysql generated ones
            warnings.simplefilter("ignore")
            warnings.simplefilter("error", category=pymysql.Warning)

            # verify for both buffered and unbuffered cursor types
            for cursor_class in (cursors.Cursor, cursors.SSCursor):
                c = conn.cursor(cursor_class)
                try:
                    c.execute("SELECT CAST('124b' AS SIGNED)")
                    c.fetchall()
                except pymysql.Warning as e:
                    # Warnings should have errorcode and string message, just like exceptions
                    self.assertEqual(len(e.args), 2)
                    self.assertEqual(e.args[0], 1292)
                    self.assertTrue(isinstance(e.args[1], text_type))
                else:
                    self.fail("Should raise Warning")
                finally:
                    c.close() 
Example #6
Source File: test_issues.py    From planespotter with MIT License 6 votes vote down vote up
def test_issue_491(self):
        """ Test warning propagation """
        conn = pymysql.connect(charset="utf8", **self.databases[0])

        with warnings.catch_warnings():
            # Ignore all warnings other than pymysql generated ones
            warnings.simplefilter("ignore")
            warnings.simplefilter("error", category=pymysql.Warning)

            # verify for both buffered and unbuffered cursor types
            for cursor_class in (cursors.Cursor, cursors.SSCursor):
                c = conn.cursor(cursor_class)
                try:
                    c.execute("SELECT CAST('124b' AS SIGNED)")
                    c.fetchall()
                except pymysql.Warning as e:
                    # Warnings should have errorcode and string message, just like exceptions
                    self.assertEqual(len(e.args), 2)
                    self.assertEqual(e.args[0], 1292)
                    self.assertTrue(isinstance(e.args[1], text_type))
                else:
                    self.fail("Should raise Warning")
                finally:
                    c.close() 
Example #7
Source File: map-string-ids.py    From dipper with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def select_database(cursor: Cursor, database: str) -> None:
    query = "USE {};".format(database)
    cursor.execute(query) 
Example #8
Source File: map-string-ids.py    From dipper with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_deprecated_protein_gene_rel(cursor: Cursor, protein: str,
                                    database: str, config: dict) -> str:
    select_database(cursor, database)
    find_db_query = config['queries']['id_mapping'].format(protein)
    cursor.execute(find_db_query)
    old_db = cursor.fetchall()
    try:
        select_database(cursor, old_db[0][0])
    except pymysql.err.InternalError:
        return ''
    except IndexError:
        return ''

    find_gene_query = config['queries']['protein2gene'].format(protein)
    try:
        cursor.execute(find_gene_query)
    except pymysql.err.ProgrammingError:
        find_gene_query = config['queries']['p2g_two'].format(protein)
        cursor.execute(find_gene_query)
    query_res = cursor.fetchall()
    if len(query_res) > 1:
        raise ValueError("Ambiguous protein to gene "
                         "mapping for {} {}".format(protein, query_res))
    elif len(query_res) == 0:
        raise ValueError("No mapping for protein {}".format(protein))
    return query_res[0][0]