1

考虑以下脚本:

create function login_web_user
(
    p_email_address app_user.email_address%type,
    p_password      text
)
returns app_user_session.session_token%type as $$
declare
    v_app_user_id   app_user.id%type;
    v_session_token app_user_session.session_token%type;
begin
    select id
    into   v_app_user_id
    from   current_app_user
    where  email_address = p_email_address
    and    password_digest = crypt(p_password, password_digest);

    if not found then
        raise exception sqlstate 'SM001';
    end if;

    insert into app_user_session
    (
        app_user_id
    )
    values
    (
        v_app_user_id
    )
    returning session_token into v_session_token;

    return v_session_token;
end;
$$ language plpgsql;


create function ws_login_web_user(jsonb) returns json as $$
select json_build_object
(
    'sessionToken',
    login_web_user
    (
        p_email_address := $1->>'emailAddress',
        p_password      := $1->>'password'
    )
)
$$ language sql security definer;

grant execute on function ws_login_web_user(jsonb) to myapp_api;

当我通过 pgAdmin3 执行以下操作时(以 身份登录myapp_api

select ws_login_web_user
(
    json_build_object
    (
        'emailAddress', 'foo@bar',
        'password', 'demo'
    )::jsonb
)

它运行没有错误。但是,当我通过 JDBC 执行完全相同的存储过程时,也登录为myapp_api,我得到这个:

ERROR: function crypt(text, text) does not exist
  Hint: No function matches the given name and argument types. You might need to add explicit type casts.
  Where: PL/pgSQL function login_web_user(character varying,character varying,text) line 7 at SQL statement
SQL function "ws_login_web_user" statement 1

我还重复了 JDBC 测试,这次以myapp拥有上述对象的身份登录。我收到了完全相同的错误。

我正在使用 PostgreSQL 9.4、9.4 JDBC 驱动程序和 Java 8。

4

0 回答 0