Re: [sqlalchemy] Pyodbc.Connection has no attribute 'dbms_ver'?

2016-02-14 Thread Jaimy Azle
Try to use ibm_db_sa 0.3.2 instead, apparently you are using the previous
version. dbms_ver is a feature specific of native ibm_db version of which
not available in pyodbc.

https://pypi.python.org/pypi/ibm_db_sa/0.3.2


Salam,

-Jaimy.


On Feb 12, 2016 22:05, "Alex Hall"  wrote:

> Hello list,
> I've configured a DSN to a test version of my work's AS400 and I seem
> to be able to connect just fine (Yes!) I'm now running into a problem
> when I try to ask for a list of all tables. The line is:
>
>  dbInspector = inspect(dbEngine)
>
> The traceback is very long, and I can paste it if you want, but it
> ends with this:
>
> AttributeError: 'pyodbc.Connection' object has no attribute 'dbms_ver'
>
> I'm unable to find anything about this online, so thought I'd check
> with this list. Here's my connection:
>
> dbEngine = create_engine("ibm_db_sa+pyodbc://user:pwd@myDSN")
>
> If anyone knows what is causing this, I'd appreciate your thoughts.
> I've installed pyodbc, ibm_db, and ibm_db_sa through pip, so I should
> have all the latest versions of everything. I'm on Windows 7x64,
> Python 2.7 (latest).
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Connecting to AS400 with SQLAlchemy fails

2016-02-10 Thread Jaimy Azle
Connecting to AS400 from native ibm_db_dbi driver would need db2 connect
which is a separated product from IBM. Use the ibm_db_sa pyodbc driver
instead, or jdbc (jython) if you don't have db2 connect installed on your
machine.

Salam,

-Jaimy
On Feb 11, 2016 01:50, "Alex Hall"  wrote:

> Hello list,
> I sent this to the ibm_db list yesterday, but no one has responded
> yet. Since it's as much ibm_db as SA, I thought I'd try here as well
> in case any of you have used an AS400 before. I have ibm_db,
> ibm_db_sa, the latest sqlalchemy, and Python 2.7 (latest) installed. I
> can talk to SQLite with no trouble, it's talking to this 400 that
> won't work. Anyway...
>
> I'm finally ready to hook my app to the 400 instead of the local
> SQLite database I've been using for testing. Here's my simple script:
>
> import globals
> import logging
> from sqlalchemy import *
> from sqlalchemy.ext.declarative import declarative_base
> from sqlalchemy.orm import sessionmaker
>
> #set up the sqlalchemy objects
> dbEngine = create_engine('ibm_db_sa://
> username:passw...@mysite.com:8471/database')
> Session = sessionmaker(bind = dbEngine) #note that's a capital s on Session
> session = Session() #lowercase s
> base = declarative_base()
>
> def getAllTables():
>  dbInspector = inspect(dbEngine)
>  for table in dbInspector.get_table_names():
>   print table
>
> getAllTables()
>
> When I run that, it waits thirty seconds or so, then tells me there
> was an error. I'll paste the entire traceback below. Sorry in
> advance--it's pretty long.
>
> Microsoft Windows [Version 6.1.7601]
> Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
>
> C:\Users\admin\Dropbox\Autodist\jobs>c:\python27\python.exe DBInterface2.py
> Traceback (most recent call last):
>   File "DBInterface2.py", line 24, in 
> getAllTables()
>   File "DBInterface2.py", line 18, in getAllTables
> dbInspector = inspect(dbEngine)
>   File "c:\python27\lib\site-packages\sqlalchemy\inspection.py", line 63,
> in ins
> pect
> ret = reg(subject)
>   File "c:\python27\lib\site-packages\sqlalchemy\engine\reflection.py",
> line 139
> , in _insp
> return Inspector.from_engine(bind)
>   File "c:\python27\lib\site-packages\sqlalchemy\engine\reflection.py",
> line 135
> , in from_engine
> return Inspector(bind)
>   File "c:\python27\lib\site-packages\sqlalchemy\engine\reflection.py",
> line 109
> , in __init__
> bind.connect().close()
>   File "c:\python27\lib\site-packages\sqlalchemy\engine\base.py", line
> 2018, in
> connect
> return self._connection_cls(self, **kwargs)
>   File "c:\python27\lib\site-packages\sqlalchemy\engine\base.py", line 72,
> in __
> init__
> if connection is not None else engine.raw_connection()
>   File "c:\python27\lib\site-packages\sqlalchemy\engine\base.py", line
> 2104, in
> raw_connection
> self.pool.unique_connection, _connection)
>   File "c:\python27\lib\site-packages\sqlalchemy\engine\base.py", line
> 2078, in
> _wrap_pool_connect
> e, dialect, self)
>   File "c:\python27\lib\site-packages\sqlalchemy\engine\base.py", line
> 1405, in
> _handle_dbapi_exception_noconnection
> exc_info
>   File "c:\python27\lib\site-packages\sqlalchemy\util\compat.py", line
> 200, in r
> aise_from_cause
> reraise(type(exception), exception, tb=exc_tb)
>   File "c:\python27\lib\site-packages\sqlalchemy\engine\base.py", line
> 2074, in
> _wrap_pool_connect
> return fn()
>   File "c:\python27\lib\site-packages\sqlalchemy\pool.py", line 318, in
> unique_c
> onnection
> return _ConnectionFairy._checkout(self)
>   File "c:\python27\lib\site-packages\sqlalchemy\pool.py", line 713, in
> _checkou
> t
> fairy = _ConnectionRecord.checkout(pool)
>   File "c:\python27\lib\site-packages\sqlalchemy\pool.py", line 480, in
> checkout
>
> rec = pool._do_get()
>   File "c:\python27\lib\site-packages\sqlalchemy\pool.py", line 1060, in
> _do_get
>
> self._dec_overflow()
>   File "c:\python27\lib\site-packages\sqlalchemy\util\langhelpers.py",
> line 60,
> in __exit__
> compat.reraise(exc_type, exc_value, exc_tb)
>   File "c:\python27\lib\site-packages\sqlalchemy\pool.py", line 1057, in
> _do_get
>
> return self._create_connection()
>   File "c:\python27\lib\site-packages\sqlalchemy\pool.py", line 323, in
> _create_
> connection
> return _ConnectionRecord(self)
>   File "c:\python27\lib\site-packages\sqlalchemy\pool.py", line 449, in
> __init__
>
> self.connection = self.__connect()
>   File "c:\python27\lib\site-packages\sqlalchemy\pool.py", line 607, in
> __connec
> t
> connection = self.__pool._invoke_creator(self)
>   File "c:\python27\lib\site-packages\sqlalchemy\engine\strategies.py",
> line 97,
>  in connect
> return dialect.connect(*cargs, **cparams)
>   File "c:\python27\lib\site-packages\sqlalchemy\engine\default.py", line
> 385, i
> n connect
> return self.dbapi.connect(*cargs, **cparams)
>   File
> "c:\python27\lib\site-packages\ibm_db-2.0.6-py2.7.egg\ibm_db_dbi.py", lin

Re: [sqlalchemy] Latest SA version which support Jython

2016-01-20 Thread Jaimy Azle
Thanks,  I saw that also,  including the bug fix made recently in jython
repository in regard to SA 1.0. It is however,  due to the jython
development progress is considered quite slow,  reaching a release version
could takes months or even years,  I couldn't use jython  devel for our
production. I think I would start with SA 0.9.x instead of 1.0
On Jan 19, 2016 23:44, "Mike Bayer"  wrote:

> I've heard people are running 1.0.x with Jython.  It's more a matter of
> Jython fixing their bugs, so if they've been doing that, try it out.
>
>
>
> On 01/18/2016 09:23 PM, Jaimy Azle wrote:
> > Hi all,
> >
> > I know jython support was dropped from current version of sqlalchemy,
> > but here I'm stuck to keep use jython in our application due to the Java
> > based technology infrastructures used.
> >
> > In the past I did cancel upgrade from 0.7.2 since 0.7.3 and later
> > introduce delayed import mechanism which tend to be source of problem in
> > jython.
> >
> > Since that,  I had to maintain our team focus on developing our project
> > and had very little time to keep monitor SA development progress.
> >
> > Now 0.7 was considered as legacy and I intend to upgrade our SA to the
> > latest version but surely there is a barrier because of we did have to
> > keep use jython.
> >
> > Can anyone help to share a recommendation the latest SA version which
> > support jython?
> >
> > Salam,
> >
> > Jaimy.
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "sqlalchemy" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> > an email to sqlalchemy+unsubscr...@googlegroups.com
> > <mailto:sqlalchemy+unsubscr...@googlegroups.com>.
> > To post to this group, send email to sqlalchemy@googlegroups.com
> > <mailto:sqlalchemy@googlegroups.com>.
> > Visit this group at https://groups.google.com/group/sqlalchemy.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Latest SA version which support Jython

2016-01-18 Thread Jaimy Azle
Hi all,

I know jython support was dropped from current version of sqlalchemy,  but
here I'm stuck to keep use jython in our application due to the Java based
technology infrastructures used.

In the past I did cancel upgrade from 0.7.2 since 0.7.3 and later introduce
delayed import mechanism which tend to be source of problem in jython.

Since that,  I had to maintain our team focus on developing our project and
had very little time to keep monitor SA development progress.

Now 0.7 was considered as legacy and I intend to upgrade our SA to the
latest version but surely there is a barrier because of we did have to keep
use jython.

Can anyone help to share a recommendation the latest SA version which
support jython?

Salam,

Jaimy.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Writing simple dialect for iSeries + pyodbc in order to use "engine.execute" for sql statements.

2014-06-11 Thread Jaimy Azle
The iSeries support of ibm_db_sa has not been tested on python3 when I
write it.
 On Jun 12, 2014 4:04 AM, "Cory Lutton"  wrote:

> Looks like I wasn't looking at it correctly then...
>
> What I did so far lets it pass through statements using execute() which is
> what I need for now but at least I know not to spend much more time on it.
>
> I just took another look at the ibm_db_sa and installed it but it seems to
> have Python 3 issues, I'll submit a request on the google code site for it
> and see where I get.
>
> Thanks for letting me know
>
> On Wednesday, June 11, 2014 4:16:19 AM UTC-7, Jaimy Azle wrote:
>>
>> Actually the ibm_db_sa support several methods to connect to iSeries;
>> natively through ibm_db, pyodbc, or jdbc (with jython).
>>  On Jun 8, 2014 8:53 AM, "Cory Lutton"  wrote:
>>
>>> Thanks for such a quick reply.  Great to hear that I am starting out on
>>> the right path with building a dialect, I have some work to do so I just
>>> wanted to make sure I wasn't missing something before I spend the time.
>>> Hopefully I can get things working enough where I can post it somewhere.
>>>
>>> I have looked at that IBM DB package, unfortunately the iSeries is a
>>> "remote" connection using ibm_db meaning I would have to get the Enterprise
>>> DB2 connect or get a special quote for unlimited makes me laugh a bit
>>> what the listed price is.
>>>
>>> On Saturday, June 7, 2014 5:48:02 PM UTC-7, Michael Bayer wrote:
>>>>
>>>>
>>>> On Jun 7, 2014, at 8:27 PM, Cory Lutton  wrote:
>>>>
>>>> I have been looking at using sqlalchemy in an internal company cherrypy
>>>> application I am working on.  It will need to interface with my companies
>>>> iSeries server in order to use ERP data.  I have been using pyodbc so far
>>>> and everything works great.  I am thinking of adding access to another
>>>> database that is postgres.  Rather than write that stuff again, I was
>>>> thinking about trying to use sqlalchemy.  If I use that I would want to use
>>>> it for bothone for the iSeries (DB2) and one for postgres..
>>>>
>>>> So, I started writing a "dialect" for iseries+pyodbc and want to make
>>>> sure I am headed down the right path.  It seems to be working so far
>>>> import sqlalchemy as sa
>>>> import sqlalchemy_iseries
>>>> from urllib.parse import quote
>>>>
>>>> engine = sa.create_engine(
>>>> "iseries+pyodbc:///?odbc_connect={connect}".format(
>>>> connect=quote(connect)), pool_size=1)
>>>> con = engine.connect()
>>>>
>>>> # Only using like a pyodbc cursor, executing specifically created
>>>> statements.
>>>> rows = con.execute("SELECT * FROM alpha.r50all.lbmx")
>>>>
>>>> # Access via name like a dictionary rather than row.LBID
>>>> for row in rows:
>>>> print(row['LBID'])
>>>>
>>>> con.close()
>>>>
>>>> Being new to sqlalchemy I am hoping to get some advice on whether what
>>>> I am doing below is basically going in the right direction or point me in
>>>> the right direction if I am headed the wrong way (or reinventing something)
>>>> .
>>>>
>>>> Here is what I have so far...
>>>>
>>>> *__init__.py:*
>>>> from sqlalchemy.dialects import registry
>>>> from . import pyodbc
>>>>
>>>> dialect = pyodbc.dialect
>>>>
>>>> registry.register("iseries.pyodbc", "sqlalchemy_iseries", "dialect")
>>>>
>>>> *base.py:*
>>>> from sqlalchemy.engine import default
>>>>
>>>> class ISeriesDialect(default.DefaultDialect):
>>>> name = 'iseries'
>>>> max_identifier_length = 128
>>>> schema_name = "qgpl"
>>>>
>>>>
>>>> *pyodbc.py:*
>>>> from .base import ISeriesDialect
>>>> from sqlalchemy.connectors.pyodbc import PyODBCConnector
>>>>
>>>> class ISeriesDialect_pyodbc(PyODBCConnector, ISeriesDialect):
>>>> pyodbc_driver_name = 'iSeries Access ODBC Driver'
>>>>
>>>> def _check_unicode_returns(self, connection):
>>>> return False
>>>>
>>>> di

Re: [sqlalchemy] Writing simple dialect for iSeries + pyodbc in order to use "engine.execute" for sql statements.

2014-06-11 Thread Jaimy Azle
Actually the ibm_db_sa support several methods to connect to iSeries;
natively through ibm_db, pyodbc, or jdbc (with jython).
 On Jun 8, 2014 8:53 AM, "Cory Lutton"  wrote:

> Thanks for such a quick reply.  Great to hear that I am starting out on
> the right path with building a dialect, I have some work to do so I just
> wanted to make sure I wasn't missing something before I spend the time.
> Hopefully I can get things working enough where I can post it somewhere.
>
> I have looked at that IBM DB package, unfortunately the iSeries is a
> "remote" connection using ibm_db meaning I would have to get the Enterprise
> DB2 connect or get a special quote for unlimited makes me laugh a bit
> what the listed price is.
>
> On Saturday, June 7, 2014 5:48:02 PM UTC-7, Michael Bayer wrote:
>>
>>
>> On Jun 7, 2014, at 8:27 PM, Cory Lutton  wrote:
>>
>> I have been looking at using sqlalchemy in an internal company cherrypy
>> application I am working on.  It will need to interface with my companies
>> iSeries server in order to use ERP data.  I have been using pyodbc so far
>> and everything works great.  I am thinking of adding access to another
>> database that is postgres.  Rather than write that stuff again, I was
>> thinking about trying to use sqlalchemy.  If I use that I would want to use
>> it for bothone for the iSeries (DB2) and one for postgres..
>>
>> So, I started writing a "dialect" for iseries+pyodbc and want to make
>> sure I am headed down the right path.  It seems to be working so far
>> import sqlalchemy as sa
>> import sqlalchemy_iseries
>> from urllib.parse import quote
>>
>> engine = sa.create_engine(
>> "iseries+pyodbc:///?odbc_connect={connect}".format(
>> connect=quote(connect)), pool_size=1)
>> con = engine.connect()
>>
>> # Only using like a pyodbc cursor, executing specifically created
>> statements.
>> rows = con.execute("SELECT * FROM alpha.r50all.lbmx")
>>
>> # Access via name like a dictionary rather than row.LBID
>> for row in rows:
>> print(row['LBID'])
>>
>> con.close()
>>
>> Being new to sqlalchemy I am hoping to get some advice on whether what I
>> am doing below is basically going in the right direction or point me in the
>> right direction if I am headed the wrong way (or reinventing something)
>> .
>>
>> Here is what I have so far...
>>
>> *__init__.py:*
>> from sqlalchemy.dialects import registry
>> from . import pyodbc
>>
>> dialect = pyodbc.dialect
>>
>> registry.register("iseries.pyodbc", "sqlalchemy_iseries", "dialect")
>>
>> *base.py:*
>> from sqlalchemy.engine import default
>>
>> class ISeriesDialect(default.DefaultDialect):
>> name = 'iseries'
>> max_identifier_length = 128
>> schema_name = "qgpl"
>>
>>
>> *pyodbc.py:*
>> from .base import ISeriesDialect
>> from sqlalchemy.connectors.pyodbc import PyODBCConnector
>>
>> class ISeriesDialect_pyodbc(PyODBCConnector, ISeriesDialect):
>> pyodbc_driver_name = 'iSeries Access ODBC Driver'
>>
>> def _check_unicode_returns(self, connection):
>> return False
>>
>> dialect = ISeriesDialect_pyodbc
>>
>>
>>
>> looks great.if you want examples of the full format, take a look at
>> some of the existing external dialects at http://docs.sqlalchemy.org/
>> en/rel_0_9/dialects/index.html#external-dialects.
>>
>> Are you sure that the IBM DB SA dialect doesn’t cover this backend
>> already?  They have support for pyodbc + DB2, but I’m not really sure how
>> “iSeries” differs.  https://code.google.com/p/ibm-db/
>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Performance degradation after few hours running

2012-12-13 Thread Jaimy Azle
On Thursday, December 13, 2012, 10:26:33 PM, Michael Bayer wrote:

>> Almost nothing changed when we were upgrading SQLA except for Jython
>> which should be upgraded from 2.5.2 to 2.5.3 to fix SQLA import
>> problem. Other technology stack used:

> Also assuming Jython 2.5.3 + SQLA 0.7.2 is fine, right?

This becomes to my curiousity also, I find SQLA 0.7.2 with Jython
2.5.3 runs slower than with Jython 2.5.2. From overall microbench
testing taken from pypy, most issue tends comes from jython 2.5.3
dictionary which performs slower than jython 2.5.2:

https://bitbucket.org/pypy/pypy/src/e4568fc96f21/pypy/translator/microbench

CPYTHON27   JY252   JY253
test_dict_instance_setnewattr_instance_dict_old_style
0.291407189 0.46871312  1.303163004
test_dict_class_dict_getmethod_old_style
0.412026777 0.518402187 1.122752555
test_dict_instance_setattr_instance_dict
0.336120035 1.007072709 3.006027284
test_dict_instance_getattr_instance_dict_old_style
0.246947478 0.275298092 0.288113081
test_dict_getitem
0.369885287 1.531311077 3.212836794
test_dict_instance_setnewattr_instance_dict
0.34283932  1.584638786 3.049607952
test_dict_class_dict_getmethod
0.366906475 0.643861795 1.675214117
test_dict_instance_setattr_instance_dict_old_style
0.28473827  0.450930618 1.239207258
test_dict_raw_range
0.039259917 0.108438472 0.23650532
test_dict_setitem2
0.381666537 1.648408104 3.86719574
test_dict_setitem1
0.319665029 1.301376816 2.943969362
test_dict_creation_mode3
0.139155867 0.77085957  1.787058169
test_dict_creation_mode2
0.136866833 0.637561469 0.691933504
test_dict_creation_mode1
0.150935604 0.42927071  0.961422087
test_dict_instance_getattr_instance_dict
0.267798221 0.506267055 1.389867345

I will try to make a deeper observation on this.

-- 
Salam,

-Jaimy Azle

“+1 for stating fact: Perl is dead. Please 
don't bring it back” – Matt Joiner
“-1 for spreading FUD about perl. It's 
absolutely not dead.” – Daenyth
“+1 + -1 = 0, then, is perl a zombie?” – joaquin
-- http://stackoverflow.com/questions/3384385/python-3-2-gil-good-bad

-- 
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] Performance degradation after few hours running

2012-12-12 Thread Jaimy Azle
Previously, I use SQLA 0.7.2 on Jython for production and it works
great for almost one year deployment until recently I manage to
upgrade to 0.7.8. With this new version, I noticed a constant
performance degradation mostly after serveral hours running,
eventually overall system become almost unusable when a single query
takes almost 10 second to complete. I have not examine in detail
however, but temporarily revert the upgrade back to 0.7.2 to let the
everything works.

As this still a preliminary issue to me, anybody here ever notice the
same problem? or is there any clue before i put some effort in
examining this? Had tried to google but found nothing. I use SQLA as
our ORM backbone in a middleware server running on Java.

Almost nothing changed when we were upgrading SQLA except for Jython
which should be upgraded from 2.5.2 to 2.5.3 to fix SQLA import
problem. Other technology stack used:

* JDK 1.6
* Jetty 6
* Jython 2.5.3
* IBM DB2
* SQLA 0.7.8
* SQL Elixir 0.7.1

-- 
Salam,

-Jaimy Azle

“+1 for stating fact: Perl is dead. Please 
don't bring it back” – Matt Joiner
“-1 for spreading FUD about perl. It's 
absolutely not dead.” – Daenyth
“+1 + -1 = 0, then, is perl a zombie?” – joaquin
-- http://stackoverflow.com/questions/3384385/python-3-2-gil-good-bad

-- 
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.



Re: [sqlalchemy] Please enhance SA support on loading dialect from entry points

2011-09-23 Thread Jaimy Azle
On Friday, September 23, 2011, 9:19:57 PM, Michael Bayer wrote:

> curious, is this for an alternate DBAPI implementation to an
> existing database, like "postgresql+somenewdriver://" ?  or
> multiple, alternate drivers for non-supported databases ? Can I
> get some specific examples?  its not clear how dialect+driver would
> map to an entrypoint.

specifically it is for alternate drivers for non-supported databases.
I try to update the ibm_db_sa to support SA 0.6/0.7 either
natively through ibm_db python DBAPI wrapper, PyODBC, or zxjdbc.
I also writing a new driver for DB2/400 through PyODBC, or zxjdbc.
My proposal is to enable any non-supported database configure the
connection url using the same pattern as on other supported database.
it is something like:

def _load_entry_point(self):


if '+' in self.drivername:
_drivername = '.'.join(self.drivername.split('+'))
else:
_drivername = '.'.join([self.drivername, 'base'])

for res in pkg_resources.iter_entry_points('sqlalchemy.dialects'):
if res.name in (self.drivername, _drivername):
return res.load()
else:
return None

so in entry_points the configuration would be:

[sqlalchemy.dialects]
ibm_db_sa = ibm_db_sa.base:dialect
ibm_db_sa.pyodbc = ibm_db_sa.pyodbc:dialect
ibm_db_sa.zxjdbc = ibm_db_sa.zxjdbc:dialect

-- 
Salam,

-Jaimy Azle

“+1 for stating fact: Perl is dead. Please 
don't bring it back” – Matt Joiner
“-1 for spreading FUD about perl. It's 
absolutely not dead.” – Daenyth
“+1 + -1 = 0, then, is perl a zombie?” – joaquin
-- http://stackoverflow.com/questions/3384385/python-3-2-gil-good-bad

-- 
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] Please enhance SA support on loading dialect from entry points

2011-09-23 Thread Jaimy Azle
Hi Michael,

As on subject, when loading an external dialect from entry points
("sqlalchemy.dialects"), currently it is not possible to load a
database dialect with alternate driver which might be supported using
general connection url pattern:

external_dialect+alt_driver://:@:/

-- 
Salam,

-Jaimy Azle

-- 
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.



Re: [sqlalchemy] ORM Event

2011-08-25 Thread Jaimy Azle
On Thursday, August 25, 2011, 11:44:48 PM, Michael Bayer wrote:

> I would ask why you believe that's true - from what I can tell,
> you're using the Session.add() or something as a means to test that
> the event is triggered, which as I mentioned will have side effects.

> A proper test as below indicates two inserts for Detail, one insert
> for Master, as expected:

Ups i believe it was my bad, combining two cases in one test.
Anyway, I got it, thanks.. :)

-- 
Salam,

-Jaimy Azle

“+1 for stating fact: Perl is dead. Please 
don't bring it back” – Matt Joiner
“-1 for spreading FUD about perl. It's 
absolutely not dead.” – Daenyth
“+1 + -1 = 0, then, is perl a zombie?” – joaquin
-- http://stackoverflow.com/questions/3384385/python-3-2-gil-good-bad

-- 
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.



Re: [sqlalchemy] ORM Event

2011-08-25 Thread Jaimy Azle
On Thursday, August 25, 2011, 7:36:53 PM, Michael Bayer wrote:

Thanks Michael,

> The Session is not usable in the way you're using it inside of
> after_insert and after_delete - in particular the modifications made
> to the state of the object that was just inserted will be discarded,
> and the add() will have no effect as the flush plan cannot be
> changed in these events.

Still, there is an odd issue here, those mapper event only triggered
on first instance only.

