[PyGreSQL] Win32 Binaries?

Mizutori Tetsuya cronus at mizutori.net
Sun Sep 12 12:41:06 EDT 2004


On Sat Sep 11 18:08:28 EDT 2004, Michael Hipp wrote:

> Can anyone tell me if there are Win32 binaries available for PyGreSQL?
> Thank you,
> Michael Hipp
> Heber Springs, Arkansas, USA

I think it's not so hard to make a pygresql module for win32.
Please follow these instructions to comile PyGreSQL source.

Required resources to make module:
(1) Microsoft .NET Framework SDK Version 1.1 (including VC7++; free)
(2) Python 2.3.4 for windows, that should be installed previously
(3) PostgreSQL 7.4.5 source
(4) PyGreSQL 3.5 source
I have tested on Microsoft Windows 2000 SP4.

Step1: create libpq.dll and libpqdll.lib interface libraries to PostgreSQL
(1) change working directory to the "src" of PostgreSQL source
(2) run win32 makefile for VC7++ as follows;
    nmake.exe /f win32.mak
(3) find generated libraries in the "./interfaces/libpq/Release/" directory

Step2: Patch pgmodule.c for disabling "long long" integer type
---[ pgmodule.patch ]---
--- pgmodule-35.c      2004-08-30 09:12:24.000000000 +0900
+++ pgmodule.c  2004-09-05 14:24:54.000000000 +0900
@@ -91,6 +91,11 @@
 #define NO_SNPRINTF 1
 #endif

+#ifdef MS_WIN32 /* patch by Mizutori 2004-09-04 */
+/*typedef long long __int64;*/
+#define strtoll(x,y,z) (__int64) strtol(x,y,z)
+#endif
+
 /* In 7.4 PQfreeNotify was deprecated and PQfreemem is used instead.  A
    macro exists in 7.4 for backwards compatibility. */
 #ifndef PQfreeNotify   /* must be earlier than 7.4 */
---

Step3: compile pgmodule.c by VC7++ of .NET Framework SDK
(1) make an export table file pgmodule.def
---[ pgmodule.def ]---
EXPORTS
	init_pg
---
(2) copy pgmodule.def and libpqdll.lib files to working directory
(3) make _pg.dll library by compiling pgmodule.c as follows
---[ make_pg.bat ]---
SET PYTHON_HOME=C:\usr\Python23 (* modify properly to your environment *)
SET PGSRC=..\postgresql-7.4.5\src (* modify properly to your environment *)

SET PYINC=%PYTHON_HOME%\include
SET PGINC=%PGSRC%\include;%PGSRC%\include\libpq;%PGSRC%\interfaces\libpq
COPY %PGSRC%\include\pg_config.h.win32 %PGSRC%\include\pg_config.h

SET INCLUDE=%PYINC%;%PGINC%;%INCLUDE%
SET LIB=%PYTHON_HOME%\libs;%LIB%
SET OPTIONS=/nologo /D "WIN32" /D "NDEBUG"

cl.exe %OPTIONS% /LD /Fe_pg.dll pgmodule.c pgmodule.def libpqdll.lib
---

Step4: test pygresql module
(1) put the related pygresql module files under the PYTHONPATH
    pg.py, pgdb.py, _pg.dll, libpq.dll
(2) run a test python script
>>> import _pg
>>> db = _pg.connect('mydb','localhost',5432,None,None,'postgres',None)
>>> result = db.query("SELECT * FROM weather")
>>> print repr(result.getresult())
>>> db.close()

[('tokyo', 'ohsaki', '2003-10-13', 23, 15), 
 ('osaka', 'kobe', '2003-10-13', 25,17), 
 ('hokkaido', 'sapporo', '2003-10-13', 15, 10)]

Congratulations to have a happy message!

-- 
Mizutori Tetsuya, Tokyo Japan
mailto:cronus at mizutori.net



More information about the PyGreSQL mailing list