Module sql_query_strings

Source
Expand description

Contains all SQL queries as constants with placeholders A centralized repository for all static SQL query strings used throughout the application.

This module acts as a single source of truth for database queries, decoupling the raw SQL from the application’s business logic. This design offers several key advantages:

  • Centralization: All queries are in one place, making them easy to find, review, and manage.
  • Maintainability: If a table or column name changes, it only needs to be updated here, rather than in multiple places across the codebase.
  • Security Auditing: Having all queries in one file simplifies the process of auditing for potential security vulnerabilities like SQL injection.
  • Decoupling: Rust code that interacts with the database can focus on logic without being cluttered with long, embedded SQL strings.

§Usage

Queries are defined as pub const &str. They use named parameters (e.g., :my_param) which are compatible with the mysql crate’s params! macro for safe data binding.

Constants§

SQL_QUERY_CHECK_BALLING_DOSING_LOG_COUNT
Checks how many entries are in the balling dosing log
SQL_QUERY_CHECK_BALLING_SETVALS_COUNT
Checks how many entries are in the balling set value table
SQL_QUERY_CHECK_BALLING_SETVALS_NULL
Checks if the balling set value table contains any NULL values.
SQL_QUERY_CHECK_DATA_COUNT
Checks how many entries there are in the data table.
SQL_QUERY_CHECK_FEEDLOG_COUNT
Checks how many entries there are in the feed log table.
SQL_QUERY_CHECK_FEEDPATTERNS_NULL
Checks if the feed patterns table contains any NULL values.
SQL_QUERY_CHECK_FEEDPATTERN_COUNT
Checks how many entries there are in the feed patterns table.
SQL_QUERY_CHECK_FEEDSCHEDULE_COUNT
Checks how many entries there are in the feed schedule table.
SQL_QUERY_CHECK_FEEDSCHEDULE_NULL
Checks if the feed schedule table contains any NULL values.
SQL_QUERY_CHECK_HEATING_SETVALS_COUNT
Checks how many entries there are in the heating set value table.
SQL_QUERY_CHECK_HEATING_SETVALS_NULL
Checks if the heating set value table contains any NULL values.
SQL_QUERY_CHECK_HEATING_STATS_COUNT
Checks how many entries there are in the heating set value table.
SQL_QUERY_CHECK_HEATING_STATS_NULL
Checks if the heating stats table contains any NULL values.
SQL_QUERY_CHECK_REFILL_COUNT
Checks how many entries there are in the refill table.
SQL_QUERY_CHECK_REFILL_EMPTY
Checks if the refill table is empty.
SQL_QUERY_CHECK_SCHEDULE_COUNT
Checks how many entries there are in the schedule table.
SQL_QUERY_CHECK_SCHEDULE_NULL
Checks if the schedule table contains any NULL values.
SQL_QUERY_CHECK_VENTILATION_SETVALS_COUNT
Checks how many entries there are in the heating set value table.
SQL_QUERY_CHECK_VENTILATION_SETVALS_NULL
SQL_QUERY_DATABASE
Provides the current database name.
SQL_QUERY_DELETE_FEED_SCHEDULE_ENTRY
Updates a feed schedule entry after having executing a feed pattern which shall not be repeated daily.
SQL_QUERY_PING
Minimal request to the database to avoid timeouts
SQL_QUERY_READ_BALLING_SETVALS
Provides the Balling dosing pump configuration for one of the pumps.
SQL_QUERY_READ_CURRENT_DATE
Provides the current date (without time) from the database.
SQL_QUERY_READ_CURRENT_TIMESTAMP
Provides the current timestamp from the database.
SQL_QUERY_READ_DURATION_UNTIL_MIDNIGHT
Provides the duration in seconds until midnight from the database.
SQL_QUERY_READ_FEEDPATTERN_HEADER
Provides the header of a feed pattern from the database.
SQL_QUERY_READ_FEED_PHASE
Provides one phase of a feed pattern from the database.
SQL_QUERY_READ_HEATING_SETVALS
Reads the heating set values from the database.
SQL_QUERY_READ_HEATING_STATS
Provides the heating statistical data of the current day from the database.
SQL_QUERY_READ_LAST_BALLING_DOSING_TIMESTAMP
Provides the timestamp of the last Balling dosing event from the database.
SQL_QUERY_READ_LAST_REFILL_TIMESTAMP
Provides the timestamp of the last refill event from the database.
SQL_QUERY_READ_PAST_FEED_SCHEDULE_ENTRY
Provides the feed schedule entries which lie in the past in descending order
SQL_QUERY_READ_REFILL_COUNT_LAST_24H
Provides the number of refill events from the last day from the database.
SQL_QUERY_READ_REFILL_COUNT_LAST_HOUR
Provides the number of refill events from the last hour from the database. It does not need to use the COALESCE function because the query returns 0 if there is no refill event in the last 24h.
SQL_QUERY_READ_REFILL_VOLUME_LAST_24H
Provides the refill volume of the last day from the database. It needs to use the COALESCE function because a null result is not interpreted correctly by the SQL library.
SQL_QUERY_READ_REFILL_VOLUME_LAST_HOUR
Provides the refill volume of the last hour from the database. It needs to use the COALESCE function because a null result is not interpreted correctly by the SQL library.
SQL_QUERY_READ_SCHEDULE
Provides the schedule entry for one of the controls (Refill, Ventilation, Heating, Balling)
SQL_QUERY_READ_TABLES
Provides all tables from the database. This query cannot be limited.
SQL_QUERY_READ_TIMEOUT
Provides the system variable that controls how long the server waits for activity on an idle connection before closing it.
SQL_QUERY_READ_TOMORROW_DATE
Provides tomorrow’s date (without time) from the database.
SQL_QUERY_READ_VENTILATION_SETVALS
Reads the ventilation set values from the database.
SQL_QUERY_UPDATE_FEED_SCHEDULE_ENTRY
Updates a feed schedule entry after having executing a feed pattern which shall be repeated daily.
SQL_QUERY_VERSION_INFORMATION
Provides version information to check if the current application is listed in the table of supported versions. It informs whether the version is supported and which hash is stored in the database for the version.
SQL_QUERY_WRITE_BALLING_EVENT
Writes the last Balling dosing event to the database.
SQL_QUERY_WRITE_DATA
Writes the time-based data into the database.
SQL_QUERY_WRITE_FEED_EVENT
Inserts data of one feed event into the database.
SQL_QUERY_WRITE_HEATING_STATS
Writes the heating statistical data into the database. If there is already data for the given date, the data will not be inserted. Instead, the existing entry will be updated.
SQL_QUERY_WRITE_REFILL_EVENT
Writes the last refill event to the database.
SQL_TABLE_FEEDLOG
Definition of table name for feed log
SQL_TABLE_FEEDPATTERNS
Definition of table name for feed patterns
SQL_TABLE_FEEDSCHEDULE
Definition of table name for feed schedule