Software /
code /
prosody
Comparison
plugins/mod_storage_sql.lua @ 5133:1443d1c37c6c
Merge 0.9->trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 19 Sep 2012 12:14:08 +0100 |
parent | 5122:b41c33dc7c36 |
parent | 5132:ce6546f867f9 |
child | 5154:429c8eeea035 |
comparison
equal
deleted
inserted
replaced
5127:cbcd173ad906 | 5133:1443d1c37c6c |
---|---|
372 return setmetatable({ store = store }, keyval_store); | 372 return setmetatable({ store = store }, keyval_store); |
373 end | 373 end |
374 return nil, "unsupported-store"; | 374 return nil, "unsupported-store"; |
375 end | 375 end |
376 | 376 |
377 function driver:list_stores(username) -- Not to be confused with the list store type | 377 function driver:stores(username) |
378 local sql = (username == true | 378 local sql = "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`" .. |
379 and "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`!=?" | 379 (username == true and "!=?" or "=?"); |
380 or "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`=?"); | |
381 if username == true or not username then | 380 if username == true or not username then |
382 username = ""; | 381 username = ""; |
383 end | 382 end |
384 local stmt, err = dosql(sql, host, username); | 383 local stmt, err = dosql(sql, host, username); |
385 if not stmt then | 384 if not stmt then |
386 return rollback(nil, err); | 385 return rollback(nil, err); |
387 end | 386 end |
388 local stores = {}; | 387 local next = stmt:rows(); |
389 for row in stmt:rows() do | 388 return commit(function() |
390 stores[#stores+1] = row[1]; | 389 local row = next(); |
391 end | 390 return row and row[1]; |
392 return commit(stores); | 391 end); |
393 end | 392 end |
394 | 393 |
395 function driver:purge(username) | 394 function driver:purge(username) |
396 local stmt, err = dosql("DELETE FROM `prosody` WHERE `host`=? AND `user`=?", host, username); | 395 local stmt, err = dosql("DELETE FROM `prosody` WHERE `host`=? AND `user`=?", host, username); |
397 if not stmt then return rollback(stmt, err); end | 396 if not stmt then return rollback(stmt, err); end |