diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 4e33fa2..14b87d7 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,6 +6,6 @@ version: 2 updates: - package-ecosystem: "uv" - directory: "/" # Location of package manifests + directory: "/" # Location of package manifests schedule: interval: "weekly" diff --git a/bcpandas/constants.py b/bcpandas/constants.py index ba3d1e3..67fe9dd 100644 --- a/bcpandas/constants.py +++ b/bcpandas/constants.py @@ -63,15 +63,25 @@ class BCPandasValueError(BCPandasException): """ -def get_delimiter(df: pd.DataFrame) -> str: - for delim in _DELIMITER_OPTIONS: +def get_delimiter(df: pd.DataFrame, additional_char: Optional[str] = None) -> str: + delims = ( + _DELIMITER_OPTIONS + (additional_char,) + if additional_char is not None + else _DELIMITER_OPTIONS + ) + for delim in delims: if not df.map(lambda x: delim in x if isinstance(x, str) else False).any().any(): return delim raise BCPandasValueError(error_msg.format(typ="delimiter", opts=_DELIMITER_OPTIONS)) -def get_quotechar(df: pd.DataFrame) -> str: - for qc in _QUOTECHAR_OPTIONS: +def get_quotechar(df: pd.DataFrame, additional_char: Optional[str] = None) -> str: + qcs = ( + _QUOTECHAR_OPTIONS + (additional_char,) + if additional_char is not None + else _QUOTECHAR_OPTIONS + ) + for qc in qcs: if not df.map(lambda x: qc in x if isinstance(x, str) else False).any().any(): return qc raise BCPandasValueError(error_msg.format(typ="quote", opts=_QUOTECHAR_OPTIONS)) diff --git a/bcpandas/main.py b/bcpandas/main.py index 4b94801..2957a1b 100644 --- a/bcpandas/main.py +++ b/bcpandas/main.py @@ -435,8 +435,8 @@ def to_sql( if index: df = df.reset_index() - delim = get_delimiter(df) if delimiter is None else delimiter - _quotechar = get_quotechar(df) if quotechar is None else quotechar + delim = get_delimiter(df, additional_char=delimiter) + _quotechar = get_quotechar(df, additional_char=quotechar) # save to temp path csv_file_path = get_temp_file(work_directory) diff --git a/bcpandas/utils.py b/bcpandas/utils.py index 5b3250f..625b4f5 100644 --- a/bcpandas/utils.py +++ b/bcpandas/utils.py @@ -135,7 +135,11 @@ def bcp( bcp_command_log_msg = sub(r"-P,\s.*,", "-P, [REDACTED],", bcp_command_log) logger.info(f"Executing BCP command now... \nBCP command is: {bcp_command_log_msg}") ret_code, output = run_cmd(bcp_command, print_output=print_output) - if ret_code != 0: + errors_check = [ + True if "Error = [Microsoft][ODBC Driver 17 for SQL Server]" in x else False + for x in output + ] + if ret_code != 0 or any(errors_check): raise BCPandasException( f"Bcp command failed with exit code {ret_code}", details=[line for line in output if line.startswith("Error =")],