def copy_to(self, file, table, sep='\t', null='\\N', columns=None): """Writes the content of a table to a file-like object (COPY table TO file syntax). The target file must have a write() method. TODO: Improve error handling """ if columns: columns_str = '(%s)' % ','.join([column for column in columns]) else: columns_str = '' query = util.ascii_to_bytes( "COPY %s%s TO stdout WITH DELIMITER AS " % ( table, columns_str)) + \ util.quote_string(self._conn, sep) + b' NULL AS ' + \ util.quote_string(self._conn, null) self._copyfile = file try: self._pq_execute(query) finally: self._copyfile = None
def copy_from(self, file, table, sep='\t', null='\\N', size=8192, columns=None): """Reads data from a file-like object appending them to a database table (COPY table FROM file syntax). The source file must have both read() and readline() method. TODO: Improve error handling """ if columns: columns_str = '(%s)' % ','.join([column for column in columns]) else: columns_str = '' query = "COPY %s%s FROM stdin WITH DELIMITER AS %s NULL AS %s" % ( table, columns_str, util.quote_string(self._conn, sep), util.quote_string(self._conn, null)) self._copysize = size self._copyfile = file try: self._pq_execute(query) finally: self._copyfile = None self._copysize = None
def copy_from(self, file, table, sep='\t', null='\\N', size=8192, columns=None): """Reads data from a file-like object appending them to a database table (COPY table FROM file syntax). The source file must have both read() and readline() method. TODO: Improve error handling """ if columns: columns_str = '(%s)' % ','.join([column for column in columns]) else: columns_str = '' query = util.ascii_to_bytes( "COPY %s%s FROM stdin WITH DELIMITER AS " % ( table, columns_str)) + \ util.quote_string(self._conn, sep) + b' NULL AS ' + \ util.quote_string(self._conn, null) self._copysize = size self._copyfile = file try: self._pq_execute(query) finally: self._copyfile = None self._copysize = None
def _set_guc(self, name, value): """Set the value of a configuration parameter.""" if value.lower() != 'default': value = util.quote_string(self, value) else: value = b'default' self._execute_command(ascii_to_bytes('SET %s TO ' % name) + value)
def _execute_tpc_command(self, command, xid): cmd = b' '.join( [ascii_to_bytes(command), util.quote_string(self, str(xid))]) self._execute_command(cmd) self._mark += 1
def _execute_tpc_command(self, command, xid): cmd = '%s %s' % (command, util.quote_string(self, str(xid))) self._execute_command(cmd) self._mark += 1
def _set_guc(self, name, value): """Set the value of a configuration parameter.""" if value.lower() != 'default': value = util.quote_string(self, value) self._execute_command('SET %s TO %s' % (name, value))
def _execute_tpc_command(self, command, xid): cmd = b' '.join([ ascii_to_bytes(command), util.quote_string(self, str(xid))]) self._execute_command(cmd) self._mark += 1