Re: [sqlalchemy] How do you do an update with a session?

2010-03-07 Thread anusha kadambala
hai,

We used the session for update like this

result = Session.query(User).filter(User.id == '1').first()
if result != None:
result.name = 'Shadow'
result.address = 'foo'
Session.commit()

Where id,name and address are columns of my class and table.
I hope this solution will help u out.
On Mon, Mar 8, 2010 at 10:17 AM, TheShadow theshad...@gmail.com wrote:

 version: 0.6beta1

 I'm just trying to update a row in a table but can't figure out what
 the heck is the problem. I'm attempting the following:

 session.execute(
warehouse.session().query(WarehouseFile)\
  .filter(WarehouseFile.warehouse_file_id == file_id)\
  .update(values={'WarehouseFile.status' : 'Failed'})

 And get the error:

 qlalchemy.exc.ProgrammingError: (ProgrammingError) (1064, You have an
 error in your SQL syntax; check the manual that corresponds to your
 MySQL server version for the right syntax to use near 'WHERE
 warehouse_file.warehouse_file_id = '38'' at line 1) 'UPDATE
 warehouse_file SET  WHERE warehouse_file.warehouse_file_id = %s' ['38']

 --
 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.comsqlalchemy%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.




-- 


Njoy the share of Freedom :)
Anusha Kadambala

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



[sqlalchemy] cursor description

2010-02-18 Thread anusha kadambala
hello,

I want to know how to find the cursor description i.e equivalent to
cursor.description in dbapi.I also want to know whether it is supported in
all types of databases?

-- 


Njoy the share of Freedom :)
Anusha Kadambala

-- 
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] Re: unable to understand this error

2010-02-17 Thread anusha kadambala
hi werner,

Thanks for the help.It is working fine now.

On Tue, Feb 16, 2010 at 9:11 PM, werner wbru...@free.fr wrote:

 On 16/02/2010 15:48, Krishnakant Mane wrote:

 On Tuesday 16 February 2010 07:01 PM, avdd wrote:

  Now the specific problem you see is that the ORM uses the declared
 ForeignKeys to determine how to join tables for a relation, but on
 your Detail table you have two foreign keys back to account and the
 ORM doesn't know which one to use.

  Even I have the same problem.
 If one table has 2 columns as foreign keys which refer back to one column
 in the parent table, how do we sort this problem out?

  I did it like this:
 class Recipeit(Base):
__table__ = sa.Table(u'recipeit', metadata,
sa.Column(u'recipeitid', sa.Integer(),
 sa.Sequence('gen_recipeit_recipeitid'), primary_key=True, nullable=False),
 ...
sa.Column(u'fk_recipeid', sa.Integer(),
 sa.ForeignKey(u'recipe.recipeid'), nullable=False),
sa.Column(u'ot_fk_recipeid', sa.Integer(),
 sa.ForeignKey(u'recipe.recipeid')),
 ...
)

recipe = sao.relation(Recipe, primaryjoin=
('Recipeit.fk_recipeid==Recipe.recipeid'))
ot_recipe = sao.relation(Recipe, primaryjoin=
('Recipeit.ot_fk_recipeid==Recipe.recipeid'))

 Werner


 --
 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.comsqlalchemy%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.




-- 


Njoy the share of Freedom :)
Anusha Kadambala

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



[sqlalchemy] unable to understand this error

2010-02-16 Thread anusha kadambala
/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/query.py,
line 100, in _set_entities
self._setup_aliasizers(self._entities)
  File
/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/query.py,
line 114, in _setup_aliasizers
mapper, selectable, is_aliased_class = _entity_info(entity)
  File
/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/util.py,
line 512, in _entity_info
mapper = mapper.compile()
  File
/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/mapper.py,
line 696, in compile
mapper._post_configure_properties()
  File
/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/mapper.py,
line 725, in _post_configure_properties
prop.init()
  File
/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/interfaces.py,
line 484, in init
self.do_init()
  File
/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/properties.py,
line 735, in do_init
self._determine_joins()
  File
/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/properties.py,
line 826, in _determine_joins
many-to-many relation, 'secondaryjoin' is needed as well. % (self))
sqlalchemy.exc.ArgumentError: Could not determine join condition between
parent/child tables on relation DebitnoteDetails.account.  Specify a
'primaryjoin' expression.  If this is a many-to-many relation,
'secondaryjoin' is needed as well.


