Bug #14403 Impossible to get the value of a column
Submitted: 27 Oct 2005 18:19 Modified: 29 Nov 2006 20:20
Reporter: Norberto Goussies Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S2 (Serious)
Version:5.0 OS:Windows (win2k)
Assigned to: CPU Architecture:Any

[27 Oct 2005 18:19] Norberto Goussies
Description:
Hello, I'm having this error:
Program type out of range

when I try to bind a column, using SQLBind, even when the coltype is given by SQLDescribeCol.

HELP PLEASE!

How to repeat:
with this table
create table TTFILE
(
   ID_TTFILE                      int                            not null auto_increment,
   ARCHIVO                        varchar(128),
)

Where hstmt is de handle returned by SQLExecDirect, when calld with : "select * from ttfile;"

	rc = SQLRowCount(m_hstmt, &m_rows);
	if (!MYSQLSUCCESS(rc))  //Error
		throw new DBException(pConnection->henv, pConnection->hdbc, hstmt);

	rc = SQLNumResultCols(m_hstmt, &nCols);
	if (!MYSQLSUCCESS(rc))  //Error
		throw new DBException(pConnection->henv, pConnection->hdbc, hstmt);

	if(m_rows > 0){
		for(int nCol=0;nCol<nCols;nCol++){
			DBField *pField = new DBField();
			SQLCHAR         colname[1024];
			SQLSMALLINT     coltype;
			SQLSMALLINT     colnamelen;
			SQLSMALLINT     nullable;
			SQLUINTEGER      collen;
			SQLSMALLINT     scale;
			SQLINTEGER displaysize;

			rc = SQLDescribeCol(hstmt, 
				nCol+1, 
				colname, 
				sizeof(colname), 
				&colnamelen, 
				&coltype, 
				&collen, 
				&scale, 
				&nullable);
			if (!MYSQLSUCCESS(rc))  //Error
				throw new DBException(pConnection->henv, pConnection->hdbc, hstmt);

			rc = SQLColAttributes(hstmt, nCol+1, SQL_DESC_LENGTH, NULL, 0,
				NULL, &displaysize);
			if (!MYSQLSUCCESS(rc))  //Error
				throw new DBException(pConnection->henv, pConnection->hdbc, hstmt);

			pField->m_isNullable = (nullable == SQL_NULLABLE);
			pField->m_Name = string((char*)colname);
			collen++;
			pField->m_size = (collen > displaysize) ? collen : displaysize ;
			pField->m_Type = coltype;
			pField->m_Value = malloc(pField->m_size);

			rc = SQLBindCol (hstmt, nCol+1, coltype, pField->m_Value, pField->m_size, &pField->m_extraInfo);
			if (!MYSQLSUCCESS(rc))  //Error
				throw new DBException(pConnection->henv, pConnection->hdbc, hstmt);

			m_Fields.push_back(pField);
		}//end for
	}//end if rows>0	
	else{
		m_eof = true;
	}
[29 Oct 2005 8:25] Vasily Kishkin
Thanks for the bug report. I was able to reproduce the bug. My test case is attached.
[29 Oct 2005 8:25] Vasily Kishkin
Test case

Attachment: test.c (text/plain), 4.94 KiB.

[29 Oct 2005 8:29] Vasily Kishkin
Sorry.... I verified the bug on 3.51. When I tested on 5.0 I got follow error message:

Connect....
Test....
[ASSERT][.\MYODBCDiaClear.c][26] hDia

My test case with 5.0 is attached too.
[29 Oct 2005 8:29] Vasily Kishkin
Test case 5.0

Attachment: test.c (text/plain), 4.94 KiB.

[29 Nov 2006 20:20] Jess Balint
This works fine now.

Table definitions for simpler reference:
create table ttfile ( id_ttfile int not null auto_increment, archivo varchar(128), primary key (id_ttfile));
insert into ttfile (archivo) values ('ashdlas');