|
FreeTDS API
|
Handle bulk copy. More...
#include <config.h>#include <assert.h>#include <freetds/tds.h>#include <freetds/tds/checks.h>#include <freetds/bytes.h>#include <freetds/tds/iconv.h>#include <freetds/tds/stream.h>#include <freetds/tds/convert.h>#include <freetds/utils/string.h>#include <freetds/utils/ascii.h>#include <freetds/replacements.h>#include <freetds/enum_cap.h>Classes | |
| struct | tds_pbcb |
| Holds clause buffer. More... | |
Macros | |
| #define | BULKCOL(n) |
| #define | check_binary_mode(f) |
Typedefs | |
| typedef struct tds_pbcb | TDSPBCB |
| Holds clause buffer. | |
Enumerations | |
| enum | { BULKCOL_colcnt , BULKCOL_colid , BULKCOL_type , BULKCOL_length , BULKCOL_status , BULKCOL_offset , BULKCOL_dflt , BULKCOL_COUNT , BULKCOL_ALL = (1 << BULKCOL_COUNT) -1 } |
Functions | |
| static bool | cbuf_match (const char *cbuf, size_t cbuf_size, size_t cpos, const char *match) |
| Check if a circular buffer matches a string of same length. | |
| static TDSRET | probe_sap_locking (TDSSOCKET *tds, TDSBCPINFO *bcpinfo) |
| Detect if table we're writing to uses 'datarows' lockmode. | |
| 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_get_col_data_or_dflt (tds_bcp_get_col_data get_col_data, TDSBCPINFO *bulk, TDSCOLUMN *bcpcol, int offset, int colnum) |
| static TDSRET | tds5_process_insert_bulk_reply (TDSSOCKET *tds, TDSBCPINFO *bcpinfo) |
| static void | tds5_read_bulk_defaults (TDSSOCKET *tds TDS_UNUSED, TDSRESULTINFO *res_info, TDSBCPINFO *bcpinfo) |
| static TDSRET | tds5_send_blobs (TDSSOCKET *tds, TDSBCPINFO *bcpinfo, tds_bcp_get_col_data get_col_data, int offset, int start_col) |
| Send text/image columns of a row (TDS 5.0), starting from a given column. | |
| 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 TDS_UNUSED, void *p TDS_UNUSED) |
| static bool | tds7_bcp_column_deferrable (TDSCOLUMN *bcpcol) |
| Check if a column can be sent using tds_bcp_send_blob_data (TDS 7+). | |
| static bool | tds7_bcp_column_skipped (TDSBCPINFO *bcpinfo, TDSCOLUMN *bcpcol) |
| Check if a column is not sent to server. | |
| 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 void | tds7_put_deferred_header (TDSSOCKET *tds, TDSCOLUMN *bindcol) |
| Send header of a column whose data will be sent using tds_bcp_send_blob_data. | |
| static TDSRET | tds7_send_columns (TDSSOCKET *tds, TDSBCPINFO *bcpinfo, int start_col) |
| Send columns of a row, starting from a given column. | |
| static TDSRET | tds7_send_record (TDSSOCKET *tds, TDSBCPINFO *bcpinfo, tds_bcp_get_col_data get_col_data, tds_bcp_null_error null_error, int offset) |
| TDSRET | tds_bcp_cancel (TDSSOCKET *tds) |
| Cancel sending BCP data to server. | |
| 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, TDSFILESTREAM *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 TDS_UNUSED) |
| Free row data allocated in the result set. | |
| static void | tds_bcp_row_free (TDSRESULTINFO *result, unsigned char *row) |
| TDSRET | tds_bcp_send_blob_data (TDSSOCKET *tds, TDSBCPINFO *bcpinfo, const void *data, TDS_INT len) |
| Send data for a deferred blob column. | |
| 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. | |
| TDSRET | tds_file_stream_close (TDSFILESTREAM *stream) |
| TDSRET | tds_file_stream_init (TDSFILESTREAM *stream, FILE *f) |
| static int | tds_file_stream_read (TDSINSTREAM *stream, void *ptr, size_t len) |
| Reads a chunk of data from file stream checking for terminator. | |
| size_t | tds_file_stream_read_raw (TDSFILESTREAM *stream, void *ptr, size_t n) |
| TDSRET | tds_file_stream_seek_set (TDSFILESTREAM *stream, offset_type seek_to) |
| offset_type | tds_file_stream_tell (TDSFILESTREAM *stream) |
| static TDSRET | tds_file_stream_use_terminator (TDSFILESTREAM *stream, const char *term, size_t term_len) |
| Sets the terminator and also performs an initial population of the circular buffer. | |
| 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. | |
| static const char * | uc_str (const char *s) |
Handle bulk copy.
| #define BULKCOL | ( | n | ) |
| #define check_binary_mode | ( | f | ) |
|
static |
Check if a circular buffer matches a string of same length.
Requires length > 0.
|
static |
Detect if table we're writing to uses 'datarows' lockmode.
| tds | A pointer to the TDSSOCKET structure managing a client/server operation. |
| bcpinfo | BCP information already prepared |
|
static |
Add fixed size columns to the row.
| bcpinfo | BCP information |
| get_col_data | function to call to retrieve data to be sent |
| ignored | function to call if we try to send NULL if not allowed (not used) |
| offset | passed to get_col_data and null_error to specify the row to get |
| rowbuffer | row buffer to write to |
| start | row buffer last end position |
|
static |
Add variable size columns to the row.
| bcpinfo | BCP information already prepared |
| get_col_data | function to call to retrieve data to be sent |
| null_error | function to call if we try to send NULL if not allowed |
| offset | passed to get_col_data and null_error to specify the row to get |
| rowbuffer | The row image that will be sent to the server. |
| start | Where to begin copying data into the rowbuffer. |
| pncols | Address of output variable holding the count of columns added to the rowbuffer. |
|
static |
Send text/image columns of a row (TDS 5.0), starting from a given column.
Stops at the first deferred column.
| get_col_data | function to retrieve data, NULL if data are already retrieved |
|
static |
Check if a column can be sent using tds_bcp_send_blob_data (TDS 7+).
Data are sent as they are so Unicode columns are not supported.
|
static |
Check if a column is not sent to server.
Timestamp columns and identity columns (unless identity_insert is enabled) are not sent.
|
static |
Send BCP metadata to server.
Only for TDS 7.0+.
| tds | A pointer to the TDSSOCKET structure managing a client/server operation. |
| bcpinfo | BCP information |
|
static |
Help to build query to be sent to server.
Append column declaration to the query. Only for TDS 7.0+.
| tds | A pointer to the TDSSOCKET structure managing a client/server operation. | |
| [out] | clause | output string |
| bcpcol | column to append | |
| first | true if column is the first |
|
static |
Send columns of a row, starting from a given column.
Data must be already retrieved. Stops at the first deferred column.
| TDSRET tds_bcp_cancel | ( | TDSSOCKET * | tds | ) |
Cancel sending BCP data to server.
Data not already sent are discarded, data already sent in the current batch are not inserted.
| tds | A pointer to the TDSSOCKET structure managing a client/server operation. |
| TDSRET tds_bcp_done | ( | TDSSOCKET * | tds, |
| int * | rows_copied ) |
Tell we finished sending BCP data to server.
| tds | A pointer to the TDSSOCKET structure managing a client/server operation. | |
| [out] | rows_copied | number of rows copied to server |
| TDSRET tds_bcp_fread | ( | TDSSOCKET * | tds, |
| TDSICONV * | char_conv, | ||
| TDSFILESTREAM * | stream, | ||
| const char * | terminator, | ||
| size_t | term_len, | ||
| char ** | outbuf, | ||
| size_t * | outbytes ) |
Read a data file, passing the data through iconv().
| TDS_SUCCESS | success |
| TDS_FAIL | error reading the column |
| TDS_NO_MORE_RESULTS | end of file detected |
| TDSRET tds_bcp_init | ( | TDSSOCKET * | tds, |
| TDSBCPINFO * | bcpinfo ) |
Initialize BCP information.
Query structure of the table to server.
| tds | A pointer to the TDSSOCKET structure managing a client/server operation. |
| bcpinfo | BCP information to initialize. Structure should be allocate and table name and direction should be already set. |
| TDSRET tds_bcp_send_blob_data | ( | TDSSOCKET * | tds, |
| TDSBCPINFO * | bcpinfo, | ||
| const void * | data, | ||
| TDS_INT | len ) |
Send data for a deferred blob column.
tds_bcp_send_record stops sending a row at the first deferred column (see BCPCOLDATA::deferred), data for that column are then sent with this function, possibly in multiple chunks. When all data for the column are sent the rest of the row is sent, stopping at the next deferred column, if any. Data are sent as they are, they must be already in server format.
| tds | A pointer to the TDSSOCKET structure managing a client/server operation. |
| bcpinfo | BCP information |
| data | data to send |
| len | length of data, cannot exceed data still to be sent for the column (bcpinfo->blob_left) |
| 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.
| tds | A pointer to the TDSSOCKET structure managing a client/server operation. |
| bcpinfo | BCP information |
| get_col_data | function to call to retrieve data to be sent |
| ignored | function to call if we try to send NULL if not allowed (not used) |
| offset | passed to get_col_data and null_error to specify the row to get |
| TDSRET tds_bcp_start | ( | TDSSOCKET * | tds, |
| TDSBCPINFO * | bcpinfo ) |
Start sending BCP data to server.
Initialize stream to accept data.
| tds | A pointer to the TDSSOCKET structure managing a client/server operation. |
| bcpinfo | BCP information already prepared |
| TDSRET tds_bcp_start_copy_in | ( | TDSSOCKET * | tds, |
| TDSBCPINFO * | bcpinfo ) |
Start bulk copy to server.
| tds | A pointer to the TDSSOCKET structure managing a client/server operation. |
| bcpinfo | BCP information already prepared |
|
static |
Prepare the query to be sent to server to request BCP information.
| tds | A pointer to the TDSSOCKET structure managing a client/server operation. |
| bcpinfo | BCP information |
|
static |
Reads a chunk of data from file stream checking for terminator.
| stream | file stream |
| ptr | buffer where to read data |
| len | length of buffer |
| 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.
| tds | A pointer to the TDSSOCKET structure managing a client/server operation. |
| text | data to write |
| size | data size in bytes |
| TDSRET tds_writetext_end | ( | TDSSOCKET * | tds | ) |
Finish sending writetext data.
| tds | A pointer to the TDSSOCKET structure managing a client/server operation. |
| 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.
| tds | A pointer to the TDSSOCKET structure managing a client/server operation. |
| objname | table name |
| textptr | TEXTPTR (see sql documentation) |
| timestamp | data timestamp |
| with_log | is log is enabled during insert |
| size | bytes to be inserted |