在delphi中在远程系统上执行Postgres查询时获取本地系统路径
我正在开发一个 delphi 7 应用程序,使用 postgres 9 作为数据库。 该应用程序以两种方式工作,它可以连接到
- 本地系统上的 Postgres 数据库
- 远程系统上的 Postgres
在本地和远程 postgres 上,数据库将具有相同数量的表。
我们有一个模块,可以使用 COPY 创建数据库表的备份并将结果写入系统上的文件。 示例
query1:='COPY (Select * from mytable where mycolumn in (2011406)) TO 'C:/Documents and Settings/All Users/Documents/drDir/myfile.bck'WITH BINARY'
Query_dmp_res.SQL.Clear;
Query_dmp_res.SQL.Add(query1) ;
Query_dmp_res.ExecSQL;
路径如果本地系统上不存在,则创建 C:/Documents and Settings/All Users/Documents/drDir
。
由于上述查询是在本地系统上执行的,并且 C:/Documents and Settings/All Users/Documents/drDir/
也存在 与当地人合作时,这很有效。
但问题是当我们连接到远程系统时。查询 'COPY (Select * from mytable where mycolumn in (2011406)) TO 'C:/Documents and Settings/All Users/Documents/drDir/myfile.bck' WITH BINARY'
失败 因为路径 /drDir/
是在本地系统上创建的,而不是在远程系统上创建的。
但即使路径 'C:/Documents and Settings/All Users/Documents/drDir /
存在于远程系统上,文件 /myfile.bck
在远程系统上创建。
谁能告诉我如何
给出我的系统的路径,以便在执行查询后在我的系统上创建文件
/myfile.bck
。 这是如何在查询中指定我的本地系统路径'COPY (Select * from mytable where mycolumn in (2011406)) TO 'myLocalSystemPath/myfile.bck' WITH BINARY'
如何在远程系统上创建用于执行查询的文件目录.
我尝试将路径更改为 'C:\Documents and Settings\All Users\Documents\drDir\
但我收到这个错误
编辑 我试过了
将(从 mytable 中选择 *,其中 mycolumn 在 (2011406) 中)复制到带有二进制的 STDOUT 但如何获取查询结果呢?
im working on a delphi 7 application with postgres 9 as the database.
the application works in two ways, it can connect to the
- Postgres database on local system
- Postgres on the remote system
On both local and remote postgres the database will have the same number of tables.
we have module where we create backup of the datbase tables using COPY
and write the result to a file on the system.
example
query1:='COPY (Select * from mytable where mycolumn in (2011406)) TO 'C:/Documents and Settings/All Users/Documents/drDir/myfile.bck' WITH BINARY'
Query_dmp_res.SQL.Clear;
Query_dmp_res.SQL.Add(query1) ;
Query_dmp_res.ExecSQL;
The path C:/Documents and Settings/All Users/Documents/drDir
is created if not existing on the local system.
As the above query is executed on the local system and the C:/Documents and Settings/All Users/Documents/drDir/
exists also
This works fine when working with a local.
But the problem is when we have connected to the remote system.The query'COPY (Select * from mytable where mycolumn in (2011406)) TO 'C:/Documents and Settings/All Users/Documents/drDir/myfile.bck' WITH BINARY'
Fails as the path /drDir/
is created on the local system and not on the remote system.
But even if the path 'C:/Documents and Settings/All Users/Documents/drDir/
exists on the remote system, the File /myfile.bck
is created on the remote system.
can any one tell me how to
Give the path of my system, so the file
/myfile.bck
is created on my system after the query is executed.
This is How to specify my local system path in the query'COPY (Select * from mytable where mycolumn in (2011406)) TO 'myLocalSystemPath/myfile.bck' WITH BINARY'
How to create the File a directory on the remote system for the query execution.
i tried changing the path as 'C:\Documents and Settings\All Users\Documents\drDir\
but i get this error
EDIT
i tried the
COPY (Select * from mytable where mycolumn in (2011406)) TO STDOUT WITH BINARY
but how to get the result of the query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1)指定文件名时不可能(摘自文档):
不过,下一句话给了你一些想法(这也取决于驱动程序):
2) 这是服务器访问权限的问题,请咨询您的管理员...但请记住,当您在服务器上创建文件夹时,运行 Postgres 的用户应该对该文件夹具有写入权限。
1) not possible when a filename is specified (excerpt from the docs):
The next sentence though gives you some ideas (and that depends on the drivers also):
2) that's a matter of access to the server, check with your administrator... but bear in mind that when you create a folder on the server the user that Postgres runs under should have write access to that folder.