Kevin Donn wrote:
> and zip_code is defined to be varchar(5), you'll receive an
> isc_arith_except error. In the Delphi TDataSet world, if you write a
> parameterized query like this, and then supply a value that is too long,
> it will in general be shortened to fit and no error returned or
> exception raised.
And this is generally not good way how to this. Why should some layer
truncate string under hands of developer? You can find some cases, where
this can be the source of long nights, cause you have to have truncation
in your hands.
BTW you're mixing two things - provider and DataSet.
> I'm not so much interested in the merits of the two approaches, but I am
> interested in how .net programmers handle situations like this in
> general. It seems like a lot of work to validate every piece of data
> coming into the system for length since at a minimum it requires the
> program to know the length of all fields in the database. But if the
> application programmer doesn't do this, then if his query has multiple
> parameters the isc_arith_except error doesn't tell him which one is too
> long so he has no way to convey this information back to the user.
Why not to use simple (where i is defined as varchar(5)):
cmd.Parameters.Add("@i", FbDbType.VarChar).Value = i.Substring(0,
Math.Min(5, i.Length));
> Is there a way to make the Firebird.NET Provider tolerant of parameter
> overflow like this and to truncate automatically? Or is there a better
> way to handle this that I'm missing, like a way to validate parameters
> individually using metadata fetched from the database?
Provider has no idea about field size before (just right before)
inserting the value. But again, this isn't providers problem, as you
wrote above, the DataSet can do truncation.
If you're using DataSet, you can do this by hand before changing value
of row in it.
--
Jiri {x2} Cincura
http://blog.vyvojar.cz/jirka/ | http://www.ID3renamer.com
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Firebird-net-provider mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider