⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ocitest.cpp

📁 oci函数批量插入数据
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ocitest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "string.h"
#include "windows.h"
#include <oci.h>

#define ROW_COUNT 1
#define MAX_LEN 2*1024

#define in1_SIZE 12
#define in2_SIZE 2
#define in3_SIZE 12
#define in4_SIZE 4
#define in5_SIZE 4
#define in6_SIZE 30
#define in7_SIZE 3
#define in8_SIZE 4
#define in9_SIZE 16
#define in10_SIZE 4
#define in11_SIZE 4
#define in12_SIZE 4
#define in13_SIZE 4
#define in14_SIZE 4
#define in15_SIZE 16
#define in16_SIZE 4
#define in17_SIZE 30
#define in18_SIZE 4
#define in19_SIZE 16
#define in20_SIZE 4
#define in21_SIZE 30
#define in22_SIZE 16
#define in23_SIZE 4
#define in24_SIZE 30
#define in25_SIZE 17
#define in26_SIZE 6
#define in27_SIZE 80
#define in28_SIZE 30
#define in29_SIZE 30
#define in30_SIZE 8
#define in31_SIZE 4
#define in32_SIZE 4
#define in33_SIZE 4
#define in34_SIZE 4
#define in35_SIZE 2
#define in36_SIZE 2
#define in37_SIZE 10
#define in38_SIZE 1

//char c1[ROW_COUNT][C1_SIZE];
static text  in1[ROW_COUNT][in1_SIZE+1];                /* for CHAR(12)     */
static text  in2[ROW_COUNT][in2_SIZE+1];
static text  in3[ROW_COUNT][in3_SIZE+1];
static int   in4[ROW_COUNT];
static text  in5[ROW_COUNT][in5_SIZE+1];
static text  in6[ROW_COUNT][in6_SIZE+1];
static text  in7[ROW_COUNT][in7_SIZE+1];
static int   in8[ROW_COUNT];
static text  in9[ROW_COUNT][in9_SIZE+1];
static int   in10[ROW_COUNT];
static int   in11[ROW_COUNT];
static int   in12[ROW_COUNT];
static int   in13[ROW_COUNT];
static int   in14[ROW_COUNT];
static text  in15[ROW_COUNT][in15_SIZE+1];
static int   in16[ROW_COUNT];
static text  in17[ROW_COUNT][in17_SIZE+1];
static int   in18[ROW_COUNT];
static text  in19[ROW_COUNT][in19_SIZE+1];
static int   in20[ROW_COUNT];
static text  in21[ROW_COUNT][in21_SIZE+1];
static text  in22[ROW_COUNT][in22_SIZE+1];
static int   in23[ROW_COUNT];
static text  in24[ROW_COUNT][in24_SIZE+1];
static text  in25[ROW_COUNT][in25_SIZE+1];
static text  in26[ROW_COUNT][in26_SIZE+1];
static text  in27[ROW_COUNT][in27_SIZE+1];
static text  in28[ROW_COUNT][in28_SIZE+1];
static text  in29[ROW_COUNT][in29_SIZE+1];
static text  in30[ROW_COUNT][in30_SIZE+1];
static int   in31[ROW_COUNT];
static text  in32[ROW_COUNT][in32_SIZE+1];
static int   in33[ROW_COUNT];
static text  in34[ROW_COUNT][in34_SIZE+1];
static text  in35[ROW_COUNT][in35_SIZE+1];
static text  in36[ROW_COUNT][in36_SIZE+1];
static text  in37[ROW_COUNT][in37_SIZE+1];
static text  in38[ROW_COUNT][in38_SIZE+1];

static const int ERRBUF_LEN = 512;



static sword bind_pos(OCIStmt *stmthp, OCIBind *bndhp[], OCIError *errhp)
{
	if (OCIBindByPos(stmthp, &bndhp[0], errhp, (ub4) 1,
		(dvoid *) in1, (sb4) sizeof(in1[0])-1, SQLT_AFC,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[1], errhp, (ub4) 2,
		(dvoid *) in2, (sb4) sizeof(in2[0])-1, SQLT_AFC,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[2], errhp, (ub4) 3,
		(dvoid *) in3, (sb4) sizeof(in3[0])-1, SQLT_CHR,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[3], errhp, (ub4) 4,
		(dvoid *) in4, (sb4) sizeof(in4[0]), SQLT_INT,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[4], errhp, (ub4) 5,
		(dvoid *) in5, (sb4) sizeof(in5[0])-1, SQLT_AFC,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[5], errhp, (ub4) 6,
		(dvoid *) in6, (sb4) sizeof(in6[0])-1, SQLT_CHR,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[6], errhp, (ub4) 7,
		(dvoid *) in7, (sb4) sizeof(in7[0])-1, SQLT_AFC,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[7], errhp, (ub4) 8,
		(dvoid *) in8, (sb4) sizeof(in8[0]), SQLT_INT,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[8], errhp, (ub4) 9,
		(dvoid *) in9, (sb4) sizeof(in9[0])-1, SQLT_AFC,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[9], errhp, (ub4) 10,
		(dvoid *) in10, (sb4) sizeof(in10[0]), SQLT_INT,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[10], errhp, (ub4) 11,
		(dvoid *) in11, (sb4) sizeof(in11[0]), SQLT_INT,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[11], errhp, (ub4) 12,
		(dvoid *) in12, (sb4) sizeof(in12[0]), SQLT_INT,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[12], errhp, (ub4) 13,
		(dvoid *) in13, (sb4) sizeof(in13[0]), SQLT_INT,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[13], errhp, (ub4) 14,
		(dvoid *) in14, (sb4) sizeof(in14[0]), SQLT_INT,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[14], errhp, (ub4) 15,
		(dvoid *) in15, (sb4) sizeof(in15[0])-1, SQLT_CHR,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[15], errhp, (ub4) 16,
		(dvoid *) in16, (sb4) sizeof(in16[0]), SQLT_INT,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[16], errhp, (ub4) 17,
		(dvoid *) in17, (sb4) sizeof(in17[0])-1, SQLT_CHR,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[17], errhp, (ub4) 18,
		(dvoid *) in18, (sb4) sizeof(in18[0]), SQLT_INT,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[18], errhp, (ub4) 19,
		(dvoid *) in19, (sb4) sizeof(in19[0])-1, SQLT_CHR,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[19], errhp, (ub4) 20,
		(dvoid *) in20, (sb4) sizeof(in20[0]), SQLT_INT,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[20], errhp, (ub4) 21,
		(dvoid *) in21, (sb4) sizeof(in21[0])-1, SQLT_CHR,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[21], errhp, (ub4) 22,
		(dvoid *) in22, (sb4) sizeof(in22[0])-1, SQLT_CHR,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[22], errhp, (ub4) 23,
		(dvoid *) in23, (sb4) sizeof(in23[0]), SQLT_INT,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[23], errhp, (ub4) 24,
		(dvoid *) in24, (sb4) sizeof(in24[0])-1, SQLT_CHR,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[24], errhp, (ub4) 25,
		(dvoid *) in25, (sb4) sizeof(in25[0])-1, SQLT_AFC,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[25], errhp, (ub4) 26,
		(dvoid *) in26, (sb4) sizeof(in26[0])-1, SQLT_AFC,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[26], errhp, (ub4) 27,
		(dvoid *) in27, (sb4) sizeof(in27[0])-1, SQLT_CHR,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[27], errhp, (ub4) 28,
		(dvoid *) in28, (sb4) sizeof(in28[0])-1, SQLT_CHR,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[28], errhp, (ub4) 29,
		(dvoid *) in29, (sb4) sizeof(in29[0])-1, SQLT_CHR,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[29], errhp, (ub4) 30,
		(dvoid *) in30, (sb4) sizeof(in30[0])-1, SQLT_AFC,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[30], errhp, (ub4) 31,
		(dvoid *) in31, (sb4) sizeof(in31[0]), SQLT_INT,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[31], errhp, (ub4) 32,
		(dvoid *) in32, (sb4) sizeof(in32[0])-1, SQLT_AFC,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[32], errhp, (ub4) 33,
		(dvoid *) in33, (sb4) sizeof(in33[0]), SQLT_INT,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[33], errhp, (ub4) 34,
		(dvoid *) in34, (sb4) sizeof(in34[0])-1, SQLT_AFC,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[34], errhp, (ub4) 35,
		(dvoid *) in35, (sb4) sizeof(in35[0])-1, SQLT_AFC,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[35], errhp, (ub4) 36,
		(dvoid *) in36, (sb4) sizeof(in36[0])-1, SQLT_AFC,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[36], errhp, (ub4) 37,
		(dvoid *) in37, (sb4) sizeof(in37[0])-1, SQLT_AFC,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
		|| OCIBindByPos(stmthp, &bndhp[37], errhp, (ub4) 38,
		(dvoid *) in38, (sb4) sizeof(in38[0])-1, SQLT_AFC,
		(dvoid *) 0, (ub2 *)0, (ub2 *)0,
		(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT))
	{
		return OCI_ERROR;
	}

	return OCI_SUCCESS;
}

static sword bind_array(OCIBind *bndhp[], OCIError *errhp)
{
	if (OCIBindArrayOfStruct(bndhp[0], errhp, (ub4) sizeof(in1[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[1], errhp, (ub4) sizeof(in2[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[2], errhp, (ub4) sizeof(in3[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[3], errhp, (ub4) sizeof(in4[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[4], errhp, (ub4) sizeof(in5[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[5], errhp, (ub4) sizeof(in6[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[6], errhp, (ub4) sizeof(in8[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[7], errhp, (ub4) sizeof(in8[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[8], errhp, (ub4) sizeof(in9[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[9], errhp, (ub4) sizeof(in10[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[10], errhp, (ub4) sizeof(in11[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[11], errhp, (ub4) sizeof(in12[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[12], errhp, (ub4) sizeof(in13[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[13], errhp, (ub4) sizeof(in14[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[14], errhp, (ub4) sizeof(in15[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[15], errhp, (ub4) sizeof(in16[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[16], errhp, (ub4) sizeof(in17[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[17], errhp, (ub4) sizeof(in18[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[18], errhp, (ub4) sizeof(in19[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[19], errhp, (ub4) sizeof(in20[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[20], errhp, (ub4) sizeof(in21[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[21], errhp, (ub4) sizeof(in22[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[22], errhp, (ub4) sizeof(in23[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[23], errhp, (ub4) sizeof(in24[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[24], errhp, (ub4) sizeof(in25[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[25], errhp, (ub4) sizeof(in26[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[26], errhp, (ub4) sizeof(in27[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[27], errhp, (ub4) sizeof(in28[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[28], errhp, (ub4) sizeof(in29[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[29], errhp, (ub4) sizeof(in30[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[30], errhp, (ub4) sizeof(in31[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[31], errhp, (ub4) sizeof(in32[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[32], errhp, (ub4) sizeof(in33[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[33], errhp, (ub4) sizeof(in34[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[34], errhp, (ub4) sizeof(in35[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[35], errhp, (ub4) sizeof(in36[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[36], errhp, (ub4) sizeof(in37[0]), 0, 0, 0)
		|| OCIBindArrayOfStruct(bndhp[37], errhp, (ub4) sizeof(in38[0]), 0, 0, 0))
	{
		return OCI_ERROR;
	}

	return OCI_SUCCESS;
}

void getdata( int nIndex )
{
	for (int i = 0; i < ROW_COUNT; i++)
	{		
		//memset(in1[i], 0x00, 12);//(size_t) in1_SIZE);
		memset(in1[i], (int) 'A', (size_t) in1_SIZE);
		in1[i][in1_SIZE] = '\0';

		/*char * pSql = new char[MAX_LEN];
		memset(pSql, 0, MAX_LEN);

		const char *sqlstr = "INSERT INTO LGJ VALUES('%s')";

		sprintf(pSql, sqlstr, in1[0]);

		delete [] pSql;*/
		memset((void *)in2[i], (int) 'B', (size_t) in2_SIZE);
		in2[i][in2_SIZE] = '\0';
		memset((void *)in3[i], (int) 'C', (size_t) in3_SIZE);
		in3[i][in3_SIZE] = '\0';
		in3[i][in3_SIZE-1] = '\0';
		in4[i] = 4 + i;
		memset((void *)in5[i], (int) 'D', (size_t) in5_SIZE);
		in5[i][in5_SIZE] = '\0';
		memset((void *)in6[i], (int) 'E', (size_t) in6_SIZE);
		in6[i][in6_SIZE] = '\0';
		in6[i][in6_SIZE-1] = '\0';
		memset((void *)in7[i], (int) 'F', (size_t) in7_SIZE);
		in7[i][in7_SIZE] = '\0';
		in8[i] = 8 + i;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -