|
@@ -61,6 +61,7 @@ def __init__(self, item, parent=None): |
|
|
self.editPkey.textChanged.connect(self.updateSql) |
|
|
self.editStart.textChanged.connect(self.updateSql) |
|
|
self.editEnd.textChanged.connect(self.updateSql) |
|
|
self.editUser.textChanged.connect(self.updateSql) |
|
|
|
|
|
self.updateSql() |
|
|
|
|
@@ -114,6 +115,7 @@ def updateSql(self): |
|
|
self.colPkey = self.db.connector.quoteId(self.editPkey.text()) |
|
|
self.colStart = self.db.connector.quoteId(self.editStart.text()) |
|
|
self.colEnd = self.db.connector.quoteId(self.editEnd.text()) |
|
|
self.colUser = self.db.connector.quoteId(self.editUser.text()) |
|
|
|
|
|
self.columns = [self.db.connector.quoteId(x.name) for x in self.table.fields()] |
|
|
|
|
@@ -173,8 +175,8 @@ def showHelp(self): |
|
|
QMessageBox.information(self, "Help", helpText) |
|
|
|
|
|
def sql_alterTable(self): |
|
|
return u"ALTER TABLE %s ADD %s serial, ADD %s timestamp, ADD %s timestamp;" % ( |
|
|
self.schematable, self.colPkey, self.colStart, self.colEnd) |
|
|
return u"ALTER TABLE %s ADD %s serial, ADD %s timestamp, ADD %s timestamp, ADD %s varchar;" % ( |
|
|
self.schematable, self.colPkey, self.colStart, self.colEnd, self.colUser) |
|
|
|
|
|
def sql_setPkey(self): |
|
|
return u"ALTER TABLE %s DROP CONSTRAINT %s, ADD PRIMARY KEY (%s);" % ( |
|
@@ -209,6 +211,7 @@ def sql_functions(self): |
|
|
IF NEW.%(end)s IS NULL THEN |
|
|
INSERT INTO %(schematable)s (%(cols)s, %(start)s, %(end)s) VALUES (%(oldcols)s, OLD.%(start)s, current_timestamp); |
|
|
NEW.%(start)s = current_timestamp; |
|
|
NEW.%(user)s = current_user; |
|
|
END IF; |
|
|
RETURN NEW; |
|
|
END; |
|
@@ -222,12 +225,13 @@ def sql_functions(self): |
|
|
if NEW.%(start)s IS NULL then |
|
|
NEW.%(start)s = now(); |
|
|
NEW.%(end)s = null; |
|
|
NEW.%(user)s = current_user; |
|
|
end if; |
|
|
RETURN NEW; |
|
|
END; |
|
|
$$ |
|
|
LANGUAGE 'plpgsql';""" % {'view': self.view, 'schematable': self.schematable, 'cols': cols, 'oldcols': old_cols, |
|
|
'start': self.colStart, 'end': self.colEnd, 'func_at_time': self.func_at_time, |
|
|
'start': self.colStart, 'end': self.colEnd, 'user': self.colUser, 'func_at_time': self.func_at_time, |
|
|
'func_update': self.func_update, 'func_insert': self.func_insert} |
|
|
return sql |
|
|
|
|
|