[sqlalchemy] transactions

2007-01-20 Thread jose

Hi all,

I have a question about transactions
I need to insert data into two tables (anag and user), sice I need to 
insert the generated primary key of anag into user.
I have to flush anag to have the id to insert into user table.
What happens if there's an interruption in the middle of this, for 
example, immediately after to flush anag?
Should I use create_transaction() to avoid a such thing?

#transaction = session.create_transaction()
#try:
anag = Anag(
name = data.get('display_name')
)
session.save(anag)
session.flush()

user = User(
anag_id = anag.id
)
session.save(user)
session.flush()

#transaction.commit()
#except:
#transaction.rollback()

jo


--~--~-~--~~~---~--~~
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: count(*) function

2007-01-20 Thread milena

It worked. Thanks!

On Jan 15, 11:37 am, Marco Mariani [EMAIL PROTECTED] wrote:
 milenawrote:

  I have tried

  select([func.count(*)], from_obj=[table_name]).execute()

  but it didn't workI suppore you're not using mappers, so this is the 
  fastest method:

 number_of_rows = table.count().execute().fetchone()[0]
 
 where table is the table object


--~--~-~--~~~---~--~~
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: Problem with array fields in postgres

2007-01-20 Thread exhuma.twn

Sean Davis wrote:
 On 1/2/07, Mando [EMAIL PROTECTED] wrote:
 
 
  Sorry,
  but I don't understand how create, insert or select data with the array
  field in postgres.


 I don't think array fields are supported yet.  There is a post from this
 week that discusses the issue.

 Sean


Good to know. Can you also give a link/reference to that post? I am
intrigued by it ;)

Cheers,

Mich.


--~--~-~--~~~---~--~~
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: Problem with array fields in postgres

2007-01-20 Thread Antonio

* sabato 20 gennaio 2007, alle 02:57, exhuma.twn wrote :
   Sorry,
   but I don't understand how create, insert or select data with the array
   field in postgres.

I use a composite type in PostgreSQL 

fatture=# \d datirim
Composite type public.datirim
Column |  Type
+
rim| smallint
hat| time without time zone
hin| time without time zone
hfn| time without time zone
turno  | character(1)

in sqlalchemy:


import sqlalchemy as sqa
import re

class _RimType(sqa.types.TypeEngine):
def __init__(self):
pass
def get_col_spec(self):
pass
def convert_bind_param(self, value, engine):
return '('+,.join(value)+')'
def convert_result_value(self, value, engine):
arr = re.sub('[()]','',value).split(',')
return 'Nome %s HAT %s HIN %s HFN %s' % \
(arr[0],arr[1],arr[2],arr[3])

.

_elem_tbl=sqa.Table('elem', _mdata,
sqa.Column('id', sqa.Integer, primary_key=True),
sqa.Column('rim1', _RimType),
sqa.Column('rim2', _RimType),
sqa.Column('tempo', sqa.Time)
)

you can use a similar class for arrays

bye ...

PS sorry for my english ;-)))

-- 
#include stdio.h
int main(void){char c[]={10,65,110,116,111,110,105,111,32,98,97,114,98,111,110,
101,32,60,104,105,110,100,101,109,105,116,64,116,105,115,99,97,108,105,110,101,
116,46,105,116,62,10,10,0};printf(%s,c);return 0;}

--~--~-~--~~~---~--~~
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: ORM ramblings 2 - and announcing some o2r wrapper

2007-01-20 Thread Michael Bayer

changeset 2221 addresses the pattern youre doing in test_case3.  it  
required SA is more strict about matching foreignkey columns in a  
relatoinship into the primary join condition, luckily all the unit  
tests still pass.  this is because youre doing self-referential  
relationships on polymorphic mappers...so all the involved tables are  
everywhere and its a big mess to figure out what points where.

other random factoids:

lazy=True is the default.
correlate=False not needed in most cases.
foreignkey not needed in most cases.  it tells a relationship which  
column in the primaryjoin condition is foreign.

the idea behind SA flags is to start with as few flags as possible  
and add in as needed.  this conflicts with what youre trying to do,  
which involves getting a mapping to work with no manual  
experimentation phase.  in particular a flag like post_update  
should only be used if absolutely needed, so it will take some fancy  
logic to guess things like that (not to mention, using primaryjoin on  
a concrete table mapping...now you need a distinct relation() +  
primaryjoin on each concrete mapper, etc.)

concrete inheritance is also hardly implemented, in rev 2221 above i  
added a basic unit test thats been hanging around for concrete +  
polymorphic.  it required i stick a kind of hacky thing in the mapper  
to get it to work.  which generally means that new variations on  
concrete are going to keep failing until a more general method is  
worked out.  in particular the big issue with concrete is that you  
cant really inherit a relation(), since the primaryjoin condition is  
going to be different for each submapper.  the current method of  
relation propigation between inheriting mappers in the 0.3 series is  
more or less broken for concrete inheritancewhich implies any  
real relation propigation with concrete mappers (since im sure youre  
going to stick a relation() on a concrete mapper's base mapper if not  
already) is going to require major surgery inside the mapper  
compilation and a whole boatload of new tests.  also i need to get an  
SA release out before any work like that starts.  unit tests for  
concrete are going to live in test/orm/inheritance4.py to start.

