sql= "INSERT INTO t_outlet (id,parentId) VALUES (null,?),"; for (int i =0; i <7; ++i) { sql+= " (null,?),"; } sql.remove(sql.length() -1, 1); for (int i =0; i <8; ++i) { m_pDb->setSqlParam(dbID); } if (m_pDb->exec(sql.toStdWString().c_str()) || m_pDb->changes() !=8) { m_lastErrorString = m_pDb->getLastError(); return-1; }
替换
先删除,后插入,key 会有增长
The idea of the REPLACE statement is that when a UNIQUE or PRIMARY KEY constraint violation occurs, it does the following:
First, delete the existing row that causes a constraint violation. Second, insert a new row. In the second step, if any constraint violation e.g., NOT NULL constraint occurs, the REPLACE statement will abort the action and roll back the transaction.