On Jun 8, 2010, at 5:38 PM, Clovis Fabricio wrote:
> I'm connecting to mssql server 2000 through pyodbc, via FreeTDS odbc
> driver, on linux ubuntu 10.04.
>
> Sqlalchemy 0.5 uses DATETIME for sqlalchemy.Date() fields.
>
> Now Sqlalchemy 0.6 uses DATE, but sql server 2000 doesn't have a DATE type.
>
> I'm aware that sqlalchemy 2005 has the DATE type, but sqlalchemy 2000 doesn't.
>
> How can I make DATETIME be the default for sqlalchemy.Date() on
> sqlalchemy 0.6 mssql+pyodbc dialect, when connecting to sqlalchemy
> 2000?
>
> I'd like to keep it as clean as possible.
>
> Here's code to reproduce the issue:
>
> import sqlalchemy
> from sqlalchemy import Table, Column, MetaData, Date, Integer, create_engine
>
> engine = create_engine(
> 'mssql+pyodbc://sa:s...@myserver/mydb?driver=FreeTDS')
>
> m = MetaData(bind=engine)
>
> tb = sqlalchemy.Table('test_date', m,
> Column('id', Integer, primary_key=True),
> Column('dt', Date())
> )
> tb.create()
according to our source, DATE is only available on 2008, not 2005 or 2000. I'm
not 100% sure that is correct.
tell me what this test produces:
engine = create_engine(
'mssql+pyodbc://sa:s...@myserver/mydb?driver=FreeTDS')
engine.connect()
print engine.dialect.server_version_info
and also what happens if you force it:
engine = create_engine(...)
engine.connect()
engine.dialect.server_version_info = (8,)
...
tb.create()
>
>
> #################################
> And here is the traceback I'm getting:
> #################################
>
> Traceback (most recent call last):
> File "/tmp/teste.py", line 15, in <module>
> tb.create()
> File "/home/nosklo/.local/lib/python2.6/site-packages/sqlalchemy/schema.py",
> line 428, in create
> bind.create(self, checkfirst=checkfirst)
> File
> "/home/nosklo/.local/lib/python2.6/site-packages/sqlalchemy/engine/base.py",
> line 1647, in create
> connection=connection, **kwargs)
> File
> "/home/nosklo/.local/lib/python2.6/site-packages/sqlalchemy/engine/base.py",
> line 1682, in _run_visitor
> **kwargs).traverse_single(element)
> File
> "/home/nosklo/.local/lib/python2.6/site-packages/sqlalchemy/sql/visitors.py",
> line 77, in traverse_single
> return meth(obj, **kw)
> File
> "/home/nosklo/.local/lib/python2.6/site-packages/sqlalchemy/engine/ddl.py",
> line 58, in visit_table
> self.connection.execute(schema.CreateTable(table))
> File
> "/home/nosklo/.local/lib/python2.6/site-packages/sqlalchemy/engine/base.py",
> line 1157, in execute
> params)
> File
> "/home/nosklo/.local/lib/python2.6/site-packages/sqlalchemy/engine/base.py",
> line 1210, in _execute_ddl
> return self.__execute_context(context)
> File
> "/home/nosklo/.local/lib/python2.6/site-packages/sqlalchemy/engine/base.py",
> line 1268, in __execute_context
> context.parameters[0], context=context)
> File
> "/home/nosklo/.local/lib/python2.6/site-packages/sqlalchemy/engine/base.py",
> line 1367, in _cursor_execute
> context)
> File
> "/home/nosklo/.local/lib/python2.6/site-packages/sqlalchemy/engine/base.py",
> line 1360, in _cursor_execute
> context)
> File
> "/home/nosklo/.local/lib/python2.6/site-packages/sqlalchemy/engine/default.py",
> line 277, in do_execute
> cursor.execute(statement, parameters)
> sqlalchemy.exc.ProgrammingError: (ProgrammingError)
> ('42000', '[42000] [FreeTDS][SQL Server]Column or parameter #2:
> Cannot find data type DATE. (2715)
> (SQLExecDirectW)')
> '\nCREATE TABLE test_date (\n\tid INTEGER NOT NULL IDENTITY(1,1),
> \n\tdt DATE NULL, \n\tPRIMARY KEY (id)\n)\n\n' ()
>
> Thanks in advance
> nosklo
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.