Skip to content

Commit

Permalink
chore: fixed errors reported by nimalyzer
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 8a503be97db5572a625bccecc336514f13bc281ce35e6f1c204ba62a61b04966
  • Loading branch information
thindil committed May 29, 2024
1 parent f41037d commit e11cc83
Showing 1 changed file with 52 additions and 43 deletions.
95 changes: 52 additions & 43 deletions src/db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ proc closeDb*(returnCode: ResultCode; db) {.sideEffect, raises: [],
quit QuitFailure
quit returnCode.int

let shellOptions: array[12, Option] = [newOption(name = "dbVersion", value = "7",
description = "Version of the database schema (read only).",
let shellOptions: array[12, Option] = [newOption(name = "dbVersion",
value = "7", description = "Version of the database schema (read only).",
valueType = OptionValType.natural, readOnly = true, defaultValue = "7"),
newOption(name = "promptCommand", value = "built-in",
description = "The command which output will be used as the prompt of shell.",
Expand Down Expand Up @@ -110,33 +110,41 @@ let shellOptions: array[12, Option] = [newOption(name = "dbVersion", value = "7"
valueType = OptionValType.boolean, readOnly = false,
defaultValue = "true")]

proc createNewDb(db): bool =
try:
if db.createAliasesDb == QuitFailure:
return false
if db.createOptionsDb == QuitFailure:
return false
if db.createHistoryDb == QuitFailure:
return false
if db.createVariablesDb == QuitFailure:
return false
if db.createPluginsDb == QuitFailure:
return false
if db.createHelpDb == QuitFailure:
return false
if db.createCompletionDb == QuitFailure:
return false
if db.createThemeDb == QuitFailure:
proc createNewDb(db): bool {.sideEffect, raises: [], tags: [ReadIOEffect,
TimeEffect, WriteDbEffect, ReadDbEffect, WriteIOEffect, RootEffect],
contractual.} =
## Create a new database for the shell
##
## * db - the connection to the newly created database
require:
db != nil
body:
try:
if db.createAliasesDb == QuitFailure:
return false
if db.createOptionsDb == QuitFailure:
return false
if db.createHistoryDb == QuitFailure:
return false
if db.createVariablesDb == QuitFailure:
return false
if db.createPluginsDb == QuitFailure:
return false
if db.createHelpDb == QuitFailure:
return false
if db.createCompletionDb == QuitFailure:
return false
if db.createThemeDb == QuitFailure:
return false
for option in shellOptions:
setOption(optionName = option.option, value = option.value,
description = option.description, valueType = option.valueType,
db = db, readOnly = (
if option.readOnly: 1 else: 0))
db.exec(query = sql(query = "PRAGMA journal_mode=WAL;"))
return true
except DbError:
return false
for option in shellOptions:
setOption(optionName = option.option, value = option.value,
description = option.description, valueType = option.valueType,
db = db, readOnly = (
if option.readOnly: 1 else: 0))
db.exec(query = sql(query = "PRAGMA journal_mode=WAL;"))
return true
except DbError:
return false

proc startDb*(dbPath: Path): DbConn {.sideEffect, raises: [], tags: [
ReadIOEffect, WriteDirEffect, DbEffect, WriteIOEffect, ReadEnvEffect,
Expand Down Expand Up @@ -211,9 +219,9 @@ proc startDb*(dbPath: Path): DbConn {.sideEffect, raises: [], tags: [
for i in shellOptions.low..shellOptions.high:
if i == 1:
continue
setOption(optionName = shellOptions[i].option, value = shellOptions[i].value,
description = shellOptions[i].description, valueType = shellOptions[i].valueType,
db = result, readOnly = (
setOption(optionName = shellOptions[i].option, value = shellOptions[
i].value, description = shellOptions[i].description,
valueType = shellOptions[i].valueType, db = result, readOnly = (
if shellOptions[i].readOnly: 1 else: 0))
of 3:
if result.updateOptionsDb(dbVersion = dbVersion) == QuitFailure:
Expand All @@ -229,32 +237,33 @@ proc startDb*(dbPath: Path): DbConn {.sideEffect, raises: [], tags: [
if result.createThemeDb == QuitFailure:
return nil
for i in [0, 8, 9, 10, 11]:
setOption(optionName = shellOptions[i].option, value = shellOptions[i].value,
description = shellOptions[i].description, valueType = shellOptions[i].valueType,
db = result, readOnly = (
setOption(optionName = shellOptions[i].option, value = shellOptions[
i].value, description = shellOptions[i].description,
valueType = shellOptions[i].valueType, db = result, readOnly = (
if shellOptions[i].readOnly: 1 else: 0))
of 4:
if result.createCompletionDb == QuitFailure:
return nil
for i in [0, 10, 11]:
setOption(optionName = shellOptions[i].option, value = shellOptions[i].value,
description = shellOptions[i].description, valueType = shellOptions[i].valueType,
db = result, readOnly = (
setOption(optionName = shellOptions[i].option, value = shellOptions[
i].value, description = shellOptions[i].description,
valueType = shellOptions[i].valueType, db = result, readOnly = (
if shellOptions[i].readOnly: 1 else: 0))
of 5:
if result.updateVariablesDb == QuitFailure:
return nil
if result.createThemeDb == QuitFailure:
return nil
for i in [0, 11]:
setOption(optionName = shellOptions[i].option, value = shellOptions[i].value,
description = shellOptions[i].description, valueType = shellOptions[i].valueType,
db = result, readOnly = (
setOption(optionName = shellOptions[i].option, value = shellOptions[
i].value, description = shellOptions[i].description,
valueType = shellOptions[i].valueType, db = result, readOnly = (
if shellOptions[i].readOnly: 1 else: 0))
of 6:
setOption(optionName = shellOptions[0].option, value = shellOptions[0].value,
description = shellOptions[0].description, valueType = shellOptions[0].valueType,
db = result, readOnly = (if shellOptions[0].readOnly: 1 else: 0))
setOption(optionName = shellOptions[0].option, value = shellOptions[
0].value, description = shellOptions[0].description,
valueType = shellOptions[0].valueType, db = result, readOnly = (
if shellOptions[0].readOnly: 1 else: 0))
of 7:
discard
else:
Expand Down

0 comments on commit e11cc83

Please sign in to comment.