Пример #1
0
  def __call__(self,*args,**kwargs):
    """
    Handles calling event of the classes.Executes given query using database driver.
    Returns instances of Entity classes which will be mapped to sub query classes.
    """
    self.args = args or kwargs or None
    if not self.code:
      raise Exception, "'code' property has to be an sql query"

    if self.args:
      code = self.code%self.args
    else:
      code = self.code

    logging.info('db.query: Running new query; %s'%(code.replace('\n',' ')))
    """
    Executing given query
    """
    from __init__ import connection
    connection.cursor.execute(code)

    try:
      data = connection.cursor.fetchall()
    except:
      data = tuple()
      logging.error( ExceptionInfo().format_stack() )

    """
    Mapping fetched data into python objects
    """
    self.data = QueryResult(data)
    self.data.query = self
    self.data = ( None if len(self.data)==0 else self.data[0] ) if self.is_singular else self.data

    return self.data
Пример #2
0
    def cursor(self):
        if self._link and self._link.get_transaction_status() == 3:
            logging.warning("db: Transaction is corrupted")
            logging.info("db: Running rollback command")
            self._link.rollback()

        if not self._cursor:
            logging.info("db: Initializing new database cursor.")
            self._cursor = self.link.cursor()

        return self._cursor
Пример #3
0
    def report_type(self, value):
        self._report_type = value

        if self.report_type == Report.ERROR:
            self.exception = ExceptionInfo(sys.exc_info())

            if not self.message_key:
                self.message_key = "error_unexpected"

            if self.log == True:
                self.exception.log()

        elif self.log:
            logging.info(self.message or self.message_key)
Пример #4
0
 def open(self, **kwargs):
     logging.info("db: Initializing new connection..")
     self._link = self.driver.connect(user=self.user, password=self.password, host=self.host, database=self.database)
     self._cursor = None