[sqlalchemy] Re: SA 0.4 weird behaviour

2007-11-13 Thread fw

Thanks for the answer

It looks indeed like  a log operation.

When adding __repr__  no error message.

Spot on.

Cheers,
   François

  File "test.py", line 230, in ?
StockItem.mapper["Primary"]=mapper(StockItem, tblStock,
properties={
AttributeError: type object 'StockItem' has no attribute 'mapper'


On 13 nov, 23:23, jason kirtland <[EMAIL PROTECTED]> wrote:
> fw wrote:
> > Hi,
>
> > I am having a weird problem. I am dealing with some "legacy" database,
> > so I subclass TypeDecorator to help clean things up a bit.
>
> > This worked fine in 0.3 but I am now trying to use 0.4 and things
> > break in the strangest of way.
>
> > When I run the file below, Python complains about
>
> > AttributeError: 'String' object has no attribute 'padding'
>
> > Now, "padding" is a parameter of the constructor of PaddedIntString.
> > So it is not an attribute.
>
> > If I make "padding" an attribute of  PaddedIntString, the error
> > dissappears.
>
> > Am I doing something wrong or is this a feature of 0.4???
>
> That sounds like the __repr__ method of AbstractType trying to be
> clever, probably called in a logging operation.  Try providing a
> __repr__ in your type class.
>
> The __repr__ behavior hasn't changed with 0.4, but there might be more
> logging than 0.3.


--~--~-~--~~~---~--~~
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: SA 0.4 weird behaviour

2007-11-13 Thread fw

Thanks for the answer.

The trace is

Traceback (most recent call last):
  File "test.py", line 227, in ?
StockItem.mapper["Primary"]=mapper(StockItem, tblStock,
properties={
  File .../sqlalchemy/orm/__init__.py", line 518, in mapper
return Mapper(class_, local_table, *args, **params)
  File ".../sqlalchemy/orm/mapper.py", line 152, in __init__
self._compile_tables()
  File ".../sqlalchemy/orm/mapper.py", line 464, in _compile_tables
self.__log("Identified primary key columns: " + str(primary_key))
  File "sqlalchemy/util.py", line 481, in __repr__
return '%s(%r)' % (self.__class__.__name__, self._list)
  File "sqlalchemy/schema.py", line 496, in __repr__
return "Column(%s)" % ', '.join(
  File "sqlalchemy/types.py", line 136, in __repr__
return "%s(%s)" % (self.__class__.__name__, ",".join(["%s=%s" %
(k, getattr(self, k)) for k in inspect.getargspec(self.__init__)[0]
[1:]]))
  File "sqlalchemy/types.py", line 208, in __getattr__
return getattr(self.impl, key)
AttributeError: 'String' object has no attribute 'padding'


Cheers,
  François



On 13 nov, 22:17, Michael Bayer <[EMAIL PROTECTED]> wrote:
> On Nov 13, 2007, at 2:51 AM, fw wrote:
>
>
>
> > Hi,
>
> > I am having a weird problem. I am dealing with some "legacy" database,
> > so I subclass TypeDecorator to help clean things up a bit.
>
> > This worked fine in 0.3 but I am now trying to use 0.4 and things
> > break in the strangest of way.
>
> > When I run the file below, Python complains about
>
> >AttributeError: 'String' object has no attribute 'padding'
>
> a full stack trace would be needed to pinpoint who is calling for that
> attribute.


--~--~-~--~~~---~--~~
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: trunk's new anon_N labeled subqueries break some eagerloading queries

2007-11-13 Thread Chris M

http://www.sqlalchemy.org/trac/ticket/864

On Nov 13, 10:35 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
> definitely need a test case illustrating what problem you encountered.
>
> On Nov 13, 2007, at 9:17 PM, Chris M wrote:
>
>
>
> > I didn't see any tickets about this on the trac, so I thought I'd
> > bring it to everyones attention. Since it's a development version I
> > wasn't sure if this mattered (or was known about), so if it does I can
> > draft up a quick test case.


--~--~-~--~~~---~--~~
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: threadlocal transactions, engine, and the Session

2007-11-13 Thread Huy Do


>> I was hoping that I could create a another session using another  
>> engine
>> (non threadlocal), for these special cases. I have not yet run into  
>> this
>> need yet. Just out of interest, have you run into any such use cases ?
>>
>> Thanks
>>
>> 
>
> if youre using threadlocal engine, you can still say engine.connect()  
> and get a Connection that is not part of the threadlocal context (and  
> start transactions off that connection, bind it to sessions,  
> whatever).  therefore you really dont lose anything when using  
> threadlocal.
You've thought of everything :-)

Thanks.

Huy

--~--~-~--~~~---~--~~
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: trunk's new anon_N labeled subqueries break some eagerloading queries

2007-11-13 Thread Michael Bayer

definitely need a test case illustrating what problem you encountered.


On Nov 13, 2007, at 9:17 PM, Chris M wrote:

>
> I didn't see any tickets about this on the trac, so I thought I'd
> bring it to everyones attention. Since it's a development version I
> wasn't sure if this mattered (or was known about), so if it does I can
> draft up a quick test case.
>
>
> >


--~--~-~--~~~---~--~~
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: threadlocal transactions, engine, and the Session

2007-11-13 Thread Michael Bayer


On Nov 13, 2007, at 7:46 PM, Huy Do wrote:

>
> Hi Rick,
>> I use a similar technique with a Pylons controller, but instead of
>> engine.begin(), I use session.begin(). Then by passing around the
>> session for all calls made by that controller,
> I had so much legacy SA code, that I just couldn't easily retrofit  
> this
> pattern throughout the code, but thanks for the tip.
>> I can use Session.execute() for expression-based and text-based SQL
>> mixed with ORM ops, and it all commits in one shot on one thread
>> without using threadlocal. This allows the freedom to open another
>> session in a separate transaction for those odd places where it's
>> needed, and have arbitrary expression-based SQL execute in that other
>> transaction -- something I don't think
>> you'll be able to do with threadlocal + implicit execution.
> I was hoping that I could create a another session using another  
> engine
> (non threadlocal), for these special cases. I have not yet run into  
> this
> need yet. Just out of interest, have you run into any such use cases ?
>
> Thanks
>

if youre using threadlocal engine, you can still say engine.connect()  
and get a Connection that is not part of the threadlocal context (and  
start transactions off that connection, bind it to sessions,  
whatever).  therefore you really dont lose anything when using  
threadlocal.

--~--~-~--~~~---~--~~
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] Learning SQLAlchemy - some questions on mapped selects and set-based update/delete in sessions

2007-11-13 Thread Luke Opperman

Hello -

I'm learning SA at the moment (using 0.4), so I apologize if any
questions go against the grain or assume something silly, I'm looking
for the "SA answer" to how to do the following things. Similarly, I'm
going to throw some possible syntax up, but I don't know the SA style
well enough yet to know if I'm choosing a good fit, so if there's
isn't a pre-existing implementation that it turns out I missed, I'll
happily code up additions with others' input on syntax.

Ok, my learning task (and a real goal of using SA) is to benefit from
the mapper by being able to swap out actual table definitions and
selects as necessary, just changing the mappers and continuing to use
the mapped objects unchanged. I think that's pretty in-line with what
SA is trying to make possible? My test scenario is two sets of data
(draft/preview and live), with two equivalent models (one table with a
boolean flag, or two tables). Here's some stubs to give some context:

class Data(object):
  ...
class LiveData(object):
  ...
class PreviewData(object):
  ...

# single table:

data_table = Table('data', ..., Column('field1', String,
primary_key=True), Column('field2', String), Column('is_live',
Boolean, nullable=False))

mapper(Data, data_table)
mapper(LiveData, select([data_table.c.field1,
data_table.c.field2]).where(data_table.c.is_live==True).alias('live_data'))
mapper(PreviewData, select([data_table.c.field1,
data_table.c.field2]).where(data_table.c.is_live==False).alias('preview_data'))

# OR separate tables:

live_table = Table('live_data', ..., Column('field1', String,
primary_key=True), Column(field2', String))
preview_table = Table('preview_data', ..., Column('field1', String,
primary_key=True), Column(field2', String))

mapper(LiveData, live_table)
mapper(PreviewData, preview_table)
mapper(Data, select([preview_table, literal_column('0',
Boolean).label('is_live')]).union(select([live_data,
literal_column('1', Boolean).label('is_live')]).alias('data')

This has worked really well up to a point, trying to use the UOW/
session concept and only referring to the mapped objects not the
tables/queries, here are the areas where I'm failing:


1. Inserting into mapped selects.

SA seems to be pretty smart here and makes a decent attempt (according
to the docs, inserts into any table whose primary key is involved in
the select, appears to be working fine). However, my simple example
points out two (possibly generic) reasons to need to go beyond that:

 a. Further conditions on inserting. In the separate table model, the
mapped select is to a union and based on the constructed column
"is_live" I need the insert to go to one of the base tables. Today,
because both base tables contribute their PKs, the insert of creating
a Data object always goes to both.
 b. Implied/constructed values not present in the source objects. In
the single table model, an insert of a LiveData object should add an
is_live=True to the mapped insertion into Data. Today, with
nullable=False on data_table.is_live an insert to LiveData fails with
IntegrityError, with nullable=True is_live is set to NULL.

A naive attempt at syntax for defining these, an "insert_conversion"
argument to mapper of a dictionary of functions keyed by table.
functions would be (source_values_dict) =>
(insert_values_dict_for_this_table) or None. The conditional case is
handled by returning None, open questions would be is the
source_values for all tables or just the table's columns, and whether
arbitrary tables can be given a function in this dictionary or only
those with PKs in the mapped select.

mapper(LiveData, live_query, insert_conversion={data_table: lambda v:
dict(v, is_live=True)})
...
mapper(Data, data_query, insert_conversion={live_table: lambda v: v if
v['is_live'] else None, prevew_table: lambda v: v if not v['is_live']
else None})

(As we go into the second issue, keep in mind that the above problems
for inserts also apply to updates and deletes - I'm not sure whether
the same functions can apply across i/u/d however, or if you'd need to
specify separately. This example scenario can use the same ones, with
some restrictions: funcs cannot assume any column values are included
for update, which does mean updates would still have to be stopped for
ambiguity, and only the boolean return of the function matters for
delete.)

2. Updating/deleting against querysets using the mapped objects

Some of my usecases for this example include making bulk updates/
deletes against sets of data, for instance "make all preview data
live". The combination I'm trying to reach here is both:

  a. A set operation, not iterative.
  b. Using the mapped objects, ie PreviewData or Data.

(Note that (a) probably conflicts with 1. above as specified, although
not at a syntax level.)

A whole series of things that don't work:

# Selects can't be converted to updates
session.query(Data).filter_by(is_live=False).update(is_live=True) #
OR .update().values(dict(is_live=True))
# session.update is entirely

[sqlalchemy] trunk's new anon_N labeled subqueries break some eagerloading queries

2007-11-13 Thread Chris M

I didn't see any tickets about this on the trac, so I thought I'd
bring it to everyones attention. Since it's a development version I
wasn't sure if this mattered (or was known about), so if it does I can
draft up a quick test case.


--~--~-~--~~~---~--~~
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: Question regarding an adjacency-tree example in svn repo

2007-11-13 Thread bob

Thanks for clearing that up! :)

Bob


--~--~-~--~~~---~--~~
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: Question regarding an adjacency-tree example in svn repo

2007-11-13 Thread jason kirtland

bob wrote:
> Hi,
> 
> I am going over this this example to learn how to construct an eager-
> loaded adjacency tree,
> 
> http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/examples/adjacencytree/byroot_tree.py
> 
> and I noticed that some of the keys in the "treenodes" table are given
> long names in the table definition, and then shorter aliases in the
> mapper.  (eg. parent_node_id, parent_id, ...)  I couldn't really
> figure out whether this is necessary functional-wise.  It would be
> nice if I could just use shorter column names to begin with and skip
> the extra aliases.  Any thoughts on that?

There's no functional need for those.  For shorter names, other options 
are: a) just use shorter column names or b) keep the long names as-is in 
the database but use short names in Python via the key='shortname' 
option to Column.  The latter is a common strategy when you're stuck 
with a legacy schema.

-j


--~--~-~--~~~---~--~~
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: threadlocal transactions, engine, and the Session

2007-11-13 Thread Huy Do

Hi Rick,
> I use a similar technique with a Pylons controller, but instead of 
> engine.begin(), I use session.begin(). Then by passing around the 
> session for all calls made by that controller, 
I had so much legacy SA code, that I just couldn't easily retrofit this 
pattern throughout the code, but thanks for the tip.
> I can use Session.execute() for expression-based and text-based SQL 
> mixed with ORM ops, and it all commits in one shot on one thread 
> without using threadlocal. This allows the freedom to open another 
> session in a separate transaction for those odd places where it's 
> needed, and have arbitrary expression-based SQL execute in that other 
> transaction -- something I don't think 
> you'll be able to do with threadlocal + implicit execution.
I was hoping that I could create a another session using another engine 
(non threadlocal), for these special cases. I have not yet run into this 
need yet. Just out of interest, have you run into any such use cases ?

Thanks

Huy
>
> Rick
>
>
> >


--~--~-~--~~~---~--~~
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] Question regarding an adjacency-tree example in svn repo

2007-11-13 Thread bob

Hi,

I am going over this this example to learn how to construct an eager-
loaded adjacency tree,

http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/examples/adjacencytree/byroot_tree.py

and I noticed that some of the keys in the "treenodes" table are given
long names in the table definition, and then shorter aliases in the
mapper.  (eg. parent_node_id, parent_id, ...)  I couldn't really
figure out whether this is necessary functional-wise.  It would be
nice if I could just use shorter column names to begin with and skip
the extra aliases.  Any thoughts on that?

Thanks

Bob


--~--~-~--~~~---~--~~
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: FYI: SQLAutocode 0.4.1 and 0.5 released

2007-11-13 Thread m h

On Nov 13, 2007 4:44 PM, m h <[EMAIL PROTECTED]> wrote:
> On Nov 13, 2007 5:14 AM, Simon Pamies <[EMAIL PROTECTED]> wrote:
> >
> > Hi,
> >
> > I'm very pleased to announce the release of SQLAutocode 0.4.1 and
> > 0.5. This tool enables SQLAlchemy users to automagically generate
> > python code from an existing database layout and even has the
> >
>
> Hey Simon, I found your code today and started to hack on it to do db
> migrations.  Since it is out of the scope of your project, I'll
> probably just write my own.   But before I came to that conclusion, I
> did some cleaning up of the autocode.py.  Feel free to accept it if
> you want.  Here's the overview of the changes in the attached diff:
>
>  * Remove import * - I know SA does this all over the place, but when
> you have various projects that you are doing this with (ie both
> autocode and SA) it makes it difficult to know what came from where.
> Especially if you are an outside developer
>
>  * added a _main() function
>
>  * changed getopt to optparse
>
>  * added newlines after "else:"
>
>  * changed "if foo is True:" to "if foo:"
>
> cheers,
>
> matt
>

I should note that I didn't test all the options...  I might have
introduced some bugs in the optparse conversion.

--~--~-~--~~~---~--~~
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: FYI: SQLAutocode 0.4.1 and 0.5 released

2007-11-13 Thread m h
On Nov 13, 2007 5:14 AM, Simon Pamies <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm very pleased to announce the release of SQLAutocode 0.4.1 and
> 0.5. This tool enables SQLAlchemy users to automagically generate
> python code from an existing database layout and even has the
>

Hey Simon, I found your code today and started to hack on it to do db
migrations.  Since it is out of the scope of your project, I'll
probably just write my own.   But before I came to that conclusion, I
did some cleaning up of the autocode.py.  Feel free to accept it if
you want.  Here's the overview of the changes in the attached diff:

 * Remove import * - I know SA does this all over the place, but when
you have various projects that you are doing this with (ie both
autocode and SA) it makes it difficult to know what came from where.
Especially if you are an outside developer

 * added a _main() function

 * changed getopt to optparse

 * added newlines after "else:"

 * changed "if foo is True:" to "if foo:"

cheers,

matt

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

=== modified file 'autocode.py'
--- autocode.py 2007-11-13 22:18:59 +
+++ autocode.py 2007-11-13 23:34:54 +
@@ -1,104 +1,93 @@
-
 import sys
-import sqlalchemy
-if sqlalchemy.__version__ != 'svn':
-if sqlalchemy.__version__.split('.')[1] != '4':
+import os
+import optparse
+
+
+import sqlalchemy as sa
+if sa.__version__ != 'svn':
+if sa.__version__.split('.')[1] != '4':
 print 'Not compatible with this version of SQLAlchemy! Only works for 
the 0.4.x line!'
 sys.exit(7)
 
-del sqlalchemy
-
-
-from sqlalchemy import engine, MetaData
-
 import constants
-from loader import *
-from formatter import *
-
-if __name__ == '__main__':
-
-import sys, getopt, os
-
-args, longargs = ('hu:o:s:t:i3e', ['help', 'url=', 'output=', 'schema=', 
'tables=', 'noindex', 'z3c', 'example'])
-
-try:
-optlist, args = getopt.getopt(sys.argv[1:], args, longargs)
-except getopt.GetoptError:
-print >>sys.stderr, 'Error: Unknown arguments.'
-print >>sys.stderr, constants.USAGE
-sys.exit(255)
-
-if len(optlist)==0:
-print >>sys.stderr, 'Error: No arguments passed.'
-print >>sys.stderr, constants.USAGE
-sys.exit(0)
-
-url, output, schema, tables, \
-filehandle, noindex, \
-example, z3c = (None, None, None, None, None, None, False, False)
-for opt, arg in optlist:
-if opt in ['-h', '--help']:
-print >>sys.stderr, constants.USAGE
-sys.exit(0)
-
-if opt in ['-u', '--url']:
-url = arg
-
-if opt in ['-i', '--noindex']:
-noindex = True
-
-if opt in ['-e', '--example']:
-example = True
-
-if opt in ['-3', '--z3c']:
-z3c = True
-constants.TAB = 26*' '
-
-if opt in ['-o', '--output']:
-output = arg
-
-if os.path.exists(output):
-print >>sys.stderr, 'Output file exists - it will be 
overwritten!'
-resp = raw_input('Overwrite (Y/N): ')
-if resp.strip().lower() != 'y':
-print "Aborted."
-sys.exit(0)
-
-else: os.unlink(output)
-
-filehandle = open(output, 'wU')
-
-if opt in ['-s', '--schema']:
-schema = arg.strip()
-
-if opt in ['-t', '--tables']:
-tables = arg.split(',')
+import loader
+import formatter
+
+def _main(prog_args=None):
+if prog_args is None:
+prog_args = sys.argv
+
+parser = optparse.OptionParser("""Generates python code for a given 
database schema.""")
+
+parser.add_option("-u", "--url",
+  help="Database url (e.g.: postgres://postgres:[EMAIL 
PROTECTED]/Database)",
+  action="store", dest="url", default=None)
+parser.add_option("-o", "--output",
+  help="Where to put the output (default is stdout)",
+  action="store", dest="output", default=None)
+parser.add_option("-s", "--schema",
+  help="Name of the schema to output (default is 
'default')",
+  action="store", dest="schema", default=None)
+parser.add_option("-t", "--tables",
+  help="""Name of tables to inspect (default is 'all').  
Support globbing character to select more tables.  ex.: -t Download* will 
generate a model for all tables starting with Download""",
+  action="stor

[sqlalchemy] FYI: SQLAutocode 0.4.1 and 0.5 released

2007-11-13 Thread Simon Pamies

Hi,

I'm very pleased to announce the release of SQLAutocode 0.4.1 and  
0.5. This tool enables SQLAlchemy users to automagically generate  
python code from an existing database layout and even has the  
possibility to generate example code working with the generated  
model. It now supports SA 0.4.x and makes heavy use of new features  
included there.

Because there can be people stuck to SA 0.3 two distinct versions are  
released:
+ 0.4.1 for SA 0.3.x users
+ 0.5 for SA 0.4 users

Both versions will be actively supported in future.

Special thanks goes to Werner F. Bruhin for helping me with some  
issues and for providing helpful tips and code! But I also want to  
thank all people from this list that made this release possible by  
answering to my first mail.

URL: http://code.google.com/p/sqlautocode/

Example usage:
python autocode.py -u postgres://postgres:[EMAIL PROTECTED]/ 
MyDatabase -s myschema -t Download,Person* -e -o t.py -i

Exports all tables starting with Person and the table Download to the  
file t.py and does not create indexing information but some example  
code.

All bugs and feature requests to http://code.google.com/p/sqlautocode/ 
issues/list

If you want to directly contribute code then please sign up for the  
project.

Enjoy!

--
Simon Pamies



--~--~-~--~~~---~--~~
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: How to use GROUP BY and HAVING in orm?

2007-11-13 Thread Michael Bayer


On Nov 13, 2007, at 5:17 PM, Andrew Stromnov wrote:

>
> I have this SQL expression (from 
> http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html)
>
> SELECT b.*
> FROM tagmap bt, bookmark b, tag t
> WHERE bt.tag_id = t.tag_id
> AND (t.name IN ('bookmark', 'webservice', 'semweb'))
> AND b.id = bt.bookmark_id
> GROUP BY b.id
> HAVING COUNT( b.id )=3
>
> How to implement this "HAVING COUNT(b.id) = 3" in ORM?
>

upgrade to trunk revision 3769.  use the having() method on Query in  
conjunction with group_by().

However, that query doesnt seem correct to me; it will fail in  
Postgres because the GROUP BY clause is invalid - it needs to name  
each column in the columns clause of the select (i.e. everything in  
b.*) that is *not* part of the aggregate criterion in having().

--~--~-~--~~~---~--~~
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] How to use GROUP BY and HAVING in orm?

2007-11-13 Thread Andrew Stromnov

I have this SQL expression (from 
http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html)

SELECT b.*
FROM tagmap bt, bookmark b, tag t
WHERE bt.tag_id = t.tag_id
AND (t.name IN ('bookmark', 'webservice', 'semweb'))
AND b.id = bt.bookmark_id
GROUP BY b.id
HAVING COUNT( b.id )=3

How to implement this "HAVING COUNT(b.id) = 3" in ORM?


--~--~-~--~~~---~--~~
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: 2 questions

2007-11-13 Thread Michael Bayer


On Nov 13, 2007, at 2:00 PM, svilen wrote:

>
> i'm not sure if i am doing proper thing at all.
> Something like i need intermediate flush() to get B in the database
> first; then the insert of A will update that B and expire it
> eventualy.
> i.e. i need to have the B record in the DB in order to have the
> aggregation /update working; else i am updating nothing...
>

OK, look into SessionExtension; you can use it for post-flush hooks. 
  

--~--~-~--~~~---~--~~
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: 2 questions

2007-11-13 Thread svilen

On Monday 12 November 2007 23:11:25 Michael Bayer wrote:
> On Nov 12, 2007, at 2:07 PM, [EMAIL PROTECTED] wrote:
> > hi
> > 1st one:  i am saving some object; the mapperExtension of the
> > object fires additional atomic updates of other things elsewhere
> > (aggregator).
> > These things has to be expired/refreshed... if i only knew them.
> > For certain cases, the object knows exactly which are these
> > target things. How (when) is best to expire these instances, i.e.
> > assure that nexttime they are used they will be re-fetched?
> > a) in the mapperext - this would be before the flush?
> > b) later, after flush, marking them somehow ?
>
> the "public" way to mark an instance as expired is
> session.expire(instance).  if you wanted to do this inside the
> mapper extension, i think its OK as long as you do the expire
> *after* the object has been inserted/updated (i.e. in
> after_insert() or after_update()).
lets say A points to B and A.price is accumulated in the B, and that B 
needs be expired.
i've done expire in the A.mapExt.after_insert(). 
but A trouble comes when creating both A and B: they are not not yet 
persistent and the expire() (as well as the refresh() hits this:
session.refresh( g)
  File "sqlalchemy/orm/session.py", line 725, in refresh
if self.query(obj.__class__)._get(obj._instance_key, reload=True) 
is None:
AttributeError: _instance_key

i'm not sure if i am doing proper thing at all.
Something like i need intermediate flush() to get B in the database 
first; then the insert of A will update that B and expire it 
eventualy.
i.e. i need to have the B record in the DB in order to have the 
aggregation /update working; else i am updating nothing...

--~--~-~--~~~---~--~~
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: FYI: SQLAutocode 0.4.1 and 0.5 released

2007-11-13 Thread Simon Pamies



On Nov 13, 6:09 pm, Paul Johnston <[EMAIL PROTECTED]> wrote:
> >Could you perhaps explain the advantages/differences to autoload=True or 
> >perhaps SqlSoup?
>
> To me, it's quite a different approach to managing your database schema.
>
> Using autoload or sqlsoup, the database holds the master definition of
> the schema, and your program automatically loads that.
>
> The other approach is to have you python code be the master definition,
> and keep the database automatically synced to that. Tools like Migrate
> and AutoCode help people using this approach.

+1 for this explanation :-)

As I said before having explicit model definition can come very handy.

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



[sqlalchemy] Re: FYI: SQLAutocode 0.4.1 and 0.5 released

2007-11-13 Thread Simon Pamies



On Nov 13, 4:53 pm, "Werner F. Bruhin" <[EMAIL PROTECTED]> wrote:
> Gerhard Haering wrote:
> > On Tue, 13 Nov 2007 06:00:25 -0800, Simon Pamies <[EMAIL PROTECTED]> wrote:
> > Could you perhaps explain the advantages/differences to autoload=True
>
> I understand that autoload=True has a pretty high overhead.  The script
> actually uses autoload=True but then generates a script for your
> model/schema which you import and then use, so you only have the
> overhead once.>  or perhaps SqlSoup?

three answers from me:

a) I currenlty have two projects where using autoload=True led to some
problems because of a weird database model. SQLAutocode only uses
autoload=True to read the model not to really work with and that made
it possible to generate the model w/o problems and then adapt it
manually for every day use.

