|
Hello all,
I am programming in C and...
I am having errors while compiling. The problem is that for some reason, the compiler is complaining that I am calling a label which is not in the function (instead is in the function above). I have been trying to de-bug this for past 4 hours, and have not had any success.
Since I have suspect about the following cursor, what is wrong with this cursor:
EXEC SQL CONNECT TO db2data;
EXEC SQL BEGIN DECLARE SECTION;
char host_someDate7[20];
sqlint32 host_total7;
EXEC SQL END DECLARE SECTION;
printf("Please enter a date (i.e. 10/15/2008)\n");
scanf("%s",&host_someDate7);
EXEC SQL DECLARE cursorfive CURSOR FOR
SELECT :host_someDate7 AS DATE, sum(PRICE) AS TOTAL
FROM (SELECT OUTGOINGORDERS.ORDERNUM, DEPT, TYPE, QUANTITY, (QUANTITY * UNITPRICE) AS PRICE FROM OUTGOINGORDERS,ORDERPRODUCTID, INVENTORYTABLE WHERE ORDERDATE = :host_someDate7 AND OUTGOINGORDERS.ORDERNUM = ORDERPRODUCTID.orderNum AND OrderProductID.PRODUCTID = INVENTORYTABLE.PRODUCTID) AS X
ORDER BY ORDERNUM;
And now I will now post the code and the compiler output.
The code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include </opt/IBM/db2/V8.1/include/sqlenv.h>
#include </opt/IBM/db2/V8.1/include/sqlcodes.h>
#include <sqlenv.h>
#include <sqlcodes.h>
#include </opt/IBM/db2/V8.1/include/sqladef.h>
#include <sys/time.h>
EXEC SQL INCLUDE SQLCA;
void salesOptions(void);
void initializer(void);
void mainMenu(void);
void initializer(void)
{
int a;
for (a=0;a<2;a++)
{
EXEC SQL CONNECT TO db2data;
EXEC SQL ALTER TABLE inventorytable ADD CONSTRAINT levelcheck CHECK (numatwarehouse >= 0);
EXEC SQL CONNECT RESET;
EXEC SQL CONNECT TO db2data;
EXEC SQL CREATE TRIGGER INVENTORY_UPDATE AFTER INSERT ON OrderProductID REFERENCING NEW ROW
AS R FOR EACH ROW UPDATE InventoryTable SET numatwarehouse=numatwarehouse-R.quantity WHERE productID=R.productID;
EXEC SQL CONNECT RESET;
}
printf("hello\n");
}
void salesOptions(void)
{
int salesChoice1;
printf( "\n\nSalesperson's Menu: \n");
printf( "1. Look up a product ID for inventory. \n");
printf( "2. Look up a customer. \n");
printf( "3. Enter a new customer. \n");
printf( "4. Book a new order. \n");
printf( "5. Delete a order. \n");
printf( "6. Check outgoing orders. \n");
printf( "7. Return to Main Menu. \n");
printf( "Please make your choice (1-7): \n");
scanf("%d",&salesChoice1);
if ( salesChoice1 == 1 )
{
EXEC SQL CONNECT TO db2data;
EXEC SQL BEGIN DECLARE SECTION;
sqlint32 host_x;
sqlint32 host_productID;
char host_dept[15];
char host_itemName[20];
sqlint32 host_unitPrice;
sqlint32 host_numAtWarehouse;
EXEC SQL END DECLARE SECTION;
printf( "Please enter a product ID: \n");
scanf("%d",&host_x);
EXEC SQL DECLARE empcsr CURSOR FOR
SELECT productID, dept, itemName, unitPrice, numAtWarehouse
FROM inventorytable
WHERE productID = :host_x;
EXEC SQL OPEN empcsr;
EXEC SQL WHENEVER NOT FOUND GO TO close_empcsr;
/* Loop indefinitely (the WHENEVER NOT FOUND statement
will cause the loop to be terminated when the end of the
table is encountered. */
do {
EXEC SQL FETCH empcsr
INTO :host_productID, :host_dept, :host_itemName, :host_unitPrice, :host_numAtWarehouse;
/* Print host_name and host_emp_number */
printf("\nProduct ID: %d\n",host_productID);
printf("Department: %s\n",host_dept);
printf("Item Name: %s\n",host_itemName);
printf("Unit Price: %d\n",host_unitPrice);
printf("Number at warehouse: %d\n",host_numAtWarehouse);
} while(1);
close_empcsr:
EXEC SQL CLOSE empcsr;
EXEC SQL CONNECT RESET;
salesOptions();
}
else if (salesChoice1 == 7)
{
mainMenu();
}
}
void totalSales(void)
{
EXEC SQL CONNECT TO db2data;
EXEC SQL BEGIN DECLARE SECTION;
char host_someDate7[20];
sqlint32 host_total7;
EXEC SQL END DECLARE SECTION;
printf("Please enter a date (i.e. 10/15/2008)\n");
scanf("%s",&host_someDate7);
EXEC SQL DECLARE cursorfive CURSOR FOR
SELECT :host_someDate7 AS DATE, sum(PRICE) AS TOTAL
FROM (SELECT OUTGOINGORDERS.ORDERNUM, DEPT, TYPE, QUANTITY, (QUANTITY * UNITPRICE) AS PRICE FROM OUTGOINGORDERS,ORDERPRODUCTID, INVENTORYTABLE WHERE ORDERDATE = :host_someDate7 AND OUTGOINGORDERS.ORDERNUM = ORDERPRODUCTID.orderNum AND OrderProductID.PRODUCTID = INVENTORYTABLE.PRODUCTID) AS X
ORDER BY ORDERNUM;
EXEC SQL OPEN cursorfive;
EXEC SQL WHENEVER NOT FOUND GO TO close_cursorfive;
do {
EXEC SQL FETCH cursorfive
INTO :host_someDate7, :host_total7;
/* Print host_name and host_emp_number */
printf("\nDate: %s\n",host_someDate7);
printf("Total: %s\n",host_total7);
} while(1);
close_cursorfive:
EXEC SQL CLOSE cursorfive;
EXEC SQL CONNECT RESET;
}
void accountantOptions(void)
{
int theChoice2;
printf("\n\nAccountant's Menu:\n");
printf("1. Total sales for some date.\n");
printf("2. Detailed daily report.\n");
printf("3. Detailed report for a period.\n");
printf("4. Main Menu.\n");
printf("Please make your choice (1-4):\n");
scanf("%d",&theChoice2);
if (theChoice2 == 1 )
{
//totalSales();
}
else if (theChoice2 == 2 )
{
//viewFinancialReport();
printf("hello\n");
}
else if (theChoice2 == 3 )
{
//financialReportPeriod();
printf("yello\n");
}
else if (theChoice2 == 4 )
{
mainMenu();
}
}
int exitProgram(void)
{
exit(0);
}
void mainMenu(void)
{
int theChoice;
top:
printf("\n\nMain Menu:\n");
printf("1. Salesperson's options.\n");
printf("2. Accountant's options.\n");
printf("3. Vice President's options.\n");
printf("4. Clerk's options.\n");
printf("5. Order Dispatcher/Receiver's options.\n");
printf("6. Database Administrator's options.\n");
printf("7. EXIT\n");
printf("Please make your choice (1-7):");
scanf("%d",&theChoice);
if (theChoice == 1)
{
salesOptions();
}
else if (theChoice == 2)
{
accountantOptions();
}
else if (theChoice == 7)
{
exitProgram();
}
else
{
goto top;
}
}
int main(void)
{
initializer();
mainMenu();
}
The compiler output:
Compiling test2 executable\c
.\c
.\c
.\c
test2.sqc: In function `totalSales':
test2.sqc:113: error: label `close_empcsr' used but not defined
.\c
.\c
|