From 4998c99d050430c51f0d0d51ea6fc2fabc4ae1cb Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Tue, 17 Mar 2015 01:32:26 +0100 Subject: [PATCH] Merge pull request #2337 from kemege/db_charset Add character set options when opening DB connection, default to UTF-8 --- src/db_sqlite.nim | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/db_sqlite.nim b/src/db_sqlite.nim index bf1ce75ef7..4be692f390 100644 --- a/src/db_sqlite.nim +++ b/src/db_sqlite.nim @@ -192,7 +192,19 @@ proc open*(connection, user, password, database: string): TDbConn {. result = db else: dbError(db) - + +proc setEncoding*(connection: TDbConn, encoding: string): bool {. + tags: [FDb].} = + ## sets the encoding of a database connection, returns true for + ## success, false for failure. + ## + ## Note that the encoding cannot be changed once it's been set. + ## According to SQLite3 documentation, any attempt to change + ## the encoding after the database is created will be silently + ## ignored. + exec(connection, sql"PRAGMA encoding = ?", [encoding]) + result = connection.getValue(sql"PRAGMA encoding") == encoding + when isMainModule: var db = open("db.sql", "", "", "") exec(db, sql"create table tbl1(one varchar(10), two smallint)", [])