b) There are some cases where you want to have full control over the
model (also then when you have a weird database model) and building
the model by yourself is a challenging task :-)

c) For beginners that also want to have the full control w/o knowing
too much about how to build up a model a generated model comes to
hand.

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



[sqlalchemy] Re: ticket 819/r3762

2007-11-13 Thread Michael Bayer


On Nov 13, 2007, at 12:24 PM, svilen wrote:

>
> what a coincidence, 2 days ago we stepped on this bindparam-types
> thing; table.some_decimal_column == decimal.Decimal(5) did not always
> work.
>
> now it mostly works, i think there is one more case that breaks for
> me: when the column itself is hidden in a function.
> e.g.
> table_A = Table( 'Nalichnost', meta,
>Column( 'db_id',   primary_key= True,   type_= Integer, ),
>Column( 'price', Numeric(precision=10,length=2,asdecimal=True), ),
> )
>
> print session.query( A).filter(
>  (func.coalesce( A.price, 0) ==Decimal( 1))
>).all()

do this for now:

func.coalesce(A.price, 0, type_=Decimal)

we have a "generic functions" ticket that eventually will make well  
known functions like "coalesce" smart enough to know that the return  
type should be taken from argument one.

--~--~-~--~~~---~--~~
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] ticket 819/r3762

