NCBI C++ ToolKit
Macros | Functions
bcp.c File Reference
#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/odbc.h>
#include <freetds/string.h>
#include <odbcss.h>
+ Include dependency graph for bcp.c:

Go to the source code of this file.

Go to the SVN repository for this file.

Macros

#define TDSODBC_BCP
 
#define ODBCBCP_ERROR_RETURN(code)    do {odbc_errs_add(&dbc->errs, code, NULL); return;} while(0)
 
#define ODBCBCP_ERROR_DBINT(code)    do {odbc_errs_add(&dbc->errs, code, NULL); return -1;} while(0)
 

Functions

static TDSRET _bcp_get_col_data (TDSBCPINFO *bcpinfo, TDSCOLUMN *bindcol, int offset)
 
static SQLLEN _bcp_get_term_var (const TDS_CHAR *pdata, const TDS_CHAR *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...
 
void odbc_bcp_init (TDS_DBC *dbc, const ODBC_CHAR *tblname, const ODBC_CHAR *hfile, const ODBC_CHAR *errfile, int direction _WIDE)
 Prepare for bulk copy operation on a table. More...
 
void odbc_bcp_control (TDS_DBC *dbc, int field, void *value)
 Set BCP options for data transfer. More...
 
void odbc_bcp_colptr (TDS_DBC *dbc, const void *colptr, int table_column)
 Override bcp_bind() by pointing to a different host variable. More...
 
void odbc_bcp_sendrow (TDS_DBC *dbc)
 Write data in host variables to the table. More...
 
int odbc_bcp_batch (TDS_DBC *dbc)
 Commit a set of rows to the table. More...
 
int odbc_bcp_done (TDS_DBC *dbc)
 Conclude the transfer of data from program variables. More...
 
void odbc_bcp_bind (TDS_DBC *dbc, const void *varaddr, int prefixlen, int varlen, const void *terminator, int termlen, int vartype, int table_column)
 Bind a program host variable to a database column. More...
 
static SQLLEN _bcp_iconv_helper (const TDS_DBC *dbc, const TDSCOLUMN *bindcol, const TDS_CHAR *src, size_t srclen, char *dest, size_t destlen)
 
static TDS_INT _tdsodbc_dbconvert (TDS_DBC *dbc, int srctype, const TDS_CHAR *src, SQLLEN src_len, int desttype, unsigned char *dest, TDSCOLUMN *bindcol)
 
void odbc_bcp_free_storage (TDS_DBC *dbc)
 

Macro Definition Documentation

◆ ODBCBCP_ERROR_DBINT

#define ODBCBCP_ERROR_DBINT (   code)     do {odbc_errs_add(&dbc->errs, code, NULL); return -1;} while(0)

Definition at line 59 of file bcp.c.

◆ ODBCBCP_ERROR_RETURN

#define ODBCBCP_ERROR_RETURN (   code)     do {odbc_errs_add(&dbc->errs, code, NULL); return;} while(0)

Definition at line 56 of file bcp.c.

◆ TDSODBC_BCP

#define TDSODBC_BCP

Definition at line 48 of file bcp.c.

Function Documentation

◆ _bcp_get_col_data()

static TDSRET _bcp_get_col_data ( TDSBCPINFO bcpinfo,
TDSCOLUMN bindcol,
int  offset 
)
static

◆ _bcp_get_term_var()

static SQLLEN _bcp_get_term_var ( const TDS_CHAR pdata,
const TDS_CHAR term,
int  term_len 
)
static

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.

Call it correctly.

Definition at line 655 of file bcp.c.

References assert, and SQLLEN.

Referenced by _bcp_get_col_data().

◆ _bcp_iconv_helper()

static SQLLEN _bcp_iconv_helper ( const TDS_DBC dbc,
const TDSCOLUMN bindcol,
const TDS_CHAR src,
size_t  srclen,
char *  dest,
size_t  destlen 
)
static

Definition at line 409 of file bcp.c.

References tds_column::char_conv, dbc, tds_iconv, and to_server.

Referenced by _tdsodbc_dbconvert().

◆ _tdsodbc_dbconvert()

static TDS_INT _tdsodbc_dbconvert ( TDS_DBC dbc,
int  srctype,
const TDS_CHAR src,
SQLLEN  src_len,
int  desttype,
unsigned char *  dest,
TDSCOLUMN bindcol 
)
static

◆ odbc_bcp_batch()

int odbc_bcp_batch ( TDS_DBC dbc)

Commit a set of rows to the table.

Parameters
dbcODBC database connection object
Remarks
If not called, bcp_done() will cause the rows to be saved.
Returns
Count of rows saved, or -1 on error.
See also
odbc_bcp_bind(), odbc_bcp_done(), odbc_bcp_sendrow()

Definition at line 278 of file bcp.c.

References dbc, NULL, ODBCBCP_ERROR_DBINT, tds_bcp_done, tds_bcp_start, TDS_DBG_FUNC, TDS_FAILED, and tdsdump_log.

Referenced by _SQLSetConnectAttr().

◆ odbc_bcp_bind()

void odbc_bcp_bind ( TDS_DBC dbc,
const void *  varaddr,
int  prefixlen,
int  varlen,
const void *  terminator,
int  termlen,
int  vartype,
int  table_column 
)

Bind a program host variable to a database column.

Parameters
dbcODBC database connection object
varaddraddress of host variable
prefixlenlength of any prefix found at the beginning of varaddr, in bytes. Use zero for fixed-length datatypes.
varlenbytes of data in varaddr. Zero for NULL, -1 for fixed-length datatypes.
terminatorbyte sequence that marks the end of the data in varaddr
termlenlength of terminator
vartypedatatype of the host variable
table_columnNth column, starting at 1, in the table.
Remarks
The order of operation is:
See also
odbc_bcp_batch(), odbc_bcp_done(), odbc_bcp_sendrow()

Definition at line 345 of file bcp.c.

References tds_column::bcp_prefix_len, tds_column::bcp_term_len, tds_column::bcp_terminator, tds_column::column_bindlen, tds_column::column_bindtype, tds_column::column_type, tds_column::column_varaddr, dbc, is_fixed_type, is_tds_type_valid(), NULL, ODBCBCP_ERROR_RETURN, SQL_VARLEN_DATA, SYBBINARY, SYBCHAR, SYBIMAGE, SYBTEXT, TDS_DBG_FUNC, tds_new, TDS_ZERO_FREE, tdsdump_log, and terminator.

Referenced by _SQLSetConnectAttr().

◆ odbc_bcp_colptr()

void odbc_bcp_colptr ( TDS_DBC dbc,
const void *  colptr,
int  table_column 
)

Override bcp_bind() by pointing to a different host variable.

Parameters
dbcODBC database connection object
colptrThe pointer, the address of your variable.
table_columnThe 1-based column ordinal in the table.
Remarks
Use between calls to bcp_sendrow(). After calling bcp_colptr(), subsequent calls to bcp_sendrow() will bind to the new address.
See also
odbc_bcp_bind(), odbc_bcp_sendrow()

Definition at line 204 of file bcp.c.

References tds_column::column_varaddr, dbc, NULL, ODBCBCP_ERROR_RETURN, TDS_DBG_FUNC, and tdsdump_log.

Referenced by _SQLSetConnectAttr().

◆ odbc_bcp_control()

void odbc_bcp_control ( TDS_DBC dbc,
int  field,
void *  value 
)

Set BCP options for data transfer.

Parameters
dbcODBC database connection object
fieldsymbolic constant indicating the option to be set, one of:
  • BCPKEEPIDENTITY Enable identity insert, as if by executing 'SET IDENTITY_INSERT table ON'. The default is off
  • BCPHINTS Arbitrary extra text to pass to the server. See the documentation for the bcp command-line tool which came with your database server for the correct syntax.
valueThe value for field.
Remarks
These options control the behavior of bcp_sendrow().
See also
odbc_bcp_batch(), odbc_bcp_init(), odbc_bcp_done()

Definition at line 170 of file bcp.c.

References BCPHINTS, BCPKEEPIDENTITY, dbc, NULL, ODBCBCP_ERROR_RETURN, strdup, TDS_DBG_FUNC, tdsdump_log, and value.

Referenced by _SQLSetConnectAttr().

◆ odbc_bcp_done()

int odbc_bcp_done ( TDS_DBC dbc)

Conclude the transfer of data from program variables.

Parameters
dbcODBC database connection object
Remarks
Do not overlook this function. According to Sybase, failure to call bcp_done() "will result in unpredictable errors".
Returns
As with bcp_batch(), the count of rows saved, or -1 on error.
See also
bcp_batch(), bcp_bind(), bcp_moretext(), bcp_sendrow()

Definition at line 305 of file bcp.c.

References dbc, odbc_bcp_free_storage(), ODBCBCP_ERROR_DBINT, tds_bcp_done, TDS_DBG_FUNC, TDS_FAILED, and tdsdump_log.

Referenced by _SQLSetConnectAttr().

◆ odbc_bcp_free_storage()

void odbc_bcp_free_storage ( TDS_DBC dbc)

Definition at line 674 of file bcp.c.

References assert, dbc, NULL, TDS_DBG_FUNC, tds_free_bcpinfo, TDS_ZERO_FREE, and tdsdump_log.

Referenced by odbc_bcp_done(), and odbc_bcp_init().

◆ odbc_bcp_init()

void odbc_bcp_init ( TDS_DBC dbc,
const ODBC_CHAR tblname,
const ODBC_CHAR hfile,
const ODBC_CHAR errfile,
int direction  _WIDE 
)

Prepare for bulk copy operation on a table.

Parameters
dbcODBC database connection object
tblnamethe name of the table receiving or providing the data.
hfilethe data file opposite the table, if any. NB: The current implementation does not support file I/O so this must be NULL
errfilethe "error file" captures messages and, if errors are encountered. NB: The current implementation does not support file I/O so this must be NULL
directionone of
  • DB_IN writing to the table
  • DB_OUT writing to the host file (Not currently supported)
Remarks
bcp_init() sets the host file data format and acquires the table metadata. It is called before the other bulk copy functions.

The ODBC BCP functionality should be accessed via the inline functions in odbcss.h.

After calling this function, call bcp_bind() to associate your data with the appropriate table column.

See also
SQL_COPT_SS_BCP, odbc_bcp_bind(), odbc_bcp_done(), odbc_bcp_exec()

Definition at line 89 of file bcp.c.

References dbc, IS_TDS7_PLUS, NULL, odbc_bcp_free_storage(), odbc_dstr_copy(), ODBCBCP_ERROR_RETURN, SQL_NTS, SQLWSTR, SQLWSTR_BUFS, SQLWSTR_FREE, tds_alloc_bcpinfo, tds_bcp_init, TDS_DBG_FUNC, tds_dstr_len(), TDS_FAILED, TDS_UNLIKELY, tds_write_dump, and tdsdump_log.

◆ odbc_bcp_sendrow()

void odbc_bcp_sendrow ( TDS_DBC dbc)

Write data in host variables to the table.

Parameters
dbcODBC database connection object
Remarks
Call bcp_bind() first to describe the variables to be used. Use bcp_batch() to commit sets of rows. After sending the last row call bcp_done().
See also
odbc_bcp_batch(), odbc_bcp_bind(), odbc_bcp_colptr(), odbc_bcp_done(), odbc_bcp_init()

Definition at line 236 of file bcp.c.

References _bcp_get_col_data(), dbc, NULL, ODBCBCP_ERROR_RETURN, tds, tds_bcp_send_record, tds_bcp_start_copy_in, TDS_DBG_FUNC, TDS_FAILED, and tdsdump_log.

Referenced by _SQLSetConnectAttr().

Modified on Fri Mar 01 10:06:34 2024 by modify_doxy.py rev. 669887