PerfectlySoft / Perfect-MySQL

A stand-alone Swift wrapper around the MySQL client library, enabling access to MySQL servers.
https://www.perfect.org
Apache License 2.0
128 stars 61 forks source link

Added method to get field names #13

Closed dannylewis-sheffield closed 8 years ago

dannylewis-sheffield commented 8 years ago

Get column names so we can do something link the following with results:

let results = mysqlStatement.results()

let fieldNames = mysqlStatement.fieldNames()

var arrayResults: [[String:Any]] = []

results.forEachRow { row in

    var rowDictionary = [String: Any]()

    var i = 0

    while i != results.numFields {
        rowDictionary[fieldNames[i]!] = row[i]!
        i += 1
    }

    arrayResults.append(rowDictionary)

}