MCPcopy Index your code
hub / github.com/webpy/webpy / SQLQuery

Class SQLQuery

web/db.py:131–295  ·  view source on GitHub ↗

You can pass this sort of thing as a clause in any db function. Otherwise, you can pass a dictionary to the keyword argument `vars` and the function will call reparam for you. Internally, consists of `items`, which is a list of strings and SQLParams, which get concatenated to p

Source from the content-addressed store, hash-verified

129
130
131class SQLQuery:
132 """
133 You can pass this sort of thing as a clause in any db function.
134 Otherwise, you can pass a dictionary to the keyword argument `vars`
135 and the function will call reparam for you.
136
137 Internally, consists of `items`, which is a list of strings and
138 SQLParams, which get concatenated to produce the actual query.
139 """
140
141 __slots__ = ["items"]
142
143 # tested in sqlquote's docstring
144 def __init__(self, items=None):
145 r"""Creates a new SQLQuery.
146
147 >>> SQLQuery("x")
148 <sql: 'x'>
149 >>> q = SQLQuery(['SELECT * FROM ', 'test', ' WHERE x=', SQLParam(1)])
150 >>> q
151 <sql: 'SELECT * FROM test WHERE x=1'>
152 >>> q.query(), q.values()
153 ('SELECT * FROM test WHERE x=%s', [1])
154 >>> SQLQuery(SQLParam(1))
155 <sql: '1'>
156 """
157 if items is None:
158 self.items = []
159 elif isinstance(items, list):
160 self.items = items
161 elif isinstance(items, SQLParam):
162 self.items = [items]
163 elif isinstance(items, SQLQuery):
164 self.items = list(items.items)
165 else:
166 self.items = [items]
167
168 # Take care of SQLLiterals
169 for i, item in enumerate(self.items):
170 if isinstance(item, SQLParam) and isinstance(item.value, SQLLiteral):
171 self.items[i] = item.value.v
172
173 def append(self, value):
174 self.items.append(value)
175
176 def __add__(self, other):
177 if isinstance(other, str):
178 items = [other]
179 elif isinstance(other, SQLQuery):
180 items = other.items
181 else:
182 return NotImplemented
183 return SQLQuery(self.items + items)
184
185 def __radd__(self, other):
186 if isinstance(other, str):
187 items = [other]
188 elif isinstance(other, SQLQuery):

Callers 14

sqlqueryMethod · 0.85
__add__Method · 0.85
__radd__Method · 0.85
joinMethod · 0.85
_sqllistFunction · 0.85
sqlorsFunction · 0.85
queryMethod · 0.85
_whereMethod · 0.85
gen_clauseMethod · 0.85
insertMethod · 0.85
multiple_insertMethod · 0.85
get_sequence_queryMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected