Re: [sqlalchemy] Re: Elixir question

2012-02-05 Thread Gaëtan de Menten

On 02/03/2012 12:08 PM, lars van gemerden wrote:

I should probably make the pair method:

def pair(name1, name2):
 p1, p2 = Pairs(name1), Pairs(name2)
 p1.other = p2
 p2.other = p1

On Feb 3, 11:57 am, lars van gemerdenl...@rational-it.com  wrote:

Hi, I am trying to sote pairs in a table as follows:

#-- 

from elixir import *

metadata.bind = sqlite:///:memory:
metadata.bind.echo = False

class Pairs(Entity):
 name = Field(String(50), primary_key = True)
 other = OneToOne('Pairs', inverse = 'other')
You can't have a OneToOne as inverse for a OneToOne, even less for 
itself. Valid relationship pairs are:


ManyToOne - OneToOne
ManyToOne - OneToMany
ManyToMany - ManyToMany

In your case you want:

class Pairs(Entity):
name = Field(String(50), primary_key = True)
other1 = ManyToOne('Pairs', inverse = 'other2')
other2 = OneToOne('Pairs', inverse = 'other1')

and if your database really only stores pairs, a property might make it 
more elegant:


@property
def other(self):
return self.other1 if self.other1 is not None else self.other2


As a side note, you probably do not want to use Elixir for a new 
project, as Elixir is not maintained anymore.


-G.

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

2012-02-05 Thread lars van gemerden
OK, thank you,

I went back to SQLA and came up with this for now (simplified):

class Pairs(Base):
__tablename__ = 'Pairs'
name = Column(String(20), primary_key=True)
other_name = Column(String(20), ForeignKey('Pairs.name'), nullable
= False)

other = relationship('Pairs',
  primaryjoin = 'Pairs.name ==
Pairs.other_name',
  remote_side=[name])
def __init__(self, name):
self.name = name
def __repr__(self):
return (%s, %s) % (self.name, self.other.name)

def pair(name1, name2):
p1, p2 = Pairs(name1), Pairs(name2)
p1.other_name = name2
p2.other_name = name1
return p1, p2

if __name__ == '__main__':

p1, p2 = pair('apple', 'pear')
session.add_all([p1, p2])
session.commit()
for p in session.query(Pairs).all():
print p
assert p1.other.other is p1
--
Note that there is no backref on other and that the primaryjoin is
completely written out (otherwise a got a mysterious (to me) error,
when using joined inheritance at the same time).

This solution is key to my datamodel. Does anyone see any drawbacks?

Cheers, Lars




On Feb 5, 10:50 am, Gaëtan de Menten gdemen...@gmail.com wrote:
 On 02/03/2012 12:08 PM, lars van gemerden wrote:







  I should probably make the pair method:

  def pair(name1, name2):
       p1, p2 = Pairs(name1), Pairs(name2)
       p1.other = p2
       p2.other = p1

  On Feb 3, 11:57 am, lars van gemerdenl...@rational-it.com  wrote:
  Hi, I am trying to sote pairs in a table as follows:

  #--
   
  from elixir import *

  metadata.bind = sqlite:///:memory:
  metadata.bind.echo = False

  class Pairs(Entity):
       name = Field(String(50), primary_key = True)
       other = OneToOne('Pairs', inverse = 'other')

 You can't have a OneToOne as inverse for a OneToOne, even less for
 itself. Valid relationship pairs are:

 ManyToOne - OneToOne
 ManyToOne - OneToMany
 ManyToMany - ManyToMany

 In your case you want:

 class Pairs(Entity):
      name = Field(String(50), primary_key = True)
      other1 = ManyToOne('Pairs', inverse = 'other2')
      other2 = OneToOne('Pairs', inverse = 'other1')

 and if your database really only stores pairs, a property might make it
 more elegant:

      @property
      def other(self):
          return self.other1 if self.other1 is not None else self.other2

 As a side note, you probably do not want to use Elixir for a new
 project, as Elixir is not maintained anymore.

 -G.

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

2012-02-05 Thread lars van gemerden
Sorry, scrap the remark about primaryjoin ... inheritance. INheritance
wasn't the problem.

On Feb 5, 1:27 pm, lars van gemerden l...@rational-it.com wrote:
 OK, thank you,

 I went back to SQLA and came up with this for now (simplified):
 
 class Pairs(Base):
     __tablename__ = 'Pairs'
     name = Column(String(20), primary_key=True)
     other_name = Column(String(20), ForeignKey('Pairs.name'), nullable
 = False)

     other = relationship('Pairs',
                           primaryjoin = 'Pairs.name ==
 Pairs.other_name',
                           remote_side=[name])
     def __init__(self, name):
         self.name = name
     def __repr__(self):
         return (%s, %s) % (self.name, self.other.name)

 def pair(name1, name2):
     p1, p2 = Pairs(name1), Pairs(name2)
     p1.other_name = name2
     p2.other_name = name1
     return p1, p2

 if __name__ == '__main__':

     p1, p2 = pair('apple', 'pear')
     session.add_all([p1, p2])
     session.commit()
     for p in session.query(Pairs).all():
         print p
     assert p1.other.other is p1
 --
 Note that there is no backref on other and that the primaryjoin is
 completely written out (otherwise a got a mysterious (to me) error,
 when using joined inheritance at the same time).

 This solution is key to my datamodel. Does anyone see any drawbacks?

 Cheers, Lars

 On Feb 5, 10:50 am, Gaëtan de Menten gdemen...@gmail.com wrote:







  On 02/03/2012 12:08 PM, lars van gemerden wrote:

   I should probably make the pair method:

   def pair(name1, name2):
        p1, p2 = Pairs(name1), Pairs(name2)
        p1.other = p2
        p2.other = p1

   On Feb 3, 11:57 am, lars van gemerdenl...@rational-it.com  wrote:
   Hi, I am trying to sote pairs in a table as follows:

   #--

   from elixir import *

   metadata.bind = sqlite:///:memory:
   metadata.bind.echo = False

   class Pairs(Entity):
        name = Field(String(50), primary_key = True)
        other = OneToOne('Pairs', inverse = 'other')

  You can't have a OneToOne as inverse for a OneToOne, even less for
  itself. Valid relationship pairs are:

  ManyToOne - OneToOne
  ManyToOne - OneToMany
  ManyToMany - ManyToMany

  In your case you want:

  class Pairs(Entity):
       name = Field(String(50), primary_key = True)
       other1 = ManyToOne('Pairs', inverse = 'other2')
       other2 = OneToOne('Pairs', inverse = 'other1')

  and if your database really only stores pairs, a property might make it
  more elegant:

       @property
       def other(self):
           return self.other1 if self.other1 is not None else self.other2

  As a side note, you probably do not want to use Elixir for a new
  project, as Elixir is not maintained anymore.

  -G.

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

2012-02-03 Thread lars van gemerden
I should probably make the pair method:

def pair(name1, name2):
p1, p2 = Pairs(name1), Pairs(name2)
p1.other = p2
p2.other = p1

On Feb 3, 11:57 am, lars van gemerden l...@rational-it.com wrote:
 Hi, I am trying to sote pairs in a table as follows:

 #-- 
 
 from elixir import *

 metadata.bind = sqlite:///:memory:
 metadata.bind.echo = False

 class Pairs(Entity):
     name = Field(String(50), primary_key = True)
     other = OneToOne('Pairs', inverse = 'other')

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

 def pair(name1, name2):
     p1, p2 = Pairs(name1), Pairs(name2)
     p1.other = p2

 if __name__ == '__main__':

     setup_all()
     create_all()

     pair('p1', 'p2')
 #-- 
 

 I am not very famiiar with SQL etc. but logically this seems possible
 (please orrect me if I am wrong). However I get the following error:
 
 File D:\Documents\Code\Eclipse\workspace\SQLAdata\src\tests.py, line
 22, in module
     setup_all()
   File build\bdist.win-amd64\egg\elixir\__init__.py, line 94, in
 setup_all

   File build\bdist.win-amd64\egg\elixir\entity.py, line 951, in
 setup_entities
   File build\bdist.win-amd64\egg\elixir\entity.py, line 198, in
 create_pk_cols
   File build\bdist.win-amd64\egg\elixir\entity.py, line 481, in
 call_builders
   File build\bdist.win-amd64\egg\elixir\relationships.py, line 448,
 in create_pk_cols
   File build\bdist.win-amd64\egg\elixir\relationships.py, line 791,
 in create_keys
   File build\bdist.win-amd64\egg\elixir\relationships.py, line 521,
 in inverse
 AssertionError: Relationships 'other' in entity 'Pair' and 'other' in
 entity 'Pair' cannot be inverse of each other because their types do
 not form a valid combination.
 

 Can anyone help me to understand the error and possibly fix it?

 Thanks in advance, Lars

-- 
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: Enum and accented characters (non-ASCII character)

2012-01-17 Thread Pierre Bossé
Thank you Michael for your answers, but

This does not work even with the UFT-8 encoding.

I changed my program with utf-8:
=
# -*- coding: utf-8 -*-

from elixir import *
from sqlalchemy import create_engine

class TestEnum(Entity):
using_options(tablename='TEST_ENUM')
myEnum = Field(Unicode(100),\
 Enum('avec é',
  u'avec è',
  u'avec à'),\
 colname='MY_ENUM')

if __name__ == '__main__':
metadata.bind = create_engine('oracle://..:..@..',
   encoding='utf-8', echo=True)

x = u'avec é'
print '=' * 20
print x.encode('utf-8')
print '=' * 20

setup_all()
drop_all()
create_all()

test = TestEnum()
test.id = 1

test.myEnum = u'avec é'
session.commit()

The execution log :
=

avec é

2012-01-17 07:10:03,375 INFO sqlalchemy.engine.base.Engine SELECT USER
FROM DUAL
2012-01-17 07:10:03,375 INFO sqlalchemy.engine.base.Engine {}
2012-01-17 07:10:03,375 INFO sqlalchemy.engine.base.Engine SELECT
table_name FROM all_tables WHERE table_name = :name AND owner
= :schema_name
2012-01-17 07:10:03,375 INFO sqlalchemy.engine.base.Engine {'name':
u'TEST_ENUM', 'schema_name': u'PBOSSE'}
2012-01-17 07:10:03,375 INFO sqlalchemy.engine.base.Engine
DROP TABLE TEST_ENUM
2012-01-17 07:10:03,375 INFO sqlalchemy.engine.base.Engine {}
2012-01-17 07:10:03,391 INFO sqlalchemy.engine.base.Engine COMMIT
2012-01-17 07:10:03,405 INFO sqlalchemy.engine.base.Engine SELECT
table_name FROM all_tables WHERE table_name = :name AND owner
= :schema_name
2012-01-17 07:10:03,405 INFO sqlalchemy.engine.base.Engine {'name':
u'TEST_ENUM', 'schema_name': u'PBOSSE'}
2012-01-17 07:10:03,405 INFO sqlalchemy.engine.base.Engine
CREATE TABLE TEST_ENUM (
id INTEGER NOT NULL,
MY_ENUM NVARCHAR2(100),
PRIMARY KEY (id),
CHECK (MY_ENUM IN ('avec é', 'avec è', 'avec à'))
)


2012-01-17 07:10:03,405 INFO sqlalchemy.engine.base.Engine {}
2012-01-17 07:10:03,453 INFO sqlalchemy.engine.base.Engine COMMIT
2012-01-17 07:10:03,453 INFO sqlalchemy.engine.base.Engine BEGIN
(implicit)
2012-01-17 07:10:03,453 INFO sqlalchemy.engine.base.Engine INSERT INTO
TEST_ENUM (id, MY_ENUM) VALUES (:id, :MY_ENUM)
2012-01-17 07:10:03,453 INFO sqlalchemy.engine.base.Engine {'MY_ENUM':
u'avec \xe9', 'id': 1}
2012-01-17 07:10:03,453 INFO sqlalchemy.engine.base.Engine ROLLBACK
Traceback (most recent call last):
  File E:\Data\!RefVec\dev\workspace\BdrsMD_Metadata\bdrs\models
\TestEnum.py, line 38, in module
session.commit()
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
py2.7.egg\sqlalchemy\orm\scoping.py, line 113, in do
return getattr(self.registry(), name)(*args, **kwargs)
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
py2.7.egg\sqlalchemy\orm\session.py, line 645, in commit
self.transaction.commit()
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
py2.7.egg\sqlalchemy\orm\session.py, line 313, in commit
self._prepare_impl()
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
py2.7.egg\sqlalchemy\orm\session.py, line 297, in _prepare_impl
self.session.flush()
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
py2.7.egg\sqlalchemy\orm\session.py, line 1547, in flush
self._flush(objects)
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
py2.7.egg\sqlalchemy\orm\session.py, line 1616, in _flush
flush_context.execute()
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
py2.7.egg\sqlalchemy\orm\unitofwork.py, line 328, in execute
rec.execute(self)
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
py2.7.egg\sqlalchemy\orm\unitofwork.py, line 472, in execute
uow
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
py2.7.egg\sqlalchemy\orm\mapper.py, line 2193, in _save_obj
execute(statement, multiparams)
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
py2.7.egg\sqlalchemy\engine\base.py, line 1399, in execute
params)
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
py2.7.egg\sqlalchemy\engine\base.py, line 1532, in
_execute_clauseelement
compiled_sql, distilled_params
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
py2.7.egg\sqlalchemy\engine\base.py, line 1640, in _execute_context
context)
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
py2.7.egg\sqlalchemy\engine\base.py, line 1633, in _execute_context
context)
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
py2.7.egg\sqlalchemy\engine\default.py, line 330, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (IntegrityError) ORA-02290: check
constraint (PBOSSE.SYS_C0017639) violated
 'INSERT 

Re: [sqlalchemy] Re: Elixir: Enum and accented characters (non-ASCII character)

2012-01-17 Thread Michael Bayer

On Jan 17, 2012, at 7:46 AM, Pierre Bossé wrote:

 Thank you Michael for your answers, but
 
 This does not work even with the UFT-8 encoding.
 
 2012-01-17 07:10:03,405 INFO sqlalchemy.engine.base.Engine
 CREATE TABLE TEST_ENUM (
   id INTEGER NOT NULL,
   MY_ENUM NVARCHAR2(100),
   PRIMARY KEY (id),
   CHECK (MY_ENUM IN ('avec é', 'avec è', 'avec à'))
 )

OK but very significantly, the behavior has changed.   SQLAlchemy is now 
sending in the correct DDL to Oracle.What remains is whether or not it gets 
to cx_oracle in the best way possible as well as if cx_oracle does the right 
thing with it.   We've had a very hard time getting cx_oracle/Oracle to 
understand fully unicode DDL expressions and it doesn't work completely.

At the very least you need to be on a recent cx_Oracle, 5.1 or later, and you 
need to ensure your NLS_LANG environment variable is set, such as 
NLS_LANG=AMERICAN.AMERICA.UTF8 though I guess you might need to adjust that for 
your locale.

Try that and I'll see if we can maybe make some more adjustments to the dialect 
for the most recent cx_Oracle versions, I notice that we're still encoding the 
DDL before we pass to cx_Oracle so maybe we can improve on that.






 
 
 2012-01-17 07:10:03,405 INFO sqlalchemy.engine.base.Engine {}
 2012-01-17 07:10:03,453 INFO sqlalchemy.engine.base.Engine COMMIT
 2012-01-17 07:10:03,453 INFO sqlalchemy.engine.base.Engine BEGIN
 (implicit)
 2012-01-17 07:10:03,453 INFO sqlalchemy.engine.base.Engine INSERT INTO
 TEST_ENUM (id, MY_ENUM) VALUES (:id, :MY_ENUM)
 2012-01-17 07:10:03,453 INFO sqlalchemy.engine.base.Engine {'MY_ENUM':
 u'avec \xe9', 'id': 1}
 2012-01-17 07:10:03,453 INFO sqlalchemy.engine.base.Engine ROLLBACK
 Traceback (most recent call last):
  File E:\Data\!RefVec\dev\workspace\BdrsMD_Metadata\bdrs\models
 \TestEnum.py, line 38, in module
session.commit()
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
 py2.7.egg\sqlalchemy\orm\scoping.py, line 113, in do
return getattr(self.registry(), name)(*args, **kwargs)
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
 py2.7.egg\sqlalchemy\orm\session.py, line 645, in commit
self.transaction.commit()
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
 py2.7.egg\sqlalchemy\orm\session.py, line 313, in commit
self._prepare_impl()
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
 py2.7.egg\sqlalchemy\orm\session.py, line 297, in _prepare_impl
self.session.flush()
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
 py2.7.egg\sqlalchemy\orm\session.py, line 1547, in flush
self._flush(objects)
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
 py2.7.egg\sqlalchemy\orm\session.py, line 1616, in _flush
flush_context.execute()
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
 py2.7.egg\sqlalchemy\orm\unitofwork.py, line 328, in execute
rec.execute(self)
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
 py2.7.egg\sqlalchemy\orm\unitofwork.py, line 472, in execute
uow
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
 py2.7.egg\sqlalchemy\orm\mapper.py, line 2193, in _save_obj
execute(statement, multiparams)
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
 py2.7.egg\sqlalchemy\engine\base.py, line 1399, in execute
params)
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
 py2.7.egg\sqlalchemy\engine\base.py, line 1532, in
 _execute_clauseelement
compiled_sql, distilled_params
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
 py2.7.egg\sqlalchemy\engine\base.py, line 1640, in _execute_context
context)
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
 py2.7.egg\sqlalchemy\engine\base.py, line 1633, in _execute_context
context)
  File C:\Program Files\Python27\lib\site-packages\sqlalchemy-0.7.3-
 py2.7.egg\sqlalchemy\engine\default.py, line 330, in do_execute
cursor.execute(statement, parameters)
 sqlalchemy.exc.IntegrityError: (IntegrityError) ORA-02290: check
 constraint (PBOSSE.SYS_C0017639) violated
 'INSERT INTO TEST_ENUM (id, MY_ENUM) VALUES
 (:id, :MY_ENUM)' {'MY_ENUM': u'avec \xe9', 'id': 1}
 
 The contraint in the Oracle DB is recorded as follows:
 MY_ENUM IN ('avec é', 'avec è', 'avec à ')
 It is normal that it does not work.
 =
 
 If I do not add value domain constraint (Enum), adding to the database
 and is non-ACII are preserved.
 
 The program without Enum :
 =
 # -*- coding: utf-8 -*-
 
 from elixir import *
 from sqlalchemy import create_engine
 
 class TestEnum(Entity):
using_options(tablename='TEST_ENUM')
 #myEnum = Field(Unicode(100),\
 # Enum('avec é',
 #  u'avec è',
 #  u'avec à'),\
 # colname='MY_ENUM')

Re: [sqlalchemy] Re: Elixir: Enum and accented characters (non-ASCII character)

2012-01-17 Thread Michael Bayer

On Jan 17, 2012, at 12:29 PM, Michael Bayer wrote:

 
 OK but very significantly, the behavior has changed.   SQLAlchemy is now 
 sending in the correct DDL to Oracle.What remains is whether or not it 
 gets to cx_oracle in the best way possible as well as if cx_oracle does the 
 right thing with it.   We've had a very hard time getting cx_oracle/Oracle to 
 understand fully unicode DDL expressions and it doesn't work completely.
 
 At the very least you need to be on a recent cx_Oracle, 5.1 or later, and you 
 need to ensure your NLS_LANG environment variable is set, such as 
 NLS_LANG=AMERICAN.AMERICA.UTF8 though I guess you might need to adjust that 
 for your locale.
 
 Try that and I'll see if we can maybe make some more adjustments to the 
 dialect for the most recent cx_Oracle versions, I notice that we're still 
 encoding the DDL before we pass to cx_Oracle so maybe we can improve on that.

It's all working for me:

NLS_LANG=AMERICAN_AMERICA.UTF8
cx_Oracle 5.1.1

script, tests creating the constraint, inserting, selecting, matching on the 
column:

# -*- coding: utf-8 -*-

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

Base= declarative_base()

class Foo(Base):
__tablename__ = 'foo'
id = Column(Integer, primary_key=True)

value = Column(Unicode(100),
Enum(u'avec é',
 u'avec è',
 u'avec à')
)

e = create_engine(oracle://scott:tiger@/xe, echo=True)
Base.metadata.drop_all(e)
Base.metadata.create_all(e)

s = Session(e)

s.add(Foo(id=1, value=u'avec è'))
s.commit()
s.close()

f = s.query(Foo).filter(Foo.value==u'avec è').first()
assert f.value == u'avec è'

output:

2012-01-17 17:55:49,916 INFO sqlalchemy.engine.base.Engine SELECT USER FROM DUAL
2012-01-17 17:55:49,917 INFO sqlalchemy.engine.base.Engine {}
2012-01-17 17:55:49,922 INFO sqlalchemy.engine.base.Engine SELECT table_name 
FROM all_tables WHERE table_name = :name AND owner = :schema_name
2012-01-17 17:55:49,922 INFO sqlalchemy.engine.base.Engine {'name': u'FOO', 
'schema_name': u'SCOTT'}
2012-01-17 17:55:49,928 INFO sqlalchemy.engine.base.Engine 
DROP TABLE foo
2012-01-17 17:55:49,928 INFO sqlalchemy.engine.base.Engine {}
2012-01-17 17:55:49,963 INFO sqlalchemy.engine.base.Engine COMMIT
2012-01-17 17:55:49,965 INFO sqlalchemy.engine.base.Engine SELECT table_name 
FROM all_tables WHERE table_name = :name AND owner = :schema_name
2012-01-17 17:55:49,965 INFO sqlalchemy.engine.base.Engine {'name': u'FOO', 
'schema_name': u'SCOTT'}
2012-01-17 17:55:49,970 INFO sqlalchemy.engine.base.Engine 
CREATE TABLE foo (
id INTEGER NOT NULL, 
value NVARCHAR2(100), 
PRIMARY KEY (id), 
CHECK (value IN ('avec é', 'avec è', 'avec à'))
)


2012-01-17 17:55:49,970 INFO sqlalchemy.engine.base.Engine {}
2012-01-17 17:55:50,131 INFO sqlalchemy.engine.base.Engine COMMIT
2012-01-17 17:55:50,133 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
2012-01-17 17:55:50,134 INFO sqlalchemy.engine.base.Engine INSERT INTO foo (id, 
value) VALUES (:id, :value)
2012-01-17 17:55:50,134 INFO sqlalchemy.engine.base.Engine {'id': 1, 'value': 
u'avec \xe8'}
2012-01-17 17:55:50,137 INFO sqlalchemy.engine.base.Engine COMMIT
2012-01-17 17:55:50,139 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
2012-01-17 17:55:50,141 INFO sqlalchemy.engine.base.Engine SELECT foo_id, 
foo_value 
FROM (SELECT foo.id AS foo_id, foo.value AS foo_value 
FROM foo 
WHERE foo.value = :value_1) 
WHERE ROWNUM = :ROWNUM_1
2012-01-17 17:55:50,141 INFO sqlalchemy.engine.base.Engine {'ROWNUM_1': 1, 
'value_1': u'avec \xe8'}



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

[sqlalchemy] Re: Elixir 0.6.1 released!

2008-08-19 Thread Jorge Vargas

On Mon, Aug 18, 2008 at 11:37 PM, Jose Galvez [EMAIL PROTECTED] wrote:

 I'm not trying to be an ass, but what are the advantages to using Elixer

well you did sound like one :)

the first thing is that declarative is very new to SA (0.4.something,
and only mainstream in 0.5), while elixir has been around since
SA0.2(?)
next elixir is more featurefull than declarative, for instance it
provides you the ability to build custom relationships [1] there was a
really nice example somewhere but I can't find it, maybe it's on the
video.
the other nice feature is giving you a more OOP-ish api, with elixir
you can almost forget you are storing to tables.
last but not least, you have some nice magic that will take care of your tables
Also I believe there is some subclassing/inheritance goodies

That said I'm not the best person to answer this because I'm not a
heavy elixir user, I just wanted to point out it has a purpose, and if
it seems to overlap with SA is because something new was develop and
not the other way around. In fact declarative is an extension
distributed with SA, not a core feature and it was added so people
(including me) stop complaining about how verbose simple projects
where [2], on the other hand elixir is an implementation of Active
Record and beyond.

[1] http://elixir.ematia.de/apidocs/elixir.relationships.html
[2] 
http://groups.google.com/group/sqlalchemy/browse_thread/thread/817097f376fc808b/2e9ac8e83df54090


 Gaetan de Menten wrote:
 I am very pleased to announce that version 0.6.1 of Elixir
 (http://elixir.ematia.de) is now available. As always, feedback is
 very welcome, preferably on Elixir mailing list.

 This is a minor release featuring some bug fixes (one of them to
 handle a late rename in SQLAlchemy's 0.5 beta cycle), a new, slighty
 nicer, syntax for providing custom arguments to the column(s) needed
 for ManyToOne relationships and some exception messages improvements.

 The full list of changes can be seen at:
 http://elixir.ematia.de/trac/browser/elixir/tags/0.6.1/CHANGES

 What is Elixir?
 -

 Elixir is a declarative layer on top of the SQLAlchemy library. It is
 a fairly thin wrapper, which provides the ability to create simple
 Python classes that map directly to relational database tables (this
 pattern is often referred to as the Active Record design pattern),
 providing many of the benefits of traditional databases without losing
 the convenience of Python objects.

 Elixir is intended to replace the ActiveMapper SQLAlchemy extension,
 and the TurboEntity project but does not intend to replace
 SQLAlchemy's core features, and instead focuses on providing a simpler
 syntax for defining model objects when you do not need the full
 expressiveness of SQLAlchemy's manual mapper definitions.

 Mailing list
 

 http://groups.google.com/group/sqlelixir/about



 


--~--~-~--~~~---~--~~
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: Elixir 0.6.1 released!

2008-08-19 Thread Jose Galvez
Thanks for the info, I guess I didn't realize declarative was added so 
recently, its been a while since I actually looked at the SA docs (which 
is where I found it).  But you do make some good points about Elixer, 
I'll have to give it another look, because I do find the way that SA 
defines relationships to be difficult at times
Jose

Jorge Vargas wrote:
 On Mon, Aug 18, 2008 at 11:37 PM, Jose Galvez [EMAIL PROTECTED] wrote:
   
 I'm not trying to be an ass, but what are the advantages to using Elixer
 

 well you did sound like one :)

 the first thing is that declarative is very new to SA (0.4.something,
 and only mainstream in 0.5), while elixir has been around since
 SA0.2(?)
 next elixir is more featurefull than declarative, for instance it
 provides you the ability to build custom relationships [1] there was a
 really nice example somewhere but I can't find it, maybe it's on the
 video.
 the other nice feature is giving you a more OOP-ish api, with elixir
 you can almost forget you are storing to tables.
 last but not least, you have some nice magic that will take care of your 
 tables
 Also I believe there is some subclassing/inheritance goodies

 That said I'm not the best person to answer this because I'm not a
 heavy elixir user, I just wanted to point out it has a purpose, and if
 it seems to overlap with SA is because something new was develop and
 not the other way around. In fact declarative is an extension
 distributed with SA, not a core feature and it was added so people
 (including me) stop complaining about how verbose simple projects
 where [2], on the other hand elixir is an implementation of Active
 Record and beyond.

 [1] http://elixir.ematia.de/apidocs/elixir.relationships.html
 [2] 
 http://groups.google.com/group/sqlalchemy/browse_thread/thread/817097f376fc808b/2e9ac8e83df54090

   
 Gaetan de Menten wrote:
 
 I am very pleased to announce that version 0.6.1 of Elixir
 (http://elixir.ematia.de) is now available. As always, feedback is
 very welcome, preferably on Elixir mailing list.

 This is a minor release featuring some bug fixes (one of them to
 handle a late rename in SQLAlchemy's 0.5 beta cycle), a new, slighty
 nicer, syntax for providing custom arguments to the column(s) needed
 for ManyToOne relationships and some exception messages improvements.

 The full list of changes can be seen at:
 http://elixir.ematia.de/trac/browser/elixir/tags/0.6.1/CHANGES

 What is Elixir?
 -

 Elixir is a declarative layer on top of the SQLAlchemy library. It is
 a fairly thin wrapper, which provides the ability to create simple
 Python classes that map directly to relational database tables (this
 pattern is often referred to as the Active Record design pattern),
 providing many of the benefits of traditional databases without losing
 the convenience of Python objects.

 Elixir is intended to replace the ActiveMapper SQLAlchemy extension,
 and the TurboEntity project but does not intend to replace
 SQLAlchemy's core features, and instead focuses on providing a simpler
 syntax for defining model objects when you do not need the full
 expressiveness of SQLAlchemy's manual mapper definitions.

 Mailing list
 

 http://groups.google.com/group/sqlelixir/about


   

 

   

--~--~-~--~~~---~--~~
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: Elixir 0.6.1 released!

2008-08-18 Thread Jose Galvez

I'm not trying to be an ass, but what are the advantages to using Elixer 
over using the declarative syntax such as:
from sqlalchemy import *
from sqlalchemy.orm import relation, scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base


dbe = create_engine(somedatabaseconnectionstring)

session = scoped_session(sessionmaker(bind=dbe))


mapper = session.mapper
meta = MetaData(bind=dbe)

Base = declarative_base(mapper=mapper)


class People(Base):
__table__ = Table('people', meta, autoload=True)
   
def __repr__(self):
return 'user: %s %s' % (self.fname, self.lname)

print 'first get everyone in the database'
people = People.query()
for p in people:
print p

Jose

Gaetan de Menten wrote:
 I am very pleased to announce that version 0.6.1 of Elixir
 (http://elixir.ematia.de) is now available. As always, feedback is
 very welcome, preferably on Elixir mailing list.

 This is a minor release featuring some bug fixes (one of them to
 handle a late rename in SQLAlchemy's 0.5 beta cycle), a new, slighty
 nicer, syntax for providing custom arguments to the column(s) needed
 for ManyToOne relationships and some exception messages improvements.

 The full list of changes can be seen at:
 http://elixir.ematia.de/trac/browser/elixir/tags/0.6.1/CHANGES

 What is Elixir?
 -

 Elixir is a declarative layer on top of the SQLAlchemy library. It is
 a fairly thin wrapper, which provides the ability to create simple
 Python classes that map directly to relational database tables (this
 pattern is often referred to as the Active Record design pattern),
 providing many of the benefits of traditional databases without losing
 the convenience of Python objects.

 Elixir is intended to replace the ActiveMapper SQLAlchemy extension,
 and the TurboEntity project but does not intend to replace
 SQLAlchemy's core features, and instead focuses on providing a simpler
 syntax for defining model objects when you do not need the full
 expressiveness of SQLAlchemy's manual mapper definitions.

 Mailing list
 

 http://groups.google.com/group/sqlelixir/about

   

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

2007-09-21 Thread Gaetan de Menten

On 9/20/07, Christine [EMAIL PROTECTED] wrote:

 Any elixir fans? Any idea on when it will finally be made an
 extension? Let me know.

Not sure. I'd like to answer: When it's ready. But ven when it'll be
ready, this might not happen. There would be some positive points to
that, but also some negative ones, so I guess we'll have to discuss
this with the community for more insight on that issue.

 PS: Here's a decent resource I like http://elixir.ematia.de/

This is the official Elixir website... ;-)

-- 
Gaëtan de Menten
http://openhex.org

--~--~-~--~~~---~--~~
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: Elixir performance

2007-09-06 Thread Gaetan de Menten

On 9/5/07, Paul Johnston [EMAIL PROTECTED] wrote:

 data.  I did some benchmarks a while back to see how everything
 stacked up as I was wondering if I was doing everything the hard way
 (in C++) instead of using SqlAlchemy, etc.  TurboEntity is the same as
 
 
 Great work Eric.

 I am quite surprised at the results. I would have thought
 ActiveMapper/TurboEntity would only be marginally slower than plain
 SQLAlchemy.

To make this really clear (even though Michael said it already),
ActiveMapper, TurboEntity and Elixir are not any slower than SA ORM.
What is slower is SA ORM compared to SA SQL layer. In fact, Elixir
querying system *is* SQLAlchemy proper.

-- 
Gaëtan de Menten
http://openhex.org

--~--~-~--~~~---~--~~
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: Elixir performance

2007-09-06 Thread Michael Bayer

since performance is the hot topic these days, I thought Id note that  
I've made some ORM improvements in the current SQLAlchemy trunk.   We  
have a profiling test that loads 10 objects each with 50 child  
objects, eagerly loaded across 500 rows.  Version 0.3.10 uses 70040  
function calls, 0.4beta5 uses 53173, and trunk uses 37403.   beta6  
should feel pretty quick.


On Sep 6, 2007, at 3:11 AM, Gaetan de Menten wrote:


 On 9/5/07, Paul Johnston [EMAIL PROTECTED] wrote:

 data.  I did some benchmarks a while back to see how everything
 stacked up as I was wondering if I was doing everything the hard way
 (in C++) instead of using SqlAlchemy, etc.  TurboEntity is the  
 same as


 Great work Eric.

 I am quite surprised at the results. I would have thought
 ActiveMapper/TurboEntity would only be marginally slower than plain
 SQLAlchemy.

 To make this really clear (even though Michael said it already),
 ActiveMapper, TurboEntity and Elixir are not any slower than SA ORM.
 What is slower is SA ORM compared to SA SQL layer. In fact, Elixir
 querying system *is* SQLAlchemy proper.

 -- 
 Gaëtan de Menten
 http://openhex.org

 


--~--~-~--~~~---~--~~
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: Elixir performance

2007-09-06 Thread EricHolmberg

 I am quite surprised at the results. I would have thought
 ActiveMapper/TurboEntity would only be marginally slower than plain
 SQLAlchemy. And again, I'm surprised that SA is faster than MySQLdb. How
 does that work out? I though SA used MySQLdb??? Your use of query cache
 and best of three sounds sensible, but I've got a feeling we're seeing
 some kind of measurement effect in the results.

I think SA is caching the results of the queries, so it has less
processing to do than MySQLdb for the repeat queries.


 If those numbers are correct though, I'd expect fairly simple changes to
 Elixir could bring the performance close to plain SA.


I think that's a reasonable assumption - I haven't had a chance to
poke around under the hood due to other priorities, but I like Elixir
and hope to see it improve in future versions.


--~--~-~--~~~---~--~~
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: Elixir performance

2007-09-05 Thread Paul Johnston

Hi,

data.  I did some benchmarks a while back to see how everything
stacked up as I was wondering if I was doing everything the hard way
(in C++) instead of using SqlAlchemy, etc.  TurboEntity is the same as
  

Great work Eric.

I am quite surprised at the results. I would have thought 
ActiveMapper/TurboEntity would only be marginally slower than plain 
SQLAlchemy. And again, I'm surprised that SA is faster than MySQLdb. How 
does that work out? I though SA used MySQLdb??? Your use of query cache 
and best of three sounds sensible, but I've got a feeling we're seeing 
some kind of measurement effect in the results.

If those numbers are correct though, I'd expect fairly simple changes to 
Elixir could bring the performance close to plain SA.

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: Elixir performance

2007-09-04 Thread Gaetan de Menten

On 9/4/07, Acm [EMAIL PROTECTED] wrote:

 I am trying out Elixir 0.3.0 over SQLAlchemy 0.3.10 in a Python 2.5
 environment.

 Are there any known performance issues with Elixir for CRUD (Create
 Select Update Delete) commands?

Not that I know of. There shouldn't be any overhead (over raw
SQLAlchemy) after the initial class initialization phase.

-- 
Gaëtan de Menten
http://openhex.org

--~--~-~--~~~---~--~~
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: elixir, sqlalchemy myqldb: Error connectiong to local socket

2007-05-09 Thread King Simon-NFHD78

Pirkka wrote:
 
 I started migrating from ActiveMapper to Elixir, and have been
 wrestling with this for hours:
 
 DBAPIError: (Connection failed) (OperationalError) (2005, Unknown
 MySQL server host '/Applications/MAMP/tmp/mysql/mysql.sock' (1))
 
 Here are the command parameters that sqlalchemy is using to open the
 connection:
 
 {'passwd': 'root', 'host': '/Applications/MAMP/tmp/mysql/mysql.sock',
 'db': 'django', 'user': 'root', 'client_flag': 2}
 
 I have no problem connecting to the above sock file using Django or
 mysql command line client with -S parameter. Any ideas what could
 cause the connection to fail?
 
 Yours,
 Pirkka

I think your 'host' parameter should be 'localhost', and you should pass
an extra parameter 'unix_socket' that contains the path to the socket
file.

If you are specifying it as a URI, it should look something like this:

mysql://root:[EMAIL PROTECTED]/django?unix_socket=/Applications/MAMP/tmp/my
sql/mysql.sock

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