[sqlalchemy] Re: session issues in TG - automatic commits happening.

2007-06-26 Thread Sanjay

As I recall, this was discussed in TG forum sometime, and there is a
nice way to disable this. Searching there might help...

Sanjay


--~--~-~--~~~---~--~~
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: Storing JSON objects, maybe OT

2007-06-26 Thread svilen

  http://www.evolt.org/article/Four_ways_to_work_with_hierarchical_
 data/17/4047/index.html

 I have to say I've seen better writeups on this topic - so be
 warned :)
that looks very much like '1st 5 things i found about recursive data'.

 Choosing a strategy for storing hierarchical data in a database
 depends largely on how you will be retrieving  the data (what kind
 of queries do you need to make).
exactly. and one more thing, the way u store data may not be the way u 
retrieve it - i.e. u have one original copy that presents everything 
as is, and one pre-calculated/calculable-on-the-fly view/copy which u 
use for queries. and for differnt queries u may have different 
extracts/views.
For example, storing a graph as links and nodes is fine to keep the 
original data, but is quite difficult for most (graph algorithmical) 
queries - procedural recursion is not SQL's piece of cake. Thus 
storing additional transient-closure of the graph (all possible 
end-to-end paths) is a way to go for some targets which need paths. 
Probably there are other solutions for other targets.

have fun
svil

--~--~-~--~~~---~--~~
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: Storing JSON objects, maybe OT

2007-06-26 Thread voltron

Thanks Arnar! I´ll prefer to take this off the list since it is only
slightly related to SQLAlchemy.

On Jun 26, 2:28 am, Arnar Birgisson [EMAIL PROTECTED] wrote:
 On 6/25/07, voltron [EMAIL PROTECTED] wrote:



  Thank you very much for your feedback guys! I was very worried the
  whole day. I did some research and found this:
 http://www.evolt.org/article/Four_ways_to_work_with_hierarchical_data...

 I have to say I've seen better writeups on this topic - so be warned :)

 Choosing a strategy for storing hierarchical data in a database
 depends largely on how you will be retrieving  the data (what kind of
 queries do you need to make).

  Actually, I would be reordering or editing page links using this
  method, the JSON data is passed to a tree widget

 I'm not sure what is the relation between your JSON issue and the
 hierarchical stuff. JSON is really only useful to serialize simple
 data structures in a way that is easy for Javascript code to
 deserialize. It won't help you particularly in designing a
 hierarchical database model.

 If you still need help and if you want to, feel free to tell us a bit
 more what you want to do. If it's not an SA issue you can mail me
 directly if you're more comfortable with that.

 Arnar


--~--~-~--~~~---~--~~
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: Concurrency control using version_id_col

2007-06-26 Thread Sanjay

Hi Mike,

Thanks a lot. It works fine (with or without default=0). The problem
was in my TG application, which was not preserving version while
populating the edit form. I made version as a hidden field in the
form, and it works fine now.

Sanjay


--~--~-~--~~~---~--~~
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: advanced mapping help

2007-06-26 Thread svilen

 The mapper expects a
 class, but I can't define Content before ContentCollection and
 ContentCollection before Content...


whhy? SA-wise u have no problem:
class X: pass
class Y: pass

mapper(X, ... y=relation(Y,...) ... )
mapper(Y, ... x=relation(X,...) ... )

The problem might be only in your own classes (X,Y).

some theory/experience:
This is a problem in ordered declarative languages, where order of 
appearance is important and which usualy have a sort of 'Forward 
declarations' for that matter. Python itself is a sort of such 
language without Forward decl, but usualy declaration and usage are in 
different lifetimes/scopes (e.g. class declaration vs 
class-method-runtime are different scopes/lifetimes), so u never hit 
it. Well, If u try using it pure declaratively, in same 
lifetime/scope - then u have trouble.

For python there 2 ways to workaround: 
 - at the reference end/ refereee: use surrogates/aliases instead of 
real 
references, then at certain 'end-of-declarations' time go replace all 
reference to surogate with reference to real thing. May need some 
rework e.g. not to expect real things before runtime. i'm using this 
approach in my sa-wrapping pure declarative framework.
 - at the owner end/ referer: declare the class empty; then somewhat 
later put the contents in (the contents may be prepared early, but 
not in the class). This is not straight forward, uses pseudo 
__bases__ that are replaced with something full later. i'm using this 
in a 2-tier protocol generator, miming C/CORBA scope semantics in 
equivalent python classes.
If u're interested i can give u some sources doing either one.

but i am 95% sure u don't need them - they are of use only for 
large frameworks where u cant choose which is when nor where.

ciao
svil

--~--~-~--~~~---~--~~
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] Relation ends up as a one-to-one, not a one-to-many

2007-06-26 Thread Paul Johnston
Hi,

I have the following property on an object, which is working fine:

class VulnResDesc:
...
@property
def rawvulns(self):
return VulnRes.select(
  and_(VulnRes.c.targetid == self.targetid,
   VulnMap.c.tool == VulnRes.c.tool,
   VulnMap.c.toolvulnid == VulnRes.c.toolvulnid,
   VulnMap.c.vulndescid == self.id))

The role of VulnMap is a bit funky in the query, but this is intentional.
Now, I am trying to code this as a relation instead of a property, the
following is what I've got so far:

VulnResDesc.mapper.add_property('rawvulns', relation(VulnRes.mapper,
primaryjoin = and_(VulnRes.c.targetid == VulnResDesc.c.targetid,
   VulnMap.c.vulndescid == VulnResDesc.c.id,
   VulnMap.c.tool == VulnRes.c.tool,
   VulnMap.c.toolvulnid == VulnRes.c.toolvulnid),
foreign_keys = [VulnResDesc.c.targetid, VulnResDesc.c.id]))

This almost works, but it returns a single object, which I was expecting a
list. Any ideas what's up?

BTW, the reason I want to recode this is I'm hoping to use the eagerloader.
Still, to start with I'll settle for just getting it to work lazily :-)

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: Relation ends up as a one-to-one, not a one-to-many

2007-06-26 Thread svilen

it might be stupid, but did u try
use_list=True ?


--~--~-~--~~~---~--~~
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: Relation ends up as a one-to-one, not a one-to-many

2007-06-26 Thread Paul Johnston
Ah, that does it.

Sorry, that really was stupid! If only I had scrolled down the docs a little
bit :-)

Thanks svilen.

Paul


On 6/26/07, svilen [EMAIL PROTECTED] wrote:


 it might be stupid, but did u try
 use_list=True ?


 


--~--~-~--~~~---~--~~
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] alchemy mysql database problem

2007-06-26 Thread warren . emmett

Hi,

I am currently using SQLAlchemy in the creation of a mysql database. I
use alchemy to create the tables and to access them but I use a python
script to collect the information from the necessary sources prepare
them and shove them into tab delimited 'out' files which i then load
into the tables using the mysql 'LOAD IN FILE' function.

These are my tables

AccessionsTable = Table('AccessionsTable',metadata,
Column('accession_number', String(20), primary_key=True),
Column('description',String(300)),
Column('seq_length',Integer),
Column('accessions_id',Integer)
)
AccessionsTable.create()

InstancesTable = Table('InstancesTable',metadata,
Column('inst_id',Integer,primary_key=True,autoincrement=True),
Column('oligomer',String(40)),
Column('instances', String),
Column('frequency',Integer),
Column('fisher_coef', Float),
Column('expectation_per_100kb', String),

Column('accession_number',String(20),ForeignKey('AccessionsTable.accession_number'))
)
InstancesTable.create()


OligosTable = Table('OligosTable', metadata,
Column('oligomer',String(40),ForeignKey('InstancesTable.oligomer'),
primary_key=True),
Column('word', String),
Column('word_length', Integer),
Column('descriptor', Integer),
Column('gc_cont', Float),
Column('melt_temp_wall', Float),
Column('melt_temp_nn', Float)
)
OligosTable.create()

This is what the command looks like

LOAD DATA INFILE '/db/test/01.ins' INTO TABLE InstancesTable FIELDS
TERMINATED BY '\t' LINES TERMINATED BY '\n';

My problem is that this specific table - InstancesTable has an
autoincremented primary key which was intended to be generated
automatically however the first value in each line in the file is
being shoved into it which breaks the operation. I am just curious if
theres an attribute i can specify for this column when i create the
table so that this doesnt happen.

Thanks


--~--~-~--~~~---~--~~
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] Table updates using data mapping

2007-06-26 Thread voltron

Could someone tell me how I would execute this SQL using data mapping?

# SQL

UPDATE users SET group=consultant WHERE group = contractor;

#  Mapped object
user_mapper = mapper(User, users)
user = User()


Thanks


--~--~-~--~~~---~--~~
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: Table updates using data mapping

2007-06-26 Thread Rick Morrison
Updates and inserts on the ORM side of the street are single-object kinds of
things. The pattern is to load a list of objects, make the appropriate
modifications to the those in-memory objects, and then issue a session
flush().

This type of
bulk operation is best done with the SQL generation portion of the library,
like so (using an implicit bound connection here):

   users.update(users.c.group == contractor).execute({users.c.group =
consultant})





On 6/26/07, voltron [EMAIL PROTECTED] wrote:


 Could someone tell me how I would execute this SQL using data mapping?

 # SQL

 UPDATE users SET group=consultant WHERE group = contractor;

 #  Mapped object
 user_mapper = mapper(User, users)
 user = User()


 Thanks


 


--~--~-~--~~~---~--~~
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: Table updates using data mapping

2007-06-26 Thread voltron

would I have to do something like this?

sess = create_session()
allusers = sess.query(User).select()


for user in allusers:
user.group = contractor
print x.name


On Jun 26, 10:40 pm, voltron [EMAIL PROTECTED] wrote:
 Could someone tell me how I would execute this SQL using data mapping?

 # SQL

 UPDATE users SET group=consultant WHERE group = contractor;

 #  Mapped object
 user_mapper = mapper(User, users)
 user = User()

 Thanks


--~--~-~--~~~---~--~~
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: Table updates using data mapping

2007-06-26 Thread Michael Bayer


On Jun 26, 2007, at 4:51 PM, Rick Morrison wrote:

 Updates and inserts on the ORM side of the street are single-object  
 kinds of things. The pattern is to load a list of objects, make the  
 appropriate modifications to the those in-memory objects, and then  
 issue a session flush().

 This type of bulk operation is best done with the SQL generation  
 portion of the library, like so (using an implicit bound connection  
 here):

users.update(users.c.group == contractor).execute({users.c.group  
 = consultant})


using the actual execution terminology i made up !  nice



--~--~-~--~~~---~--~~
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: Table updates using data mapping

2007-06-26 Thread Mike Orr

On 6/26/07, voltron [EMAIL PROTECTED] wrote:
 sess = create_session()
 allusers = sess.query(User).select()


 for user in allusers:
 user.group = contractor
 print x.name

This adds the overhead of creating a Python object for every row.  If
you already have many of the objects in memory anyway or the overhead
is too small to be noticeable, you can do it this way.  Rick's way
sends one small query to the database, which does it all internally.

-- 
Mike Orr [EMAIL PROTECTED]

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