Add character set options when opening DB connection

This commit is contained in:
KeMeGe 2015-03-14 15:21:38 +08:00
commit ca8102b96d
3 changed files with 12 additions and 6 deletions

View file

@ -183,13 +183,14 @@ proc close*(db: TDbConn) {.tags: [FDb].} =
## closes the database connection.
if sqlite3.close(db) != SQLITE_OK: dbError(db)
proc open*(connection, user, password, database: string): TDbConn {.
tags: [FDb].} =
proc open*(connection, user, password, database: string,
charset: string = "UTF-8"): TDbConn {.tags: [FDb].} =
## opens a database connection. Raises `EDb` if the connection could not
## be established. Only the ``connection`` parameter is used for ``sqlite``.
var db: TDbConn
if sqlite3.open(connection, db) == SQLITE_OK:
result = db
exec(result, sql"PRAGMA encoding = ?", [charset])
else:
dbError(db)