Taking in a InsertStatement object with some attributes set, return a string representation of the query in the correct dialect.
(self, insert_statement)
| 131 | return sql |
| 132 | |
| 133 | def _write_insert_statement(self, insert_statement): |
| 134 | """ |
| 135 | Taking in a InsertStatement object with some attributes set, return a string |
| 136 | representation of the query in the correct dialect. |
| 137 | """ |
| 138 | sql = list() |
| 139 | |
| 140 | if insert_statement.with_clause: |
| 141 | sql.append(self._write(insert_statement.with_clause)) |
| 142 | |
| 143 | if insert_statement.insert_clause: |
| 144 | sql.append(self._write(insert_statement.insert_clause)) |
| 145 | else: |
| 146 | raise Exception('InsertStatement is missing insert_clause attribute') |
| 147 | |
| 148 | if insert_statement.select_query and not insert_statement.values_clause: |
| 149 | sql.append(self._write(insert_statement.select_query)) |
| 150 | elif not insert_statement.select_query and insert_statement.values_clause: |
| 151 | sql.append(self._write(insert_statement.values_clause)) |
| 152 | else: |
| 153 | raise Exception('InsertStatement must have a select_query xor a values clause') |
| 154 | |
| 155 | sql = '\n'.join(sql) |
| 156 | return sql |
| 157 | |
| 158 | def make_pretty_sql(self, sql): |
| 159 | try: |
no test coverage detected