-- 

Thanks in advance


Njoy the share of Freedom :)
Anusha Kadambala

-- 
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] Re: unable to understand this error

2010-02-16 Thread anusha kadambala
hi avdd,

On Tue, Feb 16, 2010 at 7:01 PM, avdd adr...@gmail.com wrote:

 Hi anusha,

 The error is unrelated to your Login query because sqlalchemy compiles
 the mappers as late as possible.  It might help if you put somewhere
 in your application code, after you have imported all your entities,
 the lines:

  from sqlalchemy import orm
  orm.compile_mappers()

 to catch these sorts of errors early.


Thank you for clarify this error.


 Now the specific problem you see is that the ORM uses the declared
 ForeignKeys to determine how to join tables for a relation, but on
 your Detail table you have two foreign keys back to account and the
 ORM doesn't know which one to use.


But i want to foreign keys as per my requirement. So what i need to do to
solve this issue? Is it possible to do it with ORM or not?


 On Feb 16, 9:49 pm, anusha kadambala anusha.kadamb...@gmail.com
 wrote:
  hello all,
 
  My tables are giving following error at the time of querying. The tables
 got
  created properly but when i query on some table it is showing error on
 other
  tables.I didnt understand whats the issue here. I am querying on login
 table
  it is giving error on debitnote details tables.
 
  Tables:
  **
  class Login(Base):
  __tablename__ = 'login'
  usercode = Column(Integer,primary_key=True)
  username = Column(Text)
  userpassword = Column(Text)
  userrole = Column(Text)
 
  def __init__(self,username,userpassword,userrole):
  self.username = username
  self.userpassword = userpassword
  self.userrole = userrole
 
  login_table = Login.__table__
 
  class Account(Base):
  __tablename__ = account
  accountcode =  Column(Integer, primary_key = True)
  groupcode = Column(Integer, ForeignKey(groups.groupcode), nullable
 =
  False)
  groups = relation(Groups, backref = backref(Account, order_by =
  accountcode))
  accountname = Column(Text, nullable = False)
  basedon = Column(Text)
  accountdesc  = Column(Text)
  openingbalance = Column(Numeric(13,2))
  openingdate = Column(TIMESTAMP)
  initialbalance = Column(Numeric(13,2))
 
  def
 
 __init__(self,groupcode,groups,accountname,basedon,accountdesc,openingbalance,openingdate,initialbalance):
  self.groupcode = groupcode
  self.groups = groups
  self.accountname = accountname
  self.basedon = basedon
  self.accountdesc = accountdesc
  self.openingbalance = openingbalance
  self.openingdate = openingdate
  self.initialbalance = initialbalance
 
  account_table = Account.__table__
 
  class DebitnoteMaster(Base):
  __tablename__ = debitnotemaster
  vouchercode = Column(String(40), primary_key = True)
  sbillno = Column(String(40))
  voucherdate = Column(TIMESTAMP, nullable = False)
  reffdate = Column(TIMESTAMP)
  booktype = Column(Text)
  chequeno = Column(Text)
  bankname = Column(Text)
  debitnarration = Column(Text, nullable = False)
 
  def
 
 __init__(self,vouchercode,sbillno,voucherdate,reffdate,booktype,chequeno,bankname,debitnarration):
  self.vouchercode = vouchercode
  self.sbillno = sbillno
  self.voucherdate = voucherdate
  self.reffdate = reffdate
  self.booktype = booktype
  self.chequeno = chequeno
  self.bankname = bankname
  self.debitnarration = debitnarration
 
  debitnotemaster_table = DebitnoteMaster.__table__
 
  class DebitnoteDetails(Base):
  __tablename__ = debitnotedetails
  dndtcode = Column(Integer, primary_key = True)
  vouchercode = Column(String(40),
  ForeignKey(debitnotemaster.vouchercode))
  debitnotemaster = relation(DebitnoteMaster, backref =
  backref(DebitnoteDetails, order_by = dndtcode))
  craccountcode = Column(Integer, ForeignKey(account.accountcode),
  nullable = False)
  account = relation(Account, backref = backref(DebitnoteDetails,
  order_by = dndtcode))
  draccountcode = Column(Integer, ForeignKey(account.accountcode),
  nullable = False)
  account = relation(Account, backref = backref(DebitnoteDetails,
  order_by = dndtcode))
  amount = Column(Numeric(13,2), nullable = False)
 
  def __init__(self,vouchercode,craccountcode,draccountcode,amount):
  self.vouchercode = vouchercode
  self.craccountcode = craccountcode
  self.draccountcode = draccountcode
  self.amount = amount
 
  debitnotedetails_table = DebitnoteDetails.__table__
 
  
 
  Error:
  *
 
  Traceback (most recent call last):
