__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__
|