Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 942001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:12:12+00:00 2026-05-15T22:12:12+00:00

For some reason whenever i run a query on the db cursor, it generates

  • 0

For some reason whenever i run a query on the db cursor, it generates two errors in its .messages list, is this a feature?

here is the code that runs the query, all the application does is open a connection to the db, run this once with a forced error, read the .messages, then exit

import MySQLdb

class dbobject:
    def __init__(self, dbhost, dbuser, dbpass, dbname):
        self.connection = MySQLdb.connect( user=dbuser, passwd=dbpass, host=dbhost, db=dbname )
        self.cursor = self.connection.cursor()

    def try_query(self, query, args=()):
        """ attempts to run a query, where
                query is the query to be run, with '%s' statements where the values should be, and
                args is a tuple of the values to go with the query"""
        try:
            if args == ():
                self.cursor.execute(query)
            else:
                self.cursor.execute(query, args)
            self.connection.commit()
        except:

            self.connection.rollback()

    def add_unit(self, name, version, credits):
        """ takes name, version, credits
                name is the name of the unit paper
                version is the unit version, and
                credits is how many credits its worth"""
        self.try_query("insert into dsfdf tbl_unit (unit_name, unit_version, unit_credits) values (%s,%s,%s)",(name,version,credits))

    def close(self):
        self.cursor.close()
        self.connection.close()


blah = dbobject(#####################)
blah.add_unit( "thing", "something", 6)
for i in blah.cursor.messages:
    print i
blah.close()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:12:13+00:00Added an answer on May 15, 2026 at 10:12 pm

    Perhaps you can post the message(s) you receive.

    mysql_insert_etc.py:22: Warning: Data
    truncated for column ‘val’ at row 1
    self.cursor.execute(query, args)
    (,
    (‘Warning’, 1265L, “Data truncated for
    column ‘val’ at row 1”))

    From the above (manufactured error) it appears that MySQLdb returns:

    1. the MySQL warning, and
    2. its own exception.

    Using the code below you can either suppress warnings, or have them raise exceptions.

    Raise an exception (slightly modified from this example):

    from warnings import catch_warnings, simplefilter
    
    def try_query(self, query, args=()):
        with catch_warnings():
            simplefilter('error', MySQLdb.Warning)
            try:
                if args == ():
                    self.cursor.execute(query)
                else:
                    self.cursor.execute(query, args)
                self.connection.commit()
            except MySQLdb.Error, e:
                self.connection.rollback()
                raise e
    

    Suppress warnings (from here):

    from warnings import filterwarnings
    
    filterwarnings('ignore', category=MySQLdb.Warning)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 460k
  • Answers 460k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use rank function or row_number (http://www.databasejournal.com/features/mssql/article.php/3661461/New-Ranking-Functions-within-SQL-Server-2005.htm) select rank() OVER (ORDER… May 15, 2026 at 11:42 pm
  • Editorial Team
    Editorial Team added an answer It's not possible to do this using just PHP, a… May 15, 2026 at 11:42 pm
  • Editorial Team
    Editorial Team added an answer Yes, IsWow64Process is annoyingly useless. It really means "is 32-bit… May 15, 2026 at 11:42 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.