2007-11-13 Thread svilen

what a coincidence, 2 days ago we stepped on this bindparam-types 
thing; table.some_decimal_column == decimal.Decimal(5) did not always 
work.

now it mostly works, i think there is one more case that breaks for 
me: when the column itself is hidden in a function.
e.g.
table_A = Table( 'Nalichnost', meta,
Column( 'db_id',   primary_key= True,   type_= Integer, ),
Column( 'price', Numeric(precision=10,length=2,asdecimal=True), ),
)

print session.query( A).filter(
  (func.coalesce( A.price, 0) ==Decimal( 1))
).all()

Traceback (most recent call last):
  File "aa.py", line 40, in 
(func.coalesce( Nalichnost.cena, 0) ==Decimal( 1))
  File "sqlalchemy/orm/query.py", line 586, in all
return list(self)
  File "sqlalchemy/orm/query.py", line 634, in __iter__
return self._execute_and_instances(context)
  File "sqlalchemy/orm/query.py", line 637, in _execute_and_instances
result = self.session.execute(querycontext.statement, 
params=self._params, mapper=self.mapper)
  File "sqlalchemy/orm/session.py", line 527, in execute
return self.__connection(engine, 
close_with_result=True).execute(clause, params or {}, **kwargs)
  File "sqlalchemy/engine/base.py", line 784, in execute
return Connection.executors[c](self, object, multiparams, params)
  File "sqlalchemy/engine/base.py", line 835, in execute_clauseelement
return self._execute_compiled(elem.compile(dialect=self.dialect, 
column_keys=keys, inline=len(params) > 1), distilled_params=params)
  File "sqlalchemy/engine/base.py", line 847, in _execute_compiled
self.__execute_raw(context)
  File "sqlalchemy/engine/base.py", line 859, in __execute_raw
self._cursor_execute(context.cursor, context.statement, 
context.parameters[0], context=context)
  File "sqlalchemy/engine/base.py", line 875, in _cursor_execute
raise exceptions.DBAPIError.instance(statement, parameters, e)
sqlalchemy.exceptions.InterfaceError: (InterfaceError) 
Error binding parameter 1 - probably unsupported type. 
u'SELECT "Nalichnost".db_id AS "Nalichnost_db_id", "Nalichnost".cena 
AS "Nalichnost_cena" FROM "Nalichnost" 
WHERE coalesce("Nalichnost".cena, ?) = ? ORDER BY "Nalichnost".oid' 
[0, Decimal("1")]

which the same as what was before r3762 for half of the 
Decimal-passing queries.

i guess the funcs could return anything, so their return type is 
probably unknown generally. For this one, i am generating the query, 
so i could hint the bindparam something about the type of the 
column - but i dont know what.
any idea?

--~--~-~--~~~---~--~~
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: FYI: SQLAutocode 0.4.1 and 0.5 released

2007-11-13 Thread Paul Johnston

Hi,

>Could you perhaps explain the advantages/differences to autoload=True or 
>perhaps SqlSoup?
>  
>
To me, it's quite a different approach to managing your database schema.

Using autoload or sqlsoup, the database holds the master definition of 
the schema, and your program automatically loads that.

The other approach is to have you python code be the master definition, 
and keep the database automatically synced to that. Tools like Migrate 
and AutoCode help people using this approach.

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: SA 0.4 weird behaviour

2007-11-13 Thread jason kirtland

fw wrote:
> Hi,
> 
> I am having a weird problem. I am dealing with some "legacy" database,
> so I subclass TypeDecorator to help clean things up a bit.
> 
> This worked fine in 0.3 but I am now trying to use 0.4 and things
> break in the strangest of way.
> 
> When I run the file below, Python complains about
> 
> AttributeError: 'String' object has no attribute 'padding'
> 
> Now, "padding" is a parameter of the constructor of PaddedIntString.
> So it is not an attribute.
> 
> If I make "padding" an attribute of  PaddedIntString, the error
> dissappears.
> 
> Am I doing something wrong or is this a feature of 0.4???

That sounds like the __repr__ method of AbstractType trying to be 
clever, probably called in a logging operation.  Try providing a 
__repr__ in your type class.

