PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Writing Postgres tables  (Read 179 times)

michaelgreer

  • Gold Member
  • ****
  • Posts: 71
    • View Profile
Writing Postgres tables
« on: July 09, 2021, 01:12:55 PM »
Has anyone every written to a postgres database out of a PVX program. Any pointers would be appreciated.

Stéphane Devouard

  • Gold Member
  • ****
  • Posts: 67
  • PxPlus guru with skills in PHP, JS, C#, Java
    • View Profile
    • Stéphane's Web Resume
Re: Writing Postgres tables
« Reply #1 on: July 10, 2021, 06:02:15 AM »
Michael


Since PxPlus does not provide a direct interface to PostgreSQL, you need to download and install the ODBC driver


The attached code connects to a database on the local machine using a DSN-less connection string


When run, it yields :
Code: [Select]

-:run
1
Family


2
Work

You can also insert to a table (very simple schema : an auto-increment id and a varchar description :
Code: [Select]
1:
1:write record (pgdb)"insert into categories (category_name) values ('Friends')"
1:write record (pgdb)"select * from categories where category_id=3"
1:?rcd(pgdb)
3
Friends

And update as well :
Code: [Select]
1:write record (pgdb)"update categories set category_name='Professional' where c
ategory_id=2"
1:write record (pgdb)"select * from categories where category_id=2"
1:?rcd(pgdb)
2
Professional
1:
« Last Edit: July 10, 2021, 06:18:15 AM by Stéphane Devouard »
Stéphane Devouard
Portfolio | Work