Changeset 3973

Show
Ignore:
Timestamp:
07/05/08 13:52:52 (5 months ago)
Author:
rharkins
Message:

Merged changes from 0.2.1

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tracformsplugin/branches/tracforms-0.3/0.11/tracforms/formdb.py

    r3851 r3973  
    8787                            (context, state, updater, updated_on) 
    8888                            VALUES (%s, %s, %s, %s) 
    89                         """, context, state, updater, updated_on).last_id 
     89                        """, context, state, updater, updated_on) \ 
     90                        .last_id('tracform_forms', 'tracform_id') 
    9091                else: 
    9192                    cursor(""" 
     
    195196                updated_on      INTEGER NOT NULL 
    196197                ) 
     198            """, 
     199            mysql = """ 
     200            CREATE TABLE tracform_forms( 
     201                tracform_id     INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, 
     202                context         VARCHAR(255) NOT NULL, 
     203                state           TEXT NOT NULL, 
     204                updater         VARCHAR(127) NOT NULL, 
     205                updated_on      INTEGER NOT NULL, 
     206                PRIMARY KEY     (tracform_id) 
     207                ) 
    197208            """) 
    198209        cursor(""" 
     
    203214                old_states      TEXT NOT NULL 
    204215                ); 
     216            """, mysql=""" 
     217            CREATE TABLE tracform_history( 
     218                tracform_id     INTEGER NOT NULL, 
     219                updated_on      INTEGER NOT NULL, 
     220                updater         VARCHAR(127) NOT NULL, 
     221                old_states      TEXT NOT NULL 
     222                ); 
    205223            """) 
    206224 
     
    244262        cursor(""" 
    245263            DROP INDEX tracform_forms_updated_on 
     264            """, mysql=""" 
     265            ALTER TABLE tracform_forms DROP INDEX tracform_forms_updated_on 
    246266            """) 
    247267        cursor(""" 
     
    261281        cursor(""" 
    262282            DROP INDEX tracform_forms_context 
     283            """, mysql=""" 
     284            ALTER TABLE tracform_forms DROP INDEX tracform_forms_context 
    263285            """) 
    264286        cursor(""" 
     
    278300                field           TEXT NOT NULL, 
    279301                updater         TEXT NOT NULL, 
     302                updated_on      INTEGER NOT NULL 
     303                ) 
     304            """, mysql=""" 
     305            CREATE TABLE tracform_fields( 
     306                tracform_id     INTEGER NOT NULL, 
     307                field           VARCHAR(127) NOT NULL, 
     308                updater         VARCHAR(127) NOT NULL, 
    280309                updated_on      INTEGER NOT NULL 
    281310                ) 
  • tracformsplugin/branches/tracforms-0.3/0.11/tracforms/macros.py

    r3927 r3973  
    55from iface import TracFormDBUser, TracPasswordStoreUser 
    66from environment import TracFormEnvironment 
     7from errors import TracFormError, \ 
     8    TracFormTooManyValuesError, \ 
     9    TracFormNoOperationError, \ 
     10    TracFormNoCommandError 
    711 
    812argRE = re.compile('\s*(".*?"|\'.*?\'|\S+)\s*') 
     
    6165        # Setup preliminary context 
    6266        self.page = formatter.req.path_info 
     67        if self.page == '/wiki' or self.page == '/wiki/': 
     68            self.page = '/wiki/WikiStart' 
    6369 
    6470        # Remove leading comments and process commands. 
     
    8389                            try: 
    8490                                fn(*args, **kw) 
     91                            except TracFormError, e: 
     92                                errors.append(str(e)) 
    8593                            except Exception, e: 
    8694                                errors.append(traceback.format_exc()) 
     
    322330        op = getattr(_self, 'op_' + _op, None) 
    323331        if op is None: 
    324             return 'ERROR: No operation named %r' % str(_name
     332            raise TracFormTooManyValuesError(str(_name)
    325333        def partial(*_newargs, **_newkw): 
    326334            if _kw or _newkw: 
     
    347355            fn = getattr(self, 'op_' + op.lower(), None) 
    348356        if fn is None: 
    349             return 'ERROR: No TracForm operation "%s"' % str(op
     357            raise TracFormTooManyValuesError(str(op)
    350358        else: 
    351359            try: 
     
    354362                else: 
    355363                    return str(fn(*args, **kw)) 
     364            except TracFormError, e: 
     365                return '<PRE>' + str(e) + '</PRE>' 
    356366            except Exception, e: 
    357367                return '<PRE>' + traceback.format_exc() + '</PRE>' 
     
    371381                current = current[0] 
    372382            else: 
    373                 return 'ERROR: field %r has too many values' % str(field
     383                raise TracFormTooManyValuesError(str(name)
    374384        return current 
    375385 
  • tracformsplugin/branches/tracforms-0.3/0.11/tracforms/tracdb.py

    r3851 r3973  
    1414        self.cursor = db.cursor() 
    1515        self.log = log 
     16        # Please, please tell me there's a better way to do this... 
     17        dbtypename = type(self.db.cnx).__name__.split('.')[-1] 
     18        self.dbtype = ( 
     19            (dbtypename == 'MySQLConnection' and 'mysql') or 
     20            (dbtypename == 'PostgreSQLConnection' and 'postgres') or 
     21            'sqlite') 
    1622 
    1723    def __del__(self): 
     
    2430        self.db.commit() 
    2531 
    26     def execute(self, sql, *params): 
     32    def execute(self, sql, *params, **variants): 
    2733        if DEBUG_SQL: 
    2834            print >>sys.stderr, 'EXECUTING SQL:\n%s\n\t%r' % (sql, params) 
     35        sql = variants.get(self.dbtype, sql) 
    2936        self.log.debug('EXECUTING SQL:\n%s\n\t%r' % (sql, params)) 
    3037        try: 
     
    7784        return self.at(None, 0, 0) 
    7885 
    79     def __call__(self, sql, *args): 
    80         return self.execute(sql, *args
     86    def __call__(self, sql, *args, **variants): 
     87        return self.execute(sql, *args, **variants
    8188 
    82     @property 
    83     def last_id(self): 
    84         return self("SELECT last_insert_rowid()").value 
     89    def last_id(self, cursor, table, column='id'): 
     90        return self.db.get_last_id(self, table, column) 
    8591 
    8692class DBComponent(Component):