I have a small project I am trying to finish and I ran into a hiccup.
I saw the sqlachemy.sql.func object and decided to try to use it. Here
is the code to get us on the same page.

userPassword = 'thisisasalt';

insertDictionary = [{
    'user_name': user_name,
    'user_pwd': sqlalchemy.sql.func.encode(cred_pwd, userPassword),
    'user_host': user_host,
    'edit_user': 1,
    'edit_date': datetime.now()
}]

dbMetaObject = sqlalchemy.MetaData(self.dbConnection)
usersTable = sqlalchemy.Table('users', dbMetaObject, autoload=True,
autoload_with=self.dbConnection)
usersTableObject = usersTable.insert()
result = self.dbConnection.execute(usersTableObject, insertDictionary)

Now when I do the insert, it actually inserts the python string type.

2009-08-28 09:26:21,814 INFO sqlalchemy.engine.base.Engine.0x...0c90
['user',  <sqlalchemy.sql.expression.Function at 0x6107f0; encode>,
'', 1, datetime.datetime(2009, 8, 28, 9, 26, 21, 811219)]

which looks like the following when selected.

mysql> select * from users where user_id = 5\G
*************************** 1. row ***************************
   user_id: 5
   user_name: test_user
   user_pwd: encode(:encode_1, :encode_2)
   cred_host:
   edit_user: 1
   edit_date: 2009-08-28 09:26:21
1 row in set (0.00 sec)

My question is how do I get it to run the encode function and add the
proper value to the database? Thanks in advance for the help! This is
an insert not on a select and I the documentation doesn't have a good
example of using a function against an insert.

Checked:
http://www.sqlalchemy.org/docs/05/sqlexpression.html#functions

--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to