# SQLAlchemy 0.4 Documentation

Multiple Pages | One Page
Version: 0.4.4 Last Updated: 03/11/08 20:04:34

### module sqlalchemy.databases.mssql

MSSQL backend, thru either pymssq, adodbapi or pyodbc interfaces.

- `IDENTITY` columns are supported by using SA `schema.Sequence()` objects. In other words:

      Table('test', mss_engine,
             Column('id',   Integer, Sequence('blah',100,10), primary_key=True),
             Column('name', String(20))
           ).create()

  would yield:

      CREATE TABLE test (
        id INTEGER NOT NULL IDENTITY(100,10) PRIMARY KEY,
        name VARCHAR(20)
        )

  Note that the start & increment values for sequences are optional and will default to 1,1.

- Support for `SET IDENTITY_INSERT ON` mode (automagic on / off for `INSERT` s)

- Support for auto-fetching of `@@IDENTITY/@@SCOPE_IDENTITY()` on `INSERT`

- `select._limit` implemented as `SELECT TOP n`

- Experimental implemention of LIMIT / OFFSET with row_number()

Known issues / TODO:

- No support for more than one `IDENTITY` column per table
- pymssql has problems with binary and unicode data that this module does not work around

### Module Functions

def descriptor()

### class AdoMSNVarchar(MSNVarchar)

overrides bindparam/result processing to not convert any unicode strings

def bind_processor(self, dialect)
def result_processor(self, dialect)
back to section top

### class Decimal(object)

Floating point class for decimal arithmetic.

def adjusted(self)

Return the adjusted exponent of self

def as_tuple(self)

Represents the number as a triple tuple.

To show the internals exactly as they are.

def compare(self, other, context=None)

Compares one to another.

-1 => a < b 0 => a = b 1 => a > b NaN => one is NaN Like __cmp__, but returns Decimal instances.

def max(self, other, context=None)

Returns the larger value.

like max(self, other) except if one is not a number, returns NaN (and signals if one is sNaN). Also rounds.

def min(self, other, context=None)

Returns the smaller value.

like min(self, other) except if one is not a number, returns NaN (and signals if one is sNaN). Also rounds.

def normalize(self, context=None)

Normalize- strip trailing 0s, change anything equal to 0 to 0e0

def quantize(self, exp, rounding=None, context=None, watchexp=1)

Quantize self so its exponent is the same as that of exp.

Similar to self._rescale(exp._exp) but with error checking.

def remainder_near(self, other, context=None)

Remainder nearest to 0- abs(remainder-near) <= other/2

def same_quantum(self, other)

Test whether self and other have the same exponent.

same as self._exp == other._exp, except NaN == sNaN

def sqrt(self, context=None)

Return the square root of self.

Uses a converging algorithm (Xn+1 = 0.5*(Xn + self / Xn)) Should quadratically approach the right answer.

def to_eng_string(self, context=None)

Convert to engineering-type string.

Engineering notation has an exponent which is a multiple of 3, so there are up to 3 digits left of the decimal place.

Same rules for when in exponential and when as a value as in __str__.

def to_integral(self, rounding=None, context=None)

Rounds to the nearest integer, without raising inexact, rounded.

def __abs__(self, round=1, context=None)

Returns the absolute value of self.

If the second argument is 0, do not round.

def __add__(self, other, context=None)

Returns self + other.

-INF + INF (or the reverse) cause InvalidOperation errors.

def __add__(self, other, context=None)

Returns self + other.

-INF + INF (or the reverse) cause InvalidOperation errors.

def __cmp__(self, other, context=None)
def __copy__(self)
def __deepcopy__(self, memo)
def __div__(self, other, context=None)

Return self / other.

def __div__(self, other, context=None)

Return self / other.

def __divmod__(self, other, context=None)

