PostgresqlPatch: pgsql_patch_02.diff
| File pgsql_patch_02.diff, 53.1 kB (added by brad, 4 years ago) |
|---|
-
scripts/trac-admin
old new 92 92 return 0 93 93 return 1 94 94 95 def env_create(self ):95 def env_create(self, db_str): 96 96 try: 97 self.__env = trac.Environment.Environment (self.envname, create=1)97 self.__env = trac.Environment.Environment (self.envname, 1, db_str) 98 98 return self.__env 99 99 except Exception, e: 100 100 print 'Failed to create environment.', e … … 481 481 dt = trac.siteconfig.__default_templates_dir__ 482 482 prompt = 'Templates directory [%s]> ' % dt 483 483 returnvals.append(raw_input(prompt) or dt) 484 print 485 print " Please enter the database in which you wish to store Trac data." 486 print " Default is 'sqlite', but others are supported:" 487 print " 'sqlite' - SQLite http://www.sqlite.org" 488 print " 'pgsql' - PostgreSQL http://www.postgresql.org" 489 print 490 ddb = "sqlite" 491 prompt = 'database system [%s]> ' % ddb 492 dbms = raw_input(prompt) or ddb 493 returnvals.append(dbms) 494 495 # PostgreSQL - additional questions 496 if dbms == "pgsql": 497 print 498 print " Please enter the host of your PostgreSQL database." 499 print " Default is 'localhost'" 500 print 501 host = "localhost" 502 prompt = "PostgreSQL host [%s]> " % host 503 returnvals.append(raw_input(prompt) or host) 504 505 print 506 print " Please enter the port of your PostgreSQL database." 507 print " Default is '5432'" 508 print 509 port = "5432" 510 prompt = "PostgreSQL port [%s]> " % port 511 returnvals.append(raw_input(prompt) or port) 512 513 print 514 print " Please enter the name of your PostgreSQL database." 515 print " Default is 'trac'" 516 print " Note: This database should not exist, as trac-admin will" \ 517 " attempt to create it." 518 print 519 name = "trac" 520 prompt = "PostgreSQL host [%s]> " % name 521 returnvals.append(raw_input(prompt) or name) 522 523 print 524 print " Please enter the user of your PostgreSQL database." 525 print " Default is 'trac'" 526 print 527 user = "trac" 528 prompt = "PostgreSQL host [%s]> " % user 529 returnvals.append(raw_input(prompt) or user) 530 531 print 532 print " Please enter the password of your PostgreSQL database." 533 print " Default is 'trac'" 534 print 535 password = "trac" 536 prompt = "PostgreSQL host [%s]> " % password 537 returnvals.append(raw_input(prompt) or password) 538 484 539 return returnvals 485 540 486 541 def do_initenv(self, line): … … 491 546 project_name = None 492 547 repository_dir = None 493 548 templates_dir = None 549 db_str = None 494 550 if len(arg) == 1: 495 551 returnvals = self.get_initenv_args() 496 552 project_name = returnvals[0] 497 553 repository_dir = returnvals[1] 498 554 templates_dir = returnvals[2] 499 elif len(arg)!= 3: 555 db_str = returnvals[3] 556 elif len(arg) < 4: 500 557 print 'Wrong number of arguments to initenv %d' % len(arg) 501 558 return 502 559 else: 503 560 project_name = arg[0] 504 561 repository_dir = arg[1] 505 562 templates_dir = arg[2] 563 db_str = arg[3] 564 565 # postgres-specific stuff 566 if db_str.lower() == "pgsql": 567 if len(arg) == 1: 568 host = returnvals[4] 569 port = returnvals[5] 570 database = returnvals[6] 571 user = returnvals[7] 572 password = returnvals[8] 573 elif len(arg) != 9: 574 print 'Wrong number of arguments to initenv %d' % len(arg) 575 print 'For PostgreSQL (after pgsql): <host> <port> <database>' \ 576 ' <user> <password>' 577 return 578 else: 579 host = arg[4] 580 port = arg[5] 581 database = arg[6] 582 user = arg[7] 583 password = arg[8] 584 db_str = "pgsql:\"\",host='%s:%s',database='%s',user='%s'," \ 585 "password='%s'" \ 586 % (host, port, database, user, password) 587 createdb_str = "createdb --host=%s --port=%s --owner=%s " \ 588 "--username=%s %s\n" \ 589 % (host, port, user, user, database) 590 print createdb_str 591 try: 592 # TODO: this is not cross-platform. 593 # for Windows, look at win32pipe.popen() 594 os.popen(createdb_str) 595 except Exception, e: 596 print "Error creating PostgreSQL database: %s" % e 597 print "command: %s" % createdb_str 598 506 599 from svn import util, repos, core 507 600 core.apr_initialize() 508 601 pool = core.svn_pool_create(None) … … 521 614 return 522 615 try: 523 616 print 'Creating and Initializing Project' 524 self.env_create( )617 self.env_create(db_str) 525 618 cnx = self.__env.get_db_cnx() 526 619 print ' Inserting default data' 527 620 self.__env.insert_default_data() … … 685 778 data = data.replace("'", "''") # Escape ' for safe SQL 686 779 f.close() 687 780 688 sql = ("INSERT INTO wiki('version','name','time','author','ipnr','text') " 689 " SELECT 1+ifnull(max(version),0),'%(title)s','%(time)s','%(author)s'," 690 " '%(ipnr)s','%(text)s' FROM wiki WHERE name='%(title)s'" 781 sql = ("INSERT INTO wiki(version,name,time,author,ipnr,text) " 782 " SELECT 1+COALESCE(max(version),0),'%(title)s','%(time)s'," 783 "'%(author)s','%(ipnr)s','%(text)s' " 784 "FROM wiki WHERE name='%(title)s'" 691 785 % {'title':title, 692 786 'time':int(time.time()), 693 787 'author':'trac', -
trac/core.py
old new 1 1 # -*- coding: iso8859-1 -*- 2 2 # 3 3 # Copyright (C) 2003, 2004 Edgewall Software 4 # Copyright (C) 2003, 2004 Jonas Borgstr öm <jonas@edgewall.com>4 # Copyright (C) 2003, 2004 Jonas Borgstr?m <jonas@edgewall.com> 5 5 # 6 6 # Trac is free software; you can redistribute it and/or 7 7 # modify it under the terms of the GNU General Public License as … … 17 17 # along with this program; if not, write to the Free Software 18 18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 19 # 20 # Author: Jonas Borgstr öm <jonas@edgewall.com>20 # Author: Jonas Borgstr?m <jonas@edgewall.com> 21 21 22 22 import os 23 23 import re -
trac/db_default.py
old new 127 127 name text PRIMARY KEY, 128 128 owner text 129 129 ); 130 130 131 CREATE TABLE milestone ( 131 id integer PRIMARY KEY,132 132 name text, 133 time integer, 134 descr text, 133 due integer, -- Due date/time 134 completed integer, -- Completed date/time 135 description text, 135 136 UNIQUE(name) 136 137 ); 137 138 CREATE TABLE version ( … … 175 176 CREATE INDEX session_idx ON session(sid,var_name); 176 177 """ 177 178 179 schema_pgsql = """ 180 CREATE TABLE revision ( 181 rev integer, 182 time integer, 183 author text, 184 message text, 185 CONSTRAINT revision_pkey PRIMARY KEY (rev) 186 ) WITHOUT OIDS; 187 188 CREATE TABLE node_change ( 189 rev integer, 190 name text, 191 change char(1), 192 CONSTRAINT node_change_pkey PRIMARY KEY (rev, name, change) 193 ) WITHOUT OIDS; 194 195 CREATE TABLE auth_cookie ( 196 cookie text, 197 name text, 198 ipnr text, 199 time integer, 200 CONSTRAINT auth_cookie_pkey PRIMARY KEY(cookie, name, ipnr) 201 ) WITHOUT OIDS; 202 203 CREATE TABLE enum ( 204 type text, 205 name text, 206 value text, 207 CONSTRAINT enum_pkey PRIMARY KEY(name,type) 208 ) WITHOUT OIDS; 209 210 CREATE TABLE system ( 211 name text, 212 value text, 213 CONSTRAINT system_pkey PRIMARY KEY(name) 214 ) WITHOUT OIDS; 215 216 CREATE TABLE lock ( 217 name text, 218 owner text, 219 ipnr text, 220 time integer, 221 CONSTRAINT lock_pkey PRIMARY KEY(name) 222 ) WITHOUT OIDS; 223 224 CREATE TABLE ticket ( 225 id integer, 226 time integer, -- the time it was created 227 changetime integer, 228 component text, 229 severity text, 230 priority text, 231 owner text, -- who is this ticket assigned to 232 reporter text, 233 cc text, -- email addresses to notify 234 url text, -- url related to this ticket 235 version text, -- 236 milestone text, -- 237 status text, 238 resolution text, 239 summary text, -- one-line summary 240 description text, -- problem description (long) 241 keywords text, 242 CONSTRAINT ticket_pkey PRIMARY KEY(id) 243 ) WITHOUT OIDS; 244 245 CREATE TABLE ticket_change ( 246 ticket integer, 247 time integer, 248 author text, 249 field text, 250 oldvalue text, 251 newvalue text, 252 CONSTRAINT ticket_change_pkey PRIMARY KEY(ticket, time, field) 253 ) WITHOUT OIDS; 254 255 CREATE TABLE ticket_custom ( 256 ticket integer, 257 name text, 258 value text, 259 CONSTRAINT ticket_custom_pkey PRIMARY KEY(ticket,name) 260 ) WITHOUT OIDS; 261 262 CREATE TABLE report ( 263 id integer, 264 author text, 265 title text, 266 sql text, 267 description text, 268 CONSTRAINT report_pkey PRIMARY KEY(id) 269 ) WITHOUT OIDS; 270 271 CREATE TABLE permission ( 272 username text, -- 273 action text, -- allowable activity 274 CONSTRAINT permission_pkey PRIMARY KEY(username,action) 275 ) WITHOUT OIDS; 276 277 CREATE TABLE component ( 278 name text, 279 owner text, 280 CONSTRAINT component_pkey PRIMARY KEY(name) 281 ) WITHOUT OIDS; 282 283 CREATE TABLE milestone ( 284 name text, 285 due integer, -- Due date/time 286 completed integer, -- Completed date/time 287 description text, 288 CONSTRAINT milestone_pkey PRIMARY KEY(name) 289 ) WITHOUT OIDS; 290 291 CREATE TABLE version ( 292 name text, 293 time integer, 294 CONSTRAINT version_pkey PRIMARY KEY(name) 295 ) WITHOUT OIDS; 296 297 CREATE TABLE wiki ( 298 name text, 299 version integer, 300 time integer, 301 author text, 302 ipnr text, 303 text text, 304 comment text, 305 readonly integer, 306 CONSTRAINT wiki_pkey PRIMARY KEY(name,version) 307 ) WITHOUT OIDS; 308 309 CREATE TABLE attachment ( 310 type text, 311 id text, 312 filename text, 313 size integer, 314 time integer, 315 description text, 316 author text, 317 ipnr text, 318 CONSTRAINT attachment_pkey PRIMARY KEY(type,id,filename) 319 ) WITHOUT OIDS; 320 321 CREATE TABLE session ( 322 sid text, 323 username text, 324 var_name text, 325 var_value text, 326 CONSTRAINT session_pkey PRIMARY KEY(sid,var_name) 327 ) WITHOUT OIDS; 328 329 """ 330 178 331 ## 179 332 ## Default Reports 180 333 ## … … 351 504 (('component1', 'somebody'), 352 505 ('component2', 'somebody'))), 353 506 ('milestone', 354 ('name', 'time'), 355 (('', 0), 356 ('milestone1', 0), 357 ('milestone2', 0), 358 ('milestone3', 0), 359 ('milestone4', 0))), 507 ('name','due','completed'), 508 (('milestone1',0,0), 509 ('milestone2',0,0), 510 ('milestone3',0,0), 511 ('milestone4',0,0))), 360 512 ('version', 361 513 ('name', 'time'), 362 514 (('', 0), … … 414 566 (('trac', 'htdocs_location', '/trac/'), 415 567 ('trac', 'repository_dir', '/var/svn/myrep'), 416 568 ('trac', 'templates_dir', '/usr/lib/trac/templates'), 417 ('trac', 'database', 'sqlite: db/trac.db'),569 ('trac', 'database', 'sqlite:"db/trac.db",timeout=10000'), 418 570 ('trac', 'default_charset', 'iso-8859-15'), 419 571 ('logging', 'log_type', 'none'), 420 572 ('logging', 'log_file', 'trac.log'), -
trac/Milestone.py
old new 157 157 cursor = self.db.cursor() 158 158 self.log.debug("Creating new milestone '%s'" % name) 159 159 cursor.execute("INSERT INTO milestone (id, name, due, description) " 160 "VALUES (NULL, %s, % d, %s)", name, date, description)160 "VALUES (NULL, %s, %s, %s)", name, date, description) 161 161 self.db.commit() 162 162 self.req.redirect(self.env.href.milestone(name)) 163 163 … … 208 208 groups = [] 209 209 if by in ['status', 'resolution', 'severity', 'priority']: 210 210 cursor.execute("SELECT name FROM enum WHERE type = %s " 211 "AND IFNULL(name,'') != '' ORDER BY value", by)211 "AND COALESCE(name,'') != '' ORDER BY value", by) 212 212 elif by in ['component', 'milestone', 'version']: 213 213 cursor.execute("SELECT name FROM %s " 214 "WHERE IFNULL(name,'') != '' ORDER BY name" % by)214 "WHERE COALESCE(name,'') != '' ORDER BY name" % by) 215 215 elif by == 'owner': 216 216 cursor.execute("SELECT DISTINCT owner AS name FROM ticket " 217 217 "ORDER BY owner") -
trac/Query.py
old new 1 1 # -*- coding: iso8859-1 -*- 2 2 # 3 3 # Copyright (C) 2003, 2004 Edgewall Software 4 # Copyright (C) 2003, 2004 Jonas Borgstr öm <jonas@edgewall.com>4 # Copyright (C) 2003, 2004 Jonas Borgstr?m <jonas@edgewall.com> 5 5 # 6 6 # Trac is free software; you can redistribute it and/or 7 7 # modify it under the terms of the GNU General Public License as … … 17 17 # along with this program; if not, write to the Free Software 18 18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 19 # 20 # Author: Jonas Borgstr öm <jonas@edgewall.com>20 # Author: Jonas Borgstr?m <jonas@edgewall.com> 21 21 22 22 from __future__ import nested_scopes 23 23 from time import gmtime, localtime, strftime … … 154 154 sql.append("\nFROM ticket") 155 155 for k in [k for k in cols if k in custom_fields]: 156 156 sql.append("\n LEFT OUTER JOIN ticket_custom AS %s ON " \ 157 "(id=%s.ticket AND %s.name='%s') " % (k, k, k, k))157 "(id=%s.ticket AND %s.name='%s') tc" % (k, k, k, k)) 158 158 159 159 for col in [c for c in ['status', 'resolution', 'priority', 'severity'] 160 160 if c == self.order or c == self.group]: 161 161 sql.append("\n LEFT OUTER JOIN (SELECT name AS %s_name, " \ 162 162 "value AS %s_value " \ 163 "FROM enum WHERE type='%s') " \163 "FROM enum WHERE type='%s') e" \ 164 164 " ON %s_name=%s" % (col, col, col, col, col)) 165 165 for col in [c for c in ['milestone', 'version'] 166 166 if c == self.order or c == self.group]: 167 167 sql.append("\n LEFT OUTER JOIN (SELECT name AS %s_name, " \ 168 "time AS %s_time FROM %s) " \168 "time AS %s_time FROM %s) other" \ 169 169 " ON %s_name=%s" % (col, col, col, col, col)) 170 170 171 171 def get_constraint_sql(name, value, mode, neg): 172 172 value = sql_escape(value[len(mode and '!' or '' + mode):]) 173 173 if mode == '~' and value: 174 return " IFNULL(%s,'') %sLIKE '%%%s%%'" % (174 return "COALESCE(%s,'') %sLIKE '%%%s%%'" % ( 175 175 name, neg and 'NOT ' or '', value) 176 176 elif mode == '^' and value: 177 return " IFNULL(%s,'') %sLIKE '%s%%'" % (177 return "COALESCE(%s,'') %sLIKE '%s%%'" % ( 178 178 name, neg and 'NOT ' or '', value) 179 179 elif mode == '$' and value: 180 return " IFNULL(%s,'') %sLIKE '%%%s'" % (180 return "COALESCE(%s,'') %sLIKE '%%%s'" % ( 181 181 name, neg and 'NOT ' or '', value) 182 182 elif mode == '': 183 return " IFNULL(%s,'')%s='%s'" % (name, neg and '!' or '', value)183 return "COALESCE(%s,'')%s='%s'" % (name, neg and '!' or '', value) 184 184 185 185 clauses = [] 186 186 for k, v in self.constraints.items(): … … 194 194 # Special case for exact matches on multiple values 195 195 if not mode and len(v) > 1: 196 196 inlist = ",".join(["'" + sql_escape(val[neg and 1 or 0:]) + "'" for val in v]) 197 clauses.append(" IFNULL(%s,'') %sIN (%s)" % (k, neg and "NOT " or "", inlist))197 clauses.append("COALESCE(%s,'') %sIN (%s)" % (k, neg and "NOT " or "", inlist)) 198 198 elif len(v) > 1: 199 199 constraint_sql = [get_constraint_sql(k, val, mode, neg) for val in v] 200 200 if neg: … … 214 214 order_cols.insert(0, (self.group, self.groupdesc)) 215 215 for col, desc in order_cols: 216 216 if desc: 217 sql.append(" IFNULL(%s,'')='' DESC," % col)217 sql.append("COALESCE(%s,'')='' DESC," % col) 218 218 else: 219 sql.append(" IFNULL(%s,'')=''," % col)219 sql.append("COALESCE(%s,'')=''," % col) 220 220 if col in ['status', 'resolution', 'priority', 'severity']: 221 221 if desc: 222 222 sql.append("%s_value DESC" % col) … … 224 224 sql.append("%s_value" % col) 225 225 elif col in ['milestone', 'version']: 226 226 if desc: 227 sql.append(" IFNULL(%s_time,0)=0 DESC,%s_time DESC,%s DESC"227 sql.append("COALESCE(%s_time,0)=0 DESC,%s_time DESC,%s DESC" 228 228 % (col, col, col)) 229 229 else: 230 sql.append(" IFNULL(%s_time,0)=0,%s_time,%s"230 sql.append("COALESCE(%s_time,0)=0,%s_time,%s" 231 231 % (col, col, col)) 232 232 else: 233 233 if desc: -
trac/Report.py
old new 1 1 # -*- coding: iso8859-1 -*- 2 2 # 3 3 # Copyright (C) 2003, 2004 Edgewall Software 4 # Copyright (C) 2003, 2004 Jonas Borgstr öm <jonas@edgewall.com>4 # Copyright (C) 2003, 2004 Jonas Borgstr?m <jonas@edgewall.com> 5 5 # 6 6 # Trac is free software; you can redistribute it and/or 7 7 # modify it under the terms of the GNU General Public License as … … 17 17 # along with this program; if not, write to the Free Software 18 18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 19 # 20 # Author: Jonas Borgstr öm <jonas@edgewall.com>20 # Author: Jonas Borgstr?m <jonas@edgewall.com> 21 21 22 22 import os 23 23 import re … … 95 95 sql = 'SELECT id AS report, title FROM report ORDER BY report' 96 96 description = 'This is a list of reports available.' 97 97 else: 98 cursor.execute('SELECT title, sql, description from report ' 99 ' WHERE id=%s', id) 98 sql = "SELECT title, sql, description from report " \ 99 "WHERE id=%s" % id 100 cursor.execute(sql) 100 101 row = cursor.fetchone() 101 102 if not row: 102 103 raise util.TracError('Report %d does not exist.' % id, … … 133 134 sql = self.sql_sub_vars(sql, args) 134 135 if not sql: 135 136 raise util.TracError('Report %s has no SQL query.' % id) 137 self.env.log.debug("sql: %s" % sql) 136 138 cursor.execute(sql) 137 139 138 140 if sql.find('__group__') == -1: … … 140 142 141 143 # FIXME: fetchall should probably not be used. 142 144 info = cursor.fetchall() 143 cols = cursor.rs.col_defs 145 cols = cursor.description 146 144 147 # Escape the values so that they are safe to have as html parameters 145 148 #info = map(lambda row: map(lambda x: escape(x), row), info) 146 149 -
trac/sync.py
old new 1 1 # -*- coding: iso8859-1 -*- 2 2 # 3 3 # Copyright (C) 2003, 2004 Edgewall Software 4 # Copyright (C) 2003, 2004 Jonas Borgstr öm <jonas@edgewall.com>4 # Copyright (C) 2003, 2004 Jonas Borgstr?m <jonas@edgewall.com> 5 5 # 6 6 # Trac is free software; you can redistribute it and/or 7 7 # modify it under the terms of the GNU General Public License as … … 17 17 # along with this program; if not, write to the Free Software 18 18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 19 # 20 # Author: Jonas Borgstr öm <jonas@edgewall.com>20 # Author: Jonas Borgstr?m <jonas@edgewall.com> 21 21 22 22 from svn import fs, util, delta, repos, core 23 from util import sql_escape 23 24 24 25 import posixpath 25 26 … … 35 36 (util.SVN_VER_MAJOR, util.SVN_VER_MINOR, util.SVN_VER_MICRO) 36 37 37 38 cursor = db.cursor() 38 cursor.execute('SELECT ifnull(max(rev), 0) FROM revision') 39 youngest_stored = int(cursor.fetchone()[0]) 39 cursor.execute('SELECT max(rev) FROM revision') 40 row = cursor.fetchone() 41 youngest_stored = 0 42 if row and row[0] != None: 43 youngest_stored = int(row[0]) 44 40 45 max_rev = fs.youngest_rev(fs_ptr, pool) 41 46 num = max_rev - youngest_stored 42 47 offset = youngest_stored + 1 … … 52 57 53 58 date = util.svn_time_from_cstring(date, subpool) / 1000000 54 59 55 cursor.execute ('INSERT INTO revision (rev, time, author, message) ' 56 'VALUES (%s, %s, %s, %s)', rev + offset, date, 57 author, message) 60 sql = "INSERT INTO revision (rev, time, author, message) " \ 61 "VALUES (%s, %s, '%s', '%s')" \ 62 % ( rev + offset, date, sql_escape(author), sql_escape(message) ) 63 cursor.execute (sql) 58 64 insert_change (subpool, fs_ptr, rev + offset, cursor) 59 65 core.svn_pool_clear(subpool) 60 66 -
trac/Session.py
old new 21 21 22 22 import sys 23 23 import time 24 from util import hex_entropy, add_dict_to_hdf, TracError 24 from util import hex_entropy, add_dict_to_hdf, TracError, sql_escape 25 25 26 26 class Session: 27 27 """Basic session handling and per-session storage.""" … … 104 104 self.sid = sid 105 105 curs = self.db.cursor() 106 106 curs.execute("SELECT username,var_name,var_value FROM session" 107 " WHERE sid= %s",self.sid)107 " WHERE sid='%s'" % self.sid) 108 108 rows = curs.fetchall() 109 109 if (not rows # No session data yet 110 110 or rows[0][0] == 'anonymous' # Anon session … … 136 136 if currval == None: 137 137 if key == 'last_visit': # Limit the frequency of purging 138 138 self.purge_expired() 139 curs.execute('INSERT INTO session(sid,username,var_name,var_value)' 140 ' VALUES(%s,%s,%s,%s)', 141 self.sid, self.req.authname, key, val) 139 sql = "INSERT INTO session(sid,username,var_name,var_value) " \ 140 "VALUES('%s','%s','%s','%s')" \ 141 % ( 142 sql_escape(self.sid), sql_escape(self.req.authname), 143 sql_escape(key), sql_escape(val) 144 ) 145 curs.execute(sql) 142 146 else: 143 curs.execute('UPDATE session SET username=%s,var_value=%s' 144 ' WHERE sid=%s AND var_name=%s', 145 self.req.authname, val, self.sid, key) 147 sql = "UPDATE session SET username='%s',var_value='%s' " \ 148 "WHERE sid='%s' AND var_name='%s'" \ 149 % (sql_escape(self.req.authname), 150 sql_escape(str(val)), 151 sql_escape(self.sid), 152 sql_escape(key) 153 ) 154 curs.execute(sql) 146 155 self.db.commit() 147 156 self.vars[key] = val 148 157 -
trac/Roadmap.py
old new 44 44 if show == 'all': 45 45 icalhref += '&show=all' 46 46 query = "SELECT name,due,completed,description FROM milestone " \ 47 "WHERE IFNULL(name,'')!='' " \48 "ORDER BY IFNULL(due,0)=0,due,name"47 "WHERE COALESCE(name,'')!='' " \ 48 "ORDER BY COALESCE(due,0)=0,due,name" 49 49 else: 50 50 self.req.hdf.setValue('roadmap.showall', '1') 51 51 query = "SELECT name,due,completed,description FROM milestone " \ 52 "WHERE IFNULL(name,'')!='' " \53 "AND IFNULL(completed,0)=0 " \54 "ORDER BY IFNULL(due,0)=0,due,name"52 "WHERE COALESCE(name,'')!='' " \ 53 "AND COALESCE(completed,0)=0 " \ 54 "ORDER BY COALESCE(due,0)=0,due,name" 55 55 56 56 if self.req.authname and self.req.authname != 'anonymous': 57 57 icalhref += '&user=' + self.req.authname -
trac/auth.py
old new 1 1 # -*- coding: iso8859-1 -*- 2 2 # 3 3 # Copyright (C) 2003, 2004 Edgewall Software 4 # Copyright (C) 2003, 2004 Jonas Borgstr öm <jonas@edgewall.com>4 # Copyright (C) 2003, 2004 Jonas Borgstr?m <jonas@edgewall.com> 5 5 # 6 6 # Trac is free software; you can redistribute it and/or 7 7 # modify it under the terms of the GNU General Public License as … … 17 17 # along with this program; if not, write to the Free Software 18 18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 19 # 20 # Author: Jonas Borgstr öm <jonas@edgewall.com>20 # Author: Jonas Borgstr?m <jonas@edgewall.com> 21 21 22 22 import time 23 23 import util … … 30 30 if req.incookie.has_key('trac_auth'): 31 31 cursor = db.cursor () 32 32 cookie = req.incookie['trac_auth'].value 33 cursor.execute ("SELECT name FROM auth_cookie " 34 "WHERE cookie=%s AND ipnr=%s" 35 ,cookie, req.remote_addr) 33 sql = "SELECT name FROM auth_cookie " \ 34 "WHERE cookie='%s' AND ipnr='%s'" \ 35 % ( cookie, req.remote_addr ) 36 cursor.execute(sql) 36 37 if cursor.rowcount >= 1: 37 38 self.authname = cursor.fetchone()[0] 38 39 39 40 def login(self, req): 40 41 cursor = self.db.cursor () 41 42 cookie = util.hex_entropy() 42 cursor.execute ("INSERT INTO auth_cookie (cookie, name, ipnr, time)" + 43 "VALUES (%s, %s, %s, %d)", 44 cookie, req.remote_user, req.remote_addr, 45 int(time.time())); 43 sql = "INSERT INTO auth_cookie (cookie, name, ipnr, time)" \ 44 "VALUES ('%s', '%s', '%s', %d)" \ 45 % ( cookie, req.remote_user, req.remote_addr, int(time.time()) ) 46 cursor.execute(sql); 47 48 # cursor.execute ("INSERT INTO auth_cookie (cookie, name, ipnr, time)" + 49 # "VALUES (%s, %s, %s, %d)", 50 # cookie, req.remote_user, req.remote_addr, 51 # int(time.time())); 46 52 self.db.commit () 47 53 self.authname = req.remote_user 48 54 req.outcookie['trac_auth'] = cookie -
trac/Wiki.py
old new 1 1 # -*- coding: iso8859-1 -*- 2 2 # 3 3 # Copyright (C) 2003, 2004 Edgewall Software 4 # Copyright (C) 2003, 2004 Jonas Borgstr öm <jonas@edgewall.com>4 # Copyright (C) 2003, 2004 Jonas Borgstr?m <jonas@edgewall.com> 5 5 # 6 6 # Trac is free software; you can redistribute it and/or 7 7 # modify it under the terms of the GNU General Public License as … … 17 17 # along with this program; if not, write to the Free Software 18 18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 19 # 20 # Author: Jonas Borgstr öm <jonas@edgewall.com>20 # Author: Jonas Borgstr?m <jonas@edgewall.com> 21 21 22 22 import os 23 23 import time … … 27 27 28 28 import perm 29 29 from Module import Module 30 from util import escape, TracError, get_reporter_id 30 from util import escape, TracError, get_reporter_id, sql_escape 31 31 from Session import Session 32 32 from WikiFormatter import * 33 33 … … 56 56 self.name = name 57 57 self.perm = perm 58 58 cursor = self.db.cursor () 59 sql = "SELECT version, text, readonly FROM wiki " 59 60 if version: 60 cursor.execute ('SELECT version, text, readonly FROM wiki ' 61 'WHERE name=%s AND version=%s', 62 name, version) 61 sql += "WHERE name='%s' AND version=%s" % (name, version) 63 62 else: 64 cursor.execute ('SELECT version, text, readonly FROM wiki '65 'WHERE name=%s ORDER BY version DESC LIMIT 1', name)63 sql += "WHERE name='%s' ORDER BY version DESC LIMIT 1" % name 64 cursor.execute(sql) 66 65 row = cursor.fetchone() 67 66 if row: 68 67 self.new = 0 … … 102 101 self.db.commit () 103 102 self.old_readonly = self.readonly 104 103 elif self.modified: 105 cursor.execute ('INSERT INTO WIKI ' 106 '(name, version, time, author, ipnr, text, comment, readonly) ' 107 'VALUES (%s, %s, %s, %s, %s, %s, %s, %s)', 108 self.name, self.version, int(time.time()), 109 author, remote_addr, self.text, comment, self.readonly) 104 sql = "INSERT INTO WIKI " \ 105 "(name, version, time, author, ipnr, text, comment, readonly) " \ 106 "VALUES ('%s', %s, %s, '%s', '%s', '%s', '%s', %s)" \ 107 % ( 108 sql_escape(self.name), self.version, int(time.time()), 109 sql_escape(author), sql_escape(remote_addr), 110 sql_escape(self.text), sql_escape(comment), self.readonly 111 ) 112 cursor.execute (sql) 110 113 self.db.commit () 111 114 self.old_readonly = self.readonly 112 115 self.modified = 0 … … 124 127 This information is used to present a changelog/history for a given page 125 128 """ 126 129 cursor = self.db.cursor () 127 cursor.execute ('SELECT version, time, author, comment, ipnr FROM wiki ' 128 'WHERE name=%s ORDER BY version DESC', pagename) 130 sql = "SELECT version, time, author, comment, ipnr FROM wiki " \ 131 "WHERE name='%s' ORDER BY version DESC" % pagename 132 cursor.execute (sql) 129 133 i = 0 130 134 while 1: 131 135 row = cursor.fetchone() … … 155 159 self.req.redirect(self.env.href.wiki(pagename, version, 1)) 156 160 157 161 cursor = self.db.cursor() 158 cursor.execute ('SELECT text,author,comment,time FROM wiki ' 159 'WHERE name=%s AND (version=%s or version=%s)' 160 'ORDER BY version ASC', pagename, version - 1, version) 162 sql = "SELECT text,author,comment,time FROM wiki " \ 163 "WHERE name='%s' AND (version=%s or version=%s) " \ 164 "ORDER BY version ASC" % (pagename, version - 1, version) 165 cursor.execute (sql) 161 166 res = cursor.fetchall() 162 167 if not res: 163 168 raise TracError('Version %d of page "%s" not found.' 164 169 % (version, pagename), 165 170 'Page Not Found') 166 171 167 172 if len(res) == 1: 168 173 old = '' 169 174 else: -
trac/Environment.py
old new 1 1 # -*- coding: iso8859-1 -*- 2 2 # 3 3 # Copyright (C) 2003, 2004 Edgewall Software 4 # Copyright (C) 2003, 2004 Jonas Borgstr öm <jonas@edgewall.com>4 # Copyright (C) 2003, 2004 Jonas Borgstr?m <jonas@edgewall.com> 5 5 # 6 6 # Trac is free software; you can redistribute it and/or 7 7 # modify it under the terms of the GNU General Public License as … … 17 17 # along with this program; if not, write to the Free Software 18 18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 19 # 20 # Author: Jonas Borgstr öm <jonas@edgewall.com>20 # Author: Jonas Borgstr?m <jonas@edgewall.com> 21 21 # 22 22 # Todo: Move backup and upgrade from db.py 23 23 # … … 50 50 * Project specific templates and wiki macros. 51 51 * wiki and ticket attachments. 52 52 """ 53 def __init__(self, path, create=0 ):53 def __init__(self, path, create=0, db_str=None): 54 54 self.path = path 55 55 if create: 56 self.create( )56 self.create(db_str) 57 57 self.verify() 58 58 self.load_config() 59 59 try: # Use binary I/O on Windows … … 71 71 assert fd.read(26) == 'Trac Environment Version 1' 72 72 fd.close() 73 73 74 def get_db_cnx(self): 75 db_str = self.get_config('trac', 'database', 'sqlite:db/trac.db') 76 assert db_str[:7] == 'sqlite:' 77 db_name = os.path.join(self.path, db_str[7:]) 78 if not os.access(db_name, os.F_OK): 79 raise EnvironmentError, 'Database "%s" not found.' % db_name 74 def get_db_cnx(self, check_exists=1): 75 db_str = self.get_config('trac', 76 'database', 77 'sqlite:"db/trac.db",timeout=10000') 78 79 pos = db_str.find(':') 80 if pos == -1: 81 raise EnvironmentError, 'Connection param must be of form ' \ 82 '(db_module_name):(db_connect_params), the value "%s ' \ 83 'does not match' % db_str 80 84 81 directory = os.path.dirname(db_name) 82 if not os.access(db_name, os.R_OK + os.W_OK) or \ 83 not os.access(directory, os.R_OK + os.W_OK): 84 raise EnvironmentError, \ 85 'The web server user requires read _and_ write permission\n' \ 86 'to the database %s and the directory this file is located in.' % db_name 87 return sqlite.connect(os.path.join(self.path, db_str[7:]), 88 timeout=10000) 85 module_name = db_str[:pos] 86 connect_params = db_str[pos+1:].split(',') 87 88 # following is very crude code for parsing the arguments in the 89 # db_connect_params string 90 kargs = {} 91 arg_list = [] 92 for x in connect_params: 93 pos1 = x.find('=') 94 pos2 = x.find('"') 95 pos3 = x.find("'") 96 if pos1 > -1: 97 if pos2 > -1 and pos2 < pos1: 98 arg_lis
