# SQLAlchemy 0.4 Documentation

Multiple Pages | One Page
Version: 0.4.1 Last Updated: 11/18/07 17:50:18

### 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`

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 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)
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_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, **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 is_select(self)
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.

back to section top

### class MSSQLExecutionContext_pyodbc(MSSQLExecutionContext)

def post_exec(self)
def pre_exec(self)

execute "set nocount on" on all connections, as a partial workaround for multiple result set issues.

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