Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORA: Add named parameters in func/proc arguments #260

Merged
merged 4 commits into from May 30, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -26,7 +26,7 @@ export default class OracleDB extends GenericDialect<OracleDBLib.IConnection> im

private get lib(): typeof OracleDBLib {
const oracledb = __non_webpack_require__('oracledb');
oracledb.fetchAsString = [oracledb.DATE, oracledb.CLOB];
oracledb.fetchAsString = [oracledb.DATE, oracledb.CLOB, oracledb.NUMBER];
return oracledb;
}

@@ -67,27 +67,43 @@ export default {
)
where owner = user`,
fetchFunctions: `select
nvl(p.procedure_name, p.object_name) as name,
p.owner as dbschema,
SYS_CONTEXT ('USERENV', 'DB_NAME') as dbname,
p.owner ||'.'||p.object_name || case when p.procedure_name is not null then '.'||p.procedure_name else null end
as signature,
RTRIM(XMLAGG(XMLELEMENT(a,data_type,',').EXTRACT('//text()') ORDER BY position).GetClobVal(),',') as args,
to_clob(listagg(case when a.argument_name is null then data_type else null end, ',') within group (order by position)) as resulttype,
SYS_CONTEXT ('USERENV', 'DB_NAME') || '${TREE_SEP}' || p.owner || '${TREE_SEP}'
|| decode(p.object_type, 'PACKAGE', 'packages', 'FUNCTION', 'functions', 'PROCEDURE', 'procedures')
|| '${TREE_SEP}' || p.object_name
|| case when p.procedure_name is not null then '${TREE_SEP}' || p.procedure_name else null end
nvl(procedure_name, object_name) as name,
owner as dbschema,
sys_context ('USERENV', 'DB_NAME') as dbname,
owner ||'.'||object_name || case when procedure_name is not null then '.'||procedure_name else null end as signature,
replace(
rtrim(xmlagg(case when argument_name is null then null else xmlelement(a, argument_name || '=>' || ora_type, ','
).extract('//text()') end order by position).getclobval(), ',' ),
'=&gt;', '=>') as args,
listagg(case when argument_name is null then ora_type else null end, ',') within group (order by position) as resulttype,
sys_context ('USERENV', 'DB_NAME') || '${TREE_SEP}' || owner || '${TREE_SEP}'
|| decode(object_type, 'PACKAGE', 'packages', 'FUNCTION', 'functions', 'PROCEDURE', 'procedures')
|| '${TREE_SEP}' || object_name
|| case when procedure_name is not null then '${TREE_SEP}' || procedure_name else null end
as tree,
'' as source
from (
select p.procedure_name, p.object_name, p.owner, p.object_type,
sys_context ('USERENV', 'DB_NAME') as dbname,
a.data_type, a.argument_name, a.position,
case when a.type_name is not null
then a.type_owner || '.' || a.type_name
|| case when a.type_subname is not null
then '.' || a.type_subname
end
when a.pls_type is not null
then a.pls_type
else a.data_type
end ora_type
from all_procedures p
join all_arguments a on (a.owner = p.owner and ((a.object_name = p.object_name) or (p.procedure_name = a.object_name and p.object_name = a.package_name)))
where p.object_type in ('FUNCTION','PROCEDURE','PACKAGE')
and not (p.object_type = 'PACKAGE' and p.procedure_name is null)
and p.owner = user
group by
p.owner,
p.object_type,
p.object_name,
p.procedure_name`,
and p.owner = user
)
group by
owner,
object_type,
object_name,
procedure_name`,
} as DialectQueries;
@@ -301,7 +301,12 @@ export class SidebarFunction extends SidebarAbstractItem<null> {
this.value = `${this.functionData.signature}`;
let args = [];
this.functionData.args.forEach((type, index) => {
args.push(`\${${index + 1}:${type}}`);
const [argName, argType] = type.split('=>');
This conversation was marked as resolved by mtxr

This comment has been minimized.

Copy link
@mickeypearce

mickeypearce May 30, 2019

Author Collaborator

I am not sure if other dialects also use => for parameter name and parameter value separator... but other separators could be added later if they exist.

This comment has been minimized.

Copy link
@mtxr

mtxr May 30, 2019

Owner

That's fine! Thanks!

I'll just update if (argType !== null) to if (argType && argType.trim()) because it as breaking on other dialects.

Besides that, we are good to go!

@mickeypearce great job!

This comment has been minimized.

Copy link
@mickeypearce

mickeypearce May 30, 2019

Author Collaborator

no problem. sorry, but doesn't string.trim() returns a new value and doesn't change the original string? :)

This comment has been minimized.

Copy link
@mtxr

mtxr May 30, 2019

Owner

Nope, just if I reassign it like argType = argType.trim().

Just trim returns a new string

This comment has been minimized.

Copy link
@mickeypearce

mickeypearce May 30, 2019

Author Collaborator

what does trim() in if (argType && argType.trim()) do then?

This comment has been minimized.

Copy link
@mtxr

mtxr May 30, 2019

Owner

it's equivalent (not really but in this context it's valid) to this:

if (argType) {
  if (argType.length > 0) {
    // do stuff
  }
}

or in a single line like that:

if (argType !== null && typeof argType !== 'undefined' && argType.length > 0) {
  // do stuff
}

What was breaking for PostgreSQL was that argType was undefined, so I used a short hand to ensure argType exists.

This short hand is valid because '' (empty string) in JS is false when casting to boolean.

Try it in the browser:

Boolean('') === false // this is true

This comment has been minimized.

Copy link
@mickeypearce

mickeypearce May 30, 2019

Author Collaborator

I get it now. Thanks for the detailed explanation!

This comment has been minimized.

Copy link
@mtxr

mtxr May 30, 2019

Owner

You're welcome! ;)

if (argType && argType.trim()) {
args.push(`${argName} => \${${index + 1}:${argType}}`);
} else {
args.push(`\${${index + 1}:${type}}`);
}
});
this.snippet = new SnippetString(`${this.functionData.signature}(${args.join(', ')})$0`);
this.command = {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.