X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_ro%2Fdb_base.py;h=26e4c002c96d92eb724c0125512cd4815055f0e6;hb=a92a0eaaf370c626b442863f4127cd11fc64754c;hp=10f94045d9e5e1cf32ea2eecaaf89d032e572d66;hpb=2c290ca4088492a3c32bb6ab218d0004da68f6ea;p=osm%2FRO.git diff --git a/osm_ro/db_base.py b/osm_ro/db_base.py index 10f94045..26e4c002 100644 --- a/osm_ro/db_base.py +++ b/osm_ro/db_base.py @@ -265,6 +265,8 @@ class db_base(): ''' if data==None: return 'Null' + elif isinstance(data[1], str): + return json.dumps(data) else: return json.dumps(str(data)) @@ -277,6 +279,8 @@ class db_base(): ''' if data[1]==None: return str(data[0]) + "=Null" + elif isinstance(data[1], str): + return str(data[0]) + '=' + json.dumps(data[1]) else: return str(data[0]) + '=' + json.dumps(str(data[1])) @@ -289,24 +293,10 @@ class db_base(): ''' if data[1]==None: return str(data[0]) + " is Null" - -# if type(data[1]) is tuple: #this can only happen in a WHERE_OR clause -# text =[] -# for d in data[1]: -# if d==None: -# text.append(str(data[0]) + " is Null") -# continue -# out=str(d) -# if "'" not in out: -# text.append( str(data[0]) + "='" + out + "'" ) -# elif '"' not in out: -# text.append( str(data[0]) + '="' + out + '"' ) -# else: -# text.append( str(data[0]) + '=' + json.dumps(out) ) -# return " OR ".join(text) - - out=str(data[1]) - return str(data[0]) + '=' + json.dumps(out) + elif isinstance(data[1], str): + return str(data[0]) + '=' + json.dumps(data[1]) + else: + return str(data[0]) + '=' + json.dumps(str(data[1])) def __tuple2db_format_where_not(self, data): '''Compose the needed text for a SQL WHERE(not). parameter 'data' is a pair tuple (A,B), @@ -317,8 +307,10 @@ class db_base(): ''' if data[1]==None: return str(data[0]) + " is not Null" - out=str(data[1]) - return str(data[0]) + '<>' + json.dumps(out) + elif isinstance(data[1], str): + return str(data[0]) + '<>' + json.dumps(data[1]) + else: + return str(data[0]) + '<>' + json.dumps(str(data[1])) def __remove_quotes(self, data): '''remove single quotes ' of any string content of data dictionary''' @@ -344,7 +336,31 @@ class db_base(): self.logger.debug(cmd) self.cur.execute(cmd) return self.cur.rowcount - + + def _new_uuid(self, root_uuid=None, used_table=None, created_time=0): + """ + Generate a new uuid. It DOES NOT begin or end the transaction, so self.con.cursor must be created + :param root_uuid: master uuid of the transaction + :param used_table: the table this uuid is intended for + :param created_time: time of creation + :return: the created uuid + """ + + uuid = str(myUuid.uuid1()) + # defining root_uuid if not provided + if root_uuid is None: + root_uuid = uuid + if created_time: + created_at = created_time + else: + created_at = time.time() + # inserting new uuid + cmd = "INSERT INTO uuids (uuid, root_uuid, used_at, created_at) VALUES ('{:s}','{:s}','{:s}', {:f})".format( + uuid, root_uuid, used_table, created_at) + self.logger.debug(cmd) + self.cur.execute(cmd) + return uuid + def _new_row_internal(self, table, INSERT, add_uuid=False, root_uuid=None, created_time=0): ''' Add one row into a table. It DOES NOT begin or end the transaction, so self.con.cursor must be created Attribute