-1

So I have this sample C++ program I got from IBM (How to connect and disconnect from a database) in Embedded SQL section (see: http://www.ibm.com/support/knowledgecenter/SSEPGG_9.7.0/com.ibm.db2.luw.apdv.samptop.doc/doc/r0011556.html)

Im using Dev C++ and whenever I compile this it gives me an error. It says:

[Error] 'EXEC' does not name a type

Anyone knows the cause of this? is this a missing header file?

EDIT1: Here's the direct link for the code :http://www.ibm.com/support/knowledgecenter/en/SSEPGG_9.7.0/com.ibm.db2.luw.apdv.sample.doc/doc/cpp/s-dbconn-sqC.html

HanSoloQue
  • 19
  • 4
  • There is too little details on what should we do to reproduce an error, e.g. there is no code (see [http://stackoverflow.com/help/mcve](MCVE)). Based on the error I'd assume that you have tried to compile SQL request as a C++ code. – yeputons Feb 02 '17 at 08:08
  • Sorry if it confused everyone. The link I gave contains the code that I'm trying to compile (tho that's the main page and you still have to browse it there). Here tho is the direct link: http://www.ibm.com/support/knowledgecenter/en/SSEPGG_9.7.0/com.ibm.db2.luw.apdv.sample.doc/doc/cpp/s-dbconn-sqC.html – HanSoloQue Feb 02 '17 at 08:21
  • Are there any other errors that you get or the only line you provided is the complete compilation log? – yeputons Feb 02 '17 at 08:22
  • There are several errors after the one I gave, but what I gave is the first in line. Further inspecting the logs, the 'EXEC' error appears multiple times (mainly because EXEC SQL was used multiple times too). The remaining errors are some kind of type definitions that are 'not declared in this scope' – HanSoloQue Feb 02 '17 at 08:27

1 Answers1

1

The problem is that the example you linked is not a plain C++. It's an example for IBM's embedded SQL in C++, which requires some preprocessing with IBM-provided tools before feeding it into a compiler or standard C++ IDE which does not know about embedded SQL (like Dev C++). Quoting the link (emphasis mine):

Building embedded SQL applications involves two prerequisite steps prior to application compilation and linking.

  1. Preparing the source files containing embedded SQL statements using the DB2 precompiler.

    The PREP (PRECOMPILE) command is used to invoke the DB2 precompiler, which reads your source code, parses and converts the embedded SQL statements to DB2 run-time services API calls, and finally writes the output to a new modified source file. The precompiler produces access plans for the SQL statements, which are stored together as a package within the database.

  2. Binding the statements in the application to the target database.

    Binding is done by default during precompilation (the PREP command). If binding is to be deferred (for example, running the BIND command later), then the BINDFILE option needs to be specified at PREP time in order for a bind file to be generated.

Once you have precompiled and bound your embedded SQL application, it is ready to be compiled and linked using the host language-specific development tools.

So you have to pre-process the example with some IBM's tool (presumably called PREP) and only after that you will get a valid C++ code. I'm not sure if it's easy or possible to make Dev C++ use that automatically.

yeputons
  • 8,478
  • 34
  • 67
  • I see. Thanks for the clear explanation. I'll try researching if precompiling can be done in DevC++ – HanSoloQue Feb 02 '17 at 08:44
  • @HanSoloQue try looking for something like "pre-compilation hook" or "pre-compilation action". – yeputons Feb 02 '17 at 08:46
  • `prep` is the DB2 CLP command, you need the DB2 client installed for that. The installation also contains sample scripts to build embedded SQL programs. – mustaccio Feb 02 '17 at 11:52