Exemple #1
0
ConnStatusType CConnection::Connect(string str){
	m_pgConn = PQconnectdb(str.c_str());
	m_sConn = str;
	ConnStatusType ret = PQstatus(m_pgConn);
	if( ret == CONNECTION_BAD )
		throw CExceptionConnection("Nao foi possivel conectar com o servidor!"); 
	return ret;
}
Exemple #2
0
CResult CConnection::Query(string sql){
	PGresult *res;

	m_vQuerys.push_back(sql);
	res = PQexec(m_pgConn, sql.c_str());
	if( PQresultStatus(res) == PGRES_FATAL_ERROR ){
		PQclear(res);
		cout << "[MESSAGE] " << CConnection::getSingleton()->getLastError() << endl;
		throw CExceptionConnection("Houve um erro fatal!");
	}

	return CResult(res);
}
Exemple #3
0
CRow CResult::operator[](int i){
	if( i >= PQntuples(m_cResult) ){
		PQclear(m_cResult);
		throw CExceptionConnection("Nao existe essa linha!");
	}
	else{
		CRow row(i);
		for( int n = 0; n < PQnfields(m_cResult); n++ ){
			row.add( PQfname(m_cResult, n), PQgetvalue(m_cResult, i, n) );
		}
		return row;
	}
	return CRow(0);
}