Commits

Anonymous committed 563f0af

Initial import of Ingres support.

  • Participants
  • Parent commits b47700d

Comments (0)

Files changed (2)

File dbapi/demo_ingres.py

+#!/usr/bin/env python
+# -*- coding: ascii -*-
+# vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab
+#
+"""Usage, assuming defualt install location:
+
+    "C:\Program Files\IronPython 2.6 for .NET 4.0\ipy.exe" demo_ingres.py
+    "C:\Program Files\IronPython 2.6\ipy.exe" demo_ingres.py
+
+"""
+
+import dbapi
+
+import ingres as db
+
+
+connection_function = db.connect
+
+
+connectstr = 'Host=YOUR_SERVERNAME;Database=iidbdb;Port=II7;User ID=YOUR_USERNAME;Password=YOUR_OS_PASSWORD'
+connectstr = 'iidbdb'  # assume local connection, so operating system authentication is in effect (i.e. no need for explict user name or password)
+conn = connection_function(connectstr)
+
+c = conn.cursor()
+c.execute('select * from iidbconstants')
+print c.description
+print c.fetchall()
+
+c.execute("select ingresdate('now') from iidbconstants")
+print c.description
+print c.fetchall()
+

File dbapi/ingres.py

+#!/usr/bin/env python
+# -*- coding: ascii -*-
+# vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab
+#
+"""Ingres support for .NET Data Adapter for IronPython
+http://ingres.com
+
+Author: Chris.Clark@ingres.com
+
+You will need the Ingres .NET Data Adapter installed.
+"""
+
+import os
+
+import dbapi
+
+assembly = 'System.Data'
+typename = 'Ingres.Client.IngresConnection'
+
+import clr
+import System
+clr.AddReference("Ingres.Client")
+import Ingres.Client
+
+
+def _get_default_port():
+    result = defport = 'II7'
+    II_SYSTEM = os.environ.get('II_SYSTEM')
+    if II_SYSTEM is not None:
+        config_dat_path = os.path.join(II_SYSTEM, 'ingres', 'files', 'config.dat')
+        try:
+            f = open(config_dat_path)
+            # could use a regex here... not sure on performance
+            for line in f:
+                # Not a great search string but good enough
+                if '.gcd.*.tcp_ip.port' in line:
+                    result = line.split(':')[1]
+                    result = result.strip()
+                    break
+        except IOError:
+            result = defport
+    return result
+
+def connect(connstr):
+    """Takes a .NET Data Provider Connection String.
+    TODO adding named params (i.e. follow pep-249)
+    possibly (also) following IngresDBI param names/conventions/extensions
+    """
+    if '=' not in connstr:
+        # Probably have a regular Ingres dbname (with optional vnode)
+        # I.e. not a .NET connection string
+        # NOTE: Possible problem with dynamic vnodes with connection attributes as equals sign is used
+        default_gcd_port = _get_default_port()
+        dbhostname = '(local)'  # does NOT require authentication, assumes current user (note only tested under Windows)
+        connstr = 'Host=%s;Database=%s;Port=%s' % (dbhostname, connstr, default_gcd_port)
+    return dbapi.generic_connect('System.Data', 'Ingres.Client.IngresConnection', connstr)