📄 main.cpp
字号:
#include "hyafx.h"
#include <iostream>
#include <string>
using namespace std;
#ifdef WIN32
#include <crtdbg.h>
#endif
void test1(string& t, OCIError* errhp)
{
if (!HYException::checkErr(errhp, 100)) throw HYException();
}
int main()
{
#if defined(WIN32)
// Send all reports to STDOUT
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
int tmpDbgFlag;
tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF;
_CrtSetDbgFlag(tmpDbgFlag);
#endif
HYConnection conn;
conn.connect("orcl", "ocitest", "ocitest");
if (conn.isConnected()) cout<<"成功连接数据库"<<endl;
else cout<<HYException::errMsg()<<endl;
/*
HYConnPool* pool = HYConnPool::createPool();
for (int i=0; i<21; i++)
{
HYConnection* conn = pool->getConn();
if (conn)
{
conn->connect("orcl", "ocitest", "ocitest");
if (conn->isConnected()) cout<<"成功连接数据库"<<endl;
else cout<<HYException::errMsg()<<endl;
}
else
{
cout<<"没有可用连接"<<endl;
}
}
delete pool;
*/
/*
HYString str(&conn);
char hello[32] = "Hello World!";
str.assign((unsigned char*)hello, strlen(hello));
cout<<str.c_str()<<endl;
string me="hello";
try{
test1(me, conn.errhp);
}
catch(HYException& e)
{
cout<<e.errMsg()<<endl;
}
*/
HYCursor cursor(&conn);
try
{
cursor.query("SELECT * FROM student");
int size = cursor.numCols();
cout<<"表student中的内容如下: "<<endl;
while (cursor.fetch())
{
for (int i=0; i<size; i++)
{
cout<<cursor.getFieldValue(i+1)<<", ";
}
cout<<endl;
}
}
catch(HYException& e)
{
cout<<e.errMsg()<<endl;
return -1;
}
int i;
cin>>i;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -