MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / get_sql

Method get_sql

web/pgadmin/tools/sqleditor/command.py:459–505  ·  view source on GitHub ↗

This method is used to create a proper SQL query to fetch the data for the specified table

(self, default_conn=None)

Source from the content-addressed store, hash-verified

457 'table_view_data_by_pk').get()
458
459 def get_sql(self, default_conn=None):
460 """
461 This method is used to create a proper SQL query
462 to fetch the data for the specified table
463 """
464
465 # Fetch the primary keys for the table
466 _, primary_keys = self.get_primary_keys(default_conn)
467
468 # Fetch OIDs status
469 has_oids = self.has_oids(default_conn)
470
471 sql_filter = self.get_filter()
472 data_sorting = self.get_data_sorting()
473
474 # If data sorting is none and not reset from the filter dialog then
475 # set the data sorting in following conditions:
476 # 1. When command type is VIEW_FIRST_100_ROWS or VIEW_LAST_100_ROWS.
477 # 2. When command type is VIEW_ALL_ROWS and limit is greater than 0
478
479 if data_sorting is None and \
480 not self.is_sorting_set_from_filter_dialog() \
481 and (self.cmd_type in (VIEW_FIRST_100_ROWS, VIEW_LAST_100_ROWS) or
482 (self.cmd_type == VIEW_ALL_ROWS and self.data_sorting_by_pk)):
483 sorting = {'data_sorting': []}
484 for pk in primary_keys:
485 sorting['data_sorting'].append(
486 {'name': pk, 'order': self.get_pk_order()})
487 self.set_data_sorting(sorting)
488 data_sorting = self.get_data_sorting()
489
490 if sql_filter is None:
491 sql = render_template(
492 "/".join([self.sql_path, self._OBJECT_QUERY_SQL]),
493 object_name=self.object_name,
494 nsp_name=self.nsp_name, limit=self.limit, has_oids=has_oids,
495 data_sorting=data_sorting
496 )
497 else:
498 sql = render_template(
499 "/".join([self.sql_path, self._OBJECT_QUERY_SQL]),
500 object_name=self.object_name,
501 nsp_name=self.nsp_name, limit=self.limit, has_oids=has_oids,
502 sql_filter=sql_filter, data_sorting=data_sorting
503 )
504
505 return sql
506
507 def get_primary_keys(self, default_conn=None):
508 """

Callers

nothing calls this directly

Calls 9

get_primary_keysMethod · 0.95
has_oidsMethod · 0.95
get_filterMethod · 0.80
get_data_sortingMethod · 0.80
appendMethod · 0.80
get_pk_orderMethod · 0.80
set_data_sortingMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected