1 | from ..adapters.informix import Informix, InformixSE |
---|
2 | from .firebird import FireBirdDialect |
---|
3 | from . import dialects, sqltype_for |
---|
4 | |
---|
5 | |
---|
6 | @dialects.register_for(Informix) |
---|
7 | class InformixDialect(FireBirdDialect): |
---|
8 | @sqltype_for("id") |
---|
9 | def type_id(self): |
---|
10 | return "SERIAL" |
---|
11 | |
---|
12 | @sqltype_for("big-id") |
---|
13 | def type_big_id(self): |
---|
14 | return "BIGSERIAL" |
---|
15 | |
---|
16 | @sqltype_for("reference FK") |
---|
17 | def type_reference_fk(self): |
---|
18 | return ( |
---|
19 | "REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s " |
---|
20 | + "CONSTRAINT FK_%(table_name)s_%(field_name)s" |
---|
21 | ) |
---|
22 | |
---|
23 | @sqltype_for("reference TFK") |
---|
24 | def type_reference_tfk(self): |
---|
25 | return ( |
---|
26 | "FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_table)s" |
---|
27 | + "(%(foreign_key)s) ON DELETE %(on_delete_action)s " |
---|
28 | + "CONSTRAINT TFK_%(table_name)s_%(field_name)s" |
---|
29 | ) |
---|
30 | |
---|
31 | @property |
---|
32 | def random(self): |
---|
33 | return "Random()" |
---|
34 | |
---|
35 | def select( |
---|
36 | self, |
---|
37 | fields, |
---|
38 | tables, |
---|
39 | where=None, |
---|
40 | groupby=None, |
---|
41 | having=None, |
---|
42 | orderby=None, |
---|
43 | limitby=None, |
---|
44 | distinct=False, |
---|
45 | for_update=False, |
---|
46 | ): |
---|
47 | dst, whr, grp, order, limit, offset, upd = "", "", "", "", "", "", "" |
---|
48 | if distinct is True: |
---|
49 | dst = " DISTINCT" |
---|
50 | elif distinct: |
---|
51 | dst = " DISTINCT ON (%s)" % distinct |
---|
52 | if where: |
---|
53 | whr = " %s" % self.where(where) |
---|
54 | if groupby: |
---|
55 | grp = " GROUP BY %s" % groupby |
---|
56 | if having: |
---|
57 | grp += " HAVING %s" % having |
---|
58 | if orderby: |
---|
59 | order = " ORDER BY %s" % orderby |
---|
60 | if limitby: |
---|
61 | (lmin, lmax) = limitby |
---|
62 | fetch_amt = lmax - lmin |
---|
63 | if lmin and self.adapter.dbms_version >= 10: |
---|
64 | offset = " SKIP %i" % lmin |
---|
65 | if fetch_amt and self.adapter.dbms_version >= 9: |
---|
66 | limit = " FIRST %i" % fetch_amt |
---|
67 | if for_update: |
---|
68 | upd = " FOR UPDATE" |
---|
69 | return "SELECT%s%s%s %s FROM %s%s%s%s%s;" % ( |
---|
70 | dst, |
---|
71 | offset, |
---|
72 | limit, |
---|
73 | fields, |
---|
74 | tables, |
---|
75 | whr, |
---|
76 | grp, |
---|
77 | order, |
---|
78 | upd, |
---|
79 | ) |
---|
80 | |
---|
81 | |
---|
82 | @dialects.register_for(InformixSE) |
---|
83 | class InformixSEDialect(InformixDialect): |
---|
84 | def select( |
---|
85 | self, |
---|
86 | fields, |
---|
87 | tables, |
---|
88 | where=None, |
---|
89 | groupby=None, |
---|
90 | having=None, |
---|
91 | orderby=None, |
---|
92 | limitby=None, |
---|
93 | distinct=False, |
---|
94 | for_update=False, |
---|
95 | ): |
---|
96 | dst, whr, grp, order, limit, offset, upd = "", "", "", "", "", "", "" |
---|
97 | if distinct is True: |
---|
98 | dst = " DISTINCT" |
---|
99 | elif distinct: |
---|
100 | dst = " DISTINCT ON (%s)" % distinct |
---|
101 | if where: |
---|
102 | whr = " %s" % self.where(where) |
---|
103 | if groupby: |
---|
104 | grp = " GROUP BY %s" % groupby |
---|
105 | if having: |
---|
106 | grp += " HAVING %s" % having |
---|
107 | if orderby: |
---|
108 | order = " ORDER BY %s" % orderby |
---|
109 | if for_update: |
---|
110 | upd = " FOR UPDATE" |
---|
111 | return "SELECT%s %s FROM %s%s%s%s%s%s%s;" % ( |
---|
112 | dst, |
---|
113 | fields, |
---|
114 | tables, |
---|
115 | whr, |
---|
116 | grp, |
---|
117 | order, |
---|
118 | limit, |
---|
119 | offset, |
---|
120 | upd, |
---|
121 | ) |
---|