?? mysql.py
字號:
precision Total digits in this number. If length and precision are both None, values are stored to limits allowed by the server. length The number of digits after the decimal point. unsigned Optional. zerofill Optional. If true, values will be stored as strings left-padded with zeros. Note that this does not effect the values returned by the underlying database API, which continue to be numeric. """ if ((precision is None and length is not None) or (precision is not None and length is None)): raise exceptions.ArgumentError( "You must specify both precision and length or omit " "both altogether.") _NumericType.__init__(self, **kw) sqltypes.Float.__init__(self, asdecimal=asdecimal) self.length = length self.precision = precision def get_col_spec(self): if self.precision is not None and self.length is not None: return self._extend("DOUBLE(%(precision)s, %(length)s)" % {'precision': self.precision, 'length' : self.length}) else: return self._extend('DOUBLE')class MSReal(MSDouble): """MySQL REAL type.""" def __init__(self, precision=None, length=None, asdecimal=True, **kw): """Construct a REAL. precision Total digits in this number. If length and precision are both None, values are stored to limits allowed by the server. length The number of digits after the decimal point. unsigned Optional. zerofill Optional. If true, values will be stored as strings left-padded with zeros. Note that this does not effect the values returned by the underlying database API, which continue to be numeric. """ MSDouble.__init__(self, precision, length, asdecimal, **kw) def get_col_spec(self): if self.precision is not None and self.length is not None: return self._extend("REAL(%(precision)s, %(length)s)" % {'precision': self.precision, 'length' : self.length}) else: return self._extend('REAL')class MSFloat(sqltypes.Float, _NumericType): """MySQL FLOAT type.""" def __init__(self, precision=None, length=None, asdecimal=False, **kw): """Construct a FLOAT. precision Total digits in this number. If length and precision are both None, values are stored to limits allowed by the server. length The number of digits after the decimal point. unsigned Optional. zerofill Optional. If true, values will be stored as strings left-padded with zeros. Note that this does not effect the values returned by the underlying database API, which continue to be numeric. """ _NumericType.__init__(self, **kw) sqltypes.Float.__init__(self, asdecimal=asdecimal) self.length = length self.precision = precision def get_col_spec(self): if self.length is not None and self.precision is not None: return self._extend("FLOAT(%s, %s)" % (self.precision, self.length)) elif self.precision is not None: return self._extend("FLOAT(%s)" % (self.precision,)) else: return self._extend("FLOAT") def bind_processor(self, dialect): return Noneclass MSInteger(sqltypes.Integer, _NumericType): """MySQL INTEGER type.""" def __init__(self, length=None, **kw): """Construct an INTEGER. length Optional, maximum display width for this number. unsigned Optional. zerofill Optional. If true, values will be stored as strings left-padded with zeros. Note that this does not effect the values returned by the underlying database API, which continue to be numeric. """ self.length = length _NumericType.__init__(self, **kw) sqltypes.Integer.__init__(self) def get_col_spec(self): if self.length is not None: return self._extend("INTEGER(%(length)s)" % {'length': self.length}) else: return self._extend("INTEGER")class MSBigInteger(MSInteger): """MySQL BIGINTEGER type.""" def __init__(self, length=None, **kw): """Construct a BIGINTEGER. length Optional, maximum display width for this number. unsigned Optional. zerofill Optional. If true, values will be stored as strings left-padded with zeros. Note that this does not effect the values returned by the underlying database API, which continue to be numeric. """ super(MSBigInteger, self).__init__(length, **kw) def get_col_spec(self): if self.length is not None: return self._extend("BIGINT(%(length)s)" % {'length': self.length}) else: return self._extend("BIGINT")class MSTinyInteger(MSInteger): """MySQL TINYINT type.""" def __init__(self, length=None, **kw): """Construct a TINYINT. Note: following the usual MySQL conventions, TINYINT(1) columns reflected during Table(..., autoload=True) are treated as Boolean columns. length Optional, maximum display width for this number. unsigned Optional. zerofill Optional. If true, values will be stored as strings left-padded with zeros. Note that this does not effect the values returned by the underlying database API, which continue to be numeric. """ super(MSTinyInteger, self).__init__(length, **kw) def get_col_spec(self): if self.length is not None: return self._extend("TINYINT(%s)" % self.length) else: return self._extend("TINYINT")class MSSmallInteger(sqltypes.Smallinteger, MSInteger): """MySQL SMALLINTEGER type.""" def __init__(self, length=None, **kw): """Construct a SMALLINTEGER. length Optional, maximum display width for this number. unsigned Optional. zerofill Optional. If true, values will be stored as strings left-padded with zeros. Note that this does not effect the values returned by the underlying database API, which continue to be numeric. """ self.length = length _NumericType.__init__(self, **kw) sqltypes.SmallInteger.__init__(self, length) def get_col_spec(self): if self.length is not None: return self._extend("SMALLINT(%(length)s)" % {'length': self.length}) else: return self._extend("SMALLINT")class MSBit(sqltypes.TypeEngine): """MySQL BIT type. This type is for MySQL 5.0.3 or greater for MyISAM, and 5.0.5 or greater for MyISAM, MEMORY, InnoDB and BDB. For older versions, use a MSTinyInteger(1) type. """ def __init__(self, length=None): self.length = length def result_processor(self, dialect): """Convert a MySQL's 64 bit, variable length binary string to a long.""" def process(value): if value is not None: v = 0L for i in map(ord, value): v = v << 8 | i value = v return value return process def get_col_spec(self): if self.length is not None: return "BIT(%s)" % self.length else: return "BIT"class MSDateTime(sqltypes.DateTime): """MySQL DATETIME type.""" def get_col_spec(self): return "DATETIME"class MSDate(sqltypes.Date): """MySQL DATE type.""" def get_col_spec(self): return "DATE"class MSTime(sqltypes.Time): """MySQL TIME type.""" def get_col_spec(self): return "TIME" def result_processor(self, dialect): def process(value): # convert from a timedelta value if value is not None: return datetime.time(value.seconds/60/60, value.seconds/60%60, value.seconds - (value.seconds/60*60)) else: return None return processclass MSTimeStamp(sqltypes.TIMESTAMP): """MySQL TIMESTAMP type. To signal the orm to automatically re-select modified rows to retrieve the updated timestamp, add a PassiveDefault to your column specification:: from sqlalchemy.databases import mysql Column('updated', mysql.MSTimeStamp, PassiveDefault(sql.text('CURRENT_TIMESTAMP'))) The full range of MySQL 4.1+ TIMESTAMP defaults can be specified in the PassiveDefault:: PassiveDefault(sql.text('CURRENT TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')) """ def get_col_spec(self): return "TIMESTAMP"class MSYear(sqltypes.TypeEngine): """MySQL YEAR type, for single byte storage of years 1901-2155.""" def __init__(self, length=None): self.length = length def get_col_spec(self): if self.length is None: return "YEAR" else: return "YEAR(%s)" % self.lengthclass MSText(_StringType, sqltypes.Text): """MySQL TEXT type, for text up to 2^16 characters.""" def __init__(self, length=None, **kwargs): """Construct a TEXT. length Optional, if provided the server may optimize storage by subsitituting the smallest TEXT type sufficient to store ``length`` characters. charset Optional, a column-level character set for this string value. Takes precendence to 'ascii' or 'unicode' short-hand. collation Optional, a column-level collation for this string value. Takes precedence to 'binary' short-hand. ascii Defaults to False: short-hand for the ``latin1`` character set, generates ASCII in schema. unicode Defaults to False: short-hand for the ``ucs2`` character set, generates UNICODE in schema. national Optional. If true, use the server's configured national character set. binary Defaults to False: short-hand, pick the binary collation type that matches the column's character set. Generates BINARY in schema. This does not affect the type of data stored, only the collation of character data. """ _StringType.__init__(self, **kwargs) sqltypes.Text.__init__(self, length, kwargs.get('convert_unicode', False), kwargs.get('assert_unicode', None)) def get_col_spec(self): if self.length: return self._extend("TEXT(%d)" % self.length) else: return self._extend("TEXT")class MSTinyText(MSText): """MySQL TINYTEXT type, for text up to 2^8 characters.""" def __init__(self, **kwargs): """Construct a TINYTEXT. charset Optional, a column-level character set for this string value. Takes precendence to 'ascii' or 'unicode' short-hand. collation Optional, a column-level collation for this string value. Takes precedence to 'binary' short-hand. ascii Defaults to False: short-hand for the ``latin1`` character set, generates ASCII in schema.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -