未验证 提交 48cea608 编写于 作者: V Vlad Ilyushchenko 提交者: GitHub

fix(griffin): GORM sends ';' after login, making sure we reply to that. (#388)

上级 8fa21f67
...@@ -1214,6 +1214,11 @@ public class PGConnectionContext implements IOContext, Mutable { ...@@ -1214,6 +1214,11 @@ public class PGConnectionContext implements IOContext, Mutable {
prepareForNewQuery(); prepareForNewQuery();
parseQueryText(lo, limit - 1); parseQueryText(lo, limit - 1);
if (SqlKeywords.isSemicolon(queryText)) {
sendExecuteTail(TAIL_SUCCESS);
return;
}
final Object statement = factoryCache.peek(queryText); final Object statement = factoryCache.peek(queryText);
if (statement == null) { if (statement == null) {
CompiledQuery cc = compiler.compile(queryText, sqlExecutionContext); CompiledQuery cc = compiler.compile(queryText, sqlExecutionContext);
......
...@@ -46,6 +46,10 @@ public class SqlKeywords { ...@@ -46,6 +46,10 @@ public class SqlKeywords {
&& (tok.charAt(i) | 32) == 'n'; && (tok.charAt(i) | 32) == 'n';
} }
public static boolean isSemicolon(CharSequence tok) {
return tok.length() == 1 && (tok.charAt(0) | 32) == ';';
}
public static boolean isOnKeyword(CharSequence tok) { public static boolean isOnKeyword(CharSequence tok) {
if (tok.length() != 2) { if (tok.length() != 2) {
return false; return false;
......
...@@ -41,7 +41,7 @@ public class TableListRecordCursorFactory implements RecordCursorFactory { ...@@ -41,7 +41,7 @@ public class TableListRecordCursorFactory implements RecordCursorFactory {
static { static {
final GenericRecordMetadata metadata = new GenericRecordMetadata(); final GenericRecordMetadata metadata = new GenericRecordMetadata();
metadata.add(new TableColumnMetadata("tableName", ColumnType.STRING)); metadata.add(new TableColumnMetadata("table", ColumnType.STRING));
METADATA = metadata; METADATA = metadata;
} }
......
...@@ -1336,6 +1336,19 @@ public class PGJobContextTest extends AbstractGriffinTest { ...@@ -1336,6 +1336,19 @@ public class PGJobContextTest extends AbstractGriffinTest {
assertHexScript(script); assertHexScript(script);
} }
@Test
public void testGORMConnect() throws Exception {
// GORM is a Golang ORM tool
assertHexScript(
">0000005e0003000064617461626173650071646200646174657374796c650049534f2c204d44590065787472615f666c6f61745f646967697473003200757365720061646d696e00636c69656e745f656e636f64696e6700555446380000\n" +
"<520000000800000003\n" +
">700000000a717565737400\n" +
"<520000000800000000530000001154696d655a6f6e6500474d5400530000001d6170706c69636174696f6e5f6e616d6500517565737444420053000000187365727665725f76657273696f6e0031312e33005300000019696e74656765725f6461746574696d6573006f6e005a0000000549\n" +
">51000000063b00\n" +
"<43000000063b005a0000000549\n"
);
}
@Test @Test
public void testSimpleSimpleQuery() throws Exception { public void testSimpleSimpleQuery() throws Exception {
TestUtils.assertMemoryLeak(() -> { TestUtils.assertMemoryLeak(() -> {
......
...@@ -33,7 +33,7 @@ public class ShowTablesTest extends AbstractGriffinTest { ...@@ -33,7 +33,7 @@ public class ShowTablesTest extends AbstractGriffinTest {
public void testShowTablesWithSingleTable() throws Exception { public void testShowTablesWithSingleTable() throws Exception {
assertMemoryLeak(() -> { assertMemoryLeak(() -> {
compiler.compile("create table balances(cust_id int, ccy symbol, balance double)", sqlExecutionContext); compiler.compile("create table balances(cust_id int, ccy symbol, balance double)", sqlExecutionContext);
assertQuery("tableName\nbalances\n", "show tables", null, false, sqlExecutionContext, false); assertQuery("table\nbalances\n", "show tables", null, false, sqlExecutionContext, false);
}); });
} }
...@@ -41,10 +41,10 @@ public class ShowTablesTest extends AbstractGriffinTest { ...@@ -41,10 +41,10 @@ public class ShowTablesTest extends AbstractGriffinTest {
public void testShowTablesWithDrop() throws Exception { public void testShowTablesWithDrop() throws Exception {
assertMemoryLeak(() -> { assertMemoryLeak(() -> {
compiler.compile("create table balances(cust_id int, ccy symbol, balance double)", sqlExecutionContext); compiler.compile("create table balances(cust_id int, ccy symbol, balance double)", sqlExecutionContext);
assertQuery("tableName\nbalances\n", "show tables", null, false, sqlExecutionContext, false); assertQuery("table\nbalances\n", "show tables", null, false, sqlExecutionContext, false);
compiler.compile("create table balances2(cust_id int, ccy symbol, balance double)", sqlExecutionContext); compiler.compile("create table balances2(cust_id int, ccy symbol, balance double)", sqlExecutionContext);
compiler.compile("drop table balances", sqlExecutionContext); compiler.compile("drop table balances", sqlExecutionContext);
assertQuery("tableName\nbalances2\n", "show tables", null, false, sqlExecutionContext, false); assertQuery("table\nbalances2\n", "show tables", null, false, sqlExecutionContext, false);
}); });
} }
...@@ -99,7 +99,7 @@ public class ShowTablesTest extends AbstractGriffinTest { ...@@ -99,7 +99,7 @@ public class ShowTablesTest extends AbstractGriffinTest {
public void testShowTablesWithFunction() throws Exception { public void testShowTablesWithFunction() throws Exception {
assertMemoryLeak(() -> { assertMemoryLeak(() -> {
compiler.compile("create table balances(cust_id int, ccy symbol, balance double)", sqlExecutionContext); compiler.compile("create table balances(cust_id int, ccy symbol, balance double)", sqlExecutionContext);
assertQuery("tableName\nbalances\n", "select * from all_tables()", null, false, sqlExecutionContext, false); assertQuery("table\nbalances\n", "select * from all_tables()", null, false, sqlExecutionContext, false);
}); });
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册