Kitura / Kitura/SwiftKueryMySQL

Execution of queries without prepare statement needed

Open
#55 1 comment 0 reactions 1 assignee Claimed by @adam-rocska View on GitHub
enhancement
Dominant language
Swift
Stars
34
Forks
13
PR merge metrics
No merged PRs in 30d

Description

Hello, I found that some mysql statements cannot be "prepared". For example:

`PREPARE mystmt FROM 'LOCK TABLE mytable READ';`

returns error:

> Error Code: 1295. This command is not supported in the prepared statement protocol yet

For such cases, we need a way of executing statements that bypass the PREPARE STATEMENT phase.

As a temporary workaround, I have created an extension and added the method below. It is based on the existing MySQLConnection.executionTransaction(). However, there is one problem, self.mysql is not public and cannot be accessed from an extension.

In my case, the problem can be either solved by adding an execute method that does not prepare the statement (as the one I wrote), or by making the mysql variable accessible from extensions, so I can use my own method.

Ideally, both changes would be welcomed!

Thank you!
Javier.-

```swift
public func executeSimple(command: String, errorMessage: String, onCompletion: @escaping ((QueryResult) -> ())) {

guard let mysql = self.mysql else {
return runCompletionHandler(.error(QueryError.connection("Not connected, call connect() first")), onCompletion: onCompletion)
}

DispatchQueue.global().async {
mysql_thread_init()
if mysql_query(mysql, command) == 0 {
mysql_thread_end()
return self.runCompletionHandler(.successNoData, onCompletion: onCompletion)
} else {
let error = self.getError(mysql)
mysql_thread_end()
return self.runCompletionHandler(.error(QueryError.databaseError("\(errorMessage): \(error)")), onCompletion: onCompletion)
}
}
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.