FreeTDS API

Macros | Typedefs | Functions
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/iconv.h>`
`#include <freetds/convert.h>`
`#include <freetds/bytes.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 | fseeko(f, o, w) fseek(f,o,w)
#define | ftello(f) ftell(f)
#define | HOST_COL_CONV_ERROR 1
#define | HOST_COL_NULL_ERROR 2
#define | MAX(a, b) ( (a) > (b) ? (a) : (b) )

## Typedefs
typedef long | offset_type

## Functions
static STATUS | _bcp_check_eof (DBPROCESS *dbproc, FILE *file, int icol)
static TDSRET | _bcp_convert_in (DBPROCESS *dbproc, TDS_SERVER_TYPE srctype, const TDS_CHAR *src, TDS_UINT srclen, TDS_SERVER_TYPE desttype, BCPCOLDATA *coldata)
| 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: More...
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 offset)
| For a bcp in from program variables, get the data from the host variable. More...
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. More...
static TDSRET | _bcp_no_get_col_data (TDSBCPINFO *bcpinfo, TDSCOLUMN *bindcol, int offset)
| Function to read data from file. More...
static void | _bcp_null_error (TDSBCPINFO *bcpinfo, int index, int offset)
static STATUS | _bcp_read_hostfile (DBPROCESS *dbproc, FILE *hostfile, int *row_error, bool skip)
static int | _bcp_readfmt_colinfo (DBPROCESS *dbproc, char *buf, BCP_HOSTCOLINFO *ci)
DBINT | bcp_batch (DBPROCESS *dbproc)
| Commit a set of rows to the table. More...
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. More...
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. More...
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. More...
RETCODE | bcp_collen (DBPROCESS *dbproc, DBINT varlen, int table_column)
| Set the length of a host variable to be written to a table. More...
RETCODE | bcp_colptr (DBPROCESS *dbproc, BYTE *colptr, int table_column)
| Override bcp_bind() by pointing to a different host variable. More...
RETCODE | bcp_columns (DBPROCESS *dbproc, int host_colcount)
| Indicate how many columns are to be found in the datafile. More...
RETCODE | bcp_control (DBPROCESS *dbproc, int field, DBINT value)
| Set BCP options for uploading a datafile. More...
DBINT | bcp_done (DBPROCESS *dbproc)
| Conclude the transfer of data from program variables. More...
RETCODE | bcp_exec (DBPROCESS *dbproc, DBINT *rows_copied)
| Write a datafile to a table. More...
int | bcp_getbatchsize (DBPROCESS *dbproc)
DBBOOL | bcp_getl (LOGINREC *login)
| See if BCP_SETL() was used to set the LOGINREC for BCP work. More...
RETCODE | bcp_init (DBPROCESS *dbproc, const char *tblname, const char *hfile, const char *errfile, int direction)
| Prepare for bulk copy operation on a table. More...
RETCODE | bcp_options (DBPROCESS *dbproc, int option, BYTE *value, int valuelen)
| Set "hints" for uploading a file. More...
RETCODE | bcp_readfmt (DBPROCESS *dbproc, const char filename[])
| Read a format definition file. More...
RETCODE | bcp_sendrow (DBPROCESS *dbproc)
| Write data in host variables to the table. More...
static RETCODE | bcp_write_prefix (FILE *hostfile, 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 More...
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_out()

static 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:

## ◆ _bcp_no_get_col_data()

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

Function to read data from file.

I this case is empty as data are already on bcp_column_data