From eec9c7f2420553bf0115de653d61fbb3973d74ad Mon Sep 17 00:00:00 2001 From: Dmitriy Mihaylenko Date: Fri, 1 Dec 2023 18:03:28 +0200 Subject: [PATCH] db.pg: fix using postgresql on windows, improve instructions for installing it (#20053) --- vlib/db/pg/README.md | 32 ++++++++++++++++++++++++++++++-- vlib/db/pg/pg.c.v | 8 ++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/vlib/db/pg/README.md b/vlib/db/pg/README.md index c75c3b3036..ec15a9f199 100644 --- a/vlib/db/pg/README.md +++ b/vlib/db/pg/README.md @@ -7,7 +7,7 @@ Before you can use this module, you must first have PostgreSQL installed on your To do this, find your OS and perform the actions listed. > **Note** -> These instructions are meant only as a convenience. If your OS is not listed +> These instructions are meant only as a convenience. If your OS is not listed > or you need extra help, [go here](https://www.postgresql.org/download/). ### Fedora 31 @@ -45,6 +45,34 @@ gem install pg -- --with-pg-config=/opt/local/lib/postgresql[version number]/bin **ArchLinux**: `pacman -S postgresql-libs` +**Windows**: +``` +1. Download PostgreSQL SDK from official site +2. Extract archive to postgres-master folder +3. Copy folder postgres-master/src/interfaces/libpq to v/thirdparty/pg +4. Copy file postgres-master/src/include/postgres_ext.h to v/thirdparty/pg/libpq + +If you build PostgreSQL from source pg_config_ext.h and pg_config.h will be created automatically: +5. Copy file postgres-master/src/include/pg_config_ext.h to v/thirdparty/pg/libpq +6. Copy file postgres-master/src/include/pg_config.h to v/thirdparty/pg/libpq + +If you do not build PostgreSQL from source code: +5. Copy file postgres-master/src/include/pg_config_ext.h.in to v/thirdparty/pg/libpq +- rename pg_config_ext.h.in to pg_config_ext.h +- in pg_config_ext.h change line **#undef PG_INT64_TYPE** to **#define PG_INT64_TYPE long int** +6. Copy file postgres-master/src/include/pg_config.h.in to v/thirdparty/pg/libpq +- rename pg_config.h.in to pg_config.h +- in pg_config.h change line **#undef PG_VERSION_NUM** to **#define PG_VERSION_NUM X0Y0Z** +where X is major db version, Y is minor version, Z is patch version. So if your version is 17.1.2 +PG_VERSION_NUM will be 170102, PG_VERSION_NUM should be number, dot sign is changing to 0, +format *PG_VERSION_NUM 17* without 0 also should work + +7. Add libpq.dll to v/thirdparty/pg/win64 + +To get the libpq.dll file, you can install the PostgreSQL database, +and get this dll from its bin/ folder, or compile DB from source code. +``` + ## Getting Started with [PostgreSQL](https://www.postgresqltutorial.com/postgresql-getting-started) Read this section to learn how to install and connect to PostgreSQL @@ -54,7 +82,7 @@ Read this section to learn how to install and connect to PostgreSQL ## Using Parameterized Queries -Parameterized queries (exec_param, etc.) in V require the use of the following syntax: ($n). +Parameterized queries (exec_param, etc.) in V require the use of the following syntax: ($n). The number following the $ specifies which parameter from the argument array to use. diff --git a/vlib/db/pg/pg.c.v b/vlib/db/pg/pg.c.v index 0f1f54f8e0..1ef90431a5 100644 --- a/vlib/db/pg/pg.c.v +++ b/vlib/db/pg/pg.c.v @@ -21,7 +21,7 @@ $if $pkgconfig('libpq') { #flag darwin -I/opt/homebrew/opt/libpq/include #flag darwin -L/opt/homebrew/opt/libpq/lib - #flag windows -I @VEXEROOT/thirdparty/pg/include + #flag windows -I @VEXEROOT/thirdparty/pg/libpq #flag windows -L @VEXEROOT/thirdparty/pg/win64 } @@ -33,7 +33,11 @@ $if $pkgconfig('libpq') { #include // for orm -#include +$if windows { + #include +} $else { + #include +} #include "@VMODROOT/vlib/db/pg/compatibility.h"