renan-guimaraes / dwscript

Automatically exported from code.google.com/p/dwscript
0 stars 0 forks source link

FieldByName in dwsDatabase does not use case-insensitive string comparison #391

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In Delphi's DB.pas, TDataset.FieldByName uses a case-insensitive string 
comparison.  But in dwsDatabaseLibModule, FieldByName's OnEval calls into 
TDataSet.IndexOfField, which uses the = operator to test for matches instead of 
a case insensitive comparison, causing unexpected failures.

Original issue reported on code.google.com by masonwhe...@gmail.com on 13 May 2013 at 10:08

GoogleCodeExporter commented 9 years ago
Also, the DB.pas version of FieldByName raises an exception if there is no 
match.  The dwsDatabase version returns nil, which causes unexpected failures 
to be harder to debug because the problem is not detected until a later point 
in the code's execution.

Original comment by masonwhe...@gmail.com on 13 May 2013 at 10:34

GoogleCodeExporter commented 9 years ago
I haven't been using DB.pas for years, but isn't that a bug of DB.pas? Cf. 
http://stackoverflow.com/questions/153944/is-sql-syntax-case-sensitive column 
names are case-sensitive in many situations, and ORM DBs built for 
case-sensitive languages is one case where I encountered a need for 
case-sensitivity years ago.

For the exception, I see that it's FindField that doesn't raise the exception 
while FieldByName does. I'll change that.

Original comment by zar...@gmail.com on 14 May 2013 at 6:23

GoogleCodeExporter commented 9 years ago
Exception, FindField & unit test added.

Original comment by zar...@gmail.com on 14 May 2013 at 6:55

GoogleCodeExporter commented 9 years ago
According to the linked SO question, in the SQL standard, column names are case 
insensitive but some databases don't implement it properly.

From personal experience, in MS SQL Server and in Firebird, the two DBMSs I'm 
most familiar with, column names are case insensitive.  But more to the point, 
in Pascal, identifiers are case insensitive, which, combined with the behavior 
of DB.pas, means that this is definitely expected behavior for Delphi users.

Original comment by masonwhe...@gmail.com on 14 May 2013 at 3:05

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r2086.

Original comment by zar...@gmail.com on 15 May 2013 at 8:29

GoogleCodeExporter commented 9 years ago
Column names are case insensitive in most db's, however, in Postgres, you can 
define your column as "MyKinkyColumn", whenever you refer to it, you must type 
it's name between double-quotes, otherwise the engine will complain that it 
can't find it.

Original comment by duminica...@gmail.com on 16 May 2013 at 4:38

GoogleCodeExporter commented 9 years ago
FWIW the first case-sensitive database I encountered was an MS SQL one, where 
it seems that for some locales, case sensitive is the default after 
installation.

Original comment by zar...@gmail.com on 16 May 2013 at 6:20