I'd been trying to define my own custom column class - based on the
source and some wiki notes - but can't get it to work. The aim is to
store a list of strings, being able to write and read them as a list
(while internally storing them as a single eoln-delimited string.)
However, my solution (written below) throws when I try to create a
table using the column, saying "cannot be used for automatic schema
creation (too abstract)". This is because the customSQLType is not
set. So any advice or pointers? Have I misunderstood the necessary
inheritance patterns?
class StringListValidator (validators.Validator):
def from_python (self, value, state):
"""
Translates a Python value into one for the database.
This accepts a single string or sequence of strings and stores
them as
a single string, delimited by unix-eolns. We assume that there
are no
eolns in the strings, and so no escaping is done. Zero length
sequences
and None are treated as null strings.
"""
if (type (value) is type ('')):
return value
elif (hasattr (value, '__len__')):
return '\n'.join (value)
elif (value is None):
return ''
else:
raise "can't convert value '%s' to eoln delimited
string"
def to_python (self, value, state):
if value:
return value.split('\n')
else:
return []
class SOStringListCol (SOStringCol):
def createValidators(self):
return [StringListValidator()] + super (SOStringListCol,
self).createValidators()
class StringListCol (Col):
baseclass = SOStringListCol
--
Dr Paul-Michael Agapow: VieDigitale / Inst. for Animal Health
[EMAIL PROTECTED] / [EMAIL PROTECTED]
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss