MCPcopy Index your code
hub / github.com/pgadmin-org/pgadmin4 / initialize_viewdata

Function initialize_viewdata

web/pgadmin/tools/sqleditor/__init__.py:197–354  ·  view source on GitHub ↗

This method is responsible for creating an asynchronous connection. After creating the connection it will instantiate and initialize the object as per the object type. It will also create a unique transaction id and store the information into session variable. Args: cmd

(trans_id, cmd_type, obj_type, sgid, sid, did, obj_id)

Source from the content-addressed store, hash-verified

195)
196@pga_login_required
197def initialize_viewdata(trans_id, cmd_type, obj_type, sgid, sid, did, obj_id):
198 """
199 This method is responsible for creating an asynchronous connection.
200 After creating the connection it will instantiate and initialize
201 the object as per the object type. It will also create a unique
202 transaction id and store the information into session variable.
203
204 Args:
205 cmd_type: Contains value for which menu item is clicked.
206 obj_type: Contains type of selected object for which data grid to
207 be render
208 sgid: Server group Id
209 sid: Server Id
210 did: Database Id
211 obj_id: Id of currently selected object
212 """
213
214 if request.data:
215 _data = json.loads(request.data)
216 else:
217 _data = request.args or request.form
218
219 filter_sql = _data['sql_filter'] if 'sql_filter' in _data else None
220 server_cursor = _data['server_cursor'] if\
221 'server_cursor' in _data and (
222 _data['server_cursor'] == 'true' or _data['server_cursor'] is True
223 ) else False
224 dbname = _data['dbname'] if 'dbname' in _data else None
225
226 kwargs = {
227 'user': _data['user'] if 'user' in _data else None,
228 'role': _data['role'] if 'role' in _data else None,
229 'password': _data['password'] if 'password' in _data else None
230 }
231
232 server = get_server(sid)
233 if server is None:
234 return make_json_response(
235 status=410, success=0,
236 errormsg=gettext("Could not find the required server.")
237 )
238 if kwargs.get('password', None) is None:
239 kwargs['encpass'] = server.password
240 else:
241 kwargs['encpass'] = None
242
243 # Create asynchronous connection using random connection id.
244 conn_id = str(secrets.choice(range(1, 9999999)))
245 try:
246 manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid)
247 # default_conn is same connection which is created when user connect to
248 # database from tree
249 conn = manager.connection(conn_id=conn_id,
250 auto_reconnect=False,
251 use_binary_placeholder=True,
252 array_to_string=True,
253 **({"database": dbname} if dbname is not None
254 else {"did": did}

Callers

nothing calls this directly

Calls 14

get_serverFunction · 0.90
make_json_responseFunction · 0.90
get_driverFunction · 0.90
internal_server_errorFunction · 0.90
gettextFunction · 0.85
_connectFunction · 0.85
connection_managerMethod · 0.80
connectionMethod · 0.80
errorMethod · 0.80
get_objectMethod · 0.80
set_filterMethod · 0.80
set_data_sortingMethod · 0.80

Tested by

no test coverage detected