Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to specify the path of the error file #195

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
10 changes: 8 additions & 2 deletions bcpandas/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def to_sql(
batch_size: Optional[int] = None,
use_tablock: bool = False,
debug: bool = False,
bcp_path: Optional[str] = None,
bcp_path: Optional[Union[str, Path]] = None,
dtype: Optional[dict] = None,
process_dest_table: bool = True,
print_output: bool = True,
Expand All @@ -356,6 +356,7 @@ def to_sql(
work_directory: Optional[Path] = None,
collation: str = sql_collation,
identity_insert: bool = False,
err_file: Optional[Union[str, Path]] = None,
):
"""
Writes the pandas DataFrame to a SQL table or view.
Expand Down Expand Up @@ -394,7 +395,7 @@ def to_sql(
Setting this option allows for larger batch sizes.
debug : bool, default False
If True, will not delete the temporary CSV and format files, and will output their location.
bcp_path : str, default None
bcp_path : str, pathlib.Path, default None
The full path to the BCP utility, useful if it is not in the PATH environment variable
dtype: dict, default None
A dict with keys the names of columns and values SqlAlchemy types for defining their types. These are
Expand All @@ -418,6 +419,10 @@ def to_sql(
system-default for temporary files.
identity_insert: bool, default False
Specifies that identity value or values in the imported data file are to be used for the identity column.
err_file: str, pathlib.Path, default None
Specifies the full path of an error file used to store any rows that the bcp utility can't transfer from
the file to the database. Error messages from the bcp command go to the workstation of the user.
If this option isn't used, an error file isn't created.

Notes
-----
Expand Down Expand Up @@ -503,6 +508,7 @@ def to_sql(
use_tablock=use_tablock,
bcp_path=bcp_path,
identity_insert=identity_insert,
err_file=err_file,
)
finally:
if not debug:
Expand Down
4 changes: 4 additions & 0 deletions bcpandas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def bcp(
row_terminator: Optional[str] = None,
bcp_path: Optional[Union[str, Path]] = None,
identity_insert: bool = False,
err_file: Optional[Union[str, Path]] = None,
):
"""
See https://docs.microsoft.com/en-us/sql/tools/bcp-utility
Expand Down Expand Up @@ -114,6 +115,9 @@ def bcp(
if identity_insert:
bcp_command += ["-E"]

if err_file:
bcp_command += ["-e", str(err_file)]

# formats
if direc == IN and format_file_path is not None:
bcp_command += ["-f", str(format_file_path)]
Expand Down
Loading