How to use the pymysql.InternalError 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 magneticstain / Inquisition / lib / anatomize / Anatomize.py View on Github external
def __init__(self, cfg, sentryClient=None):
        Inquisit.__init__(self, cfg, lgrName=__name__, sentryClient=sentryClient)

        self.lgr.info('loading Anatomize.py instance...')

        # load parsers and associated templates
        try:
            self.parserStore = self.fetchParsers()
            self.lgr.debug('loaded [ ' + str(len(self.parserStore)) + ' ] parsers into parser store')
        except (InternalError, ProgrammingError) as e:
            self.lgr.critical('could not fetch parsers from inquisition database :: [ ' + str(e) + ' ]')
            if Inquisit.sentryClient:
                Inquisit.sentryClient.captureException()

            exit(1)

        self.lgr.info('loading of Anatomize.py [ COMPLETE ]')
github linkedin / iris / src / iris / bin / sender.py View on Github external
if not mode:
        return

    # Don't track this for twilio as those are kept track of separately. Make
    # use of this for email, and, as a side effect of that for slack
    if mode in ('sms', 'call'):
        return

    session = db.Session()
    try:
        session.execute('''INSERT INTO `generic_message_sent_status` (`message_id`, `status`)
                           VALUES (:message_id, :status)
                           ON DUPLICATE KEY UPDATE `status` =  :status''',
                        {'message_id': message_id, 'status': status})
        session.commit()
    except (DataError, IntegrityError, InternalError):
        logger.exception('Failed setting message sent status for message %s', message)
    finally:
        session.close()
github fhamborg / news-please / newsplease / pipeline / pipelines.py View on Github external
'rss_title': item['rss_title'], }

        try:
            self.cursor.execute(self.insert_current, current_version_list)
            self.conn.commit()
            self.log.info("Article inserted into the database.")
        except (pymysql.err.OperationalError, pymysql.ProgrammingError, pymysql.InternalError,
                pymysql.IntegrityError, TypeError) as error:
            self.log.error("Something went wrong in commit: %s", error)

        # Move the old version from the CurrentVersion table to the ArchiveVersions table
        if old_version is not None:
            # Set descendant attribute
            try:
                old_version_list['descendant'] = self.cursor.lastrowid
            except (pymysql.err.OperationalError, pymysql.ProgrammingError, pymysql.InternalError,
                    pymysql.IntegrityError, TypeError) as error:
                self.log.error("Something went wrong in id query: %s", error)

            # Delete the old version of the article from the CurrentVersion table
            try:
                self.cursor.execute(self.delete_from_current, old_version_list['db_id'])
                self.conn.commit()
            except (pymysql.err.OperationalError, pymysql.ProgrammingError, pymysql.InternalError,
                    pymysql.IntegrityError, TypeError) as error:
                self.log.error("Something went wrong in delete: %s", error)

            # Add the old version to the ArchiveVersion table
            try:
                self.cursor.execute(self.insert_archive, old_version_list)
                self.conn.commit()
                self.log.info("Moved old version of an article to the archive.")
github magneticstain / Inquisition / lib / anatomize / Anatomize.py View on Github external
# create connection to inquisition db
        try:
            self.inquisitionDbHandle = self.generateInquisitionDbConnection(cfg['mysql_database']['db_user'],
                                                                            cfg['mysql_database']['db_pass'],
                                                                            cfg['mysql_database']['db_name'],
                                                                            cfg['mysql_database']['db_host'],
                                                                            int(cfg['mysql_database']['db_port']))
            self.lgr.debug('database connection established for main inquisition database :: [ '
                           + cfg['mysql_database']['db_host'] + ':' + cfg['mysql_database']['db_port'] + ' ]')
            self.lgr.info('all database connections established [ SUCCESSFULLY ]')

            # load parsers and associated templates (IN PROGRESS)
            self.parserStore = self.fetchParsers()
            self.lgr.debug('loaded [ ' + str(len(self.parserStore)) + ' ] parsers into parser store')
        except (pymysql.InternalError, pymysql.ProgrammingError) as e:
            self.lgr.critical('could not fetch parsers from inquisition database :: [ ' + str(e) + ' ]')

            exit(2)
        except pymysql.OperationalError as e:
            self.lgr.critical('could not create database connection :: [ ' + str(e) + ' ]')

            exit(2)
