SQLAlchemy 0.3 Documentation - module sqlalchemy.databases.mssql

# SQLAlchemy 0.3 Documentation

Multiple Pages | One Page
Version: 0.3.10 Last Updated: 07/20/07 17:20:04

### 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
- No support for `GUID` type columns (yet)
- 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 convert_bind_param(self, value, dialect)
def convert_result_value(self, value, dialect)
back to section top

### class MSBinary(Binary)

def get_col_spec(self)
back to section top

### class MSBoolean(Boolean)

def convert_bind_param(self, value, dialect)
def convert_result_value(self, value, dialect)
def get_col_spec(self)
back to section top

### class MSChar(CHAR)

def get_col_spec(self)
back to section top

### class MSDate(Date)

def __init__(self, *a, **kw)
def get_col_spec(self)
back to section top

### class MSDateTime(DateTime)

def __init__(self, *a, **kw)
def get_col_spec(self)
back to section top

### class MSDateTime_adodbapi(MSDateTime)

def convert_result_value(self, value, dialect)
back to section top

### class MSDateTime_pyodbc(MSDateTime)

def convert_bind_param(self, value, dialect)
back to section top

### class MSDate_pymssql(MSDate)

def convert_result_value(self, value, dialect)
back to section top

### class MSDate_pyodbc(MSDate)

def convert_bind_param(self, value, dialect)
def convert_result_value(self, value, dialect)
back to section top

### class MSFloat(Float)

def convert_bind_param(self, value, dialect)

By converting to string, we can use Decimal types round-trip.

def get_col_spec(self)
back to section top

### class MSInteger(Integer)

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 convert_bind_param(self, value, dialect)
def convert_result_value(self, value, dialect)
def get_col_spec(self)
back to section top

### class MSSQLCompiler(ANSICompiler)

def __init__(self, dialect, statement, parameters, **kwargs)
def for_update_clause(self, select)
def limit_clause(self, select)
def order_by_clause(self, select)
def visit_alias(self, alias)
def visit_binary(self, binary)

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

def visit_column(self, column)
def visit_function(self, func)
def visit_select(self, select)
def visit_select_precolumns(self, select)

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

def visit_table(self, table)
back to section top

### class MSSQLDefaultRunner(ANSIDefaultRunner)

back to section top

### class MSSQLDialect(ANSIDialect)

def __init__(self, auto_identity_insert=True, **params)
def compiler(self, statement, bindparams, **kwargs)
def create_connect_args(self, url)
def create_execution_context(self, *args, **kwargs)
def dbapi(cls, module_name=None)
def defaultrunner(self, connection, **kwargs)
def do_execute(self, cursor, statement, params, **kwargs)
def get_default_schema_name(self)
def has_table(self, connection, tablename, schema=None)
def last_inserted_ids(self)
def preparer(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)
def schemadropper(self, *args, **kwargs)
def schemagenerator(self, *args, **kwargs)
def set_default_schema_name(self, schema_name)
def supports_sane_rowcount(self)
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)
def supports_sane_rowcount(self)
def supports_unicode_statements(self)

indicate whether the DBAPI can receive SQL statements as Python unicode strings

back to section top

### class MSSQLDialect_pymssql(MSSQLDialect)

def __init__(self, **params)
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)
def max_identifier_length(self)
def supports_sane_rowcount(self)
back to section top

### class MSSQLDialect_pyodbc(MSSQLDialect)

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)
def supports_sane_rowcount(self)
def supports_unicode_statements(self)

indicate whether the DBAPI can receive SQL statements as Python unicode strings

back to section top

### class MSSQLExecutionContext(DefaultExecutionContext)

def __init__(self, *args, **kwargs)
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(ANSIIdentifierPreparer)

def __init__(self, dialect)
back to section top

### class MSSQLSchemaDropper(ANSISchemaDropper)

def visit_index(self, index)
back to section top

### class MSSQLSchemaGenerator(ANSISchemaGenerator)

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

### class MSSmallInteger(SmallInteger)

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 MSTimeStamp(TIMESTAMP)

def get_col_spec(self)
back to section top

### class MSTinyInteger(Integer)

def get_col_spec(self)
back to section top