| Bug #11406 | Encounter "Lost connection to MySQL server during query" | ||
|---|---|---|---|
| Submitted: | 17 Jun 2005 7:38 | Modified: | 11 Jun 2007 16:42 |
| Reporter: | longsebo longsebo | Email Updates: | |
| Status: | Can't repeat | Impact on me: | |
| Category: | Connector / ODBC | Severity: | S2 (Serious) |
| Version: | 3.51 | OS: | Windows (w2k server) |
| Assigned to: | CPU Architecture: | Any | |
[17 Jun 2005 7:38]
longsebo longsebo
[17 Jun 2005 9:27]
Vasily Kishkin
Could you please try to set "--max_allowed_packet=2000000" in server options ?
[17 Jun 2005 23:53]
longsebo longsebo
I tryed make data pack size of current max_allowed_packet value,but same error!!
Then I tryed split the data pack to one to one small pack 1K,loop putdata of odbc api, but same error!flow samle code and table define :
typedef struct
{
int seqno;
char name[256];
char *content;
char typecode[31];
char location[267];
char type_name[41];
int version;
char identical[2];
}INFORMATION;
typedef struct {
SQLHENV henv;
SQLHDBC hdbc;
SQLHSTMT hstmt;
}DBSTRUCT;
#define PERBYTES 1024
BOOL AddInformation(DBSTRUCT &dbstruct,INFORMATION &information)
{
char strSQL[256];
RETCODE retcode;
HSTMT hstmt;
SQLPOINTER pToken;
SQLINTEGER cbName, cbTypeCode, cbLocation,cbContent,cbSeqno,cbVersion,cbIdentical;
LPCTSTR pContentBuf;
cbName = cbTypeCode = cbLocation = SQL_NTS;
int len;
int seqno = 0;
char buffcontent[PERBYTES+1];
int putbytes=0;
CNCString *pTemp;
//DEBUG
information.seqno = 1;
strcpy(strSQL , "insert into informat (name,typecode,location,content,version,identical,seqno)\
values(?,?,?,?,?,?,?)");
retcode = SQLAllocStmt(dbstruct.hdbc,&hstmt);
if(retcode == SQL_ERROR || retcode ==SQL_INVALID_HANDLE)
return false;
retcode = SQLPrepare(hstmt,(SQLCHAR *)strSQL,SQL_NTS);
if(retcode == SQL_SUCCESS || retcode ==SQL_SUCCESS_WITH_INFO)
{
retcode = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT,
SQL_CHAR , SQL_CHAR ,
0, 0, (SQLPOINTER) 2, 0, &cbName);
if(retcode == SQL_ERROR||retcode ==SQL_INVALID_HANDLE) goto error;
cbName = SQL_LEN_DATA_AT_EXEC(0);
retcode = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT,
SQL_CHAR , SQL_CHAR ,
0, 0, (SQLPOINTER) 2, 0, &cbTypeCode);
if(retcode == SQL_ERROR||retcode ==SQL_INVALID_HANDLE) goto error;
cbTypeCode = SQL_LEN_DATA_AT_EXEC(0);
retcode = SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT,
SQL_CHAR , SQL_CHAR ,
0, 0, (SQLPOINTER) 2, 0, &cbLocation);
if(retcode == SQL_ERROR||retcode ==SQL_INVALID_HANDLE) goto error;
cbLocation = SQL_LEN_DATA_AT_EXEC(0);
retcode = SQLBindParameter(hstmt, 4, SQL_PARAM_INPUT,
SQL_C_BINARY , SQL_VARBINARY ,
0, 0, (SQLPOINTER) 2, 0, &cbContent);
if(retcode == SQL_ERROR||retcode ==SQL_INVALID_HANDLE) goto error;
cbContent = SQL_LEN_DATA_AT_EXEC(0);
retcode = SQLBindParameter(hstmt, 5, SQL_PARAM_INPUT,
SQL_C_ULONG , SQL_INTEGER ,
0, 0, (SQLPOINTER) 2, 0, &cbVersion);
if(retcode == SQL_ERROR||retcode ==SQL_INVALID_HANDLE) goto error;
cbVersion = SQL_LEN_DATA_AT_EXEC(0);
retcode = SQLBindParameter(hstmt, 6, SQL_PARAM_INPUT,
SQL_C_CHAR , SQL_C_CHAR ,
0, 0, (SQLPOINTER) 2, 0, &cbIdentical);
if(retcode == SQL_ERROR||retcode ==SQL_INVALID_HANDLE) goto error;
cbIdentical = SQL_LEN_DATA_AT_EXEC(0);
retcode = SQLBindParameter(hstmt, 7, SQL_PARAM_INPUT, SQL_C_ULONG,
SQL_INTEGER, 0, 0, &information.seqno, 0, &cbSeqno);
if(retcode == SQL_ERROR||retcode ==SQL_INVALID_HANDLE)
goto error;
retcode = SQLExecute(hstmt);
if(retcode == SQL_ERROR||retcode ==SQL_INVALID_HANDLE)
goto error;
else
{
int i=0;
while((retcode = SQLParamData(hstmt, &pToken)) == SQL_NEED_DATA) {
i++;
if(retcode == SQL_ERROR||retcode ==SQL_INVALID_HANDLE) goto error;
switch(i)
{
case 1:
pContentBuf = (LPCTSTR)information.name;
retcode=SQLPutData(hstmt,(void*)pContentBuf,SQL_NTS);
break;
case 2:
pContentBuf = (LPCTSTR)information.typecode;
retcode=SQLPutData(hstmt,(void*)pContentBuf,SQL_NTS);
break;
case 3:
pContentBuf = (LPCTSTR)information.location;
retcode=SQLPutData(hstmt,(void*)pContentBuf,SQL_NTS);
break;
case 4:
pContentBuf = (LPCTSTR)information.content;
len = strlen(information->content);
putbytes=0;
while(len - putbytes>0){
if (len <=PERBYTES){
strcpy(buffcontent,pContentBuf);
putbytes = len;
}else{
memset(buffcontent,0,sizeof(buffcontent));
if(len -putbytes>PERBYTES)
strncpy(buffcontent,pContentBuf+putbytes,PERBYTES);
else
strncpy(buffcontent,pContentBuf+putbytes,len - putbytes);
putbytes+=PERBYTES;
}
retcode=SQLPutData(hstmt,(void*)pContentBuf,SQL_NTS);
if(retcode == SQL_ERROR||retcode ==SQL_INVALID_HANDLE) goto error;
}
break;
case 5:
retcode=SQLPutData(hstmt,&information.version,sizeof(information.version));
break;
case 6:
pContentBuf = (LPCTSTR)information.identical;
retcode=SQLPutData(hstmt,(void*)pContentBuf,SQL_NTS);
break;
default:
len = sizeof(information.seqno);
retcode = SQLPutData(hstmt,&information.seqno,len);
break;
}
if(retcode == SQL_ERROR||retcode ==SQL_INVALID_HANDLE) goto error;
}
if(retcode == SQL_ERROR||retcode ==SQL_INVALID_HANDLE) goto error;
SQLFreeStmt(hstmt,SQL_CLOSE);
SQLFreeStmt(hstmt,SQL_DROP);
return true;
}
}//if(retcode == SQL_SUCCESS || retcode ==SQL_SUCCESS_WITH_INFO)
error:
dbstruct.hstmt = hstmt;
//CNCString *pDBError;
//pDBError = GetDBError(dbstruct);
//if(pDBError->GetLengthContent()){
//TraceLog(pDBError);
//}
// delete pDBError;
SQLFreeStmt(hstmt,SQL_CLOSE);
SQLFreeStmt(hstmt,SQL_DROP);
return false;
}
informat table define:
CREATE TABLE `informat` (
`location` varchar(100) default NULL,
`typecode` varchar(30) default NULL,
`content` longblob,
`name` varchar(100) default NULL,
`seqno` int(11) NOT NULL default '0',
`version` int(11) default '1',
`identical` char(1) default 'N',
PRIMARY KEY (`seqno`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;
[17 Jun 2005 23:58]
longsebo longsebo
fixed sample code error: retcode=SQLPutData(hstmt,(void*)pContentBuf,SQL_NTS); modify: retcode=SQLPutData(hstmt,(void*)buffcontent,SQL_NTS);
[20 Jun 2005 9:21]
Vasily Kishkin
Probably I need full text of test case with example inserting values for each field. Because my test case works fine. Could you please provide full text of test case with example values of fields ?
[22 Jun 2005 1:15]
longsebo longsebo
This ms vc6.0 project demo the bug 。You will need create table ,create odbc dsn and modify code dsn ,login db user/password.
Attachment: testmysql.rar (application/octet-stream, text), 195.98 KiB.
[22 Jun 2005 1:18]
longsebo longsebo
I already upload demo ms vc6 project,dowload and verify from:http://bugs.mysql.com/file.php?id=1464
[23 Jun 2005 9:05]
Vasily Kishkin
Thanks for test case. The bug was verified. Tested on Win 2000 Sp4 , Microsoft Visual C 7.0, MyODBC 3.51.11.
[24 Jun 2005 1:08]
longsebo longsebo
This bug always appear in mysql all version!How long do you want fixed the bug?
[11 Jun 2007 16:42]
Georg Richter
Can't repeat. Tested with MyODBC 3.51.15 Server settings: [mysqld] max_allowed_packet=2M
