[sqlalchemy] Re: Mapping and updating tables with no primary key

2007-08-12 Thread Andy Hird


 you should be able to say:

 table = Table('account_stuff', metadata,
Column('account_id', Integer, ForeignKey('account_ids.account_id'),
 primary_key=True),
autoload=True)


That doesn't appear to work unfortunately. When I load the db and
create the two tables and then attempt to do a join:

join(account_ids_table, account_stuff_table)

I get the error:
class 'sqlalchemy.exceptions.ArgumentError': Can't determine join
between 'account_ids' and 'account_stuff'; tables have more than one
foreign key constraint relationship between them. Please specify the
'onclause' of this join explicitly.

Looking at account_stuff_table.foreign_keys I have:

OrderedSet([ForeignKey(u'account_ids.account_id'),
ForeignKey('account_ids.account_id')])

I'm guessing the load duplicated the key. Although I only have two
columns looking at list(account_stuff.c)

[Column(u'credit',SLNumeric(precision=10,length=2)),
 
Column('account_id',Integer(),ForeignKey('account_ids.account_id'),primary_key=True,nullable=False)]


Thanks
Andy


--~--~-~--~~~---~--~~
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: Mapping and updating tables with no primary key

2007-08-12 Thread sdobrev

 Looking at account_stuff_table.foreign_keys I have:

 OrderedSet([ForeignKey(u'account_ids.account_id'),
 ForeignKey('account_ids.account_id')])
i see one is unicode'd (the autoloaded), another one is not (yours). 
unicode!=str so they probably appear differently named.
see if u can workaround that.

autoloading does not convert unicoded names back into str. 
(Paul, u see?)

 I'm guessing the load duplicated the key. Although I only have two
 columns looking at list(account_stuff.c)

 [Column(u'credit',SLNumeric(precision=10,length=2)),

 Column('account_id',Integer(),ForeignKey('account_ids.account_id'),
primary_key=True,nullable=False)]


--~--~-~--~~~---~--~~
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: Mapping and updating tables with no primary key

2007-08-12 Thread Michael Bayer


On Aug 12, 2007, at 4:44 AM, [EMAIL PROTECTED] wrote:


 Looking at account_stuff_table.foreign_keys I have:

 OrderedSet([ForeignKey(u'account_ids.account_id'),
 ForeignKey('account_ids.account_id')])
 i see one is unicode'd (the autoloaded), another one is not (yours).
 unicode!=str so they probably appear differently named.
 see if u can workaround that.


nope

  u'hi'=='hi'
True


 autoloading does not convert unicoded names back into str.
 (Paul, u see?)


the theme these days is to keep schema elements as unicode on the  
python side when we reflect.  this is because schema table and column  
names may contain non-ascii characters.  we have a good deal of  
unittests now which successfully create and autoload back tables like  
this:

CREATE TABLE 測試 (
 id INTEGER NOT NULL,
 PRIMARY KEY (id)
)

the issue with the ForeignKey here is just a bug in the override  
columns aspect of autoload and ive added ticket #728 for it.


--~--~-~--~~~---~--~~
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] SQLAlchemy 0.4 beta1 **RELEASED**

2007-08-12 Thread Michael Bayer

SQLAlchemy version 0.4, the biggest release SQLAlchemy has ever had,
is released in its first beta.

If you haven't been following along, it's time to catch up !  An
overview-in-progress of whats new is at 
http://www.sqlalchemy.org/trac/wiki/WhatsNewIn04
.

This SQLAlchemy is different from the previous, in that its:

* collaboratively developed among six core developers.
* the fastest SQLAlchemy yet (with continuing efforts to make it
faster).
* Has *fewer* plugins, replaced with core, integrated features.
* Most documentation has been completely rewritten or revised
* source code has been refactored, modularized, and simplified like
crazy in virtually all areas, particularly ORM, SQL construction, and
execution
* is a *little* more opinionated.  Many methods, arguments, and
classnames have been removed with more singular usage patterns
recommended.
* has a large number of features which users have been asking for
since day one:  mapped attributes usable in SQL expressions (no
more .c.), higher-level query constructs (like
SomeClass.foo.contains(x)), two-phase and nested transaction support,
relation()s that load partial results, core hooks added for horizontal
partitioning of data across databases.
* Oracle support is entering the big leagues, with greatly improved
table reflection support, datatype support, as well as new support for
OUT params.

We have released at 0.4beta1.  There is a mild migration path which is
now described on the first page of the documentation as well as on the
wiki.  We hope to get people testing this version to ensure that
upgrades go smoothly and that feature regression is working out OK.
We also *desperately* need beta testers for these platforms:  MS-SQL,
Firebird, and Informix.  0.4 has been tested extensively with SQLite,
Postgres, MySQL, and Oracle.

Whats new in 0.4: http://www.sqlalchemy.org/trac/wiki/WhatsNewIn04
0.4 Documentation:  http://www.sqlalchemy.org/docs/04/
Download !  http://www.sqlalchemy.org/download.html


--~--~-~--~~~---~--~~
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: MySQL LOAD DATA INFILE

2007-08-12 Thread jason kirtland

Martin Aspeli wrote:
 Hi all,
 
 I have a use case where I need to execute a MySQL LOAD DATA INFILE
 statement on an SQLAlchemy connection.
 
 I've tried this is with an engine using a threadlocal strategy, using
 engine.scalar() and passing a string that contains the (generated)
 LOAD
 DATA INFILE statement.
 
 The statement works if typed manually into the MySQL console, so I'm
 pretty sure it's right. I don't get any errors either (and I'm able
 to
 make it error by deliberately introducing a syntax error, so it must
 reach MySQL) but no data ever ends up in the table.
 
 Can anyone think of what I'm doing wrong?

Hi Martin,

I'm guessing you're using a transactional storage engine like InnoDB for 
this table?  It looks like LOAD DATA INFILE isn't autocommiting at the 
moment, and that seems like the most likely explanation.  For the time 
being, you can workaround this by using an explicit transaction for your 
load:


import os
from sqlalchemy import create_engine
print open('/var/tmp/data.csv').read()
engine = create_engine('mysql:///test')
con = engine.connect()
trans = con.begin()
con.execute(LOAD DATA INFILE '/var/tmp/data.csv' 
 INTO TABLE testtable 
 FIELDS TERMINATED BY ',')
trans.commit()

print list(engine.execute('SELECT * FROM testtable'))

# 1,2
# 2,2
# 3,2
# 1,3
# 2,3
# 3,3
# [(1L, 2L), (2L, 2L), (3L, 2L), (1L, 3L), (2L, 3L), (3L, 3L)]



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