小编gre*_*alu的帖子

Postgres存储函数如何返回表

我想知道Postgres存储函数如何返回一个具有已识别列的表.我使用了返回setof returnType:

-- create employeeSearchResult returnType
create type employeeAllReturnType as
(
  id bigserial,
  "positionId" integer,
  "subjectId" bigint,
  "dateEngaged" date,
  "nextKin" text,
  "nrcNo" text,
  dob date,
  father text,
  mother text,
  wife text,
  "userId" integer,
  "statusId" integer,
  "mainCode" text,
  "subCode" text
);


-- Search for emmployee by name
CREATE OR REPLACE FUNCTION "employee_search_by_name"(employeeNameIN text)
returns setof employeeAllReturnType as 
$$
declare
    results record;
    resultsRow employee%rowtype;
    nameIn text;
begin
    nameIn = employeeNameIN || '%';
    for results in select 
        employee.id,-- bigserial NOT NULL,
  employee."positionId",-- integer, …
Run Code Online (Sandbox Code Playgroud)

postgresql return function

11
推荐指数
1
解决办法
2万
查看次数

Postgres两列上的唯一约束:整数和布尔值

我想找到一种方法来为我的数据库中的一个主题存储多个地址,每个主题只有一个默认地址.

简而言之,我们假设有一张桌子:

CREATE TABLE test
(
  id integer NOT NULL,
  active boolean NOT NULL,
  CONSTRAINT pk_id PRIMARY KEY (id)
)
Run Code Online (Sandbox Code Playgroud)

对于表中的每个id,最多只能有1个真有效值.

我怎么能实现这个目标?

谢谢.

postgresql constraints unique

8
推荐指数
1
解决办法
3624
查看次数

Java JDBC效率:连接应维持多长时间?

我仍在处理此处提到的相同问题。似乎工作正常,尤其是在创建如下所示的AbstractModel类之后:

public abstract class AbstractModel {

    protected static Connection myConnection = SingletonConnection.instance().establishConnection();
    protected static Statement stmt;
    protected static ResultSet rs;

    protected boolean loginCheck;                   // if userId and userLoginHistoryId are valid - true, else false
    protected boolean userLoggedIn;                 // if user is already logged in - true, else false

    public AbstractModel (int userId, Long userLoginHistoryId){
        createConnection();                                 // establish connection
            loginCheck = false;
        userLoggedIn = false;
        if (userId == 0 && userLoginHistoryId == 0){        // special case for login
            loginCheck …
Run Code Online (Sandbox Code Playgroud)

java connection performance jdbc

5
推荐指数
2
解决办法
8299
查看次数

Postgres plpgsql存储函数中的文本相等(包括空值)

我有一个存储函数,它应该比较三个文本值是否相等.其中一些文本值可能为null,如果是,则比较应返回false值.

CREATE OR REPLACE FUNCTION "subject_check_if_subjectName_exists"(name1IN text, name2IN text, name3IN text, name4IN text)
returns boolean as
$$
declare
    results boolean;
    subjectList record;
begin
    results = false;
    for subjectList in select name1, name2, name3, name4 from subject loop
    if (name1In = subjectList.name1) and (name2In = subjectList.name2) and (name3In = subjectList.name3) and (name4In = subjectList.name4)
      then
        results = true;
        EXIT; -- exit out of loop
    end if;
    end loop;
    return results;
end;
$$ language 'plpgsql';
Run Code Online (Sandbox Code Playgroud)

name4IN和subjectList.name4都是null,并且所有其他值都相等,该函数不返回true值 - 它应该是.即使它们为null,我如何比较这些文本值(null = null应该返回true)?

sql postgresql null equals plpgsql

4
推荐指数
1
解决办法
4286
查看次数

Java Swing FocusListener的MVC实现

我正在尝试使用MVC架构模式构建一个简单的Java Swing应用程序.我所做的是在我的视图中创建用户界面组件(作为私有),并具有返回组件的公共方法.然后由控制器调用这些方法,通过它我可以为事件/动作侦听器编写方法.以下是一个示例示例:

视图:

private JButton btnAdd;

    public JButton getBtnAdd(){
        return btnAdd;
    }
Run Code Online (Sandbox Code Playgroud)

控制:

myGuiFrame gui = new myGuiFrame();


        //on add button clicked
    gui.getBtnAdd().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //calls to model
        }
    });
