Changeset 4406
- Timestamp:
- 03/28/09 22:38:19 (4 years ago)
- Files:
-
- 1 modified
-
branch/merger/sqlitedb.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branch/merger/sqlitedb.py
r4404 r4406 77 77 res = old_cursor.execute("pragma table_info(%s)" % name) 78 78 old_table_info = res.fetchall() 79 old_by_col = {} 80 for col in old_table_info: 81 colname = col.pop('name') 82 old_by_col[colname] = col 79 83 80 for col_info in old_table_info: 81 name = col_info.pop('name') 82 83 if name not in new_by_col: 84 for cname, cinfo in old_by_col.iteritems(): 85 if cname not in new_by_col: 84 86 # sqlite can't handle deletion of columns, this merge 85 87 # can't be done. … … 87 89 "contains a column named '%s' which no longer " 88 90 "exists in the new table, sqlite can't handle " 89 "this." % (name, c ol_info['name']))90 elif c ol_info != new_by_col[name]:91 "this." % (name, cname)) 92 elif cinfo != new_by_col[cname]: 91 93 # sqlite also can't handle changes in column type and 92 94 # others 93 95 raise Exception("The table '%s' in the old database " 94 96 "differs in the column named '%s'. (%r != %r)" % ( 95 col_info, new_by_col[name]))97 name, cname, cinfo, new_by_col[cname])) 96 98 97 del new_by_col[ name]99 del new_by_col[cname] 98 100 99 101 # Attempt to create new columns 100 print102 # XXX not checking if they reference other columns yet. 101 103 for cname, cinfo in new_by_col.iteritems(): 102 print cname, cinfo, "<<<" 103 # XXX ToDo 104 if cinfo['pk']: 105 # sqlite doesn't allow creating new columns as primary key 106 raise Exception("The table '%s' in the new database " 107 "has a new column named '%s' which is a primary " 108 "key, but sqlite can't handle this." % ( 109 name, cname)) 110 111 query = "ALTER TABLE %s ADD COLUMN %s %s" % ( 112 name, cname, cinfo['type']) 113 if cinfo['notnull']: 114 query += " NOT NULL" 115 if cinfo['dflt_value']: 116 query += " DEFAULT %s" % cinfo['dflt_value'] 117 old_cursor.execute(query) 104 118 105 119 # XXX check for triggers here
