diff options
author | Miguel <leu-gim@moy-server.ru> | 2013-12-22 20:56:33 +0400 |
---|---|---|
committer | Miguel <leu-gim@moy-server.ru> | 2013-12-22 20:56:33 +0400 |
commit | 4396270fc7c447fa7ce9478a6bf9682ba7c496a7 (patch) | |
tree | 95fd7e2d466f10d9171eedc840dbf08c1d0be5b5 /lib | |
parent | 52a8226edda05f2d3baad791639a1c2fe7f103cc (diff) | |
download | Nim-4396270fc7c447fa7ce9478a6bf9682ba7c496a7.tar.gz |
'Connection' argument in 'Open' was not used, so MySQL host and port were always default ones. Now 'Connection' is treated as 'host:port'.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/impure/db_mysql.nim | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/impure/db_mysql.nim b/lib/impure/db_mysql.nim index 91cf8a5eb..c27be2817 100644 --- a/lib/impure/db_mysql.nim +++ b/lib/impure/db_mysql.nim @@ -194,9 +194,15 @@ proc Open*(connection, user, password, database: string): TDbConn {. ## opens a database connection. Raises `EDb` if the connection could not ## be established. result = mysql.Init(nil) - if result == nil: dbError("could not open database connection") - if mysql.RealConnect(result, "", user, password, database, - 0'i32, nil, 0) == nil: + if result == nil: dbError("could not open database connection") + var + cnctn = connection.split(':') + host = cnctn[0] + port: int32 = 3306 + if cnctn.len > 1: + port = int32((cnctn[1]).parseInt()) + if mysql.RealConnect(result, host, user, password, database, + port, nil, 0) == nil: var errmsg = $mysql.error(result) db_mysql.Close(result) dbError(errmsg) |