Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > Visual C++
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 9th, 2004, 10:49 PM
Registered User
 
Join Date: Feb 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Embedded SQL in Visual C++

Hi all;

I have problems compiling the following file which includes Exec SQL..
Does anybody out there know what causes this error?

Thanks a lot


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sqlenv.h>
#include <sqlcodes.h>
#include <time.h>

#define EXIT 0
#define NOEXIT 1

/*----------------------------------------------------------------------------
Include DB2's SQL error reporting facility.
----------------------------------------------------------------------------*/

EXEC SQL INCLUDE SQLCA ;

/*----------------------------------------------------------------------------
Declare the SQL interface variables.
----------------------------------------------------------------------------*/

EXEC SQL BEGIN DECLARE SECTION ;
    short sage;
    short sid;
    char sname[16];
EXEC SQL END DECLARE SECTION ;

/*----------------------------------------------------------------------------
Declare variables to be used in the following C program.
----------------------------------------------------------------------------*/

char msg[1025];
int rc;
int errcount;

/*----------------------------------------------------------------------------
.....
.....
main (int argc, char *argv[])
{
    /* Grab the first command argument. This is the SID. */
    if (argc > 1) {
        sid = atoi(argv[1]);
        printf("SID requested is %d.\n", sid);
    /* If there is no arguement, bail. */
    } else {
        printf("Which SID?\n");
        exit(0);
    }

        EXEC SQL CONNECT TO GO3421;
        CHECK_SQL(0, "Connect failed", EXIT);

        /* Find the name and age of sailor SID. */
        EXEC SQL SELECT SNAME, AGE into :sname, :sage
            FROM TECHSTU.SAILOR
            WHERE sid = :sid;

        CHECK_SQL(0, "The SELECT query failed.", EXIT);

        /* Report the age. */
        printf("Sailor %s's age is %d.\n", sname, sage);

        printf("Executed Successfuly\n") ;
        printf("Bye\n") ;

errorexit:
        EXEC SQL CONNECT RESET;
}


Errors:
--------------------------------------------------------
Compiling...
test2.c
D:\SQL_C\myproject\test2.c(30) : error C2282: 'EXEC' is followed by 'SQL' (missing ','?)
D:\SQL_C\myproject\test2.c(36) : error C2282: 'EXEC' is followed by 'SQL' (missing ','?)
D:\SQL_C\myproject\test2.c(40) : error C2282: 'EXEC' is followed by 'SQL' (missing ','?)
D:\SQL_C\myproject\test2.c(125) : error C2065: 'EXEC' : undeclared identifier
D:\SQL_C\myproject\test2.c(125) : error C2146: syntax error : missing ';' before identifier 'SQL'
D:\SQL_C\myproject\test2.c(125) : error C2065: 'SQL' : undeclared identifier
D:\SQL_C\myproject\test2.c(125) : error C2146: syntax error : missing ';' before identifier 'CONNECT'
D:\SQL_C\myproject\test2.c(125) : error C2065: 'CONNECT' : undeclared identifier
D:\SQL_C\myproject\test2.c(125) : error C2146: syntax error : missing ';' before identifier 'TO'
D:\SQL_C\myproject\test2.c(125) : error C2065: 'TO' : undeclared identifier
D:\SQL_C\myproject\test2.c(125) : error C2146: syntax error : missing ';' before identifier 'GO3421'
D:\SQL_C\myproject\test2.c(125) : error C2065: 'GO3421' : undeclared identifier
D:\SQL_C\myproject\test2.c(126) : error C2065: 'sqlca' : undeclared identifier
D:\SQL_C\myproject\test2.c(126) : error C2224: left of '.sqlcode' must have struct/union type
D:\SQL_C\myproject\test2.c(126) : warning C4133: 'function' : incompatible types - from 'int *' to 'struct sqlca *'
D:\SQL_C\myproject\test2.c(126) : error C2224: left of '.sqlcode' must have struct/union type
D:\SQL_C\myproject\test2.c(126) : error C2224: left of '.sqlcaid' must have struct/union type
D:\SQL_C\myproject\test2.c(126) : error C2224: left of '.sqlcabc' must have struct/union type
D:\SQL_C\myproject\test2.c(126) : error C2224: left of '.sqlcode' must have struct/union type
D:\SQL_C\myproject\test2.c(126) : error C2224: left of '.sqlerrml' must have struct/union type
D:\SQL_C\myproject\test2.c(126) : error C2224: left of '.sqlerrmc' must have struct/union type
D:\SQL_C\myproject\test2.c(126) : error C2224: left of '.sqlerrp' must have struct/union type
D:\SQL_C\myproject\test2.c(126) : error C2224: left of '.sqlerrd' must have struct/union type
D:\SQL_C\myproject\test2.c(126) : error C2224: left of '.sqlerrd' must have struct/union type
D:\SQL_C\myproject\test2.c(126) : error C2224: left of '.sqlerrd' must have struct/union type
D:\SQL_C\myproject\test2.c(126) : error C2224: left of '.sqlerrd' must have struct/union type
D:\SQL_C\myproject\test2.c(126) : error C2224: left of '.sqlerrd' must have struct/union type
D:\SQL_C\myproject\test2.c(126) : error C2224: left of '.sqlerrd' must have struct/union type
D:\SQL_C\myproject\test2.c(126) : error C2224: left of '.sqlwarn' must have struct/union type
D:\SQL_C\myproject\test2.c(126) : error C2224: left of '.sqlstate' must have struct/union type
D:\SQL_C\myproject\test2.c(129) : error C2146: syntax error : missing ';' before identifier 'SQL'
D:\SQL_C\myproject\test2.c(129) : error C2146: syntax error : missing ';' before identifier 'SELECT'
D:\SQL_C\myproject\test2.c(129) : error C2065: 'SELECT' : undeclared identifier
D:\SQL_C\myproject\test2.c(129) : error C2146: syntax error : missing ';' before identifier 'SNAME'
D:\SQL_C\myproject\test2.c(129) : error C2065: 'SNAME' : undeclared identifier
D:\SQL_C\myproject\test2.c(129) : error C2065: 'AGE' : undeclared identifier
D:\SQL_C\myproject\test2.c(129) : error C2146: syntax error : missing ';' before identifier 'into'
D:\SQL_C\myproject\test2.c(129) : error C2059: syntax error : ':'
D:\SQL_C\myproject\test2.c(133) : error C2224: left of '.sqlcode' must have struct/union type
D:\SQL_C\myproject\test2.c(133) : warning C4133: 'function' : incompatible types - from 'int *' to 'struct sqlca *'
D:\SQL_C\myproject\test2.c(133) : error C2224: left of '.sqlcode' must have struct/union type
D:\SQL_C\myproject\test2.c(133) : error C2224: left of '.sqlcaid' must have struct/union type
D:\SQL_C\myproject\test2.c(133) : error C2224: left of '.sqlcabc' must have struct/union type
D:\SQL_C\myproject\test2.c(133) : error C2224: left of '.sqlcode' must have struct/union type
D:\SQL_C\myproject\test2.c(133) : error C2224: left of '.sqlerrml' must have struct/union type
D:\SQL_C\myproject\test2.c(133) : error C2224: left of '.sqlerrmc' must have struct/union type
D:\SQL_C\myproject\test2.c(133) : error C2224: left of '.sqlerrp' must have struct/union type
D:\SQL_C\myproject\test2.c(133) : error C2224: left of '.sqlerrd' must have struct/union type
D:\SQL_C\myproject\test2.c(133) : error C2224: left of '.sqlerrd' must have struct/union type
D:\SQL_C\myproject\test2.c(133) : error C2224: left of '.sqlerrd' must have struct/union type
D:\SQL_C\myproject\test2.c(133) : error C2224: left of '.sqlerrd' must have struct/union type
D:\SQL_C\myproject\test2.c(133) : error C2224: left of '.sqlerrd' must have struct/union type
D:\SQL_C\myproject\test2.c(133) : error C2224: left of '.sqlerrd' must have struct/union type
D:\SQL_C\myproject\test2.c(133) : error C2224: left of '.sqlwarn' must have struct/union type
D:\SQL_C\myproject\test2.c(133) : error C2224: left of '.sqlstate' must have struct/union type
D:\SQL_C\myproject\test2.c(142) : error C2146: syntax error : missing ';' before identifier 'SQL'
D:\SQL_C\myproject\test2.c(142) : error C2146: syntax error : missing ';' before identifier 'CONNECT'
D:\SQL_C\myproject\test2.c(142) : error C2146: syntax error : missing ';' before identifier 'RESET'
D:\SQL_C\myproject\test2.c(142) : error C2065: 'RESET' : undeclared identifier
D:\SQL_C\myproject\test2.c(143) : warning C4035: 'main' : no return value
Error executing cl.exe.
test2.obj - 57 error(s), 3 warning(s)
 
Old February 28th, 2007, 01:54 AM
Registered User
 
Join Date: Feb 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Romesh
Default

Hi,
You have not included the files types.h and stat.h, both lying in the Include/sys directry of your installation.
Try it, the errors will come down but a few might remain..

Also these errors are of Visual C++, where as you must write the file in .pc and convert it to c/cpp , and then include it in your code.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting embedded visual basic 3 system to .Net aaudi .NET Framework 1.x 0 April 17th, 2006 02:44 AM
Getting Started with Embedded Visual C++ rodmcleay Visual C++ 6 February 21st, 2006 02:38 PM
SQL and Visual Basic mytreasure23 SQL Server 2000 1 November 9th, 2004 03:26 AM
does visual C++ support SQL script davidwong Visual C++ 1 August 17th, 2004 02:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.