]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Ensure that sqlcounter queries return 0 if there are no matching records
authorNick Porter <nick@portercomputing.co.uk>
Wed, 14 Feb 2024 11:39:39 +0000 (11:39 +0000)
committerNick Porter <nick@portercomputing.co.uk>
Thu, 15 Feb 2024 16:32:34 +0000 (16:32 +0000)
raddb/mods-config/sql/counter/mysql/dailycounter.conf
raddb/mods-config/sql/counter/mysql/monthlycounter.conf
raddb/mods-config/sql/counter/postgresql/dailycounter.conf
raddb/mods-config/sql/counter/postgresql/expire_on_login.conf
raddb/mods-config/sql/counter/postgresql/monthlycounter.conf
raddb/mods-config/sql/counter/postgresql/noresetcounter.conf
raddb/mods-config/sql/counter/sqlite/dailycounter.conf
raddb/mods-config/sql/counter/sqlite/monthlycounter.conf

index 0224659f0ea0ef194c5d126626eed4296e3fc212..80bec465bac42d4cbb55a8ff1b11a398325a7cd8 100644 (file)
@@ -5,7 +5,7 @@
 #  below
 #
 query = "\
-       SELECT SUM(acctsessiontime - GREATEST((%{control.dailycounter-reset-start} - UNIX_TIMESTAMP(acctstarttime)), 0)) \
+       SELECT IFNULL(SUM(acctsessiontime - GREATEST((%{control.dailycounter-reset-start} - UNIX_TIMESTAMP(acctstarttime)), 0)), 0) \
        FROM radacct \
        WHERE username = '%{${key}}' \
        AND UNIX_TIMESTAMP(acctstarttime) + acctsessiontime > '%{control.dailycounter-reset-start}'"
@@ -16,7 +16,7 @@ query = "\
 #  is a little easier on the SQL server
 #
 #query = "\
-#      SELECT SUM(acctsessiontime) \
+#      SELECT IFNULL(SUM(acctsessiontime), 0) \
 #      FROM radacct \
 #      WHERE username = '%{${key}}' \
 #      AND acctstarttime > FROM_UNIXTIME('%{control.dailycounter-reset-start}')"
@@ -27,7 +27,7 @@ query = "\
 #  timestamp for the end of the period
 #
 #query = "\
-#      SELECT SUM(acctsessiontime) \
+#      SELECT IFNULL(SUM(acctsessiontime), 0) \
 #      FROM radacct \
 #      WHERE username = '%{${key}}' \
 #      AND acctstarttime BETWEEN FROM_UNIXTIME('%{control.dailycounter-reset-start}') AND FROM_UNIXTIME('%{control.dailycounter-reset-end}')"
index c5bbc23c3daafd1bfd689500274202a8f7efa726..92364a4d4bd31b63c9896427bb7d928e87bc350d 100644 (file)
@@ -5,7 +5,7 @@
 #  below
 #
 query = "\
-       SELECT SUM(acctsessiontime - GREATEST((%{control.monthlycounter-reset-start} - UNIX_TIMESTAMP(acctstarttime)), 0)) \
+       SELECT IFNULL(SUM(acctsessiontime - GREATEST((%{control.monthlycounter-reset-start} - UNIX_TIMESTAMP(acctstarttime)), 0)), 0) \
        FROM radacct \
        WHERE username='%{${key}}' \
        AND UNIX_TIMESTAMP(acctstarttime) + acctsessiontime > '%{control.monthlycounter-reset-start}'"
@@ -16,7 +16,7 @@ query = "\
 #  is a little easier on the SQL server
 #
 #query = "\
-#      SELECT SUM(acctsessiontime) \
+#      SELECT IFNULL(SUM(acctsessiontime), 0) \
 #      FROM radacct\
 #      WHERE username='%{${key}}' \
 #      AND acctstarttime > FROM_UNIXTIME('%{control.monthlycounter-reset-start}')"
@@ -27,7 +27,7 @@ query = "\
 #  timestamp for the end of the period
 #
 #query = "\
