diff options
-rw-r--r-- | lib/impure/db_mysql.nim | 8 | ||||
-rw-r--r-- | lib/impure/db_postgres.nim | 5 | ||||
-rw-r--r-- | lib/impure/db_sqlite.nim | 5 |
3 files changed, 12 insertions, 6 deletions
diff --git a/lib/impure/db_mysql.nim b/lib/impure/db_mysql.nim index dab84c2d5..cd2be2ff9 100644 --- a/lib/impure/db_mysql.nim +++ b/lib/impure/db_mysql.nim @@ -212,8 +212,8 @@ proc close*(db: TDbConn) {.tags: [FDb].} = ## closes the database connection. if db != nil: mysql.close(db) -proc open*(connection, user, password, database: string): TDbConn {. - tags: [FDb].} = +proc open*(connection, user, password, database: string, + charset: string = "utf8"): TDbConn {.tags: [FDb].} = ## opens a database connection. Raises `EDb` if the connection could not ## be established. result = mysql.init(nil) @@ -229,3 +229,7 @@ proc open*(connection, user, password, database: string): TDbConn {. var errmsg = $mysql.error(result) db_mysql.close(result) dbError(errmsg) + if mysql.set_character_set(result, charset) == 0: + var errmsg = $mysql.error(result) + db_mysql.close(result) + dbError(errmsg) diff --git a/lib/impure/db_postgres.nim b/lib/impure/db_postgres.nim index d8ccc4c16..a42432a7d 100644 --- a/lib/impure/db_postgres.nim +++ b/lib/impure/db_postgres.nim @@ -239,8 +239,8 @@ proc close*(db: TDbConn) {.tags: [FDb].} = ## closes the database connection. if db != nil: pqfinish(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. ## @@ -260,3 +260,4 @@ proc open*(connection, user, password, database: string): TDbConn {. ## the nim db api. result = pqsetdbLogin(nil, nil, nil, nil, database, user, password) if pqStatus(result) != CONNECTION_OK: dbError(result) # result = nil + if pqsetClientEncoding(result, charset) != 0: dbError(result) \ No newline at end of file diff --git a/lib/impure/db_sqlite.nim b/lib/impure/db_sqlite.nim index bf1ce75ef..6873e35f7 100644 --- a/lib/impure/db_sqlite.nim +++ b/lib/impure/db_sqlite.nim @@ -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) |