Re: How to apply Bulk Copy hints when using ctlib ?

[email protected]
Newsgroups gmane.comp.db.tds.freetds
Message-ID <[email protected]>
On Thu, Mar 03, 2011 at 05:45:39PM +0200, Mark Songhurst wrote:
> You wrote:
> 
> > As long as blkdesc->bcpinfo.hint points to a valid string
> 
> I'm using 0.82 of FreeTDS and my BLKDESC structure boils down to this,
> in ctlib.h:
> 
> struct _cs_blkdesc
> {
> 	CS_CONNECTION *con;
> 	CS_CHAR *tablename;
> 	CS_CHAR *insert_stmt;
> 	CS_INT direction;
> 	CS_INT identity_insert_on;
> 	CS_INT bind_count;
> 	CS_INT xfer_init;
> 	CS_INT var_cols;
> 	TDSRESULTINFO *bindinfo;
> };
> 
> I don't have a bcpinfo member.
> Please can you tell me if you are referring to a newer version of
> FreeTDS, or perhaps I have misunderstood your suggestion?

You understood correctly; I had just checked CVS HEAD.  :-/  

It will be easier to change a recent snapshot, because Frediano unified the
bcp structures.  If you want to modify 0.82, you'll have to add your own hint
member.  

In case it matters, we're actively working on a new release Real Soon Now.  I
would be happy to incorporate your patch if you want to contribute one.  

In ctlib.h we currently have:

struct _cs_blkdesc
{
	CS_CONNECTION *con;
	TDSBCPINFO bcpinfo;
};

and in tds.h:

typedef struct tds_bcpinfo
{
	const char *hint;
	void *parent;
	TDS_CHAR *tablename;
	TDS_CHAR *insert_stmt;
	TDS_INT direction;
	TDS_INT identity_insert_on;
	TDS_INT xfer_init;
	TDS_INT var_cols;
	TDS_INT bind_count;
	TDSRESULTINFO *bindinfo;
} TDSBCPINFO;

This is used in src/tds/bulk.c::tds_bcp_start_insert_stmt()

	if (bcpinfo->hint) {
		if (asprintf(&hint, " with (%s)", bcpinfo->hint) < 0)
			hint = NULL;
	} else {
		hint = strdup("");
	}

As you can see, it's important that the hint text be carefully controlled, which
is why it's checked against a static list in db-lib.  

HTH.

--jkl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.