Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

www.webdp.net, Event 9 IIS log failed to write entry, wwwxxx jeffs, Catastrophic failure Unexpected method call sequence. 0x8000ffff (-2147418113)., ksh lock a file, [unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_DBC failed, sed: -e expression #1, char 1: unterminated address regex, procmail + change subject, w2ksp4.exe download, /proc/kallsyms format

Links

XODOX
Impressum

#1: MyODBC and BLOB"s

Posted on 2005-04-20 23:59:03 by Ian Klassen

Hello,

I was able to track down the problem with extending the net buffer to handl=
e BLOB's. In the functions copy_rowdata and batch_insert a MYSQL object is=
created by copying an existing MYSQL object from a STMT object (stmt).=20=
=20

The problem is that when the buffer is extended, only the original is updat=
ed to point to the newly allocated memory. I have updated these two functi=
ons to use MYSQL pointers instead and all is fine.

Will this fix cause some other problems?

Ian

static SQLRETURN batch_insert(STMT FAR *stmt, SQLUSMALLINT irow,
DYNAMIC_STRING *ext_query)
{
MYSQL_RES *result=3D stmt->result;
SQLUINTEGER insert_count=3D 1;
SQLUINTEGER count=3D 0;
SQLINTEGER length;
NET *net;
SQLUSMALLINT ncol;
SQLCHAR *to;
ulong query_length=3D 0;
my_bool break_insert=3D FALSE;
MYSQL* mysql=3D &stmt->dbc->mysql ;
PARAM_BIND param;

if (!irow && stmt->stmt_options.rows_in_set > 1) /* batch wise */
{
insert_count=3D stmt->stmt_options.rows_in_set;
query_length=3D ext_query->length;
}

do
{
if (break_insert)
{
/*
If query exceeded its length, then set the query
from begining..
*/
ext_query->length=3D query_length;
}
while (count < insert_count)
{
net=3D &(mysql->net);
to =3D net->buff;

dynstr_append_mem(ext_query,"(", 1);

for (ncol=3D 0; ncol < result->field_count; ncol++)
{
SQLUINTEGER transfer_length,precision,display_size;
MYSQL_FIELD *field=3D mysql_fetch_field_direct(result,ncol);
BIND *bind=3D stmt->bind+ncol;

param.SqlType=3D unireg_to_sql_datatype(stmt,field,0,
&transfer_length,&precision,
&display_size);
param.CType =3D bind->fCType;
param.buffer=3D (gptr) bind->rgbValue+count*bind->cbValueMax;

if (param.buffer)
{
if (bind->pcbValue)
{
if (*bind->pcbValue == SQL_NTS)
length=3D strlen(param.buffer);
else if (*bind->pcbValue == SQL_COLUMN_IGNORE)
length=3D SQL_NULL_DATA;
else length=3D *bind->pcbValue;
}
else length=3D bind->cbValueMax;
}
else length=3D SQL_NULL_DATA;
param.actual_len=3D &length;

if (copy_rowdata(stmt,param,&net,&to) !=3D SQL_SUCCESS)
return(SQL_ERROR);

} /* END OF for (ncol=3D 0; ncol < result->field_count; ncol++) */

length=3D (uint) ((char *)to - (char*) net->buff);
dynstr_append_mem(ext_query, (char*) net->buff, length-1);
dynstr_append_mem(ext_query, "),", 2);
count++;
if (ext_query->length+length >=3D net_buffer_length)
{
break_insert=3D TRUE;
break;
}
} /* END OF while(count < insert_count) */

ext_query->str[--ext_query->length]=3D '\0';

if (exec_stmt_query(stmt, ext_query->str, ext_query->length) !=3D
SQL_SUCCESS)
return(SQL_ERROR);

} while (break_insert && count < insert_count);

stmt->affected_rows=3D stmt->dbc->mysql.affected_rows=3D insert_count;
if (stmt->stmt_options.rowStatusPtr)
{
for (count=3D insert_count; count--;)
stmt->stmt_options.rowStatusPtr[count]=3D SQL_ROW_ADDED;
}
return(SQL_SUCCESS);
}

static SQLRETURN copy_rowdata(STMT FAR *stmt, PARAM_BIND param,
NET **net, SQLCHAR **to)
{
SQLCHAR *orig_to=3D *to;
MYSQL* mysql=3D &stmt->dbc->mysql;
SQLUINTEGER length=3D *(param.actual_len)+1;

DBUG_PRINT("copy_rowdata",("buffer: '%s', length: %d, actual: %d", *to, l=
ength, sizeof(**to)));

if (!(*to=3D (SQLCHAR *) extend_buffer(*net,(char*) *to,length)))
return set_error(stmt,MYERR_S1001,NULL,4001);

if (!(*to=3D (SQLCHAR*) insert_param(mysql, (char*) *to, &param)))
return set_error(stmt,MYERR_S1001,NULL,4001);

/* We have to remove zero bytes or we have problems! */
while ((*to > orig_to) && (*((*to) - 1) == (SQLCHAR) 0)) (*to)--;

/* insert "," */
param.SqlType=3D SQL_INTEGER;
param.CType=3D SQL_C_CHAR;
param.buffer=3D (gptr) ",";
*param.actual_len=3D 1;

if (!(*to=3D (SQLCHAR*) insert_param(mysql,(char*) *to, &param)))
return set_error(stmt,MYERR_S1001,NULL,4001);

return(SQL_SUCCESS);
}

--
MySQL ODBC Mailing List
For list archives: http://lists.mysql.com/myodbc
To unsubscribe: http://lists.mysql.com/myodbc?unsub=3Dgcdmo-myodbc@m.gmane.o rg

Report this message