[Formed-commits] r309 - in trunk: . formed/formed/plugins/export
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Feb 6 19:34:40 CET 2009
Author: teichmann
Date: 2009-02-06 19:34:38 +0100 (Fri, 06 Feb 2009)
New Revision: 309
Modified:
trunk/ChangeLog
trunk/formed/formed/plugins/export/sql.py
Log:
SQL exporter: replace '-' in names by '_'.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-02-06 17:41:29 UTC (rev 308)
+++ trunk/ChangeLog 2009-02-06 18:34:38 UTC (rev 309)
@@ -1,5 +1,10 @@
2009-02-09 Sascha L. Teichmanne <teichmann at intevation.de>
+ * formed/formed/plugins/export/sql.py: replace '-' in names
+ by '_'.
+
+2009-02-09 Sascha L. Teichmanne <teichmann at intevation.de>
+
* formed/formed/plugins/export/sql.py: to figure ou which
tables are equal the insert statememnts are lower cased
and sorted before they are compared. This reduces the number
Modified: trunk/formed/formed/plugins/export/sql.py
===================================================================
--- trunk/formed/formed/plugins/export/sql.py 2009-02-06 17:41:29 UTC (rev 308)
+++ trunk/formed/formed/plugins/export/sql.py 2009-02-06 18:34:38 UTC (rev 309)
@@ -101,6 +101,9 @@
def sqlQuote(name):
return name.replace("'", "''")
+def sqlName(name):
+ return name.replace("-", "_")
+
class RelationAnonymizer:
def __init__(self, raw_table, table):
@@ -226,7 +229,7 @@
bins = [b.lower() for b in other.inserts]
ains.sort()
bins.sort()
- return cmp(ains, bins)
+ return ains == bins
class SchemaCreator:
@@ -317,6 +320,7 @@
def _createDate(self, date):
name = date.getName()
if not name: return
+ name = sqlName(name)
table = self.tableStack[-1]
table.appendColumn(Column(name, "DATE", func=date.getFunction()))
@@ -324,6 +328,7 @@
def _createBool(self, bool):
name = bool.getName()
if not name: return
+ name = sqlName(name)
table = self.tableStack[-1]
#table.appendColumn("%s BOOLEAN" % name)
kvs = {
@@ -361,6 +366,7 @@
def _createText(self, text):
name = text.getName()
if not name: return
+ name = sqlName(name)
table = self.tableStack[-1]
length = text.getMaxLength()
if length:
@@ -372,6 +378,7 @@
def _createTextArea(self, text):
name = text.getName()
if not name: return
+ name = sqlName(name)
table = self.tableStack[-1]
table.appendColumn(Column(name, "TEXT", func=text.getFunction()))
@@ -379,6 +386,7 @@
def _createInteger(self, integer):
name = integer.getName()
if not name: return
+ name = sqlName(name)
table = self.tableStack[-1]
table.appendColumn(Column(name, "INTEGER", func=integer.getFunction()))
@@ -386,6 +394,7 @@
def _createChoice(self, choice):
name = choice.getName()
if not name: return
+ name = sqlName(name)
if choice.getMultiple():
print >> sys.stderr, "WARNING: No support for multiple choices."
@@ -460,6 +469,7 @@
def _createRadioGroup(self, radio):
name = radio.getName()
if not name: return
+ name = sqlName(name)
selected = radio.getSelected()
if selected:
found = False
@@ -523,6 +533,7 @@
if repeat:
name = group.getName()
if name:
+ name = sqlName(name)
parent = self.tableStack[-1]
table = Table("%s_tbl" % name, parent, group)
table.appendColumn(Column("id", "SERIAL PRIMARY KEY NOT NULL", False))
@@ -669,12 +680,12 @@
raw_table, joins, linear = tup
table = raw_table.name
for page in linear:
- table_name = "%s_tbl" % page.getName()
+ table_name = "%s_tbl" % sqlName(page.getName())
if table_name in page_tables:
marked.add(table_name)
else:
pfeil("CREATE OR REPLACE VIEW %s_view AS SELECT\n" \
- % page.getName())
+ % sqlName(page.getName()))
ws = [
w.getName()
@@ -707,14 +718,14 @@
pfeil(VIEW_WHERE_CLAUSE)
pfeil("\n")
- pfeil(UPDATE_RULE % (page.getName(), page.getName(), table))
+ pfeil(UPDATE_RULE % (sqlName(page.getName()), sqlName(page.getName()), table))
pfeil(",\n".join([" %s = NEW.%s" % (n, n) for n in ws]))
pfeil("\n")
pfeil("WHERE id = NEW.id;\n\n")
- pn = page.getName()
-
- vn = "%s_view" % pn
+ pn = sqlName(page.getName())
+
+ vn = "%s_view" % sqlName(pn)
pfeil(GRANT_SELECT % (vn, ':cm_ka_group'))
pfeil(GRANT_UPDATE % (vn, ':cm_ka_group'))
pfeil(GRANT_SELECT % (vn, ':admin_ka_group'))
@@ -728,7 +739,7 @@
for pt in page_tables:
if pt not in marked \
and not arr[page_tables.index(pt)][2]:
- pfeil("CREATE OR REPLACE VIEW %s_page_view AS SELECT\n" % pt)
+ pfeil("CREATE OR REPLACE VIEW %s_page_view AS SELECT\n" % sqlName(pt))
group = None
for tup2 in arr:
@@ -762,7 +773,7 @@
pfeil("\n")
pfeil("WHERE id = NEW.id;\n\n")
- vn = "%s_page_view" % pt
+ vn = "%s_page_view" % sqlName(pt)
pfeil(GRANT_SELECT % (vn, ':cm_ka_group'))
pfeil(GRANT_UPDATE % (vn, ':cm_ka_group'))
pfeil(GRANT_SELECT % (vn, ':admin_ka_group'))
@@ -778,8 +789,9 @@
for tup in arr:
raw_table, joins, linear = tup
table = raw_table.name
+ tab = sqlName(table)
pfeil("CREATE OR REPLACE VIEW %s_view\nAS SELECT %s.* FROM %s\n" % (
- table, table, table))
+ tab, tab, tab))
njoins = joins
oldTable = table
@@ -802,26 +814,27 @@
pfeil(VIEW_WHERE_CLAUSE)
pfeil("\n")
- pfeil(UPDATE_RULE % (table, table, table))
+
+ pfeil(UPDATE_RULE % (tab, tab, tab))
pfeil(",\n".join(
[" %s = NEW.%s" % (c.name, c.name)
for c in raw_table.columns if c.accessible]))
pfeil("\n")
pfeil("WHERE id = NEW.id;\n\n")
- pfeil(FORBID_DELETE_RULE % (table, table))
+ pfeil(FORBID_DELETE_RULE % (tab, tab))
pfeil("\n")
- pfeil(FORBID_INSERT_RULE % (table, table))
+ pfeil(FORBID_INSERT_RULE % (tab, tab))
pfeil("\n")
- vn = "%s_view" % table
+ vn = "%s_view" % tab
pfeil(GRANT_SELECT % (vn, ':cm_ka_group'))
pfeil(GRANT_UPDATE % (vn, ':cm_ka_group'))
pfeil(GRANT_SELECT % (vn, ':admin_ka_group'))
pfeil("\n")
# anonymization view
- self._writeAnonymizationView(pfeil, raw_table, table)
+ self._writeAnonymizationView(pfeil, raw_table, tab)
caseAnonymizer.addAnoymizer(RelationAnonymizer(raw_table, table))
More information about the Formed-commits
mailing list