System.Data.SQLite

Artifact [dedb1b7197]
Login

Artifact dedb1b7197321ffc63e9cd3a47d0eded0a155aa0:

Ticket change [dedb1b7197] - New ticket [070b05bef9] SQLiteDataReader.IsDBNull(-1) should throw an exception. by anonymous 2021-01-12 11:50:41.
D 2021-01-12T11:50:41.761
J foundin 1.0.112
J icomment Calling\sSQLiteDataReader.IsDBNull\swith\san\sinvalid\sindex\s(such\sas\s-1\sor\sindex\s>=\sreader.FieldCount)\sreturns\strue\sinstead\sof\sthrowing\san\sexception\s(ADO.NET\sthrows\san\sIndexOutOfRangeException\se.g.).\r\n\r\nLet's\sassume\swe\shave\sa\spiece\sof\scode\ssuch\sas:\r\n//Method:\r\nint\sSafeToInt(DbDataReader\sreader,\sstring\scolName)\s{\r\n\s\s\s\sif\s(reader.IsDBNull(reader.GetOrdinal(colName))\r\n\s\s\s\s\s\s\s\sreturn\ssomeDefaultValue;\r\n\s\s\s\selse\r\n\s\s\s\s\s\s\s\sreturn\sreader.GetInt32(reader.GetOrdinal(colName));\r\n}\r\n\r\n//Caller:\r\nint\smyValue\s=\sSafeToInt(reader,\s"ColumnNameWithTypo");\s\s\s\s//Oops,\sthe\sprogrammer\smade\sa\stypo\swith\sa\scolumn\sname..\r\n\r\n\r\nSince\sGetOrdinal\sreturns\s-1\sif\sit\scouldn't\sfind\sa\scolumn\sname\s(ADO.NET\sthrows\san\sexception\sin\sthis\scase\sas\swell)\sthis\sis\sdirectly\spassed\sto\sIsDBNull\swhich\sevaluates\sto\strue\sand\sthe\sdefault\svalue\sis\sused.\sIt's\snot\sobvious\sto\sthe\sdeveloper\sthat\she\saccidentially\smistyped\sthe\scolumn\sname.\sThis\sis\san\sannoying\sbug\sin\sthe\sprogram\sand\spotentially\shard\sto\strack\sdown.\sSo\sI\sthink\san\sexception\sis\smore\sappropriate\swhen\scalling\sIsDBNull\swith\san\sinvalid\sindex.
J login anonymous
J mimetype text/plain
J private_contact c3d125c79a6da6ef9a4a8ece10fe39237fc3ff5d
J severity Important
J status Open
J title SQLiteDataReader.IsDBNull(-1)\sshould\sthrow\san\sexception
J type Feature_Request
K 070b05bef9352a8657ce9c1e49fad0c935848cd8
U anonymous
Z a39a23c0b097039085cdd7671b44c118