Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix sqlite transactions #1969

Merged
merged 1 commit into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions be1-go/internal/database/sqlite/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ func (s *SQLite) StoreRumor(rumorID int, sender string, timestamp mrumor.RumorTi
if err != nil {
return poperrors.NewDatabaseTransactionBeginErrorMsg(err.Error())
}
defer tx.Rollback()

timestampBuf, err := json.Marshal(timestamp)
if err != nil {
Expand Down Expand Up @@ -283,12 +284,12 @@ func (s *SQLite) AddMessageToMyRumor(messageID string) (int, error) {
}
defer tx.Rollback()

_, err = s.database.Exec(insertMessageToMyRumor, messageID, serverKeysPath)
_, err = tx.Exec(insertMessageToMyRumor, messageID, serverKeysPath)
if err != nil {
return -1, poperrors.NewDatabaseInsertErrorMsg("message to the current rumor: %v", err)
}
var count int
err = s.database.QueryRow(selectCountMyRumor, serverKeysPath).Scan(&count)
err = tx.QueryRow(selectCountMyRumor, serverKeysPath).Scan(&count)
if err != nil {
return -1, poperrors.NewDatabaseSelectErrorMsg("number of messages in the current rumor: %v", err)
}
Expand All @@ -310,7 +311,7 @@ func (s *SQLite) GetAndIncrementMyRumor() (bool, mrumor.ParamsRumor, error) {
}
defer tx.Rollback()

rows, err := s.database.Query(selectMyRumorMessages, true, serverKeysPath, serverKeysPath)
rows, err := tx.Query(selectMyRumorMessages, true, serverKeysPath, serverKeysPath)
if err != nil {
return false, mrumor.ParamsRumor{}, poperrors.NewDatabaseSelectErrorMsg("current rumor params: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion be1-go/internal/database/sqlite/sqlite_const.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const (
insertKeys = `INSERT INTO key (channelPath, publicKey, secretKey) VALUES (?, ?, ?)`
insertPublicKey = `INSERT INTO key (channelPath, publicKey) VALUES (?, ?)`
insertRumor = `INSERT INTO rumor (ID, sender, timestamp) VALUES (?, ?, ?)`
insertUnprocessedMessage = `INSERT INTO unprocessedMessage (messageID, channelPath, message) VALUES (?, ?, ?)`
insertUnprocessedMessage = `INSERT OR IGNORE INTO unprocessedMessage (messageID, channelPath, message) VALUES (?, ?, ?)`
insertUnprocessedMessageRumor = `INSERT INTO unprocessedMessageRumor (messageID, rumorID, sender) VALUES (?, ?, ?)`
insertMessageRumor = `INSERT INTO messageRumor (messageID, rumorID, sender) VALUES (?, ?, ?)`
tranferUnprocessedMessageRumor = `INSERT INTO messageRumor (messageID, rumorID, sender) SELECT messageID, rumorID, sender FROM unprocessedMessageRumor WHERE messageID = ?`
Expand Down
Loading