Skip to content

Commit

Permalink
fix comment contains space
Browse files Browse the repository at this point in the history
  • Loading branch information
crossoverJie committed Apr 30, 2020
1 parent 760e59d commit fe3f556
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 8 deletions.
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'top.crossoverjie.opensource'
version '1.0.0-SNAPSHOT'
version '1.0.1-SNAPSHOT'

sourceCompatibility = 1.8

Expand All @@ -22,6 +22,11 @@ intellij {
}
patchPluginXml {
changeNotes """
Add change notes here.<br>
<em>most HTML tags may be used</em>"""
<div>
<p>1.0.1</p>
<ul>
<li>fix bug</li>
</ul>
</div>
"""
}
1 change: 1 addition & 0 deletions src/main/java/top/crossoverjie/plugin/core/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Constants {
static {
DB_TYPE_TO_PY.put("varchar", "String") ;
DB_TYPE_TO_PY.put("int", "Integer") ;
DB_TYPE_TO_PY.put("bigint", "Integer") ;
DB_TYPE_TO_PY.put("datetime", "DateTime") ;
DB_TYPE_TO_PY.put("decimal", "Float") ;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public List<TokenResult> tokenize(String script, Status pStatus, int pid) throws
value = (char) ch;
switch (status) {
case INIT:
result = initToken(value, result, pStatus);
result = initToken(value, result, pStatus, reader);
status = result.tokenType;
break;
case CT:
Expand Down Expand Up @@ -171,7 +171,7 @@ public List<TokenResult> tokenize(String script, Status pStatus, int pid) throws
* @param pStatus 用于递归校验状态
* @return
*/
private TokenResult initToken(char value, TokenResult result, Status pStatus) {
private TokenResult initToken(char value, TokenResult result, Status pStatus, CharArrayReader reader) {

//再次调用初始化的时候一定是状态转移后,说明可以写入一个完整的数据了。
if (result.getText().length() > 0) {
Expand All @@ -189,7 +189,8 @@ private TokenResult initToken(char value, TokenResult result, Status pStatus) {
result.tokenType = DDLTokenType.TBN;
} else if (value == '`' && pStatus == Status.BASE_FIELD_NAME) {
result.tokenType = DDLTokenType.FIELD_NAME;
} else if (value == ' ' && pStatus == Status.BASE_FIELD_TYPE) {
} else if (value == ' ' && pStatus == Status.BASE_FIELD_TYPE && ((CustomCharArrayReader) reader).frontRead(2) == '`') {
// xx4_status` varchar(64) NOT NULL COMMENT '我 HH 态' 必须得满足是空格开始,前面三位是 `
result.tokenType = DDLTokenType.FIELD_TYPE;
result.text.append(value);
} else if (value == '(' && pStatus == Status.BASE_FIELD_LEN) {
Expand Down Expand Up @@ -311,6 +312,17 @@ public int preReadNext(){
int index = pos;
return buf[index++];
}

/**
* Read value front
* @param step
* @return
*/
public int frontRead(int step){
int index = pos;
index = index - step ;
return buf[index] ;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ public void actionPerformed(ActionEvent event) {

} catch (Exception e1) {
System.err.println(e1);
Messages.showMessageDialog("Generate failure, https://github.com/crossoverJie/sqlalchemy-transfer/issues/new", "Tips", Messages.getInformationIcon());
}


Messages.showMessageDialog(filePath + "has already finished", "Tips", Messages.getInformationIcon());
Messages.showMessageDialog(filePath + " has already finished", "Tips", Messages.getInformationIcon());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,46 @@ public void tokenize10() throws IOException {
System.out.println(transfer);
}

@Test
public void tokenize11() throws IOException {
StandardDDLLexer lexer = new StandardDDLLexer();
String sql = "CREATE TABLE `xx_fee` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n" +
" `xx4_status` varchar(64) NOT NULL COMMENT '我 HH 态',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='xx表';";
List<StandardDDLLexer.TokenResult> tokenize = lexer.tokenize(sql, Status.BASE_INIT, 0);
System.out.println("base \ttoken-type \t value \t pid");
for (StandardDDLLexer.TokenResult result : tokenize) {
System.out.println(result.status() + "\t" + result.getTokenType() + "\t" + result.getText().toString() + "\t" + result.getPid());
}

String transfer = new DDLParse(sql).transfer();
System.out.println(transfer);
}

@Test
public void tokenize12() throws IOException {
StandardDDLLexer lexer = new StandardDDLLexer();
String sql = "CREATE TABLE `xx_fee` (\n" +
" `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n" +
" `xx4_status` varchar(64) NOT NULL COMMENT '时间,多个用(|)分割',\n" +
" PRIMARY KEY (`id`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='xx表';";
List<StandardDDLLexer.TokenResult> tokenize = lexer.tokenize(sql, Status.BASE_INIT, 0);
System.out.println("base \ttoken-type \t value \t pid");
for (StandardDDLLexer.TokenResult result : tokenize) {
System.out.println(result.status() + "\t" + result.getTokenType() + "\t" + result.getText().toString() + "\t" + result.getPid());
}

String transfer = new DDLParse(sql).transfer();
System.out.println(transfer);
}


@Test
public void str() throws IOException {
String sql = "CREATE TABLE `xxx_fee" ;
String sql = "`xx4_status` varchar(64) NOT NULL COMMENT '我 HH 态'" ;
CharArrayReader reader = new StandardDDLLexer.CustomCharArrayReader(sql.toCharArray());
int pre = ((StandardDDLLexer.CustomCharArrayReader) reader).preReadNext();
System.out.println((char) pre);
Expand All @@ -207,6 +243,9 @@ public void str() throws IOException {
while ((ch = reader.read()) != -1) {
value = (char) ch;
System.out.println((char) ch);
if (value == 'v'){
System.out.println("=====" + (char)((StandardDDLLexer.CustomCharArrayReader) reader).frontRead(2));
}
}


Expand Down

0 comments on commit fe3f556

Please sign in to comment.