Skip to content

Commit

Permalink
Fix #160
Browse files Browse the repository at this point in the history
When first value of select is empty, decoder assumes it is ok packet (like eof)
for various cases
the fix is to check the state of the query, if this is the middle of query
treat it as query processing and not ok packet
  • Loading branch information
oshai committed Oct 29, 2019
1 parent 481a1e8 commit c351da5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class MySQLFrameDecoder(val charset: Charset, private val connectionId: String)
private var processedParams = 0L
var totalColumns = 0L
var processedColumns = 0L
private var expectedColDefMsgCount = 0L;
private var expectedColDefMsgCount = 0L

private var hasReadColumnsCount = false

Expand Down Expand Up @@ -110,6 +110,7 @@ class MySQLFrameDecoder(val charset: Charset, private val connectionId: String)
}

private fun handleCommonFlow(messageType: Byte, slice: ByteBuf, out: MutableList<Any>) {
logger.trace { "got message type $messageType" }
val decoder = when (messageType.toInt()) {
ServerMessage.Error -> {
this.clear()
Expand Down Expand Up @@ -144,15 +145,17 @@ class MySQLFrameDecoder(val charset: Charset, private val connectionId: String)
} else {
// workaround for MemSQL ColDef messages being exactly 19 bytes, all ZEROS.
slice.resetReaderIndex()
expectedColDefMsgCount--;
expectedColDefMsgCount--
this.columnDecoder
}
} else {
if (this.isPreparedStatementExecuteRows) {
null
} else {
this.clear()
this.okDecoder
when {
this.isPreparedStatementExecuteRows -> null
this.isInQuery -> null
else -> {
this.clear()
this.okDecoder
}
}
}
}
Expand Down Expand Up @@ -188,7 +191,7 @@ class MySQLFrameDecoder(val charset: Charset, private val connectionId: String)
this.hasReadColumnsCount = true
this.totalColumns = result.columnsCount.toLong()
this.totalParams = result.paramsCount.toLong()
this.expectedColDefMsgCount = this.totalColumns + this.totalParams;
this.expectedColDefMsgCount = this.totalColumns + this.totalParams
}
is ParamAndColumnProcessingFinishedMessage -> {
this.clear()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.github.jasync.sql.db.mysql

import org.junit.Test

class QueryMoreSpec : ConnectionHelper() {




@Test
fun `"connection" should "be able to select with empty value" `() {
withConnection { connection ->
executeQuery(connection, "select '' as x,'1' as y ")
}

}

}


4 changes: 2 additions & 2 deletions versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ ext.sl4j_version='1.7.25'
ext.joda_version='2.9.7'
ext.joda_convert_version='1.8.1'
ext.netty_version='4.1.34.Final'
ext.kotlin_logging_version='1.6.23'
ext.kotlin_logging_version='1.7.6'

// test dependencines
// test dependencies

ext.assertj_version='3.11.1'
ext.mockk_version='1.9'
Expand Down

0 comments on commit c351da5

Please sign in to comment.