Пример #1
0
 def call_sp_write(self, procname, args):
     with self.lock:
         cursor = self.create_cursor()
         try:
             result_args = cursor.callproc(procname=procname, args=args)
         except DataError as e:
             raise ReadWriteError(f"DataError({e.errno}): {traceback.format_exc()}")
         except IntegrityError as e:
             raise ReadWriteError(
                 f"IntegrityError({e.errno}): {traceback.format_exc()}"
             )
         except DatabaseError as e:
             raise ReadWriteError(
                 f"DatabaseError({e.errno}): {traceback.format_exc()}"
             )
         finally:
             cursor.close()
     if result_args is not None and len(result_args) > 0:
         return result_args[0]
Пример #2
0
 def call_sf_write(self, funcname, args):
     with self.lock:
         cursor = self.create_cursor()
         try:
             cursor.execute(
                 ("select %s" % funcname) + " (%s)" % ",".join(["%s"] * len(args)),
                 args,
             )
         except DataError as e:
             raise ReadWriteError(f"DataError({e.errno}): {traceback.format_exc()}")
         except IntegrityError as e:
             raise ReadWriteError(
                 f"IntegrityError({e.errno}): {traceback.format_exc()}"
             )
         result = None
         rs = cursor.fetchone()
         if len(rs) > 0:
             try:
                 result = int(rs[0])
             except ValueError:
                 result = rs[0]
         cursor.close()
     return result
Пример #3
0
 def call_sf_retrieve(self, funcname, args):
     with self.lock:
         cursor = self.create_cursor(dictionary=True)
         try:
             cursor.execute(
                 ("select %s" % funcname) + " (%s)" % ",".join(["%s"] * len(args)),
                 args,
             )
         except DataError as e:
             raise ReadWriteError(f"DataError({e.errno}): {traceback.format_exc()}")
         result = None
         rs = cursor.fetchone()
         if len(rs) > 0:
             result = next(iter(rs.items()))[1]  # iter(rs.items()).next()[1]
         cursor.close()
     if result is None:
         raise NoResult
     return result
Пример #4
0
    def call_sp_retrieve(self, procname, args):
        with self.lock:
            cursor = self.create_cursor(dictionary=True)
            try:
                cursor.callproc(procname=procname, args=args)
            except DataError as e:
                raise ReadWriteError("DataError({0}): {1}".format(
                    e.errno, traceback.format_exc()))

            result = []
            for recordset in cursor.stored_results():
                if isinstance(cursor, mysql.connector.cursor.MySQLCursorDict):
                    for row in recordset:
                        result.append(
                            dict(list(zip(recordset.column_names, row))))
                else:
                    result = recordset.fetchall()

            cursor.close()
        if result == []:
            raise NoResult
        return result