Skip to content

Commit

Permalink
isNull helper
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssaruth committed Mar 5, 2024
1 parent b201f43 commit 76e8e89
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/main/kotlin/dartzee/achievements/AchievementSqlUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import dartzee.game.GameType
import dartzee.`object`.SegmentType
import dartzee.utils.Database
import dartzee.utils.getQuotedIdStr
import dartzee.utils.isNullStatement
import java.sql.ResultSet

const val X01_ROUNDS_TABLE = "X01Rounds"
Expand Down Expand Up @@ -119,9 +120,7 @@ fun buildQualifyingDartzeeGamesTable(database: Database): String? {

val sb = StringBuilder()
sb.append(" INSERT INTO $dartzeeGames")
sb.append(
" SELECT g.RowId, COUNT(1) + 1, CASE WHEN dt.Name IS NULL THEN '' ELSE dt.Name END AS TemplateName"
)
sb.append(" SELECT g.RowId, COUNT(1) + 1, ${isNullStatement("dt.Name", "''", "TemplateName")}")
sb.append(" FROM ${EntityName.DartzeeRule} dr, ${EntityName.Game} g")
sb.append(" LEFT OUTER JOIN ${EntityName.DartzeeTemplate} dt ON (g.GameParams = dt.RowId)")
sb.append(" WHERE dr.EntityId = g.RowId")
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/dartzee/db/AchievementEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import dartzee.core.util.getSqlDateNow
import dartzee.screen.ScreenCache
import dartzee.utils.Database
import dartzee.utils.InjectedThings.mainDatabase
import dartzee.utils.isNullStatement
import java.sql.Timestamp

/**
Expand Down Expand Up @@ -50,7 +51,7 @@ class AchievementEntity(database: Database = mainDatabase) :

val sb = StringBuilder()
sb.append("SELECT ${dao.getColumnsForSelectStatement("a")}, ")
sb.append(" CASE WHEN g.LocalId IS NULL THEN -1 ELSE g.LocalId END AS LocalGameId")
sb.append(isNullStatement("g.LocalId", "-1", "LocalGameId"))
sb.append(" FROM Achievement a")
sb.append(" LEFT OUTER JOIN Game g ON (a.GameIdEarned = g.RowId)")
sb.append(" WHERE PlayerId = '$playerId'")
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/dartzee/reporting/ReportingUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fun buildBasicSqlStatement(ptTempTable: String) =
g.DartsMatchId,
g.MatchOrdinal,
dt.Name AS TemplateName,
CASE WHEN m.LocalId IS NULL THEN -1 ELSE m.LocalId END AS LocalMatchId
${isNullStatement("m.LocalId", "-1", "LocalMatchId")}
FROM
$ptTempTable pt,
${EntityName.Player} p,
Expand Down

0 comments on commit 76e8e89

Please sign in to comment.