在犰狳 c++ 中,我使用了一些 api 并使用 oracle occi 尝试将值插入到 oracle 表中,但是我得到了一些像这样的错误:-
/home/oracle/Desktop/project/armadillo-4.450.4/include/armadillo_bits/typedef_elem.hpp:79: error: typedef arma::s32 arma::sword
/usr/include/oracle/11.1/client/ociap.h:10830: error: reference to ‘sword’ is ambiguous
/usr/include/oracle/11.1/client/oratypes.h:227: error: candidates are: typedef int sword
我的示例代码是:- main.cpp
#include <stdio.h>
#include <iostream>
#include "db_manager.h"
#include <armadillo>
using namespace arma;
int glbsize;//this variable is global it is declared in global_variables.h
mat glbmtrx;//this variable is global it is declared in global_variables.h
void add()
{
double deter;
int ppp=0;
mat z;
mat x = randu<mat>(4,4);
mat y = randu<mat>(4,4);
z=x+y;
mystruct strct;
strct.mymatrix=z;//variable from comm.structure
glbmtrx=strct.mymatrix;//varible from glb.variables
deter= det(z);
db_manager db;
db.load_determinant(deter);
}
int main()
{
add();
return 0;
}
db_manager.cpp
#include "db_manager.h"
#include <sstream>
#include <iostream>
#include <sstream>
#include <fstream>
using namespace oracle::occi;
using namespace std;
Environment *env;
Connection *con;
void db_manager::load_determinant(double det)
{
mystruct strct;
strct.deter_size=det;//var from comm.structure
string user = "user";
string passwd = "p@$$word";
string db = "localhost:1521/sisdba";
env = Environment::createEnvironment((Environment::Mode)(Environment::OBJECT|Environment::THREADED_MUTEXED));
con = env->createConnection(user, passwd, db);
Statement *stmt = NULL;
ResultSet *rs = NULL;
string concat1="";
concat1=static_cast<ostringstream*>(&(ostringstream()<<det))->str();
string sql="insert into determinanit_table values('"+concat1+"')";
stmt = con->createStatement(sql);
stmt->executeUpdate(sql);
env->terminateConnection (con);
Environment::terminateEnvironment (env);
}
db_manager.h
#include "includes/global_variables.h"
#include <occi.h>
class db_manager
{
public:
db_manager(void);
~db_manager(void);
void load_determinant(double det);
};
common_struct.h
#include <armadillo>
using namespace arma;
using namespace std;
struct mystruct
{
mat mymatrix;
double deter_size;
};
全局变量.h
#include "../includes/common_structures.h"
using namespace arma;
extern int glbsize;
extern mat glbmtrx;
生成文件:
excute:main.o db_manager.o
g++ -o excute main.o db_manager.o \
-I/home/oracle/Desktop/sum_result/armadillo-4.450.4/include -DARMA_USE_BLAS -DARMA_USE_LAPACK -DARMA_DONT_USE_WRAPPER -lblas -llapack \
-I/usr/include/oracle/11.1/client \
-L$(ORACLE_HOME)/lib -lclntsh -locci
%.o: %.cpp
g++ -c -o $@ $< -ggdb \
-I/home/oracle/Desktop/sum_result/armadillo-4.450.4/include -DARMA_USE_BLAS -DARMA_USE_LAPACK -DARMA_DONT_USE_WRAPPER -lblas -llapack \
-I/usr/include/oracle/11.1/client \
-L$(ORACLE_HOME)/lib -lclntsh -locci
clean:
rm *.o excute