Re: [sqlalchemy] Any recommended approach for creating a new dialect?

2015-04-08 Thread Ralph Heinkel
Hi Michael,

thanks for the prompt response and your directions. This was really 
helpful. I will start as you've described in your reply.

Ralph

On Wednesday, April 8, 2015 at 6:19:27 AM UTC+2, Michael Bayer wrote:

  

 On 4/7/15 1:59 PM, Ralph Heinkel wrote:
  
 Hello dialect experts,

 what would be the best approach for creating a SqlAlchemy dialect for a 
 new database system? 
 Are there any recipes available for this area, or is the way to go to read 
 code of existing dialects and derive my own dialect from those?

 I had a first glance at some built-in dialects, and also some in external 
 packages ... it is not always obvious to me why certain classes and methods 
 have been implemented.
 The obvious thing is to create a subclass of 
 sqlalchemy.enginedefault.DefaultDialect, but how would I know which 
 methods and class attributes to override/implement, except for going 
 through the trial and error approach?
 And then there are other classes which are implemented in some dialects, 
 like compiler.DDLCompiler, compiler.GenericTypeCompiler, and so on ... 
 where and how would I start best?

 Any help would be very much appreciated.
  
 Start with the README for new dialects:


 https://bitbucket.org/zzzeek/sqlalchemy/src/44a9820b4e02f65b3884fa2c016efce9663e4910/README.dialects.rst?at=master

 that will show the guidelines for writing new dialects.

 Then to see some examples of that layout, take a look at some of the 3rd 
 party dialects listed at:

 http://docs.sqlalchemy.org/en/latest/dialects/index.html#production-ready

 Also the sqlalchemy-access dialect is basically something of a demo 
 for the layout, which I basically put there after extracting it from 
 SQLAlchemy main where it had been for many years.   It might not be 100% up 
 to date, but mostly follows that guideline and even passed tests at one 
 point, that's at https://bitbucket.org/zzzeek/sqlalchemy-access.

 The key thing you'll be doing is running the suite tests, which will be 
 part of the test suite within your own dialect.  So yes, you start with a 
 fairly plain subclass of DefaultDialect, then you probably want to get a 
 hello world kind of program going where you just see if create_engine 
 and then engine.execute(select * from table) work at all, and then the 
 suite tests should test a lot more.





  
 Ciao ciao

 Ralph
  -- 
 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+...@googlegroups.com javascript:.
 To post to this group, send email to sqlal...@googlegroups.com 
 javascript:.
 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] Any recommended approach for creating a new dialect?

2015-04-08 Thread Richard Gerd Kuesters | Pollux Automation
Mike, I remember an article of yours where you described much of the 
process of creating a new dialect for SA, for a Java database if I'm not 
mistaken. I wasn't able to find it, though.


:)

On 04/08/2015 01:19 AM, Mike Bayer wrote:



On 4/7/15 1:59 PM, Ralph Heinkel wrote:

Hello dialect experts,

what would be the best approach for creating a SqlAlchemy dialect for 
a new database system?
Are there any recipes available for this area, or is the way to go to 
read code of existing dialects and derive my own dialect from those?


I had a first glance at some built-in dialects, and also some in 
external packages ... it is not always obvious to me why certain 
classes and methods have been implemented.
The obvious thing is to create a subclass of 
sqlalchemy.enginedefault.DefaultDialect, but how would I know which 
methods and class attributes to override/implement, except for going 
through the trial and error approach?
And then there are other classes which are implemented in some 
dialects, like compiler.DDLCompiler, compiler.GenericTypeCompiler, 
and so on ... where and how would I start best?


Any help would be very much appreciated.

Start with the README for new dialects:

https://bitbucket.org/zzzeek/sqlalchemy/src/44a9820b4e02f65b3884fa2c016efce9663e4910/README.dialects.rst?at=master

that will show the guidelines for writing new dialects.

Then to see some examples of that layout, take a look at some of the 
3rd party dialects listed at:


http://docs.sqlalchemy.org/en/latest/dialects/index.html#production-ready

Also the sqlalchemy-access dialect is basically something of a 
demo for the layout, which I basically put there after extracting it 
from SQLAlchemy main where it had been for many years.   It might not 
be 100% up to date, but mostly follows that guideline and even passed 
tests at one point, that's at 
https://bitbucket.org/zzzeek/sqlalchemy-access.


