Skip to content
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

whereClause bug? #134

Open
fowuyu opened this issue Dec 4, 2019 · 5 comments
Open

whereClause bug? #134

fowuyu opened this issue Dec 4, 2019 · 5 comments

Comments

@fowuyu
Copy link

@fowuyu fowuyu commented Dec 4, 2019

Hello,All
When I run this code:

    hsql::SelectStatement* stmt;
    hsql::SQLParserResult result;

   // The sql to parse
    std::string sql("SELECT name FROM foo WHERE  name = \"test\";");
    SQLParser::parse(sql, &result);

    stmt = (hsql::SelectStatement*)result.getStatement(0);
    std::cout << stmt->whereClause->expr2->name << std::endl;
   
   // I hope expr2 type is kExprLiteralString
    std::cout << "kExprColumnRef " << stmt->whereClause->expr2->isType(kExprColumnRef) << std::endl;
    return 0;

But result is:

test
kExprColumnRef 1

I can't understand this output,Is this bug? I hope someone can tell me why this code get so strange output.

@fowuyu

This comment has been minimized.

Copy link
Author

@fowuyu fowuyu commented Dec 4, 2019

flex_lexer.l define the identifier is:

\"[^\"\n]+\" {
    // Crop the leading and trailing quote char
    yylval->sval = hsql::substr(yytext, 1, strlen(yytext)-1);
    return SQL_IDENTIFIER;
}

change to

\"[^\"\n]+\" {
    // Crop the leading and trailing quote char
    yylval->sval = hsql::substr(yytext, 0, strlen(yytext));
    return SQL_IDENTIFIER;
}

will solve my problem

@fowuyu

This comment has been minimized.

Copy link
Author

@fowuyu fowuyu commented Dec 4, 2019

I don't know whether this change is right,need your comment!

@mrks

This comment has been minimized.

Copy link
Member

@mrks mrks commented Dec 4, 2019

Have a look at the example binary and/or printStatementInfo:

./a.out "SELECT name FROM foo WHERE  name = \"test\""
Parsed successfully!
Number of statements: 1
SelectStatement
	Fields:
		name
	Sources:
		foo
	Search Conditions:
		=
			name
			test

stmt->whereClause points to a kExprOperator. Only that iterator has the column and the search string.

@fowuyu

This comment has been minimized.

Copy link
Author

@fowuyu fowuyu commented Dec 4, 2019

@mrks Hi,In your case,When you try to get "test" ’s type, you will get kExprColumnRef type;This is my problem.I think "test" type should be kExprLiteralString.

@mrks

This comment has been minimized.

Copy link
Member

@mrks mrks commented Dec 4, 2019

Ah, sorry. I misunderstood your issue. This is expected and, as far as I understand it, correct. If you look at the SQL documentation, you will find that <double quote> is used for <delimited identifier>s while a <character string literal> uses single quotes.

Some DBMSs (MySQL, sqlite) are more lenient when it comes to the quote type, as you can check on SQLFiddle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.