SQLAlchemy 0.3 Documentation

Version: 0.3.5 Last Updated: 03/18/07 18:39:07

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 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 table reflection of IDENTITY columns with (seed,increment) values other than (1,1)
  • 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()
back to section top

class AdoMSNVarchar(MSNVarchar)

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

class AdoMSUnicode(MSUnicode)

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

class MSDateTime(DateTime)

def __init__(self, *a, **kw)
def convert_bind_param(self, value, dialect)
def convert_result_value(self, value, dialect)
def get_col_spec(self)
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(MSString)

NVARCHAR string, does Unicode conversion if dialect.convert_encoding is True.

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 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_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, module_name=None, module=None, auto_identity_insert=True, **params)
def compiler(self, statement, bindparams, **kwargs)
def connection(self)

returns a managed DBAPI connection from this SQLEngine's connection pool.

def create_connect_args(self, url)
def create_execution_context(self)
def dbapi(self)
def defaultrunner(self, engine, proxy)
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(ANSIDialect)

def __init__(self, module_name=None, module=None, auto_identity_insert=True, **params)
def compiler(self, statement, bindparams, **kwargs)
def connection(self)

returns a managed DBAPI connection from this SQLEngine's connection pool.

def create_connect_args(self, url)
def create_execution_context(self)
def dbapi(self)
def defaultrunner(self, engine, proxy)
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 make_connect_string(self, keys)
def supports_sane_rowcount(self)
back to section top

class MSSQLDialect_pymssql(MSSQLDialect)

def create_connect_args(self, url)
def do_rollback(self, connection)
def make_connect_string(self, keys)
def supports_sane_rowcount(self)
back to section top

class MSSQLDialect_pyodbc(MSSQLDialect)

def make_connect_string(self, keys)
def supports_sane_rowcount(self)
back to section top

class MSSQLExecutionContext(DefaultExecutionContext)

def __init__(self, dialect)
def post_exec(self, engine, proxy, compiled, parameters, **kwargs)

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, engine, proxy, compiled, parameters, **kwargs)

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 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 MSTinyInteger(Integer)

def get_col_spec(self)
back to section top

class MSUnicode(Unicode)

Unicode subclass, does Unicode conversion in all cases, uses NVARCHAR impl.

back to section top