]> granicus.if.org Git - icinga2/commitdiff
Use NULL instead of empty strings for name2 in the icinga_objects table
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 22 Jul 2014 08:28:23 +0000 (10:28 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 22 Jul 2014 08:29:09 +0000 (10:29 +0200)
fixes #6646

components/db_ido_mysql/idomysqlconnection.cpp
components/db_ido_pgsql/idopgsqlconnection.cpp

index c37058e11d08171e89c4ce5ee6faa32ed474df60..664a648c88e6dc2350378e04f2615d06371a8ab6 100644 (file)
@@ -421,9 +421,16 @@ void IdoMysqlConnection::InternalActivateObject(const DbObject::Ptr& dbobj)
        std::ostringstream qbuf;
 
        if (!dbref.IsValid()) {
-               qbuf << "INSERT INTO " + GetTablePrefix() + "objects (instance_id, objecttype_id, name1, name2, is_active) VALUES ("
-                     << static_cast<long>(m_InstanceID) << ", " << dbobj->GetType()->GetTypeID() << ", "
-                     << "'" << Escape(dbobj->GetName1()) << "', '" << Escape(dbobj->GetName2()) << "', 1)";
+               if (!dbobj->GetName2().IsEmpty()) {
+                       qbuf << "INSERT INTO " + GetTablePrefix() + "objects (instance_id, objecttype_id, name1, name2, is_active) VALUES ("
+                            << static_cast<long>(m_InstanceID) << ", " << dbobj->GetType()->GetTypeID() << ", "
+                            << "'" << Escape(dbobj->GetName1()) << "', '" << Escape(dbobj->GetName2()) << "', 1)";
+               } else {
+                       qbuf << "INSERT INTO " + GetTablePrefix() + "objects (instance_id, objecttype_id, name1, is_active) VALUES ("
+                            << static_cast<long>(m_InstanceID) << ", " << dbobj->GetType()->GetTypeID() << ", "
+                            << "'" << Escape(dbobj->GetName1()) << "', 1)";
+               }
+
                Query(qbuf.str());
                SetObjectID(dbobj, GetLastInsertID());
        } else {
index fa63eb3c427ac91464ceff7a921d31308d306b5f..917569fcf4be8d476db07611268a4f5d72002a0a 100644 (file)
@@ -419,9 +419,16 @@ void IdoPgsqlConnection::InternalActivateObject(const DbObject::Ptr& dbobj)
        std::ostringstream qbuf;
 
        if (!dbref.IsValid()) {
-               qbuf << "INSERT INTO " + GetTablePrefix() + "objects (instance_id, objecttype_id, name1, name2, is_active) VALUES ("
-                     << static_cast<long>(m_InstanceID) << ", " << dbobj->GetType()->GetTypeID() << ", "
-                     << "E'" << Escape(dbobj->GetName1()) << "', E'" << Escape(dbobj->GetName2()) << "', 1)";
+               if (!dbobj->GetName2().IsEmpty()) {
+                       qbuf << "INSERT INTO " + GetTablePrefix() + "objects (instance_id, objecttype_id, name1, name2, is_active) VALUES ("
+                             << static_cast<long>(m_InstanceID) << ", " << dbobj->GetType()->GetTypeID() << ", "
+                             << "E'" << Escape(dbobj->GetName1()) << "', E'" << Escape(dbobj->GetName2()) << "', 1)";
+               } else {
+                       qbuf << "INSERT INTO " + GetTablePrefix() + "objects (instance_id, objecttype_id, name1, is_active) VALUES ("
+                            << static_cast<long>(m_InstanceID) << ", " << dbobj->GetType()->GetTypeID() << ", "
+                            << "E'" << Escape(dbobj->GetName1()) << "', 1)";
+               }
+
                Query(qbuf.str());
                SetObjectID(dbobj, GetSequenceValue(GetTablePrefix() + "objects", "object_id"));
        } else {