From 4396270fc7c447fa7ce9478a6bf9682ba7c496a7 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sun, 22 Dec 2013 20:56:33 +0400 Subject: [PATCH 1/2] 'Connection' argument in 'Open' was not used, so MySQL host and port were always default ones. Now 'Connection' is treated as 'host:port'. --- lib/impure/db_mysql.nim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/impure/db_mysql.nim b/lib/impure/db_mysql.nim index 91cf8a5ebd..c27be28178 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) From 51d2384e1aa890b243f14a80ae2a126308a37d9f Mon Sep 17 00:00:00 2001 From: Miguel Date: Mon, 10 Feb 2014 18:41:39 +0400 Subject: [PATCH 2/2] Fix for db_mysql.Open. 'Connection' argument in 'Open' was not used, so MySQL host and port were always default ones. Now 'Connection' is treated as 'host:port'. --- lib/impure/db_mysql.nim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/impure/db_mysql.nim b/lib/impure/db_mysql.nim index 1489a04019..32cda3e4dc 100644 --- a/lib/impure/db_mysql.nim +++ b/lib/impure/db_mysql.nim @@ -87,7 +87,7 @@ proc newRow(L: int): TRow = proc properFreeResult(sqlres: mysql.PRES, row: cstringArray) = if row != nil: - while mysql.FetchRow(sqlres) != nil: nil + while mysql.FetchRow(sqlres) != nil: discard mysql.FreeResult(sqlres) iterator fastRows*(db: TDbConn, query: TSqlQuery, @@ -194,13 +194,13 @@ 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") - var - cnctn = connection.split(':') - host = cnctn[0] - port: int32 = 3306 - if cnctn.len > 1: - port = int32((cnctn[1]).parseInt()) + if result == nil: dbError("could not open database connection") + let + colonPos = connection.find(':') + host = if colonPos < 0: connection + else: substr(connection, 0, colonPos-1) + port: int32 = if colonPos < 0: 0'i32 + else: substr(connection, colonPos+1).parseInt.int32 if mysql.RealConnect(result, host, user, password, database, port, nil, 0) == nil: var errmsg = $mysql.error(result)