silent truncation of varchar data
Posted in 1999
Topics: Connectivity: ODBC / JDBC / .NET, Data Types & Schema Design, Java & JDBC Development
I am wondering if anybody else has come across this problem, with 7.3X on Windows NT where extra characters are silently truncated when writing a VARCHAR to the database. For example if I try to store the word 'foobar' in a VARCHAR(5) Informix does not return an error, but only stores 'fooba' in the database. Support has told me this is the desired behavior, and that it's a doc bug that it is described for CHAR but not VARCHAR fields. Is there anything I could turn on under the covers to do some bounds checking for me in the database? I don't really want to have to insert checks everywhere in my code (Java JDK 1.1.7B, Informix JDBC 1.2.2). Cheers
Yah Jay, pretty much all databases have always worked this way. If it helps you any, a varchar(6) and a varchar(255) take up *exactly* the same amount of space, so why not simply leave yourself some headroom and make 'em a bit larger than they can ever possibly be. What exactly is it you are checking for, i.e., how *does* a field's value get to be larger than it should? If it's user input, we generally hold the application program responsible for ensuring that user input meets the database criteria, rather than surprise yourself at insert time - peformance is much better this way. Rich Jay Walters wrote: > I am wondering if anybody else has come across this problem, with 7.3X > on Windows NT where extra characters are silently truncated when writing > a VARCHAR to the database. For example if I try to store the word > 'foobar' in a VARCHAR(5) Informix does not return an error, but only > stores 'fooba' in the database. Support has told me this is the desired > behavior, and that it's a doc bug that it is described for CHAR but not > VARCHAR fields. Is there anything I could turn on under the covers to > do some bounds checking for me in the database? I don't really want to > have to insert checks everywhere in my code (Java JDK 1.1.7B, Informix > JDBC 1.2.2). > > Cheers -- Richard C. Auslander Database Manager AirFlash, Inc. 1733 Woodside Rd., Suite #110 Redwood City, CA 94061 (650) 556-7928 www.airflash.com