Skip to content

Commit

Permalink
print error if something goes wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
123FLO321 authored Oct 5, 2018
1 parent 67782e7 commit c7825ae
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions Sources/MySQLSessions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,20 @@ public struct MySQLSessions {
let server = connect()
let params = [token]
let lastStatement = MySQLStmt(server)
var _ = lastStatement.prepare(statement: "SELECT token,userid,created, updated, idle, data, ipaddress, useragent FROM \(MySQLSessionConnector.table) WHERE token = ?")
let statement = "SELECT token,userid,created, updated, idle, data, ipaddress, useragent FROM \(MySQLSessionConnector.table) WHERE token = ?"

if !lastStatement.prepare(statement: statement) {
Log.error(message: "[MySQLSessions] Failed to prepare statement: \(lastStatement.errorMessage()) while \(statement)")
}

for p in params {
lastStatement.bindParam("\(p)")
}

_ = lastStatement.execute()

if !lastStatement.execute() {
Log.error(message: "[MySQLSessions] Failed to execute statement: \(lastStatement.errorMessage()) while \(statement)")
}

let result = lastStatement.results()

_ = result.forEachRow { row in
Expand Down Expand Up @@ -160,19 +166,20 @@ public struct MySQLSessions {

func exec(_ statement: String, params: [Any]) {
let server = connect()
var lastStatement = MySQLStmt(server)
defer { lastStatement.close() }
var _ = lastStatement.prepare(statement: statement)
// print(server.errorMessage())
let lastStatement = MySQLStmt(server)
if !lastStatement.prepare(statement: statement) {
Log.error(message: "[MySQLSessions] Failed to prepare statement: \(lastStatement.errorMessage()) while \(statement)")
}

for p in params {
lastStatement.bindParam("\(p)")
}

_ = lastStatement.execute()
if !lastStatement.execute() {
Log.error(message: "[MySQLSessions] Failed to execute statement: \(lastStatement.errorMessage()) while \(statement)")
}

let _ = lastStatement.results()
server.close()
}

func isError(_ errorMsg: String) -> Bool {
Expand All @@ -184,6 +191,3 @@ public struct MySQLSessions {
}

}



0 comments on commit c7825ae

Please sign in to comment.