[sqlalchemy] Re: More SA, pyodbc, *nux and MSSQL problems

2009-07-26 Thread Timothy N. Tsvetkov

Please, tell me about using it in OS X? What driver do u use, versions
etc.

On Jul 25, 6:17 am, mtrier  wrote:
> On Jul 23, 8:30 am, Ed Singleton  wrote:
>
> > I've managed to get SA (0.6 branch) and pyodbc connecting to anMSSQL 
> > db on Mac OS X, but I've recently been trying to get it working on  
> > linux (Debian Lenny) and have been hitting some problems.
>
> > It's definitely working to some degree.  Adding "TDS_Version = 8.0" to  
> > my odbc.ini fixed some unicode problems, and so now simple pyodbc  
> > stuff seems to work.  Querying seems to be fine, but sometimes adding  
> > lots of data using the orm fails with the message: DBAPIError: (Error)  
> > ('HY000', 'The driver did not supply an error!')
>
> > The same error occurs in both SA 0.5.5 and SA 0.6
>
> > I'm going to try a few more things to narrow down a bit more where the  
> > problem is, but if any has any ideas of what it could be or how I  
> > could debug it, I'd be very grateful.
>
> Any luck on this? I'm using both with OSX and Ubuntu without
> differences in behavior.  Do you have an isolated test case that
> duplicates this behavior?
>
> Michael
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Questions on SQLA Queries

2009-05-28 Thread Timothy N. Tsvetkov

You right, i don't like chain, because i'm to lazy to import itertools
%) so i use 'map'.

On May 27, 5:13 pm, Gregg Lind  wrote:
> I believe by "map function", Timothy may be implying that you should
> use any of the python idioms for converting iterables of tuples to a
> straight tuple.  The one I like best
>
> from itertools import chain
> q = session.query(User.name)  #(User is a class)
> names = itertools.chain(*q.all() )
>
> But you could use generator comprehensions (  names = (x[0] for x in
> q.all()),  operator.itemgetter, or map instead.
>
> Correct me, Timothy, if necessary.
>
> Gregg
>
> On Wed, May 27, 2009 at 6:25 AM, Harish Vishwanath
>
>
>
>  wrote:
> > Thanks!
>
> > Could you elaborate on how you use the map function? I couldn't find it
> > myself in the docs.
>
> > Regards,
> > Harish
>
> > On Wed, May 27, 2009 at 3:07 PM, Timothy N. Tsvetkov
> >  wrote:
>
> >> Q1. Good question %) I didn't find anything about it in docs (but i
> >> didn't search a lot), so i use map function to convert it to a list
> >> you want. And I think it is the right solution. Because if you query
> >> for more then one column (session.query(User.is, User.name).all()) a
> >> list of tuples is what you want to get as a result. So i think it is
> >> good, that it works the same way for one or more then one query
> >> params.
>
> >> On May 26, 9:10 pm, Harish Vishwanath 
> >> wrote:
> >> > Hello,
>
> >> > Question 1:
>
> >> > When there is a query like below :
>
> >> > q = session.query(User.name)  #(User is a class)
>
> >> > and when I do q.all(), a list of tuples (User.name,) is returned though
> >> > a
> >> > single column is asked for. Is there a way to get a list directly from
> >> > q.all() when a single column is required?
>
> >> > Question 2:
>
> >> > I need to delete a bulky table and I want to print diagnostics after n
> >> > number of deletes. Is there a way to use Query object so that a SQL
> >> > statement like below can be generated?
>
> >> > " delete from movie where year in (select top 30 year from movie where
> >> > year
>
> >> > > 50); ", so that a  message can be logged after every 30 deletes.
>
> >> > I am using Sqlite DB.
>
> >> > Regards,
> >> > Harish
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Questions on SQLA Queries

2009-05-27 Thread Timothy N. Tsvetkov

Q1. Good question %) I didn't find anything about it in docs (but i
didn't search a lot), so i use map function to convert it to a list
you want. And I think it is the right solution. Because if you query
for more then one column (session.query(User.is, User.name).all()) a
list of tuples is what you want to get as a result. So i think it is
good, that it works the same way for one or more then one query
params.

On May 26, 9:10 pm, Harish Vishwanath 
wrote:
> Hello,
>
> Question 1:
>
> When there is a query like below :
>
> q = session.query(User.name)  #(User is a class)
>
> and when I do q.all(), a list of tuples (User.name,) is returned though a
> single column is asked for. Is there a way to get a list directly from
> q.all() when a single column is required?
>
> Question 2:
>
> I need to delete a bulky table and I want to print diagnostics after n
> number of deletes. Is there a way to use Query object so that a SQL
> statement like below can be generated?
>
> " delete from movie where year in (select top 30 year from movie where year
>
> > 50); ", so that a  message can be logged after every 30 deletes.
>
> I am using Sqlite DB.
>
> Regards,
> Harish
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: ProgrammingError: (ProgrammingError) Cannot operate on a closed cursor. None None

2009-03-17 Thread Timothy N. Tsvetkov

I have the same problem, I've installed pysqlite (2.5.5) from sources,
and after I've removed it everything is ok.

I've tried to install the last one because I had a common problem:

ProgrammingError?: (ProgrammingError?) You must not use 8-bit
bytestrings unless you use a text_factory that can interpret 8-bit
bytestrings (like text_factory = str). It is highly recommended that
you instead just switch your application to Unicode strings. u'INSERT
INTO financialaccount (title, "order", "storedNumber", "parentId")
VALUES (?, ?, ?, ?)' ['\xd0\xa2\xd0\xbe
\xd0\xb2\xd0\xb0\xd1\x80\xd1\x8b', '00041', '41', None]

So I've removed my python25, than installed in again from ports
(Darwin) and installed again from ports pysqlite... and hurra!!! No
error with 8-bit bytesstrings. The fun was, that my pysqlite version
was more then 2.1.3. %)

pysqlite kills me %) soon as i need it only for tests, because in
production we use postgresql.

On Mar 15, 11:52 pm, Michael Bayer  wrote:
> this appears to be a SQLite bug and I've created a ticket at:
>
> http://oss.itsystementwicklung.de/trac/pysqlite/ticket/256
>
> On Mar 15, 2009, at 5:36 AM, GeertVc wrote:
>
>
>
>
>
> > Hi,
>
> > I have a problem following the DivingIn tutorial on
> >http://elixir.ematia.de/trac/wiki/TutorialDivingIn.
>
> > I've posted a question about the problem (http://groups.google.com/
> > group/sqlelixir/browse_thread/thread/419fddeb4c70a3d2), but so far, no
> > luck.
>
> > Since this is based on SqlAlchemy, I thought I'd give it a try here (I
> > know this is cross-posting, but I would like to understand what's
> > going wrong...).
>
> > Maybe someone over here knows the cause of my problem?
>
> > Any help much appreciated, since I'd really like to continue with this
> > db in Python...
>
> > Best rgds,
>
> > --Geert
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Problems with cursor, don't know what to do.

2009-02-25 Thread Timothy N. Tsvetkov

More info: I have MacOSX and use iODBC with FreeTDS driver.

And looks like everything is OK:

FreeTDS:

[tu...@2kan-2:~/bigur]% tsql -S libra -p 1433 -U user
locale is "ru_RU.KOI8-R/UTF-8/ru_RU.KOI8-R/ru_RU.KOI8-R/ru_RU.KOI8-R/
ru_RU.KOI8-R"
locale charset is ""
Password:
1> select * from tax
2> go
<...>
(4 rows affected)

ODBC:
iodbctest "DSN=libra;UID=user;PWD=password"
iODBC Demonstration program
This program shows an interactive SQL processor
Driver Manager: 03.52.0406.1211
Driver: 0.82 (libtdsodbc.so)

SQL>...

And also I tried to connect with pyodbc:

tu...@2kan-2:~/bigur/calculation]% py
Python 2.5.2 (r252:60911, Feb 23 2009, 21:22:55)
[GCC 4.0.1 (Apple Inc. build 5488)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import pyodbc
>>> pyodbc.connect("DSN=libra;UID=gik;PWD=123")
< pyodbc.connection object="object" at="at" 0x57620="0x57620" >
>>> c = _.cursor()
>>> c.execute("SELECT * from tax").fetchall()
<...>

On Feb 24, 9:04 pm, "Timothy N. Tsvetkov" 
wrote:
> Hi all, I'm new to SQLAlchemy, and I've a problem using it.
>
> [tu...@2kan-2:~/bigur/calculation]%
> python
> Python 2.5.2 (r252:60911, Feb 23 2009, 21:22:55)
> [GCC 4.0.1 (Apple Inc. build 5488)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>
> >>> from sqlalchemy import *
> >>> db = 
> >>> create_engine('mssql://some_name:some_passwpod@/?dsn=Libra&driver=FreeTDS')
> >>> metadata = MetaData()
> >>> metadata.bind = db
> >>> metadata.bind.echo = True
> >>> users_table = Table('tax', metadata, autoload=True)
>
> 2009-02-24 20:54:55,261 INFO sqlalchemy.engine.base.Engine.0x...2850
> SELECT user_name() as user_name;
> 2009-02-24 20:54:55,261 INFO sqlalchemy.engine.base.Engine.0x...2850
> []
> 2009-02-24 20:54:55,280 WARNING sqlalchemy.pool.QueuePool.0x...27b0
> Error closing cursor: Attempt to use a closed cursor.
> 2009-02-24 20:54:55,280 INFO sqlalchemy.engine.base.Engine.0x...2850
> ROLLBACK
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/opt/local/lib/python2.5/site-packages/
> SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/schema.py", line 113,
> in __call__
>     return type.__call__(self, name, metadata, *args, **kwargs)
>   File "/opt/local/lib/python2.5/site-packages/
> SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/schema.py", line 241,
> in __init__
>     _bind_or_error(metadata).reflecttable(self,
> include_columns=include_columns)
>   File "/opt/local/lib/python2.5/site-packages/
> SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py", line
> 1265, in reflecttable
>     self.dialect.reflecttable(conn, table, include_columns)
>   File "/opt/local/lib/python2.5/site-packages/
> SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/databases/mssql.py",
> line 1123, in reflecttable
>     current_schema = self.get_default_schema_name(connection)
>   File "", line 1, in 
>   File "/opt/local/lib/python2.5/site-packages/
> SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py", line
> 1894, in decorated
>     connection.info[key] = val = fn(self, connection)
>   File "/opt/local/lib/python2.5/site-packages/
> SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/databases/mssql.py",
> line 1070, in get_default_schema_name
>     user_name = connection.scalar(sql.text(query))
>   File "/opt/local/lib/python2.5/site-packages/
> SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py", line
> 814, in scalar
>     return self.execute(object, *multiparams, **params).scalar()
>   File "/opt/local/lib/python2.5/site-packages/
> SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py", line
> 1676, in scalar
>     self.connection._handle_dbapi_exception(e, None, None,
> self.cursor, self.context)
>   File "/opt/local/lib/python2.5/site-packages/
> SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py", line
> 931, in _handle_dbapi_exception
>     raise exc.DBAPIError.instance(statement, parameters, e,
> connection_invalidated=is_disconnect)
> sqlalchemy.exc.ProgrammingError: (ProgrammingError) Attempt to use a
> closed cursor. None None
>
> What I'm doing wrong?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Problems with cursor, don't know what to do.

2009-02-24 Thread Timothy N. Tsvetkov

Hi all, I'm new to SQLAlchemy, and I've a problem using it.

[tu...@2kan-2:~/bigur/calculation]%
python
Python 2.5.2 (r252:60911, Feb 23 2009, 21:22:55)
[GCC 4.0.1 (Apple Inc. build 5488)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> from sqlalchemy import *

>>> db = 
>>> create_engine('mssql://some_name:some_passwpod@/?dsn=Libra&driver=FreeTDS')
>>> metadata = MetaData()
>>> metadata.bind = db
>>> metadata.bind.echo = True
>>> users_table = Table('tax', metadata, autoload=True)
2009-02-24 20:54:55,261 INFO sqlalchemy.engine.base.Engine.0x...2850
SELECT user_name() as user_name;
2009-02-24 20:54:55,261 INFO sqlalchemy.engine.base.Engine.0x...2850
[]
2009-02-24 20:54:55,280 WARNING sqlalchemy.pool.QueuePool.0x...27b0
Error closing cursor: Attempt to use a closed cursor.
2009-02-24 20:54:55,280 INFO sqlalchemy.engine.base.Engine.0x...2850
ROLLBACK
Traceback (most recent call last):
  File "", line 1, in 
  File "/opt/local/lib/python2.5/site-packages/
SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/schema.py", line 113,
in __call__
return type.__call__(self, name, metadata, *args, **kwargs)
  File "/opt/local/lib/python2.5/site-packages/
SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/schema.py", line 241,
in __init__
_bind_or_error(metadata).reflecttable(self,
include_columns=include_columns)
  File "/opt/local/lib/python2.5/site-packages/
SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py", line
1265, in reflecttable
self.dialect.reflecttable(conn, table, include_columns)
  File "/opt/local/lib/python2.5/site-packages/
SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/databases/mssql.py",
line 1123, in reflecttable
current_schema = self.get_default_schema_name(connection)
  File "", line 1, in 
  File "/opt/local/lib/python2.5/site-packages/
SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py", line
1894, in decorated
connection.info[key] = val = fn(self, connection)
  File "/opt/local/lib/python2.5/site-packages/
SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/databases/mssql.py",
line 1070, in get_default_schema_name
user_name = connection.scalar(sql.text(query))
  File "/opt/local/lib/python2.5/site-packages/
SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py", line
814, in scalar
return self.execute(object, *multiparams, **params).scalar()
  File "/opt/local/lib/python2.5/site-packages/
SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py", line
1676, in scalar
self.connection._handle_dbapi_exception(e, None, None,
self.cursor, self.context)
  File "/opt/local/lib/python2.5/site-packages/
SQLAlchemy-0.5.3dev_r5814-py2.5.egg/sqlalchemy/engine/base.py", line
931, in _handle_dbapi_exception
raise exc.DBAPIError.instance(statement, parameters, e,
connection_invalidated=is_disconnect)
sqlalchemy.exc.ProgrammingError: (ProgrammingError) Attempt to use a
closed cursor. None None

What I'm doing wrong?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---