github fhamborg / news-please / newsplease / __main__.py View on Github external
print("Resetting database...")

        try:
            # initialize DB connection
            self.conn = pymysql.connect(host=self.mysql["host"],
                                        port=self.mysql["port"],
                                        db=self.mysql["db"],
                                        user=self.mysql["username"],
                                        passwd=self.mysql["password"])
            self.cursor = self.conn.cursor()

            self.cursor.execute("TRUNCATE TABLE CurrentVersions")
            self.cursor.execute("TRUNCATE TABLE ArchiveVersions")
            self.conn.close()
        except (pymysql.err.OperationalError, pymysql.ProgrammingError, pymysql.InternalError,
                pymysql.IntegrityError, TypeError) as error:
            self.log.error("Database reset error: %s", error)
github frappe / erpnext / erpnext / patches / v5_4 / cleanup_journal_entry.py View on Github external
def execute():
	frappe.reload_doctype("Journal Entry Account")
	for doctype, fieldname in (
		("Sales Order", "against_sales_order"),
		("Purchase Order", "against_purchase_order"),
		("Sales Invoice", "against_invoice"),
		("Purchase Invoice", "against_voucher"),
		("Journal Entry", "against_jv"),
		("Expense Claim", "against_expense_claim"),
	):
		try:
			frappe.db.sql("""update `tabJournal Entry Account`
				set reference_type=%s, reference_name={0} where ifnull({0}, '') != ''
			""".format(fieldname), doctype)
		except InternalError:
			# column not found
			pass
github frappe / frappe / frappe / model / db_schema.py View on Github external
current_col = self.current_columns.get(col.fieldname, {})
				if not current_col:
					continue
				current_type = self.current_columns[col.fieldname]["type"]
				current_length = re.findall('varchar\(([\d]+)\)', current_type)
				if not current_length:
					# case when the field is no longer a varchar
					continue
				current_length = current_length[0]
				if cint(current_length) != cint(new_length):
					try:
						# check for truncation
						max_length = frappe.db.sql("""select max(char_length(`{fieldname}`)) from `tab{doctype}`"""\
							.format(fieldname=col.fieldname, doctype=self.doctype))

					except pymysql.InternalError as e:
						if e.args[0] == ER.BAD_FIELD_ERROR:
							# Unknown column 'column_name' in 'field list'
							continue

						else:
							raise

					if max_length and max_length[0][0] and max_length[0][0] > new_length:
						if col.fieldname in self.columns:
							self.columns[col.fieldname].length = current_length

						frappe.msgprint(_("Reverting length to {0} for '{1}' in '{2}'; Setting the length as {3} will cause truncation of data.")\
							.format(current_length, col.fieldname, self.doctype, new_length))
github fhamborg / news-please / newsplease / __main__.py View on Github external
print("Resetting database...")

        try:
            # initialize DB connection
            self.conn = pymysql.connect(host=self.mysql["host"],
                                        port=self.mysql["port"],
                                        db=self.mysql["db"],
                                        user=self.mysql["username"],
                                        passwd=self.mysql["password"])
            self.cursor = self.conn.cursor()

            self.cursor.execute("TRUNCATE TABLE CurrentVersions")
            self.cursor.execute("TRUNCATE TABLE ArchiveVersions")
            self.conn.close()
        except (pymysql.err.OperationalError, pymysql.ProgrammingError, pymysql.InternalError,
                pymysql.IntegrityError, TypeError) as error:
            self.log.error("Database reset error: %s", error)
github Tianny / incepiton-mysql / app / inception.py View on Github external
cur = None
    sql_content = sql_content.encode('utf-8').decode('utf-8')

    try:
        conn = pymysql.connect(
            host=host,
            user=user,
            password=password,
            db=db_in,
            port=port,
            charset='utf8mb4'
        )
        cur = conn.cursor()
        cur.execute(sql_content)
        result = cur.fetchall()
    except pymysql.InternalError as e:
        print("Mysql Error %d: %s" % (e.args[0], e.args[1]))
    finally:
        if cur is not None:
            cur.close()
        if conn is not None:
            conn.close()

    return result
github cr0hn / golismero-legacy / tools / sqlmap / plugins / dbms / mysql / connector.py View on Github external
def connect(self):
        self.initConnection()

        try:
            self.connector = pymysql.connect(host=self.hostname, user=self.user, passwd=self.password, db=self.db, port=self.port, connect_timeout=conf.timeout, use_unicode=True)
        except (pymysql.OperationalError, pymysql.InternalError), msg:
            raise SqlmapConnectionException(msg[1])

        self.initCursor()
        self.printConnected()