- 论坛徽章:
- 0
|
我有一个SCO下SYBASE的ESQL/C方法写的tt.cpre程序,如何建立一个好的编译环境??
tt.cpre:
#include <stdio.h>;
#include <string.h>;
#include "sybsqlex.h"
/* Declare the SQLCA */
EXEC SQL INCLUDE sqlca;
/*
** Forward declarations of the error and message handlers and
** other subroutines called from main().
*/
void error_handler();
void warning_handler();
int main()
{
EXEC SQL BEGIN DECLARE SECTION;
/* storage for login name and password */
CS_CHAR username[30], password[30];
CS_CHAR char_col[10], num_col[10], dec_col[30] ;
CS_CHAR int_col[10], flt_col[30] ;
CS_SMALLINT char_indic, int_indic, flt_indic, num_indic, dec_indic;
EXEC SQL END DECLARE SECTION ;
EXEC SQL WHENEVER SQLERROR CALL error_handler();
EXEC SQL WHENEVER NOT FOUND STOP ;
EXEC SQL WHENEVER SQLWARNING CALL warning_handler();
/*
** Copy the user name and password defined in sybsqlex.h to
** the variables declared for them in the declare section.
*/
strcpy(username, USER);
strcpy(password, PASSWORD);
EXEC SQL CONNECT :username IDENTIFIED BY :password ;
EXEC SQL USE tempdb ;
EXEC SQL DECLARE sel_cursor CURSOR FOR select * from all_types ;
EXEC SQL OPEN sel_cursor ;
printf("Data \t\t Null/Not null \n" ;
printf("----------------------------------- \n" ;
for ( ;; )
{
strcpy(char_col,"NULL" ;
strcpy(int_col,"NULL" ;
strcpy(flt_col,"NULL" ;
strcpy(num_col,"NULL" ;
strcpy(dec_col,"NULL" ;
if ( sqlca.sqlcode == 100 )
{
printf("No more results. \n" ;
break ;
}
EXEC SQL FETCH sel_cursor INTO
:char_col :char_indic,
:int_col :int_indic ,
:flt_col :flt_indic ,
:num_col :num_indic ,
:dec_col :dec_indic ;
printf("%-20s %d\n",char_col, char_indic );
printf("%-20s %d\n",int_col , int_indic );
printf("%-20s %d\n",flt_col , flt_indic );
printf("%-20s %d\n",num_col , num_indic );
printf("%-20s %d\n",dec_col , dec_indic );
printf("\n \n" ;
}
EXEC SQL DISCONNECT ALL;
exit(0);
}
/*
** void error_handler()
**
** Displays error codes and numbers from the SQLCA and exits with
** an ERREXIT status.
*/
void error_handler()
{
fprintf(stderr, "\n** SQLCODE=(%d)", sqlca.sqlcode);
if (sqlca.sqlerrm.sqlerrml)
{
fprintf(stderr, "\n** Error Message: " ;
fprintf(stderr, "\n** %s", sqlca.sqlerrm.sqlerrmc);
}
fprintf(stderr, "\n\n");
exit(ERREXIT);
}
/*
** void warning_handler()
**
** Displays warning messages.
*/
void warning_handler()
{
if (sqlca.sqlwarn[1] == 'W')
{
fprintf(stderr,
"\n** Data truncated.\n");
}
if (sqlca.sqlwarn[3] == 'W')
{
fprintf(stderr,
"\n** Insufficient host variables to store results.\n");
}
return;
}
我的makefile是:
# Makefile
#
.SUFFIXES:.cpre
CC=cc
SYBASEDIR=/usr/sybase
LIBDIR=-L$(SYBASEDIR)/lib
INCLDIR=-I$(SYBASEDIR)/include
CPRE=$(SYBASEDIR)/bin/cpre -V CS_VERSION_110 -I$(SYBASEDIR)/include
CFLAGS=-O -DUNIX
LIBS =-lm
EDF=
all:
for af in *.cpre ;do \
make -r `basename $$af .cpre`;\
done
.c:
@echo Compiling the program $@
$(CC) -o $@ $< $(CFLAGS) $(INCLDIR) $(LIBDIR)
@echo "---$@ compiling done."
.cpre.c:
$(CPRE) $<
cp $*.c $@
可我在编译时总是不对,我怀疑我的环境设错了,请各位多多指正!!!!!!!!
[/url] |
|