Mysql-Mysql auto_increment usage problems

Source: Internet
Author: User
When I create a table, I set the id to autoincrement. later I found that the id should start from 1, but the result is increased from 2. I am using C ++, the following is some of my code: SQL _-& gt; SetAutoCommit (0); if (SQL _-& gt; InsertUserLoginTable (id, & quot;)-1) {result & quot; registfaild1 & quot;} else {std: stringIDsql _-& gt; GetLastID (); mysqlc ++

When I create a table, I set the id to auto increment. later I found that the id should start from 1, but the result is increased from 2. I am using C ++, below is some of my code:

        sql_->SetAutoCommit(0);        if(sql_->InsertUserLoginTable(id,"") == -1)        {            result = "regist faild1";        }        else        {            std::string ID = sql_->GetLastID();            std::cout << "ID : " << ID << std::endl;            if (sql_->InsertLoginInfoTable(ID, "", "", "", IMEI, BTMAC) == -1)            {                result = "regist faild2";            }            else if (sql_->InsertUserInfoTable(ID, FaceID, NickName, "", "", "3") == -1)            {                result = "regist faild3";            }            else if (sql_->InsertUserRecordTable(ID, RegistIP) == -1)            {                result = "regist faild4";            }            else            {                result = "regist success";            }        }        if(result == "regist success")        {            sql_->Commit(0);        }        else        {            sql_->Commit(1);        }        sql_->SetAutoCommit(1);

Some of them are self-encapsulated methods, and some are as follows:

Void SetAutoCommit (int I)
{
SQL-> AutoCommit (I );
}

Int Commit (int I)
{
SQL-> CommitSQL (I );
}

Void AutoCommit (int I)
{
Mysql_autocommit (connection _, I );
}

Int CommitSQL (int I)
{
If (I = 1)
{
Mysql_rollback (connection _);
Return-1;
}
Else
{
Mysql_commit (connection _);
Return 0;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.