(self // other, self % other)

def __eq__(self, other)
def __float__(self)

Float representation.

def __floordiv__(self, other, context=None)

self // other

def __int__(self)

Converts self to an int, truncating if necessary.

def __long__(self)

Converts to a long.

Equivalent to long(int(self))

def __mod__(self, other, context=None)

self % other

def __mul__(self, other, context=None)

Return self * other.

(+-) INF * 0 (or its reverse) raise InvalidOperation.

def __mul__(self, other, context=None)

Return self * other.

(+-) INF * 0 (or its reverse) raise InvalidOperation.

def __ne__(self, other)
def __neg__(self, context=None)

Returns a copy with the sign switched.

Rounds, if it has reason.

def __nonzero__(self)

Is the number non-zero?

0 if self == 0 1 if self != 0

def __pos__(self, context=None)

Returns a copy, unless it is a sNaN.

Rounds the number (if more then precision digits)

def __pow__(self, n, modulo=None, context=None)

Return self ** n (mod modulo)

If modulo is None (default), don't take it mod modulo.

def __rdiv__(self, other, context=None)

Swaps self/other and returns __div__.

def __rdiv__(self, other, context=None)

Swaps self/other and returns __div__.

def __rdivmod__(self, other, context=None)

Swaps self/other and returns __divmod__.

def __rfloordiv__(self, other, context=None)

Swaps self/other and returns __floordiv__.

def __rmod__(self, other, context=None)

Swaps self/other and returns __mod__.

def __rpow__(self, other, context=None)

Swaps self/other and returns __pow__.

def __rsub__(self, other, context=None)

Return other + (-self)

def __sub__(self, other, context=None)

Return self + (-other)

back to section top

### class MSBigInteger(MSInteger)

def get_col_spec(self)
back to section top

### class MSBinary(Binary)

def get_col_spec(self)
back to section top

### class MSBoolean(Boolean)

def bind_processor(self, dialect)
def get_col_spec(self)
def result_processor(self, dialect)
back to section top

### class MSChar(CHAR)

def get_col_spec(self)
back to section top

### class MSDate(Date)

def __init__(self, *a, **kw)

Construct a new `MSDate`.

def get_col_spec(self)
back to section top

### class MSDateTime(DateTime)

def __init__(self, *a, **kw)

Construct a new `MSDateTime`.

def get_col_spec(self)
back to section top

### class MSDateTime_adodbapi(MSDateTime)

def result_processor(self, dialect)
back to section top

### class MSDateTime_pyodbc(MSDateTime)

def bind_processor(self, dialect)
back to section top

### class MSDate_pymssql(MSDate)

def result_processor(self, dialect)
back to section top

### class MSDate_pyodbc(MSDate)

def bind_processor(self, dialect)
def result_processor(self, dialect)
back to section top

### class MSFloat(Float)

def bind_processor(self, dialect)
def get_col_spec(self)
back to section top

### class MSInteger(Integer)

def get_col_spec(self)
back to section top

### class MSMoney(TypeEngine)

def get_col_spec(self)
back to section top

### class MSNChar(NCHAR)

def get_col_spec(self)
back to section top

### class MSNVarchar(Unicode)

def get_col_spec(self)
back to section top

### class MSNumeric(Numeric)

def bind_processor(self, dialect)
def get_col_spec(self)
def result_processor(self, dialect)
back to section top

### class MSSQLCompiler(DefaultCompiler)

def __init__(self, *args, **kwargs)

Construct a new `MSSQLCompiler`.

def for_update_clause(self, select)
def get_select_precolumns(self, select)

MS-SQL puts TOP, it's version of LIMIT here

def label_select_column(self, select, column, asfrom)
def limit_clause(self, select)
def order_by_clause(self, select)
def visit_alias(self, alias, **kwargs)
def visit_binary(self, binary, **kwargs)

Move bind parameters to the right-hand side of an operator, where possible.

def visit_column(self, column, **kwargs)
def visit_function(self, func, **kwargs)
def visit_select(self, select, **kwargs)

Look for `LIMIT` and OFFSET in a select statement, and if so tries to wrap it in a subquery with `row_number()` criterion.

def visit_table(self, table, mssql_aliased=False, **kwargs)
back to section top

### class MSSQLDefaultRunner(DefaultRunner)

back to section top

### class MSSQLDialect(DefaultDialect)

def __init__(self, auto_identity_insert=True, **params)

Construct a new `MSSQLDialect`.

def create_connect_args(self, url)
def create_execution_context(self, *args, **kwargs)
def dbapi(cls, module_name=None)
def do_execute(self, cursor, statement, params, context=None, **kwargs)
def do_executemany(self, cursor, statement, params, context=None, **kwargs)
def get_default_schema_name(self, connection)
def has_table(self, connection, tablename, schema=None)
def last_inserted_ids(self)
def raw_connection(self, connection)

Pull the raw pymmsql connection out--sensative to "pool.ConnectionFairy" and pymssql.pymssqlCnx Classes

def reflecttable(self, connection, table, include_columns)
def set_default_schema_name(self, schema_name)
def table_names(self, connection, schema)
def type_descriptor(self, typeobj)
def uppercase_table(self, t)
back to section top

### class MSSQLDialect_adodbapi(MSSQLDialect)

def import_dbapi(cls)
def is_disconnect(self, e)
def make_connect_string(self, keys)
back to section top

### class MSSQLDialect_pymssql(MSSQLDialect)

def __init__(self, **params)

Construct a new `MSSQLDialect_pymssql`.

def create_connect_args(self, url)
def do_rollback(self, connection)
def import_dbapi(cls)
def is_disconnect(self, e)
def make_connect_string(self, keys)
back to section top

### class MSSQLDialect_pyodbc(MSSQLDialect)

def __init__(self, **params)

Construct a new `MSSQLDialect_pyodbc`.

def create_execution_context(self, *args, **kwargs)
def do_execute(self, cursor, statement, parameters, context=None, **kwargs)
def import_dbapi(cls)
def is_disconnect(self, e)
def make_connect_string(self, keys)
back to section top

### class MSSQLExecutionContext(DefaultExecutionContext)

def __init__(self, *args, **kwargs)

Construct a new `MSSQLExecutionContext`.

def post_exec(self)

Turn off the INDENTITY_INSERT mode if it's been activated, and fetch recently inserted IDENTIFY values (works only for one column).

def pre_exec(self)

MS-SQL has a special mode for inserting non-NULL values into IDENTITY columns.

Activate it if the feature is turned on and needed.

def returns_rows_text(self, statement)
back to section top

### class MSSQLExecutionContext_pyodbc(MSSQLExecutionContext)

def post_exec(self)
def pre_exec(self)

where appropriate, issue "select scope_identity()" in the same statement

back to section top

### class MSSQLIdentifierPreparer(IdentifierPreparer)

def __init__(self, dialect)

Construct a new `MSSQLIdentifierPreparer`.

back to section top

### class MSSQLSchemaDropper(SchemaDropper)

def visit_index(self, index)
back to section top

### class MSSQLSchemaGenerator(SchemaGenerator)

def get_column_specification(self, column, **kwargs)
back to section top

### class MSSmallInteger(MSInteger)

def get_col_spec(self)
back to section top

### class MSSmallMoney(MSMoney)

def get_col_spec(self)
back to section top

### class MSString(String)

def get_col_spec(self)
back to section top

### class MSText(Text)

def get_col_spec(self)
back to section top

### class MSTime(Time)

def __init__(self, *a, **kw)

Construct a new `MSTime`.

def bind_processor(self, dialect)
def get_col_spec(self)
def result_processor(self, dialect)
back to section top

### class MSTimeStamp(TIMESTAMP)

def get_col_spec(self)
back to section top

### class MSTinyInteger(MSInteger)

def get_col_spec(self)
back to section top

### class MSUniqueIdentifier(TypeEngine)

def get_col_spec(self)
back to section top

### class MSVariant(TypeEngine)

def get_col_spec(self)
back to section top