aboutsummaryrefslogtreecommitdiff
path: root/userapi/storage/sqlite3/accounts_table.go
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2022-04-27 15:05:49 +0200
committerGitHub <noreply@github.com>2022-04-27 15:05:49 +0200
commitf023cdf8c42cc1a4bb850b478dbbf7d901b5e1bd (patch)
tree5698494b5438a721976a1f685dcd29301538a7d7 /userapi/storage/sqlite3/accounts_table.go
parentd7cc187ec00410b949ffae1625835f8ac9f36c29 (diff)
Add UserAPI storage tests (#2384)
* Add tests for parts of the userapi storage * Add tests for keybackup * Add LoginToken tests * Add OpenID tests * Add profile tests * Add pusher tests * Add ThreePID tests * Add notification tests * Add more device tests, fix numeric localpart query * Fix failing CI * Fix numeric local part query
Diffstat (limited to 'userapi/storage/sqlite3/accounts_table.go')
-rw-r--r--userapi/storage/sqlite3/accounts_table.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/userapi/storage/sqlite3/accounts_table.go b/userapi/storage/sqlite3/accounts_table.go
index e6c37e58..6c5fe307 100644
--- a/userapi/storage/sqlite3/accounts_table.go
+++ b/userapi/storage/sqlite3/accounts_table.go
@@ -65,7 +65,7 @@ const selectPasswordHashSQL = "" +
"SELECT password_hash FROM account_accounts WHERE localpart = $1 AND is_deactivated = 0"
const selectNewNumericLocalpartSQL = "" +
- "SELECT COUNT(localpart) FROM account_accounts"
+ "SELECT COALESCE(MAX(CAST(localpart AS INT)), 0) FROM account_accounts WHERE CAST(localpart AS INT) <> 0"
type accountsStatements struct {
db *sql.DB
@@ -121,6 +121,7 @@ func (s *accountsStatements) InsertAccount(
UserID: userutil.MakeUserID(localpart, s.serverName),
ServerName: s.serverName,
AppServiceID: appserviceID,
+ AccountType: accountType,
}, nil
}
@@ -177,5 +178,8 @@ func (s *accountsStatements) SelectNewNumericLocalpart(
stmt = sqlutil.TxStmt(txn, stmt)
}
err = stmt.QueryRowContext(ctx).Scan(&id)
- return
+ if err == sql.ErrNoRows {
+ return 1, nil
+ }
+ return id + 1, err
}