From 503499a43210832cbe224900b8954064a21bc74b Mon Sep 17 00:00:00 2001 From: Jiri 'Ghormoon' Novak Date: Wed, 19 Oct 2022 05:34:45 +0200 Subject: [PATCH] Fix AddObject - allow to pass None as NULL --- rtapi/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rtapi/__init__.py b/rtapi/__init__.py index c445ef9..2154521 100755 --- a/rtapi/__init__.py +++ b/rtapi/__init__.py @@ -142,7 +142,14 @@ def ObjectExistSTName(self, name, asset_no): def AddObject(self, name, server_type_id, asset_no, label): """Add new object to racktables""" - sql = "INSERT INTO Object (name,objtype_id,asset_no,label) VALUES ('%s',%d,'%s','%s')" % (name, server_type_id, asset_no, label) + if asset_no and label: + sql = "INSERT INTO Object (name,objtype_id,asset_no,label) VALUES ('%s',%d,'%s','%s')" % (name, server_type_id, asset_no, label) + elif asset_no: + sql = "INSERT INTO Object (name,objtype_id,asset_no,label) VALUES ('%s',%d,'%s',NULL)" % (name, server_type_id, asset_no) + elif label: + sql = "INSERT INTO Object (name,objtype_id,asset_no,label) VALUES ('%s',%d,NULL,'%s')" % (name, server_type_id, label) + else: + sql = "INSERT INTO Object (name,objtype_id,asset_no,label) VALUES ('%s',%d,NULL,NULL)" % (name, server_type_id) self.db_insert(sql) return self.db_fetch_lastid()