The __repr__ behavior hasn't changed with 0.4, but there might be more 
logging than 0.3.


--~--~-~--~~~---~--~~
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] Joined Table Inheritance and One-to-One headache

2007-11-13 Thread Alexandre Conrad
Hi,

I've attached a test script as I'm confused with what I'm trying to do.

I have the following scenario:

- A Channel object is TV channel:

class Channel:
 pass

- A Playlist object is a piece of a channel's TV program.

class Playlist:
 pass

- A Playlist can be declined as different Playlist types, (joined table 
inheritance). Thus, a PlaylistChannel object is a Playlist of type 
'channel':

class PlaylistChannel(Playlist):
 # type = "channel"
 pass

- A Channel object can only have (none or more) PlaylistChannel objects, 
available via it's "playlists" attribute:

chan = session.query(Channel).get(1)
chan.playlists # returns a list of PlaylistChannel objects.

- A Channel has an "active" attribute which points to one of the 
playlist (PlaylistChannel) of the channel.

chan.active # returns one of the playlist or None (scalar).




Channel.playlists <- (one-to-many) -> PlaylistChannel (list)
Channel.active <- (one-to-one) -> PlaylistChannel (scalar)

But SQLAlchemy seems lost because multiple heritance and foreign_keys 
are defined. It complains about:

"""
sqlalchemy.exceptions.ArgumentError: Error determining primary and/or 
secondary join for relationship 'Channel.active (PlaylistChannel)'. If 
the underlying error cannot be corrected, you should specify the 
'primaryjoin' (and 'secondaryjoin', if there is an association table 
present) keyword arguments to the relation() function (or for backrefs, 
by specifying the backref using the backref() function with keyword 
arguments) to explicitly specify the join conditions. Nested error is 
"Can't determine join between 'channels' and 'Join object on playlists 
playlist_channels'; tables have more than one foreign key constraint 
relationship between them. Please specify the 'onclause' of this join 
explicitly."
"""

And I just can't figure how which alchemy will make my scenario work 
correctly. I've tried playing with primaryjoin/secondaryjoin, but I just 
can't figure it out.

Please see the attached test case for more details. Thanks for your help.

Regards,
-- 
Alex

--~--~-~--~~~---~--~~
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_test.py
Description: application/python


[sqlalchemy] Re: FYI: SQLAutocode 0.4.1 and 0.5 released

2007-11-13 Thread Werner F. Bruhin

Hi Gerhard,

Gerhard Haering wrote:
> On Tue, 13 Nov 2007 06:00:25 -0800, Simon Pamies <[EMAIL PROTECTED]> wrote:
>
>   
>> [...]
>> 
>
>   
>> I'm very pleased to announce the release of SQLAutocode 0.4.1 and 0.5.
>> 
>
>   
>> This tool enables SQLAlchemy users to automagically generate python
>> 
>
>   
>> code from an existing database layout [...]
>> 
>
>
>
> Could you perhaps explain the advantages/differences to autoload=True
I understand that autoload=True has a pretty high overhead.  The script 
actually uses autoload=True but then generates a script for your 
model/schema which you import and then use, so you only have the 
overhead once.
>  or perhaps SqlSoup?
>   
Don't know how SqlSoup works.

Werner

--~--~-~--~~~---~--~~
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: Best Way to Display HTML with Turbogears

2007-11-13 Thread Glauco

Wes Duff ha scritto:
> Hello, I am looking for the best way to display HTML with turbogears. 
> I am building a CMS and need to be able to display HTML when someone 
> views the text content.
>
> I tried to do what the 20min wiki has done, but it did not work.
>
> Any help would be appreciated.
>
> Thanks
>
> Wes Duff
>

a simple textarea?

consider that Zope use a textarea  for editing  sources.



