- had to tweak out latest MS-SQL module change. cant do ImportErrors right now until module
importing is moved to the connection phase across all dialects.
- took out "his" from url docstrings
- postgres doesnt do an import *
import sqlalchemy.ext.sessioncontext as sessioncontext
import sqlalchemy.mods.threadlocal as threadlocal
import sqlalchemy.ext.selectresults as selectresults
+import sqlalchemy.databases as databases
def make_doc(obj, classes=None, functions=None):
"""generate a docstring.ObjectDoc structure for an individual module, list of classes, and list of functions."""
make_doc(obj=selectresults),
make_doc(obj=exceptions),
make_doc(obj=proxy),
- ]
+ ] + [make_doc(getattr(__import__('sqlalchemy.databases.%s' % m).databases, m)) for m in databases.__all__]
return objects
def create_docstring_toc(data, root):
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-__all__ = ['oracle', 'postgres', 'sqlite', 'mysql', 'mssql', 'firebird']
+__all__ = ['sqlite', 'postgres', 'mysql', 'oracle', 'mssql', 'firebird']
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 ``SET IDENTITY_INSERT ON`` mode (automagic on / off for
+ ``INSERT`` s)
* Support for auto-fetching of ``@@IDENTITY`` on ``INSERT``
* 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)
+ (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
+
"""
import sys, StringIO, string, types, re, datetime
}
def __new__(cls, module_name=None, *args, **kwargs):
+ module = kwargs.get('module', None)
if cls != MSSQLDialect:
return super(MSSQLDialect, cls).__new__(cls, *args, **kwargs)
if module_name:
if not hasattr(dialect, 'module'):
raise dialect.saved_import_error
return dialect(*args, **kwargs)
+ elif module:
+ return object.__new__(cls, *args, **kwargs)
else:
for dialect in dialect_preference:
if hasattr(dialect, 'module'):
return dialect(*args, **kwargs)
- raise ImportError('No DBAPI module detected for MSSQL - please install adodbapi, pymssql or pyodbc')
-
- def __init__(self, module_name=None, auto_identity_insert=True, **params):
+ #raise ImportError('No DBAPI module detected for MSSQL - please install adodbapi, pymssql or pyodbc')
+ else:
+ return object.__new__(cls, *args, **kwargs)
+
+ def __init__(self, module_name=None, module=None, auto_identity_insert=True, **params):
+ if not hasattr(self, 'module'):
+ self.module = module
super(MSSQLDialect, self).__init__(**params)
self.auto_identity_insert = auto_identity_insert
self.text_as_varchar = False
self.set_default_schema_name("dbo")
-
+
def create_connect_args(self, url):
opts = url.translate_connect_args(['host', 'database', 'user', 'password', 'port'])
opts.update(url.query)
raise exceptions.NoSuchTableError(table.name)
def moretableinfo(self, connection, table):
- """Return (tabletype, {colname:foreignkey,...})
- execute(SHOW CREATE TABLE child) =>
- CREATE TABLE `child` (
- `id` int(11) default NULL,
- `parent_id` int(11) default NULL,
- KEY `par_ind` (`parent_id`),
- CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`) ON DELETE CASCADE\n) TYPE=InnoDB
+ """runs SHOW CREATE TABLE to get foreign key/options information about the table.
+
"""
c = connection.execute("SHOW CREATE TABLE " + table.fullname, {})
desc_fetched = c.fetchone()[1]
self.strings[column] = self.strings[column] + "(+)"
def visit_insert(self, insert):
- """``INSERT``s are required to have the primary keys be explicitly present.
+ """``INSERT`` s are required to have the primary keys be explicitly present.
Mapper will by default not put them in the insert statement
to comply with autoincrement fields that require they not be
import sqlalchemy.types as sqltypes
import sqlalchemy.exceptions as exceptions
from sqlalchemy.databases import information_schema as ischema
-from sqlalchemy import *
import re
try:
ORDER BY a.attnum
""" % schema_where_clause
- s = text(SQL_COLS)
+ s = sql.text(SQL_COLS)
c = connection.execute(s, table_name=table.name,
schema=table.schema)
rows = c.fetchall()
sch = table.schema
if '.' not in match.group(2) and sch is not None:
default = match.group(1) + sch + '.' + match.group(2) + match.group(3)
- colargs.append(PassiveDefault(sql.text(default)))
+ colargs.append(schema.PassiveDefault(sql.text(default)))
table.append_column(schema.Column(name, coltype, nullable=nullable, *colargs))
AND i.indisprimary = 't')
ORDER BY attnum
"""
- t = text(PK_SQL)
+ t = sql.text(PK_SQL)
c = connection.execute(t, table=table_oid)
for row in c.fetchall():
pk = row[0]
ORDER BY 1
"""
- t = text(FK_SQL)
+ t = sql.text(FK_SQL)
c = connection.execute(t, table=table_oid)
for conname, condef in c.fetchall():
m = re.search('FOREIGN KEY \((.*?)\) REFERENCES (?:(.*?)\.)?(.*?)\((.*?)\)', condef).groups()
"""
result = []
- #for module in sqlalchemy.databases.__all__:
- for module in ['sqlite', 'postgres', 'mysql']:
+ for module in sqlalchemy.databases.__all__:
module = getattr(__import__('sqlalchemy.databases.%s' % module).databases, module)
result.append(module.descriptor())
return result
Attributes on URL include:
drivername
- The name of the database backend.
+ The name of the database backend. this name will correspond to a module in sqlalchemy/databases
username
The user name for the connection.
password
- His password.
+ database password.
host
The name of the host.