📄 dbclass.~cpp
字号:
/* Result Sets Interface */
#ifndef SQL_CRSR
# define SQL_CRSR
struct sql_cursor
{
unsigned int curocn;
void *ptr1;
void *ptr2;
unsigned long magic;
};
typedef struct sql_cursor sql_cursor;
typedef struct sql_cursor SQL_CURSOR;
#endif /* SQL_CRSR */
/* Thread Safety */
typedef void * sql_context;
typedef void * SQL_CONTEXT;
/* Object support */
struct sqltvn
{
unsigned char *tvnvsn;
unsigned short tvnvsnl;
unsigned char *tvnnm;
unsigned short tvnnml;
unsigned char *tvnsnm;
unsigned short tvnsnml;
};
typedef struct sqltvn sqltvn;
struct sqladts
{
unsigned int adtvsn;
unsigned short adtmode;
unsigned short adtnum;
sqltvn adttvn[1];
};
typedef struct sqladts sqladts;
static struct sqladts sqladt = {
1,1,0,
};
/* Binding to PL/SQL Records */
struct sqltdss
{
unsigned int tdsvsn;
unsigned short tdsnum;
unsigned char *tdsval[1];
};
typedef struct sqltdss sqltdss;
static struct sqltdss sqltds =
{
1,
0,
};
/* File name & Package Name */
struct sqlcxp
{
unsigned short fillen;
char filnam[53];
};
static const struct sqlcxp sqlfpn =
{
52,
"E:\\方炜\\测试代码\\测试oracle批量插入\\test2\\dbclass.pc"
};
static unsigned long sqlctx = 2079789053;
static struct sqlexd {
unsigned int sqlvsn;
unsigned int arrsiz;
unsigned int iters;
unsigned int offset;
unsigned short selerr;
unsigned short sqlety;
unsigned int occurs;
const short *cud;
unsigned char *sqlest;
const char *stmt;
sqladts *sqladtp;
sqltdss *sqltdsp;
void **sqphsv;
unsigned int *sqphsl;
int *sqphss;
void **sqpind;
int *sqpins;
unsigned int *sqparm;
unsigned int **sqparc;
unsigned short *sqpadto;
unsigned short *sqptdso;
void *sqhstv[22];
unsigned int sqhstl[22];
int sqhsts[22];
void *sqindv[22];
int sqinds[22];
unsigned int sqharm[22];
unsigned int *sqharc[22];
unsigned short sqadto[22];
unsigned short sqtdso[22];
} sqlstm = {10,22};
/* SQLLIB Prototypes */
extern "C" {
void sqlcxt (void **, unsigned long *,
struct sqlexd *, const struct sqlcxp *);
void sqlcx2t(void **, unsigned long *,
struct sqlexd *, const struct sqlcxp *);
void sqlbuft(void **, char *);
void sqlgs2t(void **, char *);
void sqlorat(void **, unsigned long *, void *);
}
/* Forms Interface */
static const int IAPSUCC = 0;
static const int IAPFAIL = 1403;
static const int IAPFTL = 535;
extern void sqliem(char *, int *);
typedef struct { unsigned short len; unsigned char arr[1]; } VARCHAR;
typedef struct { unsigned short len; unsigned char arr[1]; } varchar;
/* cud (compilation unit data) array */
static const short sqlcud0[] =
{10,4130,0,0,0,
5,0,0,1,0,0,30,86,0,0,0,0,0,1,0,
20,0,0,2,310,0,3,171,0,0,22,22,0,1,0,1,97,0,0,1,97,0,0,1,97,0,0,1,97,0,0,1,97,
0,0,1,97,0,0,1,97,0,0,1,97,0,0,1,97,0,0,1,97,0,0,1,97,0,0,1,97,0,0,1,97,0,0,1,
97,0,0,1,97,0,0,1,97,0,0,1,97,0,0,1,97,0,0,1,97,0,0,1,97,0,0,1,97,0,0,1,97,0,0,
123,0,0,3,0,0,29,177,0,0,0,0,0,1,0,
138,0,0,4,0,0,31,184,0,0,0,0,0,1,0,
};
#define SQLCA_STORAGE_CLASS extern
/* EXEC SQL INCLUDE ora_context.pch;
*/
#ifndef ORA_CONTEXT_H
#define ORA_CONTEXT_H
#define SQLCA_STORAGE_CLASS extern
/* EXEC SQL INCLUDE SQLCA;
*/
/*
* $Header: sqlca.h,v 1.3 1994/12/12 19:27:27 jbasu Exp $ sqlca.h
*/
/* Copyright (c) 1985,1986, 1998 by Oracle Corporation. */
/*
NAME
SQLCA : SQL Communications Area.
FUNCTION
Contains no code. Oracle fills in the SQLCA with status info
during the execution of a SQL stmt.
NOTES
**************************************************************
*** ***
*** This file is SOSD. Porters must change the data types ***
*** appropriately on their platform. See notes/pcport.doc ***
*** for more information. ***
*** ***
**************************************************************
If the symbol SQLCA_STORAGE_CLASS is defined, then the SQLCA
will be defined to have this storage class. For example:
#define SQLCA_STORAGE_CLASS extern
will define the SQLCA as an extern.
If the symbol SQLCA_INIT is defined, then the SQLCA will be
statically initialized. Although this is not necessary in order
to use the SQLCA, it is a good pgming practice not to have
unitialized variables. However, some C compilers/OS's don't
allow automatic variables to be init'd in this manner. Therefore,
if you are INCLUDE'ing the SQLCA in a place where it would be
an automatic AND your C compiler/OS doesn't allow this style
of initialization, then SQLCA_INIT should be left undefined --
all others can define SQLCA_INIT if they wish.
If the symbol SQLCA_NONE is defined, then the SQLCA variable will
not be defined at all. The symbol SQLCA_NONE should not be defined
in source modules that have embedded SQL. However, source modules
that have no embedded SQL, but need to manipulate a sqlca struct
passed in as a parameter, can set the SQLCA_NONE symbol to avoid
creation of an extraneous sqlca variable.
MODIFIED
lvbcheng 07/31/98 - long to int
jbasu 12/12/94 - Bug 217878: note this is an SOSD file
losborne 08/11/92 - No sqlca var if SQLCA_NONE macro set
Clare 12/06/84 - Ch SQLCA to not be an extern.
Clare 10/21/85 - Add initialization.
Bradbury 01/05/86 - Only initialize when SQLCA_INIT set
Clare 06/12/86 - Add SQLCA_STORAGE_CLASS option.
*/
#ifndef SQLCA
#define SQLCA 1
struct sqlca
{
/* ub1 */ char sqlcaid[8];
/* b4 */ int sqlabc;
/* b4 */ int sqlcode;
struct
{
/* ub2 */ unsigned short sqlerrml;
/* ub1 */ char sqlerrmc[70];
} sqlerrm;
/* ub1 */ char sqlerrp[8];
/* b4 */ int sqlerrd[6];
/* ub1 */ char sqlwarn[8];
/* ub1 */ char sqlext[8];
};
#ifndef SQLCA_NONE
#ifdef SQLCA_STORAGE_CLASS
SQLCA_STORAGE_CLASS struct sqlca sqlca
#else
struct sqlca sqlca
#endif
#ifdef SQLCA_INIT
= {
{'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '},
sizeof(struct sqlca),
0,
{ 0, {0}},
{'N', 'O', 'T', ' ', 'S', 'E', 'T', ' '},
{0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
}
#endif
;
#endif
#endif
/* end SQLCA */
//multi msg wont exceed this length
#define MAX_MULTI_MSG_LENGTH 800
#define MAX_MSG_BUFFER_LENGTH 800
#define ERR_UNKNOWN -1
#define ERR_SELECT_NONE -2
#define ERR_PART_COMPLETE -3
//here this error means the datebase can not connect for a while but it can be recover soon
#define ERR_DB_NOT_CONNECTED -4
//here we define the two error a number to simplify the processing
#define ERR_DBEXCEPTION -4
#define ERR_NO_MORE_RECORDS -5
#define ERR_SOME_FIELD_NULL -6
#define ERR_PARAM -7
#define ERR_CONTENT_TOO_LONG -8
#define ERR_RECORDSET_NOT_OPENED -9
#define ERR_SERVER_DATA -10
#define ERR_SERVER -11
#define ERR_NO_FLOAT -12
//when we handled the error we plus it to the original error code
#define ERR_HANDLED -1000
class ora_context
{
protected:
/* EXEC SQL BEGIN DECLARE SECTION; */
struct sqlca sqlca;
sql_context m_context;
/* EXEC SQL END DECLARE SECTION; */
// int m_error_flag;
public:
ora_context(char* classname,int threadid);
virtual ~ora_context();
void on_error(void);
virtual void log_error(char* err_log){};
int conn_db(char* user,char* pwd,char* conn);
int DisplayConvertInGUI(char *info);
int errorlogwrite (char *log_name,const char *data);
int convert_error_flag ;
int convert_Connected_Database;
int convert_display;
char convert_log_name[256] ;
protected:
char m_context_name[40];
int m_threadid;
char m_CurrentDir[256];
};
#endif
#include <system.hpp>
#include <mem.h>
#include <sys\types.h>
#include <time.h>
#include "GlobalVar.h"
//#include "GlobalFunctions.h"
#include "dbclass.h"
CDbClass::CDbClass(char* classname,int threadid):ora_context(classname,threadid)
{
}
int CDbClass::CONVERT_DB_CONNECT(char* user,char* pwd,char* con)
{
char db_connect_log[100];
convert_error_flag = 0;
int ret = conn_db(user,pwd,con);
if(ret == 0)
{
sprintf(db_connect_log,"数据库连接成功");
DisplayConvertInGUI(db_connect_log);
errorlogwrite(convert_log_name,db_connect_log);
convert_Connected_Database = DATABASE_STATUS_CONNECTED;
return 0;
}
else
{
sprintf(db_connect_log,"数据库连接失败" );
DisplayConvertInGUI(db_connect_log);
errorlogwrite(convert_log_name,db_connect_log);
return -1;
}
}
int CDbClass::CONVERT_DB_CONNECT()
{
char db_connect_log[100];
char convert_user[20];
char convert_passwd[20];
char convert_conn[20];
convert_error_flag = 0;
memset(convert_user,0,sizeof(convert_user));
memset(convert_passwd,0,sizeof(convert_passwd));
memset(convert_conn,0,sizeof(convert_conn));
char cIniFile[256];
GetCurrentDirectory(256,cIniFile);
strcat(cIniFile,VNSMS_INI_FILE);
GetPrivateProfileString("Database","db_user","vnsms",convert_user,20,cIniFile);
GetPrivateProfileString("Database","db_pwd","vnsms133",convert_passwd,20,cIniFile);
GetPrivateProfileString("Database","db_sid","vnsms",convert_conn,20,cIniFile);
int ret = conn_db(convert_user,convert_passwd,convert_conn);
if(ret == 0)
{
sprintf(db_connect_log,"数据库连接成功");
DisplayConvertInGUI(db_connect_log);
errorlogwrite(convert_log_name,db_connect_log);
convert_Connected_Database = DATABASE_STATUS_CONNECTED;
return 0;
}
else
{
sprintf(db_connect_log,"数据库连接失败" );
DisplayConvertInGUI(db_connect_log);
errorlogwrite(convert_log_name,db_connect_log);
return -1;
}
}
int CDbClass::convert_Discont_db()
{
/* EXEC SQL CONTEXT USE :m_context; */
/* EXEC SQL WHENEVER SQLERROR CONTINUE; */
/* EXEC SQL COMMIT WORK RELEASE; */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -