CodeGuru
Earthweb Search
Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

jobs.internet.com

internet.commerce
Partners & Affiliates
Server Racks
Computer Deals
KVM Switches
Home Improvement
Disney World Tickets
Prepaid Phone Card
Promote Your Website
Corporate Awards
Promotional Items
Car Donations
Shop Online
Online Shopping
Corporate Gifts
Memory


RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

Home >> Visual C++ / C++ >> Data >> Database

Best Practices for Developing a Web Site. Checklists, Tips, Strategies & More. Download Exclusive eBook Now.

Classes for direct SQL calls with ODBC
Rating: none

Dave Merner (view profile)
August 6, 1998

.

During my current project, I found that I needed more functionality with my sql calls than CRecordset or CDAORecordset had to offer. These classes wrap the low-level ODBC API calls and act simular to a CRecordset, but allow me to execute any SQL statement without having to bind variables,etc.
(continued)



Turbo Screen Sharing
Adobe Acrobat Connect Professional offers users the ability to have a more productive and engaging web conferencing experience while providing the IT department with a program that efficiently utilizes bandwidth and minimally impacts the infrastructure. Learn More! »

Informal Learning: Extending the Impact of Enterprise Ideas and Information
Forward-thinking organizations are turning to enterprise learning in their quest to be better informed, better skilled, better supported at the point of need, and more competitive in their respective marketplaces. Learn More! »

Rapid E-Learning: Maturing Technology Brings Balance and Possibilities
Rapid e-learning addresses both time and cost issues by using technology tools to shift the dynamics of e-learning development. Learn why more skilled learning professionals use these tools and how you can get a solution to keep pace with your business demands. »

Delivering on the Promise of ELearning
This white paper defines the framework to launch e-learning as a set of teaching, training, and learning practices not bound by a specific technology platform or learning management system. It offers practical suggestions for creating digital learning experiences that engage learners by building interest and motivation and providing opportunities for active participation. »

The main class for doing this is CSQLDirect. CSQLDirect has the following attributes/functions:

  • CSQLDirect::Connect - Connects to a datasource.
  • CSQLDirect::ExecuteSQL - this is the main function that is used for handling the SQL statement.
  • CSQLDirect::GetCol - Will return a column from a table in the resulting cursor.
  • CSQLDirect::GetError - Provides detailed error messages in case something went wrong.
  • CSQLDirect::GetColumnType - Provides information about a cursor's column.
  • CSQLDirect::Fetch - Will properly execute a SQLFetch command with error handling.
  • CSQLDirect::Close - Closes the connection to the datasource.

The other class CSQLColumn is a support class for CSQLDirect. Since multiple queries to a cursor's column will result in a NULL value being returned, I found it necessary to keep track of the columns as they are used. This is stored in a CPtrArray within CSQLDirect and is cleaned up after each time the cursor is requeried/closed.

An example of using this class to make SQL Calls:

CSQLDirect SQLDirect( "TestData" );

if( SQLDirect.ExecuteSQL( "SELECT * FROM Employee" )==SQL_SUCCESS ) {
	while( SQLDirect.Fetch()==SQL_SUCCESS ) {
		.
		// Do some stuff here
		.
	}
}

That's it!

The great thing about this class is you no longer have need for a huge assortment of CRecordset classes for every table/query.

Anyways I hope this can be of help to anyone that uses the site. Don't hesitate to give me a shout if anyone has any questions/comments.

Thanks for all the help that CodeGuru has given my over the last few months!

Download Source 3K

Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed

Is it time to make your move to the multi-threaded and parallel processing world? Find out!
Generate Complete .NET Web Apps in Minutes . Download Iron Speed Designer today.
Intel Go Parallel Portal: Translating Multicore Power into Application Performance. Learn more.
Improve How You Manage Information: Becoming a Better Project Manager. Exclusive eBook - Download Now.
Guide to Developing a Web Site. Best Practices, Tips and Strategies. Download Exclusive eBook Now.


RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

(You must be signed in to rank an article. Not a member? Click here to register)

Latest Comments:
GetCol bug - Legacy CodeGuru (02/09/2004)
to execute stored procedures(oracle) in vc++ - Legacy CodeGuru (01/27/2004)
How to use the "SQLColumns()" in Visual Basic - Legacy CodeGuru (10/28/2003)
How to read and write binary data by ODBC API - Legacy CodeGuru (07/14/2003)
Anyone knows how to connect the mysql to my programme in Linux? - Legacy CodeGuru (07/10/2003)

View All Comments
Add a Comment:
Title:
Comment:
Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



(You must be signed in to comment on an article. Not a member? Click here to register)
Access FREE BIRT Developer Tools from Actuate:
Webinar:
Automate Secure Report Delivery
Demo:
Web-based Report Creation for End Users
Demo:
Automate the Creation of Spreadsheet Reports


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers