Skip to content
Permalink
Browse files

[misc] metadata column name fastpath correction

  • Loading branch information
rusher committed Nov 21, 2019
1 parent 564dfc4 commit 30e52a125dc6c4b6620edb6e58d7e302ddffd141
@@ -165,22 +165,21 @@ public ColumnInformation(Buffer buffer) {
public static ColumnInformation create(String name, ColumnType type) {
byte[] nameBytes = name.getBytes();

byte[] arr = new byte[23 + 2 * nameBytes.length];
byte[] arr = new byte[19 + 2 * nameBytes.length];
int pos = 0;

// lenenc_str catalog
// lenenc_str schema
// lenenc_str table
// lenenc_str org_table
for (int i = 0; i < 4; i++) {
arr[pos++] = 1;
arr[pos++] = 0;
}

// lenenc_str name
// lenenc_str org_name
for (int i = 0; i < 2; i++) {
arr[pos++] = (byte) name.length();
arr[pos++] = (byte) nameBytes.length;
System.arraycopy(nameBytes, 0, arr, pos, nameBytes.length);
pos += nameBytes.length;
}
@@ -217,14 +216,6 @@ public static ColumnInformation create(String name, ColumnType type) {

arr[pos++] = (byte) ColumnType.toServer(type.getSqlType()).getType(); /* 1 byte : type */

arr[pos++] = (byte) len; /* 2 bytes : flags */
arr[pos++] = 0;

arr[pos++] = 0; /* decimals */

arr[pos++] = 0; /* 2 bytes filler */
arr[pos] = 0;

return new ColumnInformation(new Buffer(arr));
}

@@ -0,0 +1,21 @@
package org.mariadb.jdbc.internal.com.read.resultset;

import org.junit.Assert;
import org.junit.Test;
import org.mariadb.jdbc.internal.ColumnType;

public class ColumnInformationTest {

@Test
public void fastPathTest() {
String column4BytesUtf8 = "_\uD83D\uDE0E\uD83D\uDE0E\uD83C\uDF36\uD83C\uDF36\uD83C\uDFA4\uD83C\uDFA4\uD83E\uDD42\uD83E\uDD42";

ColumnInformation col = ColumnInformation.create(column4BytesUtf8 + column4BytesUtf8, ColumnType.STRING);
Assert.assertEquals("", col.getDatabase());
Assert.assertEquals("", col.getTable());
Assert.assertEquals("", col.getOriginalTable());
Assert.assertEquals(column4BytesUtf8 + column4BytesUtf8, col.getName());
Assert.assertEquals(column4BytesUtf8 + column4BytesUtf8, col.getOriginalName());
Assert.assertEquals(33, col.getCharsetNumber());
}
}

0 comments on commit 30e52a1

Please sign in to comment.
You can’t perform that action at this time.