diff --git a/drivers/common/include/orm/drivers/sqlfield.hpp b/drivers/common/include/orm/drivers/sqlfield.hpp index 9ae44926b..df415ed71 100644 --- a/drivers/common/include/orm/drivers/sqlfield.hpp +++ b/drivers/common/include/orm/drivers/sqlfield.hpp @@ -101,7 +101,10 @@ namespace Orm::Drivers /*! Set the field QVariant value metatype (for invalid values only). */ void setMetaType(QMetaType metaType); - /*! Determine whether a field is required. */ + /*! Determine whether a field is SQL nullable (NULL in the table definition). */ + inline bool isNullColumn() const noexcept; + + /*! Determine whether a field is required (!NULL in the table definition). */ inline bool isRequired() const noexcept; /*! Set the required field status. */ inline void setRequired(bool required) noexcept; @@ -251,6 +254,12 @@ namespace Orm::Drivers return m_metaType; } + bool SqlField::isNullColumn() const noexcept + { + // Very confusing, I can't do anything about it to have compatible API 😔 + return m_requiredStatus == Optional; + } + bool SqlField::isRequired() const noexcept { return m_requiredStatus == Required; diff --git a/drivers/common/include/orm/drivers/sqlrecord.hpp b/drivers/common/include/orm/drivers/sqlrecord.hpp index 2d9dcfa38..6c46c558d 100644 --- a/drivers/common/include/orm/drivers/sqlrecord.hpp +++ b/drivers/common/include/orm/drivers/sqlrecord.hpp @@ -66,6 +66,11 @@ namespace Orm::Drivers /*! Set the value of the field with the field name to the given value. */ void setValue(const QString &name, QVariant &&value); + /*! Determine whether a field is SQL nullable (NULL in the table definition). */ + bool isNullColumn(size_type index) const; + /*! Determine whether a field is SQL nullable (NULL in the table definition). */ + bool isNullColumn(const QString &name) const; + /*! Determine whether the field at the given index is NULL. */ bool isNull(size_type index) const; /*! Determine whether the field with the given field name is NULL. */ diff --git a/drivers/common/src/orm/drivers/sqlrecord.cpp b/drivers/common/src/orm/drivers/sqlrecord.cpp index 1283ea597..38f5fbec7 100644 --- a/drivers/common/src/orm/drivers/sqlrecord.cpp +++ b/drivers/common/src/orm/drivers/sqlrecord.cpp @@ -93,6 +93,19 @@ void SqlRecord::setValue(const QString &name, QVariant &&value) setValue(indexOf(name), std::move(value)); } +bool SqlRecord::isNullColumn(const size_type index) const +{ + // Throw the OutOfRangeError exception if the record doesn't contain an index + throwIfNotContains(index); + + return m_fields[index].isNullColumn(); +} + +bool SqlRecord::isNullColumn(const QString &name) const +{ + return isNullColumn(indexOf(name)); +} + bool SqlRecord::isNull(const size_type index) const { // Throw the OutOfRangeError exception if the record doesn't contain an index