>> dt_1 = Detail(1, 1, 'This is detail')
>> dt_2 = Detail(1, 2, 'This is detail')
>> session.add(dt_1)
>> session.add(dt_2)
>> session.commit()  # only the first instance call after_insert
>>   # event, not all

> To modify the Session's flush plan within a flush event, use the
> before_flush() session event.

How to retrieve affected instances with their state (being inserted,
updated, or deleted) that belong to a flush operation? for this case I
need to validate each instance after they were inserted or before they
were deleted from a persistence storage and adjust some rows from
another table.


-- 
Salam,

-Jaimy Azle

“+1 for stating fact: Perl is dead. Please 
don't bring it back” – Matt Joiner
“-1 for spreading FUD about perl. It's 
absolutely not dead.” – Daenyth
“+1 + -1 = 0, then, is perl a zombie?” – joaquin
-- http://stackoverflow.com/questions/3384385/python-3-2-gil-good-bad

-- 
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] ORM Event

2011-08-25 Thread Jaimy Azle
Hi,

I found some weird case on using the mapper event, i setup the mapper
to firing after_insert and after_delete event. However i find some
issue, at least weird behaviour:

* after_insert and after_delete triggered only once on each committed
  transaction.

  dt_1 = Detail(1, 1, 'This is detail')
  dt_2 = Detail(1, 2, 'This is detail')
  session.add(dt_1)
  session.add(dt_2)
  session.commit() # this only fire before insert only once

* no additional data manipulation inside each event could be
  persisted.

  def model_after_insert(mapper, connection, target):
if target.__tablename__ == 'detail':
master = session.query(klass).filter_by(id = target.master).first()
if master:
   master.total = master.total + 1
   session.add(master)   # nothing would be persisted on this

Full example attached below, is there anything i had missed?

-- 
Salam,

-Jaimy Azle

 code snippet -
from sqlalchemy import create_engine, event
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import sessionmaker, mapper
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
engine = create_engine('sqlite:///:memory:')
Session = sessionmaker(bind=engine)

klass = None

def model_after_insert(mapper, connection, target):
  if target.__tablename__ == 'detail':
master = session.query(klass).filter_by(id = target.master).first()
if master:
  master.total = master.total + 1
  session.add(master)
  print('after insert', master.total)
  
def model_after_delete(mapper, connection, target):
  if target.__tablename__ == 'detail':
master = session.query(klass).filter_by(id = target.master).first()
if master:
  master.total = master.total - 1  
  session.add(master)
  print('after delete', master.total)
  

event.listen(mapper, 'after_insert', model_after_insert)
event.listen(mapper, 'after_delete', model_after_delete)

class Master(Base):
  __tablename__ = 'master'
  id = Column(Integer, primary_key=True)
  name = Column(String)
  total = Column(Integer)
  
  def __init__(self, name):
self.name = name
self.total = 0

class Detail(Base):
  __tablename__ = 'detail'  
  id = Column(Integer, primary_key=True)  
  master = Column(Integer, primary_key=True)
  name = Column(String)
  
  def __init__(self, id, master, name):
self.id = id
self.name = name
self.master = master  

klass = Master

Base.metadata.create_all(engine)
session = Session()

master = Master('hello world')  
session.add(master)
session.commit()

dt_1 = Detail(1, 1, 'This is detail')
dt_2 = Detail(1, 2, 'This is detail')
session.add(dt_1)
session.add(dt_2)
session.commit()

master = session.query(Master).filter_by(id = 1).first()
print('total ', master.total)


-- 
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.



Re: [sqlalchemy] Cursor objects in Sessions

2011-03-24 Thread Jaimy Azle
On Thursday, March 24, 2011, 9:26:01 PM, Andrew wrote:

> We have an application using SQLAlchemy to query an Oracle database.
> We started to see errors with the QueuePool running out of
> connections, so we upped the number of connections (and overflow).
> However, now we're seeing behavior where, when running in mod_wsgi,
> the number of Apache processes goes wild, and all the httpd processes
> freeze.

Please see my previous thread, what Michael explains there might be
useful for you, also try with updated version as posted by Michael
there:

http://groups.google.com/group/sqlalchemy/browse_thread/thread/95e3a4ffe806a4bf

-- 
Salam,

-Jaimy Azle

“+1 for stating fact: Perl is dead. Please 
don't bring it back” – Matt Joiner
“-1 for spreading FUD about perl. It's 
absolutely not dead.” – Daenyth
“+1 + -1 = 0, then, is perl a zombie?” – joaquin
-- http://stackoverflow.com/questions/3384385/python-3-2-gil-good-bad

-- 
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.



Re: [sqlalchemy] Discarded overflow connection object object does not automatically close DB socket connection in Jython

2011-03-23 Thread Jaimy Azle
On Thursday, March 24, 2011, 12:33:37 AM, Michael Bayer wrote:

> the pool_timeout parameter manages this from a client perspective,
> in that a stale connection won't be used. An application with a
> decent amount of activity should clean these connections out
> regularly as they are closed the moment they are called up from the
> pool, and have passed their expiration time (if you aren't observing
> that, that's another bug).

Yes I understand, some database connection pooling implementation in
java does have a functionality to enable programmer performing some
task to verify connection just after it checked out from the pool.
However, in my case this could be considered a rare situation in which
i could put this issue on a lower priority.

> If you're designing for the use case that the application is doing
> absolutely nothing for hours, then yes the stale connections will
> just sit there. but I would think that an app with such little
> usage would only have a few connections checked out anyway and these
>  are of no consequence.

My application currently serving about 200-250 users only. However
some of them does performing intensive tasks which by this SA Pool
would automatically opening new connection to serve other user request.
Total number connection actived in the pool could reach 20 connection.
These 20 connection would kept in idle state in the pool for hours
(night) until another request being made tommorow morning and those
connection recycled one by one.

Indeed 20 connections is not a large number, but after few days
running, the database server complains not enough bufferpool to serve
another application. However I might be biased on this, I believe
those issue is more related to unclosed overflow connections rather
than this case.

> If you really want to sever the TCP link proactively expecting a
> totally idle application, I'd look into getting the database server
> to perform this severing (such as what MySQL does automatically
> after 8 hours).

Yes, however not all database have this functionality. afaik,
db2, and firebird does not.

-- 
Salam,

-Jaimy Azle


-- 
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.



Re: [sqlalchemy] Discarded overflow connection object object does not automatically close DB socket connection in Jython

2011-03-23 Thread Jaimy Azle
On Wednesday, March 23, 2011, 10:50:46 AM, Michael Bayer wrote:

> uh yeah you totally nailed that one, QueuePool and
> SingletonThreadPool had similar issues.

it was quite hard to get into this. :)

