@@ -84,10 +84,11 @@ public static <T> CompletableFuture<T> mapQueryAsync(String query, StatementModi
8484 }
8585
8686 /**
87- * Counts the amount of rows that fit the given query.
87+ * Gets a count, using a query which <strong>must</strong> return a long
88+ * integer value as the first column of the result set.
8889 *
8990 * @param query The query.
90- * @param modifier The {@link StatementModifier} .
91+ * @param modifier A modifier to use to set parameters for the query .
9192 * @return The column value.
9293 */
9394 public static long count (String query , StatementModifier modifier ) {
@@ -103,13 +104,18 @@ public static long count(String query, StatementModifier modifier) {
103104 }
104105
105106 /**
106- * Counts the amount of rows that fit the given query.
107+ * Gets a count, using a query which <strong>must</strong> return a long
108+ * integer value as the first column of the result set.
107109 *
108110 * @param query The query.
109111 * @return The column value.
110112 */
111113 public static long count (String query ) {
112- try (var rs = Bot .dataSource .getConnection ().createStatement ().executeQuery (query )) {
114+ try (
115+ var conn = Bot .dataSource .getConnection ();
116+ var stmt = conn .createStatement ()
117+ ) {
118+ var rs = stmt .executeQuery (query );
113119 if (!rs .next ()) return 0 ;
114120 return rs .getLong (1 );
115121 } catch (SQLException e ) {
@@ -118,6 +124,23 @@ public static long count(String query) {
118124 }
119125 }
120126
127+ /**
128+ * Convenience method similar to {@link DbActions#count(String, StatementModifier)}
129+ * which allows for getting the count from a query using simple string
130+ * formatting instead of having to define a statement modifier.
131+ * <p>
132+ * <strong>WARNING</strong>: This method should NEVER be called with
133+ * user-provided data.
134+ * </p>
135+ *
136+ * @param queryFormat The format string.
137+ * @param args The set of arguments to pass to the formatter.
138+ * @return The count.
139+ */
140+ public static long countf (String queryFormat , Object ... args ) {
141+ return count (String .format (queryFormat , args ));
142+ }
143+
121144 /**
122145 * Updates a database table.
123146 *
0 commit comments