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

📄 occiph.cpp

📁 这是书上的代码
💻 CPP
字号:
// OCCIPH.cpp: implementation of the OCCIPH class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "OCCI2.h"
#include "OCCIPH.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

OCCIPH::OCCIPH(string user, string passwd, string db) throw (SQLException)

{
    env = Environment::createEnvironment (Environment::DEFAULT);
    con = env->createConnection (user, passwd, db);
}// end of constructor occiproc (string, string, string )

OCCIPH::~OCCIPH() throw (SQLException)
{
    env->terminateConnection (con);
    Environment::terminateEnvironment (env);

}
BOOL OCCIPH::callproc(string str_plsql)//Function to call a PL/SQL procedure
{
   
	  /*Statement *stmt = con->createStatement 
      (
	  "DECLARE  v_item_code number(10);"
	  "v_item_descr VARCHAR2(10);"
	  "BEGIN  v_item_code :=231;"
	  "v_item_descr :='Spareparts';"
	  "INSERT INTO author_tab VALUES (v_item_code, v_item_descr);"
	  "END;"
	  );

  */

    BOOL s;
	Statement *stmt = con->createStatement 
      (str_plsql);
   	try
	{
       stmt->executeUpdate();
	   s=TRUE;
	}catch(SQLException ex)
    {
       s=FALSE;
	}
    con->terminateStatement (stmt);
	return s;
 
}


void OCCIPH::callfun()//Function to call a PL/SQL function
{

	 cout << "callfun - invoking a PL/SQL function having IN, OUT and IN/OUT ";
    cout << "parameters" << endl;
    Statement *stmt = con->createStatement 
      ("BEGIN :a := demo_fun(:v1, :v2, :v3); END;");
//    cout << "Executing the block :" << stmt->getSQL() << endl;
    stmt->setInt (2, 10);
    stmt->setString (3, "IN");
    stmt->registerOutParam (1, OCCISTRING, 30, "");
    stmt->registerOutParam (3, OCCISTRING, 30, "");
    stmt->registerOutParam (4, OCCISTRING, 30, "");
    int updateCount = stmt->executeUpdate ();
    cout << "Update Count : " << updateCount << endl;

    string c1 = stmt->getString (1);
    string c2 = stmt->getString (3);
    string c3 = stmt->getString (4);

    cout << "Printing the INOUT & OUT parameters :" << endl;
//    cout << "Col2:" << c2 << " Col3:" << c3 << endl;
    cout << "Printing the return value of the function :";
//    cout << c1 << endl;

    con->terminateStatement (stmt);
    cout << "occifun - done" << endl;


}

⌨️ 快捷键说明

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