File /usr/lib/python2.6/dist-packages/twisted/web/server.py, line
 150,
  in process
  self.render(resrc)
File /usr/lib/python2.6/dist-packages/twisted/web/server.py, line
 157,
  in render
  body = resrc.render(self)
File /usr/lib/python2.6/dist-packages/twisted/web/resource.py, line
 190,
  in render

Re: [sqlalchemy] newbie to sqlalchemy :not null constraint

2010-02-10 Thread anusha kadambala
Thanks, Micheal for your help


On Wed, Feb 10, 2010 at 9:53 AM, Michael Trier mtr...@gmail.com wrote:


  hello all,
 
  I am newbie in sqlalchemy.I am thrilled by the sqlachemy features. But i
 got struck in the how to write the not null  for the following:
 
  create table organisation(orgcode varchar(30) not null,orgname text not
 null,primary key(orgcode));
 
  I have written the using declarative base as follows but dont know how to
 impose not null constraint

 You want to use the nullable=False argument.


 http://www.sqlalchemy.org/docs/reference/sqlalchemy/schema.html?highlight=nullable

 Thanks,

 Michael

 --
 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.comsqlalchemy%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.




-- 


Njoy the share of Freedom :)
Anusha Kadambala

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



[sqlalchemy] creating views declarative base is confusing

2010-02-10 Thread anusha kadambala
hello all,

I want to create view based on the following tables

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

engine = create_engine('postgresql:///try', echo=False)
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String)
fullname = Column(String)
password = Column(String)

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

def __repr__(self):
return User('%s','%s', '%s') % (self.name, self.fullname,
self.password)

users_table = User.__table__


class Office(Base):
__tablename__ = 'office'
cid = Column(Integer, primary_key=True)
name = Column(String)
org = Column(String)


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

def __repr__(self):
return User('%s','%s', '%s') % (self.name, self.org)

office_table = Office.__table__
metadata = Base.metadata
metadata.create_all(engine)
Session = scoped_session(sessionmaker(bind=engine))
Session.add_all([User('wendy', 'Wendy Williams', 'foobar'),User('mary',
'Mary Contrary', 'xxg527'),User('fred', 'Fred Flinstone',
'blah'),Office('wendy','Comet'),Office('kk','Comet')])
Session.commit()

I want to write a view class in which i can select user.name and
office.namewhere
user.id = office.id which reflects in the database.

I got something like this which i got when i google but i didnt understand
how it happens actually

http://groups.google.com/group/sqlalchemy/browse_thread/thread/cd4455178d886e73



-- 


Njoy the share of Freedom :)
Anusha Kadambala

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



[sqlalchemy] newbie to sqlalchemy :not null constraint

2010-02-09 Thread anusha kadambala
hello all,

I am newbie in sqlalchemy.I am thrilled by the sqlachemy features. But i got
struck in the how to write the not null  for the following:

create table organisation(orgcode varchar(30) not null,orgname text not
null,primary key(orgcode));

I have written the using declarative base as follows but dont know how to
impose not null constraint

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

engine = create_engine('postgresql:///gkanusha', echo=False)
Base = declarative_base()
class Organisation(Base):
__tablename__ = 'Organisation'
orgcode = Column(String,primary_key=True)
orgname = Column(String)
def __init__(self,orgcode,orgname):
self.orgcode = orgcode
self.orgname = orgname

organisation_table = Organisation.__table__

metadata = Base.metadata
metadata.create_all(engine)
Session = scoped_session(sessionmaker(bind=engine))
Session.commit()

There are other columns also but i have taken two columns for simplicity.

Thanks in advance
-- 


Njoy the share of Freedom :)
Anusha Kadambala

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