PGAccess.dll gives you easy access to PostgreSQL databases. PGAccess uses libpq classes to access postgreSQL natively.
PGAccess exports the classes CPgSQLConnection, CPgDynaset and CPgQuickQuery. The last class CPgQuickQuery combines the two first
and gives a dynaset like access to your queries. The libpq.dll that PGAccess uses is slightly modified to support GetScale and
GetPrecision methods.
To make a connection to a postgreSQL server just create an object of
CPgSQLConnection, and use the method Connect(). Once the connection is
established
use CPgQuickQuery to handle your queries. CPgQuickQuery::Select(CString
SQL) both executes your query and collects the result in a dynaset.
Then you can access your data using CPgQuickQuery::GetValueAsString(int
FieldIdx, CString& ReturnVal) or corresponding methods for long and
double.
To navigate through the rows use standard recordset cursor methods MoveFirst(), MoveNext(), MovePrev(), MoveLast().
if (!Query->MoveToRow(StartRow))
return;
for (int nRow=0; nRow < Query->RowCount; nRow++)
{
Row.Format("Row %d: ",nRow);
for (nField=0; nField < Query->GetFieldCount(); nField++)
{
Query->GetValueByString(nField,Cell);
if (nField)
Row = Row + " , ";
Row = Row + Cell;
}
Data = Data + Row + "\n";
if (!Query->MoveNext())
break;
}
}
Both PGAccess and libpq are included in the following download. The package contains debug and release versions of
the dll's and lib-files.
New from version 1.3 to 1.4:
* Columnbinding
* Fixed problem with floating point
Download PGAccess v1.4.0 package: pgaccess_v14.zip - PGAccess and libpq dll's, lib's and headerfiles
Applicating PGAccess:
PgSQLLoader.zip
Usage example:
PgSQLLoader is a console program which uses the PgAccess classes to import data from a field delimited datafile. It works
pretty much like Oracle's sqlloader. All you need to do is tell PgSQLLoader is how the delimiter looks and which table and
fields to insert the data into. You do this by writing an authorization script and a control script: