Re: [SQLObject] Strange column type conversion
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Oleg B. <ph...@ph...> - 2005-01-03 09:10:51
|
Hello! (CC'ing to the list.) On Mon, Jan 03, 2005 at 10:43:10AM +0800, Hong Yaun wrote: > IMHO IntCol should convert the string to integers, and only raises > errors when the conversion can not be made, Why?! You've declared IntCol, an *integer* column. Of course, it expects to be passed in only integers, not strings. If strings, why not other types, for example objects thta implements __int__()? > 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. > SQLObject do this for me. Since I have already declared the column to be > integer with SQLObject, it seems more natural that SQLObject would do > this conversion for me, otherwise I have to declare the column type > again elsewhere in my program. No, you don't have to. You have to declare your own descendant of IntCol, and implement a validator that will convert values according to your rules. See UnicodeCol for a good example. > 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. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |