source: OpenRLabs-Git/deploy/rlabs-docker/web2py-rlabs/gluon/packages/dal/pydal/dialects/ingres.py

main
Last change on this file was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100755
File size: 3.8 KB
Line 
1from .._compat import basestring
2from ..adapters.ingres import Ingres, IngresUnicode
3from .base import SQLDialect
4from . import dialects, sqltype_for
5
6
7@dialects.register_for(Ingres)
8class IngresDialect(SQLDialect):
9    SEQNAME = "ii***lineitemsequence"
10
11    @sqltype_for("text")
12    def type_text(self):
13        return "CLOB"
14
15    @sqltype_for("integer")
16    def type_integer(self):
17        return "INTEGER4"
18
19    @sqltype_for("bigint")
20    def type_bigint(self):
21        return "BIGINT"
22
23    @sqltype_for("double")
24    def type_float(self):
25        return "FLOAT8"
26
27    @sqltype_for("date")
28    def type_date(self):
29        return "ANSIDATE"
30
31    @sqltype_for("time")
32    def type_time(self):
33        return "TIME WITHOUT TIME ZONE"
34
35    @sqltype_for("datetime")
36    def type_datetime(self):
37        return "TIMESTAMP WITHOUT TIME ZONE"
38
39    @sqltype_for("id")
40    def type_id(self):
41        return (
42            "int not null unique with default next value for %s" % self.INGRES_SEQNAME
43        )
44
45    @sqltype_for("big-id")
46    def type_big_id(self):
47        return (
48            "bigint not null unique with default next value for %s"
49            % self.INGRES_SEQNAME
50        )
51
52    @sqltype_for("reference")
53    def type_reference(self):
54        return (
55            "INT, FOREIGN KEY (%(field_name)s) REFERENCES "
56            + "%(foreign_key)s ON DELETE %(on_delete_action)s"
57        )
58
59    @sqltype_for("big-reference")
60    def type_big_reference(self):
61        return (
62            "BIGINT, FOREIGN KEY (%(field_name)s) REFERENCES "
63            + "%(foreign_key)s ON DELETE %(on_delete_action)s"
64        )
65
66    @sqltype_for("reference FK")
67    def type_reference_fk(self):
68        return (
69            ", CONSTRAINT FK_%(constraint_name)s FOREIGN KEY "
70            + "(%(field_name)s) REFERENCES %(foreign_key)s "
71            + "ON DELETE %(on_delete_action)s"
72        )
73
74    @sqltype_for("reference TFK")
75    def type_reference_tfk(self):
76        return (
77            " CONSTRAINT FK_%(constraint_name)s_PK FOREIGN KEY "
78            + "(%(field_name)s) REFERENCES %(foreign_table)s"
79            + "(%(foreign_key)s) ON DELETE %(on_delete_action)s"
80        )
81
82    def left_join(self, val, query_env={}):
83        # Left join must always have an ON clause
84        if not isinstance(val, basestring):
85            val = self.expand(val, query_env=query_env)
86        return "LEFT OUTER JOIN %s" % val
87
88    @property
89    def random(self):
90        return "RANDOM()"
91
92    def select(
93        self,
94        fields,
95        tables,
96        where=None,
97        groupby=None,
98        having=None,
99        orderby=None,
100        limitby=None,
101        distinct=False,
102        for_update=False,
103    ):
104        dst, whr, grp, order, limit, offset, upd = "", "", "", "", "", "", ""
105        if distinct is True:
106            dst = " DISTINCT"
107        elif distinct:
108            dst = " DISTINCT ON (%s)" % distinct
109        if where:
110            whr = " %s" % self.where(where)
111        if groupby:
112            grp = " GROUP BY %s" % groupby
113            if having:
114                grp += " HAVING %s" % having
115        if orderby:
116            order = " ORDER BY %s" % orderby
117        if limitby:
118            (lmin, lmax) = limitby
119            fetch_amt = lmax - lmin
120            if fetch_amt:
121                limit = " FIRST %i" % fetch_amt
122            if lmin:
123                offset = " OFFSET %i" % lmin
124        if for_update:
125            upd = " FOR UPDATE"
126        return "SELECT%s%S %s FROM %s%s%s%s%s%s;" % (
127            dst,
128            limit,
129            fields,
130            tables,
131            whr,
132            grp,
133            order,
134            offset,
135            upd,
136        )
137
138
139@dialects.register_for(IngresUnicode)
140class IngresUnicodeDialect(IngresDialect):
141    @sqltype_for("string")
142    def type_string(self):
143        return "NVARCHAR(%(length)s)"
144
145    @sqltype_for("text")
146    def type_text(self):
147        return "NCLOB"
Note: See TracBrowser for help on using the repository browser.