def insert(self, name, **kwargs): con = self.connect() if con: try: with con: cur = con.cursor() query = sqlbuild.build_sql_insert(name, kwargs) cur.execute(query) except db.Error, e: logging.error("Error {}: {}".format(e.args[0], e.args[1])) return None finally:
def insertmany(self, name, values, **keys): total_iter = len(values) print total_iter if len(values) >= self.maximum: sequencor = self._iterator_sequencor(values) else: sequencor = self._iterator_sequencor(values, bs=total_iter) new_keys = {} sorted_values = keys.values() sorted_values.sort() searchkey = lambda d, val: [c for c,v in d.items() if v==val] for k in sorted_values: new_keys[k] = searchkey(keys, k)[0] kwargs = [(v,'%s') for k, v in new_keys.items()] con = self.connect() if con: try: with con: cur = con.cursor(cursorclass=cursor_perso) cur.thread_delay = self.td query = sqlbuild.build_sql_insert(name, kwargs) logging.info(query) i = 0 logging.info("in transfering ...") percent = 0 for seq in sequencor: cur.executemany(query, seq) if total_iter >= self.maximum: i += self.maximum else: i = total_iter percent = (i * 100) / total_iter sys.stdout.write('\r%d/100' % (percent)) sys.stdout.flush() logging.debug("commit, offset {} (bs={})".format((i / self.maximum) , self.maximum)) con.commit() sys.stdout.write('\r\n') sys.stdout.flush() except db.Error, e: logging.fatal("Error {}: {}".format(e.args[0], e.args[1])) sys.exit(67) finally: