[sqlalchemy] image field in mssql

2013-06-12 Thread alex bodnaru

hello friends,

i'm happily using sa, both with a declarative/elixir orm, and directly through
DBSession.execute(text statement).

there is an issue that works great with orm, but i don't khown how to achieve in
direct execution:

image fields.
i'm inserting the data as:

sql = insert tablename(img) values(:img)
DBSession.execute(sql, dict(img=bytearray(data))

data is not empty, but it just retrieves as bytearray(b'')
could you advice me?

many thanks in advance,
alex

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sqlalchemy] image field in mssql

2013-06-12 Thread alex bodnaru

hello michael,

as usually, you were faster than me to answer.

after reviewing my surrounding code to fix additional bugs there,
i've just found the answer:

a bytearray is needed as sql param. i've built the buffer from an image with
BytesIO.

im = Images.new()
image = BytesIO()
im.save(image)
buffer = image.getvalue()
param = dict(picture=bytearray(buffer)

thanks a lot for your consideration :)

alex

there was no need to use pyodbc.Binary, since it has the very same effect.

On 06/12/2013 06:36 PM, Michael Bayer wrote:
 blobs are problematic, and this is often highly dependent on DBAPI version 
 and platform.
 
 So can you send along details:
 
 1. python version
 2. operating system
 3. SQLAlchemy version
 4. DBAPI in use, version
 
 I can give it a test on this end.  
 
 
 On Jun 12, 2013, at 6:00 AM, alex bodnaru alexbodn.gro...@gmail.com wrote:
 

 hello friends,

 i'm happily using sa, both with a declarative/elixir orm, and directly 
 through
 DBSession.execute(text statement).

 there is an issue that works great with orm, but i don't khown how to 
 achieve in
 direct execution:

 image fields.
 i'm inserting the data as:

 sql = insert tablename(img) values(:img)
 DBSession.execute(sql, dict(img=bytearray(data))

 data is not empty, but it just retrieves as bytearray(b'')
 could you advice me?

 many thanks in advance,
 alex

 -- 
 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?hl=en.
 For more options, visit https://groups.google.com/groups/opt_out.


 

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




[sqlalchemy] statement preparation in sa

2013-01-13 Thread alex bodnaru

hello friends,

i've just made an alternative sqlite driver, to overcome the dbapi short of
running multiple statements separated by ';'.
executescript would do the work, but it won't receive parameters.
hence, i'd like to perform the parameter substitution inside the driver, before
turning to executescript.
is there any proved way to go? any special paramstyle?

thanks in advance,
alex

-- 
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] making bindparms required by default

2012-08-28 Thread alex bodnaru

thanks michael,

On 08/27/2012 07:49 PM, Michael Bayer wrote:
 Here's a patch:
 
 diff -r 594b0162e8a5 lib/sqlalchemy/sql/expression.py
 --- a/lib/sqlalchemy/sql/expression.pyMon Aug 27 12:33:10 2012 -0400
 +++ b/lib/sqlalchemy/sql/expression.pyMon Aug 27 12:43:48 2012 -0400
 @@ -3110,7 +3110,7 @@
  typemap[key] = sqltypes.to_instance(typemap[key])
  
  def repl(m):
 -self.bindparams[m.group(1)] = bindparam(m.group(1))
 +self.bindparams[m.group(1)] = bindparam(m.group(1), 
 required=True)
  return ':%s' % m.group(1)
  
  # scan the string and search for bind parameter names, add them
 
that's what i did indeed.
but it would break queries that are happy with the null on missing default.
thus, a configurable option, false by default, would do the job.
 
 however, this is too easy.  There's lots of other places binds are generated. 
   A rule such that if value is not passed to bindparam(), then flip the 
 required flag on, would be the best behavior.  needs a few lines in the 
 bindparam() function, but also would need a lot of tests, in 
 test/sql/test_query.py.   ticket #2556 is added.
thank you very much. the patch is very sensible, but it will certainly break
scripts that rely on the null on missing behaviour.
however, i don't have such scripts ;).
 
 for your immediate needs, you can make a function that returns a Text() 
 construct, and just supplies a dictionary of bindparam() objects to the 
 Text() pre-established, with the required=True flag turned on.
 
thought of it too, but it won't do the work: i needed to catch :variables
missing in the given bindparm.
 
 
 
thanks a lot,
alex
 
 
 On Aug 27, 2012, at 12:06 PM, alex bodnaru wrote:
 

 hello friends,

 for a migrated system, i'm using textual queries in the form:

 dbsession.execute(select name from table where id=:id, dict(id=1))

 to my surprise, select ... id=:idd would still work, asuming idd is null,
 despite 'idd' is not in bindparms.
 
 
 
 

 a 'required' argument to bindparam in _TextClause __init__() would indeed 
 make
 the 'idd' column required, thus raise an exception when not found in bind
 dict(id=1).

 is there an official way to acomplish this, or should i just hack in 
 hardcoded?

 thanks in advance,
 alex

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

 

-- 
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] making bindparms required by default

2012-08-28 Thread alex bodnaru
On 08/27/2012 10:13 PM, Michael Bayer wrote:
 I'm super-hot to get the first betas of 0.8 out the door, and as this is a 
 backwards-compatability-sensitive change, I was in a super rush to get this 
 in, so it's in tip.
 
seen it' thanks again :).
 
 
 On Aug 27, 2012, at 12:49 PM, Michael Bayer wrote:
 
 Here's a patch:

 diff -r 594b0162e8a5 lib/sqlalchemy/sql/expression.py
 --- a/lib/sqlalchemy/sql/expression.py   Mon Aug 27 12:33:10 2012 -0400
 +++ b/lib/sqlalchemy/sql/expression.py   Mon Aug 27 12:43:48 2012 -0400
 @@ -3110,7 +3110,7 @@
 typemap[key] = sqltypes.to_instance(typemap[key])

 def repl(m):
 -self.bindparams[m.group(1)] = bindparam(m.group(1))
 +self.bindparams[m.group(1)] = bindparam(m.group(1), 
 required=True)
 return ':%s' % m.group(1)

 # scan the string and search for bind parameter names, add them


 however, this is too easy.  There's lots of other places binds are 
 generated.   A rule such that if value is not passed to bindparam(), then 
 flip the required flag on, would be the best behavior.  needs a few lines in 
 the bindparam() function, but also would need a lot of tests, in 
 test/sql/test_query.py.   ticket #2556 is added.

 for your immediate needs, you can make a function that returns a Text() 
 construct, and just supplies a dictionary of bindparam() objects to the 
 Text() pre-established, with the required=True flag turned on.






 On Aug 27, 2012, at 12:06 PM, alex bodnaru wrote:


 hello friends,

 for a migrated system, i'm using textual queries in the form:

 dbsession.execute(select name from table where id=:id, dict(id=1))

 to my surprise, select ... id=:idd would still work, asuming idd is 
 null,
 despite 'idd' is not in bindparms.





 a 'required' argument to bindparam in _TextClause __init__() would indeed 
 make
 the 'idd' column required, thus raise an exception when not found in bind
 dict(id=1).

 is there an official way to acomplish this, or should i just hack in 
 hardcoded?

 thanks in advance,
 alex

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


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

 

-- 
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] making bindparms required by default

2012-08-27 Thread alex bodnaru

hello friends,

for a migrated system, i'm using textual queries in the form:

dbsession.execute(select name from table where id=:id, dict(id=1))

to my surprise, select ... id=:idd would still work, asuming idd is null,
despite 'idd' is not in bindparms.

a 'required' argument to bindparam in _TextClause __init__() would indeed make
the 'idd' column required, thus raise an exception when not found in bind
dict(id=1).

is there an official way to acomplish this, or should i just hack in hardcoded?

thanks in advance,
alex

-- 
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] dialect sensible declaration

2012-07-16 Thread alex bodnaru

hello michael, friends,

here is my test case.
thanks a lot for your consideraion. please take a look.


from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, Unicode, ForeignKeyConstraint
from sqlalchemy.orm import relation, backref, sessionmaker
from sqlalchemy.event import listen


engine = create_engine('sqlite:///:memory:', echo=True)
Base = declarative_base()

class Lang(Base):
__tablename__ = 'lang'
lang_code = Column(String(20), primary_key=True)
lang_name = Column(Unicode(64))

class PageData(Base):
__tablename__ = 'pagedata'
lang_code = Column(String(20), primary_key=True)
lang = relation('Lang', backref='pages',
primaryjoin=lang_code==Lang.lang_code,
foreign_keys=[Lang.lang_code], uselist=False)
data = Column(Unicode(64), nullable=True)

def add_lang_fk(table, conn, **kw):
if 'added_lang_fk' not in table.info:
params = dict(ondelete='cascade')
if conn.dialect.name != 'mssql':
params['onupdate'] = 'restrict'
table.append_constraint(
ForeignKeyConstraint(
['lang_code'], [Lang.__tablename__ + '.lang_code'], **params))
table.info['added_lang_fk'] = True

listen(PageData.__table__, before_create, add_lang_fk)

Base.metadata.create_all(engine)


Session = sessionmaker(bind=engine)
session = Session()

de = Lang(lang_code='de', lang_name='Deutsch')
session.add(de)

data = PageData(lang_code='de', data=uVielen Dank im Voraus) #this works
data = PageData(lang=de, data=uVielen Dank im Voraus) #this fails
session.add(data)

session.flush()


thanks in advance,
alex

On 07/15/2012 07:08 PM, Michael Bayer wrote:
 
 On Jul 15, 2012, at 5:53 AM, alex bodnaru wrote:
 

 hello michael, friends,

 On 07/11/2012 10:31 AM, alex bodnaru wrote:

 hello michael,

 now it works. i also had to add uselist=False.

 i tried it the longest way possible, by adding a Pool first_connect 
 listener,
 but this was not really needed. just the uselist.

 thanks a lot,
 alex

 sorry, not yet:

 the relationship should also allow assignment like this:

 class Lang(DeclarativeBase):
   lang_code = Column(String(20), primary_key=True)
   lang_name = Column(String(20))

 class PageData(DeclarativeBase):
   lang_code = Column(String(20), primary_key=True)
   lang = relation('Lang', backref='pages',
 primaryjoin=lang_code==Lang.lang_code, foreign_keys=[Lang.lang_code], 
 uselist=False)

 the PageData.lang_code foreign key is being added in an event on before 
 create.

 before delaying creation of the foreign key, i could do like this:

 p = PageData()
 p.lang = Lang.get('en')

 and p.lang_code got assigned. why isn't lang_code being assigned now anymore?
 
 it would imply the relationship is not working at all.
 
 like before: 
 
  can you just throw these two classes, the event, and some imports into a 
 file for me ?  I can just run it.
 
 much quicker than lots of back and forth.
 
 
 
 
 

 thanks in advance,
 alex
 On 07/09/2012 04:25 PM, Michael Bayer wrote:

 On Jul 9, 2012, at 4:48 AM, alex bodnaru wrote:


 hello michael, friends,

 after successfuly fixing the ddl by the append_constraint event, the 
 relations
 that needed the said foreign keys remained orphan, asking for a 
 foreign_keys
 argument and failing to load the remote table:

 class Lang(DeclarativeBase):
   lang_code = Column(String(20), primary_key=True)
   lang_name = Column(String(20))

 class PageData(DeclarativeBase):
   lang_code = Column(String(20), primary_key=True) # this foreign key is 
 being
 successfully appended on before_create.
   lang = relation('Lang', backref='pages',
 primaryjoin=lang_code==Lang.lang_code) #this relationship won't work, 
 since at
 the moment the class is being made, the foreign key is not there yet.

 the foreign_keys=Lang.lang_code arg does calm the exception, but doesn't 
 do the
 work.
 could i add the relationship to the mapper on the same event?

 I would think foreign_keys should fix the problem totally, what do you 
 mean doesn't do the work?  I'd have to work up a test case, can you just 
 throw these two classes, the event, and some imports into a file for me ?  
 I can just run it.

 well, almost totally ;)
 it also needed uselist=False.



 thank in advance,
 alex

 On 07/07/2012 05:13 PM, Michael Bayer wrote:
 sure engine and connection have .dialect.name.   Foreign key constraints 
 don't matter on SQLite unless you've actually enabled them, which is 
 rare.   I'd still use an event though so at least the behavior is 
 transparent.

 @event.listens_for(my_table, before_create)
 def add_fk(table, conn, **kw):
   if conn.dialect.name != 'mssql':
   table.append_constraint(ForeignKeyConstraint(...))

 tricky though to modify the table metadata within a create event in 
 the case that the table is created multiple times in an app.  you can 
 put a flag in table.info, like table.info

Re: [sqlalchemy] dialect sensible declaration

2012-07-16 Thread alex bodnaru

thank you very much michael.

both ways worked like a charm.

i have implemented the other way, though this is better and more general: any
constraint with onupdate or ondelete attributes should have these attributes set
to none if the dialect name is mssql.

thanks a lot,
alex

On 07/16/2012 05:10 PM, Michael Bayer wrote:
 thanks - though one thought I had is, why not just modify an existing 
 ForeignKeyConstraint.onupdate directly in the event, instead of trying to add 
 the constraint later and confusing the ORM.  you wouldn't need the 
 relationship arguments then.
 
 the constraints for the table are in table.constraints, its a set and you'd 
 iterate through to find the ForeignKeyConstraint with the name you're looking 
 for.
 
 if you can try that out let me know.
 
 
 
 
 On Jul 16, 2012, at 5:18 AM, alex bodnaru wrote:
 

 hello michael, friends,

 here is my test case.
 thanks a lot for your consideraion. please take a look.


 from sqlalchemy import create_engine
 from sqlalchemy.ext.declarative import declarative_base
 from sqlalchemy import Column, Integer, String, Unicode, ForeignKeyConstraint
 from sqlalchemy.orm import relation, backref, sessionmaker
 from sqlalchemy.event import listen


 engine = create_engine('sqlite:///:memory:', echo=True)
 Base = declarative_base()

 class Lang(Base):
__tablename__ = 'lang'
lang_code = Column(String(20), primary_key=True)
lang_name = Column(Unicode(64))

 class PageData(Base):
__tablename__ = 'pagedata'
lang_code = Column(String(20), primary_key=True)
lang = relation('Lang', backref='pages',
primaryjoin=lang_code==Lang.lang_code,
foreign_keys=[Lang.lang_code], uselist=False)
data = Column(Unicode(64), nullable=True)

 def add_lang_fk(table, conn, **kw):
if 'added_lang_fk' not in table.info:
params = dict(ondelete='cascade')
if conn.dialect.name != 'mssql':
params['onupdate'] = 'restrict'
table.append_constraint(
ForeignKeyConstraint(
['lang_code'], [Lang.__tablename__ + '.lang_code'], **params))
table.info['added_lang_fk'] = True

 listen(PageData.__table__, before_create, add_lang_fk)

 Base.metadata.create_all(engine)


 Session = sessionmaker(bind=engine)
 session = Session()

 de = Lang(lang_code='de', lang_name='Deutsch')
 session.add(de)

 data = PageData(lang_code='de', data=uVielen Dank im Voraus) #this works
 data = PageData(lang=de, data=uVielen Dank im Voraus) #this fails
 session.add(data)

 session.flush()


 thanks in advance,
 alex

 On 07/15/2012 07:08 PM, Michael Bayer wrote:

 On Jul 15, 2012, at 5:53 AM, alex bodnaru wrote:


 hello michael, friends,

 On 07/11/2012 10:31 AM, alex bodnaru wrote:

 hello michael,

 now it works. i also had to add uselist=False.

 i tried it the longest way possible, by adding a Pool first_connect 
 listener,
 but this was not really needed. just the uselist.

 thanks a lot,
 alex

 sorry, not yet:

 the relationship should also allow assignment like this:

 class Lang(DeclarativeBase):
  lang_code = Column(String(20), primary_key=True)
  lang_name = Column(String(20))

 class PageData(DeclarativeBase):
  lang_code = Column(String(20), primary_key=True)
  lang = relation('Lang', backref='pages',
 primaryjoin=lang_code==Lang.lang_code, foreign_keys=[Lang.lang_code], 
 uselist=False)

 the PageData.lang_code foreign key is being added in an event on before 
 create.

 before delaying creation of the foreign key, i could do like this:

 p = PageData()
 p.lang = Lang.get('en')

 and p.lang_code got assigned. why isn't lang_code being assigned now 
 anymore?

 it would imply the relationship is not working at all.

 like before: 

 can you just throw these two classes, the event, and some imports into a 
 file for me ?  I can just run it.

 much quicker than lots of back and forth.






 thanks in advance,
 alex
 On 07/09/2012 04:25 PM, Michael Bayer wrote:

 On Jul 9, 2012, at 4:48 AM, alex bodnaru wrote:


 hello michael, friends,

 after successfuly fixing the ddl by the append_constraint event, the 
 relations
 that needed the said foreign keys remained orphan, asking for a 
 foreign_keys
 argument and failing to load the remote table:

 class Lang(DeclarativeBase):
  lang_code = Column(String(20), primary_key=True)
  lang_name = Column(String(20))

 class PageData(DeclarativeBase):
  lang_code = Column(String(20), primary_key=True) # this foreign key is 
 being
 successfully appended on before_create.
  lang = relation('Lang', backref='pages',
 primaryjoin=lang_code==Lang.lang_code) #this relationship won't work, 
 since at
 the moment the class is being made, the foreign key is not there yet.

 the foreign_keys=Lang.lang_code arg does calm the exception, but 
 doesn't do the
 work.
 could i add the relationship to the mapper on the same event?

 I would think foreign_keys should fix the problem totally, what do you 
 mean doesn't do the work?  I'd have

Re: [sqlalchemy] dialect sensible declaration

2012-07-15 Thread alex bodnaru

hello michael, friends,

On 07/11/2012 10:31 AM, alex bodnaru wrote:
 
 hello michael,
 
 now it works. i also had to add uselist=False.
 
 i tried it the longest way possible, by adding a Pool first_connect listener,
 but this was not really needed. just the uselist.
 
 thanks a lot,
 alex
 
sorry, not yet:

the relationship should also allow assignment like this:

class Lang(DeclarativeBase):
   lang_code = Column(String(20), primary_key=True)
   lang_name = Column(String(20))

class PageData(DeclarativeBase):
   lang_code = Column(String(20), primary_key=True)
   lang = relation('Lang', backref='pages',
primaryjoin=lang_code==Lang.lang_code, foreign_keys=[Lang.lang_code], 
uselist=False)

the PageData.lang_code foreign key is being added in an event on before create.

before delaying creation of the foreign key, i could do like this:

p = PageData()
p.lang = Lang.get('en')

and p.lang_code got assigned. why isn't lang_code being assigned now anymore?

thanks in advance,
alex
 On 07/09/2012 04:25 PM, Michael Bayer wrote:

 On Jul 9, 2012, at 4:48 AM, alex bodnaru wrote:


 hello michael, friends,

 after successfuly fixing the ddl by the append_constraint event, the 
 relations
 that needed the said foreign keys remained orphan, asking for a foreign_keys
 argument and failing to load the remote table:

 class Lang(DeclarativeBase):
lang_code = Column(String(20), primary_key=True)
lang_name = Column(String(20))

 class PageData(DeclarativeBase):
lang_code = Column(String(20), primary_key=True) # this foreign key is 
 being
 successfully appended on before_create.
lang = relation('Lang', backref='pages',
 primaryjoin=lang_code==Lang.lang_code) #this relationship won't work, since 
 at
 the moment the class is being made, the foreign key is not there yet.

 the foreign_keys=Lang.lang_code arg does calm the exception, but doesn't do 
 the
 work.
 could i add the relationship to the mapper on the same event?

 I would think foreign_keys should fix the problem totally, what do you 
 mean doesn't do the work?  I'd have to work up a test case, can you just 
 throw these two classes, the event, and some imports into a file for me ?  I 
 can just run it.

 well, almost totally ;)
 it also needed uselist=False.
 


 thank in advance,
 alex

 On 07/07/2012 05:13 PM, Michael Bayer wrote:
 sure engine and connection have .dialect.name.   Foreign key constraints 
 don't matter on SQLite unless you've actually enabled them, which is rare. 
   I'd still use an event though so at least the behavior is transparent.

 @event.listens_for(my_table, before_create)
 def add_fk(table, conn, **kw):
if conn.dialect.name != 'mssql':
table.append_constraint(ForeignKeyConstraint(...))

 tricky though to modify the table metadata within a create event in the 
 case that the table is created multiple times in an app.  you can put a 
 flag in table.info, like table.info['added_the_fk'] = True, to keep 
 track of things.



 On Jul 7, 2012, at 12:59 AM, alex bodnaru wrote:


 hello mike and thanks for your answer.

 no problem with ForeignKeyConstraint, but wouldn't AddConstraint go the 
 alter
 way? in this case, it will be ignored by the sqlite dialect.

 what i was looking for was more like:

 from sqlalchemy... import get_dialect

 
 fk_parms = dict(.)
 if get_dialect() != 'mssql':
   fk_parms.update(onupdate='restrict')
 fk = ForeignKey(**fk_parms)

 would the dialect be accessible from the engine, metadata etc?

 thanks in advance,
 alex


 On 07/06/2012 11:39 PM, Michael Bayer wrote:
 you'd use ForeignKeyConstraint along with the AddConstraint directive, 
 and limit it per-dialect using create/drop events as documented at 
 http://docs.sqlalchemy.org/en/rel_0_7/core/schema.html#controlling-ddl-sequences
  .


 On Jul 6, 2012, at 1:30 PM, alex bodnaru wrote:


 hello friends,

 i need to define a foreign key differently for different dialects:
 ondelete='restrict' for most engines, but nothing (implied and not 
 recognized)
 for mssql.

 could you help?

 thanks in advance,
 alex

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



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



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

Re: [sqlalchemy] dialect sensible declaration

2012-07-11 Thread alex bodnaru

hello michael,

now it works. i also had to add uselist=False.

i tried it the longest way possible, by adding a Pool first_connect listener,
but this was not really needed. just the uselist.

thanks a lot,
alex

On 07/09/2012 04:25 PM, Michael Bayer wrote:
 
 On Jul 9, 2012, at 4:48 AM, alex bodnaru wrote:
 

 hello michael, friends,

 after successfuly fixing the ddl by the append_constraint event, the 
 relations
 that needed the said foreign keys remained orphan, asking for a foreign_keys
 argument and failing to load the remote table:

 class Lang(DeclarativeBase):
lang_code = Column(String(20), primary_key=True)
lang_name = Column(String(20))

 class PageData(DeclarativeBase):
lang_code = Column(String(20), primary_key=True) # this foreign key is 
 being
 successfully appended on before_create.
lang = relation('Lang', backref='pages',
 primaryjoin=lang_code==Lang.lang_code) #this relationship won't work, since 
 at
 the moment the class is being made, the foreign key is not there yet.

 the foreign_keys=Lang.lang_code arg does calm the exception, but doesn't do 
 the
 work.
 could i add the relationship to the mapper on the same event?
 
 I would think foreign_keys should fix the problem totally, what do you mean 
 doesn't do the work?  I'd have to work up a test case, can you just throw 
 these two classes, the event, and some imports into a file for me ?  I can 
 just run it.
 
well, almost totally ;)
it also needed uselist=False.

 

 thank in advance,
 alex

 On 07/07/2012 05:13 PM, Michael Bayer wrote:
 sure engine and connection have .dialect.name.   Foreign key constraints 
 don't matter on SQLite unless you've actually enabled them, which is rare.  
  I'd still use an event though so at least the behavior is transparent.

 @event.listens_for(my_table, before_create)
 def add_fk(table, conn, **kw):
if conn.dialect.name != 'mssql':
table.append_constraint(ForeignKeyConstraint(...))

 tricky though to modify the table metadata within a create event in the 
 case that the table is created multiple times in an app.  you can put a 
 flag in table.info, like table.info['added_the_fk'] = True, to keep track 
 of things.



 On Jul 7, 2012, at 12:59 AM, alex bodnaru wrote:


 hello mike and thanks for your answer.

 no problem with ForeignKeyConstraint, but wouldn't AddConstraint go the 
 alter
 way? in this case, it will be ignored by the sqlite dialect.

 what i was looking for was more like:

 from sqlalchemy... import get_dialect

 
 fk_parms = dict(.)
 if get_dialect() != 'mssql':
fk_parms.update(onupdate='restrict')
 fk = ForeignKey(**fk_parms)

 would the dialect be accessible from the engine, metadata etc?

 thanks in advance,
 alex


 On 07/06/2012 11:39 PM, Michael Bayer wrote:
 you'd use ForeignKeyConstraint along with the AddConstraint directive, 
 and limit it per-dialect using create/drop events as documented at 
 http://docs.sqlalchemy.org/en/rel_0_7/core/schema.html#controlling-ddl-sequences
  .


 On Jul 6, 2012, at 1:30 PM, alex bodnaru wrote:


 hello friends,

 i need to define a foreign key differently for different dialects:
 ondelete='restrict' for most engines, but nothing (implied and not 
 recognized)
 for mssql.

 could you help?

 thanks in advance,
 alex

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



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



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

 

-- 
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] dialect sensible declaration

2012-07-09 Thread alex bodnaru

hello michael, friends,

after successfuly fixing the ddl by the append_constraint event, the relations
that needed the said foreign keys remained orphan, asking for a foreign_keys
argument and failing to load the remote table:

class Lang(DeclarativeBase):
lang_code = Column(String(20), primary_key=True)
lang_name = Column(String(20))

class PageData(DeclarativeBase):
lang_code = Column(String(20), primary_key=True) # this foreign key is being
successfully appended on before_create.
lang = relation('Lang', backref='pages',
primaryjoin=lang_code==Lang.lang_code) #this relationship won't work, since at
the moment the class is being made, the foreign key is not there yet.

the foreign_keys=Lang.lang_code arg does calm the exception, but doesn't do the
work.
could i add the relationship to the mapper on the same event?

thank in advance,
alex

On 07/07/2012 05:13 PM, Michael Bayer wrote:
 sure engine and connection have .dialect.name.   Foreign key constraints 
 don't matter on SQLite unless you've actually enabled them, which is rare.   
 I'd still use an event though so at least the behavior is transparent.
 
 @event.listens_for(my_table, before_create)
 def add_fk(table, conn, **kw):
 if conn.dialect.name != 'mssql':
 table.append_constraint(ForeignKeyConstraint(...))
 
 tricky though to modify the table metadata within a create event in the 
 case that the table is created multiple times in an app.  you can put a flag 
 in table.info, like table.info['added_the_fk'] = True, to keep track of 
 things.
 
 
 
 On Jul 7, 2012, at 12:59 AM, alex bodnaru wrote:
 

 hello mike and thanks for your answer.

 no problem with ForeignKeyConstraint, but wouldn't AddConstraint go the alter
 way? in this case, it will be ignored by the sqlite dialect.

 what i was looking for was more like:

 from sqlalchemy... import get_dialect

 
 fk_parms = dict(.)
 if get_dialect() != 'mssql':
  fk_parms.update(onupdate='restrict')
 fk = ForeignKey(**fk_parms)

 would the dialect be accessible from the engine, metadata etc?

 thanks in advance,
 alex


 On 07/06/2012 11:39 PM, Michael Bayer wrote:
 you'd use ForeignKeyConstraint along with the AddConstraint directive, and 
 limit it per-dialect using create/drop events as documented at 
 http://docs.sqlalchemy.org/en/rel_0_7/core/schema.html#controlling-ddl-sequences
  .


 On Jul 6, 2012, at 1:30 PM, alex bodnaru wrote:


 hello friends,

 i need to define a foreign key differently for different dialects:
 ondelete='restrict' for most engines, but nothing (implied and not 
 recognized)
 for mssql.

 could you help?

 thanks in advance,
 alex

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



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

 

-- 
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] dialect sensible declaration

2012-07-08 Thread alex bodnaru

it worked very well,

thanks a lot michael :),

alex

On 07/07/2012 05:13 PM, Michael Bayer wrote:
 sure engine and connection have .dialect.name.   Foreign key constraints 
 don't matter on SQLite unless you've actually enabled them, which is rare.   
 I'd still use an event though so at least the behavior is transparent.
 
 @event.listens_for(my_table, before_create)
 def add_fk(table, conn, **kw):
 if conn.dialect.name != 'mssql':
 table.append_constraint(ForeignKeyConstraint(...))
 
 tricky though to modify the table metadata within a create event in the 
 case that the table is created multiple times in an app.  you can put a flag 
 in table.info, like table.info['added_the_fk'] = True, to keep track of 
 things.
 
 
 
 On Jul 7, 2012, at 12:59 AM, alex bodnaru wrote:
 

 hello mike and thanks for your answer.

 no problem with ForeignKeyConstraint, but wouldn't AddConstraint go the alter
 way? in this case, it will be ignored by the sqlite dialect.

 what i was looking for was more like:

 from sqlalchemy... import get_dialect

 
 fk_parms = dict(.)
 if get_dialect() != 'mssql':
  fk_parms.update(onupdate='restrict')
 fk = ForeignKey(**fk_parms)

 would the dialect be accessible from the engine, metadata etc?

 thanks in advance,
 alex


 On 07/06/2012 11:39 PM, Michael Bayer wrote:
 you'd use ForeignKeyConstraint along with the AddConstraint directive, and 
 limit it per-dialect using create/drop events as documented at 
 http://docs.sqlalchemy.org/en/rel_0_7/core/schema.html#controlling-ddl-sequences
  .


 On Jul 6, 2012, at 1:30 PM, alex bodnaru wrote:


 hello friends,

 i need to define a foreign key differently for different dialects:
 ondelete='restrict' for most engines, but nothing (implied and not 
 recognized)
 for mssql.

 could you help?

 thanks in advance,
 alex

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



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

 

-- 
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] dialect sensible declaration

2012-07-07 Thread alex bodnaru

thanks a lot michael.

i think i'll go this way :)

best regards,
alex

On 07/07/2012 05:13 PM, Michael Bayer wrote:
 sure engine and connection have .dialect.name.   Foreign key constraints 
 don't matter on SQLite unless you've actually enabled them, which is rare.   
 I'd still use an event though so at least the behavior is transparent.
 
 @event.listens_for(my_table, before_create)
 def add_fk(table, conn, **kw):
 if conn.dialect.name != 'mssql':
 table.append_constraint(ForeignKeyConstraint(...))
 
 tricky though to modify the table metadata within a create event in the 
 case that the table is created multiple times in an app.  you can put a flag 
 in table.info, like table.info['added_the_fk'] = True, to keep track of 
 things.
 
 
 
 On Jul 7, 2012, at 12:59 AM, alex bodnaru wrote:
 

 hello mike and thanks for your answer.

 no problem with ForeignKeyConstraint, but wouldn't AddConstraint go the alter
 way? in this case, it will be ignored by the sqlite dialect.

 what i was looking for was more like:

 from sqlalchemy... import get_dialect

 
 fk_parms = dict(.)
 if get_dialect() != 'mssql':
  fk_parms.update(onupdate='restrict')
 fk = ForeignKey(**fk_parms)

 would the dialect be accessible from the engine, metadata etc?

 thanks in advance,
 alex


 On 07/06/2012 11:39 PM, Michael Bayer wrote:
 you'd use ForeignKeyConstraint along with the AddConstraint directive, and 
 limit it per-dialect using create/drop events as documented at 
 http://docs.sqlalchemy.org/en/rel_0_7/core/schema.html#controlling-ddl-sequences
  .


 On Jul 6, 2012, at 1:30 PM, alex bodnaru wrote:


 hello friends,

 i need to define a foreign key differently for different dialects:
 ondelete='restrict' for most engines, but nothing (implied and not 
 recognized)
 for mssql.

 could you help?

 thanks in advance,
 alex

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



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

 

-- 
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] dialect sensible declaration

2012-07-06 Thread alex bodnaru

hello friends,

i need to define a foreign key differently for different dialects:
ondelete='restrict' for most engines, but nothing (implied and not recognized)
for mssql.

could you help?

thanks in advance,
alex

-- 
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] dialect sensible declaration

2012-07-06 Thread alex bodnaru

hello mike and thanks for your answer.

no problem with ForeignKeyConstraint, but wouldn't AddConstraint go the alter
way? in this case, it will be ignored by the sqlite dialect.

what i was looking for was more like:

from sqlalchemy... import get_dialect


fk_parms = dict(.)
if get_dialect() != 'mssql':
fk_parms.update(onupdate='restrict')
fk = ForeignKey(**fk_parms)

would the dialect be accessible from the engine, metadata etc?

thanks in advance,
alex


On 07/06/2012 11:39 PM, Michael Bayer wrote:
 you'd use ForeignKeyConstraint along with the AddConstraint directive, and 
 limit it per-dialect using create/drop events as documented at 
 http://docs.sqlalchemy.org/en/rel_0_7/core/schema.html#controlling-ddl-sequences
  .
 
 
 On Jul 6, 2012, at 1:30 PM, alex bodnaru wrote:
 

 hello friends,

 i need to define a foreign key differently for different dialects:
 ondelete='restrict' for most engines, but nothing (implied and not 
 recognized)
 for mssql.

 could you help?

 thanks in advance,
 alex

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

 

-- 
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] a list as a named argument for an in clause

2012-01-22 Thread alex bodnaru

hello friends,

i'm using sa at a quite low level, with session.execute(text, dict)

is it possible to do something in the spirit of:

session.execute(select * from tablename where id in (:ids), 
dict(ids=[1,2,3,4])) ?

thanks in advance,
alex

-- 
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] override char() handling

2011-12-24 Thread alex bodnaru

hello friends,

i'm happily using  sqlalchemy in a tg 2.1 project. with a legacy database, thus
my queries are in the form of dbsession.execute(sql).

where should i hook a strip of the data from a char(len) field? this is needed
for this application only.

best regards and merry christmas,
alex

-- 
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] adding listener(s) to existing engine

2011-04-02 Thread alex bodnaru

hello friends,

the turbogears framework is providing my application with an engine.

i'd like to add to it a listener, to turn on a pragma in sqlite.

how should i proceed?

thanks in advance,
alex

-- 
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] adding listener(s) to existing engine

2011-04-02 Thread alex bodnaru
On 04/02/2011 07:04 PM, Michael Bayer wrote:

 On Apr 2, 2011, at 6:48 AM, alex bodnaru wrote:

 hello friends,

 the turbogears framework is providing my application with an engine.

 i'd like to add to it a listener, to turn on a pragma in sqlite.

 how should i proceed?

 thanks in advance,
 alex
 So this is way super easy in 0.7, just event.listen() anytime.   In 0.6 I'd 
 have to give you a hack.
thanks a lot michael, i'll try to upgrade to 0.7.
on fail, i'd dare ask for the hack.

best regards
alex

-- 
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: [elixir] problem with cascade deletes

2010-09-14 Thread alex bodnaru
 hey yacine, friends,

indeed the problem came partly because i haven't followed the traces of elixir
close enough: i've used backref instead of inverse for manytoone relations.

the only drawback of using inverse, is that it requires the inverse relation to
really exist, hence it can't be implied.

here comes to light an elixir extension i've made a time ago (inverse_orphans),
that would create an inverse relation on the onetomany side when it is missing.

for your interest, the plugin is attached. i'd extend this plugin to take kwargs
too.

best regards,
alex

On 09/12/2010 10:37 AM, chaouche yacine wrote:
 Yes, except I wanted the children *not* to be deleted but raise an 
 integrity_error exception instead, because what was done is that they were 
 not deleted but their FK (pointing to the parent) were set to NULL and they 
 were raising a non-null constraint related exception. 




 --- On Sun, 9/12/10, alex bodnaru alexbodn.gro...@gmail.com wrote:

 From: alex bodnaru alexbodn.gro...@gmail.com
 Subject: Re: [elixir] problem with cascade deletes
 To: sqleli...@googlegroups.com
 Date: Sunday, September 12, 2010, 1:21 AM
  hello yacine,

 elixir isn't known to reinvent sa, but please point me to
 things you would
 change for a pure approach.
 part of the lower level stuff is needed to turn foreign
 keys on in sqlite.

 in the mean time, i did a declarative example which fails
 like elixir.

 btw. this is the same problem you have also previously
 reported on this list.

 alex

 On 09/12/2010 09:58 AM, chaouche yacine wrote:
 hello alex,

 In your elixir program, you are mixing some imports
 from sqlalchemy (create_engine from example) with imports
 from elixir. Did you try an elixir only approach ?
 Y.Chaouche



 --- On Sat, 9/11/10, alex bodnaru alexbodn.gro...@gmail.com
 wrote:
 From: alex bodnaru alexbodn.gro...@gmail.com
 Subject: [elixir] problem with cascade deletes
 To: sqleli...@googlegroups.com
 Date: Saturday, September 11, 2010, 6:31 AM

 hello friends,

 there seems to be a flaw in elixir with cascade
 deletes.
 i have a program that does it with sqlalchemy orm,
 and a
 similar one to do it
 with elixir.
 instead of deleting the elixir program only nulls
 the keys
 in the child.

 the programs are attached.

 best regards,
 alex

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




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



   


-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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.


inverse_orphans Elixir Statement Generator

===
inverse_orphans
===

i am using an identity model module from a third party, 
having, among others, an User class. 
this model file might well be upgraded by it's supplier. 
in another model file, which imports the identity model entities, 
i have a Person class, which has a ManyToOne relationship with the User table. 
However i'd like to also know the Person which references a given User, adding 
OneToMany relationships to User, will need to be maintained everytime the 
supplier upgrades identity model. 
to implement this, i am giving an inverse name on the ManyToOne side, and 
adding an after_mapper action to create the OneToMany relationship.


from elixir.statements import Statement
from elixir import OneToOne, OneToMany, ManyToOne, ManyToMany

__all__ = ['inverse_orphans']
__doc_all__ = __all__


#TODO: inherit from entity builder
class inverse_orphans_entity_builder(object):
An inverse_orphans Elixir Statement object

def __init__(self, entity):
self.entity = entity

def before_table(self):
'''
if we name an inverse relationship which is not already defined on the
target, here we create the inverse relationship on the target.
should run this for each relationship property.
'''
for r in self.entity._descriptor.relationships:
desc = r.target._descriptor
if r.inverse_name and desc.find_relationship(r.inverse_name) is None:
if type(r) == ManyToOne:
# should probably test uselist
if 'unique' in r.column_kwargs

Re: [sqlalchemy] passive_deletes/updates with sqlite

2010-09-14 Thread alex bodnaru
 On 09/13/2010 05:49 PM, Michael Bayer wrote:

 On Sep 13, 2010, at 11:16 AM, alex bodnaru wrote:

 hope my approach isn't too simplist, but onetomany is usually implemented in
 rdbms by an manytoone column or a few of them, with or without ri clauses: 
 thus,
 a foreign key or an index.
 conversely, a manytoone relation has an implicit onetomany one (or an 
 explicit
 onetoone).

 if you read what I wrote, I was explaining, that we architecturally choose not
 to generate the implicit reverse direction when it isn't specified by the
 user.  And that this decision is not too controversial since Hibernate made
 the same one.


 the example i've given with elixir (look at the sql echo) shows the onetomany
 updates the foreign key to null, not knowing they wouldn't be found in the
 cascading delete. i'm searching the exact point elixir should give the
 passive_deletes to the sa relation, thus to force it to give it to the right
 side of it.

 right  - Elixir has a more abstracted layer of user configuration, which is
 basically what you're asking SQLAlchemy to build into it.  Id rather make
 things simpler on the inside, not more magical. 
 -- 
 You received this message because you are subscribed to the Google Groups
 sqlalchemy group.
 To post to this group, send email to sqlalch...@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.
well i found the problem (it's in my code). i was hilariously dealing with
something more magical in sa then in elixir: i've used backref from sa instead
of inverse from elixir. for this specific case it's simply my error to do this,
since passive_deletes is an argument to be passed to an existing relation, but
the magic i usually wanted to achieve with backref was auto-creating a onetomany
relation to complement a manytoone one, especially when i don't wish to touch
the file of the parent entity.
btw, to achieve this same magic with elixir i've made in the past an elixir
extension, that was rejected by elixir people, that pointed me to backref.

best regards and thanks again,
alex

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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.


from sqlalchemy import (MetaData, Table, Column, Integer, String, ForeignKey,
create_engine, ForeignKeyConstraint)
from sqlalchemy.orm import (mapper, relationship, sessionmaker)

from elixir import *
from sqlalchemy.interfaces import PoolListener

class SQLiteFKListener(PoolListener):
def connect(self, dbapi_con, con_record):
dbapi_con.execute('PRAGMA foreign_keys = ON;')

engine = create_engine(sqlite:///:memory:, echo=True, listeners=[SQLiteFKListener()])

metadata.bind = engine


class MyClass(Entity):
using_options(tablename='mytable')
id = Field(Integer, primary_key=True, autoincrement=True)
name = Field(String(20))
children = OneToMany('MyOtherClass', passive_deletes=True)

def __repr__(self):
return 'MyClass %s, %s' % (None if self.id is None else str(self.id), self.name)

class MyOtherClass(Entity):
using_options(tablename='myothertable')
id = Field(Integer, primary_key=True, autoincrement=True)
name = Field(String(20))
parent = ManyToOne('MyClass', inverse='children', colname='parent_id', ondelete=cascade)

def __repr__(self):
return 'MyOtherClass %s, %s, %s' % (None if self.parent_id is None else str(self.parent_id), None if self.id is None else str(self.id), self.name)


setup_all()
create_all()


alex = MyClass(name='alex')
pisi = MyClass(name='pisi')

print alex, pisi

#session.commit()
session.flush()

print alex, pisi

alexdagan = MyOtherClass(parent=alex, name='dagan')
alexshaked = MyOtherClass(parent=alex, name='shaked')
pisidagan = MyOtherClass(parent=pisi, name='dagan')
pisishaked = MyOtherClass(parent=pisi, name='shaked')

#session.commit()
session.flush()

shaked1 = session.query(MyOtherClass).filter_by(parent_id=1, name=u'shaked')

session.delete(alex)

#session.commit()
session.flush()


for my in session.query(MyClass).all():
print my
for my in session.query(MyOtherClass).all():
print my



Re: [sqlalchemy] passive_deletes/updates with sqlite

2010-09-13 Thread alex bodnaru
 On 09/13/2010 08:32 AM, Michael Bayer wrote:
 On Sep 12, 2010, at 11:02 PM, alex bodnaru wrote:

 thanks a lot michael.
 indeed it works, but it seems counter-intuitive a little since passive_* 
 should
 in my opinion be on the side of the on * cascade it describes.
 anyway, it's great, and hope to make it work with elixir too.
 If you said session.delete(my_other_object), no action is needed if it 
 references some particular my_object.It is only if you 
 session.delete(my_object) that SQLAlchemy needs to do something - and for 
 that, it must load those objects which reference my_object.   It does this 
 simply by using the one-to-many collection on my_object which states how to 
 load my_other_objects with an association.So the one-to-many collection 
 is what's needed here - if you only specified the other direction, SQLAlchemy 
 would need to derive the forwards collection from it and apply it to the o2m 
 parent class internally.  Right now the internals are simple such that 
 loading is only possible in the direction in which the relationship() was 
 configured.

 It is certainly possible to alter relationship() to be able to load 
 collections or associations in both directions so that a many-to-one 
 relationship could transparently load from the other direction, though 
 internally this would require doing pretty much what backref does 
 explicitly - placing some linkage to the relationship on the target class of 
 the many-to-one which could react to deletions of that target class.   So the 
 current implementation is much simpler than that, so the passive_updates 
 flag goes onto the side of the relationship that ultimately needs it, so that 
 SQLAlchemy doesn't need to generate the backref which is easy enough for 
 the user to specify, and in very rare conditions may even be configured 
 differently than the reverse direction.

 The original design of cascade is taken from Hibernate, probably the most 
 widely used object relational tool in history.   They too tend to define 
 ORM-level information about the foreign key, including the CASCADE 
 attributes on the primary key side:  

 http://docs.jboss.org/hibernate/stable/core/reference/en/html/mapping.html#mapping-declaration-key
 http://docs.jboss.org/hibernate/stable/core/reference/en/html/collections.html#collections-mapping
   



 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalch...@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.

hope my approach isn't too simplist, but onetomany is usually implemented in
rdbms by an manytoone column or a few of them, with or without ri clauses: thus,
a foreign key or an index.
conversely, a manytoone relation has an implicit onetomany one (or an explicit
onetoone).

hereinafter, anything you would define on one end, at least in terms of ri,
should be at the end it needs to be there.

the example i've given with elixir (look at the sql echo) shows the onetomany
updates the foreign key to null, not knowing they wouldn't be found in the
cascading delete. i'm searching the exact point elixir should give the
passive_deletes to the sa relation, thus to force it to give it to the right
side of it.

best regards,
alex

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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] passive_deletes/updates with sqlite

2010-09-12 Thread alex bodnaru
 On 09/12/2010 04:27 PM, Michael Bayer wrote:
 cant speak for Elixir, but your passive_deletes is on the wrong side in 
 your declarative example.

 The correlations between classical and declarative relationship patterns are 
 now individually contrasted at 
 http://www.sqlalchemy.org/docs/orm/relationships.html#basic-relational-patterns
  .

 On Sep 11, 2010, at 10:58 PM, alex bodnaru wrote:

 On 09/11/2010 04:31 AM, alex wrote:
 On 09/10/2010 05:41 PM, Michael Bayer wrote:
 On Sep 10, 2010, at 4:13 AM, alex wrote:

 hello friends,

 as sqlite has recently introduced support for on delete/update cascade,
 i'd like to implement the passive_* functionality for this driver too.

 please give me a hint where to start.
 passive_delete and passive_update are database agnostic and only apply to 
 what effects the ORM can expect from the underlying schema, just use them 
 normally.

 thanks a lot for your response michael.
 i spent a little time to make a more isolated test case, and it works with
 sa+orm, but not with elixir, that seems to forget to pass the 
 passive_deletes.
 i'm further inquiring there, in a hope to make a patch.

 best regards,
 alex
 one further step took me closer to the problem. it happens with declarative 
 too.
 i'm attaching 3 scripts for comparison: one made with regular orm, one with
 elixir and one with declarative. the same problem with elixir and 
 declarative.
 haven't tested on other rdbms.


 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalch...@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.

 cascade_declarative.pycascade_elixir.pycascade_orm.py
thanks a lot michael.
indeed it works, but it seems counter-intuitive a little since passive_* should
in my opinion be on the side of the on * cascade it describes.
anyway, it's great, and hope to make it work with elixir too.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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] passive_deletes/updates with sqlite

2010-09-12 Thread alex bodnaru
 On 09/12/2010 04:27 PM, Michael Bayer wrote:
 cant speak for Elixir, but your passive_deletes is on the wrong side in 
 your declarative example.

 The correlations between classical and declarative relationship patterns are 
 now individually contrasted at 
 http://www.sqlalchemy.org/docs/orm/relationships.html#basic-relational-patterns
  .

 On Sep 11, 2010, at 10:58 PM, alex bodnaru wrote:

 On 09/11/2010 04:31 AM, alex wrote:
 On 09/10/2010 05:41 PM, Michael Bayer wrote:
 On Sep 10, 2010, at 4:13 AM, alex wrote:

 hello friends,

 as sqlite has recently introduced support for on delete/update cascade,
 i'd like to implement the passive_* functionality for this driver too.

 please give me a hint where to start.
 passive_delete and passive_update are database agnostic and only apply to 
 what effects the ORM can expect from the underlying schema, just use them 
 normally.

 thanks a lot for your response michael.
 i spent a little time to make a more isolated test case, and it works with
 sa+orm, but not with elixir, that seems to forget to pass the 
 passive_deletes.
 i'm further inquiring there, in a hope to make a patch.

 best regards,
 alex
 one further step took me closer to the problem. it happens with declarative 
 too.
 i'm attaching 3 scripts for comparison: one made with regular orm, one with
 elixir and one with declarative. the same problem with elixir and 
 declarative.
 haven't tested on other rdbms.


 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalch...@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.

 cascade_declarative.pycascade_elixir.pycascade_orm.py
btw, the fixed code.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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.


from sqlalchemy import (MetaData, Table, Column, Integer, String, ForeignKey,
create_engine, ForeignKeyConstraint)
from sqlalchemy.orm import scoped_session, sessionmaker, relation
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.interfaces import PoolListener

class SQLiteFKListener(PoolListener):
def connect(self, dbapi_con, con_record):
dbapi_con.execute('PRAGMA foreign_keys = ON;')


engine = create_engine(sqlite:///:memory:, echo=True, listeners=[SQLiteFKListener()])

Base = declarative_base(bind=engine)


class MyClass(Base):
__tablename__ = 'mytable'
id = Column(Integer, primary_key=True, autoincrement=True)
name =  Column(String(50))
children = relation('MyOtherClass', backref='parent', passive_deletes=True)

def __repr__(self):
return 'MyClass %s, %s' % (None if self.id is None else str(self.id), self.name)

class MyOtherClass(Base):
__tablename__ = 'myothertable'
id = Column(Integer, primary_key=True, autoincrement=True)
parent_id = Column(Integer, ForeignKey('mytable.id', ondelete=CASCADE))
name =  Column(String(50))

def __repr__(self):
return 'MyOtherClass %s, %s, %s' % (None if self.parent_id is None else str(self.parent_id), None if self.id is None else str(self.id), self.name)

Base.metadata.create_all(engine)

session = scoped_session(sessionmaker(autocommit=False,
  autoflush=False,
  bind=engine))


alex = MyClass(name='alex')
pisi = MyClass(name='pisi')

session.add_all([
alex, pisi
])

print alex, pisi

session.flush()

session.add_all([
MyOtherClass(parent=alex, name='dagan'),
MyOtherClass(parent=alex, name='shaked'),
MyOtherClass(parent=pisi, name='dagan'),
MyOtherClass(parent=pisi, name='shaked'),
])

session.flush()

shaked1 = session.query(MyOtherClass).filter_by(parent_id=1, name=u'shaked')

session.delete(alex)

session.flush()

for my in session.query(MyClass).all():
print my
for my in session.query(MyOtherClass).all():
print my



Re: [sqlalchemy] passive_deletes/updates with sqlite

2010-09-11 Thread alex bodnaru
 On 09/11/2010 04:31 AM, alex wrote:
  On 09/10/2010 05:41 PM, Michael Bayer wrote:
 On Sep 10, 2010, at 4:13 AM, alex wrote:

 hello friends,

 as sqlite has recently introduced support for on delete/update cascade,
 i'd like to implement the passive_* functionality for this driver too.

 please give me a hint where to start.
 passive_delete and passive_update are database agnostic and only apply to 
 what effects the ORM can expect from the underlying schema, just use them 
 normally.

 thanks a lot for your response michael.
 i spent a little time to make a more isolated test case, and it works with
 sa+orm, but not with elixir, that seems to forget to pass the passive_deletes.
 i'm further inquiring there, in a hope to make a patch.

 best regards,
 alex
one further step took me closer to the problem. it happens with declarative too.
i'm attaching 3 scripts for comparison: one made with regular orm, one with
elixir and one with declarative. the same problem with elixir and declarative.
haven't tested on other rdbms.


-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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.


from sqlalchemy import (MetaData, Table, Column, Integer, String, ForeignKey,
create_engine, ForeignKeyConstraint)
from sqlalchemy.orm import scoped_session, sessionmaker, relation
from sqlalchemy.ext.declarative import declarative_base

engine = create_engine(sqlite:///:memory:, echo=True)

Base = declarative_base(bind=engine)


class MyClass(Base):
__tablename__ = 'mytable'
id = Column(Integer, primary_key=True, autoincrement=True)
name =  Column(String(50))
#children = relation('MyOtherClass', backref='parent')

def __repr__(self):
return 'MyClass %s, %s' % (None if self.id is None else str(self.id), self.name)

class MyOtherClass(Base):
__tablename__ = 'myothertable'
id = Column(Integer, primary_key=True, autoincrement=True)
parent_id = Column(Integer, ForeignKey('mytable.id', ondelete=CASCADE))
parent = relation('MyClass', backref='children', passive_deletes=True)
name =  Column(String(50))

def __repr__(self):
return 'MyOtherClass %s, %s, %s' % (None if self.parent_id is None else str(self.parent_id), None if self.id is None else str(self.id), self.name)

Base.metadata.create_all(engine)

session = scoped_session(sessionmaker(autocommit=False,
  autoflush=False,
  bind=engine))


alex = MyClass(name='alex')
pisi = MyClass(name='pisi')

session.add_all([
alex, pisi
])

print alex, pisi

session.flush()

session.add_all([
MyOtherClass(parent=alex, name='dagan'),
MyOtherClass(parent=alex, name='shaked'),
MyOtherClass(parent=pisi, name='dagan'),
MyOtherClass(parent=pisi, name='shaked'),
])

session.flush()

shaked1 = session.query(MyOtherClass).filter_by(parent_id=1, name=u'shaked')

session.delete(alex)

session.flush()

for my in session.query(MyClass).all():
print my
for my in session.query(MyOtherClass).all():
print my


from sqlalchemy import (MetaData, Table, Column, Integer, String, ForeignKey,
create_engine, ForeignKeyConstraint)
from sqlalchemy.orm import (mapper, relationship, sessionmaker)

from elixir import *


engine = create_engine(sqlite:///:memory:, echo=True)

metadata.bind = engine

connection = engine.connect()
connection.execute('PRAGMA foreign_keys = ON;')


class MyClass(Entity):
using_options(tablename='mytable')
id = Field(Integer, primary_key=True, autoincrement=True)
name = Field(String(20))
#children = OneToMany('MyOtherClass', ondelete=CASCADE, passive_deletes=True)

def __repr__(self):
return 'MyClass %s, %s' % (None if self.id is None else str(self.id), self.name)

class MyOtherClass(Entity):
using_options(tablename='myothertable')
id = Field(Integer, primary_key=True, autoincrement=True)
name = Field(String(20))
parent = ManyToOne('MyClass', backref='children', colname='parent_id', ondelete=cascade, passive_deletes=True)

def __repr__(self):
return 'MyOtherClass %s, %s, %s' % (None if self.parent_id is None else str(self.parent_id), None if self.id is None else str(self.id), self.name)


setup_all()
create_all()


alex = MyClass(name='alex')
pisi = MyClass(name='pisi')

print alex, pisi

#session.commit()
session.flush()

print alex, pisi

alexdagan = MyOtherClass(parent=alex, name='dagan')
alexshaked = MyOtherClass(parent=alex, name='shaked')
pisidagan = MyOtherClass(parent=pisi, name='dagan')
pisishaked = MyOtherClass(parent=pisi, name='shaked')

#session.commit()
session.flush()

shaked1 = session.query(MyOtherClass).filter_by(parent_id=1, name=u'shaked')


[sqlalchemy] fail to make an custom type

2008-10-21 Thread alex bodnaru
hello friends,

i'm trying to use a custom type, as illustrated in
http://www.sqlalchemy.org/docs/05/types.html,
but neither the old convert_bind_param and convert_result_value, nor
the newer process_bind_param and
process_result_value to not appear to be invoked when i manipulate the type.

the original code was working for me, in the old method. it was
downloaded from:
http://www.mail-archive.com/[EMAIL PROTECTED]/msg00299.html.

the code and test are attached.

best regards,
alex

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

#
enum.py

from sqlalchemy.types import TypeDecorator, String, Unicode

class Enum(TypeDecorator):
This class adds support for ENUM fields, similar in 
functionality to the
ENUM column type in MySQL

def __init__(self, values, empty_to_none=False):
'''
contruct an Enum type

values : a list of values that are valid for this column
empty_to_none : treat the empty string '' as None
'''
if values is None or len(values) is 0:
raise exceptions.AssertionError('Enum requires a list of values')
self.empty_to_none = empty_to_none
self.values = values
# the length of the string/unicode column should be the longest string
# in values
size = max([len(v) for v in values if v is not None])
super(Enum, self).__init__(size)

def test_range(self, value):
if value not in self.values:
raise AssertionError('%s not in Enum.values' % value)
return value

#def convert_bind_param(self, value, engine):
#if self.empty_to_none and value is '':
#value = None
#self.test_range(value)
#return super(Enum, self).convert_bind_param(value, engine)
#
#
#def convert_result_value(self, value, engine):
#self.test_range(value)
#return super(Enum, self).convert_result_value(value, engine)
#
def process_bind_param(self, value, dialect): 
print 'bind'
return self.test_range(value)

def process_result_value(self, value, dialect):
print 'result'
return self.test_range(value)

def copy(self):
return Enum(self.values, self.empty_to_none)

class EnumUnicode(Enum):
impl = Unicode

class EnumString(Enum):
impl = String
#
test_enum.py

from sqlalchemy import create_engine
from enum import *
from elixir import *

#engine = create_engine('sqlite:///')
#metadata.connect(engine)
metadata.bind = 'sqlite:///'
metadata.bind.echo = True

def test_enum():
 class TestPerson(Entity):
 gender = Field(EnumString([m,f]))


 create_all()

 t = TestPerson()
 t.gender = m
 session.flush()
 t.gender = f
 session.flush()

 t.gender = W  #this should fail
# session.flush()
 try:
 session.flush()
 except AssertionError:
 print 'W' failed
 pass
 else:
 print success with W
 assert False  #make sure this fails if it doesn't raise the exception above

 drop_all()
 session.clear()


[sqlalchemy] Re: fail to make an custom type

2008-10-21 Thread alex bodnaru
found my fault.

i have used elixir in a deprecated way, so the error has been masked.

reposting correct code. it may still work the older way too.

thanks,
alex

On Tue, Oct 21, 2008 at 10:25, alex bodnaru [EMAIL PROTECTED] wrote:
 hello friends,

 i'm trying to use a custom type, as illustrated in
 http://www.sqlalchemy.org/docs/05/types.html,
 but neither the old convert_bind_param and convert_result_value, nor
 the newer process_bind_param and
 process_result_value to not appear to be invoked when i manipulate the type.

 the original code was working for me, in the old method. it was
 downloaded from:
 http://www.mail-archive.com/[EMAIL PROTECTED]/msg00299.html.

 the code and test are attached.

 best regards,
 alex


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

#
enum.py

from sqlalchemy.types import TypeEngine, TypeDecorator, String, Unicode

class Enum(TypeDecorator):
This class adds support for ENUM fields, similar in 
functionality to the
ENUM column type in MySQL

impl = TypeEngine

def __init__(self, values, empty_to_none=False):
'''
contruct an Enum type

values : a list of values that are valid for this column
empty_to_none : treat the empty string '' as None
'''
if values is None or len(values) is 0:
raise exceptions.AssertionError('Enum requires a list of values')
self.empty_to_none = empty_to_none
self.values = values
# the length of the string/unicode column should be the longest string
# in values
size = max([len(v) for v in values if v is not None])
super(Enum, self).__init__(size)

def test_range(self, value):
if value not in self.values:
raise AssertionError('%s not in Enum.values' % value)
return value

def convert_bind_param(self, value, engine):
if self.empty_to_none and value is '':
value = None
self.test_range(value)
return super(Enum, self).convert_bind_param(value, engine)

def convert_result_value(self, value, engine):
self.test_range(value)
return super(Enum, self).convert_result_value(value, engine)

def process_bind_param(self, value, dialect): 
return self.test_range(value)

def process_result_value(self, value, dialect):
return self.test_range(value)

def copy(self):
return type(self)(self.values, self.empty_to_none)

class EnumUnicode(Enum):
impl = Unicode

class EnumString(Enum):
impl = String
#
test_enum.py

from enum import *
from elixir import *

metadata.bind = 'sqlite:///'
#metadata.bind.echo = True

def test_enum():
class TestPerson(Entity):
gender = Field(EnumString([m,f]))

setup_all(True)

t = TestPerson()
t.gender = m
session.flush()
t.gender = f
session.flush()

t.gender = W  #this should fail
#session.flush()
try:
session.flush()
except AssertionError:
#print 'W' failed
pass
else:
assert False  #make sure this fails if it doesn't raise the exception above

drop_all()
session.clear()



[sqlalchemy] Re: how to print a constructed query with it's parameters?

2008-10-15 Thread alex bodnaru

hi friends,

i have a lot to learn from both approaches, but i have sadly appeared too lazy.

there will be no problem to imagine what the sql will be, only by
looking at the
template statement (with ?'s) and at the list of parameters.

since the template is available to print (probably by __str__), i'd
onlu ask where
the bindparams list is. eventual quotes and escapes may be imagined by
the types of
the columns.

thanks in advance,
alex

On Wed, Oct 15, 2008 at 12:54,  [EMAIL PROTECTED] wrote:

 i have another approach, which may or may not serve you.
 All those '?' are bindparams, and one can eventualy get them printed
 with their names - and put names where there aren't.
 that's what i needed, i guess replacing names with values would be
 easy job.
 the code is part of tests/convertertest.py of sqlalchemyAggregator,
 http://dev.gafol.net/t/aggregator/
 or
 http://dbcook.svn.sourceforge.net/viewvc/dbcook/trunk/dbcook/misc/aggregator/


 class T_mark( unittest.TestCase):
 ...
def setUp( self):
self.m = MetaData()
#hack for better visibility
def bp( self,bindparam):
if bindparam.value is not None:
   return 'const('+repr(bindparam.value)+')'
k = bindparam.key
if k.startswith( Converter._pfx): #my own bindparams
k = k[ len( Converter._pfx):]
return 'BindParam('+k+')'
self.old_bp = DefaultCompiler._truncate_bindparam
DefaultCompiler._truncate_bindparam = bp

def tearDown( self):
DefaultCompiler._truncate_bindparam = self.old_bp
 ...

 str(expression) then does things like
 :const(True) AND :BindParam(oid) = movies.id
 tags.tabl = :const('movies') AND tags.oid = :BindParam(oid)

 there's some more stuff going on there around compatibility with SA
 0.3--0.5, but that's core.

 ciao
 svil

 On Wednesday 15 October 2008 13:33:46 King Simon-NFHD78 wrote:
  -Original Message-
  From: sqlalchemy@googlegroups.com
  [mailto:[EMAIL PROTECTED] On Behalf Of alex bodnaru
  Sent: 15 October 2008 11:00
  To: SQLAlchemy
  Subject: [sqlalchemy] how to print a constructed query with
  it's parameters?
 
 
  hello friends,
 
  in order to debug my code, i wish to print my query sql.
 
  it's in the fashion of
  query =
  table.query().filter(table.code='XL').filter(table.name.like('
  %'+q+'%')
  with unicode parameters.
 
  by just printing query, i get the select with ? parameters, but
  not the additional parameters list, that contains ['XL',
  %q-value%]. since it doesn't presently work ok, i'd like to print
  the list as well.
 
  thanks in advance,
  alex

 This question comes up a lot. For example, see
 http://groups.google.com/group/sqlalchemy/browse_thread/thread/a060
2ede8 18f55c7

 Firstly, if you use echo=True in your call to create_engine, all
 SQL will be printed to stdout. The parameters will be displayed as
 a list AFTER the SQL is printed.

 Eg. (from http://www.sqlalchemy.org/docs/05/ormtutorial.html)

 BEGIN
 INSERT INTO users (name, fullname, password) VALUES (?, ?, ?)
 ['ed', 'Ed Jones', 'edspassword']
 SELECT users.id AS users_id, users.name AS users_name,
 users.fullname AS users_fullname, users.password AS users_password
 FROM users
 WHERE users.name = ?
 LIMIT 1 OFFSET 0
 ['ed']

 You can control the logging more finely using the logging module -
 see
 http://www.sqlalchemy.org/docs/05/dbengine.html#dbengine_logging
 for more details.

 The problem is that SQLAlchemy doesn't ever replace those '?'
 characters with the actual parameter values. Those strings are
 passed directly to the DBAPI driver, along with the list of
 parameter values. It is then up to the DBAPI driver how it passes
 the query to the database. (This is why SQLAlchemy is fairly safe
 from SQL Injection attacks).

 Hope that helps,

 Simon




 


--~--~-~--~~~---~--~~
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] how to print a constructed query with it's parameters?

2008-10-15 Thread alex bodnaru

hello friends,

in order to debug my code, i wish to print my query sql.

it's in the fashion of
query = table.query().filter(table.code='XL').filter(table.name.like('%'+q+'%')
with unicode parameters.

by just printing query, i get the select with ? parameters, but not
the additional parameters list, that contains ['XL', %q-value%]. since
it doesn't presently work ok, i'd like to print the list as well.

thanks in advance,
alex

--~--~-~--~~~---~--~~
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: how to print a constructed query with it's parameters?

2008-10-15 Thread alex bodnaru

hi Ants,

thank you very much.

it will help me and many others in printf style debugging.

best regards,
alex

On Wed, Oct 15, 2008 at 15:09, Ants Aasma [EMAIL PROTECTED] wrote:

 This seems to come up often. I took a few minutes and threw together a
 semi-robust way to do this on 0.5 series. I posted it under usage
 recipes in the wiki: http://www.sqlalchemy.org/trac/wiki/DebugInlineParams
 It has some flaws, but should be somewhat helpful for debugging.

 Ants

 On Oct 15, 2:42 pm, alex bodnaru [EMAIL PROTECTED] wrote:
 hi friends,

 i have a lot to learn from both approaches, but i have sadly appeared too 
 lazy.

 there will be no problem to imagine what the sql will be, only by
 looking at the
 template statement (with ?'s) and at the list of parameters.

 since the template is available to print (probably by __str__), i'd
 onlu ask where
 the bindparams list is. eventual quotes and escapes may be imagined by
 the types of
 the columns.

 thanks in advance,
 alex

 On Wed, Oct 15, 2008 at 12:54,  [EMAIL PROTECTED] wrote:

  i have another approach, which may or may not serve you.
  All those '?' are bindparams, and one can eventualy get them printed
  with their names - and put names where there aren't.
  that's what i needed, i guess replacing names with values would be
  easy job.
  the code is part of tests/convertertest.py of sqlalchemyAggregator,
 http://dev.gafol.net/t/aggregator/
  or
 http://dbcook.svn.sourceforge.net/viewvc/dbcook/trunk/dbcook/misc/agg...

  class T_mark( unittest.TestCase):
  ...
 def setUp( self):
 self.m = MetaData()
 #hack for better visibility
 def bp( self,bindparam):
 if bindparam.value is not None:
return 'const('+repr(bindparam.value)+')'
 k = bindparam.key
 if k.startswith( Converter._pfx): #my own bindparams
 k = k[ len( Converter._pfx):]
 return 'BindParam('+k+')'
 self.old_bp = DefaultCompiler._truncate_bindparam
 DefaultCompiler._truncate_bindparam = bp

 def tearDown( self):
 DefaultCompiler._truncate_bindparam = self.old_bp
  ...

  str(expression) then does things like
  :const(True) AND :BindParam(oid) = movies.id
  tags.tabl = :const('movies') AND tags.oid = :BindParam(oid)

  there's some more stuff going on there around compatibility with SA
  0.3--0.5, but that's core.

  ciao
  svil

  On Wednesday 15 October 2008 13:33:46 King Simon-NFHD78 wrote:
   -Original Message-
   From: sqlalchemy@googlegroups.com
   [mailto:[EMAIL PROTECTED] On Behalf Of alex bodnaru
   Sent: 15 October 2008 11:00
   To: SQLAlchemy
   Subject: [sqlalchemy] how to print a constructed query with
   it's parameters?

   hello friends,

   in order to debug my code, i wish to print my query sql.

   it's in the fashion of
   query =
   table.query().filter(table.code='XL').filter(table.name.like('
   %'+q+'%')
   with unicode parameters.

   by just printing query, i get the select with ? parameters, but
   not the additional parameters list, that contains ['XL',
   %q-value%]. since it doesn't presently work ok, i'd like to print
   the list as well.

   thanks in advance,
   alex

  This question comes up a lot. For example, see
 http://groups.google.com/group/sqlalchemy/browse_thread/thread/a060
 2ede8 18f55c7

  Firstly, if you use echo=True in your call to create_engine, all
  SQL will be printed to stdout. The parameters will be displayed as
  a list AFTER the SQL is printed.

  Eg. (fromhttp://www.sqlalchemy.org/docs/05/ormtutorial.html)

  BEGIN
  INSERT INTO users (name, fullname, password) VALUES (?, ?, ?)
  ['ed', 'Ed Jones', 'edspassword']
  SELECT users.id AS users_id, users.name AS users_name,
  users.fullname AS users_fullname, users.password AS users_password
  FROM users
  WHERE users.name = ?
  LIMIT 1 OFFSET 0
  ['ed']

  You can control the logging more finely using the logging module -
  see
 http://www.sqlalchemy.org/docs/05/dbengine.html#dbengine_logging
  for more details.

  The problem is that SQLAlchemy doesn't ever replace those '?'
  characters with the actual parameter values. Those strings are
  passed directly to the DBAPI driver, along with the list of
  parameter values. It is then up to the DBAPI driver how it passes
  the query to the database. (This is why SQLAlchemy is fairly safe
  from SQL Injection attacks).

  Hope that helps,

  Simon
 


--~--~-~--~~~---~--~~
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: how could a foreign key reference a unique (non pk) column combination?

2008-10-01 Thread alex bodnaru

i found it in alchemy:

ForeignKeyConstraint(['invoice_id', 'ref_num'],
['invoices.invoice_id', 'invoices.ref_num'])

posted on elixir list too, but expressing it in elixir would help a
lot, too :) .

thanks

On Wed, Oct 1, 2008 at 9:26 AM, alex bodnaru [EMAIL PROTECTED] wrote:
 hello friends,

 how could a foreign key reference a unique (but not primary kyey)
 column combination?


--~--~-~--~~~---~--~~
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] how could a foreign key reference a unique (non pk) column combination?

2008-10-01 Thread alex bodnaru

hello friends,

how could a foreign key reference a unique (but not primary kyey)
column combination?

--~--~-~--~~~---~--~~
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: multiple statements in a ddl construct

2008-09-10 Thread alex bodnaru

hi jason,

after a second thought, i have used your idea for data preloading. it is way
more pythonic and portable that ddl.

thanks again,
alex

On Mon, Sep 8, 2008 at 6:45 PM, jason kirtland [EMAIL PROTECTED] wrote:

 alex bodnaru wrote:
 hello friends,

 i wanted to do a few sql commands in a ddl construct, but i failed with:

 pysqlite2:dbapi2 warning: you can execute one statement at a time

 i'm not very familiar with python db layer, but i know sqlite may be invoked
 specifically to execute one, or many statements divided by ';', so i suspect
 it's specifically invoked for one statement.

 while this is a good security measure for sql from untrusted sources, like 
 user
 input, it's quite annoying for a situation where free sql should be
 specifically
 added.

 as for my case, i had a batch of inserts based on an external file,
 and i couldn't
 invoke ddl.execute_at in a loop, so i had to switch to inserting a
 batch of unioned
 selects in one insert, which was nice to learn :).

 The use case behind the DDL() construct is a single statement.  You can
 fire multiple statements by using multiple DDL()s.  But for inserts,
 I've found it more useful to write a 'after-create' event listener from
 scratch.  Here's one that I use in pretty much every project, in some
 form or another:

   def fixture(table, column_names, *rows):
   Insert data into table after creation.
   def onload(event, schema_item, connection):
   insert = table.insert()
   connection.execute(
   insert,
   [dict(zip(column_names, column_values))
for column_values in rows])
   table.append_ddl_listener('after-create', onload)

 Looks like this in use:

   fixture(some_table,
   ('x', 'y'),
   (1, 2),
   (3, 4),
   (5, 6))

 


--~--~-~--~~~---~--~~
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: multiple statements in a ddl construct

2008-09-09 Thread alex bodnaru

hi jason,

On Mon, Sep 8, 2008 at 6:45 PM, jason kirtland [EMAIL PROTECTED] wrote:

 alex bodnaru wrote:
 hello friends,

 i wanted to do a few sql commands in a ddl construct, but i failed with:

 pysqlite2:dbapi2 warning: you can execute one statement at a time

 i'm not very familiar with python db layer, but i know sqlite may be invoked
 specifically to execute one, or many statements divided by ';', so i suspect
 it's specifically invoked for one statement.

 while this is a good security measure for sql from untrusted sources, like 
 user
 input, it's quite annoying for a situation where free sql should be
 specifically
 added.

 as for my case, i had a batch of inserts based on an external file,
 and i couldn't
 invoke ddl.execute_at in a loop, so i had to switch to inserting a
 batch of unioned
 selects in one insert, which was nice to learn :).

 The use case behind the DDL() construct is a single statement.  You can
 fire multiple statements by using multiple DDL()s.  But for inserts,
 I've found it more useful to write a 'after-create' event listener from
 scratch.  Here's one that I use in pretty much every project, in some
 form or another:

   def fixture(table, column_names, *rows):
   Insert data into table after creation.
   def onload(event, schema_item, connection):
   insert = table.insert()
   connection.execute(
   insert,
   [dict(zip(column_names, column_values))
for column_values in rows])
   table.append_ddl_listener('after-create', onload)

 Looks like this in use:

   fixture(some_table,
   ('x', 'y'),
   (1, 2),
   (3, 4),
   (5, 6))


thanks for your idea. it looks cool. i understand this will be
triggered after all DDL end.

but i wanted to do arbitrary sql as DDL provides, and the insert was
just an example for a
series of statements.

just wondered why would this be the place to limit to one statement:
it isn't parsed by SA
in any way.

btw, my case is a generic ddl extension to elixir, made to be run
once. but i made it receive
a list of commands, and register each command in turn, and did the job.

best regards,
alex

 


--~--~-~--~~~---~--~~
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: multiple statements in a ddl construct

2008-09-09 Thread alex bodnaru

hi az,

thanks for commenting.

loading the whole (elixir) model to the (sqlite) db took about 3 seconds,
and it being done once anyway.
so jetflight performance was not a constraint ;) .

best regards,

alex

On Tue, Sep 9, 2008 at 9:53 AM,  [EMAIL PROTECTED] wrote:

 On Monday 08 September 2008 18:45:17 jason kirtland wrote:
 alex bodnaru wrote:
  hello friends,
 
  i wanted to do a few sql commands in a ddl construct, but i
  failed with:
 
  pysqlite2:dbapi2 warning: you can execute one statement at a time
 
  i'm not very familiar with python db layer, but i know sqlite may
  be invoked specifically to execute one, or many statements
  divided by ';', so i suspect it's specifically invoked for one
  statement.
 
  while this is a good security measure for sql from untrusted
  sources, like user input, it's quite annoying for a situation
  where free sql should be specifically
  added.
 
  as for my case, i had a batch of inserts based on an external
  file, and i couldn't
  invoke ddl.execute_at in a loop, so i had to switch to inserting
  a batch of unioned
  selects in one insert, which was nice to learn :).

 The use case behind the DDL() construct is a single statement.  You
 can fire multiple statements by using multiple DDL()s.  But for
 inserts, I've found it more useful to write a 'after-create' event
 listener from scratch.  Here's one that I use in pretty much every
 project, in some form or another:

def fixture(table, column_names, *rows):
Insert data into table after creation.
def onload(event, schema_item, connection):
insert = table.insert()
connection.execute(
insert,
[dict(zip(column_names, column_values))
 for column_values in rows])
table.append_ddl_listener('after-create', onload)

 Looks like this in use:

fixture(some_table,
('x', 'y'),
(1, 2),
(3, 4),
(5, 6))

 hmm.. interesting. how would u do an initial insert of batch of
 objects (orm-mapped to whatever entangled bunch of tables)? any
 possible optimization?
 for obj in objfactory(somedicts): sess.save(obj); sess.flush()
 isn't very fast thing...
 any needed gymnastics with the objects is possible (grouping by type
 or whatever)

 


--~--~-~--~~~---~--~~
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: multiple statements in a ddl construct

2008-09-09 Thread alex bodnaru

hi jason,

On Tue, Sep 9, 2008 at 9:59 PM, jason kirtland [EMAIL PROTECTED] wrote:

 alex bodnaru wrote:
 hi jason,

 On Mon, Sep 8, 2008 at 6:45 PM, jason kirtland [EMAIL PROTECTED] wrote:
 alex bodnaru wrote:
 hello friends,

 i wanted to do a few sql commands in a ddl construct, but i failed with:

 pysqlite2:dbapi2 warning: you can execute one statement at a time

 i'm not very familiar with python db layer, but i know sqlite may be 
 invoked
 specifically to execute one, or many statements divided by ';', so i 
 suspect
 it's specifically invoked for one statement.

 while this is a good security measure for sql from untrusted sources, like 
 user
 input, it's quite annoying for a situation where free sql should be
 specifically
 added.

 as for my case, i had a batch of inserts based on an external file,
 and i couldn't
 invoke ddl.execute_at in a loop, so i had to switch to inserting a
 batch of unioned
 selects in one insert, which was nice to learn :).
 The use case behind the DDL() construct is a single statement.  You can
 fire multiple statements by using multiple DDL()s.  But for inserts,
 I've found it more useful to write a 'after-create' event listener from
 scratch.  Here's one that I use in pretty much every project, in some
 form or another:

   def fixture(table, column_names, *rows):
   Insert data into table after creation.
   def onload(event, schema_item, connection):
   insert = table.insert()
   connection.execute(
   insert,
   [dict(zip(column_names, column_values))
for column_values in rows])
   table.append_ddl_listener('after-create', onload)

 Looks like this in use:

   fixture(some_table,
   ('x', 'y'),
   (1, 2),
   (3, 4),
   (5, 6))


 thanks for your idea. it looks cool. i understand this will be
 triggered after all DDL end.

 but i wanted to do arbitrary sql as DDL provides, and the insert was
 just an example for a
 series of statements.

 The DDL() function is just some sugar for the DDL event shown interface
 above.  If you want to perform more than one statement, the API is in
 place for any customization you'd like.

 just wondered why would this be the place to limit to one statement:
 it isn't parsed by SA
 in any way.

 SA doesn't put any limits on what SQL gets pushed through.  It's passed
 through directly to the DB-API execute() method.  I'd guess that most
 DB-API implementations will probably reject multiple statements in a
 single execution.

i really have no experience with pydb. but i know for sure that sqlite can
either work with one statement or with multiple ones, depending on the caller's
option.

alex
 


--~--~-~--~~~---~--~~
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] Fwd: before_insert is not being called, thus invalidating extensions in the spirit of acts_as_versioned

2008-08-31 Thread alex bodnaru

hello friends,

i notice that the before_insert method in an orm MapperExtension
derived class is not being called at all, thus invalidating these
extensions.

any idea of how could i proceed?

best regards,
alex

--~--~-~--~~~---~--~~
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: Fwd: before_insert is not being called, thus invalidating extensions in the spirit of acts_as_versioned

2008-08-31 Thread alex bodnaru

hi mike,

i found my fault: the before_insert was omitted while i inserted a
record via an insert statement, thus bypassing the orm.

thanks for your reply,

alex

On Mon, Sep 1, 2008 at 12:37 AM, Michael Bayer [EMAIL PROTECTED] wrote:


 On Aug 31, 2008, at 2:21 AM, alex bodnaru wrote:


 hello friends,

 i notice that the before_insert method in an orm MapperExtension
 derived class is not being called at all, thus invalidating these
 extensions.

 any idea of how could i proceed?

 provide a reproducible example of the failing usage in question to the
 list.  before_insert() is well tested and widely used.


 


--~--~-~--~~~---~--~~
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: access the fields in a record as a dict

2008-07-06 Thread alex bodnaru

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


hi ilya, everybody,

that time, i was using elixir and not the select() function in sa.
elixir.query.filter() returned a list of objects, with their fields as
attributes (same as the entity definition in elixir).

thus, to have each record transformed in a dict, i have used a transformation
function, and an iterator converter, like the following:

~def prep_record(record):
~values = {}
~for field in allfields: #a list of field names
~values[field] = getattr(record, field)

~records = itertools.imap(prep_record, query)

now i'm using sa 0.4.6, and when i'm executing a select() on a session, i'm
getting a resultproxy object, which may be iterated by rows, and each field of
each row may be got by row[fieldname]

hope this helps,

alex

zipito wrote:
| good day alex
|
|
| Did you find the solution for this ?
|
|
| Best regards,
| Ilya Dyohsin
|
| On 17 янв, 06:06, alex bodnaru [EMAIL PROTECTED] wrote:
| hi mike,
|
| thanks for your prompt answer.
|
| it doesn't work anymore, indeed :(
|
| alex
|
|
|
| Michael Bayer wrote:
|
| what, likedict(row) ?  that should workno ?
| On Jan 16, 2008, at 6:29 PM, alex bodnaru wrote:
| hi friends,
| in older sa i could cast a record to adict, in order to access their
| fields by their name, especially if the field name is not a valid
| python
| identifier, like a calculated or fixed numeric column.
| how could i do it again please?
| tia,
| alex
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBSHCg8dpwN1sq38njAQKIxAP/Y8eKEMm18qI12ZEtmw2nwq+z9HB8ykjY
g/w3ErQvfcOp3K9bFqL7/1MHgIIVATy636rQbe1F7wZYkR3NaQlKlkdVt8Z+YSxu
zmLeR4EL+q1CgnuJTsRh5+xRxqzdUZf4vEAFKipjGwrOvJT4EglY/CqUNx0AZpwP
LTQC456nCPQ=
=imB5
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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] register dml to be triggerred after create_all

2008-06-29 Thread alex bodnaru

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


hi friends,

i wish to insert some initial data in a few management tables (like applications
groups, roles etc).

is there a way to register dml to be done after create_all ends?

i'd specifically like it to happen after the entire ddl dust reaches the ground.

thanks in advance,

alex
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBSGeqaNpwN1sq38njAQI0LQP/ZVKlf0hibUVQAy24fd8JFKNaN6C0yVul
b104X2nm/5aVzC1/1oSdSkBLpK4G8EYBNEf/r8eIdPTUutBZMUm1zn04iSUF73Kj
0EaNYgyBjJrKTfGlrS0Yk8/uwKDPPdXoTsbKL2Xm/zITqcbEPdIMAk4HzKjXP3QY
uh3xq4MbRk8=
=JSlq
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: register dml to be triggerred after create_all

2008-06-29 Thread alex bodnaru

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


thanks a lot jason, now i see the metadata version of the same.

alex

jason kirtland wrote:
| alex bodnaru wrote:
| hi friends,
|
| i wish to insert some initial data in a few management tables (like 
applications
| groups, roles etc).
|
| is there a way to register dml to be done after create_all ends?
|
| i'd specifically like it to happen after the entire ddl dust reaches the 
ground.
|
| MetaData and Tables emit DDL events that you can listen for with
| .append_ddl_listener.
|
|
http://www.sqlalchemy.org/docs/04/sqlalchemy_schema.html#docstrings_sqlalchemy.schema_MetaData
|
| Here's an example insert-after-CREATE function from the SA test suite:
|
| def fixture(table, columns, *rows):
| Insert data into table after creation.
| def onload(event, schema_item, connection):
| insert = table.insert()
| column_names = [col.key for col in columns]
| connection.execute(insert,
|[dict(zip(column_names, column_values))
| for column_values in rows])
| table.append_ddl_listener('after-create', onload)
|
|
| |
|
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBSGgW8tpwN1sq38njAQKUsQP/UmbeNlPKzYGGAnjnk4/axjYtasO8HAUg
jRcRp57J9L0t0UFXE9Lyra66wywSM0fg80Q4ajEEcTQFyh8DOwwbuoJT55pQyV+e
BJ8lw379eCdVsHhdA/fFg/vIjZF96qFXHfCj6UnFrk9Gsk/mLWuWqUZPSd8dyS3M
yUeDOWzs5vI=
=7KPc
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: accessing fields by name

2008-06-25 Thread alex bodnaru

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


thanks werner, but i was asking about a generic query (not about one table)

alex

Werner F. Bruhin wrote:
| Alex,
|
| alex bodnaru wrote:
| -BEGIN PGP SIGNED MESSAGE-
| Hash: SHA1
|
|
| hello friends,
|
| as opposed to a table.query() that returns a list of records of that table, 
with
| fields accessible as record attributes, a select() statement returns a list 
of
| tuples with the values of the fields in the virtual record.
|
| i'd like to access the fields by their column name or label, at least the non
| calculated or labelled ones. it would suffice to be able to retrieve a list 
with
| the labels of the fields in the resulted tuples.
|
| could you point me in the right direction?
|
| No expert, so take this with a grain of salt.
|
| q = db.Quality.__table__.select()
| print q
| print dir(q)
| print q.columns
|
| q.columns is giving the column names as a list
|
| Werner
|
| |
|
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBSGIzI9pwN1sq38njAQKqoQP/VaLmQ87HFKc8At/iuMAk3PdWsJqBvOdi
HLveRI+FGZPEr/ICezW0YzVtXjTiAqPees5j/6PjMsoHeY4AEJKSTCpCBEwCQSdY
lcnyXrdg0cram1uhSItnLSyQslgQAPvAANQEv5AgJlh1garw/3O1h+yWi4kgqswO
mYAClwKrBxE=
=N3xj
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: accessing fields by name

2008-06-25 Thread alex bodnaru

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


thanks a lot,

it realy works :)

[EMAIL PROTECTED] wrote:
| AFAIK non-orm queries yield RowProxies, which are sort of ordered
| dicts, i.e. can be used as sequences or as dicts, keyed by
| column-name or by column-object itself.
|
| class RowProxy(object):
| Proxy a single cursor row for a parent ResultProxy.
|
| Mostly follows ordered dictionary behavior, mapping result
| values to the string-based column name, the integer position of
| the result in the row, as well as Column instances which can be
| mapped to the original Columns that produced this result set (for
| results that correspond to constructed SQL expressions).
| 
|
|
| On Wednesday 25 June 2008 13:01:11 alex bodnaru wrote:
| hello friends,
|
| as opposed to a table.query() that returns a list of records of
| that table, with fields accessible as record attributes, a select()
| statement returns a list of tuples with the values of the fields in
| the virtual record.
|
| i'd like to access the fields by their column name or label, at
| least the non calculated or labelled ones. it would suffice to be
| able to retrieve a list with the labels of the fields in the
| resulted tuples.
|
| could you point me in the right direction?
|
| thanks in advance,
| alex
|
| |
|
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBSGJC2NpwN1sq38njAQLk0gQAtG3y4MPPxVux6zFHYxaz+hpIHBHjAJkI
nuJPi+c+iAm58OSQPGZXfyXadzaoFgu+DAgLsx7MaL5bwOtjnEUsuRQ9cMgaWIWZ
b0cqJo7jXOuF39IglrEaLO3pNjl6mzkjHPkBXUO+KnybJxuCoazkwRC/moXV/kiN
e/CGoq1fMM0=
=OH0/
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: arbitrary information for sa objects

2008-05-05 Thread alex bodnaru


we were talking conceptually, of course :)

[EMAIL PROTECTED] wrote:
 IMvhO:
  -  table / columns are DB-side terms, relations - 
 sqlalchemy.orm.relation() - are not really. They are more ORM. 
 Foreign keys/Constraints are DB-side, yes. 
 But if annotate relations, then mappers should follow... as they talk 
 of mappers and then keys/joins.
 
 TO me, keeping the OO model in DB-side terms may not be the best 
 thing, as OO-side (mappers/props) may be different beast 
 alltogether - names / meanings / etc.
 On another hand, if model is wholly based on DB-side stuff, then its 
 not really the relations that has to be annotated, its something 
 lower... but i dont know what.
 
 ciao
 svilen
 
 On Sunday 04 May 2008 17:13:15 alex bodnaru wrote:
 
 hi paul,

 the relations should follow, indeed.

 thanks again,

 alex

 Paul Johnston wrote:
 Hi,



 http://www.sqlalchemy.org/docs/04/sqlalchemy_schema.html#docstrin
 gs_sqlalchemy.schema_Table shows info as a parameter in the kwargs
 to a table.


 So it does, so it's tables and columns. The column info setting
 is in the same page as you sent across, just a bit further up.

 What other objects would you like it for? I'm likely to have a
 requirement for it on relations pretty soon.

 Paul

 
 
  
 

--~--~-~--~~~---~--~~
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: arbitrary information for sa objects

2008-05-04 Thread alex bodnaru


hi paul,

the relations should follow, indeed.

thanks again,

alex

Paul Johnston wrote:
 Hi,
  
 
 
 http://www.sqlalchemy.org/docs/04/sqlalchemy_schema.html#docstrings_sqlalchemy.schema_Table
 shows info as a parameter in the kwargs to a table.
 
  
 So it does, so it's tables and columns. The column info setting is in 
 the same page as you sent across, just a bit further up.
  
 What other objects would you like it for? I'm likely to have a 
 requirement for it on relations pretty soon.
  
 Paul
 
  

--~--~-~--~~~---~--~~
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] arbitrary information for sa objects

2008-05-03 Thread alex bodnaru


hello friends,

however sa stands at the model foundation of an application, i'd be interested 
to add additional information to some columns/tables/keys.

is there a way to insert arbitrary information for sa objects?


thanks in advance,

alex

--~--~-~--~~~---~--~~
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: arbitrary information for sa objects

2008-05-03 Thread alex bodnaru


i read info is such a table option, but i'm not sure it's not deprecating?

alex bodnaru wrote:
 
 hello friends,
 
 however sa stands at the model foundation of an application, i'd be 
 interested 
 to add additional information to some columns/tables/keys.
 
 is there a way to insert arbitrary information for sa objects?
 
 
 thanks in advance,
 
 alex
 
  
 

--~--~-~--~~~---~--~~
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: arbitrary information for sa objects

2008-05-03 Thread alex bodnaru


hi paul,

thanks for your attention.

http://www.sqlalchemy.org/docs/04/sqlalchemy_schema.html#docstrings_sqlalchemy.schema_Table
 
shows info as a parameter in the kwargs to a table.

it would be great if there were info for other objects too. please point me to 
the column info setting.

best regards,

alex

Paul Johnston wrote:
 Alex,
  
 The info bucket is available just on columns at the moment, and it is 
 a supported feature. I think we're open to adding it to other types, 
 such as tables, if someone has a requirement.
  
 My desire for this was exactly the same as yours - the SA model serving 
 as the authoritative master definition.
  
 Paul
 
 On Sat, May 3, 2008 at 9:47 AM, alex bodnaru [EMAIL PROTECTED] 
 mailto:[EMAIL PROTECTED] wrote:
 
 
 
 i read info is such a table option, but i'm not sure it's not
 deprecating?
 
 alex bodnaru wrote:
  
   hello friends,
  
   however sa stands at the model foundation of an application, i'd
 be interested
   to add additional information to some columns/tables/keys.
  
   is there a way to insert arbitrary information for sa objects?
  
  
   thanks in advance,
  
   alex
  
   
  
 
 
  

--~--~-~--~~~---~--~~
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] listing a table's relationships

2008-03-26 Thread alex bodnaru


hello friends,

is there a way to query a table object of all the relationships it's involved 
with?

both onoe2many, many2one, many2many etc.

thanks in advance,

alex

--~--~-~--~~~---~--~~
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] the columns retrieved in a recordset

2008-01-19 Thread alex bodnaru

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


hi friends,

could i know the columns a select would retrieve, without examining the
first record retrieved?
or if no records matched the where.

tia ,

alex
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBR5Hxx9pwN1sq38njAQIkGQP/QtdYPK/58VHShiidSO9vVCACFQNNcVae
CbyRQjaqhUizKsUY5RDGCjVeaE+xoWQBQ3Xz+mjN4lufwKhw5Lz6AouLP/oNejNa
2gTFCJiQ8VErw+XgctJus2MVJK2W+u3xodVtcqMibc66A6H+PXW5vuJab2zMaoMU
RiPQ6KrDsZM=
=7tG3
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: the columns retrieved in a recordset

2008-01-19 Thread alex bodnaru

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


thanks for your answer.

i just wonder whether the * (all columns) is being expanded there.

alex

[EMAIL PROTECTED] wrote:
 theoreticaly, looking at the sql.expression.py/Select, try
for a in yourselect.inner_columns: print a
 it's a yielding property.
 
 alex bodnaru wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1


 hi friends,

 could i know the columns a select would retrieve, without examining the
 first record retrieved?
 or if no records matched the where.

 tia ,

 alex
 
  
 
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBR5JfrNpwN1sq38njAQJ+gwQAqkvp2a2+9y6lq0tOfiGr6KcXAZ78NJi0
YzMdMgpgFC7kRHbqEydDg1OW8O1i+FvW75fMvFZm1bqi10A7faJEqx8TUrBJOOdw
97oGDshxUEWlB9XB2+k1c32TPlIgQaBYdNaOPUDTuulyUullIFPbv9aYUvYSlm4I
pRws955+d1U=
=Fw/H
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: the columns retrieved in a recordset

2008-01-19 Thread alex bodnaru

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

thanks a lot, mike and sdobrev :)

Michael Bayer wrote:
 
 On Jan 19, 2008, at 4:50 PM, Michael Bayer wrote:
 
 result.keys()
 
 oh its a propresult.keys
 
  
 
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBR5J6B9pwN1sq38njAQKjjAQAtPM6Og2DB1lnnAgi1eh50LVdcQmC2M+P
lIaj+GGYFwf2z4phVi09mVBiieZtGvZhe+XwcUbhG5iou6b7AqoIh/zUu1gza63D
MbWnI2DmdpBAU1WTiVGg9i8IEjxAObWRtmbb6dgIfv/sRd1N4/eqszX0F6/1QnW0
asdgKwQ3z6s=
=lbwT
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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] access the fields in a record as a dict

2008-01-16 Thread alex bodnaru

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


hi friends,

in older sa i could cast a record to a dict, in order to access their
fields by their name, especially if the field name is not a valid python
identifier, like a calculated or fixed numeric column.

how could i do it again please?

tia,

alex
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBR46TPdpwN1sq38njAQKv7wQArF0nV0WRTZVI/3qdLC5+7yZDspw1bGhT
6H8vPFQKDZCsJNNP98nbV1zKjMC/OfypPOqJvS7T9SpD2XZ9G7LOYeAQpSakzNOO
DiJE/vY4SzX83cwfFj218EfzqtOeg0L010sIrkj9IG9ZETkXQjAG9iZIF/i3hujq
CoOV31EiB4k=
=bBud
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: access the fields in a record as a dict

2008-01-16 Thread alex bodnaru

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


hi mike,

thanks for your prompt answer.

it doesn't work anymore, indeed :(

alex

Michael Bayer wrote:
 
 what, like dict(row) ?  that should workno ?
 
 On Jan 16, 2008, at 6:29 PM, alex bodnaru wrote:
 
 
 hi friends,
 
 in older sa i could cast a record to a dict, in order to access their
 fields by their name, especially if the field name is not a valid  
 python
 identifier, like a calculated or fixed numeric column.
 
 how could i do it again please?
 
 tia,
 
 alex


 

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBR47GONpwN1sq38njAQKiKwP7BhcGfQIbqXRdoJRSyELSsuDlc8JCoa2W
qAsWBARQ8uRdmO/EhDglRN/K/60sMVVUWDbarLH8F/qerC4pwTOrZwQcKyRG/LPL
zIftKU9uNg/yS2Q6kmPSPsXbbA1Kjwe/JwbHm0LXPk15fB5vzwXk76F6ae1oDRAO
kgb7oQTIbOw=
=jmyV
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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] record as a dict

2008-01-02 Thread alex bodnaru

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


hi friends,

i'm missing the previously available option to cast a record to a dict,
or otherwise accessing it's fields by their names.

this would be very important for non identifier name compatible columns,
especially calculated ones.

what would be the way to get a dictionary of field:value for a record?

tia,

alex
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBR3wlC9pwN1sq38njAQI0EAQAlAlHQwIsPPW7edmNwyrbXhyaB22zdexO
RmxAsGqzPyAGQrpVW2IvLWwTTTAmD8DoFvmasuqQBjCQX7IBVPOYtVx59BuQTedy
IKyYGzxBDHc+nlM9DHdKIWOyduUH3ol2c6ZYDx20y7ODnNvF8PW94Nuui0/0+ZXQ
ptCL5giiaOU=
=PVhb
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: Database Referential Integrity Constraints Puzzle

2007-12-15 Thread alex bodnaru

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

hi jerryji,

this database is not normalized.

you may consider switching to:
things(thingid INTEGER, thing_weight etc.)
and
things_translations(thingid INTEGER, thing_name VARCHAR, language CHAR(5))

jerryji wrote:
 Dear Kind Soul,
 
 I am stuck with the following database referential integrity
 constraint problem.
 
 I have two tables:
 things(thingid INTEGER, thing_name VARCHAR, language CHAR(5))
 and
 thing_relations(thingid INTEGER, thing_parentid INTEGER)
 
 things hosts items in different languages, e.g.:
 things(1, 'car', 'en_US'); things(1, 'voiture', 'fr_FR');
 things(2, 'engine', 'en_US'); things(2, 'moteur', 'fr_FR');
 things(3, 'brake', 'en_US'); things(3, 'freins', 'fr_FR');
 
 while thing_relations describes the consists of relationship between
 things, e.g.:
 thing_relations(2, 1);
 thing_relations(3, 1)
 as engine and brake are parts of a car
 
 but since things(thingid) is not unique hence it can't be the primary
 key in things and can't be the foreign key in thing_relations, how
 can the referential integrity constraints between
 thing_relations(thingid) and things(thingid) be described? Or my
 design is not making sense?
 
 Many thanks in advance.
 
 Jerry
  
 
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBR2TRNNpwN1sq38njAQLJPgP/diPRHpnH7s/auHx/LTXF5Y2Hx7npdLc/
yLuhvjx6Qatm4eU8sASFLLcTEYv1EZsOMRNVaxBEq7Aq89DeSPGVjIl7iy4egjKv
rKIyCA4W5nhB37vFbdjMpd1fOmLiUqdtm/ObvSBxb6x3Hd3JDXYwcr86ve5j0XtT
hlMT5X2uG4g=
=WTdr
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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] migration deprecation?

2007-12-04 Thread alex bodnaru

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


hi friends,

i was using the table.c.keys() to enumerate the fields of a table. what
would be the 0.4 way to do it?

thanks in advance,

alex
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBR1YBe9pwN1sq38njAQL2rgQApP6SW0rI5k9Nn/TvYzq3da7WawHdklwl
mV4eDvzl9WB3r61g35DrdlAzgOr1uxQMsAvgS3ZDpzYjmP0/1xx/Hw2RUn97IbHH
p3b4ljz3Flp8K4h1x5fl95giI2CyqyI0uzn3fdFCHWpU4ZIoSps9REP0LtWdWfJV
GE7wldimiXo=
=CAkQ
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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: last_inserted_ids()

2007-07-09 Thread alex bodnaru

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


hi mike,

i have installed the 0.3.9 from svn, and now it's returning the primary
key values of the last inserted record, as documented, even if those are
not numeric.

thanks a lot!

though i'm on a well packaged debian system, i have a lib deirectory
ahead of PYTHONPATH for last minute functionality as this.

could i make the sqlalchemy subdirectory updateable by svn, or should i
re-egg the updated package after every significant change?

best regards an thanks again,

alex

Michael Bayer wrote:
 
 On Jul 8, 2007, at 2:59 PM, alex bodnaru wrote:
 
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1


 hello,

 i was following this thread with interest, and found that
 last_inserted_ids returns the oid of the inserted record.

 can i portably retrieve a record by this oid?

 
 no.  it does not return OID, it returns whatever was last inserted as  
 a primary key value.  in the case of mysql as well as sqlite tables  
 which have an integer primary key, its synonymous with OID on those  
 databases.  but this is an implementation detail of those particular  
 databases.
 
 
 
  
 
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBRpIwQNpwN1sq38njAQKbIQP+NCkq0Xog6fvhWg8tPlBasickCvliTwxA
QByk+ePDngGTcKfObBiwNolIf9sJ2/8p9zKI3vQ9dCBicGvPMjqfji3FalRC1Yl8
nP537siQGf6FYvfKhA9nhfp01tOuBdVEVrTQgAYvNB7VW3igb0ZwGqVluswScacw
LAxarfdJaEc=
=nmBF
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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] problem with whereclause

2007-07-09 Thread alex bodnaru

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


hi all,

i'm using sa 0.3.9 from svn for the new last_inserted_ids functionality.

after upgrading from official 0.3.8 i have encountered the following
problem:

since i'm calling a select statement using whereclause with bindparams,
its execution depends on a dictionary of fields to compare with.

in 0.3.8, only the bound fields would be considered in the whereclause,
while other keys in that dictionary were ignored. this is the behaviour
i understood will be in 0.4, instead of select_by.

in 0.3.9, all the field-value pairs in the execute dictionary are being
considered part of the where with checking for equality, with no reason.

a more severe form of this problem raises, where i wish to use an update
sentence with both where clause and values, receiving bindparam. then, i
definitely would use a dictionary in execute for values and where
conditions, according to their bindings, but i have only one dictionary
in execute.

best regards,

alex
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBRpLNZNpwN1sq38njAQL/IgQAlu1dKYK2sx6OfsuKwngW9t6/IlFVVyny
hmtR+IpyjgTQzzzagLBick5Gqvpn/LdJLUbY8HKy33To+VfgyMpBeWgxoR1qC9z2
kd1nbNVfZhBN7Eqm0G2LX+PR0/pkJrPNCPGVdKgY0c5obDTiirEPH/mTJBbycJAO
0zfAyXTj3ZY=
=QwRP
-END PGP SIGNATURE-

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