Beispiel #1
0
 def RAISE_APPLICATION_ERROR(error_number, message):
     error_number = extract_value(error_number)
     message = extract_value(message)
     message = f"ORA{error_number}: {message}"
     PLGLOBALS.SQLCODE = m(error_number)
     PLGLOBALS.SQLERRM = m(message)
     raise _PL_EXCEPTION
Beispiel #2
0
 def REPLACE(char, search, replacement=None):
     if replacement is None:
         replacement = NULL()
     if ISNULL(char) or ISNULL(search):
         return char
     char: str = extract_value(char)
     search: str = extract_value(search)
     if not ISNULL(replacement):
         replacement = extract_value(replacement)
     else:
         replacement = ""
     value = char.replace(search, replacement)
     return m(value)
Beispiel #3
0
 def SUBSTR(string, position, length=None):
     if ISNULL(string) or ISNULL(position):
         return NULL()
     string = extract_value(string)
     position = extract_value(position)
     length = extract_value(length)
     if position == 0:
         position = 1
     if position > 0:
         position -= 1
     if length is not None:
         value = string[position:position+length]
     else:
         value = string[position:]
     return m(value)
Beispiel #4
0
 def LOWER(string):
     if ISNULL(string):
         return NULL()
     string = extract_value(string)
     string = str(string)
     string = string.lower()
     return m(string)
Beispiel #5
0
 def UPPER(string):
     if ISNULL(string):
         return NULL()
     string = extract_value(string)
     string = str(string)
     string = string.upper()
     return m(string)
Beispiel #6
0
 def CHR(n):
     if ISNULL(n):
         return NULL()
     value = extract_value(n)
     if isinstance(value, str):
         value = int(value)
     value = chr(value)
     return m(value)
Beispiel #7
0
 def TO_NUMBER(value):
     if ISNULL(value):
         return NULL()
     value = extract_value(value)
     value = float(value)
     if value.is_integer():
         value = int(value)
     return m(value)
Beispiel #8
0
 def padstr(to_left: bool, value, count, fill):
     if ISNULL(value) or ISNULL(count) or ISNULL(fill) or count <= m(0):
         return NULL()
     if fill is None:
         fill = m(' ')
     value = extract_value(value)
     count = extract_value(count)
     fill = extract_value(fill)
     valuelen = len(value)
     if count <= valuelen:
         value = value[:count]
         return value
     charsleft = count - valuelen
     filllen = len(fill)
     charsfill = fill * int(charsleft / filllen)
     charsfill += fill[:(charsleft % filllen)]
     if to_left:
         value = charsfill + value
     else:
         value = value + charsfill
     return value
Beispiel #9
0
 def execute(self, sql: str, params=None):
     sql = extract_value(sql)
     if not params:
         params = {}
     for key in _sqls_mocked:
         if not re.search(key, sql, re.IGNORECASE):
             continue
         self.mocksql = _sqls_mocked[key]
         del _sqls_mocked[key]
         self.mocksql.cursor = self
         self.rowcount = self.mocksql.rowcount
         return
     raise RuntimeError("unable to find valid sql mock")
Beispiel #10
0
 def OPEN(self, cursor_params: list, the_locals: Dict):
     params = {}
     for i, param_name in enumerate(self.cursor_params_names):
         value = cursor_params[i]
         value = extract_value(value)
         params[f'"{param_name}"'] = value
     for sql_bind in self.sql_binds:
         if sql_bind in self.cursor_params_names:
             continue
         if not sql_bind in the_locals:
             raise RuntimeError(f"expected variable {sql_bind} to be defined in the locals")
         value = the_locals[sql_bind]
         value = extract_value(value)
         if not isinstance(value, PLRECORD):
             params[f'"{sql_bind}"'] = value
             continue
         for key in value.keys():
             record_bind = f"{sql_bind}.{key}"
             field = value.__getattr__(key)
             field = extract_value(field)
             params[f'"{record_bind}"'] = field
     self.cursor = PLCURSOR.getConn().cursor()
     self.cursor.execute(self.sql, params)
     PLCURSOR.rowcount = self.cursor.rowcount
Beispiel #11
0
 def __setitem__(self, index, value):
     index = extract_value(index)
     index -= 1
     self._safe_access_index(index)
     self.inner_list[index] = value
Beispiel #12
0
 def NEXT(self, index):
     index = extract_value(index)
     if index >= len(self.inner_list):
         return NULL()
     return m(index + 1)
Beispiel #13
0
 def PRIOR(self, index):
     index = extract_value(index)
     if index == 1:
         return NULL()
     return m(index - 1)
Beispiel #14
0
 def MOD(n, mod):
     n = extract_value(n)
     mod = extract_value(mod)
     return m(n % mod)
Beispiel #15
0
 def __getitem__(self, index):
     index = extract_value(index)
     index -= 1
     self._safe_access_index(index)
     return self.inner_list[index]
Beispiel #16
0
 def LENGTH(string):
     if ISNULL(string):
         return NULL()
     string = extract_value(string)
     return len(string)
Beispiel #17
0
 def INSTR(st, sub):
     st: str = extract_value(st)
     sub: str = extract_value(sub)
     index = st.find(sub)
     return m(index + 1)
Beispiel #18
0
 def __init__(self, sql):
     sql = extract_value(sql)
     self.datasource: Deque[List] = None
     self.cursor = None
     self.rowcount = None
     _sqls_mocked[sql] = self
Beispiel #19
0
 def RTRIM(value):
     if ISNULL(value):
         return NULL()
     value = extract_value(value)
     value = value.rstrip(" ")
     return m(value)
Beispiel #20
0
 def EXISTS(self, index):
     index = extract_value(index)
     index -= 1
     return index >= 0 and index < len(self.inner_list)
Beispiel #21
0
 def TO_CHAR(value):
     if ISNULL(value):
         return NULL()
     value = extract_value(value)
     value = str(value)
     return m(value)