|
|
Comments and Discussions
|
|
 |

|
Am using Microsoft Visual C++.NET. I downloaded the demo project but it fails to compile. I get the error message;
fatal error C1083: Cannot open include file: 'ODBCDynamic.hpp': No such file or directory
I there a way i can access this file.
This looks like some thing great if it worked. Please help
|
|
|
|

|
line 431:
strValue.ReleaseBuffer(nActualSize < (static_cast<CODBCColumnInfo*>(arrODBCColumns[j]))->m_nLen ? nActualSize : ((CODBCColumnInfo*)arrODBCColumns[j])->m_nLen);
What for to cut off the size of the returned line of data on length of the name of a column?
sorry for my english
|
|
|
|

|
I have run into the same problem and have not found a fix yet. The problem I think stems from SQLDescribeCol() call made in FetchData which returns what appears to be the column name length rather than the actual data length of the field. I am not sure whether the error is in SQLDescribeCol() or in Tom's code.
Larry
|
|
|
|

|
Hi. I’m trying to develop an application that must operate on the oracle database using (ODBC) CDatabase & CRecordset. But the application can't show the record (NUMBER) type correctly and it show instead some strange numbers in the edit contrl. like -19841 instead of 50. // here's an example of the code. char str[255]; int index=0; CDBVariant var; recordset.GetFieldValue(index,var); wsprintf(str, "%d" ,var.m_iVal); // i tried to use 'var.m_dblVal' also. EditCtrl->SetWindowText(str); may you tell me please what i have to do to convert the number and show it correctly? or how to make sure about which data type is in the CDBVariant for further proper conversion? I'm using VC++ 6.0 & Oracle 9i. Best regards
|
|
|
|

|
Hello,
I was wondering if there's any repository with updates on this (quite usefull !) set of classes ?
Thanks,
-- Jeff
|
|
|
|

|
While I enjoy giving back to the community in the form of code/articles, continually updating past articles isn't something I can do and still have time to make money to put food on the table
Therefore, this is the only "free" version of the code I've made available.
If you're questions are generic ODBC-type questions, you can probably get loads of help on this site's forums as well as the MSDN Forums.
On the other hand, if you're in a pinch and want these classes customized for your company's needs, I have done that for several clients on an hourly, paid basis. If so, drop me a line and we can discuss further.
Tom Archer (blog)
Program Manager
MSDN Online (Windows Vista and Visual C++)
MICROSOFT
|
|
|
|

|
Any idea how to distinguish if a CDBVariant is actually holding a date or time?
|
|
|
|

|
if (myDbVariant.m_dwType == DBVT_DATE)
{
}
Tom Archer (blog)
Program Manager
MSDN Online (Windows Vista and Visual C++)
MICROSOFT
-- modified at 12:15 Monday 13th March, 2006
|
|
|
|

|
Thanks for your code!
I got a problem: when I assign the content of a field to a CString with both CODBCRecord::Lookup or CODBCRecord::GetNextAssoc, only the first N characters of the record cell are copied into the CString, where N is the length of the field name!
For ex:
If the value of the field named Name is Michelangelo, the content of the CString will be Mich (as Name is 4 character long).
The same happens with your demo project.
I used Access databases for my tests.
Do you know why this happens?
Thanks!
Mauro Pamiro
|
|
|
|

|
I encounter the same problem. And focused it out to the following line
if ((-1 != nActualSize)
&& ((static_cast(arrODBCColumns[j]))->m_nFieldType == SQL_C_CHAR))
{
// Release the string buffer
CString strValue = (CString)*pvarValue->m_pstring;
strValue.ReleaseBuffer(nActualSize < (static_cast(arrODBCColumns[j]))->m_nLen ? nActualSize : ((CODBCColumnInfo*)arrODBCColumns[j])->m_nLen);
}
I think the intention was to be able to read out char fields not ended correctly by a \0. Th problem is that m_nLen does not store the size of the column, but the size of the header. This is filled in the following line
if (SQL_SUCCESS == (rc = ::SQLDescribeCol(hstmt, i, reinterpret_cast(lpszColName), MAX_COLNAME, &nLen, &nSQLType, &nPrecision, &nScale, &nNullability)))
{
// Determine the default field type and get the data buffer
short nFieldType = GetFieldTypeFromSQLType(nSQLType);
pODBCColumnInfo = new CODBCColumnInfo(lpszColName, nLen, nFieldType, nSQLType, nPrecision);
arrODBCColumns.Add(static_cast(pODBCColumnInfo));
}
Here he used nLen instead of nPrecision. You should replace the line to
pODBCColumnInfo = new CODBCColumnInfo(lpszColName, nPrecision, nFieldType, nSQLType, nPrecision);
and all works fine...
|
|
|
|

|
Very easy to use and concise. I have used it to get data from DB2 - Great Effort Tom!
Please let me know how I can execute stored procedure which takes both input and output parameters.
Also I got an error when the resultset(from DB2) contained a VARCHAR. I will apply Steve's fix and see.
|
|
|
|

|
Thanks. However, I don't know if or when I'm update this code as it's something I haven't used in many years. (It was something I needed for a job iat AT&T back in '98 I believe).
Cheers,
Tom Archer, Inside C#
Mainstream is just a word for the way things always have been -- just a middle-of-the-road, tow-the-line thing; a front for the Man serving up the same warmed-over slop he did yesterday and expecting you to say, "Thank you sir, may I have another?"
|
|
|
|

|
Hi,
Your Classes are very good and straight forward, but when I implemented them into my SQL DB, it took a little too much time retrieving the rows ( 2000row ) and that was only for one column, I didn't try it for the 17 columns that Ihad.
I there a way to speed up the process, maybe using some cahing method.
Thanks
|
|
|
|

|
.
.
for (pos = pODBCRecord->GetStartPosition(); pos != NULL;)
{
pODBCRecord->GetNextAssoc(pos, strColName, pvarValue);
pvarValue->GetStringValue(strValue);
TRACE("Record: %ld, Column: %s, Value: '%s'\n",iRecord, strColName, strValue);
}
.
.
everything is ok but the problem is:
-> the strColName is not in correct order for each record as in database
Mohd Alwi
|
|
|
|

|
Great article man. I was looking out for something like this. Thanks.
|
|
|
|

|
Thanks man! I know it definitely saved me a lot of time in a couple of gigs once I got it finished.
Cheers,
Tom Archer, Inside C#
Mainstream is just a word for the way things always have been -- just a middle-of-the-road, tow-the-line thing; a front for the Man serving up the same warmed-over slop he did yesterday and expecting you to say, "Thank you sir, may I have another?"
|
|
|
|

|
I usually have some error in ASSERT in line 200 and 300 of ODBCDynamic.cpp
short CODBCDynamic::GetFieldTypeFromSQLType(short nSQLType)
{
.........................
default:
ASSERT(FALSE);
}
return nFieldType;
}
void* CODBCDynamic::GetDataBuffer(CDBVariantEx* pvarValue,
short nFieldType, int* pnLen, short nSQLType, UDWORD nPrecision)
{
...........................................
default: ASSERT(FALSE);
}
return pvData;
}
|
|
|
|

|
I already posted this error and my solution below: http://www.codeproject.com/database/dynamic_odbc_class.asp?df=100&forumid=480&select=44209#xx44209xx
Cheers
Steve
|
|
|
|

|
Thanks Steve. One of these days, I'll actually have a few minutes to update the article. When I do, I'll definitely give you credit for this fix.
Cheers,
Tom Archer
Author - Inside C#, Visual C++.NET Bible
|
|
|
|

|
I have 1 error in line 259 in File ODBCDynamicTestDlg.cpp
CODBCRecordArray* pODBCRecordArray = &odbcDynamic.m_ODBCRecordArray;
I think the &odbcDynamic.m_ODBCRecordArray is NULL
Can you help me.
|
|
|
|

|
I found another message post site for more articles on Tom Archer's CODBCDynamic Class.....
http://www.codeguru.com/mfc_database/dynamic_odbc_class.shtml?0.0767822265625
Ryan
92110.com
Ryan
|
|
|
|

|
Hi Ryan,
Chris Maunder and I originally built CodeGuru so that's where this article first appeared. When Chris started this site, I posted some of my articles over here to help him get started with some content.
Cheers,
Tom Archer
Author - Inside C#, Visual C++.NET Bible
|
|
|
|

|
Hi,
Anyone has idea about how to create a database in oracle from within a vc++ program using the SQL statement "create database"??
|
|
|
|

|
if you mean to create a table it would be....
CREATE TABLE MyTable
(
MyNumber NUMBER,
MyText VARCHAR2(30),
PRIMARY KEY(MyNumber)
);
Ryan
92110.com
|
|
|
|

|
This space is really intended as a means of me getting feedback on this article. You'll probably have a greater chance of getting help on specific questions regarding other issues if you ask them in the VC++ forum.
Cheers,
Tom Archer
Author - Inside C#, Visual C++.NET Bible
|
|
|
|
|

|
Hello TOM:
Thanks for your code, really is very nive.
I have a problem, I don't know if I'm using bad the source code,or what... But When I make a lot of ExecuteSQL(...), the memory of my system never it's released, only when I close the connection.
I work with Visual 6 SP 5, Windows XP RC2.
Best Regards,
Alfonso Bastias
|
|
|
|

|
Sorry, but the problem was Windows XP, take more time to release the memory. In Windows 2K it too fast. Maybe is the final version of Windows XP will be more fast.
Regards,
Alfonso
|
|
|
|

|
There actually might be a memory leak.... i found this in another news post group.
"I was having a steady memory leak while using this class, and I finally found the culprit. In the ExecuteSQL() function, the ::SQLFreeHandle(SQL_HANDLE_STMT, &hstmt)
call to release the statement handle is incorrect. It should be ::SQLFreeHandle(SQL_HANDLE_STMT, hstmt) where the handle is passed in, not the address of the handle.
Other than that, the class works quite well. I have made extensive modification in the error checking and handling area which I may offer up once I am finally done with this project."
copied from: Dan Ramage (2002/04/18)
Ryan White
92110.com
|
|
|
|

|
Thanks Ryan for the kind words. Actually, I had intentionally pared down the error checking and other niceties since people tend to have their methods of doing such things. However, if you'll send me what you have then I'll update the article and give you credit for implementing that.
Cheers,
Tom Archer
Author - Inside C#, Visual C++.NET Bible
|
|
|
|

|
Hi Tom (or other who can help me!),
I'm having a problem with a missing include file "ODBCDynamic.hpp" on line 11 of ODBCDynamicTestDlg.h. It doesn't seem to be part of the source zip file. Where can I get it?
Cheers
|
|
|
|

|
I just opened the file directly from this page and it is in the zip file.
Cheers,
Tom
"Ya got lucky, ya lucky prick" - Keith McCready
|
|
|
|

|
Yes, you're right, it's in the zipped source files, but not in the demo project zip. I'll try compiling the source this time.
Cheers,
Sinclair
|
|
|
|

|
Sorry to disagree, mate. However, when I click on the "Download demo project", that file has the header file you say isn't there. When I click on the "Download source files", that files *does not* have the file (as it should not). Therefore, I really don't know what you're looking at but with all due respect, the files are correct.
Cheers,
Tom
"Ya got lucky, ya lucky prick" - Keith McCready
|
|
|
|

|
Once compiled, it's a great app.
Cheers.
|
|
|
|

|
Thanks mate. It won't solve everyone's problems, but it helped me a great deal and hopefully will do the same for you.
Cheers,
Tom
"Ya got lucky, ya lucky prick" - Keith McCready
|
|
|
|

|
Tom,
demo project doesn't contain the hpp file.
regards,
Andrei
|
|
|
|

|
I found a bug - if you run a query to get system objects CODBCDynamic::GetFieldTypeFromSQLType asserts. Enter a query like " Select * from sysobjects where type = 'U' " and you will see the error. It seems that SQLDescribeCol returns a type of constant -9 which is not defined in Microsoft's SQLEXT.H header file. To get around it I added #define SQL_SYSVARCHAR -9 to ODBCDynamic.cpp and in CODBCDynamic::GetFieldTypeFromSQLType added -
case SQL_SYSVARCHAR:
nFieldType = SQL_C_CHAR;
break;
Apart from this bug the code seems to work great!
|
|
|
|

|
can anybody help about how to send mail and receive mail programatically like the Outlook Express application. OE gives the http address of the hotmail server can my program also check for mails and send mails.
Will the Wininet API be useful for this or there is something else.
:(
|
|
|
|

|
Cool class, by the way.
In CODBCDynamic::GetDataBuffer(), fields of type 'SQL_LONGVARCHAR' (and 'SQL_LONGVARBINARY') will always have their associated length set to 1. So the subsequent call to ::SQLGetData() will truncate data from fields of type 'SQL_LONGVARCHAR'. I found this when retrieving data from a SQL Server field of type 'text'. Any thoughts?
|
|
|
|

|
Have you updated this class to also Write to any ODBC source?
|
|
|
|

|
That really falls outside the scope of what I wanted this class for. I needed it to read data from an unknown, or dynamic schema. With regards to writing data, normally you would know the schema when doing operations like that, which is why its not included.
Cheers,
Tom
"Ya got lucky, ya lucky prick" - Keith McCready
|
|
|
|

|
I can't get the test project to compile are there some basic instruction for using the test project. The readme doesn't help. It also doesn't include the ODBCClasses.lib needed.
|
|
|
|

|
I download this (as have many others) and don't have a problem. Can you be a little more specific about what doesn't build on your system?
Cheers,
Tom
"Ya got lucky, ya lucky prick" - Keith McCready
|
|
|
|

|
thanks for the author, great work.
email: linxiao@eng.auburn.edu
|
|
|
|

|
You're very welcome, mate! I'm always glad to hear when someone is getting good use out of something I've done.
Cheers,
Tom
"Ya got lucky, ya lucky prick" - Keith McCready
|
|
|
|

|
I am using aliases in the from clause of my SQL statement and would like to include the alias prefix in the returned columnname for the map (or even just the tablename that the column belongs to). I started to look at the source and tried using the SQLColAttribute function. But everything that comes back is just an empty string or the column name without the alias prefix attached. Any help is much appreciated! Thanks
|
|
|
|

|
Damn good question Seriously, nobody's ever asked that one before. I think the main issue is going to be what I get back from ODBC. IOW, what I put in the columnName is what ODBC tells me (remember that my code is agnostic and knows nothing about your query). Therefore, I'll have to play with that a bit to find out.
I've got my kids today, but I'll give it a look tomorrow.
Cheers,
Tom Archer - CodeGuru.com
Author - Inside C#
Visual C++ 6 Bible
Teach Yourself Visual InterDev 6 in 24 Hour
|
|
|
|

|
This doesn't solve the issue but if anyone is interested here is my workaround. It doesn't really have much to do with the ODBC Dynamic class as much as SQL syntax:
Instead of:
Select a.name, b.name from....
In the above query only 'name' is returned as a column name.
Do this instead:
Select a.name as aname, b.name as bname from...
This returns 'aname' now..
|
|
|
|

|
I had problems with SQL_DESC_BASE_COLUMN_NAME on an access db.
To make it work I updated the driver (mdac 2.5)
http://msdn.microsoft.com/library/psdk/dasdk/odbc2jn7.htm
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
|
A class to dynamically read data from any ODBC data source
| Type | Article |
| Licence | |
| First Posted | 14 Mar 2000 |
| Views | 139,524 |
| Bookmarked | 37 times |
|
|