The key thing you'll be doing is running the suite tests, which will 
be part of the test suite within your own dialect.  So yes, you start 
with a fairly plain subclass of DefaultDialect, then you probably want 
to get a hello world kind of program going where you just see if 
create_engine and then engine.execute(select * from table) work 
at all, and then the suite tests should test a lot more.








Ciao ciao

Ralph
--
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 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 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto: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.


[sqlalchemy] Specifying itersize when streaming_results=True for psycopg2 driver ?

2015-04-08 Thread Dorian Hoxha
I searched documentation, mailing list, issue-list, code (on github), 
google, and couldn't find for a way to set the iterszie, the number of 
rows to get on each batch when streaming results with psycogp2. 

Is it possible ?
In psycopg2 docs:
http://initd.org/psycopg/docs/cursor.html#cursor.itersize

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


[sqlalchemy] Eagerly loading backrefs

2015-04-08 Thread Sebastian Eckweiler
Hi there - 

I'm having trouble working with backrefs of detached objects.
I'm basically working with a extended version of the code below:

class Config(Base):
__tablename__ = 'config'

ID = Column('ID', Integer, primary_key=True)
name = Column('name', String)
last_modified = Column('last_modified', DateTime, default=now, onupdate=
now)

params = relationship('ConfigParam', backref='config', lazy=False)

class ConfigParam(Base):

__tablename__ = 'config_params'

ID = Column('ID', Integer, primary_key=True)
ConfigID = Column('ConfigID', Integer, ForeignKey('config.ID'), nullable
=False)

key = Column('key', String)
value = Column('value', Float)

Now when I load a Config instance I'd have assumed that 
Config.params[0].config should be populated - since the eager query 
contains all necessary information.
Testing this with a sqlite engine using the following code:


s = Session()
c = Config(name='my_config')
c.params += [ConfigParam(key='a', value=1),
 ConfigParam(key='b', value=2)]
s.add(c)
s.commit()
s.close()
del c

# reload from new session:
logging.info('\n\n')
logging.info('Starting with new session:')
s = Session()
c = s.query(Config).filter(Config.name=='my_config').one()
s.close()
for p in c.params:
logging.info('Params:%s = %s' % (p.key, p.value))
for p in c.params:
logging.info('backref: config = %s' % p.config)

however produces (omitting the create_all) the following output:

INFO:sqlalchemy.engine.base.Engine:()
INFO:sqlalchemy.engine.base.Engine:COMMIT
INFO:sqlalchemy.engine.base.Engine:BEGIN (implicit)
INFO:sqlalchemy.engine.base.Engine:INSERT INTO config (name, last_modified) 
VALUES (?, ?)
INFO:sqlalchemy.engine.base.Engine:('my_config', '2015-04-08 
09:04:16.111000')
INFO:sqlalchemy.engine.base.Engine:INSERT INTO config_params (ConfigID, 
key, value) VALUES (?, ?, ?)
INFO:sqlalchemy.engine.base.Engine:(1, 'a', 1.0)
INFO:sqlalchemy.engine.base.Engine:INSERT INTO config_params (ConfigID, 
key, value) VALUES (?, ?, ?)
INFO:sqlalchemy.engine.base.Engine:(1, 'b', 2.0)
INFO:sqlalchemy.engine.base.Engine:COMMIT
INFO:root:


INFO:root:Starting with new session:
INFO:sqlalchemy.engine.base.Engine:BEGIN (implicit)
INFO:sqlalchemy.engine.base.Engine:SELECT config.ID AS config_ID, 
config.name AS config_name, config.last_modified AS config_last_modified, 
config_params_1.ID AS config_params_1_ID, config_params_1.ConfigID AS 
config_params_1_ConfigID, config_params_1.key AS config_params_1_key, 
config_params_1.value AS config_params_1_value 
FROM config LEFT OUTER JOIN config_params AS config_params_1 ON config.ID 
= config_params_1.ConfigID 
WHERE config.name = ?
INFO:sqlalchemy.engine.base.Engine:('my_config',)
INFO:sqlalchemy.engine.base.Engine:ROLLBACK
INFO:root:Params:a = 1.0
INFO:root:Params:b = 2.0
Traceback (most recent call last):
  File D:/Assess/Kiln/assess/scratch/sqla_example.py, line 77, in module
logging.info('backref: config = %s' % p.config)
  File 
D:\Anaconda\envs\assess\lib\site-packages\sqlalchemy\orm\attributes.py, 
line 239, in __get__
return self.impl.get(instance_state(instance), dict_)
  File 
D:\Anaconda\envs\assess\lib\site-packages\sqlalchemy\orm\attributes.py, 
line 591, in get
value = self.callable_(state, passive)
  File 
D:\Anaconda\envs\assess\lib\site-packages\sqlalchemy\orm\strategies.py, 
line 507, in _load_for_state
(orm_util.state_str(state), self.key)
sqlalchemy.orm.exc.DetachedInstanceError: Parent instance ConfigParam at 
0x307d898 is not bound to a Session; lazy load operation of attribute 
'config' cannot proceed

I'm somewhat new to ORM's - 
naively I had assumed the backref should/could be loaded at the same time 
the parent is eagerly loaded, since all required information is retrieved 
in the above query.
Is there anything I'm missing here?

ps: This is on sqlalchemy 0.9.8 - if that should matter.


-- 
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] Eagerly loading backrefs

2015-04-08 Thread Mike Bayer



On 4/8/15 3:22 AM, Sebastian Eckweiler wrote:

Hi there -

I'm having trouble working with backrefs of detached objects.
I'm basically working with a extended version of the code below:

|
classConfig(Base):
__tablename__ ='config'

ID =Column('ID',Integer,primary_key=True)
name =Column('name',String)
last_modified 
=Column('last_modified',DateTime,default=now,onupdate=now)


params=relationship('ConfigParam',backref='config',lazy=False)

classConfigParam(Base):

__tablename__ ='config_params'

ID =Column('ID',Integer,primary_key=True)
ConfigID=Column('ConfigID',Integer,ForeignKey('config.ID'),nullable=False)

key =Column('key',String)
value =Column('value',Float)
|

Now when I load a Config instance I'd have assumed that 
Config.params[0].config should be populated - since the eager query 
contains all necessary information.
A load that can be resolved to using the session's identity map instead 
of SELECT is still a load nonetheless.  You would need a lazy setting on 
the backref as well.   Since these are many-to-ones and the lazyload 
pulls from identity map, I suggest immediate.


Using these settings at the mapping level does mean however that if you 
load a ConfigParam object by itself, it will, for a clean session, 
immediately issue a second SELECT statement for its Config object.






Testing this with a sqlite engine using the following code:

|

s =Session()
c =Config(name='my_config')
c.params+=[ConfigParam(key='a',value=1),
ConfigParam(key='b',value=2)]
s.add(c)
s.commit()
s.close()
delc

# reload from new session:
logging.info('\n\n')
logging.info('Starting with new session:')
s =Session()
c =s.query(Config).filter(Config.name=='my_config').one()
s.close()
forp inc.params:
logging.info('Params:%s = %s'%(p.key,p.value))
forp inc.params:
logging.info('backref: config = %s'%p.config)
|

however produces (omitting the create_all) the following output:

