How to create a temporary dbf file by copying the structure of a POSTGRESQL table

Use this forum for questions and answers regarding PostGreSQL and the PGDBE.
Post Reply
Message
Author
Diego Euri Almanzar
Posts: 114
Joined: Thu Nov 05, 2020 10:51 am
Location: DOMINICAN REPUBLIC

How to create a temporary dbf file by copying the structure of a POSTGRESQL table

#1 Post by Diego Euri Almanzar »

In a session with POSTGRESQL via PGDBE, it has been impossible for me to obtain a structure of any table, to create temporary files that I need in reports.

I have done the following test:

SELECT("PGTABLE")
// COPY STRUCTURE TO (DBFSTRUC)
DBCOPYEXTSTRUCT(DBFSTRUC)
USE (DBFSTRUC) VIA FOXCDX

DC_DBEDIT()

DBFCREATEFROM(NEWTEMP,,DBFSTRUC, "FOXCDX")

It never gets to the DC_DBEDIT() line, it gives me an error.

If there is no command that can copy the structure of a table, I will have to have the table in a folder, and use it via foxdbe to copy it. I wanted to gradually eliminate the use of set default to.

Please can someone help me with the following:

1. Is there any way to put the name of the server in the default set, so as not to have to do the Map Network Drive, in the client computers or terminals?

For example
Set Default To \\server\c\data

2. What command or function allows me to make a copy of a table structure while using the POSTGRESQL driver?


Best regards

User avatar
Tom
Posts: 1022
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: How to create a temporary dbf file by copying the structure of a POSTGRESQL table

#2 Post by Tom »

Hi, Diego.

Almost every database command knows the VIA clause. This allows you to use a DBE for operations that is not the default DBE:

Code: Select all

USE mytable // uses the default DBE
COPY TO mytable2 VIA DBFNTX // creates a physical DBF at the path set by your app
When using functions like DbCreate(), DbExport() and others, the DBE is a parameter - take a look at the docs. You can also use a session object instead of the DBE name, if you want.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

Diego Euri Almanzar
Posts: 114
Joined: Thu Nov 05, 2020 10:51 am
Location: DOMINICAN REPUBLIC

Re: How to create a temporary dbf file by copying the structure of a POSTGRESQL table

#3 Post by Diego Euri Almanzar »

Hello, Tom

Great. Thank you so much. The subject of the temporary file, already works correctly for me.

I notice that these temporary files, I also have to open them with the same VIA that they were created. Therefore, I will have to give a map network driver to the server where they are hosted.

Is there any way to put the name of the server in the default set, so as not to have to do the Map Network Drive, in the client computers or terminals, by putting the name of the server in a set default to, or in another statement ?

Best regards

User avatar
Tom
Posts: 1022
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: How to create a temporary dbf file by copying the structure of a POSTGRESQL table

#4 Post by Tom »

Hi, Diego.

You may use the PG for temporary tables aswell. It's just a little harder to delete them - you have to use a SQL statement for that (DROP TABLE ...). Besides, it's a good idea to get rid of temporary tables. Use arrays or arrays of data objects instead. This is ways faster - and you don't have to deal with files.

I'm not sure if I understand your question. If you have a network path set with SET PATH or SET DEFAULT, this will work even if your database is on a PG server. The location/URL of your server is a part of the connection string you use for the DAC session, so you don't need that elsewhere.

So if you set Set(_SET_DEFAULT,"\\myServer\data\") and you use DbCreate() or DbExport() (COPY TO), your files will be created there. You need to mention the path only if you create tagless single index files (DBFNTX), since OrdCreate() doesn't reflect SET DEFAULT.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

Diego Euri Almanzar
Posts: 114
Joined: Thu Nov 05, 2020 10:51 am
Location: DOMINICAN REPUBLIC

Re: How to create a temporary dbf file by copying the structure of a POSTGRESQL table

#5 Post by Diego Euri Almanzar »

Hello, Tom

As I get more experience with POSTGRESQL, and as I learn to use your excellent suggestions, including DROP TABLE, I must have a shared folder on the server, as I always have.

For this, I have always used Set Default to.

Then I'll use your excellent array recommendation. In the meantime, I'll use temporary files. And for this I will have to make the map network to each terminal or client.

However, if your recommendation of the Set(_SET_DEFAULT,"\\myServer\data\") It works for me, it will be a success, a great thing for me, because it would avoid me giving the physical map network drive to each computer, or client.

Finally, this sentence Set(_SET_DEFAULT,"\\myServer\data\") that you recommend is what I was looking for a long time.

Excellent thanks.

Best regards.

Post Reply