/*************************************************************************
PROGRAM: SQLTESTR - SQL Data Server sample program for MS DOS
Copyright (c), 1988-1995 by Microsoft Corp.
*************************************************************************/
#define DBMSDOS /* must identify operating system envorinment */
#include <sqlfront.h>
#include <sqldb.h> /* DB-LIB header file (should always be included) */
#define NULL 0
main ()
{
PDBPROCESS dbproc; /* allocate a DB-LIB process structure */
PLOGINREC login; /* allocate a DB-LIB login structure */
int errno; /* variable to store DB-LIB error number in */
char *msg; /* used to receive DB-LIB error message pointer */
/* Variables used to store the returning data */
char au_lname[41];
char au_fname[20];
char id[12];
char phone[13];
char address[41];
char city[21];
char state[3];
char zip[6];
char getname[41];
char Servername[25];
RETCODE result_code;
/* Forward declarations of the error handler and message handler. */
int err_handler(PDBPROCESS, int, int, int, char*, char*);
int msg_handler(PDBPROCESS, DBINT, int, int, char*);
if(dbinit() == (char *)NULL)
{
printf("Communications layer not loaded\n");
exit(1);
}
// Install the user-supplied error-handling and message-handling
// routines. They are defined at the bottom of this source file.
dberrhandle((DBERRHANDLE_PROC)err_handler);
dbmsghandle((DBMSGHANDLE_PROC)msg_handler);
// Get server's computer name
Servername[0] = NULL;
printf ("\nEnter Name of SQL Server: ");
gets (Servername);
login = dblogin(); /* get login record from DB-LIB */
DBSETLUSER (login, "sa"); /* set the username */
DBSETLAPP (login, "example1"); /* set the application name */
DBSETLPWD (login, ""); /* set the SQL Server password */
DBSETLVERSION(login,DBVER60);
/* Now attempt to create and initialize a DBPROCESS structure */
if ((dbproc = dbopen (login, Servername)) == NULL)
{
printf ("dbopen failed\n");
return (1); /* exit program */
}
dbuse (dbproc, "pubs"); /* use the "pubs" database */
while (TRUE)
{
printf ("\nEnter author's last name to retrieve (return to exit): ");
gets (getname);
/* if only a return was entered */
if (getname[0] == NULL)
break;
/* construct command buffer to be sent to the SQL server */
dbcmd (dbproc, "select au_id, au_lname, au_fname, phone,");
dbcmd (dbproc, " address, city, state, zip");
dbcmd (dbproc, " from authors");
dbfcmd (dbproc, " where au_lname = '%s'",getname);
dbsqlexec (dbproc); /* send command buffer to SQL server */
/* now check the results from the SQL server */
while ((result_code = dbresults(dbproc)) != NO_MORE_RESULTS)
{
if (result_code == SUCCEED)
{
dbbind (dbproc, 1, NTBSTRINGBIND, (DBINT) 0, id);
dbbind (dbproc, 2, NTBSTRINGBIND, (DBINT) 0, au_lname);
dbbind (dbproc, 3, NTBSTRINGBIND, (DBINT) 0, au_fname);
dbbind (dbproc, 4, NTBSTRINGBIND, (DBINT) 0, phone);
dbbind (dbproc, 5, NTBSTRINGBIND, (DBINT) 0, address);
dbbind (dbproc, 6, NTBSTRINGBIND, (DBINT) 0, city);
dbbind (dbproc, 7, NTBSTRINGBIND, (DBINT) 0, state);
dbbind (dbproc, 8, NTBSTRINGBIND, (DBINT) 0, zip);
/* now process the rows */
while (dbnextrow(dbproc) != NO_MORE_ROWS)
{
printf ("Author ID: %s\n", id);
printf ("Last Name: %s\n", au_lname);
printf ("First Name: %s\n", au_fname);
printf ("Address: %s\n", address);
printf ("City: %s\n", city);
printf ("State: %s\n", state);
printf ("Zip Code: %s\n", zip);
printf ("Telephone: %s\n", phone);
printf ("\n");
}
}
else
{
printf ("Results Failed\n");
break;
}
}
} /* while (TRUE) */
/* Close the connection and exit */
dbexit();
}
int err_handler(PDBPROCESS dbproc, int severity, int dberr, int oserr, char * dberrstr, char * oserrstr)
{
printf("DB-LIBRARY error:\n\t%s\n", dberrstr);
if (oserr != DBNOERR)
printf("Operating-system error:\n\t%s\n", oserrstr);
if ((dbproc == NULL) || (DBDEAD(dbproc)))
return(INT_EXIT);
else
return(INT_CANCEL);
}
int msg_handler(PDBPROCESS dbproc, DBINT msgno, int msgstate, int severity, char * msgtext)
{
printf("SQL Server message %ld, state %d, severity %d:\n\t%s\n",
msgno, msgstate, severity, msgtext);
return(0);
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
SQLDBLIB.rar (50个子文件)
SQLDBLIB
dtccm.lib 3KB
srv.h 1KB
odbcver.h 1KB
srvmisc.h 3KB
bmdblib.lib 230KB
util.lib 51KB
TXCOORD.H 29KB
srvtok.h 2KB
svcsrvl.lib 2KB
dtccfg.lib 2KB
ntwdblib.lib 84KB
TXDTC.H 9KB
dtcuic.lib 3KB
w3dblib.lib 13KB
transact.h 33KB
msdtctm.lib 3KB
dtcuis.lib 4KB
dtcutil.lib 3KB
bldblib.lib 271KB
XOLEHLP.H 2KB
srvconst.h 6KB
MSDOS
buildbor.bat 2KB
sqlcommn.loc 4KB
buildr.bat 2KB
sqltestr.c 4KB
buildr.mak 649B
sqltestr.mak 2KB
buildbor.mak 528B
srvapi.h 7KB
msdblib3.lib 13KB
logmgr.lib 3KB
rldblib.lib 270KB
msdtcprx.lib 9KB
dtctrace.lib 3KB
opends60.lib 39KB
samprm.lib 5KB
sqlfront.h 24KB
odbcss.h 10KB
srvdbtyp.h 2KB
dacdll.lib 19KB
adme.lib 14KB
rmdblib.lib 237KB
dtchelp.lib 10KB
srvtypes.h 2KB
sqldb.h 13KB
xolehlp.lib 3KB
srvstruc.h 27KB
sqlole.h 272KB
sqloleid.h 23KB
XACTOMSG.H 585B
共 50 条
- 1
tty1a__
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页