This function is used to fetch the primary key columns.
(self, default_conn=None)
| 505 | return sql |
| 506 | |
| 507 | def get_primary_keys(self, default_conn=None): |
| 508 | """ |
| 509 | This function is used to fetch the primary key columns. |
| 510 | """ |
| 511 | driver = get_driver(PG_DEFAULT_DRIVER) |
| 512 | if default_conn is None: |
| 513 | manager = driver.connection_manager(self.sid) |
| 514 | conn = manager.connection(did=self.did, conn_id=self.conn_id) |
| 515 | else: |
| 516 | conn = default_conn |
| 517 | |
| 518 | pk_names = '' |
| 519 | primary_keys = OrderedDict() |
| 520 | |
| 521 | if conn.connected(): |
| 522 | |
| 523 | # Fetch the primary key column names |
| 524 | query = render_template( |
| 525 | "/".join([self.sql_path, 'primary_keys.sql']), |
| 526 | table_name=self.object_name, |
| 527 | table_nspname=self.nsp_name, |
| 528 | conn=conn, |
| 529 | ) |
| 530 | |
| 531 | status, result = conn.execute_dict(query) |
| 532 | if not status: |
| 533 | raise ExecuteError(result) |
| 534 | |
| 535 | for row in result['rows']: |
| 536 | pk_names += driver.qtIdent(conn, row['attname']) + ',' |
| 537 | primary_keys[row['attname']] = row['typname'] |
| 538 | |
| 539 | if pk_names != '': |
| 540 | # Remove last character from the string |
| 541 | pk_names = pk_names[:-1] |
| 542 | else: |
| 543 | raise InternalServerError(SERVER_CONNECTION_CLOSED) |
| 544 | |
| 545 | return pk_names, primary_keys |
| 546 | |
| 547 | def can_edit(self): |
| 548 | return True |
no test coverage detected