47 lines
876 B
Python
47 lines
876 B
Python
from ...core.Guid import Guid
|
|
from .Normalization import Normalization
|
|
|
|
class SQLExpression:
|
|
|
|
@staticmethod
|
|
def sqlescape(parm : str):
|
|
return parm.replace("'", "\\'")
|
|
|
|
@staticmethod
|
|
def normalize_parm(parm : str):
|
|
query = ""
|
|
if parm == None:
|
|
query += "NULL"
|
|
elif isinstance(parm, Guid):
|
|
gid = None
|
|
if parm is not None:
|
|
gid = "'" + Normalization.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 to_string(parm):
|
|
return SQLExpression.normalize_parm(parm)
|
|
|
|
@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 |