INFO:sqlalchemy.engine.base.Engine:()
INFO:sqlalchemy.engine.base.Engine:COMMIT
INFO:sqlalchemy.engine.base.Engine:BEGIN (implicit)
INFO:sqlalchemy.engine.base.Engine:INSERT INTO config (name, 
last_modified) VALUES (?, ?)
INFO:sqlalchemy.engine.base.Engine:('my_config', '2015-04-08 
09:04:16.111000')
INFO:sqlalchemy.engine.base.Engine:INSERT INTO config_params 
(ConfigID, key, value) VALUES (?, ?, ?)

INFO:sqlalchemy.engine.base.Engine:(1, 'a', 1.0)
INFO:sqlalchemy.engine.base.Engine:INSERT INTO config_params 
(ConfigID, key, value) VALUES (?, ?, ?)

INFO:sqlalchemy.engine.base.Engine:(1, 'b', 2.0)
INFO:sqlalchemy.engine.base.Engine:COMMIT
INFO:root:


INFO:root:Starting with new session:
INFO:sqlalchemy.engine.base.Engine:BEGIN (implicit)
INFO:sqlalchemy.engine.base.Engine:SELECT config.ID AS config_ID, 
config.name AS config_name, config.last_modified AS 
config_last_modified, config_params_1.ID AS config_params_1_ID, 
config_params_1.ConfigID AS config_params_1_ConfigID, 
config_params_1.key AS config_params_1_key, config_params_1.value AS 
config_params_1_value
FROM config LEFT OUTER JOIN config_params AS config_params_1 ON 
config.ID = config_params_1.ConfigID

WHERE config.name = ?
INFO:sqlalchemy.engine.base.Engine:('my_config',)
INFO:sqlalchemy.engine.base.Engine:ROLLBACK
INFO:root:Params:a = 1.0
INFO:root:Params:b = 2.0
Traceback (most recent call last):
  File D:/Assess/Kiln/assess/scratch/sqla_example.py, line 77, in 
module

logging.info('backref: config = %s' % p.config)
  File 
D:\Anaconda\envs\assess\lib\site-packages\sqlalchemy\orm\attributes.py, 
line 239, in __get__

return self.impl.get(instance_state(instance), dict_)
  File 
D:\Anaconda\envs\assess\lib\site-packages\sqlalchemy\orm\attributes.py, 
line 591, in get

value = self.callable_(state, passive)
  File 
D:\Anaconda\envs\assess\lib\site-packages\sqlalchemy\orm\strategies.py, 
line 507, in _load_for_state

(orm_util.state_str(state), self.key)
sqlalchemy.orm.exc.DetachedInstanceError: Parent instance ConfigParam 
at 0x307d898 is not bound to a Session; lazy load operation of 
attribute 'config' cannot proceed


I'm somewhat new to ORM's -
naively I had assumed the backref should/could be loaded at the same 
time the parent is eagerly loaded, since all required information is 
retrieved in the above query.

Is there anything I'm missing here?

ps: This is on sqlalchemy 0.9.8 - if that should matter.


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

Re: [sqlalchemy] Specifying itersize when streaming_results=True for psycopg2 driver ?

2015-04-08 Thread Mike Bayer



On 4/8/15 6:43 AM, Dorian Hoxha wrote:
I searched documentation, mailing list, issue-list, code (on github), 
google, and couldn't find for a way to set the iterszie, the number 
of rows to get on each batch when streaming results with psycogp2.


we don't have public API for that attribute at the moment, so unless you 
want to work with the cursor directly as in 
http://docs.sqlalchemy.org/en/rel_0_9/core/connections.html#working-with-raw-dbapi-connections, 
this feature would be an execution_option supported and documented by 
the psycopg2 dialect.  Feel free to open a feature request and/or work 
up a pull request.



--
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] updating a unicode column

2015-04-08 Thread arash afshar
You are good!
The problem was the errant comma!
Thanks

On Wednesday, April 8, 2015 at 7:41:01 PM UTC-6, Michael Bayer wrote:

  

 On 4/8/15 9:38 PM, arash afshar wrote:
  
 I am calling commit, right after updated those two values. 
 Any suggestion on what else to check?
  

 what is the exact column type given to this column, are there any 
 event.listen() things going on, and also what does a repr() of the object's 
 __dict__ look like?

 in particular, Python has a really sneaky issue where if you happen to 
 have an errant comma:

 x = foo,


 you get:

 (foo, )




  
 On Wednesday, April 8, 2015 at 7:33:49 PM UTC-6, Michael Bayer wrote: 

  

 On 4/8/15 9:16 PM, arash afshar wrote:
  
 When I try to update a row using ORM in the following way, it shows the 
 following error: 
 InterfaceError: (InterfaceError) Error binding parameter 0 - probably 
 unsupported type. u'UPDATE table_name SET unicode_col=?, int_col=? WHERE 
 table_name.id = ?' ((u'abcd',), 1, 2)
  
  
  I suspect the problem is that the value corresponding to unicode_col is 
 (u'abcd',) as opposed to a simple u'abcd'.
  
 that is the problem.

   
  Here is how I update the database:
 1) I first query it and obtain an object representing the row that I need 
   --  file_row
 2) I perform some checks and change the values  -- file_row.int_col = 1 
followed by   file_row.unicode_col = uabcd
 3) I call commit on the session

   
 looks fine, so, I'd imagine that somehow that unicode_col = u'abcd' is 
 not what it seems.  Either that's not what's there or something is 
 interfering with it after the fact.




   I am pretty sure the problem is not the original type of value of the 
 unicode_col since the following succeeds without error:
  
  query(TableName).filter(TableName.id == file_row.id).update({'unicode_col': 
 uabcd, 'int_col': 1})
  
  
  Any idea how to fix the error?
 Thanks
  -- 
 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+...@googlegroups.com.
 To post to this group, send email to sqlal...@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+...@googlegroups.com javascript:.
 To post to this group, send email to sqlal...@googlegroups.com 
 javascript:.
 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] listening for events on 'mapper'

2015-04-08 Thread Mike Bayer



On 4/8/15 5:14 PM, Tim Tisdall wrote:

I have some code I'm trying to figure out...  Here it is:

from sqlalchemy import event
from colanderalchemy import setup_schema
from sqlalchemy.orm import mapper

event.listen(mapper, 'mapper_configured', setup_schema)


It appears to call `setup_schema` on every ORM class that derives from 
the `declarative_base()`.  All the documentation in SQLAlchemy shows 
event.listen being called on specific classes or mappers and I'm 
wondering if this usage is a documented feature.


yes, mapper events can be passed the mapper function itself which is 
recognized as one way to assign an event to all mappers.



I found a mention in the 0.7 docs, but no where else: 
 http://docs.sqlalchemy.org/en/rel_0_7/orm/events.html#sqlalchemy.orm.events.MapperEvents
that would qualify as documented :)   The formatting is cleaner in 
http://docs.sqlalchemy.org/en/latest/orm/events.html#sqlalchemy.orm.events.MapperEvents.





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


[sqlalchemy] updating a unicode column

2015-04-08 Thread arash afshar
When I try to update a row using ORM in the following way, it shows the 
following error:
InterfaceError: (InterfaceError) Error binding parameter 0 - probably 
unsupported type. u'UPDATE table_name SET unicode_col=?, int_col=? 
WHERE table_name.id = ?' ((u'abcd',), 1, 2)


I suspect the problem is that the value corresponding to unicode_col is 
(u'abcd',) as opposed to a simple u'abcd'.

Here is how I update the database:
1) I first query it and obtain an object representing the row that I need   
--  file_row
2) I perform some checks and change the values  -- file_row.int_col = 1   
 followed by   file_row.unicode_col = uabcd
3) I call commit on the session

I am pretty sure the problem is not the original type of value of the 
unicode_col since the following succeeds without error:

query(TableName).filter(TableName.id == file_row.id).update({'unicode_col': 
uabcd, 'int_col': 1})


Any idea how to fix the error?
Thanks

-- 
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] updating a unicode column

2015-04-08 Thread Mike Bayer



On 4/8/15 9:38 PM, arash afshar wrote:

I am calling commit, right after updated those two values.
Any suggestion on what else to check?


what is the exact column type given to this column, are there any 
event.listen() things going on, and also what does a repr() of the 
object's __dict__ look like?


in particular, Python has a really sneaky issue where if you happen to 
have an errant comma:


x = foo,


you get:

(foo, )






On Wednesday, April 8, 2015 at 7:33:49 PM UTC-6, Michael Bayer wrote:



On 4/8/15 9:16 PM, arash afshar wrote:

When I try to update a row using ORM in the following way, it
shows the following error:
InterfaceError: (InterfaceError) Error binding parameter 0 -
probably unsupported type. u'UPDATE table_name SET unicode_col=?,
int_col=? WHERE table_name.id http://table_name.id = ?'
((u'abcd',), 1, 2)


I suspect the problem is that the value corresponding to
unicode_col is (u'abcd',) as opposed to a simple u'abcd'.

that is the problem.



Here is how I update the database:
1) I first query it and obtain an object representing the row
that I need   --  file_row
2) I perform some checks and change the values  --
file_row.int_col = 1followed by file_row.unicode_col = uabcd
3) I call commit on the session



looks fine, so, I'd imagine that somehow that unicode_col =
u'abcd' is not what it seems.  Either that's not what's there or
something is interfering with it after the fact.





I am pretty sure the problem is not the original type of value of
the unicode_col since the following succeeds without error:

query(TableName).filter(TableName.id == file_row.id
http://file_row.id).update({'unicode_col': uabcd, 'int_col': 1})


Any idea how to fix the error?
Thanks
-- 
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+...@googlegroups.com javascript:.
To post to this group, send email to sqlal...@googlegroups.com
javascript:.
Visit this group at http://groups.google.com/group/sqlalchemy
http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout
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 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto: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] listening for events on 'mapper'

2015-04-08 Thread Tim Tisdall
Sorry, I just saw the the Mapper class itself and the mapper()
function indicate listening for all mappers. on the latest docs.
Thanks.

On Wed, Apr 8, 2015 at 5:27 PM, Mike Bayer mike...@zzzcomputing.com wrote:


 On 4/8/15 5:14 PM, Tim Tisdall wrote:

 I have some code I'm trying to figure out...  Here it is:

 from sqlalchemy import event
 from colanderalchemy import setup_schema
 from sqlalchemy.orm import mapper

 event.listen(mapper, 'mapper_configured', setup_schema)


 It appears to call `setup_schema` on every ORM class that derives from the
 `declarative_base()`.  All the documentation in SQLAlchemy shows
 event.listen being called on specific classes or mappers and I'm wondering
 if this usage is a documented feature.


 yes, mapper events can be passed the mapper function itself which is
 recognized as one way to assign an event to all mappers.


 I found a mention in the 0.7 docs, but no where else:
 http://docs.sqlalchemy.org/en/rel_0_7/orm/events.html#sqlalchemy.orm.events.MapperEvents

 that would qualify as documented :)   The formatting is cleaner in
 http://docs.sqlalchemy.org/en/latest/orm/events.html#sqlalchemy.orm.events.MapperEvents.



 --
 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 a topic in the
 Google Groups sqlalchemy group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/sqlalchemy/bmWUxihSDqY/unsubscribe.
 To unsubscribe from this group and all its topics, 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] updating a unicode column

2015-04-08 Thread Mike Bayer



On 4/8/15 9:16 PM, arash afshar wrote:
When I try to update a row using ORM in the following way, it shows 
the following error:
InterfaceError: (InterfaceError) Error binding parameter 0 - probably 
unsupported type. u'UPDATE table_name SET unicode_col=?, int_col=? 
WHERE table_name.id = ?' ((u'abcd',), 1, 2)



I suspect the problem is that the value corresponding to unicode_col 
is (u'abcd',) as opposed to a simple u'abcd'.

that is the problem.



Here is how I update the database:
1) I first query it and obtain an object representing the row that I 
need   --  file_row
2) I perform some checks and change the values  -- file_row.int_col = 
1followed by   file_row.unicode_col = uabcd

3) I call commit on the session



looks fine, so, I'd imagine that somehow that unicode_col = u'abcd' is 
not what it seems.  Either that's not what's there or something is 
interfering with it after the fact.





I am pretty sure the problem is not the original type of value of the 
unicode_col since the following succeeds without error:


query(TableName).filter(TableName.id == 
file_row.id).update({'unicode_col': uabcd, 'int_col': 1})



Any idea how to fix the error?
Thanks
--
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 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] updating a unicode column

2015-04-08 Thread arash afshar
I am calling commit, right after updated those two values.
Any suggestion on what else to check?

On Wednesday, April 8, 2015 at 7:33:49 PM UTC-6, Michael Bayer wrote:

  

 On 4/8/15 9:16 PM, arash afshar wrote:
  
 When I try to update a row using ORM in the following way, it shows the 
 following error: 
 InterfaceError: (InterfaceError) Error binding parameter 0 - probably 
 unsupported type. u'UPDATE table_name SET unicode_col=?, int_col=? WHERE 
 table_name.id = ?' ((u'abcd',), 1, 2)
  
  
  I suspect the problem is that the value corresponding to unicode_col is 
 (u'abcd',) as opposed to a simple u'abcd'.
  
 that is the problem.

   
  Here is how I update the database:
 1) I first query it and obtain an object representing the row that I need 
   --  file_row
 2) I perform some checks and change the values  -- file_row.int_col = 1   
  followed by   file_row.unicode_col = uabcd
 3) I call commit on the session

   
 looks fine, so, I'd imagine that somehow that unicode_col = u'abcd' is not 
 what it seems.  Either that's not what's there or something is interfering 
 with it after the fact.




   I am pretty sure the problem is not the original type of value of the 
 unicode_col since the following succeeds without error:
  
  query(TableName).filter(TableName.id == file_row.id).update({'unicode_col': 
 uabcd, 'int_col': 1})
  
  
  Any idea how to fix the error?
 Thanks
  -- 
 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+...@googlegroups.com javascript:.
 To post to this group, send email to sqlal...@googlegroups.com 
 javascript:.
 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.


[sqlalchemy] listening for events on 'mapper'

2015-04-08 Thread Tim Tisdall
I have some code I'm trying to figure out...  Here it is:

from sqlalchemy import event
from colanderalchemy import setup_schema
from sqlalchemy.orm import mapper

event.listen(mapper, 'mapper_configured', setup_schema)


It appears to call `setup_schema` on every ORM class that derives from the 
`declarative_base()`.  All the documentation in SQLAlchemy shows 
event.listen being called on specific classes or mappers and I'm wondering 
if this usage is a documented feature.

I found a mention in the 0.7 docs, but no where else: 
 
http://docs.sqlalchemy.org/en/rel_0_7/orm/events.html#sqlalchemy.orm.events.MapperEvents

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