[sqlalchemy] Re: Using a non-string in sqlalchemy

2007-08-06 Thread Jonathan Ellis

On 8/6/07, malkarouri [EMAIL PROTECTED] wrote:
 rec = Record()
 setattr(rec, col, val)

 This works if col is a string (the column subclassing SQLAlchemy's
 String) but not otherwise. I can identify the type of the column as

I think most people just use a higher-level forms api.

-Jonathan

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Using a non-string in sqlalchemy

2007-08-06 Thread Michael Bayer


On Aug 6, 2007, at 8:29 AM, malkarouri wrote:


 Hi everyone,

 I am a newbie and I must be overlooking a simple thing here. But how
 do I typecast a string to the type needed by a mapped class, which is
 identified at run time?

 I have a class,

 class Record(object):
 pass

 which I map to one of different tables identified at run time. I get
 strings like this

 col, val = raw_input(), raw_input()

 (my actual application uses HTML form, but this was for testing) which
 I try to use to insert a new record, like:

 rec = Record()
 setattr(rec, col, val)

 This works if col is a string (the column subclassing SQLAlchemy's
 String) but not otherwise. I can identify the type of the column as

 coltype = rec.c[col].type

 I probably can write a big if elif else to identify the type and do
 the typecasting. e.g.:

 if isinstance(coltype, Integer):
 val = int(val)

 but is there a canonical solution already there?


for parsing HTML form data into Python objects most people use  
FormEncode:  http://formencode.org/



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Using a non-string in sqlalchemy

2007-08-06 Thread Michael Bayer


On Aug 6, 5:35 pm, malkarouri [EMAIL PROTECTED] wrote:
 On Aug 6, 4:36 pm, Michael Bayer [EMAIL PROTECTED] wrote:



  for parsing HTML form data into Python objects most people use
  FormEncode:  http://formencode.org/

 Thanks a lot for the suggestion. FormEncode looks great and I will
 definitely be using it. Still, as I identify my object (column)
 classes at run-time, I need to find a mapping between sqlalchemy types
 and python types. I guess I will build a dictionary with the types I
 need.

we do have a trac ticket for this idea, associating python types with
SQL types, which we havent yet decided how we'd like to do.  theres a
bigger ticket for a rewrite of the types system which would probably
address this issue.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---