New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
statement.split(";") cannot be used with strings which contains symbo… #24
Conversation
… Charset and don't use default-value.
…l ";" like "vasya;petya". I think, it would be better to check for the end of line after ";" symbol. At least we would have an opportunity to use semicolons in text.
@olamy ? |
@stephenc @seblm @ajs6f @giejay @djarnis73 @Willem1987 @dmitrymurashenkov |
Looks good, but unfortunately I do not have the access rights to merge it |
This is not a fix in my opinion, it will quickly break with a cryptic error message (like today), I have a version that uses the cql lexer, so it should handle any wellformed cql. But I did not have time to polish it into a PR. The splitter code looks like this: protected static String[] splitStatementsUsingCqlLexer(String statements) {
ANTLRStringStream stream = new ANTLRStringStream(statements);
CqlLexer lexer = new CqlLexer(stream);
ArrayList<String> statementList = new ArrayList<String>();
StringBuffer currentStatement = new StringBuffer();
boolean inComment;
// Not the prettiest code i ever wrote, but it gets the job done.
for (Token token = lexer.nextToken(); token.getType() != Token.EOF; token = lexer.nextToken()) {
if (token.getText().equals(";")) {
// when we meet a ; terminate current statement and prepare the next
currentStatement.append(";");
statementList.add(currentStatement.toString());
currentStatement = new StringBuffer();
} else if (token.getType() == CqlLexer.STRING_LITERAL) {
// If we meet a string we should quote it and escape any enclosed ' as ''
currentStatement.append("'");
// TODO: There must be a cassandra util method somewhere that escapes a string for sql
currentStatement.append(token.getText().replaceAll("'", "''"));
currentStatement.append("'");
} else {
currentStatement.append(token.getText());
}
}
if (currentStatement.length() > 0 && currentStatement.toString().trim().length() > 0) {
statementList.add(currentStatement.toString());
}
return statementList.toArray(new String[statementList.size()]);
} |
Thanks. I will try to update my pull request with your code. |
This will use the cql lexer instead of blindly splitting on ;
I have pushed my changes to my clone, you can see full commit here: djarnis73@0ed68b2 i can make a PR for it if it looks good to you. |
@djarnis73 Your code much better but it is not finished yet. It does not work with my cql-code from my job for which I trying to adapt the plugin. And it still has problems with comments. I will try to fix it. I will make a pull request when I finish. |
Conflicts: src/main/java/org/codehaus/mojo/cassandra/AbstractCqlExecMojo.java
How about now? |
@stephenc @seblm @ajs6f @giejay @djarnis73 @Willem1987 @dmitrymurashenkov @olamy |
* It is not enabled by default since has not been extensively tested. | ||
* | ||
* @parameter default-value=false | ||
* @since 3.6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since should be bumped to 3.7, since 3.6 is already released.
Fixed. |
@stephenc @seblm @ajs6f @giejay @djarnis73 @Willem1987 @dmitrymurashenkov @olamy |
I don't know why you think I can merge your work. I have no role in this project and have never contributed to it. |
I think It is better to fork this repo and produce my own version of this plugin. I have really no idea whom and how should I push to force him to merge this branch. |
…l ";" like "vasya;petya". I think, it would be better to check for the end of line after ";" symbol. At least we would have an opportunity to use semicolons in text.
Example for test:
https://github.com/urvanov-ru/cassandra-maven-plugin-semicolon-test