//----------------------------------------------------------------------------/* Free operator's identifier */
code = SQLFreeStmt(stmt,SQL_DROP);
if ((code == SQL_SUCCESS) || (code == SQL_SUCCESS_WITH_INFO))
printf("\nOperator identifier is dropped...\n");
else
{
printf("Error is occured while dropped operator identifier!\n");
SQLError(env,dbc,stmt,sqlstate, &nativeerr, errmsg,
SQL_MAX_MESSAGE_LENGTH - 1, &actualmsglen);
printf("SQLSTATE = %s\nNATIVE ERROR = %d\n", sqlstate, nativeerr);
errmsg[actualmsglen] = '\0';
printf("MSG = %s\n", errmsg);
End(env);
}
//----------------------------------------------------------------------------/* Disconnect from data source */
code = SQLDisconnect(dbc);
if (code != SQL_SUCCESS)
{
printf("Error when disconnecting from data source!\n");
End(env);
}
printf("Disconnection with data source is successful...\n");
//----------------------------------------------------------------------------/* Free connection's identifier */
code = SQLFreeConnect(dbc);
if (code != SQL_SUCCESS)
{
printf("Error when free connection's identifier!\n");
End(env);
}
printf("Connection's identifier is free...\n");
//----------------------------------------------------------------------------/* Free enviroment descriptor */
code = SQLFreeEnv(env);
if (code != SQL_SUCCESS)
{
printf("Error when free enviroment descriptor!\n");
End(env);
}
printf("Enviroment descriptor is free...\n");
//----------------------------------------------------------------------------/* Commit transaction */
SQLEndTran(SQL_HANDLE_ENV, env, SQL_COMMIT);
printf("Transaction is commited.\n");
exit(EXIT_SUCCESS);
} /* end of main */
void End(HENV env) /* Exit with rollback transaction */
{
/* Rollback transaction */
SQLEndTran(SQL_HANDLE_ENV, env, SQL_ROLLBACK);
printf("Transaction is canceled.\n\n");
exit(EXIT_FAILURE);
}
2. Вывести информацию о поставщиках, поставивших указанную деталь в заданный период (с использованием функций SQLFetch() и SQLGetData()).
Программа, реализующая выполнение.
#include <sqlext.h>
#include <sqltypes.h>
#include <strings.h>
#include <stdio.h>
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
void End(HENV env); /* Exit with rollback transaction */
int main (void)
{
HENV env; /* Environment descriptor */
HDBC dbc; /* Connection descriptor */
HSTMT stmt; /* Operator's identifier */
UCHAR driver[32]; /* Server name */
RETCODE code; /* Return code */
UCHAR errmsg[SQL_MAX_MESSAGE_LENGTH], sqlstate[10];
SDWORD nativeerr;
SWORD actualmsglen;
UCHAR sql[255]; /* Query string */
SDWORD cbTest = SQL_NTS;
UCHAR n_det[7]; /* Detail number */
UCHAR n_post[7]; /* Supplier number */
UCHAR surname[21]; /* Supplier surname */
SDWORD rating; /* Supplier rating */
UCHAR city[21]; /* Supplier city */
SDWORD val_n_post,val_surname,val_rating,val_city;
//-----------------------------------------------------------------------------
printf("Enter detail name: ");
scanf("%s",n_det);
//----------------------------------------------------------------------------/* Set enviroment descriptor */
code = SQLAllocEnv(&env);
if ((code == SQL_SUCCESS)||(code == SQL_SUCCESS_WITH_INFO))
printf("Enviroment descriptor is allocated...\n");
else
{
printf("Error when try to set enviroment descriptor!\n");
End(env);
}
//----------------------------------------------------------------------------/* Set connection descriptor */
code = SQLAllocConnect(env,&dbc);
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.