vc通过ado方式连接postgresql
if(m_adoConnection.IsOpen())
m_adoConnection.Close();
if(!m_adoConnection.ConnectPostSql(_T("postgres"),_T("123"),_T("postgres"),_T("127.0.0.1"),5432))
{
AfxMessageBox(_T("访问数据库失败!"));
return;
}
if(!m_adoConnection.IsOpen())
{
AfxMessageBox(_T("数据库异常!"));
return;
}
m_recordSet.SetAdoConnection(&m_adoConnection);
//test
DWORD dwbegin = ::GetTickCount();
double dbegin = (double)time(NULL);
m_adoConnection.BeginTrans();
for (int i=0;i<TESTCOUNT;i++)
{
CTime tim=CTime::GetCurrentTime();
CString str=tim.Format("%Y-%m-%d-%M-%S");//显示年月日
CString strSql;
strSql.Format(_T("INSERT INTO table1(test1, test2) VALUES ('%s我啊', '%s')"),str,str);
m_recordSet.Open(strSql);
//m_recordSet.Close();
//Sleep(100);
}
//m_recordSet.Open(_T("delete from table1"));
m_adoConnection.CommitTrans();
//m_adoConnection.Execute(_T("delete * from table1"));
//m_recordSet.Open(_T("select * from table1"));
//while(!m_recordSet.IsEOF())
//{
// CString str;
// m_recordSet.GetCollect(_T("test1"),str);
// AfxMessageBox(str);
// m_recordSet.MoveNext();
//}
//m_adoConnection.Execute(_T("INSERT INTO table1(test1, test2) VALUES ('113', '113')"));
DWORD dwend = ::GetTickCount();
CString strOut;
strOut.Format(_T("插入%d条数据 ADO所用时间为:%lf秒"),TESTCOUNT,(double)(dwend-dwbegin)/1000);
AfxMessageBox(strOut);
经测试 插入一万条数据需要25秒左右