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;
}
}