1
0
mirror of https://github.com/Eyre-S/sekai-scores.git synced 2024-11-22 11:14:56 +08:00

fixed SekaiSong insert Song ignored its difficulties

This commit is contained in:
A.C.Sukazyo Eyre 2022-12-08 19:09:35 +08:00
parent f4a58a81db
commit 86bc530f14
Signed by: Eyre_S
GPG Key ID: C17CE40291207874
3 changed files with 33 additions and 2 deletions

View File

@ -1,7 +1,7 @@
## Project Configurations ## Project Configurations
# Proj Metadata # Proj Metadata
projVersion = 0.8 projVersion = 0.8.1
# Dependencies # Dependencies

View File

@ -2,6 +2,8 @@ package cc.sukazyo.sekai_db.table;
import cc.sukazyo.sekai_db.PostgresSession; import cc.sukazyo.sekai_db.PostgresSession;
import cc.sukazyo.sekai_db.type.SekaiDifficulties; import cc.sukazyo.sekai_db.type.SekaiDifficulties;
import cc.sukazyo.sekai_scores.Difficulty;
import cc.sukazyo.sekai_scores.Song;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -63,5 +65,24 @@ public class SekaiSongDifficulties {
else insert.setInt(7, data.plvlp); else insert.setInt(7, data.plvlp);
return insert.executeUpdate(); return insert.executeUpdate();
} }
public int insertFromSong (Difficulty difficulty, Song parent) throws SQLException {
final PreparedStatement insert = session.session.prepareStatement("""
insert into sekai_song_difficulties
(song_id, difficulty, level, notes, "lvl+", "flvl+", "plvl+")
values (?, cast(? as sekai_difficulties), ?, ?, ?, ?, ?)
""");
insert.setInt(1, parent.id());
insert.setString(2, difficulty.id());
insert.setInt(3, difficulty.level());
insert.setInt(4, difficulty.noteCount());
if (difficulty.levelPlus() == Difficulty.NULL) insert.setNull(5, Types.SMALLINT);
insert.setInt(5, difficulty.levelPlus());
if (difficulty.levelPlus_f() == Difficulty.NULL) insert.setNull(6, Types.SMALLINT);
insert.setInt(6, difficulty.levelPlus_f());
if (difficulty.levelPlus_p() == Difficulty.NULL) insert.setNull(7, Types.SMALLINT);
insert.setInt(7, difficulty.levelPlus_p());
return insert.executeUpdate();
}
} }

View File

@ -1,6 +1,7 @@
package cc.sukazyo.sekai_db.table; package cc.sukazyo.sekai_db.table;
import cc.sukazyo.sekai_db.PostgresSession; import cc.sukazyo.sekai_db.PostgresSession;
import cc.sukazyo.sekai_scores.Difficulty;
import cc.sukazyo.sekai_scores.Song; import cc.sukazyo.sekai_scores.Song;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -30,6 +31,9 @@ public class SekaiSongs {
} }
public int insert (Song song) throws SQLException { public int insert (Song song) throws SQLException {
int updated = 0;
final PreparedStatement statement = session.session.prepareStatement(""" final PreparedStatement statement = session.session.prepareStatement("""
insert into sekai_songs insert into sekai_songs
(id, unit_seq, name, producer, arranger, composer, lyricist, bpm, duration, release_date, name_alias) (id, unit_seq, name, producer, arranger, composer, lyricist, bpm, duration, release_date, name_alias)
@ -49,7 +53,13 @@ public class SekaiSongs {
if (song.releaseDate() == null) statement.setNull(10, Types.TIMESTAMP_WITH_TIMEZONE); if (song.releaseDate() == null) statement.setNull(10, Types.TIMESTAMP_WITH_TIMEZONE);
else statement.setTimestamp(10, Timestamp.from(song.releaseDate().toInstant())); else statement.setTimestamp(10, Timestamp.from(song.releaseDate().toInstant()));
statement.setArray(11, session.session.createArrayOf("text", song.nameAlias())); statement.setArray(11, session.session.createArrayOf("text", song.nameAlias()));
return statement.executeUpdate(); updated += statement.executeUpdate();
for (Difficulty difficulty : song.difficulties().getAll())
updated += SekaiSongDifficulties.as(session).insertFromSong(difficulty, song);
return updated;
} }
} }