Thought I'd start over with a brand new application & get the wiki working
but I am running into difficulty before I even get to the wiki part.
I created a brand new app and started by moving my 0.py file into models
then edited db.py like so:
if not request.env.web2py_runtime_gae:
## if NOT running on Google App Engine use SQLite or other DB
db = DAL(settings.database_uri, check_reserved=['oracle'])
## store sessions and tickets there
session.connect(request, response, db=db, migrate=
'db.web2py_session_tamoto')
else:
.
.
.
## create all tables needed by auth if not custom tables
auth.define_tables(username=True, signature=False, migrate=False)
Of course I get an Oracle Error:
Traceback (most recent call last):
File "C:\web2py_src_2.1.1\web2py\gluon\restricted.py", line 209, inrestricted
exec ccode in environment
File
"C:/web2py_src_2.1.1/web2py/applications/TAMOTO/models/db.py"<http://127.0.0.1:8000/admin/default/edit/TAMOTO/models/db.py>
, line 16, in <module>
session.connect(request, response, db=db, migrate=
'db.web2py_session_tamoto')
File "C:\web2py_src_2.1.1\web2py\gluon\globals.py", line 581, in connect
migrate=table_migrate,
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 7092, in define_table
table = self.lazy_define_table(tablename,*fields,**args)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 7124, inlazy_define_table
polymodel=polymodel)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 920, in create_table
self.create_sequence_and_triggers(query,table)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 2865,
increate_sequence_and_triggers
self.execute(query)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 2856, in execute
return self.log_execute(command, args)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 1687, in log_execute
ret = self.cursor.execute(*a, **b)
DatabaseError: ORA-00955: name is already used by an existing object
Thought I might give writing a patch a try so I tried catching and ignoring the
exception in the OracleAdaptor but it does not work.
def create_sequence_and_triggers(self, query, table, **args):
from contrib.pg8000.errors import DatabaseError
err = DatabaseError
tablename = table._tablename
sequence_name = table._sequence_name
trigger_name = table._trigger_name
try:
self.execute(query)
self.execute('CREATE SEQUENCE %s START WITH 1 INCREMENT BY 1
NOMAXVALUE MINVALUE -1;' % sequence_name)
self.execute("""
CREATE OR REPLACE TRIGGER %(trigger_name)s BEFORE INSERT ON
%(tablename)s FOR EACH ROW
DECLARE
curr_val NUMBER;
diff_val NUMBER;
PRAGMA autonomous_transaction;
BEGIN
IF :NEW.id IS NOT NULL THEN
EXECUTE IMMEDIATE 'SELECT %(sequence_name)s.nextval
FROM dual' INTO curr_val;
diff_val := :NEW.id - curr_val - 1;
IF diff_val != 0 THEN
EXECUTE IMMEDIATE 'alter sequence %(sequence_name)s
increment by '|| diff_val;
EXECUTE IMMEDIATE 'SELECT %(sequence_name)s.nextval
FROM dual' INTO curr_val;
EXECUTE IMMEDIATE 'alter sequence %(sequence_name)s
increment by 1';
END IF;
END IF;
SELECT %(sequence_name)s.nextval INTO :NEW.id FROM DUAL;
END;
""" % dict(trigger_name=trigger_name, tablename=tablename,
sequence_name=sequence_name))
except DatabaseError as error:
if 'ORA-00955' in error.value():
pass
--