Changeset 3973
- Timestamp:
- 07/05/08 13:52:52 (5 months ago)
- Files:
-
- tracformsplugin/branches/tracforms-0.3/0.11/tracforms/errors.py (copied) (copied from tracformsplugin/branches/tracforms-0.2/0.11/tracforms/errors.py)
- tracformsplugin/branches/tracforms-0.3/0.11/tracforms/formdb.py (modified) (6 diffs)
- tracformsplugin/branches/tracforms-0.3/0.11/tracforms/macros.py (modified) (7 diffs)
- tracformsplugin/branches/tracforms-0.3/0.11/tracforms/tracdb.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tracformsplugin/branches/tracforms-0.3/0.11/tracforms/formdb.py
r3851 r3973 87 87 (context, state, updater, updated_on) 88 88 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') 90 91 else: 91 92 cursor(""" … … 195 196 updated_on INTEGER NOT NULL 196 197 ) 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 ) 197 208 """) 198 209 cursor(""" … … 203 214 old_states TEXT NOT NULL 204 215 ); 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 ); 205 223 """) 206 224 … … 244 262 cursor(""" 245 263 DROP INDEX tracform_forms_updated_on 264 """, mysql=""" 265 ALTER TABLE tracform_forms DROP INDEX tracform_forms_updated_on 246 266 """) 247 267 cursor(""" … … 261 281 cursor(""" 262 282 DROP INDEX tracform_forms_context 283 """, mysql=""" 284 ALTER TABLE tracform_forms DROP INDEX tracform_forms_context 263 285 """) 264 286 cursor(""" … … 278 300 field TEXT NOT NULL, 279 301 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, 280 309 updated_on INTEGER NOT NULL 281 310 ) tracformsplugin/branches/tracforms-0.3/0.11/tracforms/macros.py
r3927 r3973 5 5 from iface import TracFormDBUser, TracPasswordStoreUser 6 6 from environment import TracFormEnvironment 7 from errors import TracFormError, \ 8 TracFormTooManyValuesError, \ 9 TracFormNoOperationError, \ 10 TracFormNoCommandError 7 11 8 12 argRE = re.compile('\s*(".*?"|\'.*?\'|\S+)\s*') … … 61 65 # Setup preliminary context 62 66 self.page = formatter.req.path_info 67 if self.page == '/wiki' or self.page == '/wiki/': 68 self.page = '/wiki/WikiStart' 63 69 64 70 # Remove leading comments and process commands. … … 83 89 try: 84 90 fn(*args, **kw) 91 except TracFormError, e: 92 errors.append(str(e)) 85 93 except Exception, e: 86 94 errors.append(traceback.format_exc()) … … 322 330 op = getattr(_self, 'op_' + _op, None) 323 331 if op is None: 324 r eturn 'ERROR: No operation named %r' % str(_name)332 raise TracFormTooManyValuesError(str(_name)) 325 333 def partial(*_newargs, **_newkw): 326 334 if _kw or _newkw: … … 347 355 fn = getattr(self, 'op_' + op.lower(), None) 348 356 if fn is None: 349 r eturn 'ERROR: No TracForm operation "%s"' % str(op)357 raise TracFormTooManyValuesError(str(op)) 350 358 else: 351 359 try: … … 354 362 else: 355 363 return str(fn(*args, **kw)) 364 except TracFormError, e: 365 return '<PRE>' + str(e) + '</PRE>' 356 366 except Exception, e: 357 367 return '<PRE>' + traceback.format_exc() + '</PRE>' … … 371 381 current = current[0] 372 382 else: 373 r eturn 'ERROR: field %r has too many values' % str(field)383 raise TracFormTooManyValuesError(str(name)) 374 384 return current 375 385 tracformsplugin/branches/tracforms-0.3/0.11/tracforms/tracdb.py
r3851 r3973 14 14 self.cursor = db.cursor() 15 15 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') 16 22 17 23 def __del__(self): … … 24 30 self.db.commit() 25 31 26 def execute(self, sql, *params ):32 def execute(self, sql, *params, **variants): 27 33 if DEBUG_SQL: 28 34 print >>sys.stderr, 'EXECUTING SQL:\n%s\n\t%r' % (sql, params) 35 sql = variants.get(self.dbtype, sql) 29 36 self.log.debug('EXECUTING SQL:\n%s\n\t%r' % (sql, params)) 30 37 try: … … 77 84 return self.at(None, 0, 0) 78 85 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) 81 88 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) 85 91 86 92 class DBComponent(Component):