Returns tuple (title, rows, headers, status)
(self, split_sql)
| 441 | return self.conn.closed != 0 |
| 442 | |
| 443 | def execute_normal_sql(self, split_sql): |
| 444 | """Returns tuple (title, rows, headers, status)""" |
| 445 | _logger.debug("Regular sql statement. sql: %r", split_sql) |
| 446 | |
| 447 | title = "" |
| 448 | |
| 449 | def handle_notices(n): |
| 450 | nonlocal title |
| 451 | title = f"{title}" |
| 452 | if n.message_primary is not None: |
| 453 | title = f"{title}\n{n.message_primary}" |
| 454 | if n.message_detail is not None: |
| 455 | title = f"{title}\n{n.message_detail}" |
| 456 | |
| 457 | self.conn.add_notice_handler(handle_notices) |
| 458 | |
| 459 | if self.is_virtual_database() and "show help" in split_sql.lower(): |
| 460 | # see https://github.com/psycopg/psycopg/issues/303 |
| 461 | # special case "show help" in pgbouncer |
| 462 | res = self.conn.pgconn.exec_(split_sql.encode()) |
| 463 | return title, None, None, res.command_status.decode() |
| 464 | |
| 465 | cur = self.conn.cursor() |
| 466 | cur.execute(split_sql) |
| 467 | |
| 468 | # cur.description will be None for operations that do not return |
| 469 | # rows. |
| 470 | if cur.description: |
| 471 | headers = [x[0] for x in cur.description] |
| 472 | return title, cur, headers, cur.statusmessage |
| 473 | elif cur.protocol_error: |
| 474 | _logger.debug("Protocol error, unsupported command.") |
| 475 | return title, None, None, cur.protocol_message |
| 476 | else: |
| 477 | _logger.debug("No rows in result.") |
| 478 | return title, None, None, cur.statusmessage |
| 479 | |
| 480 | def search_path(self): |
| 481 | """Returns the current search path as a list of schema names""" |
no test coverage detected