Glauco


-- 
++
  Glauco Uri - Programmatore
glauco(at)allevatori.com 
   
  Sfera Carta Software®  [EMAIL PROTECTED]
  Via Bazzanese,69  Casalecchio di Reno(BO) - Tel. 051591054 
++



--~--~-~--~~~---~--~~
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: threadlocal transactions, engine, and the Session

2007-11-13 Thread Rick Morrison
I use a similar technique with a Pylons controller, but instead of
engine.begin(), I use session.begin(). Then by passing around the session
for all calls made by that controller, I can use Session.execute() for
expression-based and text-based SQL mixed with ORM ops, and it all commits
in one shot on one thread without using threadlocal. This allows the freedom
to open another session in a separate transaction for those odd places where
it's needed, and have arbitrary expression-based SQL execute in that other
transaction -- something I don't think
you'll be able to do with threadlocal + implicit execution.

Rick

--~--~-~--~~~---~--~~
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: 2 questions

2007-11-13 Thread Michael Bayer


On Nov 13, 2007, at 1:05 AM, [EMAIL PROTECTED] wrote:

> hmm, these seems to me like one
>
> def reload( instance, later=False, attribs= ()): ...
>
> with later=True meaning expire(), and non-empty attribs meaning "only
> these".
> but then this is generalizing the API not the implementation...

current function is sqlalchemy.orm.properties.deferred_load().

> mmm i mean i have bunch of inserts and updates without a commit, and
> then several atomic updates come with their own commits. and then one
> more commit at the end.

if youre using the connection passed around to MapperExtension,  
nothing should be committing until the outermost transaction is  
committed.


--~--~-~--~~~---~--~~
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: 2 questions

2007-11-13 Thread Michael Bayer


On Nov 13, 2007, at 5:21 AM, svilen wrote:

>
> clarification for this below; i have non-ORM updates happening inside
> ORM transaction (in after_insert() etc). How to make them use the
> parent transaction? i have a connection there.

thats the connection for the transaction - use that.

--~--~-~--~~~---~--~~
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: SA 0.4 weird behaviour

2007-11-13 Thread Michael Bayer


On Nov 13, 2007, at 2:51 AM, fw wrote:

>
> Hi,
>
> I am having a weird problem. I am dealing with some "legacy" database,
> so I subclass TypeDecorator to help clean things up a bit.
>
> This worked fine in 0.3 but I am now trying to use 0.4 and things
> break in the strangest of way.
>
> When I run the file below, Python complains about
>
>AttributeError: 'String' object has no attribute 'padding'

a full stack trace would be needed to pinpoint who is calling for that  
attribute. 
   

--~--~-~--~~~---~--~~
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: Object Init Bug?

2007-11-13 Thread Michael Bayer


On Nov 13, 2007, at 8:25 AM, Koen Bok wrote:

>
> Hi, I have this strange bug or problem...
>
> I have a basic class like this mapped to a table with the same name.
> Metatype is a relation to the metatype object.
>
> class MetaData(DBObject):
>
>   def __init__(self, metatype, value, item):
>
>   self.metatype = metatype
>   self.item = item
>   self.value = value
>
> class MetaType(DBObject):
>
>   def __init__(self, name, parent=None, offset=None):
>
>   self.parent = parent
>   self.offset = offset
>   self.name = name
>
> Now when I create a MetaData object like this I get the following
> error:
>
 nameMetaType = MetaType('name')
 product = Product(Decimal('20.00'), Decimal('15.00'))
 Session.commit()
>
 MetaData(nameMetaType, 'Koen', product)
>
> Traceback (most recent call last):
>  method testMetabug in test_connection.py at line 16
>MetaData(nameMetaType, 'Koen', product)
>  method init in attributes.py at line 1025
>oldinit(instance, *args, **kwargs)
> TypeError: __init__() takes at most 3 arguments (4 given)
>

what happens if you change the name "MetaData" to something else ?   
your error below seems to indicate that your MetaData class/object is  
getting treated like a SQLAlchemy "MetaData" 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: FYI: SQLAutocode 0.4.1 and 0.5 released

2007-11-13 Thread Gerhard Haering


On Tue, 13 Nov 2007 06:00:25 -0800, Simon Pamies <[EMAIL PROTECTED]> wrote:

> [...]

> I'm very pleased to announce the release of SQLAutocode 0.4.1 and 0.5.

> This tool enables SQLAlchemy users to automagically generate python

> code from an existing database layout [...]



Could you perhaps explain the advantages/differences to autoload=True or 
perhaps SqlSoup?



-- Gerhard


--~--~-~--~~~---~--~~
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] FYI: SQLAutocode 0.4.1 and 0.5 released

2007-11-13 Thread Simon Pamies

Hi,

(sorry if this mail will appear 2 times here but I had problems with
SMTP on gmail)

I'm very pleased to announce the release of SQLAutocode 0.4.1 and 0.5.
This tool enables SQLAlchemy users to automagically generate python
code from an existing database layout and even has the possibility to
generate example code working with the generated model. It now
supports SA 0.4.x and makes heavy use of new features included there.

Because there can be people stuck to SA 0.3 two distinct versions are
released:
+ 0.4.1 for SA 0.3.x users
+ 0.5 for SA 0.4 users

Both versions will be actively supported in future.

Special thanks goes to Werner F. Bruhin for helping me with some
issues and for providing helpful tips and code! But I also want to
thank all people from this list that made this release possible by
answering to my first mail.

URL: http://code.google.com/p/sqlautocode/

Example usage:
python autocode.py -u postgres://postgres:[EMAIL PROTECTED]/MyDatabase
-s myschema -t Download,Person* -e -o t.py -i

Exports all tables starting with Person and the table Download to the
file t.py and does not create indexing information but some example
code.

All bugs and feature requests to 
http://code.google.com/p/sqlautocode/issues/list

If you want to directly contribute code then please sign up for the
project.

Enjoy!

--
Simon Pamies


