Edgewall Software

Ticket #986: trac-sqlcolfix-r2944.patch

File trac-sqlcolfix-r2944.patch, 6.0 KB (added by Andres Salomon <dilinger@…>, 6 years ago)

rename 'sql' column to 'query' in report table; against r2944

  • trac/db_default.py

    ------------------------------------------------------------
    revno: 8
    committer: Andres Salomon <dilinger@athenacr.com>
    branch nick: trac-sqlcolfix
    timestamp: Tue 2006-02-28 16:06:21 -0500
    message:
      include the `sql` column rename in the db17 upgrade.
    ------------------------------------------------------------
    revno: 7
    committer: Andres Salomon <dilinger@athenacr.com>
    branch nick: trac-sqlcolfix
    timestamp: Tue 2006-02-28 15:57:49 -0500
    message:
      Rename 'sql' column in report table to 'query', so it doesn't conflict w/
      mysql keyword.
    === modified file 'trac/db_default.py'
     
    148148        Column('id', auto_increment=True), 
    149149        Column('author'), 
    150150        Column('title'), 
    151         Column('sql'), 
     151        Column('query'), 
    152152        Column('description')], 
    153153] 
    154154 
     
    379379             ('name', 'value'), 
    380380               (('database_version', str(db_version)),)), 
    381381           ('report', 
    382              ('author', 'title', 'sql', 'description'), 
     382             ('author', 'title', 'query', 'description'), 
    383383               __mkreports(reports))) 
    384384 
    385385default_config = \ 
  • trac/ticket/report.py

    === modified file 'trac/ticket/report.py'
     
    148148            req.redirect(self.env.href.report()) 
    149149 
    150150        title = req.args.get('title', '') 
    151         sql = req.args.get('sql', '') 
     151        query = req.args.get('query', '') 
    152152        description = req.args.get('description', '') 
    153153        cursor = db.cursor() 
    154         cursor.execute("INSERT INTO report (title,sql,description) " 
    155                        "VALUES (%s,%s,%s)", (title, sql, description)) 
     154        cursor.execute("INSERT INTO report (title,query,description) " 
     155                       "VALUES (%s,%s,%s)", (title, query, description)) 
    156156        id = db.get_last_id(cursor, 'report') 
    157157        db.commit() 
    158158        req.redirect(self.env.href.report(id)) 
     
    176176 
    177177        if not req.args.has_key('cancel'): 
    178178            title = req.args.get('title', '') 
    179             sql = req.args.get('sql', '') 
     179            query = req.args.get('query', '') 
    180180            description = req.args.get('description', '') 
    181181            cursor = db.cursor() 
    182             cursor.execute("UPDATE report SET title=%s,sql=%s,description=%s " 
    183                            "WHERE id=%s", (title, sql, description, id)) 
     182            cursor.execute("UPDATE report SET title=%s,query=%s,description=%s " 
     183                           "WHERE id=%s", (title, query, description, id)) 
    184184            db.commit() 
    185185        req.redirect(self.env.href.report(id)) 
    186186 
     
    204204    def _render_editor(self, req, db, id, copy=False): 
    205205        if id == -1: 
    206206            req.perm.assert_permission('REPORT_CREATE') 
    207             title = sql = description = '' 
     207            title = query = description = '' 
    208208        else: 
    209209            req.perm.assert_permission('REPORT_MODIFY') 
    210210            cursor = db.cursor() 
    211             cursor.execute("SELECT title,description,sql FROM report " 
     211            cursor.execute("SELECT title,description,query FROM report " 
    212212                           "WHERE id=%s", (id,)) 
    213213            row = cursor.fetchone() 
    214214            if not row: 
     
    216216                                     'Invalid Report Number') 
    217217            title = row[0] or '' 
    218218            description = row[1] or '' 
    219             sql = row[2] or '' 
     219            query = row[2] or '' 
    220220 
    221221        if copy: 
    222222            title += ' (copy)' 
     
    233233        req.hdf['report.id'] = id 
    234234        req.hdf['report.mode'] = 'edit' 
    235235        req.hdf['report.title'] = title 
    236         req.hdf['report.sql'] = sql 
     236        req.hdf['report.sql'] = query 
    237237        req.hdf['report.description'] = description 
    238238 
    239239    def _render_view(self, req, db, id): 
     
    426426            description = 'This is a list of reports available.' 
    427427        else: 
    428428            cursor = db.cursor() 
    429             cursor.execute("SELECT title,sql,description from report " 
     429            cursor.execute("SELECT title,query,description from report " 
    430430                           "WHERE id=%s", (id,)) 
    431431            row = cursor.fetchone() 
    432432            if not row: 
    433433                raise util.TracError('Report %d does not exist.' % id, 
    434434                                     'Invalid Report Number') 
    435435            title = row[0] or '' 
    436             sql = row[1] 
     436            query = row[1] 
    437437            description = row[2] or '' 
    438438 
    439         return [title, description, sql] 
     439        return [title, description, query] 
    440440 
    441441    def get_var_args(self, req): 
    442442        report_args = {} 
  • trac/upgrades/db17.py

    === modified file 'trac/upgrades/db17.py'
     
    22 
    33def do_upgrade(env, ver, cursor): 
    44    """Rename the columns `kind` and `change` in the `node_change` table for 
    5     compatibity with MySQL. 
     5    compatibity with MySQL, as well as the `sql` column in the `reports` table. 
    66    """ 
     7    db_connector, _ = DatabaseManager(env)._get_connector() 
     8 
     9    # alter node_change table 
    710    cursor.execute("CREATE TEMP TABLE nc_old AS SELECT * FROM node_change") 
    811    cursor.execute("DROP TABLE node_change") 
    912 
     
    1619        Column('base_rev'), 
    1720        Index(['rev']) 
    1821    ] 
    19     db_connector, _ = DatabaseManager(env)._get_connector() 
    2022    for stmt in db_connector.to_sql(table): 
    2123        cursor.execute(stmt) 
    2224 
    2325    cursor.execute("INSERT INTO node_change (rev,path,node_type,change_type," 
    2426                   "base_path,base_rev) SELECT rev,path,kind,change," 
    2527                   "base_path,base_rev FROM nc_old") 
     28 
     29    # alter report table 
     30    cursor.execute("CREATE TEMP TABLE report_old AS SELECT * FROM report") 
     31    cursor.execute("DROP TABLE report") 
     32 
     33    table = Table('report', key='id')[ 
     34        Column('id', auto_increment=True), 
     35        Column('author'), 
     36        Column('title'), 
     37        Column('query'), 
     38        Column('description') 
     39    ] 
     40    for stmt in db_connector.to_sql(table): 
     41        cursor.execute(stmt) 
     42 
     43    cursor.execute("INSERT INTO report (id,author,title,query,description) " 
     44                   "SELECT id,author,title,sql,description FROM report_old")