FreeTDS API
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Enumerations | Functions
bulk.c File Reference

Handle bulk copy. More...

#include <config.h>
#include <assert.h>
#include <freetds/tds.h>
#include <freetds/checks.h>
#include <freetds/bytes.h>
#include <freetds/iconv.h>
#include <freetds/stream.h>
#include <freetds/convert.h>
#include <freetds/utils/string.h>
#include <freetds/replacements.h>
Include dependency graph for bulk.c:

Classes

struct  tds_file_stream
 input stream to read a file More...
 
struct  tds_pbcb
 Holds clause buffer. More...
 

Macros

#define BULKCOL(n)
 

Typedefs

typedef struct tds_file_stream TDSFILESTREAM
 input stream to read a file
 
typedef struct tds_pbcb TDSPBCB
 Holds clause buffer.
 

Enumerations

enum  {
  BULKCOL_colcnt , BULKCOL_colid , BULKCOL_type , BULKCOL_length ,
  BULKCOL_status , BULKCOL_offset , BULKCOL_COUNT , BULKCOL_ALL = (1 << BULKCOL_COUNT) -1
}
 

Functions

static int tds5_bcp_add_fixed_columns (TDSBCPINFO *bcpinfo, tds_bcp_get_col_data get_col_data, tds_bcp_null_error null_error, int offset, unsigned char *rowbuffer, int start)
 Add fixed size columns to the row.
 
static int tds5_bcp_add_variable_columns (TDSBCPINFO *bcpinfo, tds_bcp_get_col_data get_col_data, tds_bcp_null_error null_error, int offset, TDS_UCHAR *rowbuffer, int start, int *pncols)
 Add variable size columns to the row.
 
static int tds5_bulk_insert_column (const char *name)
 
static TDSRET tds5_process_insert_bulk_reply (TDSSOCKET *tds, TDSBCPINFO *bcpinfo)
 
static TDSRET tds5_send_record (TDSSOCKET *tds, TDSBCPINFO *bcpinfo, tds_bcp_get_col_data get_col_data, tds_bcp_null_error null_error, int offset)
 
static void tds5_swap_data (const TDSCOLUMN *col, void *p)
 
static TDSRET tds7_bcp_send_colmetadata (TDSSOCKET *tds, TDSBCPINFO *bcpinfo)
 Send BCP metadata to server.
 
static TDSRET tds7_build_bulk_insert_stmt (TDSSOCKET *tds, TDSPBCB *clause, TDSCOLUMN *bcpcol, int first)
 Help to build query to be sent to server.
 
static TDSRET tds7_send_record (TDSSOCKET *tds, TDSBCPINFO *bcpinfo, tds_bcp_get_col_data get_col_data, int offset)
 
TDSRET tds_bcp_done (TDSSOCKET *tds, int *rows_copied)
 Tell we finished sending BCP data to server.
 
TDSRET tds_bcp_fread (TDSSOCKET *tds, TDSICONV *char_conv, FILE *stream, const char *terminator, size_t term_len, char **outbuf, size_t *outbytes)
 Read a data file, passing the data through iconv().
 
TDSRET tds_bcp_init (TDSSOCKET *tds, TDSBCPINFO *bcpinfo)
 Initialize BCP information.
 
static void tds_bcp_row_free (TDSRESULTINFO *result, unsigned char *row)
 Free row data allocated in the result set.
 
TDSRET tds_bcp_send_record (TDSSOCKET *tds, TDSBCPINFO *bcpinfo, tds_bcp_get_col_data get_col_data, tds_bcp_null_error null_error, int offset)
 Send one row of data to server.
 
TDSRET tds_bcp_start (TDSSOCKET *tds, TDSBCPINFO *bcpinfo)
 Start sending BCP data to server.
 
TDSRET tds_bcp_start_copy_in (TDSSOCKET *tds, TDSBCPINFO *bcpinfo)
 Start bulk copy to server.
 
static TDSRET tds_bcp_start_insert_stmt (TDSSOCKET *tds, TDSBCPINFO *bcpinfo)
 Prepare the query to be sent to server to request BCP information.
 
static int tds_file_stream_read (TDSINSTREAM *stream, void *ptr, size_t len)
 Reads a chunk of data from file stream checking for terminator.
 
TDSRET tds_writetext_continue (TDSSOCKET *tds, const TDS_UCHAR *text, TDS_UINT size)
 Send some data in the writetext request started by tds_writetext_start.
 
TDSRET tds_writetext_end (TDSSOCKET *tds)
 Finish sending writetext data.
 
TDSRET tds_writetext_start (TDSSOCKET *tds, const char *objname, const char *textptr, const char *timestamp, int with_log, TDS_UINT size)
 Start writing writetext request.
 

Detailed Description

Handle bulk copy.

Macro Definition Documentation

◆ BULKCOL

#define BULKCOL (   n)
Value:
do {\
if (strcmp(name, #n) == 0) \
return BULKCOL_ ## n; \
} while(0)

Function Documentation

◆ tds5_bcp_add_fixed_columns()

static int tds5_bcp_add_fixed_columns ( TDSBCPINFO bcpinfo,
tds_bcp_get_col_data  get_col_data,
tds_bcp_null_error  null_error,
int  offset,
unsigned char *  rowbuffer,
int  start 
)
static

Add fixed size columns to the row.

Parameters
bcpinfoBCP information
get_col_datafunction to call to retrieve data to be sent
ignoredfunction to call if we try to send NULL if not allowed (not used)
offsetpassed to get_col_data and null_error to specify the row to get
rowbufferrow buffer to write to
startrow buffer last end position
Returns
new row length or -1 on error.
Here is the call graph for this function:

◆ tds5_bcp_add_variable_columns()

static int tds5_bcp_add_variable_columns ( TDSBCPINFO bcpinfo,
tds_bcp_get_col_data  get_col_data,
tds_bcp_null_error  null_error,
int  offset,
TDS_UCHAR *  rowbuffer,
int  start,
int *  pncols 
)
static

Add variable size columns to the row.

Parameters
bcpinfoBCP information already prepared
get_col_datafunction to call to retrieve data to be sent
null_errorfunction to call if we try to send NULL if not allowed
offsetpassed to get_col_data and null_error to specify the row to get
rowbufferThe row image that will be sent to the server.
startWhere to begin copying data into the rowbuffer.
pncolsAddress of output variable holding the count of columns added to the rowbuffer.
Returns
length of (potentially modified) rowbuffer, or -1.

◆ tds7_bcp_send_colmetadata()

static TDSRET tds7_bcp_send_colmetadata ( TDSSOCKET tds,
TDSBCPINFO bcpinfo 
)
static

Send BCP metadata to server.

Only for TDS 7.0+.

Parameters
tdsA pointer to the TDSSOCKET structure managing a client/server operation.
bcpinfoBCP information
Returns
TDS_SUCCESS or TDS_FAIL.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tds7_build_bulk_insert_stmt()

static TDSRET tds7_build_bulk_insert_stmt ( TDSSOCKET tds,
TDSPBCB clause,
TDSCOLUMN bcpcol,
int  first 
)
static

Help to build query to be sent to server.

Append column declaration to the query. Only for TDS 7.0+.

Parameters
tdsA pointer to the TDSSOCKET structure managing a client/server operation.
[out]clauseoutput string
bcpcolcolumn to append
firsttrue if column is the first
Returns
TDS_SUCCESS or TDS_FAIL.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tds_bcp_done()

TDSRET tds_bcp_done ( TDSSOCKET tds,
int *  rows_copied 
)

Tell we finished sending BCP data to server.

Parameters
tdsA pointer to the TDSSOCKET structure managing a client/server operation.
[out]rows_copiednumber of rows copied to server
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tds_bcp_fread()

TDSRET tds_bcp_fread ( TDSSOCKET tds,
TDSICONV char_conv,
FILE *  stream,
const char *  terminator,
size_t  term_len,
char **  outbuf,
size_t *  outbytes 
)

Read a data file, passing the data through iconv().

Return values
TDS_SUCCESSsuccess
TDS_FAILerror reading the column
TDS_NO_MORE_RESULTSend of file detected
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tds_bcp_init()

TDSRET tds_bcp_init ( TDSSOCKET tds,
TDSBCPINFO bcpinfo 
)

Initialize BCP information.

Query structure of the table to server.

Parameters
tdsA pointer to the TDSSOCKET structure managing a client/server operation.
bcpinfoBCP information to initialize. Structure should be allocate and table name and direction should be already set.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tds_bcp_send_record()

TDSRET tds_bcp_send_record ( TDSSOCKET tds,
TDSBCPINFO bcpinfo,
tds_bcp_get_col_data  get_col_data,
tds_bcp_null_error  null_error,
int  offset 
)

Send one row of data to server.

Parameters
tdsA pointer to the TDSSOCKET structure managing a client/server operation.
bcpinfoBCP information
get_col_datafunction to call to retrieve data to be sent
ignoredfunction to call if we try to send NULL if not allowed (not used)
offsetpassed to get_col_data and null_error to specify the row to get
Returns
TDS_SUCCESS or TDS_FAIL.
Here is the caller graph for this function:

◆ tds_bcp_start()

TDSRET tds_bcp_start ( TDSSOCKET tds,
TDSBCPINFO bcpinfo 
)

Start sending BCP data to server.

Initialize stream to accept data.

Parameters
tdsA pointer to the TDSSOCKET structure managing a client/server operation.
bcpinfoBCP information already prepared
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tds_bcp_start_copy_in()

TDSRET tds_bcp_start_copy_in ( TDSSOCKET tds,
TDSBCPINFO bcpinfo 
)

Start bulk copy to server.

Parameters
tdsA pointer to the TDSSOCKET structure managing a client/server operation.
bcpinfoBCP information already prepared
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tds_bcp_start_insert_stmt()

static TDSRET tds_bcp_start_insert_stmt ( TDSSOCKET tds,
TDSBCPINFO bcpinfo 
)
static

Prepare the query to be sent to server to request BCP information.

Parameters
tdsA pointer to the TDSSOCKET structure managing a client/server operation.
bcpinfoBCP information
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tds_file_stream_read()

static int tds_file_stream_read ( TDSINSTREAM stream,
void *  ptr,
size_t  len 
)
static

Reads a chunk of data from file stream checking for terminator.

Parameters
streamfile stream
ptrbuffer where to read data
lenlength of buffer
Here is the caller graph for this function:

◆ tds_writetext_continue()

TDSRET tds_writetext_continue ( TDSSOCKET tds,
const TDS_UCHAR *  text,
TDS_UINT  size 
)

Send some data in the writetext request started by tds_writetext_start.

You should write in total (with multiple calls to this function) all bytes declared calling tds_writetext_start.

Parameters
tdsA pointer to the TDSSOCKET structure managing a client/server operation.
textdata to write
sizedata size in bytes
Here is the caller graph for this function:

◆ tds_writetext_end()

TDSRET tds_writetext_end ( TDSSOCKET tds)

Finish sending writetext data.

Parameters
tdsA pointer to the TDSSOCKET structure managing a client/server operation.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tds_writetext_start()

TDSRET tds_writetext_start ( TDSSOCKET tds,
const char *  objname,
const char *  textptr,
const char *  timestamp,
int  with_log,
TDS_UINT  size 
)

Start writing writetext request.

This request start a bulk session.

Parameters
tdsA pointer to the TDSSOCKET structure managing a client/server operation.
objnametable name
textptrTEXTPTR (see sql documentation)
timestampdata timestamp
with_logis log is enabled during insert
sizebytes to be inserted
Here is the call graph for this function:
Here is the caller graph for this function: