VC6 Compiler and SQL

Hi guys,

I have got this code to run a simple stored procedure (DB2) from the command line. Now - it does not compile in VC6 - but I think thats because it needs to run on a DB2 compiler? Any ideas?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "util.h"
//#include <sqlca.h>

EXEC SQL INCLUDE SQLCA;
#define  CHECKERR(CE_STR) if (check_error (CE_STR, &sqlca) != 0) return 1;
int main(int argc, char *argv[])
{    
      EXEC SQL BEGIN DECLARE SECTION;
   
            char firstname[13];      
            char userid[9];
            char passwd[19];
            char tradecapid[8];
      
      EXEC SQL END DECLARE SECTION;    
      printf( "Sample C program: STATIC\n" );

      if (argc == 1)
            {      
                  EXEC SQL CONNECT TO AAMC204D;
                  CHECKERR ("CONNECT TO AAMC204D");  
            }  
      else if (argc == 3)
            {
                  strcpy (userid, argv[1]);      
                  strcpy (passwd, argv[2]);
                  EXEC SQL CONNECT TO sample USER :userid USING :passwd;
                  CHECKERR ("CONNECT TO SAMPLE");  
            }  
      else if (argc == 4)
            {
                  strcpy (userid, argv[1]);      
                  strcpy (passwd, argv[2]);
                  strcpy (tradecapid, argv[3]);
                  EXEC SQL CONNECT TO sample USER :userid USING :passwd;
                  CHECKERR ("CONNECT TO SAMPLE");  
            }  
      else
            {
            printf ("\nUSAGE: static [userid passwd]\n\n");      
            return 1;
            }
            
      EXEC SQL INSERT 'TEST STORED PROC' INTO :SPL_INSTR4 FROM SEC_TRD WHERE TRD_CAP_ID = :tradecapid;
      CHECKERR ("SELECT statement");  
      printf( "First name = %s\n", firstname );    
      EXEC SQL CONNECT RESET;
      CHECKERR ("CONNECT RESET");  
      return 0;

}

Errors:

C:\WINNT\Profiles\Adccg19\Desktop\SQLTest.cpp(7) : error C2146: syntax error : missing ';' before identifier 'SQL'
C:\WINNT\Profiles\Adccg19\Desktop\SQLTest.cpp(7) : error C2501: 'EXEC' : missing storage-class or type specifiers
C:\WINNT\Profiles\Adccg19\Desktop\SQLTest.cpp(7) : fatal error C1004: unexpected end of file found

Cheers

Simon
LVL 6
simonbennettAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KangaRooCommented:
The code seems to use something called embedded SQL. Usually this involves a pre-parser which translates the special SQL stuff into valid C code. This system depends on the Database (DB2)
You should probably convert to ODBC, which is independent of the actual DBM, as long as the specific ODBC for the DBM is installed.
0
simonbennettAuthor Commented:
Thanks Kangaroo - I did think that It needed something like that. You mention ODBC which I am pretty familiar with - (bear in mind the front end is in VB) - is it possible to call eSQL procs via the ODBC interface? We use DB2CLI at them moment.

Can you think of a better way?

Cheers

Simon
0
simonbennettAuthor Commented:
.extra points available for a top anwser...
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

KangaRooCommented:
I do it regarly from an iSQL like application which uses ODBC. Pass-through queries from Access also work, well as long as the procedure doesn't 'return' anything that doesn't fit in a 'table'.
Anyway, ODBC has a specific method to call stored procedures using an escape sequence. Details in the manual (sorry :(
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
simonbennettAuthor Commented:
Cheers Kangaroo. I am waiting on some info from my US colleagues on the DB2 compiler. I will leave this open to see if anyone else bites...

BTW - bonus points if anyone has a VB example of calling this embedded SQL. Would it just be like

database.execute "StoredProcName", dbfailonerror

or do I have to use the SQL API functions (thats how we talk to DB2 at the mo) to send the Proc name as an SQL statement?

And what about parameters?

I will  give all of my points in the world for a good response, not yet though because we may want to split it.

Cheers

Simon
0
SrwCommented:
I've used both.  When using VB, I've use the database.execute method  When using C++, I've used raw ODBC, just send the SQL command with SQLExecDirect.

In either case, just build a string with a complete, valid sql command and everything should work fine.

You know "exec proc_TEST 'string param', 15, '12/01/1999'" or whatever.

You can also do insert/update/delete, and any other db specific commands this way, too.  "use master" for instance.  Obviously, when using DAO/ADO,etc. there are better ways to do inserts, updates and the like.  But, you can also do them all with native sql.

Just remember, if you use db specific syntax, you lose portability.
0
simonbennettAuthor Commented:
Ta Kangaroo - sorry about the delay - it's been a 'heavy' old xmas

SIW - will post a Q for you...
0
KangaRooCommented:
That is fine. Thanx and a Happy New Year!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.