Skip to content

Commit 5636445

Browse files
committed
ctlib: Add support for setting hints for bulk copy
This is an extension as Sybase does not support hints. Microsoft supports hints using bcp_control. Hints are passed as a string using blk_props. Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
1 parent e2cf0d3 commit 5636445

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

include/bkpublic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ extern "C"
3535
/* bulk properties start with 1 */
3636
#define BLK_IDENTITY 1
3737

38+
/* FreeTDS extention, set MS bulk hints */
39+
#define BLK_HINTS 1001
40+
3841
CS_RETCODE blk_alloc(CS_CONNECTION * connection, CS_INT version, CS_BLKDESC ** blk_pointer);
3942
CS_RETCODE blk_bind(CS_BLKDESC * blkdesc, CS_INT colnum, CS_DATAFMT * datafmt, CS_VOID * buffer, CS_INT * datalen,
4043
CS_SMALLINT * indicator);

include/ctlib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,8 @@ const CS_DATAFMT_LARGE *_ct_datafmt_conv_in(CS_CONTEXT * ctx, const CS_DATAFMT *
402402
CS_DATAFMT_LARGE *_ct_datafmt_conv_prepare(CS_CONTEXT * ctx, CS_DATAFMT * datafmt, CS_DATAFMT_LARGE * fmtbuf);
403403
void _ct_datafmt_conv_back(CS_DATAFMT * datafmt, CS_DATAFMT_LARGE * fmtbuf);
404404

405+
CS_RETCODE _ct_props_dstr(CS_CONNECTION * con, DSTR *s, CS_INT action, CS_VOID * buffer, CS_INT buflen, CS_INT * outlen);
406+
405407
#ifdef __cplusplus
406408
#if 0
407409
{

src/ctlib/blk.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,9 @@ blk_props(CS_BLKDESC * blkdesc, CS_INT action, CS_INT property, CS_VOID * buffer
405405
}
406406
break;
407407

408+
case BLK_HINTS:
409+
return _ct_props_dstr(CONN(blkdesc), &blkdesc->bcpinfo.hint, action, buffer, buflen, outlen);
410+
408411
default:
409412
_ctclient_msg(NULL, CONN(blkdesc), "blk_props", 2, 5, 1, 141, "%s, %d", "property", property);
410413
break;

src/ctlib/ctutil.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,27 @@ _ct_get_string_length(const char *buf, CS_INT buflen)
334334

335335
return buflen;
336336
}
337+
338+
CS_RETCODE
339+
_ct_props_dstr(CS_CONNECTION * con, DSTR *s, CS_INT action, CS_VOID * buffer, CS_INT buflen, CS_INT * out_len)
340+
{
341+
if (action == CS_SET) {
342+
buflen = _ct_get_string_length(buffer, buflen);
343+
if (buflen < 0) {
344+
/* TODO what error ?? */
345+
_ctclient_msg(NULL, con, "ct_con_props(SET,APPNAME)", 1, 1, 1, 5, "%d, %s", buflen, "buflen");
346+
return CS_FAIL;
347+
}
348+
if (tds_dstr_copyn(s, buffer, buflen) != NULL)
349+
return CS_SUCCEED;
350+
} else if (action == CS_GET) {
351+
if (out_len)
352+
*out_len = tds_dstr_len(s);
353+
strlcpy((char *) buffer, tds_dstr_cstr(s), buflen);
354+
return CS_SUCCEED;
355+
} else if (action == CS_CLEAR) {
356+
tds_dstr_empty(s);
357+
return CS_SUCCEED;
358+
}
359+
return CS_FAIL;
360+
}

src/ctlib/unittests/blk_in2.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ hoge_blkin(CS_CONNECTION * con, CS_BLKDESC * blk, char *table, char *data)
2424
check_call(ct_cancel, (con, NULL, CS_CANCEL_ALL));
2525
check_call(blk_init, (blk, CS_BLK_IN, table, CS_NULLTERM));
2626

27+
check_call(blk_props, (blk, CS_SET, BLK_HINTS, "TABLOCK", CS_NULLTERM, NULL));
28+
2729
meta.count = 1;
2830
meta.datatype = CS_CHAR_TYPE;
2931
meta.format = CS_FMT_PADBLANK;

0 commit comments

Comments
 (0)