视图是否需要任何动作来更新,甚至还需要一些时间?

时间:2019-05-09 14:41:27

标签: mysql database

我创建了一个视图,该视图应该只包含date字段在范围之间的行。当我使用php页面以某些where条件获取数据时,它不返回任何结果。但是,如果我使用“ select * from”,则通过phpMyAdmin返回所有数据,然后,如果我尝试再次获取php页面(具有与我之前尝试过的条件相同的代码),它将正常工作。我的印象是,仅当我执行“ select * from”查询时,视图才会更新。请记住,该视图只有4行用于测试。

我的观点:(字段“ causedoEm”和“ causedoPara”的类型为datetime)

 try
      {
          String sql = "UPDATE `master.Employees` SET `EmployeeName`=?, `Address `=?, `PhoneNumber`=?, `EmailAddress`=? WHERE `EmployeeID `=?";
         PreparedStatement ps = con.prepareStatement(sql);
         //putting value for all placeholder (?)
         ps.setString(1,jTextField2.getText());
         ps.setString(2,jTextField3.getText());
         ps.setInt(3,Integer.parseInt(jTextField4.getText()));
         ps.setString(4,jTextField5.getText());
         ps.setInt(5,Integer.parseInt(jTextField1.getText()));

         int i=0;
         i = ps.executeUpdate();
         if(i>0)
             {
         //do   something   
             }
     }
     catch(Exception e)
      {

      e.printStackTrace();

      }

我在php页面上执行的查询:

CREATE VIEW vw_Agendamento AS (
SELECT agendamentos.id as id, agendamentos.userid as userid, agendamentos.paciente as paciente,agendamentos.agendadoEm as agendadoEm, agendamentos.agendadoPara as agendadoPara,
agendamentos.confirmado as confirmado, agendamentos.notificada as notificada,usuarios.contaTipo as contaTipo, profissionais.profissao as profissao

    FROM agendamentos

LEFT JOIN usuarios ON usuarios.id=agendamentos.userid
LEFT JOIN profissionais ON profissionais.userid=agendamentos.userid

WHERE (agendamentos.confirmado=0 AND TIMESTAMPDIFF(MINUTE,agendamentos.agendadoEm,NOW())<35) OR

(agendamentos.confirmado=1 AND TIMESTAMPDIFF(SECOND,NOW(),agendamentos.agendadoPara)>1));

我运行该查询多少次都没有关系,它不会返回任何结果。但是在“从vw_Agendamento中选择*”之后,我打开了相同的php页面,并且正在获取正确的数据。你知道发生了什么吗?

0 个答案:

没有答案