> you can get at these from hg via:

> http://hg.sqlalchemy.org/sqlalchemy/archive/default.tar.gz
> http://hg.sqlalchemy.org/sqlalchemy/archive/rel_0_6.tar.gz

Thank you, I'll look into those links. However, I still have another
issue on those idle connection objects held in the pool. If there is
no activity related to the database, those connection would be kept
on idle state in the pool, until then it is checked out and
refreshed/recycled. I think i would need to extend QueuePool, and
Queue by adding a functionality to monitor those idle time connection
and dispose it from the pool when maximum idle time reached.

--
Salam,

-Jaimy Azle - http://jaim.log.web.id



-- 
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] Discarded overflow connection object object does not automatically close DB socket connection in Jython

2011-03-22 Thread Jaimy Azle
Dear All,

I am using SQLAlchemy with Jython, I found there is a different
SQLAlchemy behaviour between CPython and Jython. In Jython, discarded
overflow connection object does not automatically close the actual
database socket connection during gc, anybody could confirm this?

my temporary, simple workaround was to explicitly close those overflow
connection before discard it in sqlalchemy.pool.QueuePool.

def do_return_conn(self, conn):
try:
self._pool.put(conn, False)
except sqla_queue.Full:
if self._overflow_lock is None:
self._overflow -= 1
>>  conn.close()
else:
self._overflow_lock.acquire()
try:
self._overflow -= 1
>>  conn.close()
finally:
self._overflow_lock.release()


-- 
Salam,

-Jaimy Azle

-- 
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.



Re: [sqlalchemy] Howto identify connection which has not been returned back to the pool?

2011-03-20 Thread Jaimy Azle
On Saturday, March 19, 2011, 4:09:51 AM, Michael Bayer wrote:

> Otherwise use a PoolListener and add every connection checked out
> to a global set, remove every returned connection from the set. 
> Inspect the set to see what isn't getting returned.   

> http://www.sqlalchemy.org/docs/core/interfaces.html#sqlalchemy.interfaces.PoolListener

Ok, Thanks for pointing, I will look into this.


-- 
Salam,

-Jaimy Azle

“+1 for stating fact: Perl is dead. Please 
don't bring it back” – Matt Joiner
“-1 for spreading FUD about perl. It's 
absolutely not dead.” – Daenyth
“+1 + -1 = 0, then, is perl a zombie?” – joaquin
-- http://stackoverflow.com/questions/3384385/python-3-2-gil-good-bad

-- 
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.



Re: [sqlalchemy] Howto identify connection which has not been returned back to the pool?

2011-03-18 Thread Jaimy Azle
On Friday, March 18, 2011, 8:59:04 PM, Michael Bayer wrote:

> there's a lot of detail missing there, what is the exact error
> message, what DB is this (sounds like SQL server).

The database used was IBM DB2 Express-C, i connect using a modified
version of ibm_db_sa adapted for SQLAchemy 0.6.x running on Jython
2.5.2. The application itself is a middleware server serving
approximately 200-250 active users every day.

I believe there is nothing wrong with the database itself since
previous version of the middleware, which was written in delphi,
proved running without problem for almost one year deployment. I did
sure this comes from my java code base, but it was quite difficult to
trace which routine causing this problem since it requires few days to
run before those problem arise.

> The best way is to use monitoring on the database to identify
> connections and/or transactions that have been opened for a long
> time. There are system views and such which provide this
> information.

Yes, DB2 does have those feature. However, it does not help much since
those number shown is biased because either actively used connection,
stale connection object (if any), and iddle connection kept in the
pool were also listed there.

-- 
Salam,

-Jaimy Azle

“+1 for stating fact: Perl is dead. Please 
don't bring it back” – Matt Joiner
“-1 for spreading FUD about perl. It's 
absolutely not dead.” – Daenyth
“+1 + -1 = 0, then, is perl a zombie?” – joaquin
-- http://stackoverflow.com/questions/3384385/python-3-2-gil-good-bad

-- 
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] Howto identify connection which has not been returned back to the pool?

2011-03-17 Thread Jaimy Azle

Dear All,

Having a logging functionality to trace creation, checkout, and
checkin connection from pool is very helpfull. however is there a way
to identify connection which has not been returned back to the pool
for a period of time?

I suspect I had a stale connection object which does not returned back
to the pool in my code but i cannot sure, I just get the database
server run out of bufferpool stating i have too many uncommitted
rowset after running for few days.

I don't understand, i did commit/rollback consistently for every,
mostly probably, data manipulation routine in my code. And at final
execution i did recheck any active transaction left and do rollback
before returning the session back to the pool. Lastly, the pool has
also been configured to recycle connection after 2 minutes to ensure
no pending transaction left.

However, i might be missed here.

sqlalchemy.pool.QueuePool.0x...0x2:Connection  exceeded timeout; recycling
sqlalchemy.pool.QueuePool.0x...0x2:Closing connection 
sqlalchemy.pool.QueuePool.0x...0x2:Created new connection 
sqlalchemy.pool.QueuePool.0x...0x2:Connection  checked out from pool
sqlalchemy.pool.QueuePool.0x...0x2:Connection  being returned to pool

-- 
Salam,

-Jaimy Azle

-- 
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] MS SQL wrapper for pymssql DBAPI broken in 0.5.0

2009-01-07 Thread Jaimy Azle

Hi,

it seems mssql wrapper for pymmsql DBAPI driver in sqlalchemy 0.5.0
(release) is broken. I haven't check it out with adodbapi, but
pyodbc confirmed works.

File 
"c:\python25\lib\site-packages\sqlalchemy-0.5.0-py2.5.egg\sqlalchemy\databases\mssql.py",
 line 1059, in do_begin
connection.execute("SET IMPLICIT_TRANSACTIONS OFF")
File 
"c:\python25\lib\site-packages\sqlalchemy-0.5.0-py2.5.egg\sqlalchemy\pool.py", 
line 361, in __getattr__
return getattr(self.connection, key)
AttributeError: pymssqlCnx instance has no attribute 'execute'

unit test:

from elixir import *
import sqlalchemy as sa
import unittest

db_opts = {}
db_eng = None

