index
int64 0
731k
| package
stringlengths 2
98
⌀ | name
stringlengths 1
76
| docstring
stringlengths 0
281k
⌀ | code
stringlengths 4
1.07M
⌀ | signature
stringlengths 2
42.8k
⌀ |
---|---|---|---|---|---|
27,364 | sqlobject.sqlbuilder | RLIKE | null | class RLIKE(LIKE):
op = "RLIKE"
op_db = {
'firebird': 'RLIKE',
'maxdb': 'RLIKE',
'mysql': 'RLIKE',
'postgres': '~',
'sqlite': 'REGEXP'
}
def _get_op(self, db):
return self.op_db.get(db, 'LIKE')
def __sqlrepr__(self, db):
return "(%s %s (%s))" % (
sqlrepr(self.expr, db), self._get_op(db), sqlrepr(self.string, db)
)
def execute(self, executor):
self.op = self._get_op(self.db)
return LIKE.execute(self, executor)
| (expr, string, escape=None) |
27,398 | sqlobject.sqlbuilder | __sqlrepr__ | null | def __sqlrepr__(self, db):
return "(%s %s (%s))" % (
sqlrepr(self.expr, db), self._get_op(db), sqlrepr(self.string, db)
)
| (self, db) |
27,402 | sqlobject.sqlbuilder | _get_op | null | def _get_op(self, db):
return self.op_db.get(db, 'LIKE')
| (self, db) |
27,406 | sqlobject.sqlbuilder | execute | null | def execute(self, executor):
self.op = self._get_op(self.db)
return LIKE.execute(self, executor)
| (self, executor) |
27,411 | sqlobject.joins | RelatedJoin | null | class RelatedJoin(MultipleJoin):
baseClass = SORelatedJoin
| (otherClass=None, **kw) |
27,416 | sqlobject.col | SOBLOBCol | null | class SOBLOBCol(SOStringCol):
def __init__(self, **kw):
# Change the default from 'auto' to False -
# this is a (mostly) binary column
if 'varchar' not in kw:
kw['varchar'] = False
super(SOBLOBCol, self).__init__(**kw)
def createValidators(self):
return [BinaryValidator(name=self.name)] + \
super(SOBLOBCol, self).createValidators()
def _mysqlType(self):
length = self.length
varchar = self.varchar
if length:
if length >= 2 ** 24:
return varchar and "LONGTEXT" or "LONGBLOB"
if length >= 2 ** 16:
return varchar and "MEDIUMTEXT" or "MEDIUMBLOB"
if length >= 2 ** 8:
return varchar and "TEXT" or "BLOB"
return varchar and "TINYTEXT" or "TINYBLOB"
def _postgresType(self):
return 'BYTEA'
def _mssqlType(self):
if self.connection and self.connection.can_use_max_types():
return 'VARBINARY(MAX)'
else:
return "IMAGE"
| (**kw) |
27,417 | sqlobject.col | __delete__ | null | def __delete__(self, obj):
raise AttributeError("I can't be deleted from %r" % obj)
| (self, obj) |
27,418 | sqlobject.col | __get__ | null | def __get__(self, obj, type=None):
if obj is None:
# class attribute, return the descriptor itself
return self
if obj.sqlmeta._obsolete:
raise RuntimeError('The object <%s %s> is obsolete' % (
obj.__class__.__name__, obj.id))
if obj.sqlmeta.cacheColumns:
columns = obj.sqlmeta._columnCache
if columns is None:
obj.sqlmeta.loadValues()
try:
return columns[name] # noqa
except KeyError:
return obj.sqlmeta.loadColumn(self)
else:
return obj.sqlmeta.loadColumn(self)
| (self, obj, type=None) |
27,419 | sqlobject.col | __init__ | null | def __init__(self, **kw):
# Change the default from 'auto' to False -
# this is a (mostly) binary column
if 'varchar' not in kw:
kw['varchar'] = False
super(SOBLOBCol, self).__init__(**kw)
| (self, **kw) |
27,420 | sqlobject.col | __repr__ | null | def __repr__(self):
r = '<%s %s' % (self.__class__.__name__, self.name)
if self.default is not NoDefault:
r += ' default=%s' % repr(self.default)
if self.foreignKey:
r += ' connected to %s' % self.foreignKey
if self.alternateID:
r += ' alternate ID'
if self.notNone:
r += ' not null'
return r + '>'
| (self) |
27,421 | sqlobject.col | __set__ | null | def __set__(self, obj, value):
if self.immutable:
raise AttributeError("The column %s.%s is immutable" %
(obj.__class__.__name__,
self.name))
obj.sqlmeta.setColumn(self, value)
| (self, obj, value) |
27,422 | sqlobject.col | _check_case_sensitive | null | def _check_case_sensitive(self, db):
if self.char_binary:
raise ValueError("%s does not support "
"binary character columns" % db)
| (self, db) |
27,423 | sqlobject.col | _extraSQL | null | def _extraSQL(self):
result = []
if self.notNone or self.alternateID:
result.append('NOT NULL')
if self.unique or self.alternateID:
result.append('UNIQUE')
if self.defaultSQL is not None:
result.append("DEFAULT %s" % self.defaultSQL)
return result
| (self) |
27,424 | sqlobject.col | _firebirdType | null | def _firebirdType(self):
self._check_case_sensitive("FireBird")
if not self.length:
return 'BLOB SUB_TYPE TEXT'
else:
return self._sqlType()
| (self) |
27,425 | sqlobject.col | _get_default | null | def _get_default(self):
# A default can be a callback or a plain value,
# here we resolve the callback
if self._default is NoDefault:
return NoDefault
elif hasattr(self._default, '__sqlrepr__'):
return self._default
elif callable(self._default):
return self._default()
else:
return self._default
| (self) |
27,426 | sqlobject.col | _get_joinName | null | def _get_joinName(self):
return self.soClass.sqlmeta.style.instanceIDAttrToAttr(self.name)
| (self) |
27,427 | sqlobject.col | _get_validator | null | def _get_validator(self):
return self._validator
| (self) |
27,428 | sqlobject.col | _maxdbType | null | def _maxdbType(self):
self._check_case_sensitive("SAP DB/MaxDB")
if not self.length:
return 'LONG ASCII'
else:
return self._sqlType()
| (self) |
27,429 | sqlobject.col | _mssqlType | null | def _mssqlType(self):
if self.connection and self.connection.can_use_max_types():
return 'VARBINARY(MAX)'
else:
return "IMAGE"
| (self) |
27,430 | sqlobject.col | _mysqlType | null | def _mysqlType(self):
length = self.length
varchar = self.varchar
if length:
if length >= 2 ** 24:
return varchar and "LONGTEXT" or "LONGBLOB"
if length >= 2 ** 16:
return varchar and "MEDIUMTEXT" or "MEDIUMBLOB"
if length >= 2 ** 8:
return varchar and "TEXT" or "BLOB"
return varchar and "TINYTEXT" or "TINYBLOB"
| (self) |
27,431 | sqlobject.col | _postgresType | null | def _postgresType(self):
return 'BYTEA'
| (self) |
27,432 | sqlobject.col | _set_validator | null | def _set_validator(self, value):
self._validator = value
if self._validator:
self.to_python = self._validator.to_python
self.from_python = self._validator.from_python
else:
self.to_python = None
self.from_python = None
| (self, value) |
27,433 | sqlobject.col | _sqlType | null | def _sqlType(self):
if self.customSQLType is not None:
return self.customSQLType
if not self.length:
return 'TEXT'
elif self.varchar:
return 'VARCHAR(%i)' % self.length
else:
return 'CHAR(%i)' % self.length
| (self) |
27,434 | sqlobject.col | _sqliteType | null | def _sqliteType(self):
self._check_case_sensitive("SQLite")
return super(SOStringLikeCol, self)._sqliteType()
| (self) |
27,435 | sqlobject.col | _sybaseType | null | def _sybaseType(self):
self._check_case_sensitive("SYBASE")
type = self._sqlType()
return type
| (self) |
27,436 | sqlobject.col | autoConstraints | null | def autoConstraints(self):
constraints = [constrs.isString]
if self.length is not None:
constraints += [constrs.MaxLength(self.length)]
return constraints
| (self) |
27,437 | sqlobject.col | createSQL | null | def createSQL(self):
return ' '.join([self._sqlType()] + self._extraSQL())
| (self) |
27,438 | sqlobject.col | createValidators | null | def createValidators(self):
return [BinaryValidator(name=self.name)] + \
super(SOBLOBCol, self).createValidators()
| (self) |
27,439 | sqlobject.col | firebirdCreateSQL | null | def firebirdCreateSQL(self):
# Ian Sparks pointed out that fb is picky about the order
# of the NOT NULL clause in a create statement. So, we handle
# them differently for Enum columns.
if not isinstance(self, SOEnumCol):
return ' '.join(
[self.dbName, self._firebirdType()] + self._extraSQL())
else:
return ' '.join(
[self.dbName] + [self._firebirdType()[0]]
+ self._extraSQL() + [self._firebirdType()[1]])
| (self) |
27,440 | sqlobject.col | getDbEncoding | null | def getDbEncoding(self, state, default='utf-8'):
if self.dbEncoding:
return self.dbEncoding
dbEncoding = state.soObject.sqlmeta.dbEncoding
if dbEncoding:
return dbEncoding
try:
connection = state.connection or state.soObject._connection
except AttributeError:
dbEncoding = None
else:
dbEncoding = getattr(connection, "dbEncoding", None)
if not dbEncoding:
dbEncoding = default
return dbEncoding
| (self, state, default='utf-8') |
27,441 | sqlobject.col | maxdbCreateSQL | null | def maxdbCreateSQL(self):
return ' '.join([self.dbName, self._maxdbType()] + self._extraSQL())
| (self) |
27,442 | sqlobject.col | mssqlCreateSQL | null | def mssqlCreateSQL(self, connection=None):
self.connection = connection
return ' '.join([self.dbName, self._mssqlType()] + self._extraSQL())
| (self, connection=None) |
27,443 | sqlobject.col | mysqlCreateSQL | null | def mysqlCreateSQL(self, connection=None):
self.connection = connection
return ' '.join([self.dbName, self._mysqlType()] + self._extraSQL())
| (self, connection=None) |
27,444 | sqlobject.col | postgresCreateSQL | null | def postgresCreateSQL(self):
return ' '.join([self.dbName, self._postgresType()] + self._extraSQL())
| (self) |
27,445 | sqlobject.col | sqliteCreateSQL | null | def sqliteCreateSQL(self):
return ' '.join([self.dbName, self._sqliteType()] + self._extraSQL())
| (self) |
27,446 | sqlobject.col | sybaseCreateSQL | null | def sybaseCreateSQL(self):
return ' '.join([self.dbName, self._sybaseType()] + self._extraSQL())
| (self) |
27,447 | sqlobject.col | SOBigIntCol | null | class SOBigIntCol(SOIntCol):
def _sqlType(self):
return self.addSQLAttrs("BIGINT")
| (**kw) |
27,450 | sqlobject.col | __init__ | null | def __init__(self, **kw):
self.length = kw.pop('length', None)
self.unsigned = bool(kw.pop('unsigned', None))
self.zerofill = bool(kw.pop('zerofill', None))
SOCol.__init__(self, **kw)
| (self, **kw) |
27,454 | sqlobject.col | _firebirdType | null | def _firebirdType(self):
return self._sqlType()
| (self) |
27,458 | sqlobject.col | _maxdbType | null | def _maxdbType(self):
return self._sqlType()
| (self) |
27,459 | sqlobject.col | _mssqlType | null | def _mssqlType(self):
return self._sqlType()
| (self) |
27,460 | sqlobject.col | _mysqlType | null | def _mysqlType(self):
return self._sqlType()
| (self) |
27,461 | sqlobject.col | _postgresType | null | def _postgresType(self):
return self._sqlType()
| (self) |
27,463 | sqlobject.col | _sqlType | null | def _sqlType(self):
return self.addSQLAttrs("BIGINT")
| (self) |
27,464 | sqlobject.col | _sqliteType | null | def _sqliteType(self):
# SQLite is naturally typeless, so as a fallback it uses
# no type.
try:
return self._sqlType()
except ValueError:
return ''
| (self) |
27,465 | sqlobject.col | _sybaseType | null | def _sybaseType(self):
return self._sqlType()
| (self) |
27,466 | sqlobject.col | addSQLAttrs | null | def addSQLAttrs(self, str):
_ret = str
if str is None or len(str) < 1:
return None
if self.length and self.length >= 1:
_ret = "%s(%d)" % (_ret, self.length)
if self.unsigned:
_ret += " UNSIGNED"
if self.zerofill:
_ret += " ZEROFILL"
return _ret
| (self, str) |
27,467 | sqlobject.col | autoConstraints | null | def autoConstraints(self):
return [constrs.isInt]
| (self) |
27,469 | sqlobject.col | createValidators | null | def createValidators(self):
return [IntValidator(name=self.name)] + \
super(SOIntCol, self).createValidators()
| (self) |
27,478 | sqlobject.col | SOBoolCol | null | class SOBoolCol(SOCol):
def autoConstraints(self):
return [constrs.isBool]
def createValidators(self):
return [BoolValidator(name=self.name)] + \
super(SOBoolCol, self).createValidators()
def _postgresType(self):
return 'BOOL'
def _mysqlType(self):
return "BOOL"
def _sybaseType(self):
return "BIT"
def _mssqlType(self):
return "BIT"
def _firebirdType(self):
return 'INT'
def _maxdbType(self):
return "BOOLEAN"
def _sqliteType(self):
return "BOOLEAN"
| (name, soClass, creationOrder, dbName=None, default=<class 'sqlobject.sqlbuilder.NoDefault'>, defaultSQL=None, foreignKey=None, alternateID=False, alternateMethodName=None, constraints=None, notNull=<class 'sqlobject.sqlbuilder.NoDefault'>, notNone=<class 'sqlobject.sqlbuilder.NoDefault'>, unique=<class 'sqlobject.sqlbuilder.NoDefault'>, sqlType=None, columnDef=None, validator=None, validator2=None, immutable=False, cascade=None, lazy=False, noCache=False, forceDBName=False, title=None, tags=[], origName=None, dbEncoding=None, extra_vars=None) |
27,481 | sqlobject.col | __init__ | null | def __init__(self,
name,
soClass,
creationOrder,
dbName=None,
default=NoDefault,
defaultSQL=None,
foreignKey=None,
alternateID=False,
alternateMethodName=None,
constraints=None,
notNull=NoDefault,
notNone=NoDefault,
unique=NoDefault,
sqlType=None,
columnDef=None,
validator=None,
validator2=None,
immutable=False,
cascade=None,
lazy=False,
noCache=False,
forceDBName=False,
title=None,
tags=[],
origName=None,
dbEncoding=None,
extra_vars=None):
super(SOCol, self).__init__()
# This isn't strictly true, since we *could* use backquotes or
# " or something (database-specific) around column names, but
# why would anyone *want* to use a name like that?
# @@: I suppose we could actually add backquotes to the
# dbName if we needed to...
if not forceDBName:
assert sqlbuilder.sqlIdentifier(name), (
'Name must be SQL-safe '
'(letters, numbers, underscores): %s (or use forceDBName=True)'
% repr(name))
assert name != 'id', (
'The column name "id" is reserved for SQLObject use '
'(and is implicitly created).')
assert name, "You must provide a name for all columns"
self.columnDef = columnDef
self.creationOrder = creationOrder
self.immutable = immutable
# cascade can be one of:
# None: no constraint is generated
# True: a CASCADE constraint is generated
# False: a RESTRICT constraint is generated
# 'null': a SET NULL trigger is generated
if not isinstance(cascade, (bool, string_type, type(None))):
raise TypeError(
'Expected cascade to be True, False, None or "null", '
"(you gave: %r %r)" % (type(cascade), cascade)
)
if isinstance(cascade, str) and (cascade != 'null'):
raise ValueError(
"The only string value allowed for cascade is 'null' "
"(you gave: %r)" % cascade)
self.cascade = cascade
if not isinstance(constraints, (list, tuple)):
constraints = [constraints]
self.constraints = self.autoConstraints() + constraints
self.notNone = False
if notNull is not NoDefault:
self.notNone = notNull
assert notNone is NoDefault or (not notNone) == (not notNull), (
"The notNull and notNone arguments are aliases, "
"and must not conflict. "
"You gave notNull=%r, notNone=%r" % (notNull, notNone))
elif notNone is not NoDefault:
self.notNone = notNone
if self.notNone:
self.constraints = [constrs.notNull] + self.constraints
self.name = name
self.soClass = soClass
self._default = default
self.defaultSQL = defaultSQL
self.customSQLType = sqlType
# deal with foreign keys
self.foreignKey = foreignKey
if self.foreignKey:
if origName is not None:
idname = soClass.sqlmeta.style.instanceAttrToIDAttr(origName)
else:
idname = soClass.sqlmeta.style.instanceAttrToIDAttr(name)
if self.name != idname:
self.foreignName = self.name
self.name = idname
else:
self.foreignName = soClass.sqlmeta.style.\
instanceIDAttrToAttr(self.name)
else:
self.foreignName = None
# if they don't give us a specific database name for
# the column, we separate the mixedCase into mixed_case
# and assume that.
if dbName is None:
self.dbName = soClass.sqlmeta.style.pythonAttrToDBColumn(self.name)
else:
self.dbName = dbName
# alternateID means that this is a unique column that
# can be used to identify rows
self.alternateID = alternateID
if unique is NoDefault:
self.unique = alternateID
else:
self.unique = unique
if self.unique and alternateMethodName is None:
self.alternateMethodName = 'by' + capword(self.name)
else:
self.alternateMethodName = alternateMethodName
_validators = self.createValidators()
if validator:
_validators.append(validator)
if validator2:
_validators.insert(0, validator2)
_vlen = len(_validators)
if _vlen:
for _validator in _validators:
_validator.soCol = weakref.proxy(self)
if _vlen == 0:
self.validator = None # Set sef.{from,to}_python
elif _vlen == 1:
self.validator = _validators[0]
elif _vlen > 1:
self.validator = compound.All.join(
_validators[0], *_validators[1:])
self.noCache = noCache
self.lazy = lazy
# this is in case of ForeignKey, where we rename the column
# and append an ID
self.origName = origName or name
self.title = title
self.tags = tags
self.dbEncoding = dbEncoding
if extra_vars:
for name, value in extra_vars.items():
setattr(self, name, value)
| (self, name, soClass, creationOrder, dbName=None, default=<class 'sqlobject.sqlbuilder.NoDefault'>, defaultSQL=None, foreignKey=None, alternateID=False, alternateMethodName=None, constraints=None, notNull=<class 'sqlobject.sqlbuilder.NoDefault'>, notNone=<class 'sqlobject.sqlbuilder.NoDefault'>, unique=<class 'sqlobject.sqlbuilder.NoDefault'>, sqlType=None, columnDef=None, validator=None, validator2=None, immutable=False, cascade=None, lazy=False, noCache=False, forceDBName=False, title=None, tags=[], origName=None, dbEncoding=None, extra_vars=None) |
27,485 | sqlobject.col | _firebirdType | null | def _firebirdType(self):
return 'INT'
| (self) |
27,489 | sqlobject.col | _maxdbType | null | def _maxdbType(self):
return "BOOLEAN"
| (self) |
27,490 | sqlobject.col | _mssqlType | null | def _mssqlType(self):
return "BIT"
| (self) |
27,491 | sqlobject.col | _mysqlType | null | def _mysqlType(self):
return "BOOL"
| (self) |
27,492 | sqlobject.col | _postgresType | null | def _postgresType(self):
return 'BOOL'
| (self) |
27,494 | sqlobject.col | _sqlType | null | def _sqlType(self):
if self.customSQLType is None:
raise ValueError("Col %s (%s) cannot be used for automatic "
"schema creation (too abstract)" %
(self.name, self.__class__))
else:
return self.customSQLType
| (self) |
27,495 | sqlobject.col | _sqliteType | null | def _sqliteType(self):
return "BOOLEAN"
| (self) |
27,496 | sqlobject.col | _sybaseType | null | def _sybaseType(self):
return "BIT"
| (self) |
27,497 | sqlobject.col | autoConstraints | null | def autoConstraints(self):
return [constrs.isBool]
| (self) |
27,499 | sqlobject.col | createValidators | null | def createValidators(self):
return [BoolValidator(name=self.name)] + \
super(SOBoolCol, self).createValidators()
| (self) |
27,508 | sqlobject.col | SOCol | null | class SOCol(object):
def __init__(self,
name,
soClass,
creationOrder,
dbName=None,
default=NoDefault,
defaultSQL=None,
foreignKey=None,
alternateID=False,
alternateMethodName=None,
constraints=None,
notNull=NoDefault,
notNone=NoDefault,
unique=NoDefault,
sqlType=None,
columnDef=None,
validator=None,
validator2=None,
immutable=False,
cascade=None,
lazy=False,
noCache=False,
forceDBName=False,
title=None,
tags=[],
origName=None,
dbEncoding=None,
extra_vars=None):
super(SOCol, self).__init__()
# This isn't strictly true, since we *could* use backquotes or
# " or something (database-specific) around column names, but
# why would anyone *want* to use a name like that?
# @@: I suppose we could actually add backquotes to the
# dbName if we needed to...
if not forceDBName:
assert sqlbuilder.sqlIdentifier(name), (
'Name must be SQL-safe '
'(letters, numbers, underscores): %s (or use forceDBName=True)'
% repr(name))
assert name != 'id', (
'The column name "id" is reserved for SQLObject use '
'(and is implicitly created).')
assert name, "You must provide a name for all columns"
self.columnDef = columnDef
self.creationOrder = creationOrder
self.immutable = immutable
# cascade can be one of:
# None: no constraint is generated
# True: a CASCADE constraint is generated
# False: a RESTRICT constraint is generated
# 'null': a SET NULL trigger is generated
if not isinstance(cascade, (bool, string_type, type(None))):
raise TypeError(
'Expected cascade to be True, False, None or "null", '
"(you gave: %r %r)" % (type(cascade), cascade)
)
if isinstance(cascade, str) and (cascade != 'null'):
raise ValueError(
"The only string value allowed for cascade is 'null' "
"(you gave: %r)" % cascade)
self.cascade = cascade
if not isinstance(constraints, (list, tuple)):
constraints = [constraints]
self.constraints = self.autoConstraints() + constraints
self.notNone = False
if notNull is not NoDefault:
self.notNone = notNull
assert notNone is NoDefault or (not notNone) == (not notNull), (
"The notNull and notNone arguments are aliases, "
"and must not conflict. "
"You gave notNull=%r, notNone=%r" % (notNull, notNone))
elif notNone is not NoDefault:
self.notNone = notNone
if self.notNone:
self.constraints = [constrs.notNull] + self.constraints
self.name = name
self.soClass = soClass
self._default = default
self.defaultSQL = defaultSQL
self.customSQLType = sqlType
# deal with foreign keys
self.foreignKey = foreignKey
if self.foreignKey:
if origName is not None:
idname = soClass.sqlmeta.style.instanceAttrToIDAttr(origName)
else:
idname = soClass.sqlmeta.style.instanceAttrToIDAttr(name)
if self.name != idname:
self.foreignName = self.name
self.name = idname
else:
self.foreignName = soClass.sqlmeta.style.\
instanceIDAttrToAttr(self.name)
else:
self.foreignName = None
# if they don't give us a specific database name for
# the column, we separate the mixedCase into mixed_case
# and assume that.
if dbName is None:
self.dbName = soClass.sqlmeta.style.pythonAttrToDBColumn(self.name)
else:
self.dbName = dbName
# alternateID means that this is a unique column that
# can be used to identify rows
self.alternateID = alternateID
if unique is NoDefault:
self.unique = alternateID
else:
self.unique = unique
if self.unique and alternateMethodName is None:
self.alternateMethodName = 'by' + capword(self.name)
else:
self.alternateMethodName = alternateMethodName
_validators = self.createValidators()
if validator:
_validators.append(validator)
if validator2:
_validators.insert(0, validator2)
_vlen = len(_validators)
if _vlen:
for _validator in _validators:
_validator.soCol = weakref.proxy(self)
if _vlen == 0:
self.validator = None # Set sef.{from,to}_python
elif _vlen == 1:
self.validator = _validators[0]
elif _vlen > 1:
self.validator = compound.All.join(
_validators[0], *_validators[1:])
self.noCache = noCache
self.lazy = lazy
# this is in case of ForeignKey, where we rename the column
# and append an ID
self.origName = origName or name
self.title = title
self.tags = tags
self.dbEncoding = dbEncoding
if extra_vars:
for name, value in extra_vars.items():
setattr(self, name, value)
def _set_validator(self, value):
self._validator = value
if self._validator:
self.to_python = self._validator.to_python
self.from_python = self._validator.from_python
else:
self.to_python = None
self.from_python = None
def _get_validator(self):
return self._validator
validator = property(_get_validator, _set_validator)
def createValidators(self):
"""Create a list of validators for the column."""
return []
def autoConstraints(self):
return []
def _get_default(self):
# A default can be a callback or a plain value,
# here we resolve the callback
if self._default is NoDefault:
return NoDefault
elif hasattr(self._default, '__sqlrepr__'):
return self._default
elif callable(self._default):
return self._default()
else:
return self._default
default = property(_get_default, None, None)
def _get_joinName(self):
return self.soClass.sqlmeta.style.instanceIDAttrToAttr(self.name)
joinName = property(_get_joinName, None, None)
def __repr__(self):
r = '<%s %s' % (self.__class__.__name__, self.name)
if self.default is not NoDefault:
r += ' default=%s' % repr(self.default)
if self.foreignKey:
r += ' connected to %s' % self.foreignKey
if self.alternateID:
r += ' alternate ID'
if self.notNone:
r += ' not null'
return r + '>'
def createSQL(self):
return ' '.join([self._sqlType()] + self._extraSQL())
def _extraSQL(self):
result = []
if self.notNone or self.alternateID:
result.append('NOT NULL')
if self.unique or self.alternateID:
result.append('UNIQUE')
if self.defaultSQL is not None:
result.append("DEFAULT %s" % self.defaultSQL)
return result
def _sqlType(self):
if self.customSQLType is None:
raise ValueError("Col %s (%s) cannot be used for automatic "
"schema creation (too abstract)" %
(self.name, self.__class__))
else:
return self.customSQLType
def _mysqlType(self):
return self._sqlType()
def _postgresType(self):
return self._sqlType()
def _sqliteType(self):
# SQLite is naturally typeless, so as a fallback it uses
# no type.
try:
return self._sqlType()
except ValueError:
return ''
def _sybaseType(self):
return self._sqlType()
def _mssqlType(self):
return self._sqlType()
def _firebirdType(self):
return self._sqlType()
def _maxdbType(self):
return self._sqlType()
def mysqlCreateSQL(self, connection=None):
self.connection = connection
return ' '.join([self.dbName, self._mysqlType()] + self._extraSQL())
def postgresCreateSQL(self):
return ' '.join([self.dbName, self._postgresType()] + self._extraSQL())
def sqliteCreateSQL(self):
return ' '.join([self.dbName, self._sqliteType()] + self._extraSQL())
def sybaseCreateSQL(self):
return ' '.join([self.dbName, self._sybaseType()] + self._extraSQL())
def mssqlCreateSQL(self, connection=None):
self.connection = connection
return ' '.join([self.dbName, self._mssqlType()] + self._extraSQL())
def firebirdCreateSQL(self):
# Ian Sparks pointed out that fb is picky about the order
# of the NOT NULL clause in a create statement. So, we handle
# them differently for Enum columns.
if not isinstance(self, SOEnumCol):
return ' '.join(
[self.dbName, self._firebirdType()] + self._extraSQL())
else:
return ' '.join(
[self.dbName] + [self._firebirdType()[0]]
+ self._extraSQL() + [self._firebirdType()[1]])
def maxdbCreateSQL(self):
return ' '.join([self.dbName, self._maxdbType()] + self._extraSQL())
def __get__(self, obj, type=None):
if obj is None:
# class attribute, return the descriptor itself
return self
if obj.sqlmeta._obsolete:
raise RuntimeError('The object <%s %s> is obsolete' % (
obj.__class__.__name__, obj.id))
if obj.sqlmeta.cacheColumns:
columns = obj.sqlmeta._columnCache
if columns is None:
obj.sqlmeta.loadValues()
try:
return columns[name] # noqa
except KeyError:
return obj.sqlmeta.loadColumn(self)
else:
return obj.sqlmeta.loadColumn(self)
def __set__(self, obj, value):
if self.immutable:
raise AttributeError("The column %s.%s is immutable" %
(obj.__class__.__name__,
self.name))
obj.sqlmeta.setColumn(self, value)
def __delete__(self, obj):
raise AttributeError("I can't be deleted from %r" % obj)
def getDbEncoding(self, state, default='utf-8'):
if self.dbEncoding:
return self.dbEncoding
dbEncoding = state.soObject.sqlmeta.dbEncoding
if dbEncoding:
return dbEncoding
try:
connection = state.connection or state.soObject._connection
except AttributeError:
dbEncoding = None
else:
dbEncoding = getattr(connection, "dbEncoding", None)
if not dbEncoding:
dbEncoding = default
return dbEncoding
| (name, soClass, creationOrder, dbName=None, default=<class 'sqlobject.sqlbuilder.NoDefault'>, defaultSQL=None, foreignKey=None, alternateID=False, alternateMethodName=None, constraints=None, notNull=<class 'sqlobject.sqlbuilder.NoDefault'>, notNone=<class 'sqlobject.sqlbuilder.NoDefault'>, unique=<class 'sqlobject.sqlbuilder.NoDefault'>, sqlType=None, columnDef=None, validator=None, validator2=None, immutable=False, cascade=None, lazy=False, noCache=False, forceDBName=False, title=None, tags=[], origName=None, dbEncoding=None, extra_vars=None) |
27,527 | sqlobject.col | autoConstraints | null | def autoConstraints(self):
return []
| (self) |
27,529 | sqlobject.col | createValidators | Create a list of validators for the column. | def createValidators(self):
"""Create a list of validators for the column."""
return []
| (self) |
27,538 | sqlobject.col | SOCurrencyCol | null | class SOCurrencyCol(SODecimalCol):
def __init__(self, **kw):
pushKey(kw, 'size', 10)
pushKey(kw, 'precision', 2)
super(SOCurrencyCol, self).__init__(**kw)
| (**kw) |
27,541 | sqlobject.col | __init__ | null | def __init__(self, **kw):
pushKey(kw, 'size', 10)
pushKey(kw, 'precision', 2)
super(SOCurrencyCol, self).__init__(**kw)
| (self, **kw) |
27,554 | sqlobject.col | _sqlType | null | def _sqlType(self):
return 'DECIMAL(%i, %i)' % (self.size, self.precision)
| (self) |
27,559 | sqlobject.col | createValidators | null | def createValidators(self):
return [DecimalValidator(name=self.name)] + \
super(SODecimalCol, self).createValidators()
| (self) |
27,568 | sqlobject.col | SODateCol | null | class SODateCol(SOCol):
dateFormat = '%Y-%m-%d'
def __init__(self, **kw):
dateFormat = kw.pop('dateFormat', None)
if dateFormat:
self.dateFormat = dateFormat
super(SODateCol, self).__init__(**kw)
def createValidators(self):
"""Create a validator for the column.
Can be overriden in descendants.
"""
_validators = super(SODateCol, self).createValidators()
if default_datetime_implementation == DATETIME_IMPLEMENTATION:
validatorClass = DateValidator
elif default_datetime_implementation == MXDATETIME_IMPLEMENTATION:
validatorClass = MXDateTimeValidator
elif default_datetime_implementation == ZOPE_DATETIME_IMPLEMENTATION:
validatorClass = ZopeDateTimeValidator
if default_datetime_implementation:
_validators.insert(0, validatorClass(name=self.name,
format=self.dateFormat))
return _validators
def _mysqlType(self):
return 'DATE'
def _postgresType(self):
return 'DATE'
def _sybaseType(self):
return self._postgresType()
def _mssqlType(self):
"""
SQL Server doesn't have a DATE data type, to emulate we use a vc(10)
"""
return 'VARCHAR(10)'
def _firebirdType(self):
return 'DATE'
def _maxdbType(self):
return 'DATE'
def _sqliteType(self):
return 'DATE'
| (**kw) |
27,571 | sqlobject.col | __init__ | null | def __init__(self, **kw):
dateFormat = kw.pop('dateFormat', None)
if dateFormat:
self.dateFormat = dateFormat
super(SODateCol, self).__init__(**kw)
| (self, **kw) |
27,575 | sqlobject.col | _firebirdType | null | def _firebirdType(self):
return 'DATE'
| (self) |
27,579 | sqlobject.col | _maxdbType | null | def _maxdbType(self):
return 'DATE'
| (self) |
27,580 | sqlobject.col | _mssqlType |
SQL Server doesn't have a DATE data type, to emulate we use a vc(10)
| def _mssqlType(self):
"""
SQL Server doesn't have a DATE data type, to emulate we use a vc(10)
"""
return 'VARCHAR(10)'
| (self) |
27,581 | sqlobject.col | _mysqlType | null | def _mysqlType(self):
return 'DATE'
| (self) |
27,582 | sqlobject.col | _postgresType | null | def _postgresType(self):
return 'DATE'
| (self) |
27,585 | sqlobject.col | _sqliteType | null | def _sqliteType(self):
return 'DATE'
| (self) |
27,586 | sqlobject.col | _sybaseType | null | def _sybaseType(self):
return self._postgresType()
| (self) |
27,589 | sqlobject.col | createValidators | Create a validator for the column.
Can be overriden in descendants.
| def createValidators(self):
"""Create a validator for the column.
Can be overriden in descendants.
"""
_validators = super(SODateCol, self).createValidators()
if default_datetime_implementation == DATETIME_IMPLEMENTATION:
validatorClass = DateValidator
elif default_datetime_implementation == MXDATETIME_IMPLEMENTATION:
validatorClass = MXDateTimeValidator
elif default_datetime_implementation == ZOPE_DATETIME_IMPLEMENTATION:
validatorClass = ZopeDateTimeValidator
if default_datetime_implementation:
_validators.insert(0, validatorClass(name=self.name,
format=self.dateFormat))
return _validators
| (self) |
27,598 | sqlobject.col | SODateTimeCol | null | class SODateTimeCol(SOCol):
datetimeFormat = '%Y-%m-%d %H:%M:%S.%f'
def __init__(self, **kw):
datetimeFormat = kw.pop('datetimeFormat', None)
if datetimeFormat:
self.datetimeFormat = datetimeFormat
super(SODateTimeCol, self).__init__(**kw)
def createValidators(self):
_validators = super(SODateTimeCol, self).createValidators()
if default_datetime_implementation == DATETIME_IMPLEMENTATION:
validatorClass = DateTimeValidator
elif default_datetime_implementation == MXDATETIME_IMPLEMENTATION:
validatorClass = MXDateTimeValidator
elif default_datetime_implementation == ZOPE_DATETIME_IMPLEMENTATION:
validatorClass = ZopeDateTimeValidator
if default_datetime_implementation:
_validators.insert(0, validatorClass(name=self.name,
format=self.datetimeFormat))
return _validators
def _mysqlType(self):
if self.connection and self.connection.can_use_microseconds():
return 'DATETIME(6)'
else:
return 'DATETIME'
def _postgresType(self):
return 'TIMESTAMP'
def _sybaseType(self):
return 'DATETIME'
def _mssqlType(self):
if self.connection and self.connection.can_use_microseconds():
return 'DATETIME2(6)'
else:
return 'DATETIME'
def _sqliteType(self):
return 'TIMESTAMP'
def _firebirdType(self):
return 'TIMESTAMP'
def _maxdbType(self):
return 'TIMESTAMP'
| (**kw) |
27,601 | sqlobject.col | __init__ | null | def __init__(self, **kw):
datetimeFormat = kw.pop('datetimeFormat', None)
if datetimeFormat:
self.datetimeFormat = datetimeFormat
super(SODateTimeCol, self).__init__(**kw)
| (self, **kw) |
27,605 | sqlobject.col | _firebirdType | null | def _firebirdType(self):
return 'TIMESTAMP'
| (self) |
27,609 | sqlobject.col | _maxdbType | null | def _maxdbType(self):
return 'TIMESTAMP'
| (self) |
27,610 | sqlobject.col | _mssqlType | null | def _mssqlType(self):
if self.connection and self.connection.can_use_microseconds():
return 'DATETIME2(6)'
else:
return 'DATETIME'
| (self) |
27,611 | sqlobject.col | _mysqlType | null | def _mysqlType(self):
if self.connection and self.connection.can_use_microseconds():
return 'DATETIME(6)'
else:
return 'DATETIME'
| (self) |
27,612 | sqlobject.col | _postgresType | null | def _postgresType(self):
return 'TIMESTAMP'
| (self) |
27,615 | sqlobject.col | _sqliteType | null | def _sqliteType(self):
return 'TIMESTAMP'
| (self) |
27,616 | sqlobject.col | _sybaseType | null | def _sybaseType(self):
return 'DATETIME'
| (self) |
27,619 | sqlobject.col | createValidators | null | def createValidators(self):
_validators = super(SODateTimeCol, self).createValidators()
if default_datetime_implementation == DATETIME_IMPLEMENTATION:
validatorClass = DateTimeValidator
elif default_datetime_implementation == MXDATETIME_IMPLEMENTATION:
validatorClass = MXDateTimeValidator
elif default_datetime_implementation == ZOPE_DATETIME_IMPLEMENTATION:
validatorClass = ZopeDateTimeValidator
if default_datetime_implementation:
_validators.insert(0, validatorClass(name=self.name,
format=self.datetimeFormat))
return _validators
| (self) |
27,628 | sqlobject.col | SODecimalCol | null | class SODecimalCol(SOCol):
def __init__(self, **kw):
self.size = kw.pop('size', NoDefault)
assert self.size is not NoDefault, \
"You must give a size argument"
self.precision = kw.pop('precision', NoDefault)
assert self.precision is not NoDefault, \
"You must give a precision argument"
super(SODecimalCol, self).__init__(**kw)
def _sqlType(self):
return 'DECIMAL(%i, %i)' % (self.size, self.precision)
def createValidators(self):
return [DecimalValidator(name=self.name)] + \
super(SODecimalCol, self).createValidators()
| (**kw) |
27,631 | sqlobject.col | __init__ | null | def __init__(self, **kw):
self.size = kw.pop('size', NoDefault)
assert self.size is not NoDefault, \
"You must give a size argument"
self.precision = kw.pop('precision', NoDefault)
assert self.precision is not NoDefault, \
"You must give a precision argument"
super(SODecimalCol, self).__init__(**kw)
| (self, **kw) |
27,658 | sqlobject.col | SODecimalStringCol | null | class SODecimalStringCol(SOStringCol):
def __init__(self, **kw):
self.size = kw.pop('size', NoDefault)
assert (self.size is not NoDefault) and (self.size >= 0), \
"You must give a size argument as a positive integer"
self.precision = kw.pop('precision', NoDefault)
assert (self.precision is not NoDefault) and (self.precision >= 0), \
"You must give a precision argument as a positive integer"
kw['length'] = int(self.size) + int(self.precision)
self.quantize = kw.pop('quantize', False)
assert isinstance(self.quantize, bool), \
"quantize argument must be Boolean True/False"
super(SODecimalStringCol, self).__init__(**kw)
def createValidators(self):
if self.quantize:
v = DecimalStringValidator(
name=self.name,
precision=Decimal(10) ** (-1 * int(self.precision)),
max=Decimal(10) ** (int(self.size) - int(self.precision)))
else:
v = DecimalStringValidator(name=self.name, precision=0)
return [v] + \
super(SODecimalStringCol, self).createValidators(dataType=Decimal)
| (**kw) |
27,661 | sqlobject.col | __init__ | null | def __init__(self, **kw):
self.size = kw.pop('size', NoDefault)
assert (self.size is not NoDefault) and (self.size >= 0), \
"You must give a size argument as a positive integer"
self.precision = kw.pop('precision', NoDefault)
assert (self.precision is not NoDefault) and (self.precision >= 0), \
"You must give a precision argument as a positive integer"
kw['length'] = int(self.size) + int(self.precision)
self.quantize = kw.pop('quantize', False)
assert isinstance(self.quantize, bool), \
"quantize argument must be Boolean True/False"
super(SODecimalStringCol, self).__init__(**kw)
| (self, **kw) |
27,671 | sqlobject.col | _mssqlType | null | def _mssqlType(self):
if self.customSQLType is not None:
return self.customSQLType
if not self.length:
if self.connection and self.connection.can_use_max_types():
type = 'VARCHAR(MAX)'
else:
type = 'VARCHAR(4000)'
elif self.varchar:
type = 'VARCHAR(%i)' % self.length
else:
type = 'CHAR(%i)' % self.length
return type
| (self) |
27,672 | sqlobject.col | _mysqlType | null | def _mysqlType(self):
type = self._sqlType()
if self.char_binary:
type += " BINARY"
return type
| (self) |
27,673 | sqlobject.col | _postgresType | null | def _postgresType(self):
self._check_case_sensitive("PostgreSQL")
return super(SOStringLikeCol, self)._postgresType()
| (self) |
27,680 | sqlobject.col | createValidators | null | def createValidators(self):
if self.quantize:
v = DecimalStringValidator(
name=self.name,
precision=Decimal(10) ** (-1 * int(self.precision)),
max=Decimal(10) ** (int(self.size) - int(self.precision)))
else:
v = DecimalStringValidator(name=self.name, precision=0)
return [v] + \
super(SODecimalStringCol, self).createValidators(dataType=Decimal)
| (self) |
27,689 | sqlobject.col | SOEnumCol | null | class SOEnumCol(SOCol):
def __init__(self, **kw):
self.enumValues = kw.pop('enumValues', None)
assert self.enumValues is not None, \
'You must provide an enumValues keyword argument'
super(SOEnumCol, self).__init__(**kw)
def autoConstraints(self):
return [constrs.isString, constrs.InList(self.enumValues)]
def createValidators(self):
return [EnumValidator(name=self.name, enumValues=self.enumValues,
notNone=self.notNone)] + \
super(SOEnumCol, self).createValidators()
def _mysqlType(self):
# We need to map None in the enum expression to an appropriate
# condition on NULL
if None in self.enumValues:
return "ENUM(%s)" % ', '.join(
[sqlbuilder.sqlrepr(v, 'mysql') for v in self.enumValues
if v is not None])
else:
return "ENUM(%s) NOT NULL" % ', '.join(
[sqlbuilder.sqlrepr(v, 'mysql') for v in self.enumValues])
def _postgresType(self):
length = max(map(self._getlength, self.enumValues))
enumValues = ', '.join(
[sqlbuilder.sqlrepr(v, 'postgres') for v in self.enumValues])
checkConstraint = "CHECK (%s in (%s))" % (self.dbName, enumValues)
return "VARCHAR(%i) %s" % (length, checkConstraint)
_sqliteType = _postgresType
def _sybaseType(self):
return self._postgresType()
def _mssqlType(self):
return self._postgresType()
def _firebirdType(self):
length = max(map(self._getlength, self.enumValues))
enumValues = ', '.join(
[sqlbuilder.sqlrepr(v, 'firebird') for v in self.enumValues])
checkConstraint = "CHECK (%s in (%s))" % (self.dbName, enumValues)
# NB. Return a tuple, not a string here
return "VARCHAR(%i)" % (length), checkConstraint
def _maxdbType(self):
raise TypeError("Enum type is not supported on MAX DB")
def _getlength(self, obj):
"""
None counts as 0; everything else uses len()
"""
if obj is None:
return 0
else:
return len(obj)
| (**kw) |
27,692 | sqlobject.col | __init__ | null | def __init__(self, **kw):
self.enumValues = kw.pop('enumValues', None)
assert self.enumValues is not None, \
'You must provide an enumValues keyword argument'
super(SOEnumCol, self).__init__(**kw)
| (self, **kw) |
27,696 | sqlobject.col | _firebirdType | null | def _firebirdType(self):
length = max(map(self._getlength, self.enumValues))
enumValues = ', '.join(
[sqlbuilder.sqlrepr(v, 'firebird') for v in self.enumValues])
checkConstraint = "CHECK (%s in (%s))" % (self.dbName, enumValues)
# NB. Return a tuple, not a string here
return "VARCHAR(%i)" % (length), checkConstraint
| (self) |
27,700 | sqlobject.col | _getlength |
None counts as 0; everything else uses len()
| def _getlength(self, obj):
"""
None counts as 0; everything else uses len()
"""
if obj is None:
return 0
else:
return len(obj)
| (self, obj) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.