[SQL-CVS] r712 - in trunk/SQLObject/sqlobject: . mysql
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2005-04-04 20:50:43
|
Author: phd Date: 2005-04-04 20:50:38 +0000 (Mon, 04 Apr 2005) New Revision: 712 Modified: trunk/SQLObject/sqlobject/col.py trunk/SQLObject/sqlobject/mysql/mysqlconnection.py Log: StringCol now has a new attribute: case_sensitive. Default value for is True. Currently it is meaningful to set it to False only for MySQL: it strips CHAR/VARCHAR columns off of the BINARY attribute. Modified: trunk/SQLObject/sqlobject/col.py =================================================================== --- trunk/SQLObject/sqlobject/col.py 2005-04-04 19:08:30 UTC (rev 711) +++ trunk/SQLObject/sqlobject/col.py 2005-04-04 20:50:38 UTC (rev 712) @@ -352,6 +352,7 @@ def __init__(self, **kw): self.length = popKey(kw, 'length') self.varchar = popKey(kw, 'varchar', 'auto') + self.case_sensitive = popKey(kw, 'case_sensitive', True) if not self.length: assert self.varchar == 'auto' or not self.varchar, \ "Without a length strings are treated as TEXT, not varchar" @@ -377,19 +378,40 @@ else: return 'CHAR(%i)' % self.length + def _check_case_sensitive(self, db): + if not self.case_sensitive: + raise ValueError, "%s does not support case-insensitive columns" % db + + def _mysqlType(self): + type = self._sqlType() + if self.case_sensitive: + type += " BINARY" + return type + + def _postgresType(self): + self._check_case_sensitive("PostgreSQL") + return super(SOStringCol, self)._postgresType() + + def _sqliteType(self): + self._check_case_sensitive("SQLite") + return super(SOStringCol, self)._sqliteType() + def _sybaseType(self): + self._check_case_sensitive("SYBASE") type = self._sqlType() if not self.notNone and not self.alternateID: type += ' NULL' return type def _firebirdType(self): + self._check_case_sensitive("FireBird") if not self.length: return 'BLOB SUB_TYPE TEXT' else: return self._sqlType() def _maxdbType(self): + self._check_case_sensitive("SAP DB/MaxDB") if not self.length: return 'LONG ASCII' else: Modified: trunk/SQLObject/sqlobject/mysql/mysqlconnection.py =================================================================== --- trunk/SQLObject/sqlobject/mysql/mysqlconnection.py 2005-04-04 19:08:30 UTC (rev 711) +++ trunk/SQLObject/sqlobject/mysql/mysqlconnection.py 2005-04-04 20:50:38 UTC (rev 712) @@ -140,10 +140,19 @@ if t.startswith('int'): return col.IntCol, {} elif t.startswith('varchar'): - return col.StringCol, {'length': int(t[8:-1])} + if t.endswith('binary'): + return col.StringCol, {'length': int(t[8:-8])} + else: + return col.StringCol, {'length': int(t[8:-1]), + 'case_sensitive': False} elif t.startswith('char'): - return col.StringCol, {'length': int(t[5:-1]), - 'varchar': False} + if t.endswith('binary'): + return col.StringCol, {'length': int(t[5:-8]), + 'varchar': False} + else: + return col.StringCol, {'length': int(t[5:-1]), + 'varchar': False, + 'case_sensitive': False} elif t.startswith('datetime'): return col.DateTimeCol, {} elif t.startswith('bool'): |