giraffez/cmd.py
def insert(self, table_name, rows, fields=None, delimiter=None, null='NULL', parse_dates=False, quotechar='"'):
        """
        Load a text file into the specified :code:`table_name` or Insert Python :code:`list` rows into the specified :code:`table_name`

        :param str table_name: The name of the destination table
        :param list/str rows: A list of rows **or** the name of an input file. Each row
            must be a :code:`list` of field values.
        :param list fields: The names of the target fields, in the order that
            the data will be presented (defaults to :code:`None` for all columns
            in the table).
        :param str delimiter: The delimiter used by the input file (or :code:`None`
            to infer it from the header).
        :param str null: The string used to indicated nulled values in the
            file (defaults to :code:`'NULL'`).
        :param str quotechar: The character used to quote fields containing special
            characters, like the delimiter.
        :param bool parse_dates: If :code:`True`, attempts to coerce date fields
            into a standard format (defaults to :code:`False`).
        :raises `giraffez.errors.GiraffeEncodeError`: if the number of values in a row does not match
            the length of :code:`fields`
        :raises `giraffez.errors.GiraffeError`: if :code:`panic` is set and the insert statement
            caused an error.
        :return: A dictionary containing counts of applied rows and errors
        :rtype: :class:`dict`

        For most insertions, this will be faster and produce less strain on
        Teradata than using :class:`~giraffez.load.TeradataBulkLoad` (:class:`giraffez.BulkLoad <giraffez.load.TeradataBulkLoad>`).

        Requires that any input file be a properly delimited text file, with a
        header that corresponds to the target fields for insertion. Valid delimiters
        include '|', ',', and <tab> or a properly encoded JSON stream.
        """
        if not isfile(rows):
            return self._insert(table_name, rows, fields, parse_dates)
        with Reader(rows, delimiter=delimiter, quotechar=quotechar) as f:
            preprocessor = null_handler(null)
            rows = (preprocessor(l) for l in f)
            if isinstance(f, CSVReader):
                self.options("delimiter", unescape_string(f.reader.dialect.delimiter), 1)
                self.options("quote char", f.reader.dialect.quotechar, 2)
            elif isinstance(f, JSONReader):
                self.options("encoding", "json", 1)
            return self._insert(table_name, rows, f.header, parse_dates)
def insert(self, table_name, rows, fields=None, delimiter=None, null='NULL', parse_dates=False, quotechar='"'):
        """
        Load a text file into the specified :code:`table_name` or Insert Python :code:`list` rows into the specified :code:`table_name`

        :param str table_name: The name of the destination table
        :param list/str rows: A list of rows **or** the name of an input file. Each row
            must be a :code:`list` of field values.
        :param list fields: The names of the target fields, in the order that
            the data will be presented (defaults to :code:`None` for all columns
            in the table).
        :param str delimiter: The delimiter used by the input file (or :code:`None`
            to infer it from the header).
        :param str null: The string used to indicated nulled values in the
            file (defaults to :code:`'NULL'`).
        :param str quotechar: The character used to quote fields containing special
            characters, like the delimiter.
        :param bool parse_dates: If :code:`True`, attempts to coerce date fields
            into a standard format (defaults to :code:`False`).
        :raises `giraffez.errors.GiraffeEncodeError`: if the number of values in a row does not match
            the length of :code:`fields`
        :raises `giraffez.errors.GiraffeError`: if :code:`panic` is set and the insert statement
            caused an error.
        :return: A dictionary containing counts of applied rows and errors
        :rtype: :class:`dict`

        For most insertions, this will be faster and produce less strain on
        Teradata than using :class:`~giraffez.load.TeradataBulkLoad` (:class:`giraffez.BulkLoad <giraffez.load.TeradataBulkLoad>`).

        Requires that any input file be a properly delimited text file, with a
        header that corresponds to the target fields for insertion. Valid delimiters
        include '|', ',', and <tab> or a properly encoded JSON stream.
        """
        if not isfile(rows):
            return self._insert(table_name, rows, fields, parse_dates)
        with Reader(rows, delimiter=delimiter, quotechar=quotechar) as f:
            preprocessor = null_handler(null)
            rows = (preprocessor(l) for l in f)
            if isinstance(f, CSVReader):
                self.options("delimiter", unescape_string(f.reader.dialect.delimiter), 1)
                self.options("quote char", f.reader.dialect.quotechar, 2)
            elif isinstance(f, JSONReader):
                self.options("encoding", "json", 1)
            return self._insert(table_name, rows, f.header, parse_dates)
Load a text file into the specified :code:`table_name` or Insert Python :code:`list` rows into the specified :code:`table_name`

        :param str table_name: The name of the destination table
        :param list/str rows: A list of rows **or** the name of an input file. Each row
            must be a :code:`list` of field values.
        :param list fields: The names of the target fields, in the order that
            the data will be presented (defaults to :code:`None` for all columns
            in the table).
        :param str delimiter: The delimiter used by the input file (or :code:`None`
            to infer it from the header).
        :param str null: The string used to indicated nulled values in the
            file (defaults to :code:`'NULL'`).
        :param str quotechar: The character used to quote fields containing special
            characters, like the delimiter.
        :param bool parse_dates: If :code:`True`, attempts to coerce date fields
            into a standard format (defaults to :code:`False`).
        :raises `giraffez.errors.GiraffeEncodeError`: if the number of values in a row does not match
            the length of :code:`fields`
        :raises `giraffez.errors.GiraffeError`: if :code:`panic` is set and the insert statement
            caused an error.
        :return: A dictionary containing counts of applied rows and errors
        :rtype: :class:`dict`

        For most insertions, this will be faster and produce less strain on
        Teradata than using :class:`~giraffez.load.TeradataBulkLoad` (:class:`giraffez.BulkLoad <giraffez.load.TeradataBulkLoad>`).

        Requires that any input file be a properly delimited text file, with a
        header that corresponds to the target fields for insertion. Valid delimiters
        include '|', ',', and <tab> or a properly encoded JSON stream.