google-code-export / django-pyodbc

Automatically exported from code.google.com/p/django-pyodbc
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Error in operations.py looking for more arguments. #127

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hey Guys I am having a problem getting django-pyodbc running on 

Ubuntu 12.04 LTS 64x

When using setting in DJANGO 1.4
--------------------------------
DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'DBName',           
        'USER': 'myuser', 
        'PASSWORD': 'password', 
        'HOST': 'servername\sql2008_r2',
        'PORT': '',
    }
}

DATABASE_OPTIONS= {
    'driver': 'FreeTDS',
    'dns': 'SQLDNS',
    'collation': 'Latin1_General_CI_AS',
}

I get the following error
-------------------------
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/shell.py", line 45, in handle_noargs
    from django.db.models.loading import get_models
  File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 40, in <module>
    backend = load_backend(connection.settings_dict['ENGINE'])
  File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 34, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 93, in __getitem__
    conn = backend.DatabaseWrapper(db, alias)
  File "/usr/local/lib/python2.7/dist-packages/sql_server/pyodbc/base.py", line 133, in __init__
    self.ops = DatabaseOperations(self)
  File "/usr/local/lib/python2.7/dist-packages/sql_server/pyodbc/operations.py", line 11, in __init__
    super(DatabaseOperations, self).__init__()
TypeError: __init__() takes exactly 2 arguments (1 given)

I am using django-pyodbc ref 191

When using just pyodbc with connection string
pyodbc.connect("DRIVER=FreeTDS;SERVER=servername\\sql_2008r2;UID=myuser;PWD=pass
word;DATABASE=DBName") 
I do get an connection.

Please advice.

Original issue reported on code.google.com by lombaard...@gmail.com on 17 Jul 2012 at 1:41

GoogleCodeExporter commented 9 years ago
I think passing connection into __init__() fixes this

Original comment by bench...@gmail.com on 18 Sep 2012 at 11:27

GoogleCodeExporter commented 9 years ago
This is a regression from Django 1.4 which has not been pulled from any patch 
maintainer. avidal has forked the project on github and as much as I hate 
seeing forks, django-pyodbc has not been updated in almost a year including 
zero bug fixes on trunk. The project should really be turned over to additional 
maintainers if no one is going to update trunk for modern Django versions.

Original comment by bj.car...@gmail.com on 20 Sep 2012 at 9:40

GoogleCodeExporter commented 9 years ago
Oops... you can find avidal's patches here:

https://github.com/avidal/django-pyodbc

Original comment by bj.car...@gmail.com on 20 Sep 2012 at 9:40

GoogleCodeExporter commented 9 years ago
I was getting the same error (in addition to another error where the parameter 
count was not correct).
Here are the changes I made to get resolve these errors.

--- sql_server/pyodbc/operations.py     (revision 191)
+++ sql_server/pyodbc/operations.py     (working copy)
@@ -7,7 +7,8 @@
 class DatabaseOperations(BaseDatabaseOperations):
     compiler_module = "sql_server.pyodbc.compiler"
     def __init__(self, connection):
-        super(DatabaseOperations, self).__init__()
+        super(DatabaseOperations, self).__init__(self)
+
         self.connection = connection
         self._ss_ver = None

@@ -52,7 +53,7 @@
         if lookup_type == 'day':
             return "Convert(datetime, Convert(varchar(12), %s, 112))" % field_name

-    def field_cast_sql(self, db_type):
+    def field_cast_sql(self, db_type, internal_type):
         """
         Given a column type (e.g. 'BLOB', 'VARCHAR'), returns the SQL necessary
         to cast it before using it in a WHERE statement. Note that the

Original comment by Terry.Dr...@gmail.com on 14 Jun 2013 at 3:51