--~--~-~--~~~---~--~~
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: 2 questions

2007-11-13 Thread Rick Morrison
>in the after_*() there are (mapper, connection, instance) arguments -
>but there's no session. Any way to get to that? mapext.get_session()
>does not look like one

http://www.sqlalchemy.org/docs/04/sqlalchemy_orm.html#docstrings_sqlalchemy.orm_modfunc_object_session

--~--~-~--~~~---~--~~
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: 2 questions

2007-11-13 Thread Rick Morrison
>i have non-ORM updates happening inside
>ORM transaction (in after_insert() etc). How to make them use the
>parent transaction? i have a connection there.

You can pass in the Session and use Session.execute() to reuse the session
connection.

--~--~-~--~~~---~--~~
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] Object Init Bug?

2007-11-13 Thread Koen Bok

Hi, I have this strange bug or problem...

I have a basic class like this mapped to a table with the same name.
Metatype is a relation to the metatype object.

class MetaData(DBObject):

def __init__(self, metatype, value, item):

self.metatype = metatype
self.item = item
self.value = value

class MetaType(DBObject):

def __init__(self, name, parent=None, offset=None):

self.parent = parent
self.offset = offset
self.name = name

Now when I create a MetaData object like this I get the following
error:

>>> nameMetaType = MetaType('name')
>>> product = Product(Decimal('20.00'), Decimal('15.00'))
>>> Session.commit()

>>> MetaData(nameMetaType, 'Koen', product)

Traceback (most recent call last):
  method testMetabug in test_connection.py at line 16
MetaData(nameMetaType, 'Koen', product)
  method init in attributes.py at line 1025
oldinit(instance, *args, **kwargs)
TypeError: __init__() takes at most 3 arguments (4 given)

That seems odd to me, as it clearly takes 4 arguments: self, metatype,
value, item. But I tried it anyway with 3 arguments to see what it
did:

>>> MetaData(nameMetaType, 'Koen')

Traceback (most recent call last):
  method testMetabug in test_connection.py at line 16
MetaData(nameMetaType, 'Koen')
  method init in attributes.py at line 1025
oldinit(instance, *args, **kwargs)
  method __init__ in schema.py at line 1070
self.reflect()
  method reflect in schema.py at line 1193
available = util.OrderedSet(bind.engine.table_names(schema,
AttributeError: 'MetaType' object has no attribute 'engine'

Extra info: The item is a polymorphic mapper to product, employee
etc... I use scoped_session and created my mappers with
Session.mapper.

If you need more info let me know...

Thanks,

Koen


--~--~-~--~~~---~--~~
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: 2 questions

2007-11-13 Thread svilen

clarification for this below; i have non-ORM updates happening inside 
ORM transaction (in after_insert() etc). How to make them use the 
parent transaction? i have a connection there.

> >> and, why atomic updates also have with commit after them? or is
> >> this sqlite-specific?
> >
> > every CRUD operation requires a commit.  DBAPI is always inside
> > of a transaction.
>
> mmm i mean i have bunch of inserts and updates without a commit,
> and then several atomic updates come with their own commits. and
> then one more commit at the end.
> e.g.
> * SA: INFO BEGIN
> * SA: INFO UPDATE "SequenceCounter" SET "curNum"=? WHERE
> "SequenceCounter".db_id = ?
> * SA: INFO [2, 8]
> * SA: INFO INSERT INTO "Nalichnost" (kolvo_kym, cena, obj_id,
> data_godnost, sklad_id, disabled, time_valid, kolvo_ot, stoka_id,
> time_trans) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
> * SA: INFO ['0', '978', None, None, 3, 0, None, '0', 1, None]
> * SA: INFO INSERT INTO "Nalichnost" (kolvo_kym, cena, obj_id,
> data_godnost, sklad_id, disabled, time_valid, kolvo_ot, stoka_id,
> time_trans) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
> * SA: INFO ['0', '94', None, None, 3, 0, None, '0', 1, None]
> ...
> * SA: INFO INSERT INTO "DocItem" (kolichestvo, data_godnost,
> sk_ot_id, number, sk_kym_id, opisanie, cena, stoka_id, doc_id)
> VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
> * SA: INFO ['702', None, None, 3, 5, None, '668', 1, 2]
> * SA: INFO INSERT INTO "DocItem" (kolichestvo, data_godnost,
> sk_ot_id, number, sk_kym_id, opisanie, cena, stoka_id, doc_id)
> VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
> * SA: INFO ['422', None, None, 4, 6, None, '17', 1, 2]
>
> * SA: INFO UPDATE "Nalichnost" SET
> kolvo_ot=(coalesce("Nalichnost".kolvo_ot, ?) + ?) WHERE
> "Nalichnost".db_id = ?
> * SA: INFO [0, 643, 4]
> * SA: INFO COMMIT
> * SA: INFO UPDATE "Nalichnost" SET
> kolvo_kym=(coalesce("Nalichnost".kolvo_kym, ?) + ?) WHERE
> "Nalichnost".db_id = ?
> * SA: INFO [0, 643, None]
> * SA: INFO COMMIT
> * SA: INFO UPDATE "Nalichnost" SET
> kolvo_ot=(coalesce("Nalichnost".kolvo_ot, ?) + ?) WHERE
> "Nalichnost".db_id = ?
> * SA: INFO [0, 702, 5]
> * SA: INFO COMMIT
> * SA: INFO UPDATE "Nalichnost" SET
> kolvo_kym=(coalesce("Nalichnost".kolvo_kym, ?) + ?) WHERE
> "Nalichnost".db_id = ?
> * SA: INFO [0, 702, None]
> * SA: INFO COMMIT
> * SA: INFO UPDATE "Nalichnost" SET
> kolvo_ot=(coalesce("Nalichnost".kolvo_ot, ?) + ?) WHERE
> "Nalichnost".db_id = ?
> * SA: INFO [0, 9, 3]
> * SA: INFO COMMIT
> * SA: INFO COMMIT
>
>
>
> 


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