Run Code Online (Sandbox Code Playgroud)

这个实现是否正确?

如果是这样,那么我遇到了FocusListeners的问题.当我在视图中创建FocusListener时,会在视图中创建focusLost和focusGained方法.

private FocusListener l;

someComponent.addFocusListener(l);

        l = new FocusListener() {

            @Override
            public void focusLost(FocusEvent e) {
                // TODO Auto-generated method stub
            }

            @Override
            public void focusGained(FocusEvent e) {
                // TODO Auto-generated method stub

            }
        };
Run Code Online (Sandbox Code Playgroud)

我希望所有的事件处理程序都在我的控制器中.我的问题是......有没有办法可以从我的控制器调用/声明focusLost和focusGained方法?我试图将FocusListener定义为public,以便我可以在我的控制器中定义它:

视图:

public FocusListener l;
public someComponentType someComponent; …
Run Code Online (Sandbox Code Playgroud)

java model-view-controller swing focus listener

2
推荐指数
1
解决办法
1419
查看次数

PostgreSQL CallableStatement:偏移量为6的格式错误的函数或过程转义语法

我在Java应用程序中使用CallableStatement调用Postgres存储函数时出错.错误如下:

org.postgresql.util.PSQLException: Malformed function or procedure escape syntax at offset 6.
    at org.postgresql.jdbc2.AbstractJdbc2Statement.modifyJdbcCall(AbstractJdbc2Statement.java:2390)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.<init>(AbstractJdbc2Statement.java:149)
    at org.postgresql.jdbc3.AbstractJdbc3Statement.<init>(AbstractJdbc3Statement.java:40)
    at org.postgresql.jdbc3g.AbstractJdbc3gStatement.<init>(AbstractJdbc3gStatement.java:26)
    at org.postgresql.jdbc3g.Jdbc3gStatement.<init>(Jdbc3gStatement.java:28)
    at org.postgresql.jdbc3g.Jdbc3gPreparedStatement.<init>(Jdbc3gPreparedStatement.java:21)
    at org.postgresql.jdbc3g.Jdbc3gCallableStatement.<init>(Jdbc3gCallableStatement.java:17)
    at org.postgresql.jdbc3g.Jdbc3gConnection.prepareCall(Jdbc3gConnection.java:45)
    at org.postgresql.jdbc3.AbstractJdbc3Connection.prepareCall(AbstractJdbc3Connection.java:316)
    at org.postgresql.jdbc2.AbstractJdbc2Connection.prepareCall(AbstractJdbc2Connection.java:203)
    at com.mchange.v2.c3p0.impl.NewProxyConnection.prepareCall(NewProxyConnection.java:632)
    at zm.co.freight.model.user.UserRoleModel.getUserRoleDocumentPermission(UserRoleModel.java:212)
Run Code Online (Sandbox Code Playgroud)

应该注意的是,我使用的是Postgres 9.2,posgresql-9.1-902.jdbc3.jar和c3p0-0.9.2-pre4.jar连接池.

这是我想要调用的存储函数:

CREATE OR REPLACE FUNCTION user_role_document_permission_select_all_per_user_role(userroleidin integer)
  RETURNS refcursor AS
$BODY$
declare
    mycurs refcursor;
begin
    open mycurs for
        select document._name,
          document_user_role_permission.viewing,
          document_user_role_permission.processing,
          document_user_role_permission.editing,
          document_user_role_permission.updating,
          document_user_role_permission.user_role_id,
          document_user_role_permission.document_id
       from document_user_role_permission, document where document_user_role_permission.document_id = document.id and document_user_role_permission.user_role_id =  userroleidin;
    return mycurs;
end;
$BODY$
  LANGUAGE plpgsql …
Run Code Online (Sandbox Code Playgroud)

postgresql jdbc callable-statement

1
推荐指数
1
解决办法
2593
查看次数