SQLRETURN ODBC::Connect(SQLHDBC ConnectionHandle,
           SQLCHAR *ServerName, 
		   SQLSMALLINT NameLength1,
           SQLCHAR *UserName, 
		   SQLSMALLINT NameLength2,
           SQLCHAR *Authentication, 
		   SQLSMALLINT NameLength3)
{
	SQLRETURN	rc;
	CConnect	*pConnect;
	if (! gDrvrGlobal.gHandle.validateHandle(SQL_HANDLE_DBC, ConnectionHandle))
		return SQL_INVALID_HANDLE;

	pConnect = (CConnect *)ConnectionHandle;
	rc = pConnect->Connect(ServerName, NameLength1, UserName, NameLength2, Authentication, NameLength3,
		TRUE);
	return rc;
}
Esempio n. 2
0
int _tmain(int argc, _TCHAR* argv[])
{
	bool bReturn = false;
	for(int i = 0;i < 5;++i)
	{
		//std::string host = "10.0.0.218";
		//std::string user = "******";
		//std::string password = "******";
		//std::string dbname = "test";
		//WORD port = MYSQL_PORT;
		CConnect * conn = new CConnect();
		bReturn = false;
		//bReturn = conn->Connect(host, user, password, dbname, port);
		bReturn = conn->Connect("localhost", "root", "tiptop", "test", MYSQL_PORT);
		if (bReturn)
		{
			std::cout<<"连接数据库成功!!!"<<endl;
		}
		else
		{
			std::cout<<"连接数据库失败!!!"<<endl;
		}					
		
		//bReturn = conn->Connect("10.0.0.218", "root", "tiptop", "test", MYSQL_PORT);
		CManagerPool::GetInitInstance().AddConObject(conn);
	}

	CSqlClient client;

	COperMysql store;
	store.SetTransAction(client.GetConnect());

	//先删除数据表
	std::string s_sql = "drop table processingtransactioninterface";//删除表
	if(!store.Exec(s_sql))
	{
		//删除表失败
		std::cout<<"drop table fail"<<endl<<store.What()<<endl;   
	}
	else
	{
		std::cout<<"drop table success"<<endl;
	}

	//创建数据表,字段 actid 设置了自增列属性
	s_sql = "create table processingtransactioninterface(";
	s_sql += "actid integer not null AUTO_INCREMENT,";
	s_sql += "acttype integer not null,resourceid integer not null,";
	s_sql += " subresoureid  integer, actdate varchar(19), actresult integer,";
	s_sql += " memo varchar(50) null,primary key(actid))";
	if(!store.Exec(s_sql))
	{
		//创建表失败
		std::cout<<"create table fail"<<endl;
		return -1;
	}
	else
	{
		std::cout<<"create table success"<<endl;
		std::cout<<s_sql.c_str()<<endl;
	}
	std::cout<<"开始运行线程……"<<endl;

	unsigned long p1 = 0;	
	::CreateThread(0,0,(funcptr)show,0,0,&p1);

	unsigned long p2 = 0;	
	::CreateThread(0,0,(funcptr)update,0,0,&p2);
	
	unsigned long p3 = 0;
	::CreateThread(0,0,(funcptr)insert,0,0,&p3);

	system("pause");
	return 0;
}