コード例 #1
0
 def _batch_insert(self, multiple_value_list):
     columns, values_list, set_columns = [], [], False
     for values_dict in multiple_value_list:
         values = []
         for k, v in values_dict.iteritems():
             if set_columns is False:
                 columns.append(self._compile_fieldname(k, False))
             values.append(v)
         set_columns = True
         values_list.append(values)
     sql = 'INSERT INTO `%s` (%s) VALUES %s' % (self._from, ', '.join(columns), ', '.join([ '(%s)' % self._postion_flag(vs) for vs in values_list ]))
     return self.conn.execute_rowcount(sql, *flatten(values_list))
コード例 #2
0
 def __show_sql(self, sql, params):
     if isinstance(sql, unicode):
         sql = sql.encode('utf8')
     if not params:
         return sql
     else:
         formated_params = []
         for param in params:
             if isinstance(param, unicode):
                 param = param.encode('utf8')
             if is_str(param):
                 param = "'%s'" % MySQLdb.escape_string(param)
             elif is_datetime(param):
                 param = "'%s'" % str2datetime(param)
             elif is_date(param):
                 param = "'%s'" % str2date(param)
             else:
                 param = str(param)
             formated_params.append(param)
         formated_params.append(';')
         return ''.join(flatten(izip(sql.split('?'), formated_params)))