RE: "Invalid number of parameter markers" when executing SQL command
- From: HScottBuck <HScottBuck@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 7 Jun 2006 07:51:02 -0700
Not sure if this is correct in your code but it appears the SQLSetEnvAttr()
call needs help. Specifically, the 3rd parameter should be a pointer to your
odbcVersion variable instead of the value SQL_OV_ODBC3. (Unless I'm reading
the help file on SQLSetEnvAttr() incorrectly). This is equivalent to passing
(void *)3 so your setting the version to whatever happens to be at memory
address 0x03.
Scott
"Jonathan Blitz" wrote:
I am using VC++ 2005 and am trying to get to an ODBC database..
This is my code:
SQLHENV henv1;
SQLRETURN returnValue;
SQLINTEGER odbcVersion = SQL_OV_ODBC3;
SQLWCHAR SQLState[5];
SQLINTEGER nativeErrorCode;
SQLWCHAR nativeErrorMessage[1000];
SQLSMALLINT nativeErrorMessageLength;
returnValue = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv1);
returnValue =
SQLSetEnvAttr(henv1,SQL_ATTR_ODBC_VERSION,(void*)SQL_OV_ODBC3,0);
/* Allocate connection handle */
SQLHDBC hdbc;
SQLHSTMT hstmt;
returnValue = SQLAllocHandle(SQL_HANDLE_DBC, henv1, &hdbc);
//returnValue =
SQLConnectA(hdbc,(SQLCHAR*)"PTPGSQL21",9,(SQLCHAR*)"postgres",8,(SQLCHAR*)"e
ngland",7);
returnValue =
SQLConnectA(hdbc,(SQLCHAR*)"PTPGSQL21",9,(SQLCHAR*)"",SQL_NTS,(SQLCHAR*)"",S
QL_NTS);
returnValue = SQLAllocStmt(hdbc,&hstmt);
// Execute the SELECT statement.
SQLUINTEGER NumRowsFetched;
SQLUSMALLINT RowStatusArray[ROW_ARRAY_SIZE];
SQLINTEGER rowArraySize = 10;
typedef struct {SQLUINTEGER gameId; SQLINTEGER gameIdInd;} gameStruct;
gameStruct gamesData[ROW_ARRAY_SIZE];
returnValue = SQLSetStmtAttr(hstmt,
SQL_ATTR_ROW_BIND_TYPE,(void*)sizeof(gameStruct), 0);
returnValue = SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_ARRAY_SIZE,
(void*)rowArraySize, 0);
returnValue = SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_STATUS_PTR, RowStatusArray,
0);
returnValue = SQLSetStmtAttr(hstmt, SQL_ATTR_ROWS_FETCHED_PTR,
&NumRowsFetched, 0);
returnValue = SQLBindCol(hstmt, 1, SQL_C_ULONG, &gamesData[0].gameId, 0,
&gamesData[0].gameIdInd);
returnValue = SQLExecDirect(hstmt,(SQLWCHAR *)"SELECT game_id FROM game",
SQL_NTS);
switch (returnValue)
{
case SQL_SUCCESS:
break;
case SQL_SUCCESS_WITH_INFO:
break;
case SQL_ERROR:
SQLError
(henv1,hdbc,hstmt,SQLState,&nativeErrorCode,nativeErrorMessage,1000,&nativeE
rrorMessageLength);
break;
case SQL_INVALID_HANDLE:
SQLGetDiagRec
(SQL_HANDLE_DBC,henv1,1,SQLState,&nativeErrorCode,nativeErrorMessage,1000,&n
ativeErrorMessageLength);
break;
};
All works ok until the SQLExecDirect command. It returns an error: "The # of
binded parameters < the # of parameter markers".
From what I can see I have the parameters. I copied this from an example in
the doumentation so I can't think of anything I left out.
What have I done wrong?
Jonathan Blitz
- Follow-Ups:
- Re: "Invalid number of parameter markers" when executing SQL command
- From: Jonathan Blitz
- Re: "Invalid number of parameter markers" when executing SQL command
- References:
- "Invalid number of parameter markers" when executing SQL command
- From: Jonathan Blitz
- "Invalid number of parameter markers" when executing SQL command
- Prev by Date: Anzahl der Datensätze bei SELECT
- Next by Date: Re: ODBC 3.0 issue - HY003 Program type out of range
- Previous by thread: "Invalid number of parameter markers" when executing SQL command
- Next by thread: Re: "Invalid number of parameter markers" when executing SQL command
- Index(es):
Relevant Pages
|
|