コード例 #1
0
    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
コード例 #2
0
ファイル: cursor.py プロジェクト: fantix/psycopg2cffi
    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
コード例 #3
0
    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
コード例 #4
0
ファイル: cursor.py プロジェクト: cutso/psycopg2cffi
    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
コード例 #5
0
ファイル: connection.py プロジェクト: cdepman/falcon_api
 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)
コード例 #6
0
ファイル: connection.py プロジェクト: chtd/psycopg2cffi
 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)
コード例 #7
0
ファイル: connection.py プロジェクト: cdepman/falcon_api
 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
コード例 #8
0
ファイル: connection.py プロジェクト: thomaslegg/psycopg2cffi
 def _execute_tpc_command(self, command, xid):
     cmd = '%s %s' % (command, util.quote_string(self, str(xid)))
     self._execute_command(cmd)
     self._mark += 1
コード例 #9
0
ファイル: connection.py プロジェクト: thomaslegg/psycopg2cffi
 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))
コード例 #10
0
ファイル: connection.py プロジェクト: chtd/psycopg2cffi
 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