Page 1 of 1

Bug: Calling TZTable.Refresh will ignore #'s in FIELDNAMEs

Posted: 30.09.2008, 01:08
by rfwoolf
I am running Firebird 2.1. I have a table with a field "ESTIMATEITEM#" - everything is working fine but if I specifically call .REFRESH it generates an error "Project XXX raised exception class EDatabaseError with message 'TABLE: Field 'ESTIMATEITEM' not found'.

As you can see it is cutting of the '#' in the SQL.
I have verified this with tests.

How to solve?

Posted: 30.09.2008, 22:30
by seawolf
Take a look at the Tokenizer.pas

Search

constructor TZWordState.Create;
begin
SetWordChars(#0, #255, False);
SetWordChars('a', 'z', True);
SetWordChars('A', 'Z', True);
SetWordChars('0', '9', True);
SetWordChars('-', '-', True);
SetWordChars('_', '_', True);
SetWordChars(#39, #39, True);
SetWordChars(Char($c0), Char($ff), True);
end;

Here is the place where add

SetWordChars('#', '#', True);

Posted: 01.10.2008, 01:19
by rfwoolf
Thanks so much seawolf. Becauase this was urgent I just went through all my fields with # in them and took out the '#' (this did unfortunately still take me a long time to do and your fix would have been much easier). Hopefully others will benefit from this in the future! :)

Posted: 01.10.2008, 08:41
by mdaems
This is dangerous, however. Didn't test this specific case, but mysql treats # as a comment marker. So this line should be added to your database specific tokenizer. (TZInterbaseWordState.Create)

Can you make a test case and add that to the bug tracker? Please add a table creation script so we don't depend on a specific FB version.

Mark

Posted: 01.10.2008, 18:08
by seawolf
A Test is almost ready, but what makes me wonder is that in Firebird # can be used as a comment .. so

Field1# as Integer

give an error, while

"Field1#" as Integer

is recognized as a valid field.

So Is it an error? Or is the normal behaviour?

Posted: 01.10.2008, 19:22
by mdaems
Well, that means the problem is not the tokenizer but the query being fired to the server. Where the sql statement is made there must be some call to IdentifierConverter.Quote. (Search for 'quote' in the component directory and you'll find some samples)
Or, if the statement is provided by the user, he should just quote himself.

Mark