Solved

the compliting of SQL

Posted on 2009-05-18
4
333 Views
Last Modified: 2013-11-12
If you compile C++code that depends on some sort of SQL library, how does SQL change under the hood?  Is all code changed into some form of optimal abstract data types to store the info?

Looking for a general answer as well as good resource that talks about this - thanks!
0
Comment
Question by:figmit
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 400 total points
ID: 24421918
The question is a bit vague, can you qualify "some sort of SQL library", otherwise it is hard to answer specifically.

A "SQL library" could range from hardcoded SQL as in const character strings that cannot be changed (easily) at runtime, to a data file of stored SQL queries that _could_ be modified at runtime.

C++ uses a database specific library to both bind the SQL statement to a set of parameters as well as execute the SQL against the database, so at runtime you can generate dynamic SQL statements, as long as they are legal and the bind variables are of the correct type for parameters in the statement.

Since you use the term "abstract data types", I assume you mean how is inline SQL handled. Typically it is stored the same way as other constant character strings in a C++ program, as string data. It is not parsed at compile time, per se, except to pre-process from embedded SQL syntax to low level API syntax, but it is still stored as a SQL string.





0
 
LVL 40

Assisted Solution

by:mrjoltcola
mrjoltcola earned 400 total points
ID: 24422009
The only compiling I am aware of, except in the case of Microsoft's new LINQ, is the pre-processing of embedded SQL syntax; this is sort of a standard that lets you mix SQL with the host language (C, C++, etc.) by saying:

char name[100]; // C++ variable

EXEC SQL SELECT NAME INTO :name FROM CUSTOMER;


The pre-processor will convert this to low-level C++ code

Statement * statement = connection->createStatement("SELECT NAME INTO :1 FROM CUSTOMER");
statement->setString(1, name);
ResultSet * result = statement->executeQuery();

As you can see it really doesn't compile the SQL but just translates to expliciti API usage.
0
 
LVL 3

Assisted Solution

by:Akumas
Akumas earned 100 total points
ID: 24557495
generally, SQL lib such as OCI or sybase DBLibrary always map DB data type to basic c data type, like char*, long, int
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Creating and Managing Databases with phpMyAdmin in cPanel.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now