1 | from .base import SQLAdapter |
---|
2 | from . import adapters, with_connection_or_raise |
---|
3 | |
---|
4 | |
---|
5 | @adapters.register_for("informix") |
---|
6 | class Informix(SQLAdapter): |
---|
7 | dbengine = "informix" |
---|
8 | drivers = ("informixdb",) |
---|
9 | |
---|
10 | def _initialize_(self): |
---|
11 | super(Informix, self)._initialize_() |
---|
12 | ruri = self.uri.split("://", 1)[1] |
---|
13 | m = self.REGEX_URI.match(ruri) |
---|
14 | if not m: |
---|
15 | raise SyntaxError("Invalid URI string in DAL") |
---|
16 | user = self.credential_decoder(m.group("user")) |
---|
17 | if not user: |
---|
18 | raise SyntaxError("User required") |
---|
19 | password = self.credential_decoder(m.group("password")) |
---|
20 | if not password: |
---|
21 | password = "" |
---|
22 | host = m.group("host") |
---|
23 | if not host: |
---|
24 | raise SyntaxError("Host name required") |
---|
25 | db = m.group("db") |
---|
26 | if not db: |
---|
27 | raise SyntaxError("Database name required") |
---|
28 | self.dsn = "%s@%s" % (db, host) |
---|
29 | self.driver_args.update(user=user, password=password) |
---|
30 | self.get_connection() |
---|
31 | |
---|
32 | def connector(self): |
---|
33 | return self.driver.connect(self.dsn, **self.driver_args) |
---|
34 | |
---|
35 | def _after_first_connection(self): |
---|
36 | self.dbms_version = int(self.connection.dbms_version.split(".")[0]) |
---|
37 | |
---|
38 | @with_connection_or_raise |
---|
39 | def execute(self, *args, **kwargs): |
---|
40 | command = self.filter_sql_command(args[0]) |
---|
41 | if command[-1:] == ";": |
---|
42 | command = command[:-1] |
---|
43 | handlers = self._build_handlers_for_execution() |
---|
44 | for handler in handlers: |
---|
45 | handler.before_execute(command) |
---|
46 | rv = self.cursor.execute(command, *args[1:], **kwargs) |
---|
47 | for handler in handlers: |
---|
48 | handler.after_execute(command) |
---|
49 | return rv |
---|
50 | |
---|
51 | def test_connection(self): |
---|
52 | self.execute("SELECT COUNT(*) FROM systables;") |
---|
53 | |
---|
54 | def lastrowid(self, table): |
---|
55 | return self.cursor.sqlerrd[1] |
---|
56 | |
---|
57 | |
---|
58 | @adapters.register_for("informix-se") |
---|
59 | class InformixSE(Informix): |
---|
60 | def rowslice(self, rows, minimum=0, maximum=None): |
---|
61 | if maximum is None: |
---|
62 | return rows[minimum:] |
---|
63 | return rows[minimum:maximum] |
---|