from .Guid import Guid class SQLExpression: @staticmethod def sqlescape(parm : str): return parm.replace("'", "\\'") @staticmethod def to_string(parm): query = "" if parm == None: query += "NULL" elif isinstance(parm, Guid): gid = None if parm is not None: gid = "mocha_normalize_uuid('" + parm.get_value() + "')" else: gid = "NULL" query += gid elif isinstance(parm, str): query += "'" + SQLExpression.sqlescape(str(parm)) + "'" else: query += str(parm) return query @staticmethod def array_to_string(parms): i = 0 query = '' for parm in parms: query += SQLExpression.to_string(parm) if i < len(parms) - 1: query += ", " i += 1 return query