The fact is, indices must be created only once. If you have the index
already that line fails. You handle the exception at the web2py level
but the transcation still aborts. Try:

try:
    db.executesql("CREATE UNIQUE INDEX indexO ON secretnum
(primocod);")
except:
    db.rollback()

On Nov 18, 2:34 pm, leone <handja...@gmail.com> wrote:
> Peraphs I found the piece of code that creates the problem.
> After table definition I have:
> try:
>     db.executesql("CREATE UNIQUE INDEX indexO ON secretnum
> (primocod);")
> except:
>     pass
> if I comment these rows all runs, even if DAL and table definition is
> in plugin_secretnum.py
>
> On 18 Nov, 21:11, leone <handja...@gmail.com> wrote:
>
> > If I put DAL and table definition in db.py all is Ok and sql.log
> > report:
> > CREATE TABLE secretnum(
> >         id SERIAL PRIMARY KEY,
> >         primocod VARCHAR(8),
> >         secondocod VARCHAR(5),
> >         terzocod VARCHAR(5),
> >         username VARCHAR(20),
> >         attivo CHAR(1)
> > );
> > success!
>
> > If I put DAL and table definition in plugin_secretnum.py in models I
> > have error:
>
> > row = db(db.secretnum.primocod == primocod).select()
> >   File "/home/eugenio/web2py/web2py/gluon/sql.py", line 2901, in
> > select
> >     rows = response(query)
> >   File "/home/eugenio/web2py/web2py/gluon/sql.py", line 2896, in
> > response
> >     db._execute(query)
> >   File "/home/eugenio/web2py/web2py/gluon/sql.py", line 909, in
> > <lambda>
> >     self._execute = lambda *a, **b: self._cursor.execute(*a, **b)
> > InternalError: current transaction is aborted, commands ignored until
> > end of transaction block
>
> > .......and sql.log have no new message.
>
> > On 18 Nov, 21:01, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > what is in sql.log?
>
> > > On Nov 18, 10:54 am, leone <handja...@gmail.com> wrote:
>
> > > > Grrr.
> > > > I can't uderstand. I have code that runs in sqlite bat non in
> > > > postgresql.
> > > > Apparently it is very simple.
> > > > Where is my error??
>
> > > > db.define_table('secretnum',
> > > >                 Field('primocod','string', length=8),
> > > >                 Field('secondocod','string', length=5),
> > > >                 Field('terzocod','string', length=5),
> > > >                 Field('username','string', length=20),
> > > >                 Field('attivo','boolean', default=True),
> > > >             )
> > > > row = db(db.secretnum.primocod == '12345678').select()
>
> > > > Error:
> > > > File "/home/eugenio/web2py/web2py/gluon/sql.py", line 2901, in select
> > > >     rows = response(query)
> > > >   File "/home/eugenio/web2py/web2py/gluon/sql.py", line 2896, in
> > > > response
> > > >     db._execute(query)
> > > >   File "/home/eugenio/web2py/web2py/gluon/sql.py", line 909, in
> > > > <lambda>
> > > >     self._execute = lambda *a, **b: self._cursor.execute(*a, **b)
> > > > InternalError: current transaction is aborted, commands ignored until
> > > > end of transaction block
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to