How do I know if a record has been added to the database?

3
Hello, I'm working on an alert system, when a larger than normal data is registered in the database an alert has to appear on the page where the user is browsing. The problem is that I do not know how to check if an element has been added to the database.

I'm getting my data automatically from a PCD (weather station), if any of these data goes beyond the limit registered by the ADM, an alert will be shown to the user.

I have the following tables in my bank:

CREATE TABLE PARAMETROS_DE_ALERTAS (
    PRA_ID INTEGER AUTO_INCREMENT PRIMARY KEY,
    PRA_VALOR_MAXIMO INTEGER(5) NOT NULL,
    PRA_VALOR_MINIMO INTEGER NOT NULL,
    PRA_COR_MINIMA VARCHAR(30) NOT NULL,
    PRA_COR_MAXIMA VARCHAR(30) NOT NULL,
    SEN_ID INTEGER NOT NULL
);

This table is the parameter for the alerts, where the minimum and maximum measurement from the PCD will be registered for it to be an alert.

CREATE TABLE MEDICOES (
    MED_ID INTEGER AUTO_INCREMENT PRIMARY KEY,
    MED_DADO VARCHAR(10) NOT NULL,
    MED_DATA_HORA_MEDICAO DATETIME NOT NULL,
    API_ID INTEGER,
    SEN_ID INTEGER NOT NULL
);

This is the measurement table, where you will save the data coming from PCD.

CREATE TABLE ALERTAS_CRITICOS (
    ALC_DATA_HORA_ALERTA DATETIME NOT NULL,
    ALC_ID INTEGER AUTO_INCREMENT PRIMARY KEY,
    ALC_VALOR_MEDICAO FLOAT NOT NULL,
    SEN_ID INTEGER NOT NULL
);

The system should add a record of this table if the measurement data is larger or smaller than the parameters. After this critical alert is registered, the system should display an alert to the user browsing any page of my site.

The problem is that I do not know how to check if a record has been added to the bank.

    
asked by anonymous 15.07.2016 / 23:08

3 answers

1

You can use a bank function to give this insert. Within this function you make the INSERT necessary and can give a SELECT then return true or false for the application to know if it was successful.

    
02.09.2016 / 19:30
1

Nicolas, so I understand your need, there is no method that will do everything you need, so I will suggest what I would do in your situation:

  • Bank alert insert
  • Read in a json file saved in your application
  • Generate an array, or add to the existing array of alerts
  • Create a middleware for your entire application that reads this JSON and displays alerts on the page load and or js on the page with an infinite looping reading through the json url
  • Delete alerts (if it's part of your rule) and save this file after editing
  • The advantages of using json are, you can easily edit the content (using the json_encode and json_decode functions) and the reading is extremely fast, as it does not need to query the database and is not a large volume of data.

        
    02.09.2016 / 19:45
    0

    You need to create an api that accesses the bank and you can call it via ajax. This api queries the bank and returns the data and in the get of its ajax when receiving the callback of this call can implement the alert

        
    15.07.2016 / 23:18