sqlalchemy :: types :: String :: Class String
[hide private]
[frames] | no frames]

Class String

                    object --+    
                             |    
                  Concatenable --+
                                 |
            object --+           |
                     |           |
sql.visitors.Visitable --+       |
                         |       |
              AbstractType --+   |
                             |   |
                    TypeEngine --+
                                 |
                                String

The base for all string and character types.

In SQL, corresponds to VARCHAR. Can also take Python unicode objects and encode to the database's encoding in bind params (and the reverse for result sets.)

The `length` field is usually required when the `String` type is used within a CREATE TABLE statement, as VARCHAR requires a length on most databases.

Nested Classes [hide private]

Inherited from sql.visitors.Visitable: __metaclass__

Instance Methods [hide private]
 
__init__(self, length=None, convert_unicode=False, assert_unicode=None, unicode_error=None, _warn_on_bytestring=False)
Create a string-holding type.
 
_compiler_dispatch(self, visitor, **kw)
 
adapt(self, impltype)
 
bind_processor(self, dialect)
Return a conversion function for processing bind values.
 
get_dbapi_type(self, dbapi)
Return the corresponding type object from the underlying DB-API, if any.
 
result_processor(self, dialect, coltype)
Return a conversion function for processing result row values.

Inherited from Concatenable (private): _adapt_expression

Inherited from TypeEngine: __getstate__, dialect_impl

Inherited from TypeEngine (private): _impl_dict

Inherited from AbstractType: __repr__, compare_values, compile, copy_value, is_mutable

Inherited from AbstractType (private): _coerce_compared_value, _compare_type_affinity, _type_affinity

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__

Class Variables [hide private]
  __visit_name__ = 'string'
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, length=None, convert_unicode=False, assert_unicode=None, unicode_error=None, _warn_on_bytestring=False)
(Constructor)

 

Create a string-holding type.

:param length: optional, a length for the column for use in
  DDL statements.  May be safely omitted if no ``CREATE
  TABLE`` will be issued.  Certain databases may require a
  *length* for use in DDL, and will raise an exception when
  the ``CREATE TABLE`` DDL is issued.  Whether the value is
  interpreted as bytes or characters is database specific.

:param convert_unicode: defaults to False.  If True, the 
  type will do what is necessary in order to accept 
  Python Unicode objects as bind parameters, and to return
  Python Unicode objects in result rows.   This may
  require SQLAlchemy to explicitly coerce incoming Python 
  unicodes into an encoding, and from an encoding 
  back to Unicode, or it may not require any interaction
  from SQLAlchemy at all, depending on the DBAPI in use.

  When SQLAlchemy performs the encoding/decoding, 
  the encoding used is configured via
  :attr:`~sqlalchemy.engine.base.Dialect.encoding`, which
  defaults to `utf-8`.

  The "convert_unicode" behavior can also be turned on
  for all String types by setting 
  :attr:`sqlalchemy.engine.base.Dialect.convert_unicode`
  on create_engine().
  
  To instruct SQLAlchemy to perform Unicode encoding/decoding
  even on a platform that already handles Unicode natively,
  set convert_unicode='force'.  This will incur significant
  performance overhead when fetching unicode result columns.
  
:param assert_unicode: Deprecated.  A warning is raised in all cases when a non-Unicode
  object is passed when SQLAlchemy would coerce into an encoding
  (note: but **not** when the DBAPI handles unicode objects natively).
  To suppress or raise this warning to an 
  error, use the Python warnings filter documented at:
  http://docs.python.org/library/warnings.html

:param unicode_error: Optional, a method to use to handle Unicode
  conversion errors. Behaves like the 'errors' keyword argument to
  the standard library's string.decode() functions.   This flag
  requires that `convert_unicode` is set to `"force"` - otherwise,
  SQLAlchemy is not guaranteed to handle the task of unicode
  conversion.   Note that this flag adds significant performance
  overhead to row-fetching operations for backends that already
  return unicode objects natively (which most DBAPIs do).  This
  flag should only be used as an absolute last resort for reading
  strings from a column with varied or corrupted encodings,
  which only applies to databases that accept invalid encodings 
  in the first place (i.e. MySQL.  *not* PG, Sqlite, etc.)

Overrides: object.__init__

adapt(self, impltype)

 
Overrides: TypeEngine.adapt

bind_processor(self, dialect)

 

Return a conversion function for processing bind values.

Returns a callable which will receive a bind parameter value as the sole positional argument and will return a value to send to the DB-API.

If processing is not necessary, the method should return ``None``.

Overrides: AbstractType.bind_processor
(inherited documentation)

get_dbapi_type(self, dbapi)

 
Return the corresponding type object from the underlying DB-API, if
any.

 This can be useful for calling ``setinputsizes()``, for example.

Overrides: AbstractType.get_dbapi_type
(inherited documentation)

result_processor(self, dialect, coltype)

 

Return a conversion function for processing result row values.

Returns a callable which will receive a result row column value as the sole positional argument and will return a value to return to the user.

If processing is not necessary, the method should return ``None``.

Overrides: AbstractType.result_processor
(inherited documentation)