Code

Opened 7 years ago

Closed 6 years ago

#3702 closed (invalid)

ado_mssql Introspection module

Reported by: moof@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: ado_mssql mssql
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Attached is a patch for the introspection section of ado_mssql. It was currently not implemented, which makes syncdb not work.

There's a rather ugly hack in it due to the fact that adodbapi returns an Error of "None" if no result is returned sometime. I shall try and report this to the adodbapi maintainer.

This has not been tested extensively. I can't find decent documentation for the module's supposed internals, or a test suite. It correctly introspects a bunch of my databases, but if there's an appropriate test module around, I'd like to run it on there first.

Attachments (1)

adodbintrospection.patch (2.9 KB) - added by Moof 7 years ago.
patch for django.db.backends.ado_mssql.introspection

Download all attachments as: .zip

Change History (5)

Changed 7 years ago by Moof

patch for django.db.backends.ado_mssql.introspection

comment:1 Changed 7 years ago by Ramiro Morales

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

moof,

See also ticket #2358 for ongoing work regarding MS SQL Server support enhancements.

comment:2 Changed 7 years ago by Simon G. <dev@…>

Has anyone used this? does it work well?

comment:3 Changed 7 years ago by rokclimb15@…

I just tried to use this today to do some testing on a rather large database with a lot of tables.

I am using Python 2.5.1, Django 0.96 release, adodbapi 2.0.1, and pywin32 build 210 on Windows XP Pro SP2 connecting to SQL Server 2000 SP4 (whew that is a lot of components).

I suspect that the error is not related to Django or this patch, but to the adodbapi or pywin32 components. It appears that it is trying to execute multiple statements inside of a single transaction, which MS SQL server doesn't support.

Here is the output.

# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
#     * Rearrange models' order
#     * Make sure each model has one field with primary_key=True
# Feel free to rename the models, but don't rename db_table values or field names.
#
# Also note: You'll have to insert the output of 'django-admin.py sqlcustom [appname]'
# into your database.

from django.db import models

class ActionObjectPermissions(models.Model):
Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_manager(settings)
  File "c:\python25\Lib\site-packages\django\core\management.py", line 1672, in execute_manager
    execute_from_command_line(action_mapping, argv)
  File "c:\python25\Lib\site-packages\django\core\management.py", line 1574, in execute_from_command_line
    for line in action_mapping[action]():
  File "c:\python25\Lib\site-packages\django\core\management.py", line 844, in inspectdb
    relations = introspection_module.get_relations(cursor, table_name)
  File "c:\python25\lib\site-packages\django\db\backends\ado_mssql\introspection.py", line 27, in get_relations
    my_field_dict = _name_to_index(cursor, table_name)
  File "c:\python25\lib\site-packages\django\db\backends\ado_mssql\introspection.py", line 20, in _name_to_index
    return dict([(d[0], i) for i, d in enumerate(get_table_description(cursor, table_name))])
  File "c:\python25\lib\site-packages\django\db\backends\ado_mssql\introspection.py", line 12, in get_table_description
    cursor.execute("SELECT TOP 1 * FROM %s" % table_name)
  File "c:\python25\lib\site-packages\django\db\backends\util.py", line 12, in execute
    return self.cursor.execute(sql, params)
  File "c:\python25\Lib\site-packages\adodbapi\adodbapi.py", line 592, in execute
    self.executeHelper(operation,0,parameters)
  File "c:\python25\Lib\site-packages\adodbapi\adodbapi.py", line 552, in executeHelper
    self._raiseCursorError(DatabaseError,tracebackhistory)
  File "c:\python25\Lib\site-packages\adodbapi\adodbapi.py", line 407, in _raiseCursorError
    eh(self.conn,self,errorclass,errorvalue)
  File "c:\python25\Lib\site-packages\adodbapi\adodbapi.py", line 38, in standardErrorHandler
    raise errorclass(errorvalue)
adodbapi.adodbapi.DatabaseError: 
-----------
Strategy 1: Traceback:Traceback (most recent call last):
   File "c:\python25\Lib\site-packages\adodbapi\adodbapi.py", line 540, in executeHelper
    adoRetVal=self.cmd.Execute()
   File "<COMObject ADODB.Command>", line 3, in Execute
   File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 258, in _ApplyTypes_
    result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
 com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft OLE DB Provider for SQL Server', 'Cannot create new connection because in manual or distributed transaction mode.', None, 0, -2147467259), None)


-----------
Strategy 2: Traceback:Traceback (most recent call last):
   File "c:\python25\Lib\site-packages\adodbapi\adodbapi.py", line 540, in executeHelper
    adoRetVal=self.cmd.Execute()
   File "<COMObject ADODB.Command>", line 3, in Execute
   File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 258, in _ApplyTypes_
    result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
 com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft OLE DB Provider for SQL Server', 'Cannot create new connection because in manual or distributed transaction mode.', None, 0, -2147467259), None)


-----------
Strategy 3: Traceback:Traceback (most recent call last):
   File "c:\python25\Lib\site-packages\adodbapi\adodbapi.py", line 540, in executeHelper
    adoRetVal=self.cmd.Execute()
   File "<COMObject ADODB.Command>", line 3, in Execute
   File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 258, in _ApplyTypes_
    result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
 com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft OLE DB Provider for SQL Server', 'Cannot create new connection because in manual or distributed transaction mode.', None, 0, -2147467259), None)


-----------
Strategy 4: Traceback:Traceback (most recent call last):
   File "c:\python25\Lib\site-packages\adodbapi\adodbapi.py", line 540, in executeHelper
    adoRetVal=self.cmd.Execute()
   File "<COMObject ADODB.Command>", line 3, in Execute
   File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 258, in _ApplyTypes_
    result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
 com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft OLE DB Provider for SQL Server', 'Cannot create new connection because in manual or distributed transaction mode.', None, 0, -2147467259), None)

--- ADODBAPI on command:SELECT TOP 1 * FROM Action_Object_Permissions with parameters: ()

comment:4 Changed 6 years ago by jacob

  • Resolution set to invalid
  • Status changed from new to closed

This should become part of the external mssql backend I asked for over in #2358.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.