Returns the query part of the sql query. >>> q = SQLQuery(["SELECT * FROM test WHERE name=", SQLParam('joe')]) >>> q.query() 'SELECT * FROM test WHERE name=%s' >>> q.query(paramstyle='qmark') 'SELECT * FROM test WHERE name=?'
(self, paramstyle=None)
| 207 | return isinstance(other, SQLQuery) and other.items == self.items |
| 208 | |
| 209 | def query(self, paramstyle=None): |
| 210 | """ |
| 211 | Returns the query part of the sql query. |
| 212 | >>> q = SQLQuery(["SELECT * FROM test WHERE name=", SQLParam('joe')]) |
| 213 | >>> q.query() |
| 214 | 'SELECT * FROM test WHERE name=%s' |
| 215 | >>> q.query(paramstyle='qmark') |
| 216 | 'SELECT * FROM test WHERE name=?' |
| 217 | """ |
| 218 | s = [] |
| 219 | for x in self.items: |
| 220 | if isinstance(x, SQLParam): |
| 221 | x = x.get_marker(paramstyle) |
| 222 | s.append(safestr(x)) |
| 223 | else: |
| 224 | x = safestr(x) |
| 225 | # automatically escape % characters in the query |
| 226 | # For backward compatibility, ignore escaping when the query |
| 227 | # looks already escaped |
| 228 | if paramstyle in ["format", "pyformat"]: |
| 229 | if "%" in x and "%%" not in x: |
| 230 | x = x.replace("%", "%%") |
| 231 | s.append(x) |
| 232 | return "".join(s) |
| 233 | |
| 234 | def values(self): |
| 235 | """ |