Software / code / prosody
Comparison
plugins/mod_storage_sql.lua @ 12600:3d3a0c4e2662
Merge 0.12->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 29 Jul 2022 17:10:31 +0200 |
| parent | 12595:0572b6e604a3 |
| parent | 12599:5aafcf6a0730 |
| child | 12631:9524bb7f3944 |
comparison
equal
deleted
inserted
replaced
| 12596:78f874441e21 | 12600:3d3a0c4e2662 |
|---|---|
| 541 local ok, result = engine:transaction(function() | 541 local ok, result = engine:transaction(function() |
| 542 local sql_query = [[ | 542 local sql_query = [[ |
| 543 SELECT DISTINCT "with", COUNT(*), MIN("when"), MAX("when") | 543 SELECT DISTINCT "with", COUNT(*), MIN("when"), MAX("when") |
| 544 FROM "prosodyarchive" | 544 FROM "prosodyarchive" |
| 545 WHERE %s | 545 WHERE %s |
| 546 GROUP BY "with" | 546 GROUP BY "with"; |
| 547 ORDER BY "sort_id" %s%s; | |
| 548 ]]; | 547 ]]; |
| 549 local args = { host, user or "", store, }; | 548 local args = { host, user or "", store, }; |
| 550 local where = { "\"host\" = ?", "\"user\" = ?", "\"store\" = ?", }; | 549 local where = { "\"host\" = ?", "\"user\" = ?", "\"store\" = ?", }; |
| 551 | 550 |
| 552 archive_where(query, args, where); | 551 archive_where(query, args, where); |
| 555 | 554 |
| 556 if query.limit then | 555 if query.limit then |
| 557 args[#args+1] = query.limit; | 556 args[#args+1] = query.limit; |
| 558 end | 557 end |
| 559 | 558 |
| 560 sql_query = sql_query:format(t_concat(where, " AND "), query.reverse | 559 sql_query = sql_query:format(t_concat(where, " AND ")); |
| 561 and "DESC" or "ASC", query.limit and " LIMIT ?" or ""); | |
| 562 return engine:select(sql_query, unpack(args)); | 560 return engine:select(sql_query, unpack(args)); |
| 563 end); | 561 end); |
| 564 if not ok then return ok, result end | 562 if not ok then return ok, result end |
| 565 local counts = {}; | 563 local counts = {}; |
| 566 local earliest, latest = {}, {}; | 564 local earliest, latest = {}, {}; |