class MSTSTA(Entity):
  CMSTIDCD  = Field(String(3), primary_key=True)
  CMSTIDNM  = Field(String(16))
  CMSTIDDS  = Field(String(32))
  CMSTAUDT  = Field(Numeric(8,0))
  CMSTAUTM  = Field(Numeric(6,0))
  CMSTAUUS  = Field(String(24))

def setUp_dbconn():
  global db_opts, db_eng
  url = 'mssql://sa:mas...@127.0.0.1/TESTDB'
  db_opts['strategy'] = 'threadlocal'
  db_opts['pool_size'] = 16
  db_opts['pool_recycle'] = 900
  db_opts['max_overflow'] = 32
  db_opts['echo'] = False
  db_opts['echo_pool'] = False
  db_eng = sa.create_engine(url, **db_opts)
  metadata.bind = db_eng
  setup_all(True, checkfirst=True)

class TestMSSQLNumeric(unittest.TestCase):

  def test_1(self):
obj = MSTSTA(
  CMSTIDCD = 'UNG',
  CMSTIDNM = 'Ungaran',
  CMSTIDDS = 'Ungaran',
  CMSTAUDT = 20090102,
  CMSTAUTM = 93000,
  CMSTAUUS = 'ADMIN'
)
try:
  session.save(obj)
  session.commit()
  session.close()
except:
  session.rollback()
  raise

  def test_2(self):
obj = MSTSTA.get('UNG')
self.assert_(obj is not None)
try:
  obj.CMSTAUDT = 20090103
  session.update(obj)
      session.commit()
  session.close()
except:
  session.rollback()
  raise


if __name__ == '__main__':
  setUp_dbconn()
  unittest.main()


-- 
Salam,

-Jaimy Azle

"Great new ideas usually come from very small teams...
 don't give up so easily."
  -- John Kaster



--~--~-~--~~~---~--~~
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: mssql wrapper for numeric Datatype.

2009-01-05 Thread Jaimy Azle

On Sunday, January 4, 2009, 3:10:08 AM, Michael Trier wrote:

>
> Corrected in r5602.  Please confirm if you get a moment.  Thanks.
>

yes, it works. thanks.

-- 
Salam,

-Jaimy Azle

"Great new ideas usually come from very small teams...
 don't give up so easily."
  -- John Kaster



--~--~-~--~~~---~--~~
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: How to identify a transaction that has already begun

2009-01-03 Thread Jaimy Azle

On Saturday, January 3, 2009, 12:04:54 AM, Michael Bayer wrote:

>>  session = sqlalchemy.orm.scoped_session(
>> sqlalchemy.orm.sessionmaker(
>>autoflush=False,
>>autocommit=False
>> )
>>)

> session has an is_active flag which indicates this, but if you are
> using autocommit=False, the Session is always within a transaction and
> you should never call begin().

Thanks, but is_active flag could not be accessed from ScopedSession
instance since it is not listed on Session.public_methods. is there
any alternate way could be used?

-- 
Salam,

-Jaimy Azle

"Great new ideas usually come from very small teams...
 don't give up so easily."
  -- John Kaster



--~--~-~--~~~---~--~~
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: mssql wrapper for numeric Datatype.

2009-01-02 Thread Jaimy Azle

On Saturday, January 3, 2009, 7:07:00 AM, Michael Trier wrote:

> Would it be possible for you to do up a test case demonstrating the
> problem?  If so, we could get to it very quickly.

sure, here it is:

from elixir import *
import sqlalchemy as sa
import unittest

db_opts = {}
db_eng = None

class MSTSTA(Entity):
  CMSTIDCD  = Field(String(3), primary_key=True)
  CMSTIDNM  = Field(String(16))
  CMSTIDDS  = Field(String(32))
  CMSTAUDT  = Field(Numeric(8,0))
  CMSTAUTM  = Field(Numeric(6,0))
  CMSTAUUS  = Field(String(24))

def setUp_dbconn():
  global db_opts, db_eng
  url = 'mssql://sa:mas...@127.0.0.1/TESTDB'
  db_opts['strategy'] = 'threadlocal'
  db_opts['pool_size'] = 16
  db_opts['pool_recycle'] = 900
  db_opts['max_overflow'] = 32
  db_opts['echo'] = False
  db_opts['echo_pool'] = False
  db_eng = sa.create_engine(url, **db_opts)
  metadata.bind = db_eng
  setup_all(True, checkfirst=True)

class TestMSSQLNumeric(unittest.TestCase):

  def test_1(self):
obj = MSTSTA(
  CMSTIDCD = 'UNG',
  CMSTIDNM = 'Ungaran',
  CMSTIDDS = 'Ungaran',
  CMSTAUDT = 20090102,
  CMSTAUTM = 93000,
  CMSTAUUS = 'ADMIN'
)
try:
  session.save(obj)
  session.commit()
  session.close()
except:
  session.rollback()
  raise

  def test_2(self):
obj = MSTSTA.get('UNG')
self.assert_(obj is not None)
try:
  obj.CMSTAUDT = 20090103
  session.update(obj)
  session.commit()
  session.close()
except:
  session.rollback()
  raise


if __name__ == '__main__':
  setUp_dbconn()
  unittest.main()

the exception raised:

  File 
"c:\python25\lib\site-packages\sqlalchemy-0.5.0rc4-py2.5.egg\sqlalchemy\databases\mssql.py",
 line 72, in process
if not isinstance(value, float) and value._exp < -6:
AttributeError: 'int' object has no attribute '_exp'

-- 
Salam,

-Jaimy Azle

"Great new ideas usually come from very small teams...
 don't give up so easily."
  -- John Kaster



--~--~-~--~~~---~--~~
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] mssql wrapper for numeric Datatype.

2009-01-01 Thread Jaimy Azle


Hi Michael,

using mssql with sqlalchemy 0.5rc4 for update process on a table that
has Numeric field type will get an exception:

01-02-2009 11:59:15 [ INFO]   File "D:\Enterprise Core 
Framework\script\ecf\core\sqlalchemy\databases\mssql.py", line 72, in process
01-02-2009 11:59:15 [ INFO] if not isinstance(value, float) and value._exp 
< -6:
01-02-2009 11:59:15 [ INFO] AttributeError: 'int' object has no attribute '_exp'

table DDL i used:

class MSTSTA(Entity):
  CMSTIDCD  = Field(String(3), primary_key=True)
  CMSTIDNM  = Field(String(16))
  CMSTIDDS  = Field(String(32))
  CMSTAUDT  = Field(Numeric(8,0))
  CMSTAUTM  = Field(Numeric(6,0))
  CMSTAUUS  = Field(String(24))

