FreeTDS API
Loading...
Searching...
No Matches
bcp.c File Reference

Implementation of db-lib bulk copy functions. More...

#include <config.h>
#include <stdarg.h>
#include <stdio.h>
#include <assert.h>
#include <freetds/tds.h>
#include <freetds/tds/checks.h>
#include <freetds/tds/iconv.h>
#include <freetds/tds/convert.h>
#include <freetds/bytes.h>
#include <freetds/tds/stream.h>
#include <freetds/utils/string.h>
#include <freetds/encodings.h>
#include <freetds/replacements.h>
#include <sybfront.h>
#include <sybdb.h>
#include <syberror.h>
#include <dblib.h>
Include dependency graph for bcp.c:

Macros

#define BCP_DEFAULT_DATEFMT   "%Y-%m-%d %H:%M:%S.%z"
#define HOST_COL_CONV_ERROR   1
#define HOST_COL_NULL_ERROR   2
#define TDS_EOL   "\n"

Functions

static STATUS _bcp_check_eof (DBPROCESS *dbproc, TDSFILESTREAM *stream, int icol)
static TDSRET _bcp_convert_in (DBPROCESS *dbproc, TDS_SERVER_TYPE srctype, const TDS_CHAR *src, TDS_UINT srclen, TDS_SERVER_TYPE desttype, TDSCOLUMN *col, bool *truncated)
 Convert column for input to a table.
static int _bcp_convert_out (DBPROCESS *dbproc, TDSCOLUMN *curcol, BCP_HOSTCOLINFO *hostcol, TDS_UCHAR **p_data, const char *bcpdatefmt)
 Convert column for output (usually to a file) Conversion is slightly different from input as:
static RETCODE _bcp_exec_in (DBPROCESS *dbproc, DBINT *rows_copied)
static RETCODE _bcp_exec_out (DBPROCESS *dbproc, DBINT *rows_copied)
static char * _bcp_fgets (char *buffer, int size, FILE *f)
static void _bcp_free_columns (DBPROCESS *dbproc)
static void _bcp_free_storage (DBPROCESS *dbproc)
static TDSRET _bcp_get_col_data (TDSBCPINFO *bcpinfo, TDSCOLUMN *bindcol, int index TDS_UNUSED, int offset TDS_UNUSED)
 For a bcp in from program variables, get the data from the host variable.
static int _bcp_get_term_var (const BYTE *pdata, const BYTE *term, int term_len)
 Get the data for bcp-in from program variables, where the program data have been identified as character terminated,
This is a low-level, internal function.
static TDSRET _bcp_no_get_col_data (TDSBCPINFO *bcpinfo TDS_UNUSED, TDSCOLUMN *bindcol TDS_UNUSED, int index TDS_UNUSED, int offset TDS_UNUSED)
 Function to read data from file.
static TDSRET _bcp_no_get_col_data (TDSBCPINFO *bcpinfo, TDSCOLUMN *bindcol, int index, int offset)
static void _bcp_null_error (TDSBCPINFO *bcpinfo, int index, int offset)
static STATUS _bcp_read_hostfile (DBPROCESS *dbproc, TDSFILESTREAM *hostfile, bool *row_error, bool skip)
static int _bcp_readfmt_colinfo (DBPROCESS *dbproc, char *buf, BCP_HOSTCOLINFO *ci)
static int _bcp_strftime (char *buf, size_t maxsize, const char *format, const TDSDATEREC *dr, int prec)
 Fast strftime for default bcp format.
DBINT bcp_batch (DBPROCESS *dbproc)
 Commit a set of rows to the table.
RETCODE bcp_bind (DBPROCESS *dbproc, BYTE *varaddr, int prefixlen, DBINT varlen, BYTE *terminator, int termlen, int db_vartype, int table_column)
 Bind a program host variable to a database column.
static int bcp_cache_prefix_len (BCP_HOSTCOLINFO *hostcol, const TDSCOLUMN *curcol)
RETCODE bcp_colfmt (DBPROCESS *dbproc, int host_colnum, int host_type, int host_prefixlen, DBINT host_collen, const BYTE *host_term, int host_termlen, int table_colnum)
 Specify the format of a datafile prior to writing to a table.
RETCODE bcp_colfmt_ps (DBPROCESS *dbproc, int host_colnum, int host_type, int host_prefixlen, DBINT host_collen, BYTE *host_term, int host_termlen, int table_colnum, DBTYPEINFO *typeinfo)
 Specify the format of a host file for bulk copy purposes, with precision and scale support for numeric and decimal columns.
RETCODE bcp_collen (DBPROCESS *dbproc, DBINT varlen, int table_column)
 Set the length of a host variable to be written to a table.
RETCODE bcp_colptr (DBPROCESS *dbproc, BYTE *colptr, int table_column)
 Override bcp_bind() by pointing to a different host variable.
RETCODE bcp_columns (DBPROCESS *dbproc, int host_colcount)
 Indicate how many columns are to be found in the datafile.
RETCODE bcp_control (DBPROCESS *dbproc, int field, DBINT value)
 Set BCP options for uploading a datafile.
DBINT bcp_done (DBPROCESS *dbproc)
 Conclude the transfer of data from program variables.
RETCODE bcp_exec (DBPROCESS *dbproc, DBINT *rows_copied)
 Write a datafile to a table.
int bcp_getbatchsize (DBPROCESS *dbproc)
int bcp_gethostcolcount (DBPROCESS *dbproc)
DBBOOL bcp_getl (LOGINREC *login)
 See if BCP_SETL() was used to set the LOGINREC for BCP work.
RETCODE bcp_init (DBPROCESS *dbproc, const char *tblname, const char *hfile, const char *errfile, int direction)
 Prepare for bulk copy operation on a table.
RETCODE bcp_options (DBPROCESS *dbproc, int option, BYTE *value, int valuelen)
 Set bulk copy options.
RETCODE bcp_readfmt (DBPROCESS *dbproc, const char filename[])
 Read a format definition file.
RETCODE bcp_sendrow (DBPROCESS *dbproc)
 Write data in host variables to the table.
static RETCODE bcp_write_prefix (TDSFILEOUTSTREAM *hoststream, BCP_HOSTCOLINFO *hostcol, TDSCOLUMN *curcol, int buflen)
static void init_hostfile_columns (DBPROCESS *dbproc)
static int rtrim (char *str, int len)
 trim a string of trailing blanks
static void rtrim_bcpcol (TDSCOLUMN *bcpcol)
static int rtrim_u16 (uint16_t *str, int len, uint16_t space)

Detailed Description

Implementation of db-lib bulk copy functions.

Function Documentation

◆ _bcp_convert_in()

TDSRET _bcp_convert_in ( DBPROCESS * dbproc,
TDS_SERVER_TYPE srctype,
const TDS_CHAR * src,
TDS_UINT srclen,
TDS_SERVER_TYPE desttype,
TDSCOLUMN * col,
bool * truncated )
static

Convert column for input to a table.

Character data copied to a character column, or binary data copied to a binary column, which is too long for the server column is truncated and SYBEBCOR is reported, as Sybase library does. Any other conversion producing data too long is an error (SYBECOFL).

Parameters
truncatedif not NULL, set to true if data were truncated, false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _bcp_convert_out()

int _bcp_convert_out ( DBPROCESS * dbproc,
TDSCOLUMN * curcol,
BCP_HOSTCOLINFO * hostcol,
TDS_UCHAR ** p_data,
const char * bcpdatefmt )
static

Convert column for output (usually to a file) Conversion is slightly different from input as:

  • date is formatted differently;
  • you have to set properly numeric while on input the column metadata are used;
  • we need to make sure buffer is always at least a minimum bytes.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _bcp_no_get_col_data()

TDSRET _bcp_no_get_col_data ( TDSBCPINFO *bcpinfo TDS_UNUSED,
TDSCOLUMN *bindcol TDS_UNUSED,
int index TDS_UNUSED,
int offset TDS_UNUSED )
static

Function to read data from file.

In this case is empty as data are already on bcp_column_data