获取当前数据库最大id的方法

int SYDBMgr::QueryMaxIdFromTable(DatabaseTable table)
{
	const QString& tableName = GetTableName(table);
	if(tableName == m_errorTableName)
		return -1;

	int id = -1;
	QString sql = QString("select max(id) id from %1").arg(tableName);
	bool bRet = m_sqlQuery.exec(sql);
	CheckQuery(bRet,m_sqlQuery);
	if(bRet)
	{
		if(m_sqlQuery.next())
			id = m_sqlQuery.record().value("id").toInt();
		else
			id = 0;
	}
	return id;
}

 

你可能感兴趣的:(mysql)