inspecting to MSNumeric class, i found that on bind_processor code,
value datatype is only assumed as float or Decimal only, so if it is
int or else it would break.

class MSNumeric(sqltypes.Numeric):
...
def bind_processor(self, dialect):
def process(value):
if value is None:
# Not sure that this exception is needed
return value
else:
# please adjust the code below to something better
# --
# if not isinstance(value, float) and value._exp < -6:
# --
# my temporary patch:
#
if isinstance(value, _python_Decimal) and value._exp < -6:
value = ((value < 0 and '-' or '')
+ '0.'
+ '0' * -(value._exp+1)
+ value._int)
return value
else:
return str(value)
return process


-- 
Salam,

-Jaimy Azle

"Great new ideas usually come from very small teams...
 don't give up so easily."
  -- John Kaster



--~--~-~--~~~---~--~~
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] How to identify a transaction that has already begun

2009-01-01 Thread Jaimy Azle

Hi All,

I configure a session (from elixir) using this code:

  session = sqlalchemy.orm.scoped_session(
 sqlalchemy.orm.sessionmaker(
autoflush=False,
autocommit=False
 )
)

Is there any way to identify whether the transaction has already
begun to avoid exception?

-- 
Salam,

-Jaimy Azle

"Great new ideas usually come from very small teams...
 don't give up so easily."
  -- John Kaster



--~--~-~--~~~---~--~~
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: DBMS

2008-01-16 Thread Jaimy Azle

On Thursday, January 17, 2008, 2:11:56 AM, Christoph Haas wrote:

>> Send me some study material on DBMS.

> Pardon me... you have all these "degrees" but still just order the
> mailing list of an open-source database toolkit to send you "some
> material" on DBMS? We must be having a serious language interface
> problem here. Back when I made my Master of Informatics I learned a
> whole lot about DBMSs.

probably virus?

-- 
Salam,

-Jaimy Azle

"Train yourselft to let go of everything you fear to loose."
  -- Master Yoda



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: SQLAlchemy change Decimal type operation behaviour

2008-01-13 Thread Jaimy Azle

On Monday, January 14, 2008, 8:51:44 AM, jason kirtland wrote:

> Could be something in the MSSQL db-api driver changing the decimal 
> context- replacing the query code with the following gives me the same
> result:

>decimal.getcontext().prec = 1

Thanks,

I will try with it.

-- 
Salam,

-Jaimy Azle

"Train yourselft to let go of everything you fear to loose."
  -- Master Yoda



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: SQLAlchemy change Decimal type operation behaviour

2008-01-13 Thread Jaimy Azle

On Monday, January 14, 2008, 8:46:15 AM, Jaimy Azle wrote:

> I will try to write some similar test case soon as this is really
> reproducable in my machine.

Sadly, ...and strange. I can reproduce it on every part of my project
source, but not on a simple test-case. Yet the problem is still there
... :(

-- 
Salam,

-Jaimy Azle

"Train yourselft to let go of everything you fear to loose."
  -- Master Yoda



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: SQLAlchemy change Decimal type operation behaviour

2008-01-13 Thread Jaimy Azle

On Monday, January 14, 2008, 8:36:14 AM, Rick Morrison wrote:

Thanks for very fast response,

> I don't see how that code would produce those strings.
> At any rate, we'll need to see the SA schema definition, Jaimy.

me neither, the decimal computation looks has nothing to do with
sqlalchemy, but computation result before executing any query is
differ with the one after. here is the schema, i use elixir to define
it:

from elixir import *
from sqlalchemy import *

class SBCITM(Entity):
  SCITKYID= Field(Integer, Sequence('SBCITM_SCITKYID_SEQ'), \
 primary_key=True)
  SCITSQNO= Field(Integer, index=True)
  SCITRMRK= Field(String(64))
  SCITITTP= Field(String(8))
  SCITPRDS= Field(String(48))
  SCITPRCT= Field(Integer)
  SCITPRUM= Field(String(4))
  SCITMTDS= Field(String(48))
  SCITMTCT= Field(Integer)
  SCITMTUM= Field(String(4))
  SCITCRTP= Field(String(4))
  SCITITPR= Field(Numeric(10, 4))
  SCITCRRT= Field(Numeric(10, 4))
  SCITPTCT= Field(Integer)
  SCITPVAL= Field(Numeric(10, 4))
  SCITPTBM= Field(Numeric(10, 4))
  SCITBEMV= Field(Numeric(10, 4))
  SCITPPNV= Field(Numeric(10, 4))
  SCITPPHV= Field(Numeric(10, 4))
  SCITTOTL= Field(Numeric(10, 4))
  SCITCBAL= Field(Integer)
  SCMSKYID= Field(Integer, index=True)
  

> A small reproducing test case would be ideal, if you can.

I will try to write some similar test case soon as this is really
reproducable in my machine.

-- 
Salam,

-Jaimy Azle

"Train yourselft to let go of everything you fear to loose."
  -- Master Yoda



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] SQLAlchemy change Decimal type operation behaviour

2008-01-13 Thread Jaimy Azle

Hi,

I have a problem on using Decimal type along with SQLAlchemy, the
decimal value could not be used for any computation after querying
something with SQLAlchemy object. This is reproducable in my machine:

import decimal
from tbl import SBCITM

pval = decimal.Decimal(decimal.Decimal('0.999') * 99)
print 'value of type %s was %s' % (type(pval), pval)

obj = SBCITM.query.filter_by(SCITKYID = 3).first()
if not obj:
   raise Exception('record id could be found in the database')

pval = decimal.Decimal(decimal.Decimal('0.999') * 99)
print 'value of type %s was %s' % (type(pval), pval)

output from the script:

>> value of type  was 98.901
>> value of type  was 1E+2

I'm using SQLAlchemy + Elixir with MSSQL, option used:

  db_opts = opts or {}
  db_opts['strategy'] = 'threadlocal'
  db_opts['pool_size'] = 8
  db_opts['pool_recycle'] = 1800
  db_opts['max_overflow'] = 16
  db_opts['echo'] = False
  db_opts['echo_pool'] = False
  db_engine = sa.create_engine(url, **db_opts)
  elixir.metadata.bind = db_engine
  elixir.setup_all(True, checkfirst=True)

Please help,

Salam,

-Jaimy.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---