Compilation Tutorial: ODBC Basics

Source: Internet
Author: User
Tags odbc win32

This is the first tutorial in a series of database programming using WIN32ASM. In today's IT world, database programming is becoming more and more important, so we can no longer ignore it. But now there are many kinds of databases in use, if we in order to achieve Win32 database assembly language programming and learning various database file format, the time spent is probably called "eternal."

Luckily, a Microsoft technology enabled us to get out of this big trouble. It is called ODBC and is abbreviated as an Open database interconnect (Open DB connectivity), a family of APIs similar to the Windows API. It deals primarily with databases. That is, with the ODBC API, you can interact with many different databases through a unified interface.

How does ODBC work? What is its structural style? Before using ODBC, you should have a clear understanding of its structure. ODBC has four components:

Application (application, your program)

ODBC Administrator (ODBC Manager)

ODBC Driver (ODBC Drivers)

Data source (Sources, database)

The core of these four components is the ODBC Administrator. You can think of it as your supervisor. You tell it what you want him to do, and then it communicates your request to its worker (the ODBC driver) and completes the work. If the worker has anything to tell you, it will talk to the overseer (the ODBC manager) and be communicated to you by the supervisor. The workers are very clear about what they should do, so they will do a good job for you.

With such a pattern, we do not communicate directly with the database driver. You just tell the database manager what you want to do. Using the appropriate ODBC driver to achieve your purpose is an ODBC manager thing. Each ODBC driver has sufficient knowledge of its corresponding database. Each part has its own responsibilities, greatly simplifying the workload.

Your program <----> ODBC Manager <----> ODBC driver <----> Database

The ODBC Administrator is provided by Microsoft. Take a look at your control panel. If you install ODBC correctly you will find an ODBC data source (32-bit) project. As for ODBC drivers, Microsoft offers several of their products. And you can always get a new ODBC driver from your database provider. Simply install the new ODBC driver, and your machine will be able to use a new database that it didn't previously know about.

ODBC APIs are easy to use, but you need to know something about SQL and the database. For example, fields (field), primary keys (primary key), records (record), Columns (column), Rows (row), and so on. I have to assume that you already know some of the basics of database theory, so that I can discuss the details of Win32 in assembly language for ODBC programming. As you can see, the ODBC administrator is trying to hide the details of the implementation in your program. This means that it must provide some basic interface to communicate with your program and the ODBC driver. Because of the differences in performance between ODBC drivers, there must be a way for our programs to know whether an ODBC driver supports an attribute. ODBC defines a three-tier service interface called interface conformance levels. The third layer is the core layer. Any ODBC driver implements all of the features in the core tier table as it does on the first and second tiers. From the perspective of our program, ODBC APIs are split into such three tiers. If a function is labeled as core, it means you can use it with ease without worrying about whether it is supported by the ODBC driver you are using. If it is a first-or second-tier function, you must verify that the ODBC driver is supported and then use it. You can get more information on ODBC APIs via MSDN.

You should know some ODBC nouns before you write the code.

Environment (Environment). As with literal meaning, a global text is used to access data. If you are familiar with DAO, you can imagine it as a workspace. It contains information that applies to all ODBC sessions, such as the connections handle of a session. You must obtain this handle from the environment before using ODBC.

Connection (Connection). Specifies an ODBC driver and data source (database). You can connect different databases at the same time in the same environment

Statement (Statement). ODBC uses SQL as its own language. So simply think of the statement as the SQL command you want ODBC to execute.

The following are general steps for programming with ODBC:

Connecting to a data source

Create and execute one or more SQL statements

Check the result record (if any)

Disconnecting a data source

In the next tutorial we will learn how to achieve these steps.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.