adodb_pyodbc.py :  » Database » ADOdb » adodb-220 » adodb » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Database » ADOdb 
ADOdb » adodb 220 » adodb » adodb_pyodbc.py
########################################################################
# Vers 2.10 16 July 2008, (c)2004-2008 John Lim (jlim#natsoft.com) All Rights Reserved
# Released under a BSD-style license. See LICENSE.txt.
# Download: http://adodb.sourceforge.net/#pydownload
#######################################################################

import adodb,adodb_odbc,sys

##if sys.platform.find('win32') >= 0:
##    import mx.ODBC.Windows
##    mxODBC = mx.ODBC.Windows
##else:
##    import mx.ODBC.iODBC
##    mxODBC = mx.ODBC.iODBC

import pyodbc

try:
    True, False
except NameError:
    # Maintain compatibility with Python 2.2
    True, False = 1, 0

class adodb_pyodbc(adodb.ADOConnection):
    databaseType = 'pyodbc'
    dataProvider = 'pyodbc'
    hasRowCount = False

    def __init__(self):
        pass

    def Module(self):
        global mxODBC
        
        return mxODBC
        #host=host1 user=user1 password=secret port=4341
    
    def _connect(self,host=None,user=None,password=None,database=None):
        
        
        if user == None and password == None and database == None:
            dsn = host
        else:
            dsn = 'dsn='+self.addq(host)+';'
            if (user != None): dsn += ' uid='+self.addq(user)+';'
            if (password != None): dsn += ' pwd='+self.addq(password)+';'
            if (database != None): dsn += ' database='+self.addq(database)+';'
      
        self._conn = pyodbc.connect(dsn)
        self._conn.autocommit = True
        #self._conn.setconnectoption(mxODBC.SQL.AUTOCOMMIT, mxODBC.SQL.AUTOCOMMIT_ON)

    def _newcursor(self,rs):
        return cursor_pyodbc(rs,self)
    
    def BeginTrans(self):
        global mxODBC
        if self._autocommit:
            self._autocommit = False
        self._conn.autocommit = self._autocommit

    def RollbackTrans(self):
        global mxODBC
        self._conn.rollback()
        self._autocommit = True
        self._conn.autocommit = self._autocommit
        
    def CommitTrans(self):
        global mxODBC
        self._conn.commit()
        self._autocommit = True
        self._conn.autocommit = self._autocommit

    def MetaColumns(self, table):
        curs = self._conn.cursor()
        curs.columns(table) # columns('%', '%', table) ?
        rs = self._newcursor(curs)
        arr = []
        table = table.upper()
        while not rs.EOF:
            if rs.fields[2].upper() == table:
                arr.append((rs.fields[3],rs.fields[5],rs.fields[6]))
            rs.MoveNext()
        return arr
    
class cursor_pyodbc(adodb.ADOCursor):
    def __init__(self,rs,conn):
        adodb.ADOCursor.__init__(self,rs,conn)
        rs.arraysize=10
            
if __name__ == '__main__':
    db = adodb_pyodbc()
    #db.Connect("Driver=Microsoft Visual FoxPro Driver;UID=;PWD=;SourceDB=D:\\inetpub\\adodb\\adoxyz.DBC;SourceType=DBC;Exclusive=No;BackgroundFetch=No;Collate=Machine;Null=Yes;Deleted=Yes;")
    db.Connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=d:\\inetpub\\adodb\\northwind.mdb;Uid=Admin;Pwd=;")
    adodb.Test(db)        
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.