as far as typecolname i dont like that flag much.  using an  
explicit setup means you know exactly what youre doing:

p = polymorphic_union({
'foo':select([footable, column(footype).label 
('type')]),
'bar':bartable
 })

also i tried your polymorphic_union, but since you changed its API it  
doesnt pass any of the unit tests.  polymorphic_union is intended for  
the end-user to manually configure, so it wouldnt have arguments like  
allow_empty_typecolname.  however, one reason i like having the  
function separate from mapper config is so folks can do exactly what  
you did; come up with some other way to make their selection criterion.


On Jan 19, 2007, at 7:32 AM, svilen wrote:

 and that change is in rev 2214, your two test scripts run
 unmodified now.

 without these changes (pure 0.3.3), adding explicit foreignkey=...  
 on all relations worked OK in all 39 cases.

 With new changes (trunk/2216), B pointing to A (manager pointing to  
 employee) does not work. B pointing to B is ok, A pointing to A or  
 B is ok.
 sqlalchemy.exceptions.ArgumentError: Cant determine relation  
 direction for 'manager' on mapper 'Mapper|Manager|Manager' with  
 primary join 'Manager.manager_id = Employee.id' - foreign key  
 columns are present in both the parent and the child's mapped  
 tables.  Specify 'foreignkey' argument.

 regardless that foreignkey= argument is there.

 see attach.

 --
 Thanks for the other changes. Here's a fixed polumunion.py. It is  
 best if typecolname there is always given - it will be used only if  
 needed (concrete). But by default i've made it fit your present  
 protocol.

 
 test_case3.py
 polymunion.py


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

2007-01-20 Thread Jonathan Ellis

yes, you should, and your commented-out code looks fine

On 1/20/07, jose [EMAIL PROTECTED] wrote:

 Hi all,

 I have a question about transactions
 I need to insert data into two tables (anag and user), sice I need to
 insert the generated primary key of anag into user.
 I have to flush anag to have the id to insert into user table.
 What happens if there's an interruption in the middle of this, for
 example, immediately after to flush anag?
 Should I use create_transaction() to avoid a such thing?

 #transaction = session.create_transaction()
 #try:
 anag = Anag(
 name = data.get('display_name')
 )
 session.save(anag)
 session.flush()

 user = User(
 anag_id = anag.id
 )
 session.save(user)
 session.flush()

 #transaction.commit()
 #except:
 #transaction.rollback()

 jo


 


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

2007-01-20 Thread jose

Jonathan Ellis wrote:

yes, you should, and your commented-out code looks fine
  

thank you, Jonathan.

On 1/20/07, jose [EMAIL PROTECTED] wrote:
  

Hi all,

I have a question about transactions
I need to insert data into two tables (anag and user), sice I need to
insert the generated primary key of anag into user.
I have to flush anag to have the id to insert into user table.
What happens if there's an interruption in the middle of this, for
example, immediately after to flush anag?
Should I use create_transaction() to avoid a such thing?

#transaction = session.create_transaction()
#try:
anag = Anag(
name = data.get('display_name')
)
session.save(anag)
session.flush()

user = User(
anag_id = anag.id
)
session.save(user)
session.flush()

#transaction.commit()
#except:
#transaction.rollback()

jo




jo

--~--~-~--~~~---~--~~
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] PickleType too small

2007-01-20 Thread milena

Hi,

I am having trouble with PickleType used as column type
(Column('data',MyPickle)). I want to store a dictionary data type into
a database (mySQL), but the dictionary is to big. Can anyone tell me
how to enlarge PickleType so that it can hold up all my data.

Thanks in advance!


--~--~-~--~~~---~--~~
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] new docs new docs new docs

2007-01-20 Thread Michael Bayer

hey list -

trying to wrap up as much as i can for the next release, just wanted to
highlight some new doc sections and improvements, since i know everyone
just loves my docs and their various typos, careless flubs, and great
endorsement of the insurance industry:

SQLAlchemy is Two Libraries in One
http://www.sqlalchemy.org/docs/tutorial.myt#tutorial_twoinone

Configuring Logging
http://www.sqlalchemy.org/docs/dbengine.myt#dbengine_logging

Creating Joins Using selectby() - added a note about the new feature
(in the trunk until 0.3.4)
which lets you select_by(somerelation=someinstance)
http://www.sqlalchemy.org/docs/datamapping.myt#datamapping_selectrelations_relselectby

Working with Large Collections
http://www.sqlalchemy.org/docs/adv_datamapping.myt#advdatamapping_properties_working

Mapper Options - complete and alphabetical
http://www.sqlalchemy.org/docs/adv_datamapping.myt#advdatamapping_mapperoptions

Relation Options - complete and alphabetical
http://www.sqlalchemy.org/docs/adv_datamapping.myt#advdatamapping_properties_relationoptions

Combining Eager Loads with Result Set Mappings
http://www.sqlalchemy.org/docs/adv_datamapping.myt#advdatamapping_resultset_combining


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