@@ -61,6 +61,7 @@ def __init__(self, item, parent=None):
61
61
self .editPkey .textChanged .connect (self .updateSql )
62
62
self .editStart .textChanged .connect (self .updateSql )
63
63
self .editEnd .textChanged .connect (self .updateSql )
64
+ self .editUser .textChanged .connect (self .updateSql )
64
65
65
66
self .updateSql ()
66
67
@@ -114,6 +115,7 @@ def updateSql(self):
114
115
self .colPkey = self .db .connector .quoteId (self .editPkey .text ())
115
116
self .colStart = self .db .connector .quoteId (self .editStart .text ())
116
117
self .colEnd = self .db .connector .quoteId (self .editEnd .text ())
118
+ self .colUser = self .db .connector .quoteId (self .editUser .text ())
117
119
118
120
self .columns = [self .db .connector .quoteId (x .name ) for x in self .table .fields ()]
119
121
@@ -173,8 +175,8 @@ def showHelp(self):
173
175
QMessageBox .information (self , "Help" , helpText )
174
176
175
177
def sql_alterTable (self ):
176
- return u"ALTER TABLE %s ADD %s serial, ADD %s timestamp, ADD %s timestamp;" % (
177
- self .schematable , self .colPkey , self .colStart , self .colEnd )
178
+ return u"ALTER TABLE %s ADD %s serial, ADD %s timestamp, ADD %s timestamp, ADD %s varchar ;" % (
179
+ self .schematable , self .colPkey , self .colStart , self .colEnd , self . colUser )
178
180
179
181
def sql_setPkey (self ):
180
182
return u"ALTER TABLE %s DROP CONSTRAINT %s, ADD PRIMARY KEY (%s);" % (
@@ -209,6 +211,7 @@ def sql_functions(self):
209
211
IF NEW.%(end)s IS NULL THEN
210
212
INSERT INTO %(schematable)s (%(cols)s, %(start)s, %(end)s) VALUES (%(oldcols)s, OLD.%(start)s, current_timestamp);
211
213
NEW.%(start)s = current_timestamp;
214
+ NEW.%(user)s = current_user;
212
215
END IF;
213
216
RETURN NEW;
214
217
END;
@@ -222,12 +225,13 @@ def sql_functions(self):
222
225
if NEW.%(start)s IS NULL then
223
226
NEW.%(start)s = now();
224
227
NEW.%(end)s = null;
228
+ NEW.%(user)s = current_user;
225
229
end if;
226
230
RETURN NEW;
227
231
END;
228
232
$$
229
233
LANGUAGE 'plpgsql';""" % {'view' : self .view , 'schematable' : self .schematable , 'cols' : cols , 'oldcols' : old_cols ,
230
- 'start' : self .colStart , 'end' : self .colEnd , 'func_at_time' : self .func_at_time ,
234
+ 'start' : self .colStart , 'end' : self .colEnd , 'user' : self . colUser , ' func_at_time' : self .func_at_time ,
231
235
'func_update' : self .func_update , 'func_insert' : self .func_insert }
232
236
return sql
233
237
0 commit comments