基于OCILIB的oracle数据库操作总结及自动生成Model和Dao的工具
基于OCILIB的oracle数据库操作总结
1. 类图
2. 基类BaseOCIDao的设计与实现
BaseOCIDao.h头文件
#pragma once /* --------------------------------------------------------------------------------------------- *
* INCLUDES
* --------------------------------------------------------------------------------------------- */ #include "ocilib.h"
#include <string>
#include <vector>
using namespace std;
/* --------------------------------------------------------------------------------------------- *
* PLATFORMS
* --------------------------------------------------------------------------------------------- */ #ifdef _MSC_VER #if defined(OCI_CHARSET_WIDE)
#pragma comment(lib, "ocilibw.lib")
#elif defined(OCI_CHARSET_ANSI)
#pragma comment(lib, "ociliba.lib")
#endif #endif #ifndef OCI_SHARED_LIB
#if defined(_WINDOWS)
#define OCI_SHARED_LIB "oci.dll"
#elif defined(__APPLE__)
#define OCI_SHARED_LIB "libclntsh.dylib"
#elif defined(__hppa)
#define OCI_SHARED_LIB "libclntsh.sl"
#else
#define OCI_SHARED_LIB "libclntsh.so"
#endif
#endif #define print_frmt(f, x) printf(f, x)
#define print_text(x) printf(x) #if defined(OCI_CHARSET_WIDE)
#ifdef _WINDOWS
#define print_ostr(x) wprintf(OTEXT("%s"), x)
#else
#define print_ostr(x) printf("%ls", x)
#endif
#else
#define print_ostr(x) printf(OTEXT("%s"), x)
#endif class BaseOCIDao
{
protected:
string m_ip;
unsigned int m_port;
string m_inst;
string m_user;
string m_pwd;
unsigned int m_mode; OCI_Statement* m_stmt;
OCI_Connection* m_conn; bool m_useTrans;
bool m_IsConnected;
bool m_ShareConn;
POCI_ERROR m_ErrHandler;
vector<BaseOCIDao*> m_Children;
public:
BaseOCIDao();
BaseOCIDao(string ip,unsigned int port,string inst,string user,string pwd,POCI_ERROR ErrHandler,unsigned int mode=OCI_ENV_DEFAULT);
virtual ~BaseOCIDao(); BOOL Connect(BaseOCIDao* parent);
BOOL AddChildDao(BaseOCIDao* child); BOOL Connect();
BOOL DisConnect(); OCI_Resultset* QuerySql(const char* sql);
BOOL ExecuteSql(const char* sql);
OCI_Statement* PrepareBindStmt(const char* sql);
OCI_Resultset* QueryBindStmt(OCI_Statement *stmt);
BOOL ExecuteBindStmt(OCI_Statement *stmt); BOOL BeginTrans();
BOOL EndTrans();
BOOL Commit();
BOOL Rollback();
};
BaseOCIDao.cpp文件
#include "StdAfx.h"
#include "BaseOCIDao.h" BaseOCIDao::BaseOCIDao(string ip,unsigned int port,string inst,string user,string pwd,POCI_ERROR ErrHandler,unsigned int mode)
{
m_ip = ip;
m_port = port;
m_inst = inst;
m_user = user;
m_pwd = pwd;
m_mode = mode;
m_ErrHandler = ErrHandler;
m_ShareConn = false;
m_IsConnected = false;
m_useTrans = false; m_stmt = NULL;
m_conn = NULL;
} BaseOCIDao::BaseOCIDao()
{
m_ShareConn = false;
m_IsConnected = false;
m_useTrans = false; m_stmt = NULL;
m_conn = NULL;
} BaseOCIDao::~BaseOCIDao()
{
if(m_IsConnected && !m_ShareConn)
DisConnect();
} BOOL BaseOCIDao::Connect(BaseOCIDao* parent)
{
m_ShareConn = true;
return TRUE;
} BOOL BaseOCIDao::Connect()
{
m_ShareConn = false; /* Possible values for parameter mode:
* - OCI_ENV_DEFAULT : default mode
* - OCI_ENV_THREADED : multi-threading support
* - OCI_ENV_CONTEXT : thread contextual error handling
* - OCI_ENV_EVENTS : enables events for subscription, HA Events, AQ notifications
*/ /* INITIALIZE OCI ------------------------------------------------------- */
if (!OCI_Initialize(m_ErrHandler, NULL, m_mode))//the Oracle library is loaded from system environment variables
return EXIT_FAILURE; OCI_EnableWarnings(TRUE);
/* CONNECTION TO SERVER ------------------------------------------------- */
char dbs[];
sprintf_s(dbs,,"(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=%s)(PORT=%d)))(CONNECT_DATA=(SERVICE_NAME=%s)))",m_ip.c_str(),m_port,m_inst.c_str());
m_conn = OCI_ConnectionCreate(dbs, m_user.c_str(), m_pwd.c_str(), OCI_SESSION_DEFAULT);
if(m_conn!=NULL)
{
OCI_SetAutoCommit(m_conn,FALSE);
m_IsConnected = true; for (vector<BaseOCIDao*>::iterator itr = m_Children.begin();
itr!=m_Children.end(); itr++)
{
(*itr)->Connect(this);
} return EXIT_SUCCESS;
}
else
{
print_ostr(OCI_ErrorGetString(OCI_GetLastError()));
return EXIT_FAILURE;
}
} BOOL BaseOCIDao::DisConnect()
{
if(m_conn!=NULL)
{
if(OCI_ConnectionFree(m_conn))
{
print_ostr(OCI_ErrorGetString(OCI_GetLastError()));
OCI_Cleanup();
return TRUE;
}
else
{
print_ostr(OCI_ErrorGetString(OCI_GetLastError()));
return FALSE;
}
}
else
return FALSE;
} BOOL BaseOCIDao::AddChildDao(BaseOCIDao* child)
{
if(child!=NULL)
m_Children.push_back(child);
return TRUE;
} OCI_Statement* BaseOCIDao::PrepareBindStmt(const char* sql)
{
if(!m_IsConnected) return NULL;
m_stmt = OCI_StatementCreate(m_conn);
OCI_Prepare(m_stmt,sql);
return m_stmt;
} OCI_Resultset* BaseOCIDao::QuerySql(const char* sql)
{
if(!m_IsConnected) return NULL;
m_stmt = OCI_StatementCreate(m_conn);
OCI_ExecuteStmt(m_stmt,sql);
return OCI_GetResultset(m_stmt);
} OCI_Resultset* BaseOCIDao::QueryBindStmt(OCI_Statement *stmt)
{
if(!m_IsConnected) return NULL;
OCI_Execute(stmt);
return OCI_GetResultset(stmt);
} BOOL BaseOCIDao::ExecuteSql(const char* sql)
{
if(!m_IsConnected) return FALSE;
m_stmt = OCI_StatementCreate(m_conn);
BOOL flag = OCI_ExecuteStmt(m_stmt,sql);
if(!m_useTrans && !m_ShareConn)
{
if(flag)
OCI_Commit(m_conn);
else
OCI_Rollback(m_conn);
}
return flag;
} BOOL BaseOCIDao::ExecuteBindStmt(OCI_Statement *stmt)
{
if(!m_IsConnected) return FALSE;
BOOL flag = OCI_Execute(stmt);
if(!m_useTrans && !m_ShareConn)
{
if(flag)
OCI_Commit(m_conn);
else
OCI_Rollback(m_conn);
}
return flag;
} BOOL BaseOCIDao::BeginTrans()
{
if(!m_IsConnected) return FALSE;
m_useTrans = true;
return TRUE;
} BOOL BaseOCIDao::EndTrans()
{
if(!m_IsConnected || !m_useTrans) return FALSE;
m_useTrans = false;
return TRUE;
} BOOL BaseOCIDao::Commit()
{
if(!m_IsConnected || !m_useTrans) return FALSE;
return OCI_Commit(m_conn);
} BOOL BaseOCIDao::Rollback()
{
if(!m_IsConnected || !m_useTrans) return FALSE;
return OCI_Rollback(m_conn);
}
3. 继承实体类的使用
3.1 BaseModel定义
BaseModel
#pragma once
#include <string>
using namespace std;
class BaseModel{
public:
BaseModel(){}
virtual ~BaseModel(){}
};
3.2 例子
Model定义
#pragma once #include "BaseModel.h"
#include <string>
using namespace std; #define NameSize 100
class TDao;
class TModel : BaseModel{
friend TDao;
protected:
int m_ID;
char m_Name[NameSize];
public:
TModel(){
m_ID = ;
memset(m_Name,,NameSize);
}
TModel(const TModel& obj)
{
m_ID = obj.GetID();
SetName(obj.GetName());
} TModel& operator = (const TModel& obj)
{
if(this == &obj) return *this;
m_ID = obj.GetID();
return *this;
}
~TModel()
{ } void SetID(int ID)
{
m_ID = ID;
} int GetID() const
{
return m_ID;
}
void SetName(string Name)
{
strcpy_s(m_Name,NameSize,Name.c_str());
} string GetName() const
{
return m_Name;
}
};
Dao定义
#include "BaseOCIDao.h"
class TDao:BaseOCIDao
{
public:
TDao(){}
TDao(string ip,unsigned int port,string inst,string user,string pwd,POCI_ERROR ErrHandler,unsigned int mode):
BaseOCIDao(ip,port,inst,user,pwd,ErrHandler,mode)
{ }
~TDao(){} BOOL Insert(TModel* model)
{
char* sql = "insert into TabName(id,name) values (:id,:name)";
OCI_Statement* stmt = PrepareBindStmt(sql); OCI_BindInt(stmt,":id",&model->m_ID);
OCI_BindString(stmt,":name",model->m_Name,NameSize);
return ExecuteBindStmt(stmt);
} BOOL Update(TModel* model)
{
char* sql = "update TabName set name=:name where id=:id";
OCI_Statement* stmt = PrepareBindStmt(sql); OCI_BindInt(stmt,":id",&model->m_ID);
OCI_BindString(stmt,":name",model->m_Name,NameSize);
return ExecuteBindStmt(stmt);
} BOOL Delete(string cond)
{
string sql = "delete from TabName";
if(cond!="")
sql+=" where " + cond; return ExecuteSql(sql.c_str());
} vector<TModel*> Select(string cond)
{
vector<TModel*> resVec;
string sql = "select id,name from TabName";
if(cond!="")
sql+=" where " + cond; OCI_Resultset* rs = QuerySql(sql.c_str());
while(OCI_FetchNext(rs))
{
TModel *model = new TModel();
model->SetID(OCI_GetInt(rs,));
model->SetName(OCI_GetString(rs,));
resVec.push_back(model);
}
return resVec;
} BOOL Exist(TModel* model)
{
char* sql = "select id from TabName where name=:name";
OCI_Statement* stmt = PrepareBindStmt(sql);
OCI_BindString(stmt,":name",model->m_Name,NameSize);
OCI_Resultset* rs = QueryBindStmt(stmt);
if(OCI_FetchNext(rs))
{
model->SetID(OCI_GetInt(rs,));
return TRUE;
}
else
return FALSE;
}
};
DaoFactory定义
void err_handler(OCI_Error *err)
{
int err_type = OCI_ErrorGetType(err); print_text("\n"); if (err_type == OCI_ERR_WARNING)
{
print_text("> WARNING : ");
}
else
{
print_text("> ERROR : ");
} print_ostr(OCI_ErrorGetString(err));
print_text("\n");
}
class DaoFactory{
private:
string m_ip;
unsigned int m_port;
string m_inst;
string m_user;
string m_pwd;
unsigned int m_mode;
private:
DaoFactory(){
m_ip = "127.0.0.1";
m_port = ;
m_inst = "orcl";
m_user = "user";
m_pwd = "password";
m_mode = OCI_ENV_DEFAULT;
}
public:
static DaoFactory* GetInstance()
{
static DaoFactory factory;
return &factory;
}
~DaoFactory(){}
public:
TDao* CreateTDao()
{
TDao* dao = new TDao(m_ip,m_port,m_inst,m_user,m_pwd,err_handler,m_mode);
return dao;
}
};
简单情况
- 使用DaoFactory创建dao对象 dao
- 打开数据库连接 dao->Connect
- 执行搜索或增删改操作 dao->Select dao->Insert ….
- 关闭数据库连接 dao->DisConnect
- 删除dao对象 delete dao;
更复杂的情况
共享数据库连接进行查询
- 使用DaoFactory创建两个dao对象:DaoParent, DaoChild;
- DaoParent->AddChildDao(DaoChild);
- 打开数据库连接DaoParent->Connect();
- 搜索 DaoParent->Select();DaoChild->Select();
- 关闭数据库连接 DaoParent->DisConnect();
- 删除dao对象内存;delete DaoChild; delete DaoParent;
共享数据库事务,进行增删改操作
- 使用DaoFactory创建两个dao对象:DaoParent, DaoChild;
- DaoParent->AddChildDao(DaoChild);
- 打开数据库连接DaoParent->Connect();
- 打开事务 DaoParent-> BeginTrans
- 执行增删改操作 DaoParent->Insert();DaoChild->Update();。。。
- 提交或回滚事务 DaoParent-> Commit DaoParent-> Rollback
- 关闭事务 DaoParent-> EndTrans
- 关闭数据库连接 DaoParent->DisConnect();
- 删除dao对象内存;delete DaoChild; delete DaoParent;
4. 自动生成Model和Dao的工具设计
工具从输入流中读入一组规定格式的数据,按照此数据构建Model和Dao类代码。
输入内容格式规定
类名
数据库表名
字段个数N
字段1 类型1 数据库字段名1
…
字段N 类型N 数据库字段名N
支持的类型
类型 |
真实类型 |
数据库对应类型 |
int |
int |
number(10) |
unsigned int |
unsigned int |
number(10) |
short |
short |
number(5) |
unsigned short |
unsigned short |
number(5) |
float |
float |
binary_float |
double |
double |
binary_double |
string |
char[] |
varchar2() |
big_int |
long long |
number(14) |
big_uint |
unsigned long long |
number(14) |
例子:
User类有3个字段,ID,Name,Pwd
可输入如下:
User
UserTable
3
ID unsigned int ID
Name string Name
Pwd string Pwd
自动生成工具根据BaseMode和BaseOCIDao生成,可根据需要将生成后的Model和Dao进行修改。对于stirng类型的数据,自动生成Model后,可修改xxxSize宏,设置string类型字段的长度。
自动生成Model和Dao的工具AutoGenModelDao
AutoGenModelDao.h
#pragma once
#include <iostream>
#include <string>
#include <vector>
#include <iostream>
using namespace std; typedef struct FieldType
{
string Field;
string FType;//string,int,unsigned int, short,unsigned short,float,double,big_int,big_uint
string DBField;
friend istream& operator >> (istream& myin,FieldType& obj)
{
myin>>obj.Field;
myin>>obj.FType;
if(obj.FType=="unsigned")
{
string tmp;
myin>>tmp;
obj.FType = obj.FType+" "+tmp;
}
myin>>obj.DBField;
return myin;
}
}FieldType; class AutoGenModelDao
{
private:
string m_ModelClass;
string m_DaoClass;
string m_DBTable;
string m_OutputDir;
vector<FieldType> m_Fields;
public:
AutoGenModelDao();
~AutoGenModelDao(); void AutoGen(istream& myin);
private:
void GenModelHeader();
ostream& GenConstructFun(ostream& myout);
ostream& GenGetSetFun(ostream& myout);
void GenModelBody();
private:
void GenDaoHeader();
void GenDaoBody();
ostream& GenInsertFun(ostream& myout);
ostream& GenInsertBatchFun(ostream& myout);
ostream& GenUpdateFun(ostream& myout);
ostream& GenUpdateBatchFun(ostream& myout);
ostream& GenDeleteFun(ostream& myout);
ostream& GenSelectFun(ostream& myout);
ostream& GenExistFun(ostream& myout);
};
AutoGenModelDao.cpp
#include "StdAfx.h"
#include "AutoGenModelDao.h"
#include <iostream>
#include <fstream>
using namespace std; AutoGenModelDao::AutoGenModelDao(void)
{
} AutoGenModelDao::~AutoGenModelDao(void)
{
} void AutoGenModelDao::AutoGen(istream& myin)
{
m_OutputDir = "..\\output";
string className;
myin>>className;//ClassName
m_ModelClass = className+"Model";
m_DaoClass = className+"Dao";
myin>>m_DBTable;
int fieldLen;
myin>>fieldLen;
m_Fields.clear();
for (int i=;i<fieldLen;i++)
{
FieldType field;
myin>>field;
m_Fields.push_back(field);
} GenModelHeader();
GenModelBody();
GenDaoHeader();
GenDaoBody();
} void AutoGenModelDao::GenModelHeader()
{
int strsize = ;
string file = m_OutputDir+"\\"+m_ModelClass+".h";
ofstream myout(file.c_str(),ios::out);
myout<<"#pragma once"<<endl;
myout<<"#include \"BaseModel.h\""<<endl;
myout<<"#include <string>"<<endl;
myout<<"using namespace std;"<<endl; myout<<endl;
//build #define string size
for (vector<FieldType>::iterator itr = m_Fields.begin();
itr != m_Fields.end(); itr++)
{
if(itr->FType == "string")
myout<<"#define "<<itr->Field<<"Size "<<strsize<<endl;
}
myout<<endl;
myout<<"class "<<m_DaoClass<<";"<<endl;
myout<<"class "<<m_ModelClass<<" : BaseModel{"<<endl;
myout<<"friend "<<m_DaoClass<<";"<<endl; myout<<"protected:"<<endl;
for (vector<FieldType>::iterator itr = m_Fields.begin();
itr != m_Fields.end(); itr++)
{
if(itr->FType == "string")
myout<<"\t char m_"<<itr->Field<<"["<<itr->Field<<"Size];"<<endl;
else
myout<<"\t "<<itr->FType<<" m_"<<itr->Field<<";"<<endl;
}
myout<<endl; myout<<"public:"<<endl;
myout<<"\t "<<m_ModelClass<<"();"<<endl;
myout<<"\t ~"<<m_ModelClass<<"();"<<endl;
myout<<"\t "<<m_ModelClass<<"(const "<<m_ModelClass<<"& obj);"<<endl;
myout<<"\t "<<m_ModelClass<<"& operator = (const "<<m_ModelClass<<"& obj);"<<endl; for (vector<FieldType>::iterator itr = m_Fields.begin();
itr != m_Fields.end(); itr++)
{
myout<<"\t void Set"<<itr->Field<<"("<<itr->FType<<" val);"<<endl;
myout<<"\t "<<itr->FType<<" Get"<<itr->Field<<"() const;"<<endl;
} myout<<"};"<<endl;
myout.close();
} void AutoGenModelDao::GenModelBody()
{
string file = m_OutputDir+"\\"+m_ModelClass+".cpp";
ofstream myout(file.c_str(),ios::out);
myout<<"#include \"StdAfx.h\""<<endl;
myout<<"#include \""<<m_ModelClass<<".h\""<<endl;
GenConstructFun(myout);
GenGetSetFun(myout);
myout.close();
}
ostream& AutoGenModelDao::GenConstructFun(ostream& myout)
{
myout<<m_ModelClass<<"::"<<m_ModelClass<<"(){"<<endl;
for (vector<FieldType>::iterator itr = m_Fields.begin();
itr != m_Fields.end(); itr++)
{
if(itr->FType!="string")
myout<<"\t m_"<<itr->Field<<" = 0;"<<endl;
else
myout<<"\t memset(m_"<<itr->Field<<",0,"<<itr->Field<<"Size);m_"<<itr->Field<<"[0]='\\0';"<<endl;
}
myout<<"}"<<endl;
myout<<endl;
myout<<m_ModelClass<<"::~"<<m_ModelClass<<"(){}"<<endl;
myout<<endl;
myout<<m_ModelClass<<"::"<<m_ModelClass<<"(const "<<m_ModelClass<<"& obj){"<<endl;
for (vector<FieldType>::iterator itr = m_Fields.begin();
itr != m_Fields.end(); itr++)
{
if(itr->FType!="string")
myout<<"\t m_"<<itr->Field<<" = obj.Get"<<itr->Field<<"();"<<endl;
else
myout<<"\t Set"<<itr->Field<<"(obj.Get"<<itr->Field<<"());"<<endl;
}
myout<<"}"<<endl;
myout<<endl;
myout<<m_ModelClass<<"& "<<m_ModelClass<<"::operator = (const "<<m_ModelClass<<"& obj){"<<endl;
myout<<"\t if(this == &obj) return *this;"<<endl;
for (vector<FieldType>::iterator itr = m_Fields.begin();
itr != m_Fields.end(); itr++)
{
if(itr->FType!="string")
myout<<"\t m_"<<itr->Field<<" = obj.Get"<<itr->Field<<"();"<<endl;
else
myout<<"\t Set"<<itr->Field<<"(obj.Get"<<itr->Field<<"());"<<endl;
}
myout<<"\t return *this;"<<endl;
myout<<"}"<<endl;
return myout;
}
ostream& AutoGenModelDao::GenGetSetFun(ostream& myout)
{
myout<<endl;
for (vector<FieldType>::iterator itr = m_Fields.begin();
itr != m_Fields.end(); itr++)
{
myout<<"void "<<m_ModelClass<<"::Set"<<itr->Field<<"("<<itr->FType<<" val){"<<endl;
if(itr->FType != "string")
myout<<"\t m_"<<itr->Field<<" = val;"<<endl;
else
myout<<"\t strcpy_s(m_"<<itr->Field<<","<<itr->Field<<"Size,val.c_str());"<<endl;
myout<<"}"<<endl;
myout<<endl; myout<<itr->FType<<" "<<m_ModelClass<<"::Get"<<itr->Field<<"()const{"<<endl;
myout<<"\t return m_"<<itr->Field<<";"<<endl;
myout<<"}"<<endl;
}
return myout;
}
void AutoGenModelDao::GenDaoHeader()
{
string file = m_OutputDir+"\\"+m_DaoClass+".h";
ofstream myout(file.c_str(),ios::out);
myout<<"#pragma once"<<endl;
myout<<"#include \""<<m_ModelClass<<".h\""<<endl;
myout<<"#include \"BaseOCIDao.h\""<<endl;
myout<<"#include <string>"<<endl;
myout<<"#include <vector>"<<endl;
myout<<"using namespace std;"<<endl;
myout<<endl;
myout<<"class "<<m_DaoClass<<" : BaseOCIDao{"<<endl;
myout<<"public:"<<endl;
myout<<"\t "<<m_DaoClass<<"():BaseOCIDao(){}"<<endl;
myout<<"\t "<<m_DaoClass<<"(string ip,unsigned int port,string inst,string user,string pwd,POCI_ERROR ErrHandler,unsigned int mode):BaseOCIDao(ip,port,inst,user,pwd,ErrHandler,mode){}"<<endl;
myout<<"\t ~"<<m_DaoClass<<"(){}"<<endl;
myout<<"\t BOOL Insert("<<m_ModelClass<<"* model);"<<endl;
myout<<"\t BOOL InsertBatch(vector<"<<m_ModelClass<<"*> models);"<<endl;
myout<<"\t BOOL Update("<<m_ModelClass<<"* model);"<<endl;
myout<<"\t BOOL UpdateBatch(vector<"<<m_ModelClass<<"*> models);"<<endl;
myout<<"\t BOOL Exist("<<m_ModelClass<<"* model);"<<endl;
myout<<"\t BOOL Delete(string cond);"<<endl;
myout<<"\t vector<"<<m_ModelClass<<"*> Select(string cond);"<<endl;
myout<<"};"<<endl;
myout.close();
} void AutoGenModelDao::GenDaoBody()
{
string file = m_OutputDir+"\\"+m_DaoClass+".cpp";
ofstream myout(file.c_str(),ios::out);
myout<<"#include \"StdAfx.h\""<<endl;
myout<<"#include \""<<m_ModelClass<<".h\""<<endl;
myout<<"#include \""<<m_DaoClass<<".h\""<<endl;
myout<<endl;
GenInsertFun(myout);
GenInsertBatchFun(myout);
GenUpdateFun(myout);
GenUpdateBatchFun(myout);
GenDeleteFun(myout);
GenSelectFun(myout);
GenExistFun(myout);
myout.close();
}
ostream& AutoGenModelDao::GenInsertFun(ostream& myout)
{
myout<<endl;
myout<<"BOOL "<<m_DaoClass<<"::Insert("<<m_ModelClass<<"* model){"<<endl;
myout<<"\t if(model==NULL)return FALSE;"<<endl;
myout<<"\t char* sql=\"insert into "<<m_DBTable<<"(";
for (vector<FieldType>::iterator itr = m_Fields.begin();
itr != m_Fields.end(); itr++)
{
myout<<itr->DBField;
if(itr+ != m_Fields.end())
myout<<",";
}
myout<<") values (";
for (vector<FieldType>::iterator itr = m_Fields.begin();
itr != m_Fields.end(); itr++)
{
myout<<":"<<itr->Field;
if(itr+ != m_Fields.end())
myout<<",";
}
myout<<")\";"<<endl;
myout<<endl; myout<<"\t OCI_Statement* stmt = PrepareBindStmt(sql);"<<endl;
for (vector<FieldType>::iterator itr = m_Fields.begin();
itr != m_Fields.end(); itr++)
{
if(itr->FType=="int")
myout<<"\t OCI_BindInt(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "unsigned int")
myout<<"\t OCI_BindUnsignedInt(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "short")
myout<<"\t OCI_BindShort(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "unsigned short")
myout<<"\t OCI_BindUnsignedShort(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "float")
myout<<"\t OCI_BindFloat(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "double")
myout<<"\t OCI_BindDouble(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "big_int")
myout<<"\t OCI_BindBigInt(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "big_uint")
myout<<"\t OCI_BindUnsignedBigInt(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "string")
myout<<"\t OCI_BindString(stmt,\":"<<itr->Field<<"\",model->m_"<<itr->Field<<","<<itr->Field<<"Size);"<<endl;
}
myout<<"\t return ExecuteBindStmt(stmt);"<<endl;
myout<<"}"<<endl;
return myout;
} ostream& AutoGenModelDao::GenInsertBatchFun(ostream& myout)
{
myout<<endl;
myout<<"BOOL "<<m_DaoClass<<"::InsertBatch(vector<"<<m_ModelClass<<"*> models){"<<endl;
myout<<"\t if(models.empty())return FALSE;"<<endl;
myout<<"\t char* sql=\"insert into "<<m_DBTable<<"(";
for (vector<FieldType>::iterator itr = m_Fields.begin();
itr != m_Fields.end(); itr++)
{
myout<<itr->DBField;
if(itr+ != m_Fields.end())
myout<<",";
}
myout<<") values (";
for (vector<FieldType>::iterator itr = m_Fields.begin();
itr != m_Fields.end(); itr++)
{
myout<<":"<<itr->Field;
if(itr+ != m_Fields.end())
myout<<",";
}
myout<<")\";"<<endl;
myout<<endl; myout<<"\t OCI_Statement* stmt = PrepareBindStmt(sql);"<<endl;
myout<<"\t int bindSize=models.size();"<<endl;
myout<<"\t int strOffset=0;"<<endl;
myout<<"\t OCI_BindArraySetSize(stmt, bindSize);"<<endl;
for (vector<FieldType>::iterator itr = m_Fields.begin();
itr != m_Fields.end(); itr++)
{
if(itr->FType=="int")
{
myout<<"\t int* t"<<itr->Field<<"Arr = new int[bindSize];"<<endl;
myout<<"\t for(int i=0;i<bindSize;++i){"<<endl;
myout<<"\t t"<<itr->Field<<"Arr[i]=models[i]->m_"<<itr->Field<<";"<<endl;
myout<<"\t }"<<endl;
myout<<"\t OCI_BindArrayOfInts(stmt,\":"<<itr->Field<<"\",t"<<itr->Field<<"Arr,bindSize);"<<endl<<endl;
}
else if(itr->FType == "unsigned int")
{
myout<<"\t unsigned int* t"<<itr->Field<<"Arr = new unsigned int[bindSize];"<<endl;
myout<<"\t for(int i=0;i<bindSize;++i){"<<endl;
myout<<"\t t"<<itr->Field<<"Arr[i]=models[i]->m_"<<itr->Field<<";"<<endl;
myout<<"\t }"<<endl;
myout<<"\t OCI_BindArrayOfUnsignedInts(stmt,\":"<<itr->Field<<"\",t"<<itr->Field<<"Arr,bindSize);"<<endl<<endl;
}
else if(itr->FType == "short")
{
myout<<"\t short* t"<<itr->Field<<"Arr = new short[bindSize];"<<endl;
myout<<"\t for(int i=0;i<bindSize;++i){"<<endl;
myout<<"\t t"<<itr->Field<<"Arr[i]=models[i]->m_"<<itr->Field<<";"<<endl;
myout<<"\t }"<<endl;
myout<<"\t OCI_BindArrayOfShorts(stmt,\":"<<itr->Field<<"\",t"<<itr->Field<<"Arr,bindSize);"<<endl<<endl;
}
else if(itr->FType == "unsigned short")
{
myout<<"\t unsigned short* t"<<itr->Field<<"Arr = new unsigned short[bindSize];"<<endl;
myout<<"\t for(int i=0;i<bindSize;++i){"<<endl;
myout<<"\t t"<<itr->Field<<"Arr[i]=models[i]->m_"<<itr->Field<<";"<<endl;
myout<<"\t }"<<endl;
myout<<"\t OCI_BindArrayOfUnsignedShorts(stmt,\":"<<itr->Field<<"\",t"<<itr->Field<<"Arr,bindSize);"<<endl<<endl;
}
else if(itr->FType == "float")
{
myout<<"\t float* t"<<itr->Field<<"Arr = new float[bindSize];"<<endl;
myout<<"\t for(int i=0;i<bindSize;++i){"<<endl;
myout<<"\t t"<<itr->Field<<"Arr[i]=models[i]->m_"<<itr->Field<<";"<<endl;
myout<<"\t }"<<endl;
myout<<"\t OCI_BindArrayOfFloats(stmt,\":"<<itr->Field<<"\",t"<<itr->Field<<"Arr,bindSize);"<<endl<<endl;
}
else if(itr->FType == "double")
{
myout<<"\t double* t"<<itr->Field<<"Arr = new double[bindSize];"<<endl;
myout<<"\t for(int i=0;i<bindSize;++i){"<<endl;
myout<<"\t t"<<itr->Field<<"Arr[i]=models[i]->m_"<<itr->Field<<";"<<endl;
myout<<"\t }"<<endl;
myout<<"\t OCI_BindArrayOfDoubles(stmt,\":"<<itr->Field<<"\",t"<<itr->Field<<"Arr,bindSize);"<<endl<<endl;
}
else if(itr->FType == "big_int")
{
myout<<"\t big_int* t"<<itr->Field<<"Arr = new big_int[bindSize];"<<endl;
myout<<"\t for(int i=0;i<bindSize;++i){"<<endl;
myout<<"\t t"<<itr->Field<<"Arr[i]=models[i]->m_"<<itr->Field<<";"<<endl;
myout<<"\t }"<<endl;
myout<<"\t OCI_BindArrayOfBigInts(stmt,\":"<<itr->Field<<"\",t"<<itr->Field<<"Arr,bindSize);"<<endl<<endl;
}
else if(itr->FType == "big_uint")
{
myout<<"\t big_uint* t"<<itr->Field<<"Arr = new big_uint[bindSize];"<<endl;
myout<<"\t for(int i=0;i<bindSize;++i){"<<endl;
myout<<"\t t"<<itr->Field<<"Arr[i]=models[i]->m_"<<itr->Field<<";"<<endl;
myout<<"\t }"<<endl;
myout<<"\t OCI_BindArrayOfUnsignedBigInts(stmt,\":"<<itr->Field<<"\",t"<<itr->Field<<"Arr,bindSize);"<<endl<<endl;
}
else if(itr->FType == "string")
{
myout<<"\t strOffset=0;"<<endl;
myout<<"\t char* t"<<itr->Field<<"Arr = new char["<<itr->Field<<"Size*bindSize];"<<endl;
myout<<"\t for(int i=0;i<bindSize;++i){"<<endl;
myout<<"\t strcpy_s(t"<<itr->Field<<"Arr+strOffset,"<<itr->Field<<"Size,models[i]->m_"<<itr->Field<<");"<<endl;
myout<<"\t strOffset+="<<itr->Field<<"Size;"<<endl;
myout<<"\t }"<<endl;
myout<<"\t OCI_BindArrayOfStrings(stmt,\":"<<itr->Field<<"\",t"<<itr->Field<<"Arr,"<<itr->Field<<"Size-1,bindSize);"<<endl<<endl;
}
}
myout<<"\t BOOL flag = ExecuteBindStmt(stmt);"<<endl<<endl; for (vector<FieldType>::iterator itr = m_Fields.begin();
itr != m_Fields.end(); itr++)
{
myout<<"\t delete[] t"<<itr->Field<<"Arr;"<<endl;
}
myout<<endl<<"\t return flag;"<<endl;
myout<<"}"<<endl;
return myout;
} ostream& AutoGenModelDao::GenUpdateFun(ostream& myout)
{
myout<<endl;
myout<<"BOOL "<<m_DaoClass<<"::Update("<<m_ModelClass<<"* model){"<<endl;
myout<<"\t if(model==NULL)return FALSE;"<<endl;
myout<<"\t char* sql=\"update "<<m_DBTable<<" set ";
vector<FieldType>::iterator itr = m_Fields.begin();
itr++;
for (;itr != m_Fields.end(); itr++)
{
myout<<itr->DBField<<" = :"<<itr->Field;
if(itr+ != m_Fields.end())
myout<<",";
}
myout<<" where "<<m_Fields.begin()->DBField<<"=:"<<m_Fields.begin()->Field<<"\";"<<endl;
myout<<endl; myout<<"\t OCI_Statement* stmt = PrepareBindStmt(sql);"<<endl;
for (vector<FieldType>::iterator itr = m_Fields.begin();
itr != m_Fields.end(); itr++)
{
if(itr->FType=="int")
myout<<"\t OCI_BindInt(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "unsigned int")
myout<<"\t OCI_BindUnsignedInt(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "short")
myout<<"\t OCI_BindShort(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "unsigned short")
myout<<"\t OCI_BindUnsignedShort(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "float")
myout<<"\t OCI_BindFloat(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "double")
myout<<"\t OCI_BindDouble(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "big_int")
myout<<"\t OCI_BindBigInt(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "big_uint")
myout<<"\t OCI_BindUnsignedBigInt(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "string")
myout<<"\t OCI_BindString(stmt,\":"<<itr->Field<<"\",model->m_"<<itr->Field<<","<<itr->Field<<"Size);"<<endl;
} myout<<"\t return ExecuteBindStmt(stmt);"<<endl;
myout<<"}"<<endl;
return myout;
} ostream& AutoGenModelDao::GenUpdateBatchFun(ostream& myout)
{
myout<<endl;
myout<<"BOOL "<<m_DaoClass<<"::UpdateBatch(vector<"<<m_ModelClass<<"*> models){"<<endl;
myout<<"\t if(models.empty())return FALSE;"<<endl;
myout<<"\t char* sql=\"update "<<m_DBTable<<" set ";
vector<FieldType>::iterator itr = m_Fields.begin();
itr++;
for (;itr != m_Fields.end(); itr++)
{
myout<<itr->DBField<<" = :"<<itr->Field;
if(itr+ != m_Fields.end())
myout<<",";
}
myout<<" where "<<m_Fields.begin()->DBField<<"=:"<<m_Fields.begin()->Field<<"\";"<<endl;
myout<<endl; myout<<"\t OCI_Statement* stmt = PrepareBindStmt(sql);"<<endl;
myout<<"\t int bindSize=models.size();"<<endl;
myout<<"\t int strOffset=0;"<<endl;
myout<<"\t OCI_BindArraySetSize(stmt, bindSize);"<<endl;
for (vector<FieldType>::iterator itr = m_Fields.begin();
itr != m_Fields.end(); itr++)
{
if(itr->FType=="int")
{
myout<<"\t int* t"<<itr->Field<<"Arr = new int[bindSize];"<<endl;
myout<<"\t for(int i=0;i<bindSize;++i){"<<endl;
myout<<"\t t"<<itr->Field<<"Arr[i]=models[i]->m_"<<itr->Field<<";"<<endl;
myout<<"\t }"<<endl;
myout<<"\t OCI_BindArrayOfInts(stmt,\":"<<itr->Field<<"\",t"<<itr->Field<<"Arr,bindSize);"<<endl<<endl;
}
else if(itr->FType == "unsigned int")
{
myout<<"\t unsigned int* t"<<itr->Field<<"Arr = new unsigned int[bindSize];"<<endl;
myout<<"\t for(int i=0;i<bindSize;++i){"<<endl;
myout<<"\t t"<<itr->Field<<"Arr[i]=models[i]->m_"<<itr->Field<<";"<<endl;
myout<<"\t }"<<endl;
myout<<"\t OCI_BindArrayOfUnsignedInts(stmt,\":"<<itr->Field<<"\",t"<<itr->Field<<"Arr,bindSize);"<<endl<<endl;
}
else if(itr->FType == "short")
{
myout<<"\t short* t"<<itr->Field<<"Arr = new short[bindSize];"<<endl;
myout<<"\t for(int i=0;i<bindSize;++i){"<<endl;
myout<<"\t t"<<itr->Field<<"Arr[i]=models[i]->m_"<<itr->Field<<";"<<endl;
myout<<"\t }"<<endl;
myout<<"\t OCI_BindArrayOfShorts(stmt,\":"<<itr->Field<<"\",t"<<itr->Field<<"Arr,bindSize);"<<endl<<endl;
}
else if(itr->FType == "unsigned short")
{
myout<<"\t unsigned short* t"<<itr->Field<<"Arr = new unsigned short[bindSize];"<<endl;
myout<<"\t for(int i=0;i<bindSize;++i){"<<endl;
myout<<"\t t"<<itr->Field<<"Arr[i]=models[i]->m_"<<itr->Field<<";"<<endl;
myout<<"\t }"<<endl;
myout<<"\t OCI_BindArrayOfUnsignedShorts(stmt,\":"<<itr->Field<<"\",t"<<itr->Field<<"Arr,bindSize);"<<endl<<endl;
}
else if(itr->FType == "float")
{
myout<<"\t float* t"<<itr->Field<<"Arr = new float[bindSize];"<<endl;
myout<<"\t for(int i=0;i<bindSize;++i){"<<endl;
myout<<"\t t"<<itr->Field<<"Arr[i]=models[i]->m_"<<itr->Field<<";"<<endl;
myout<<"\t }"<<endl;
myout<<"\t OCI_BindArrayOfFloats(stmt,\":"<<itr->Field<<"\",t"<<itr->Field<<"Arr,bindSize);"<<endl<<endl;
}
else if(itr->FType == "double")
{
myout<<"\t double* t"<<itr->Field<<"Arr = new double[bindSize];"<<endl;
myout<<"\t for(int i=0;i<bindSize;++i){"<<endl;
myout<<"\t t"<<itr->Field<<"Arr[i]=models[i]->m_"<<itr->Field<<";"<<endl;
myout<<"\t }"<<endl;
myout<<"\t OCI_BindArrayOfDoubles(stmt,\":"<<itr->Field<<"\",t"<<itr->Field<<"Arr,bindSize);"<<endl<<endl;
}
else if(itr->FType == "big_int")
{
myout<<"\t big_int* t"<<itr->Field<<"Arr = new big_int[bindSize];"<<endl;
myout<<"\t for(int i=0;i<bindSize;++i){"<<endl;
myout<<"\t t"<<itr->Field<<"Arr[i]=models[i]->m_"<<itr->Field<<";"<<endl;
myout<<"\t }"<<endl;
myout<<"\t OCI_BindArrayOfBigInts(stmt,\":"<<itr->Field<<"\",t"<<itr->Field<<"Arr,bindSize);"<<endl<<endl;
}
else if(itr->FType == "big_uint")
{
myout<<"\t big_uint* t"<<itr->Field<<"Arr = new big_uint[bindSize];"<<endl;
myout<<"\t for(int i=0;i<bindSize;++i){"<<endl;
myout<<"\t t"<<itr->Field<<"Arr[i]=models[i]->m_"<<itr->Field<<";"<<endl;
myout<<"\t }"<<endl;
myout<<"\t OCI_BindArrayOfUnsignedBigInts(stmt,\":"<<itr->Field<<"\",t"<<itr->Field<<"Arr,bindSize);"<<endl<<endl;
}
else if(itr->FType == "string")
{
myout<<"\t strOffset=0;"<<endl;
myout<<"\t char* t"<<itr->Field<<"Arr = new char["<<itr->Field<<"Size*bindSize];"<<endl;
myout<<"\t for(int i=0;i<bindSize;++i){"<<endl;
myout<<"\t strcpy_s(t"<<itr->Field<<"Arr+strOffset,"<<itr->Field<<"Size,models[i]->m_"<<itr->Field<<");"<<endl;
myout<<"\t strOffset+="<<itr->Field<<"Size;"<<endl;
myout<<"\t }"<<endl;
myout<<"\t OCI_BindArrayOfStrings(stmt,\":"<<itr->Field<<"\",t"<<itr->Field<<"Arr,"<<itr->Field<<"Size-1,bindSize);"<<endl<<endl;
}
} myout<<"\t BOOL flag = ExecuteBindStmt(stmt);"<<endl<<endl; for (vector<FieldType>::iterator itr = m_Fields.begin();
itr != m_Fields.end(); itr++)
{
myout<<"\t delete[] t"<<itr->Field<<"Arr;"<<endl;
}
myout<<endl<<"\t return flag;"<<endl;
myout<<"}"<<endl;
return myout;
} ostream& AutoGenModelDao::GenDeleteFun(ostream& myout)
{
myout<<endl;
myout<<"BOOL "<<m_DaoClass<<"::Delete(string cond){"<<endl;
myout<<"\t string sql=\"delete from "<<m_DBTable<<"\";"<<endl;
myout<<"\t if(cond!=\"\") sql+=\" where \"+cond;"<<endl;
myout<<"\t return ExecuteSql(sql.c_str());"<<endl;
myout<<"}"<<endl;
return myout;
} ostream& AutoGenModelDao::GenSelectFun(ostream& myout)
{
myout<<endl;
myout<<"vector<"<<m_ModelClass<<"*> "<<m_DaoClass<<"::Select(string cond){"<<endl;
myout<<"\t vector<"<<m_ModelClass<<"*> resVec;"<<endl;
myout<<"\t string sql=\"select ";
vector<FieldType>::iterator itr = m_Fields.begin();
for (;itr != m_Fields.end(); itr++)
{
myout<<itr->DBField;
if(itr+ != m_Fields.end())
myout<<",";
}
myout<<" from "<<m_DBTable<<"\";"<<endl;
myout<<"\t if(cond!=\"\") sql+=\" where \"+cond;"<<endl;
myout<<"\t OCI_Resultset* rs = QuerySql(sql.c_str());"<<endl;
myout<<"\t while(OCI_FetchNext(rs)){"<<endl;
myout<<"\t "<<m_ModelClass<<"* model = new "<<m_ModelClass<<"();"<<endl; int fieldCnt = ;
for (itr=m_Fields.begin();itr != m_Fields.end(); itr++)
{
fieldCnt++;
myout<<"\t model->Set"<<itr->Field<<"(";
if(itr->FType=="int")
myout<<"OCI_GetInt(rs,"<<fieldCnt<<")";
else if(itr->FType == "unsigned int")
myout<<"OCI_GetUnsignedInt(rs,"<<fieldCnt<<")";
else if(itr->FType == "short")
myout<<"OCI_BindShort(rs,"<<fieldCnt<<")";
else if(itr->FType == "unsigned short")
myout<<"OCI_GetUnsignedShort(rs,"<<fieldCnt<<")";
else if(itr->FType == "float")
myout<<"OCI_GetFloat(rs,"<<fieldCnt<<")";
else if(itr->FType == "double")
myout<<"OCI_BindDouble(rs,"<<fieldCnt<<")";
else if(itr->FType == "big_int")
myout<<"OCI_GetBigInt(rs,"<<fieldCnt<<")";
else if(itr->FType == "big_uint")
myout<<"OCI_GetUnsignedBigInt(rs,"<<fieldCnt<<")";
else if(itr->FType == "string")
myout<<"OCI_GetString(rs,"<<fieldCnt<<")"; myout<<");"<<endl;
}
myout<<"\t resVec.push_back(model);"<<endl;
myout<<"\t }"<<endl;
myout<<"\t return resVec;"<<endl;
myout<<"}"<<endl;
return myout;
}
ostream& AutoGenModelDao::GenExistFun(ostream& myout)
{
myout<<endl;
myout<<"BOOL "<<m_DaoClass<<"::Exist("<<m_ModelClass<<"* model){"<<endl;
myout<<"\t if(model==NULL) return FALSE;"<<endl;
vector<FieldType>::iterator itr = m_Fields.begin();
myout<<"\t char* sql=\"select "<<itr->DBField<<" from "<<m_DBTable<<" where ";
itr++;
for (;itr != m_Fields.end(); itr++)
{
myout<<itr->DBField<<" = :"<<itr->Field;
if(itr+ != m_Fields.end())
myout<<",";
}
myout<<"\";"<<endl; myout<<"\t OCI_Statement* stmt = PrepareBindStmt(sql);"<<endl;
itr = m_Fields.begin();
itr++;
for (;itr != m_Fields.end(); itr++)
{
if(itr->FType=="int")
myout<<"\t OCI_BindInt(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "unsigned int")
myout<<"\t OCI_BindUnsignedInt(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "short")
myout<<"\t OCI_BindShort(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "unsigned short")
myout<<"\t OCI_BindUnsignedShort(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "float")
myout<<"\t OCI_BindFloat(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "double")
myout<<"\t OCI_BindDouble(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "big_int")
myout<<"\t OCI_BindBigInt(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "big_uint")
myout<<"\t OCI_BindUnsignedBigInt(stmt,\":"<<itr->Field<<"\",&model->m_"<<itr->Field<<");"<<endl;
else if(itr->FType == "string")
myout<<"\t OCI_BindString(stmt,\":"<<itr->Field<<"\",model->m_"<<itr->Field<<","<<itr->Field<<"Size);"<<endl;
}
myout<<"\t OCI_Resultset* rs = QueryBindStmt(stmt);"<<endl;
myout<<"\t if(OCI_FetchNext(rs)){"<<endl;
myout<<"\t model->Set"<<m_Fields.begin()->Field<<"(OCI_GetUnsignedInt(rs,1));"<<endl;
myout<<"\t return TRUE;"<<endl;
myout<<"\t }"<<endl;
myout<<"\t else return FALSE;"<<endl;
myout<<"}"<<endl;
return myout;
}
基于OCILIB的oracle数据库操作总结及自动生成Model和Dao的工具的更多相关文章
- C#连接Oracle数据库,通过EF自动生成与数据库表相关的实体类
C#连接Oracle数据库,通过EF自动生成与数据库表相关的实体类 ps:如需转载,请在转载文章明显处,i标注作者和原文地址 一.准备条件 需要自己电脑上已经安装了Oracle数据库,并且已经创建了相 ...
- core 中ef 连接sql server数据库 在类库中 自动生成 model
首先 介绍 Scaffold-DbContext "Server=.;database=sdd;User Id=sa;Password=123456;" Microsoft.Ent ...
- C# Oracle数据库操作类实例详解
本文所述为C#实现的Oracle数据库操作类,可执行超多常用的Oracle数据库操作,包含了基础数据库连接.关闭连接.输出记录集.执行Sql语句,返回带分页功能的dataset .取表里字段的类型和长 ...
- (转)C# Oracle数据库操作类
原文地址:http://www.cnblogs.com/haibing0107/p/6143922.html using System;using System.Data;using System.C ...
- C# Oracle数据库操作类
using System; using System.Data; using System.Collections.Generic; using System.Configuration; using ...
- SSM 框架基于ORACLE集成TKMYBATIS 和GENERATOR自动生成代码(Github源码)
基于前一个博客搭建的SSM框架 https://www.cnblogs.com/jiangyuqin/p/9870641.html 源码:https://github.com/JHeaven/ssm- ...
- 利用 Oracle EM 企业管理器 进行oracle SQL的优化(自动生成索引)
利用 Oracle EM 企业管理器 进行oracle SQL的优化(自动生成索引) ##应用情景 项目中有大量的SQL,尤其是涉及到统计报表时,表关联比较多,当初开发建表时也没搞好索引关联的,上线后 ...
- 循序渐进Python3(十二) --2-- web框架之django简单实现oracle数据库操作
在 Django 中构建 Oracle 数据库支持的 Web 应用程序 了解如何配置 Django 以便与 Oracle 数据库交互,并使用 ORM 进行数据库连接. 产能在软 ...
- C++使用ocilib访问oracle数据库
引用: http://blog.csdn.net/u011311985/article/details/51221898 测试程序我放到 http://download.csdn.NET/detail ...
随机推荐
- 解决ajax.net 1.0中文乱码问题!
在使用ajax.net的UpdatePanel的时候,当requestEncoding编码为GB2312的时候,出现乱码.如果要解决这个问题最简单的就是改用utf-8了,但是原来使用GB2312, ...
- 记录一下bing的图片 - 升级版冰糖葫芦
记录一下bing的图片 - 升级版冰糖葫芦
- IP, TCP, and HTTP--reference
IP, TCP, and HTTP Issue #10 Syncing Data, March 2014 By Daniel Eggert When an app communicates with ...
- 关于Android LinearLayout添加分隔线的方法
目前了解的办法有两个:1.自定义一个view当作分隔线:2.使用高版本的分隔线属性 一.在需要添加分隔线的地方,添加一个view,比如ImageView,TextView等都可以,如代码,关键是设置高 ...
- java 删除字符串中的反斜杠\
Java中有时候会打印出来会含有反斜杠(\)的字符串,我们需要删除时,可以使用 replace() 或 replaceAll() 但是要注意的是replaceAll()里面用的是正则表达式,所以一个斜 ...
- [Java] HashMap详解
转自:http://alex09.iteye.com/blog/539545 HashMap 和 HashSet 是 Java Collection Framework 的两个重要成员,其中 Hash ...
- java cpu load
$ps -Lp 179093 cu | more USER PID LWP %CPU NLWP %MEM VSZ RSS TTY STAT START TIME COMMAND admin 17909 ...
- 剑指Offer14 逆序链表
/************************************************************************* > File Name: 14_Revers ...
- ServiceLoader的使用
ServiceLoader与ClassLoader是Java中2个即相互区别又相互联系的加载器.JVM利用ClassLoader将类载入内存,这是一个类声明周期的第一步(一个java类的完整的生命周期 ...
- 看完final的感受
今天没课,(其实是有体育课的,去打了一会球就跑路了...)就在宿舍看world final ; 我去,老毛子真是好厉害,看的我目瞪口呆,哈喇子直流; 上交的大神好厉害,本来还以为上交要夺冠的,最后罚时 ...