Re: [SQLObject] Strange column type conversion
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Hong Y. <hon...@ho...> - 2005-01-03 14:39:19
|
Hello! >>on the following grounds: >> >>I have encountered this problem when I am passing the user input value >>collected in the GUI components (wxPython in particular) to the >>database. The GUI components returns their values as string, so I would >>either convert the strings to integer in my own program, or have >> >> > > The logic is flawed. You are connecting GUI and SQLObject in your >program. The job of connecting and converting is neither in the GUI nor >in SQLObject - it is the job of your program. > It is easy to implement, btw. See below. > > ...... >>Second, I think this behavior is more compatible with the way that >>database is coping with type conversion. You can for example simply send >>a string in the SQL command to an int column in the database, and the >>database would perform the conversion whenever possible. >> >> > > I have never understand that behaviour of databases. And of >programming langauges. Why on Earth one would want a typesystem where >(s)he can add an integer to a string and got a result instead of >TypeError? > >Oleg. > > I get your point, that the validating and type conversion belongs to the application itself, not the ORM or GUI layer. But at least I would be very happy if I could be spared the tedious job of doing simple and frequent conversions, specially the very common conversion from strings to numbers. As long as the program integrity is not engendered, the convenience of automatical conversion would always be welcome. For the end user at least, when she/he input a number in a field, she doesn't care whether it is actually a string or a number. For her it IS an nubmer. I think that is why the SQL standard is not so strict on the data types and most databases do a lot of automatic conversions. I think it is rather a matter of taste whether a type system should be more strict or user friendly, and either way should work. It is just necessary to point out which approach SQLObject has taken so we know what is to be expected. But anyway, for a column decalred as IntCol, it should always return values as <type int>, and I wish this could be fixed soon, maybe by prohibiting to assign a string value to such a column. Hong Yuan |