Solved

the compliting of SQL

Posted on 2009-05-18
4
328 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

763 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

11 Experts available now in Live!

Get 1:1 Help Now