mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-17 22:22:13 -04:00
ee40adf5f8
support for types to be propigated into boolean expressions; new label() function/method to make any column/literal/function/bind param into a "foo AS bar" clause, better support in ansisql for this concept; trying to get column list on a select() object to be Column and ColumnClause objects equally, working on mappers that map to those select() objects
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
from sqlalchemy import *
|
|
import testbase
|
|
import string
|
|
|
|
|
|
|
|
class TypesTest(testbase.PersistTest):
|
|
def setUpAll(self):
|
|
global db
|
|
db = testbase.db
|
|
|
|
def testprocessing(self):
|
|
class MyType(types.TypeEngine):
|
|
def get_col_spec(self):
|
|
return "VARCHAR(100)"
|
|
def convert_bind_param(self, value):
|
|
return "BIND_IN"+ value
|
|
def convert_result_value(self, value):
|
|
return value + "BIND_OUT"
|
|
def adapt(self, typeobj):
|
|
return typeobj()
|
|
def adapt_args(self):
|
|
return self
|
|
|
|
users = Table('users', db,
|
|
Column('user_id', Integer, primary_key = True),
|
|
Column('goofy', MyType, nullable = False)
|
|
)
|
|
|
|
users.create()
|
|
|
|
users.insert().execute(user_id = 2, goofy = 'jack')
|
|
users.insert().execute(user_id = 3, goofy = 'lala')
|
|
users.insert().execute(user_id = 4, goofy = 'fred')
|
|
|
|
l = users.select().execute().fetchall()
|
|
print repr(l)
|
|
self.assert_(l == [(2, u'BIND_INjackBIND_OUT'), (3, u'BIND_INlalaBIND_OUT'), (4, u'BIND_INfredBIND_OUT')])
|
|
|
|
l = users.select(use_labels=True).execute().fetchall()
|
|
print repr(l)
|
|
self.assert_(l == [(2, u'BIND_INjackBIND_OUT'), (3, u'BIND_INlalaBIND_OUT'), (4, u'BIND_INfredBIND_OUT')])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
testbase.main()
|