-#      SELECT SUM(acctsessiontime) \
+#      SELECT IFNULL(SUM(acctsessiontime), 0) \
 #      FROM radacct \
 #      WHERE username='%{${key}}' \
 #      AND acctstarttime BETWEEN FROM_UNIXTIME('%{control.monthlycounter-reset-start}') \
index 6347291cf20cf4482a87e44a5662cea445c3f5dd..3fc51ada81cbba6ecc5b1aecb3bac6c434900aa4 100644 (file)
@@ -5,7 +5,7 @@
 #  below
 #
 query = "\
-       SELECT SUM(AcctSessionTime - GREATEST((%{control.dailycounter-reset-start} - EXTRACT(epoch FROM AcctStartTime)), 0)) \
+       SELECT COALESCE(SUM(AcctSessionTime - GREATEST((%{control.dailycounter-reset-start} - EXTRACT(epoch FROM AcctStartTime)), 0)), 0) \
        FROM radacct \
        WHERE UserName='%{${key}}' \
        AND EXTRACT(epoch FROM AcctStartTime) + AcctSessionTime > '%{control.dailycounter-reset-start}'"
@@ -16,7 +16,7 @@ query = "\
 #  is a little easier on the SQL server
 #
 #query = "\
-#      SELECT SUM(AcctSessionTime) \
+#      SELECT COALESCE(SUM(AcctSessionTime), 0) \
 #      FROM radacct \
 #      WHERE UserName='%{${key}}' \
 #      AND EXTRACT(epoch FROM AcctStartTime) > '%{control.dailycounter-reset-start}'"
@@ -27,7 +27,7 @@ query = "\
 #  timestamp for the end of the period
 #
 #query = "\
-#      SELECT SUM(AcctSessionTime) \
+#      SELECT COALESCE(SUM(AcctSessionTime), 0) \
 #      FROM radacct \
 #      WHERE UserName='%{${key}}' \
 #      AND EXTRACT(epoch FROM AcctStartTime) BETWEEN '%{control.dailycounter-reset-start}' \
index 6ec4c4e969a858a2cd6316ab1d823f8c9e28c3f6..f92bba328403b25b8378dadbfc01e6156ace3312 100644 (file)
@@ -1,5 +1,5 @@
 query = "\
-       SELECT EXTRACT(EPOCH FROM (NOW() - acctstarttime)) \
+       SELECT COALESCE(EXTRACT(EPOCH FROM (NOW() - acctstarttime)), 0) \
        FROM radacct \
        WHERE UserName='%{${key}}' \
        ORDER BY acctstarttime \
index 9f628d8d46f6f3e8915b7f0f78b077464c7befa1..3ded21809c307e399ae0de2dca92b3dfd2766e7a 100644 (file)
@@ -3,7 +3,7 @@
 #  involves more work for the SQL server than those
 #  below
 query = "\
-       SELECT SUM(AcctSessionTime - GREATEST((%{control.monthlycounter-reset-start} - EXTRACT(epoch FROM AcctStartTime)), 0)) \
+       SELECT COALESCE(SUM(AcctSessionTime - GREATEST((%{control.monthlycounter-reset-start} - EXTRACT(epoch FROM AcctStartTime)), 0)), 0) \
        FROM radacct \
        WHERE UserName='%{${key}}' \
        AND EXTRACT(epoch FROM AcctStartTime) + AcctSessionTime > '%{control.monthlycounter-reset-start}'"
@@ -14,7 +14,7 @@ query = "\
 #  is a little easier on the SQL server
 #
 #query = "\
-#      SELECT SUM(AcctSessionTime) \
+#      SELECT COALESCE(SUM(AcctSessionTime), 0) \
 #      FROM radacct \
 #      WHERE UserName='%{${key}}' \
 #      AND EXTRACT(epoch FROM AcctStartTime) > '%{control.monthlycounter-reset-start}'"
@@ -25,7 +25,7 @@ query = "\
 #  timestamp for the end of the period
 #
 #query = "\
-#      SELECT SUM(AcctSessionTime) \
+#      SELECT COALESCE(SUM(AcctSessionTime), 0) \
 #      FROM radacct \
 #      WHERE UserName='%{${key}}' \
 #      AND EXTRACT(epoch FROM AcctStartTime) BETWEEN '%{control.monthlycounter-reset-start}' AND '%{control.monthlycounter-reset-end}'"
index ac5182e62981afa6e1cd592c8833affa52f2b7df..a82ada26935d2d4565b275fe9d3a6b28995e409e 100644 (file)
@@ -1,4 +1,4 @@
 query = "\
-       SELECT SUM(AcctSessionTime) \
+       SELECT COALESCE(SUM(AcctSessionTime), 0) \
        FROM radacct \
        WHERE UserName='%{${key}}'"
index e657dce5c3b7aa7198465a108049b7822ed4dc35..4a5fa7267451018443317ceb5d1da2cb44b21144 100644 (file)
@@ -5,7 +5,7 @@
 #  below
 #
 query = "\
-       SELECT SUM(acctsessiontime - GREATEST((%{control.dailycounter-reset-start} - strftime('%%s', acctstarttime)), 0)) \
+       SELECT IFNULL(SUM(acctsessiontime - GREATEST((%{control.dailycounter-reset-start} - strftime('%%s', acctstarttime)), 0)), 0) \
        FROM radacct \
        WHERE username = '%{${key}}' \
        AND (strftime('%%s', acctstarttime) + acctsessiontime) > %{control.dailycounter-reset-start}"
@@ -16,7 +16,7 @@ query = "\
 #  is a little easier on the SQL server
 #
 #query = "\
-#      SELECT SUM(acctsessiontime) \
+#      SELECT IFNULL(SUM(acctsessiontime), 0) \
 #      FROM radacct \
 #      WHERE \username = '%{${key}}' \
 #      AND acctstarttime > %{control.dailycounter-reset-start}"
@@ -27,7 +27,7 @@ query = "\
 #  timestamp for the end of the period
 #
 #query = "\
-#      SELECT SUM(acctsessiontime) FROM radacct \
+#      SELECT IFNULL(SUM(acctsessiontime), 0) FROM radacct \
 #      WHERE username = '%{${key}}' \
 #      AND acctstarttime BETWEEN %{control.dailycounter-reset-start} \
 #      AND %{dailycounter-reset-end}"
index 80fd21166cda0709724fe93a01984bf3c128a4e9..f01911dcd3a55131f7e9ee81950e7e8eca525210 100644 (file)
@@ -5,7 +5,7 @@
 #  below
 #
 query = "\
-       SELECT SUM(acctsessiontime - GREATEST((%{control.monthlycounter-reset-start} - strftime('%%s', acctstarttime)), 0)) \
+       SELECT IFNULL(SUM(acctsessiontime - GREATEST((%{control.monthlycounter-reset-start} - strftime('%%s', acctstarttime)), 0)), 0) \
        FROM radacct \
        WHERE username = '%{${key}}' AND \
        (strftime('%%s', acctstarttime) + acctsessiontime) > %{control.monthlycounter-reset-start}"
@@ -16,7 +16,7 @@ query = "\
 #  is a little easier on the SQL server
 #
 #query = "\
-#      SELECT SUM(acctsessiontime) \
+#      SELECT IFNULL(SUM(acctsessiontime), 0) \
 #      FROM radacct \
 #      WHERE username = '%{${key}}' \
 #      AND acctstarttime > %{control.monthlycounter-reset-start}"
@@ -27,7 +27,7 @@ query = "\
 #  timestamp for the end of the period
 #
 #query = "\
-#      SELECT SUM(acctsessiontime) \
+#      SELECT IFNULL(SUM(acctsessiontime), 0) \
 #      FROM radacct \
 #      WHERE username = '%{${key}}' \
 #      AND acctstarttime BETWEEN %{control.monthlycounter-reset-start} \