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 7702691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:17:05+00:00 2026-05-31T23:17:05+00:00

I cannot be sure whether the ids generated is continously,if not,is there any otherway

  • 0

I cannot be sure whether the ids generated is continously,if not,is there any otherway to get them?

class BaseDao(object):

    def __init__(self,pooldb):
        self.pooldb = pooldb

    def insertmany(self,sql,args):
        conn,cur = None,None
        try:
            conn = pooldb.dedicated_connection()
            cur = conn.cursor()
            num=cur.executemany(sql,args)
            if num <= 0:
                raise Exception("insert failure with num equals zero")
            lastrowid = int(cur.lastrowid)
            return [range(lastrowid - num + 1,lastrowid+1)]
        except:
            conn.rollback()
            traceback.print_exc()
            raise Exception("error happened when insert sql=%s args=%s " % (sql,str(args)))
        finally:
            if cur:
                cur.close()
            if conn:
                conn.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-31T23:17:07+00:00Added an answer on May 31, 2026 at 11:17 pm

    Every time mysqldb executes a query involving an auto-increment column, the last insert ID will be lost unless you read it before the next execute(), which with an executemany() you won’t be able to do.

    You would have to change the above code to something like:

    num = 0
    insert_ids = []
    
    for arg in args:
        num += cur.execute(sql, arg)
        insert_ids.append(cur.lastrowid)
    

    Since the Python module is really a thin layer over the MySQL API, here is some insight into how the mysql_insert_id() function works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not sure whether this is just a simple mistake of my code.
I am not sure whether I am missing something basic. But I am unable
I am not sure whether i am missing something here, but it seems i
I'm not sure whether I'm asking the question correctly, but I've been told SQL
I am pretty sure I cannot, but I would just like to double check
I'm sure this is a very simple fix but I cannot seem to find
I'm sure this question is asked a lot but I cannot find an answer
I'm sure this has been answered before, but I really cannot find it. I
I am sure what I want to do is very easy, yet I cannot
I am not professional programmer so i can not be sure about this.How many

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.