Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
version: 2
updates:
- package-ecosystem: "uv"
directory: "/" # Location of package manifests
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
18 changes: 14 additions & 4 deletions bcpandas/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
4 changes: 2 additions & 2 deletions bcpandas/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion bcpandas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 =")],
Expand Down
Loading