Strange behaviour of ODBC cursor

This is a discussion on Strange behaviour of ODBC cursor within the Windows Programming forums, part of the Platform Specific Boards category; When i'm opening an ODBC cursor and querying a value, i often get blank values in columns i know contain ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    Strange behaviour of ODBC cursor

    When i'm opening an ODBC cursor and querying a value, i often get blank values in columns i know contain data..
    I open the cursors as forwardonly/static, and i know that records are returned.
    Could this be a memory violation?
    Code:
    char *RecSet::GetData(short colNum){
    	char *retVal = new char[101];
    	long lLen(0);
    	short sRes(0);
    
    	sRes=SQLGetData(this->m_hStmt, colNum, SQL_C_CHAR, retVal, 100,  &lLen);
    	if(sRes != SQL_SUCCESS && sRes != SQL_SUCCESS_WITH_INFO){
    		delete [] retVal;
    		return(0);
    	}
    	return(retVal);
    }
    Last edited by knutso; 05-07-2003 at 12:23 AM.

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Still no replies..
    Maybe the source will help? I'm not even sure the error is in the recordset class.
    Unexplainable things seem to happen when i try to use GetData() with the column name instead of the number..
    Attached Files Attached Files

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Still no replies..
    Maybe you should read this . Your question isn't directly C++, is it?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    I realize it should be at the Windows board, I don't know why i originally posted it at the c++ board.
    I don't have the rights to delete it, thus it's stuck at c++...

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    I dont use ODBC (prefer ADO via MFC), but it looks like you are assuming all values are stings........and your not checking to see if there's any more additional info such as if there's a data mismatch

    Have a look here. Pay attention about the SQLSTATE part

    Also, consider the ADO/MFC approach...the technology is current (not legacy like ODBC API), and the use of the Variant wrapper in MFC make's life so much easier

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    I thought the SQL_C_CHAR was a kind of a variant...
    From MSDN:
    07006 Restricted data type attribute violation The data value of a column in the result set cannot be converted to the C data type specified by the argument TargetType.
    I'll try to dp a typecheck in the getdata function, and print to a char array instead.
    I don't think this explains the strange things happening sometimes when i open a cursor:
    -Sometimes the main window moves
    -Sometimes i get a memory violation(in ODBC32.dll), that's why i figured it was in the recordset class..

  7. #7
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    Originally posted by knutso
    I thought the SQL_C_CHAR was a kind of a variant...
    No...a variant is a special type that basically represents any valid data type.....in C++ its often represented as a union with LONG, SHORT, IDispatch, BSTR, LPVOID etc......they are most common in VB when you program with late binding, or if you use VBScript etc..

    There are some APIs to work with them, but they are a pain....and so MFC and ATL have a wrapper that handles them.....for instance with ADO, I can get any value from a recordset as a variant and then convert it to what I need (assuming its convertable)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Oracle cursor in ODBC
    By Mortissus in forum C Programming
    Replies: 4
    Last Post: 09-10-2007, 01:19 PM
  2. strange program behaviour...
    By now5 in forum C Programming
    Replies: 10
    Last Post: 03-08-2004, 04:39 AM
  3. GetClientRect strange behaviour
    By btq in forum Windows Programming
    Replies: 2
    Last Post: 10-02-2002, 02:13 PM
  4. Strange behaviour
    By PrivatePanic in forum Windows Programming
    Replies: 11
    Last Post: 07-23-2002, 12:54 AM
  5. Mouse in 800x600 24Bit Mode?
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 11-11-2001, 12:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21