- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My subroutine declares,
character*15000 SQLStmtStr
character*15000 SQLStmtStrA
where SQLStmtStr is an incoming argument. My goal is to make a C string to call
iRet = SQLExecDirect(StmtHndl,SQLStmtStrA,len)
And I'm not sure how to accomplish this...if I try
SQLStmtStrA=ADJUSTL(TRIM(SQLStmtStr))//char(0)
Then SQLStmtStrA ends up with garbage characters.
If I try
len=
len_trim(SQLStmtStr)SQLStmtStrA=SQLStmtStr(1:len)//char(0)
Then the code stops execution when I step over that last line.
Errr...what am I doing wrong?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When you say that the code "stops execution", what do you mean? Was there an error message?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I saw an error that looks like this:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
A very peculiar thing is thatmy SQLStmtStrA has an initial value that starts with a funny character (a square).
I also just tried re-defining
character(*) SQLStmtStr
but that didn't help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This gets even more fun!
I also have
character*255 ColStr
and when I call
iRet = SQLBindCol(StmtHndl,int(1,2),1,ColStr,255,0)
that's when my SQLStmtStrA seems to get corrupt.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes and yes. (Though I tried the last argument by reference, since it wasn't really clear). Does anything stand out from how I wrote my interface? (Microsoft definition of SQLBindCol follows)
C
C see http://msdn2.microsoft.com/en-us/library/ms711010.aspx
C see also ODBC32.lib in notepad
integer(2) function SQLBindCol
& (StatementHandle,ColumnNumber,TargetType,
& TargetValuePtr,BufferLength,StrLen_or_Ind)
CVBASIC UNCOMMENT START
!DEC$ATTRIBUTES C, ALIAS: "_SQLBindCol@24":: SQLBindCol
!DEC$ATTRIBUTES VALUE:: StatementHandle
!DEC$ATTRIBUTES VALUE:: ColumnNumber
!DEC$ATTRIBUTES VALUE:: TargetType
!DEC$ATTRIBUTES REFERENCE:: TargetValuePtr
!DEC$ATTRIBUTES VALUE:: BufferLength
!DEC$ATTRIBUTES VALUE:: StrLen_or_Ind
CVBASIC UNCOMMENT END
integer(4) StatementHandle
integer(2) ColumnNumber
integer(2) TargetType
character(*) TargetValuePtr
integer(4) BufferLength
integer(4) StrLen_or_Ind
end function
SQLRETURN SQLBindCol( SQLHSTMTStatementHandle, SQLUSMALLINTColumnNumber, SQLSMALLINTTargetType, SQLPOINTERTargetValuePtr, SQLINTEGERBufferLength, SQLLEN *StrLen_or_Ind);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
!DEC$ATTRIBUTES C, ALIAS: "_SQLBindCol@24":: SQLBindCol
Make this instead:
!DEC$ ATTRIBUTES STDCALL, DECORATE, ALIAS:"SQLBindCol" :: SQLBindCol
You've told ifort to use the C calling convention for a STDCALL routine, which will corrupt the stack on every call. That @24 on the end of the alias is the giveaway that the routine is STDCALL (as all Win32 API routines are.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve, you're Da Man!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page