does not handle sql comments with question mark
watercraft opened this issue · 7 comments
I had a large query that had a question mark in the SQL comments (after --). This resulted in an error "sql: expected 1 arguments, got 0". It took me a while to track this down, but the question mark is used by this driver's NumInput() function to indicate the presence of an argument. As alexbrainman/odbc doesn't have this issue I suspect there is another way to evaluate this property. For now I have removed the question mark and the query seems to be working correctly.
Thanks, @watercraft. I've actually seen this issue in the past and thought I had opened up an issue on it. This was seen with and without question marks under various circumstances. The simple solution would be to pre-parse away all comments before passing them to Vertica.
I'll work on adding that.
Parsing away all comments is not enough. Question marks can also appear in values, select * from x where c='whatever?'
. A more safe way is to tokenize the sql.
But something lopped off after -- will not affect this. In other words,
select * from x where c='whatever?' -- what happened here?
will just be transformed into:
select * from x where c="whatever?"
@watercraft, please confirm this is demonstrative of your issue.
@huebnerr What I mean is interpolate()
is very fragile as it just replaces question marks without any restriction. If the sql is select * from x where c1="whatever?" and c2=?
, and you pass one parameter. Will you replace the question mark in c1? or c2?
@watercraft What's your use_prepared_statements
setting in the connection string?
@sitingren You're right. interpolate() is pretty naive in that matter.
I have a change coming together that should fix this issue as a side effect of emulating named parameters.