INSERT INTO mytable (id, field1, field2....) VALUES (NULL, f1val, f2val);
INSERT INTO mytable (field1, field2....) VALUES (f1val, f2val);
в .h // возвращает уникальный номер отсутствующий в данном поле в таблице (имя базы, имя таблицы, поле с кодом(int)) int zSerial(QString baseName, QString tableName, QString fieldName);в .cppint ZDB::zSerial(QString baseName, QString tableName, QString fieldName){ int serial; QSqlDatabase *db = QSqlDatabase::database( baseName, TRUE ); QSqlQuery query(db); query.exec("SELECT min("+ fieldName +") FROM "+ tableName); if(!query.next()) { serial = 1; return serial; } if (query.value(0).toInt() >1 ) { serial = 1; return serial; } else { bool MaX = true; int first=0; int next =0; query.exec("SELECT "+ fieldName +" FROM "+ tableName +" ORDER BY "+ fieldName); query.next(); first = query.value(0).toInt(); while (query.next()) { next = query.value(0).toInt(); if (next - first > 1) { serial = first + 1; MaX = false; break; } first = next; } if (MaX) { query.exec("SELECT max("+ fieldName +") FROM "+ tableName); if (query.next()) { serial = query.value(0).toInt() + 1; } else { serial = 1; } } return serial; }}