def _getRemotes(self, txn, remote): ## the procedures remoted (indexed by URI) we return ## procs = {} txn.execute(""" SELECT id, schema, package, procedure, object_id, subprogram_id, return_type, args_cnt, arg_types, arg_inouts, uri, authkeys FROM endpoint """) res = txn.fetchall() if res is not None: for r in res: id = r[0] schema = r[1] package = r[2] procedure = r[3] return_type = r[6] args_cnt = r[7] arg_types = r[8] arg_inouts = r[9] uri = r[10] authkeys = r[11] meta = DbProcedureMeta(remote.id, "%s.%s.%s" % (schema, package, procedure), args_cnt) meta.id = id meta.uri = uri meta.return_type = return_type meta.arg_types = arg_types meta.arg_inouts = arg_inouts meta.arg_sess_inout = None for i in xrange(len(meta.arg_types)): if meta.arg_types[i] == 'CROSSBAR_SESSION': meta.arg_sess_inout = meta.arg_inouts[i] break procs[uri] = meta return procs
def _getRemotes(self, txn, remote): ## FIXME: filter ## - overloaded funs ## - funs with default params ## - funs with parameter types we cannot digest ## the procedures remoted (indexed by URI) we return ## procs = {} ## iterate over all Schemas defined in the remote ## for s in remote.schemaList.split(','): ## FIXME: are PG identifiers case-insensitive? ## schema = s.strip().lower() ## get info on all stored procedures in given schema for which ## we (the connection pool user connecting) have execute rights ## txn.execute( """ SELECT n.nspname, p.proname, p.pronargs, p.pronargdefaults FROM pg_proc p INNER JOIN pg_namespace n ON p.pronamespace = n.oid WHERE n.nspname = %s AND has_schema_privilege(current_user, n.oid, 'usage') = true AND has_function_privilege(current_user, p.oid, 'execute') = true ORDER BY n.nspname, p.proname """, [schema]) res = txn.fetchall() if res is not None: for r in res: ## the RPC endpoint URI is constructed as: ## RPC Base URI + Schema Name + '#' + Function Name ## uri = urljoin(remote.rpcBaseUri, str(r[0]).lower() + "#" + str(r[1]).lower()) ## the SQL statement used when calling the SP later ## statement = "SELECT %s.%s(%s)" % (str(r[0]), str(r[1]), ("%s," * r[2])[:-1]) ## procs[uri] = (Schema Name, ## Function Name, ## Function Arity, ## Remote ID, ## SQL Statement) ## meta = DbProcedureMeta(remote.id, r[0] + '.' + r[1], r[2]) meta.statement = statement procs[uri] = meta return procs
def _getRemotes(self, txn, remote): ## FIXME: filter ## - overloaded funs ## - funs with default params ## - funs with parameter types we cannot digest ## the procedures remoted (indexed by URI) we return ## procs = {} ## iterate over all Schemas defined in the remote ## for s in remote.schemaList.split(","): ## FIXME: are PG identifiers case-insensitive? ## schema = s.strip().lower() ## get info on all stored procedures in given schema for which ## we (the connection pool user connecting) have execute rights ## txn.execute( """ SELECT n.nspname, p.proname, p.pronargs, p.pronargdefaults FROM pg_proc p INNER JOIN pg_namespace n ON p.pronamespace = n.oid WHERE n.nspname = %s AND has_schema_privilege(current_user, n.oid, 'usage') = true AND has_function_privilege(current_user, p.oid, 'execute') = true ORDER BY n.nspname, p.proname """, [schema], ) res = txn.fetchall() if res is not None: for r in res: ## the RPC endpoint URI is constructed as: ## RPC Base URI + Schema Name + '#' + Function Name ## uri = urljoin(remote.rpcBaseUri, str(r[0]).lower() + "#" + str(r[1]).lower()) ## the SQL statement used when calling the SP later ## statement = "SELECT %s.%s(%s)" % (str(r[0]), str(r[1]), ("%s," * r[2])[:-1]) ## procs[uri] = (Schema Name, ## Function Name, ## Function Arity, ## Remote ID, ## SQL Statement) ## meta = DbProcedureMeta(remote.id, r[0] + "." + r[1], r[2]) meta.statement = statement procs[uri] = meta return procs