Fix a few deprecation warnings

This commit is contained in:
def
2015-07-11 14:39:19 +02:00
parent 4246f660ea
commit c50b5b62ef
32 changed files with 53 additions and 65 deletions

View File

@@ -1,6 +1,6 @@
# Backend for a simple todo program with sqlite persistence.
#
# Most procs dealing with a TDbConn object may raise an EDb exception.
# Most procs dealing with a DbConn object may raise an EDb exception.
import db_sqlite, parseutils, strutils, times
@@ -42,7 +42,7 @@ proc initDefaults*(params: var TPagedParams) =
params.showChecked = false
proc openDatabase*(path: string): TDbConn =
proc openDatabase*(path: string): DbConn =
## Creates or opens the sqlite3 database.
##
## Pass the path to the sqlite database, if the database doesn't exist it
@@ -86,7 +86,7 @@ proc getModificationDate*(todo: TTodo): Time =
return todo.modificationDate
proc update*(todo: var TTodo; conn: TDbConn): bool =
proc update*(todo: var TTodo; conn: DbConn): bool =
## Checks the database for the object and refreshes its variables.
##
## Use this method if you (or another entity) have modified the database and
@@ -112,7 +112,7 @@ proc update*(todo: var TTodo; conn: TDbConn): bool =
echo("Something went wrong selecting for id " & $todo.id)
proc save*(todo: var TTodo; conn: TDbConn): bool =
proc save*(todo: var TTodo; conn: DbConn): bool =
## Saves the current state of text, priority and isDone to the database.
##
## Returns true if the database object was updated (in which case the
@@ -135,7 +135,7 @@ proc save*(todo: var TTodo; conn: TDbConn): bool =
# - Procs dealing directly with the database
#
proc addTodo*(conn: TDbConn; priority: int; text: string): TTodo =
proc addTodo*(conn: DbConn; priority: int; text: string): TTodo =
## Inserts a new todo into the database.
##
## Returns the generated todo object. If there is an error EDb will be raised.
@@ -149,7 +149,7 @@ proc addTodo*(conn: TDbConn; priority: int; text: string): TTodo =
result = initFromDB(todoId, text, priority, false, currentDate)
proc deleteTodo*(conn: TDbConn; todoId: int64): int64 {.discardable.} =
proc deleteTodo*(conn: DbConn; todoId: int64): int64 {.discardable.} =
## Deletes the specified todo identifier.
##
## Returns the number of rows which were affected (1 or 0)
@@ -157,7 +157,7 @@ proc deleteTodo*(conn: TDbConn; todoId: int64): int64 {.discardable.} =
result = conn.execAffectedRows(query, $todoId)
proc getNumEntries*(conn: TDbConn): int =
proc getNumEntries*(conn: DbConn): int =
## Returns the number of entries in the Todos table.
##
## If the function succeeds, returns the zero or positive value, if something
@@ -171,7 +171,7 @@ proc getNumEntries*(conn: TDbConn): int =
result = -1
proc getPagedTodos*(conn: TDbConn; params: TPagedParams;
proc getPagedTodos*(conn: DbConn; params: TPagedParams;
page = 0'i64): seq[TTodo] =
## Returns the todo entries for a specific page.
##
@@ -210,7 +210,7 @@ proc getPagedTodos*(conn: TDbConn; params: TPagedParams;
row[3].parseBool, Time(row[4].parseInt)))
proc getTodo*(conn: TDbConn; todoId: int64): ref TTodo =
proc getTodo*(conn: DbConn; todoId: int64): ref TTodo =
## Returns a reference to a TTodo or nil if the todo could not be found.
var tempTodo: TTodo
tempTodo.id = todoId

View File

@@ -3,7 +3,7 @@
import backend, db_sqlite, strutils, times
proc showPagedResults(conn: TDbConn; params: TPagedParams) =
proc showPagedResults(conn: DbConn; params: TPagedParams) =
## Shows the contents of the database in pages of specified size.
##
## Hmm... I guess this is more of a debug proc which should be moved outside,

View File

@@ -191,7 +191,7 @@ proc parseCmdLine(): TParamConfig =
abort("Used list options, but didn't specify the list command.", 10)
proc generateDatabaseRows(conn: TDbConn) =
proc generateDatabaseRows(conn: DbConn) =
## Adds some rows to the database ignoring errors.
discard conn.addTodo(1, "Watch another random youtube video")
discard conn.addTodo(2, "Train some starcraft moves for the league")
@@ -209,7 +209,7 @@ proc generateDatabaseRows(conn: TDbConn) =
echo("Generated some entries, they were added to your database.")
proc listDatabaseContents(conn: TDbConn; listParams: TPagedParams) =
proc listDatabaseContents(conn: DbConn; listParams: TPagedParams) =
## Dumps the database contents formatted to the standard output.
##
## Pass the list/filter parameters parsed from the commandline.
@@ -239,7 +239,7 @@ proc listDatabaseContents(conn: TDbConn; listParams: TPagedParams) =
todo.text])
proc deleteOneTodo(conn: TDbConn; todoId: int64) =
proc deleteOneTodo(conn: DbConn; todoId: int64) =
## Deletes a single todo entry from the database.
let numDeleted = conn.deleteTodo(todoId)
if numDeleted > 0:
@@ -248,7 +248,7 @@ proc deleteOneTodo(conn: TDbConn; todoId: int64) =
quit("Couldn't delete todo id " & $todoId, 11)
proc deleteAllTodos(conn: TDbConn) =
proc deleteAllTodos(conn: DbConn) =
## Deletes all the contents from the database.
##
## Note that it would be more optimal to issue a direct DELETE sql statement
@@ -273,7 +273,7 @@ proc deleteAllTodos(conn: TDbConn) =
echo("Deleted $1 todo entries from database." % $counter)
proc setTodoCheck(conn: TDbConn; todoId: int64; value: bool) =
proc setTodoCheck(conn: DbConn; todoId: int64; value: bool) =
## Changes the check state of a todo entry to the specified value.
let
newState = if value: "checked" else: "unchecked"
@@ -293,7 +293,7 @@ proc setTodoCheck(conn: TDbConn; todoId: int64; value: bool) =
quit("Error updating todo id $1 to $2." % [$todoId, newState])
proc addTodo(conn: TDbConn; priority: int; tokens: seq[string]) =
proc addTodo(conn: DbConn; priority: int; tokens: seq[string]) =
## Adds to the database a todo with the specified priority.
##
## The tokens are joined as a single string using the space character. The