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'.
This commit is contained in:
parent
a6186fa486
commit
51d2384e1a
1 changed files with 8 additions and 8 deletions
|
|
@ -87,7 +87,7 @@ proc newRow(L: int): TRow =
|
||||||
|
|
||||||
proc properFreeResult(sqlres: mysql.PRES, row: cstringArray) =
|
proc properFreeResult(sqlres: mysql.PRES, row: cstringArray) =
|
||||||
if row != nil:
|
if row != nil:
|
||||||
while mysql.FetchRow(sqlres) != nil: nil
|
while mysql.FetchRow(sqlres) != nil: discard
|
||||||
mysql.FreeResult(sqlres)
|
mysql.FreeResult(sqlres)
|
||||||
|
|
||||||
iterator fastRows*(db: TDbConn, query: TSqlQuery,
|
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
|
## opens a database connection. Raises `EDb` if the connection could not
|
||||||
## be established.
|
## be established.
|
||||||
result = mysql.Init(nil)
|
result = mysql.Init(nil)
|
||||||
if result == nil: dbError("could not open database connection")
|
if result == nil: dbError("could not open database connection")
|
||||||
var
|
let
|
||||||
cnctn = connection.split(':')
|
colonPos = connection.find(':')
|
||||||
host = cnctn[0]
|
host = if colonPos < 0: connection
|
||||||
port: int32 = 3306
|
else: substr(connection, 0, colonPos-1)
|
||||||
if cnctn.len > 1:
|
port: int32 = if colonPos < 0: 0'i32
|
||||||
port = int32((cnctn[1]).parseInt())
|
else: substr(connection, colonPos+1).parseInt.int32
|
||||||
if mysql.RealConnect(result, host, user, password, database,
|
if mysql.RealConnect(result, host, user, password, database,
|
||||||
port, nil, 0) == nil:
|
port, nil, 0) == nil:
|
||||||
var errmsg = $mysql.error(result)
|
var errmsg = $mysql.error(result)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue