30 |
{ |
{ |
31 |
my $attr = $_; |
my $attr = $_; |
32 |
my $type = $table->attr($attr); |
my $type = $table->attr($attr); |
33 |
|
my $comment = $table->comment($attr); |
34 |
|
$comment =~ s/^\s*(.*?)\s*$/$1/s; |
35 |
$attr =~ s/^_/${name}_/; |
$attr =~ s/^_/${name}_/; |
36 |
$type =~ s/serial$/int" auto_increment="true/; |
$type =~ s/serial$/int" auto_increment="true/; |
37 |
$type .= '" null="false' |
$type .= '" null="false' |
38 |
if $attr eq 'id'; |
if $attr eq 'id'; |
39 |
printf " <field name=\"%s\" type=\"%s\"/>\n", $attr, $type; |
printf " <field name=\"%s\" type=\"%s\">\n", $attr, $type; |
40 |
|
printf " <doc><![CDATA[%s]]></doc>\n", $comment |
41 |
|
if defined($comment) and $comment !~ /^\s*$/; |
42 |
|
printf " </field>\n"; |
43 |
} |
} |
44 |
foreach ($table->rels) |
foreach ($table->rels) |
45 |
{ |
{ |
46 |
my $rel = $_; |
my $rel = $_; |
47 |
|
my $comment = $table->comment($rel); |
48 |
|
$comment =~ s/^\s*(.*?)\s*$/$1/s; |
49 |
$rel =~ s/^_/${name}_/; |
$rel =~ s/^_/${name}_/; |
50 |
printf " <field name=\"%s\" references=\"%s\"/>\n", $rel, $table->rel($_); |
printf " <field name=\"%s\" references=\"%s\">\n", $rel, $table->rel($_); |
51 |
|
printf " <doc><![CDATA[%s]]></doc>\n", $comment |
52 |
|
if defined($comment) and $comment !~ /^\s*$/; |
53 |
|
printf " </field>\n"; |
54 |
} |
} |
55 |
print(" </fields>\n", |
print(" </fields>\n", |
56 |
" <indexes>\n", |
" <indexes>\n", |
70 |
foreach ($table->styles); |
foreach ($table->styles); |
71 |
printf " </hooks>\n"; |
printf " </hooks>\n"; |
72 |
} |
} |
73 |
print " </table>\n"; |
my $comment = $table->comment('__main__'); |
74 |
|
$comment =~ s/^\s*(.*?)\s*$/$1/s; |
75 |
|
printf " <doc><![CDATA[%s]]></doc>\n", $comment |
76 |
|
if defined($comment) and $comment !~ /^\s*$/; |
77 |
|
print " </table>\n"; |
78 |
} |
} |
79 |
print " </tables>\n"; |
print " </tables>\n"; |
80 |
if ($zot->styles) |
if ($zot->styles) |
100 |
my $style = ''; |
my $style = ''; |
101 |
if ($name eq 'history') |
if ($name eq 'history') |
102 |
{ |
{ |
103 |
$style = "add_history"; |
$style = <<'EOF'; |
104 |
|
|
105 |
|
addChunk=lambda node, chunk: node.addChild(libxml2.parseDoc(chunk).children) |
106 |
|
|
107 |
|
self = self.xpathEval('table')[0] |
108 |
|
name = self.prop('name') |
109 |
|
fields = self.xpathEval('fields')[0] |
110 |
|
id = fields.xpathEval('field[@name="id"]')[0] |
111 |
|
type = id.prop('type') |
112 |
|
|
113 |
|
addChunk(fields, '<field name="%s" references="%s"/>' % ('_table', name)) |
114 |
|
addChunk(fields, '<field name="_start_t" type="timestamp"/>') |
115 |
|
addChunk(fields, '<field name="_end_t" type="timestamp"/>') |
116 |
|
self.setProp('name', "_%s_data" % name) |
117 |
|
id.setProp('type', 'bigint') |
118 |
|
|
119 |
|
addChunk(self.parent, ''' |
120 |
|
<table name="%s"> |
121 |
|
<fields> |
122 |
|
<field auto_increment="true" null="false" name="id" type="%s"/> |
123 |
|
</fields> |
124 |
|
<indexes> |
125 |
|
<index type="primary_key"> |
126 |
|
<index_field name="id"/> |
127 |
|
</index> |
128 |
|
</indexes> |
129 |
|
</table>''' % (name, type)) |
130 |
|
]]></hook_impl> |
131 |
|
<hook_impl lang="python" target="ref"><![CDATA[ |
132 |
|
|
133 |
|
import re |
134 |
|
is_data = re.compile('_\w+_data$') |
135 |
|
|
136 |
|
tg = self.table.group.xot.table_groups[self.symbolic].tables |
137 |
|
assert len(tg) == 2, "I don't know what to do with this group" |
138 |
|
id=None |
139 |
|
data=None |
140 |
|
for i in tg: |
141 |
|
if is_data.match(i): |
142 |
|
data = tg[i] |
143 |
|
else: |
144 |
|
id = tg[i] |
145 |
|
assert id and data, "A strange group indeed" |
146 |
|
if self.table.fields.has_key('_table'): |
147 |
|
# transactional table referencing transactional table |
148 |
|
RV=id |
149 |
|
else: |
150 |
|
# other case |
151 |
|
RV=data |
152 |
|
EOF |
153 |
} |
} |
154 |
elsif ($name eq 'account') |
elsif ($name eq 'account') |
155 |
{ |
{ |
156 |
$style = "add_reference('account_plan')"; |
$style = <<'EOF'; |
157 |
|
|
158 |
|
addChunk=lambda node, chunk: node.addChild(libxml2.parseDoc(chunk).children) |
159 |
|
|
160 |
|
fields = self.xpathEval('descendant::fields')[0] |
161 |
|
addChunk(fields, '<field name="account_plan" references="account_plan"/>') |
162 |
|
|
163 |
|
EOF |
164 |
} |
} |
165 |
else |
else |
166 |
{ |
{ |
167 |
$style = "add_reference('$name')"; |
$style = <<'EOF'; |
168 |
|
|
169 |
|
addChunk=lambda node, chunk: node.addChild(libxml2.parseDoc(chunk).children) |
170 |
|
|
171 |
|
fields = self.xpathEval('descendant::fields')[0] |
172 |
|
addChunk(fields, '<field name="entry" references="entry"/>') |
173 |
|
|
174 |
|
|
175 |
|
EOF |
176 |
} |
} |
177 |
|
|
178 |
return $style; |
return $style; |