📄 database.c
字号:
#include "database.h"
#define ERR_CH stderr
int err_handler();
int msg_handler();
void database_init()
{
//DBPROCESS *dbproc; /* The connection with SQL Server */
//LOGINREC *login; /* The login information */
int aa;
/* Initialize DB-LIBRARY */
if ( dbinit() == CS_FAIL ) {
printf("Error: Can't Initialize Sybase Database !");
exit(ERREXIT);
}
/* Install The User supplied error-handleing and message-handling routines*/
dberrhandle((EHANDLEFUNC)err_handler);
dbmsghandle((MHANDLEFUNC)msg_handler);
/* Get a LOGINREC */
login = dblogin();
DBSETLUSER(login, "xuzq");
DBSETLPWD(login, "hotmail98");
DBSETLAPP(login, "iptgate");
/* get a DBPROCESS Structure for communication with Sql Server */
dbproc=dbopen(login, "xuzqtest");
/* Open Database */
if ( ( aa = dbuse(dbproc, "Iphone")) == CS_FAIL ) {
printf( "Error: Use Database Iphone ");
exit( 1 );
}
/* Insert a new record to the rate_route_table*/
//dbcmd(dbproc,"INSERT INTO rate_route_table VALUES('澳大利亚','61','202.112.58.200','37',1,3.34,3.44)");
/* Process the results of each of the INSERT statements. */
//while ((return_code = dbresults(dbproc)) != NO_MORE_RESULTS)
//{
// if (return_code == FAIL)
// printf("One of the insert statements FAILed.\n");
//}
/* Retrieve some columns from the rate_route_table
in the Iphone database!*/
//dbcmd(dbproc," SELECT * FROM rate_route_table ");
/* Send the command to SQL server and start execution*/
//dbsqlexec(dbproc);
/* Process the command */
//while(return_code=dbresults(dbproc)!=NO_MORE_RESULTS)
//{
// if(return_code==SUCCEED)
// {
/* Bind results to program varibles */
// dbbind(dbproc, 1,STRINGBIND,(DBINT)0, nation_name);
// dbbind(dbproc, 2,STRINGBIND,(DBINT)0, idd_code);
// dbbind(dbproc, 3,STRINGBIND,(DBINT)0, ip_address);
// dbbind(dbproc, 4,STRINGBIND,(DBINT)0, gateway_code);
// dbbind(dbproc, 5,INTBIND,(DBINT)0, &status);
// dbbind(dbproc, 6,FLT8BIND,(DBINT)0, &call_fee);
// dbbind(dbproc, 7,FLT8BIND,(DBINT)0, &called_fee);
//
// while(dbnextrow(dbproc)!=NO_MORE_ROWS)
// {
// printf("The Nation Name get from database is %s\n",nation_name);
// printf("The Idd code get from database is %s\n",idd_code);
// printf("The IP address get from database is %s\n",ip_address);
// printf("The GateWay code get from database is %s\n",gateway_code);
// printf("The GateWay Status get from database is %d\n",status);
// printf("The call_fee get from database is %.2f\n",call_fee);
// printf("The called_fee get from database is %.2f\n",called_fee);
// getch();
// }
// }
//}
}
void database_close()
{
/*close the connection to SQL server*/
dbexit();
}
int err_handler(dbproc, severity, dberr, oserr, dberrstr, oserrstr)
DBPROCESS *dbproc;
int severity;
int dberr;
int oserr;
char *dberrstr;
char *oserrstr;
{
if ((dbproc == NULL) || (DBDEAD(dbproc)))
return(INT_EXIT);
else
{
fprintf (ERR_CH, "DB-Library error:\n\t%s\n", dberrstr);
if (oserr != DBNOERR)
fprintf (ERR_CH, "Operating-system error:\n\t%s\n", oserrstr);
return(INT_CANCEL);
}
}
int msg_handler(dbproc, msgno, msgstate, severity, msgtext,
srvname, procname, line)
DBPROCESS *dbproc;
DBINT msgno;
int msgstate;
int severity;
char *msgtext;
char *srvname;
char *procname;
DBUSMALLINT line;
{
fprintf (ERR_CH, "Msg %ld, Level %d, State %d\n",
msgno, severity, msgstate);
if (strlen(srvname) > 0)
fprintf (ERR_CH, "Server '%s', ", srvname);
if (strlen(procname) > 0)
fprintf (ERR_CH, "Procedure '%s', ", procname);
if (line > 0)
fprintf (ERR_CH, "Line %d", line);
fprintf (ERR_CH, "\n\t%s\n", msgtext);
return(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -