# -*- coding: iso-8859-1 -*-
#-----------------------------------------------------------------------------
# Modeling Framework: an Object-Relational Bridge for python
#
# Copyright (c) 2001-2004 Sbastien Bigaret <sbigaret@users.sourceforge.net>
# All rights reserved.
#
# This file is part of the Modeling Framework.
#
# This code is distributed under a "3-clause BSD"-style license;
# see the LICENSE file for details.
#-----------------------------------------------------------------------------
"""
MySQLAdaptor
CVS information
$Id: MySQLAdaptor.py 933 2004-08-02 19:58:54Z sbigaret $
"""
__version__='$Revision: 933 $'[11:-2]
#
from Modeling.logging import db_info
from Modeling.utils import staticmethod
from Modeling.DatabaseAdaptors.AbstractDBAPI2AdaptorLayer import AbstractDBAPI2Adaptor
import MySQLdb
class MySQLAdaptor(AbstractDBAPI2Adaptor.AbstractDBAPI2Adaptor):
"""
"""
def underlying_py_adaptor_module():
return MySQLdb
underlying_py_adaptor_module=staticmethod(underlying_py_adaptor_module)
def createAdaptorContext(self):
"See Modeling.interfaces.Adaptor for details"
from MySQLAdaptorContext import MySQLAdaptorContext
concreteAdaptorContext=MySQLAdaptorContext(self)
self._contexts.append(concreteAdaptorContext)
return concreteAdaptorContext
def defaultExpressionClass(self):
"Returns PostgresqlSQLExpression"
from MySQLSQLExpression import MySQLSQLExpression
return MySQLSQLExpression
def expressionFactory(self):
"See Modeling.interfaces.Adaptor for details"
return SQLExpressionFactory
def schemaGenerationFactory(self):
"See Modeling.interfaces.Adaptor for details"
from MySQLSchemaGeneration import MySQLSchemaGeneration
return MySQLSchemaGeneration(self)
def dbAPI_connectionDictionaryForConnect(self, aModelConnectionDictionary):
"""
Returns a dictionary usable as keyword parameters by
MySQLSchemaGeneration.connect. Between the original dict. and the
returned one, the matching of keys goes like this:
- 'database' -> 'db'
- 'user' -> user' (unchanged)
- 'password' -> 'passwd'
- 'host' -> 'host' (unchanged)
- 'port' -> 'port' (unchanged) if and only if the key exists
"""
dbAPI_d={ 'db': '%(database)s'%aModelConnectionDictionary,
'user': '%(user)s'%aModelConnectionDictionary,
'passwd': '%(password)s'%aModelConnectionDictionary,
'host': '%(host)s'%aModelConnectionDictionary }
if aModelConnectionDictionary.get('port'):
dbAPI_d['port']=int(aModelConnectionDictionary['port'])
return dbAPI_d
def dbAPI_gimmeCnxAndCursorForDBAdmin(self, administrativeConnectionDictionary):
cnxDict=self.dbAPI_connectionDictionaryForConnect(administrativeConnectionDictionary)
cnx=apply(self.underlying_py_adaptor_module().connect, (), cnxDict)
#cnx.autocommit()
return cnx, cnx.cursor()
|