addrecord: a small fix that should make add record a bit more robust

This commit is contained in:
Peinthor Rene
2015-01-30 19:47:36 +01:00
parent 78df7275fe
commit d0f3de3927

View File

@@ -565,24 +565,32 @@ QString DBBrowserDB::emptyInsertStmt(const sqlb::Table& t, int pk_value) const
QStringList vals;
QStringList fields;
foreach(sqlb::FieldPtr f, t.fields()) {
if( f->primaryKey() && f->isInteger() )
{
fields << f->name();
if(pk_value != -1)
vals << QString::number(pk_value);
else
if(f->primaryKey()) {
if(f->isInteger())
{
if(f->notnull())
{
int64_t maxval = this->max(t, f);
vals << QString::number(maxval + 1);
}
fields << f->name();
if(pk_value != -1)
vals << QString::number(pk_value);
else
{
vals << "NULL";
if(f->notnull())
{
int64_t maxval = this->max(t, f);
vals << QString::number(maxval + 1);
}
else
{
vals << "NULL";
}
}
}
else
{
fields << f->name();
vals << "''";
}
} else if(f->notnull() && f->defaultValue().length() == 0) {
fields << f->name();