# -*- coding: utf8 -*-
'''
DB MODULE - SYBASE
*******************************
***  DB MODULE - SYBASE
*******************************
$RCSfile: dbmod_sybase.py,v $
$Revision: 905 $
$Author: markus $
$Date: 2008-04-30 11:57:10 +0200 (Mi, 30. Apr 2008) $

The biocase.wrapper database module to access Sybase databases.
You will need the Sybase module from http://www.object-craft.com.au/projects/sybase/ to connect.
'''

from string                                import join
from datetime                             import datetime
from biocase.wrapper.errorclasses         import *
from biocase.wrapper.typeconverter        import DBtransformerClass
from biocase.wrapper.sql.base             import sqlBase
from biocase.wrapper.dbmod.base_dbmod   import DBBasemodule
from types                                 import *

import logging
log = logging.getLogger("pywrapper.dbmod")


#############################################
#
# CUSTOMIZATION for Sybase T-SQL
#
# OVERLOAD BASE CLASSES AND OTHER METHODS
#
#############################################


# uses inherited ANSI SQL apart from the following.
sqlBase.templates['attribute'] = '[#1].[#2]'
sqlBase.templates['table'] = '[#1]'




# ---------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------
class DBmodule(DBBasemodule):
    __version__ = '0.31 using Sybase ?'
    __dbmod__    = u'Sybase module'
    
    # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    def __init__(self, psfObj):
        # setting the psfObj reference to self.psfObj
        # call createDBconnection method
        DBBasemodule.__init__(self, psfObj)

        # dont use parameters but integrate all parameters into SQL strings:
        self.trans.integrateParametersInSQLString()


    # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    def createDBconnection(self):
        try:
            import Sybase
        except:
            raise DbModuleMissingError('Sybase')
        self.__class__.__version__ = self.__class__.__version__[:-1] +Sybase.__version__
        #
        # connect
        #
        conn = Sybase.connect(self.psfObj.dbIP, self.psfObj.user, self.psfObj.password, self.psfObj.database)
        return conn 
        
    
