📄 dbinterface.c
字号:
/*
** Generated code begins here.
*/
# line 1 "dbInterface.cpp"
/*
** This file was generated on Sun Mar 22 13:44:01 2009
** by Sybase Embedded SQL Preprocessor Sybase ESQL/C Precompiler/15.0/P-EBF141
** 65 ESD #7/DRV.15.0.3/Linux Intel/Linux 2.4.21-47.0.1.ELsmp i686 Native Threa
** ds/BUILD1500-093/OPT/Wed Dec 13 22:11:44 2006
*/
# line 1 "dbInterface.cpp"
# line 1 "dbInterface.cpp"
#define _SQL_SCOPE extern
# line 1 "dbInterface.cpp"
#include <sybhesql.h>
/*
** Generated code ends here.
*/
# line 1 "dbInterface.cpp"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../inc/dbInterface.hpp"
/**************************************/
#define MAX_TMSI_LEN 4 //the TMSI/P-TMSI is 4 octets long
#define MAX_IMSI_LEN 15 //The IMSI shall not exceed 15 digits
#define MAX_MSISDN_LEN 32
#define MAX_FILENAME_LEN 128 //NOTE
#define MAX_A_SPC_LEN 3 //A接口点码长度BYTE
#define MAX_LR_LEN 3
#define MAX_TIME_LEN 32
#define MAX_FACILITY_LEN 256 //
#define MAX_FN_LEN 32
#define MINIX(a, b) ((a) > (b) ? (b) : (a))
/**************************************/
#ifndef _MULTITHREAD_SUPPORT_
/*
** SQL STATEMENT: 1
** exec sql include sqlca;
*/
# line 20 "dbInterface.cpp"
# line 20 "dbInterface.cpp"
SQLCA sqlca;
/*
** Generated code ends here.
*/
# line 20 "dbInterface.cpp"
#endif
/*
cpre_r sample.cp
gcc -g -D_REENTRANT -I/opt/sybase/OCS-15_0/include -L/opt/sybase/OCS-15_0/lib -lsybct_r -lsybtcl_r -lsybcs_r -lsybcomn_r -lsybunic -rdynamic -ldl -lpthread -lnsl -lm /opt/sybase/OCS-15_0/include/sybesql.c sample.c -o sample
*/
/*
#ifdef _MULTITHREAD_SUPPORT_
typedef struct threadLocalData
{
int retCode;
char errMsg[512];
} threadLocalData;
#define OBJECT_SIZE sizeof(threadLocalData)
static pthread_key_t key;
static pthread_once_t key_once = PTHREAD_ONCE_INIT;
static void make_key()
{
(void) pthread_key_create(&key, NULL);
}
void threadInit()
{
void *ptr;
(void) pthread_once(&key_once, make_key);
if ((ptr = pthread_getspecific(key)) == NULL)
{
ptr = malloc(OBJECT_SIZE);
if(ptr != NULL) memset(ptr, 0, OBJECT_SIZE);
(void) pthread_setspecific(key, ptr);
}
}
static atomic_t iConnectCnt = ATOMIC_INIT(0);
#else
unsigned int iConnectCnt = 0;
#endif
*/
static unsigned long iConnectCnt =0;
int getConnectName(char* cntBuf)
{
int cnt = ++iConnectCnt;
sprintf(cntBuf, "joyit@zyj%d", cnt);
return cnt;
}
int connectDb(char *uname, char *pwd, char *srv)
{
/*
** SQL STATEMENT: 1
** exec sql begin declare section;
*/
# line 73 "dbInterface.cpp"
char username[32];
char passwd[32] ;
char servname[32];
char cntname[32];
/*
** SQL STATEMENT: 2
** exec sql end declare section;
*/
# line 78 "dbInterface.cpp"
/*
** Generated code ends here.
*/
# line 78 "dbInterface.cpp"
if(uname != NULL) strncpy(username, uname, 32);
if(pwd != NULL) strncpy(passwd, pwd, 32);
if(srv != NULL) strncpy(servname, srv, 32);
int id = getConnectName(cntname);
/*
** SQL STATEMENT: 3
** exec sql connect :username identified by :passwd at :cntname using
** :servname;
*/
# line 85 "dbInterface.cpp"
# line 85 "dbInterface.cpp"
{
# line 85 "dbInterface.cpp"
_SQL_CT_HANDLES * _sql;
# line 85 "dbInterface.cpp"
_sqlinitctx(&_sql, CS_VERSION_150, CS_TRUE, &sqlca, (long
# line 85 "dbInterface.cpp"
*)NULL, (CS_CHAR *)NULL);
# line 85 "dbInterface.cpp"
if (_sql != (_SQL_CT_HANDLES *) NULL)
# line 85 "dbInterface.cpp"
{
# line 85 "dbInterface.cpp"
_sql->stmtData.persistent = CS_FALSE;
# line 85 "dbInterface.cpp"
_sql->stmttype = SQL_NONANSI_CONNECT;
# line 85 "dbInterface.cpp"
_sql->connName.lnlen = CS_NULLTERM;
# line 85 "dbInterface.cpp"
strcpy(_sql->connName.last_name, cntname);
# line 85 "dbInterface.cpp"
if ((_sql->retcode = _sqlprolog(_sql)) == CS_SUCCEED)
# line 85 "dbInterface.cpp"
{
# line 85 "dbInterface.cpp"
if (_sql->doDecl == CS_TRUE)
# line 85 "dbInterface.cpp"
{
# line 85 "dbInterface.cpp"
if (_sql->retcode == CS_SUCCEED)
# line 85 "dbInterface.cpp"
{
# line 85 "dbInterface.cpp"
_sql->retcode =
# line 85 "dbInterface.cpp"
ct_con_props(_sql->conn.connection, CS_SET,
# line 85 "dbInterface.cpp"
CS_USERNAME, username, CS_NULLTERM, NULL);
# line 85 "dbInterface.cpp"
}
# line 85 "dbInterface.cpp"
# line 85 "dbInterface.cpp"
if (_sql->retcode == CS_SUCCEED)
# line 85 "dbInterface.cpp"
{
# line 85 "dbInterface.cpp"
_sql->retcode =
# line 85 "dbInterface.cpp"
ct_con_props(_sql->conn.connection, CS_SET,
# line 85 "dbInterface.cpp"
CS_PASSWORD, passwd, CS_NULLTERM, NULL);
# line 85 "dbInterface.cpp"
}
# line 85 "dbInterface.cpp"
# line 85 "dbInterface.cpp"
if (_sql->retcode == CS_SUCCEED)
# line 85 "dbInterface.cpp"
{
# line 85 "dbInterface.cpp"
_sql->retcode = _sqlctdiag(_sql, CS_CLEAR,
# line 85 "dbInterface.cpp"
CS_UNUSED);
# line 85 "dbInterface.cpp"
}
# line 85 "dbInterface.cpp"
# line 85 "dbInterface.cpp"
if (_sql->retcode == CS_SUCCEED)
# line 85 "dbInterface.cpp"
{
# line 85 "dbInterface.cpp"
_sql->retcode =
# line 85 "dbInterface.cpp"
ct_capability(_sql->conn.connection, CS_SET,
# line 85 "dbInterface.cpp"
CS_CAP_RESPONSE, CS_RES_NOSTRIPBLANKS,
# line 85 "dbInterface.cpp"
&_sql->cstrue);
# line 85 "dbInterface.cpp"
}
# line 85 "dbInterface.cpp"
# line 85 "dbInterface.cpp"
if (_sql->retcode == CS_SUCCEED)
# line 85 "dbInterface.cpp"
{
# line 85 "dbInterface.cpp"
_sql->retcode =
# line 85 "dbInterface.cpp"
ct_con_props(_sql->conn.connection, CS_SET,
# line 85 "dbInterface.cpp"
CS_EXTRA_INF, &_sql->cstrue, CS_UNUSED,
# line 85 "dbInterface.cpp"
NULL);
# line 85 "dbInterface.cpp"
}
# line 85 "dbInterface.cpp"
# line 85 "dbInterface.cpp"
if (_sql->retcode == CS_SUCCEED)
# line 85 "dbInterface.cpp"
{
# line 85 "dbInterface.cpp"
_sql->retcode =
# line 85 "dbInterface.cpp"
ct_con_props(_sql->conn.connection, CS_SET,
# line 85 "dbInterface.cpp"
CS_ANSI_BINDS, &_sql->cstrue, CS_UNUSED,
# line 85 "dbInterface.cpp"
NULL);
# line 85 "dbInterface.cpp"
}
# line 85 "dbInterface.cpp"
# line 85 "dbInterface.cpp"
if (_sql->retcode == CS_SUCCEED)
# line 85 "dbInterface.cpp"
{
# line 85 "dbInterface.cpp"
_sql->retcode =
# line 85 "dbInterface.cpp"
ct_connect(_sql->conn.connection, servname,
# line 85 "dbInterface.cpp"
CS_NULLTERM);
# line 85 "dbInterface.cpp"
}
# line 85 "dbInterface.cpp"
# line 85 "dbInterface.cpp"
if (_sql->retcode == CS_SUCCEED)
# line 85 "dbInterface.cpp"
{
# line 85 "dbInterface.cpp"
_sql->retcode =
# line 85 "dbInterface.cpp"
ct_con_props(_sql->conn.connection, CS_GET,
# line 85 "dbInterface.cpp"
CS_TDS_VERSION, &_sql->temp_int, CS_UNUSED,
# line 85 "dbInterface.cpp"
&_sql->outlen);
# line 85 "dbInterface.cpp"
if (_sql->retcode == CS_SUCCEED)
# line 85 "dbInterface.cpp"
{
# line 85 "dbInterface.cpp"
if (_sql->temp_int < CS_TDS_50)
# line 85 "dbInterface.cpp"
{
# line 85 "dbInterface.cpp"
_sqlsetintrerr(_sql, (CS_INT)
# line 85 "dbInterface.cpp"
_SQL_INTRERR_25013);
# line 85 "dbInterface.cpp"
}
# line 85 "dbInterface.cpp"
# line 85 "dbInterface.cpp"
}
# line 85 "dbInterface.cpp"
# line 85 "dbInterface.cpp"
}
# line 85 "dbInterface.cpp"
# line 85 "dbInterface.cpp"
if (_sql->retcode == CS_SUCCEED)
# line 85 "dbInterface.cpp"
{
# line 85 "dbInterface.cpp"
_sql->retcode =
# line 85 "dbInterface.cpp"
ct_options(_sql->conn.connection, CS_SET,
# line 85 "dbInterface.cpp"
CS_OPT_ANSINULL, &_sql->cstrue, CS_UNUSED,
# line 85 "dbInterface.cpp"
NULL);
# line 85 "dbInterface.cpp"
}
# line 85 "dbInterface.cpp"
# line 85 "dbInterface.cpp"
if (_sql->retcode == CS_SUCCEED)
# line 85 "dbInterface.cpp"
{
# line 85 "dbInterface.cpp"
_sql->retcode =
# line 85 "dbInterface.cpp"
ct_options(_sql->conn.connection, CS_SET,
# line 85 "dbInterface.cpp"
CS_OPT_ANSIPERM, &_sql->cstrue, CS_UNUSED,
# line 85 "dbInterface.cpp"
NULL);
# line 85 "dbInterface.cpp"
_sql->retcode = CS_SUCCEED;
# line 85 "dbInterface.cpp"
}
# line 85 "dbInterface.cpp"
# line 85 "dbInterface.cpp"
if (_sql->retcode == CS_SUCCEED)
# line 85 "dbInterface.cpp"
{
# line 85 "dbInterface.cpp"
_sql->retcode =
# line 85 "dbInterface.cpp"
ct_options(_sql->conn.connection, CS_SET,
# line 85 "dbInterface.cpp"
CS_OPT_STR_RTRUNC, &_sql->cstrue, CS_UNUSED,
# line 85 "dbInterface.cpp"
NULL);
# line 85 "dbInterface.cpp"
_sql->retcode = CS_SUCCEED;
# line 85 "dbInterface.cpp"
}
# line 85 "dbInterface.cpp"
# line 85 "dbInterface.cpp"
if (_sql->retcode == CS_SUCCEED)
# line 85 "dbInterface.cpp"
{
# line 85 "dbInterface.cpp"
_sql->retcode =
# line 85 "dbInterface.cpp"
ct_options(_sql->conn.connection, CS_SET,
# line 85 "dbInterface.cpp"
CS_OPT_ARITHABORT, &_sql->csfalse,
# line 85 "dbInterface.cpp"
CS_UNUSED, NULL);
# line 85 "dbInterface.cpp"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -