|
15 | 15 |
|
16 | 16 |
|
17 | 17 | MAX_DL_LIMIT = 1000000 |
| 18 | +EXTENSIONS = ('tsm_system_time', 'quantile') |
18 | 19 |
|
19 | 20 |
|
20 | 21 | class OWSql(widget.OWWidget): |
@@ -132,20 +133,20 @@ def __init__(self): |
132 | 133 |
|
133 | 134 | def error(self, id=0, text=""): |
134 | 135 | super().error(id, text) |
| 136 | + err_style = 'QLineEdit {border: 2px solid red;}' |
135 | 137 | if 'server' in text or 'host' in text: |
136 | | - self.servertext.setStyleSheet('QLineEdit {border: 2px solid red;}') |
| 138 | + self.servertext.setStyleSheet(err_style) |
137 | 139 | else: |
138 | 140 | self.servertext.setStyleSheet('') |
139 | 141 | if 'role' in text: |
140 | | - self.usernametext.setStyleSheet('QLineEdit {border: 2px solid red;}') |
| 142 | + self.usernametext.setStyleSheet(err_style) |
141 | 143 | else: |
142 | 144 | self.usernametext.setStyleSheet('') |
143 | 145 | if 'database' in text: |
144 | | - self.databasetext.setStyleSheet('QLineEdit {border: 2px solid red;}') |
| 146 | + self.databasetext.setStyleSheet(err_style) |
145 | 147 | else: |
146 | 148 | self.databasetext.setStyleSheet('') |
147 | 149 |
|
148 | | - |
149 | 150 | def connect(self): |
150 | 151 | hostport = self.servertext.text().split(':') |
151 | 152 | self.host = hostport[0] |
@@ -173,9 +174,9 @@ def connect(self): |
173 | 174 | self.database_desc = self.data_desc_table = None |
174 | 175 | self.tablecombo.clear() |
175 | 176 |
|
176 | | - |
177 | 177 | def refresh_tables(self): |
178 | 178 | self.tablecombo.clear() |
| 179 | + self.error(1) |
179 | 180 | if self._connection is None: |
180 | 181 | self.data_desc_table = None |
181 | 182 | return |
@@ -215,7 +216,25 @@ def select_table(self): |
215 | 216 | self.database_desc["Table"] = "(None)" |
216 | 217 | self.table = None |
217 | 218 |
|
| 219 | + def create_extensions(self): |
| 220 | + missing = [] |
| 221 | + for ext in EXTENSIONS: |
| 222 | + try: |
| 223 | + cur = self._connection.cursor() |
| 224 | + cur.execute("CREATE EXTENSION IF NOT EXISTS " + ext) |
| 225 | + except psycopg2.OperationalError: |
| 226 | + missing.append(ext) |
| 227 | + finally: |
| 228 | + self._connection.commit() |
| 229 | + if missing: |
| 230 | + self.error(1, 'Database missing extension{}: {}'.format( |
| 231 | + 's' if len(missing) > 1 else '', |
| 232 | + ', '.join(missing))) |
| 233 | + else: |
| 234 | + self.error(1) |
| 235 | + |
218 | 236 | def open_table(self): |
| 237 | + self.create_extensions() |
219 | 238 | table = self.get_table() |
220 | 239 | self.data_desc_table = table |
221 | 240 | self.send("Data", table) |
|
0 commit comments