Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/psqlparse-1.0rc7-py3.11-linux-x86_64.egg/psqlparse/nodes/primnodes.py: 67%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

100 statements  

1from .utils import build_from_item 

2from .nodes import Node 

3 

4 

5class RangeVar(Node): 

6 

7 def __init__(self, obj): 

8 """ 

9 Range variable, used in FROM clauses 

10 

11 Also used to represent table names in utility statements; there, 

12 the alias field is not used, and inhOpt shows whether to apply the 

13 operation recursively to child tables. 

14 """ 

15 

16 self.catalogname = obj.get('catalogname') 

17 self.schemaname = obj.get('schemaname') 

18 self.relname = obj.get('relname') 

19 self.inh_opt = obj.get('inhOpt') 

20 self.relpersistence = obj.get('relpersistence') 

21 self.alias = build_from_item(obj, 'alias') 

22 self.location = obj['location'] 

23 

24 def __repr__(self): 

25 return '<RangeVar (%s)>' % self.relname 

26 

27 def __str__(self): 

28 return '%s' % self.relname 

29 

30 def tables(self): 

31 components = [ 

32 getattr(self, name) for name in ('schemaname', 'relname') 

33 if getattr(self, name, None) is not None 

34 ] 

35 return {'.'.join(components)} 

36 

37 

38class JoinExpr(Node): 

39 """ 

40 For SQL JOIN expressions 

41 """ 

42 

43 def __init__(self, obj): 

44 self.jointype = obj.get('jointype') 

45 self.is_natural = obj.get('isNatural') 

46 self.larg = build_from_item(obj, 'larg') 

47 self.rarg = build_from_item(obj, 'rarg') 

48 self.using_clause = build_from_item(obj, 'usingClause') 

49 self.quals = build_from_item(obj, 'quals') 

50 self.alias = build_from_item(obj, 'alias') 

51 

52 def __repr__(self): 

53 return '<JoinExpr type=%s>' % self.jointype 

54 

55 def __str__(self): 

56 return '%s JOIN %s ON ()' % (self.larg, self.rarg) 

57 

58 def tables(self): 

59 return self.larg.tables() | self.rarg.tables() 

60 

61 

62class Alias(Node): 

63 

64 def __init__(self, obj): 

65 self.aliasname = obj.get('aliasname') 

66 self.colnames = build_from_item(obj, 'colnames') 

67 

68 def tables(self): 

69 return set() 

70 

71 

72class IntoClause(Node): 

73 

74 def __init__(self, obj): 

75 self._obj = obj 

76 

77 

78class Expr(Node): 

79 """ 

80 Expr - generic superclass for executable-expression nodes 

81 """ 

82 

83 

84class BoolExpr(Expr): 

85 

86 def __init__(self, obj): 

87 self.boolop = obj.get('boolop') 

88 self.args = build_from_item(obj, 'args') 

89 self.location = obj.get('location') 

90 

91 def tables(self): 

92 _tables = set() 

93 for item in self.args: 

94 _tables |= item.tables() 

95 return _tables 

96 

97 

98class SubLink(Expr): 

99 

100 def __init__(self, obj): 

101 self.sub_link_type = obj.get('subLinkType') 

102 self.sub_link_id = obj.get('subLinkId') 

103 self.testexpr = build_from_item(obj, 'testexpr') 

104 self.oper_name = build_from_item(obj, 'operName') 

105 self.subselect = build_from_item(obj, 'subselect') 

106 self.location = obj.get('location') 

107 

108 def tables(self): 

109 return self.subselect.tables() 

110 

111 

112class SetToDefault(Node): 

113 

114 def __init__(self, obj): 

115 self.type_id = obj.get('typeId') 

116 self.type_mod = obj.get('typeMod') 

117 self.collation = obj.get('collation') 

118 self.location = obj.get('location') 

119 

120 

121class CaseExpr(Node): 

122 

123 def __init__(self, obj): 

124 self.casetype = obj.get('casetype') 

125 self.casecollid = obj.get('casecollid') 

126 self.arg = build_from_item(obj, 'arg') 

127 self.args = build_from_item(obj, 'args') 

128 self.defresult = build_from_item(obj, 'defresult') 

129 self.location = obj.get('location') 

130 

131 

132class CaseWhen(Node): 

133 

134 def __init__(self, obj): 

135 self.expr = build_from_item(obj, 'expr') 

136 self.result = build_from_item(obj, 'result') 

137 self.location = obj.get('location') 

138 

139 

140class NullTest(Node): 

141 

142 def __init__(self, obj): 

143 self.arg = build_from_item(obj, 'arg') 

144 self.nulltesttype = obj.get('nulltesttype') 

145 self.argisrow = obj.get('argisrow') 

146 self.location = obj.get('location') 

147 

148 

149class BooleanTest(Node): 

150 

151 def __init__(self, obj): 

152 self.arg = build_from_item(obj, 'arg') 

153 self.booltesttype = obj.get('booltesttype') 

154 self.location = obj.get('location') 

155 

156 

157class RowExpr(Node): 

158 

159 def __init__(self, obj): 

160 self.args = build_from_item(obj, 'args') 

161 self.colnames = build_from_item(obj, 'colnames') 

162 self.location = obj['location'] 

163 self.row_format = obj.get('row_format') 

164 self.type_id = obj.get('typeId')