Software / code / prosody
Comparison
plugins/mod_storage_sql.lua @ 10031:17c175ad65f9
mod_storage_sql: Correctly return item-not-found error
`return ok, err` comes out as `transaction_ok, ok, err`
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 28 May 2019 00:46:24 +0200 |
| parent | 10020:deb68066c7aa |
| child | 10032:de5ab807e438 |
comparison
equal
deleted
inserted
replaced
| 10030:98ef41a60fc3 | 10031:17c175ad65f9 |
|---|---|
| 365 local cache_key = jid_join(username, host, self.store); | 365 local cache_key = jid_join(username, host, self.store); |
| 366 local total = archive_item_count_cache:get(cache_key); | 366 local total = archive_item_count_cache:get(cache_key); |
| 367 if total ~= nil and query.limit == 0 and query.start == nil and query.with == nil and query["end"] == nil and query.key == nil then | 367 if total ~= nil and query.limit == 0 and query.start == nil and query.with == nil and query["end"] == nil and query.key == nil then |
| 368 return noop, total; | 368 return noop, total; |
| 369 end | 369 end |
| 370 local ok, result = engine:transaction(function() | 370 local ok, result, err = engine:transaction(function() |
| 371 local sql_query = [[ | 371 local sql_query = [[ |
| 372 SELECT "key", "type", "value", "when", "with" | 372 SELECT "key", "type", "value", "when", "with" |
| 373 FROM "prosodyarchive" | 373 FROM "prosodyarchive" |
| 374 WHERE %s | 374 WHERE %s |
| 375 ORDER BY "sort_id" %s%s; | 375 ORDER BY "sort_id" %s%s; |
| 405 | 405 |
| 406 sql_query = sql_query:format(t_concat(where, " AND "), query.reverse | 406 sql_query = sql_query:format(t_concat(where, " AND "), query.reverse |
| 407 and "DESC" or "ASC", query.limit and " LIMIT ?" or ""); | 407 and "DESC" or "ASC", query.limit and " LIMIT ?" or ""); |
| 408 return engine:select(sql_query, unpack(args)); | 408 return engine:select(sql_query, unpack(args)); |
| 409 end); | 409 end); |
| 410 if not ok then return ok, result end | 410 if not ok then return ok, result; end |
| 411 if not result then return nil, err; end | |
| 411 return function() | 412 return function() |
| 412 local row = result(); | 413 local row = result(); |
| 413 if row ~= nil then | 414 if row ~= nil then |
| 414 local value, err = deserialize(row[2], row[3]); | 415 local value, err = deserialize(row[2], row[3]); |
| 415 assert(value ~= nil, err); | 416 assert(value ~= nil, err); |