I attached to this mail a new version of the patch both in unified and single file format.
I attached the unit tests for all the new methods too. They are three files: one for pgsqlIsInTransaction(), one for pgsqlCopyFrom* methods and one for pgsqlCopyTo* methods.
I did a typo writing the documentation in my first mail. The typo is about the $fields parameter. It is actually a string (not an array) with field names separated by comma.
If needed, I can write also documentation in a more suitable format for php web site.
The updated documentation of the methods follows.
Any feedback is appreciated.
Thank you in advance,
Denis
pgsqlIsInTransaction()
It uses the native Postgresql functions to check transaction status.
It returns one of the following status codes:
* PDO:GSQL_TRANSACTION_IDLE: connection in idle status
* PDO:GSQL_TRANSACTION_ACTIVE: connection is executing a command
* PDO:GSQL_TRANSACTION_INTRANS: connection is idle in a valid transaction block
* PDO:GSQL_TRANSACTION_INERROR: connection is idle, in a failed transaction block
* PDO:GSQL_TRANSACTION_UNKNOWN: connection is in a bad status
pgsqlCopyFromArray($table,Array $data,$delimiter,$null, Array $fields)
It uses the native Postgresql copy construct to append $data to $table.
It returns boolean.
Parameters:
* (mandatory) $table: table to append data to
* (mandatory) $data: Array of rows with data in table field order
(or as specified in the $fields array). Fields must be separated by $delimiter or by
postgresql standard \t)
* $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N"
* $fields: string with table fields that are specified in $data parameter. Fields are separated by comma
pgsqlCopyFromFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to append $filename contents to $table.
It returns boolean.
Parameters:
* (mandatory) $table: table to append data to.
* (mandatory) $filename: file with contents to append to $table. See Postgresql documentation for the format.
* $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N"
* $fields: string with table fields that are specified in $filename file. Fields are separated by comma
pgsqlCopyToArray($table,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them to an array.
It returns an array of rows or false in case of problems.
The format of the rows into the array is indicated in the $delimiter, $null and $fields parameters.
Parameters:
* (mandatory) $table: table to retrieve data from.
* $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N"
* $fields: string with table fields to include in the row of the array. Fields are separated by comma
pgsqlCopyToFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them into a file.
It returns boolean.
The format of the rows stored into the file is indicated in the $delimiter, $null and $fields parameters.
Parameters:
* (mandatory) $table: table to retrieve data from.
* (mandatory) $filename: file where to store the contents of the table
* $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N"
* $fields: string with table fields to include in the row of the array. Fields are separated by comma
----- Messaggio originale -----
Da: "Ilia Alshanetsky" ilia@prohost.org
A: "Denis Gasparin" denis.gasparin@edistar.com Cc: internals@lists.php.net
Inviato: Martedì, 25 maggio 2010 18:40:09 Oggetto: Re: [PHP-DEV] [PATCH] New PDO methods for PostgreSQL driver
Quoted text · 72 lines
Good reason, I'll review the patch in the next day or two.
On Mon, May 24, 2010 at 5:55 PM, Denis Gasparin < denis.gasparin@edistar.com > wrote:
The copy to/from sql statements accept both as main parameter a filename or stdout/stdin respectively.
The filename represents a file in the database filesystem (apache/php and postgresql must reside on the same machine or share the file via shared filesystem). I quote from the postgresql manual:
<<<
COPY with a file name instructs the PostgreSQL server to directly read from or write to a file. The file must be accessible to the server and the name must be specified from the viewpoint of the (database) server.Because of this "limitation", if you'd like to load a csv file into pgsql via copy command, you must before copy into a shared folder and the issue the copy from filename command. Using the methods added to PDO, you can do it directly from the webserver.
About copying to/from stdin and stdout, PostgreSQL enters a particular status after a copy stdin/stdout command has been issued via sql. These status codes are PGRES_COPY_OUT and PGRES_COPY_IN. When in this status, the only way to interact with the database server is via PQgetCopyData and PQputCopyData.
There are not PDO methods or functions that implements these functions and there is no way to share the connection between PDO driver and old pgsql drivers.
These are the relevant PostgreSQL man pages:
http://www.postgresql.org/docs/8.2/interactive/libpq-copy..html http://www.postgresql.org/docs/8.2/interactive/sql-copy.html
Denis
Denis could you elaborate on what makes use of the COPY code via Sql behave differently then a PHP method call?
Ilia Alshanetsky
CIO/CSO Centah Inc.On 2010-05-24, at 15:45, Denis Gasparin < denis.gasparin@edistar.com
wrote:
I'll provide the patches in a single file as soon as possible..
Actually all the methods are wrappers against the native PostgreSQL commands (connection status, copy to/from).
I needed to develop them as methods because it is not possible to get the same results with a sql statement (in particular for connection status).
It was not possible also for COPY TO/FROM because of the way PostgreSQL handle them ( special functions were developed also for the old pgsql driver).
We are currently using them in production and we needed them in order to avoid additional connections to database (one with the old driver and one with PDO).
Denis
----- Messaggio originale -----
Da: "Ilia Alshanetsky" < ilia@prohost.org > A: "Denis Gasparin" < denis.gasparin@edistar.com > Cc: internals@lists.php.net
Inviato: Lunedì, 24 maggio 2010 19:54:46 Oggetto: Re: [PHP-DEV] [PATCH] New PDO methods for PostgreSQL driverDenis,
Could you merge the patches into a single for easier code review. Also, the copy to/from file seems like it would just be a wrapper against the native COPY PostgreSQL command, is there really a need to provide a method for it?
On Mon, May 24, 2010 at 4:57 AM, Denis Gasparin < denis.gasparin@edistar.com > wrote:
Hi.
I developed some patches for PDO/Postgresql driver in order to add some useful methods that were available in the original pgsql driver.
The attached patches apply on 5.3.2 and svn 5.3.x. If needed, i have patches also for 5.2.x.
Please comment and tell me improvements or tips.
Thank you in advance,
Denis Gasparin
Documentation of the added methods follows:
pgsqlIsInTransaction()
It uses the native Postgresql functions to check transaction status..
It returns one of the following status codes:
- PDO::PGSQL_TRANSACTION_IDLE: connection in idle status
- PDO::PGSQL_TRANSACTION_ACTIVE: connection is executing a command * PDO::PGSQL_TRANSACTION_INTRANS: connection is idle in a valid transaction block
- PDO::PGSQL_TRANSACTION_INERROR: connection is idle, in a failed transaction block
- PDO::PGSQL_TRANSACTION_UNKNOWN: connection is in a bad status
pgsqlCopyFromArray($table,Array $data,$delimiter,$null, Array $fields)
It uses the native Postgresql copy construct to append $data to $table. It returns boolean.
Parameters: * (mandatory) $table: table to append data to
- (mandatory) $data: Array of rows with data in table field order (or as specified in the $fields array). Fields must be separated by $delimiter or by
postgresql standard \t)- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields that are specified in $data parameter
pgsqlCopyFromFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to append $filename contents to $table.
It returns boolean.
Parameters: * (mandatory) $table: table to append data to.
- (mandatory) $filename: file with contents to append to $table. See Postgresql documentation for the format.
- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields that are specified in $filename file
pgsqlCopyToArray($table,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them to an array.
It returns an array of rows or false in case of problems. The format of the rows into the array is indicated in the $delimiter, $null and $fields parameters. Parameters: * (mandatory) $table: table to retrieve data from..
- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields to include in the row of the array.
pgsqlCopyToFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them into a file.
It returns boolean.
The format of the rows stored into the file is indicated in the $delimiter, $null and $fields parameters. Parameters: * (mandatory) $table: table to retrieve data from..
- (mandatory) $filename: file where to store the contents of the table * $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields to include in the row of the array.
Denis,
I've cleaned up the patch, fixing whitespace, a few memory leaks and optimized the copy from array code. The code for the copy to/from array/file was just committed.
I am still reviewing the inTransaction code, since that is something I think can probably be generic and not database specific.
On Wed, May 26, 2010 at 1:11 PM, Denis Gasparin denis.gasparin@edistar.comwrote:
Quoted text · 115 lines
I attached to this mail a new version of the patch both in unified and single file format.
I attached the unit tests for all the new methods too. They are three files: one for pgsqlIsInTransaction(), one for pgsqlCopyFrom* methods and one for pgsqlCopyTo* methods.
I did a typo writing the documentation in my first mail. The typo is about the $fields parameter.
It is actually a string (not an array) with field names separated by comma.If needed, I can write also documentation in a more suitable format for php web site.
The updated documentation of the methods follows.
Any feedback is appreciated.
Thank you in advance,
DenispgsqlIsInTransaction()
It uses the native Postgresql functions to check transaction status. It returns one of the following status codes: * PDO:GSQL_TRANSACTION_IDLE: connection in idle status * PDO:GSQL_TRANSACTION_ACTIVE: connection is executing a command * PDO:GSQL_TRANSACTION_INTRANS: connection is idle in a valid transaction block
* PDO:GSQL_TRANSACTION_INERROR: connection is idle, in a failed transaction block
* PDO:GSQL_TRANSACTION_UNKNOWN: connection is in a bad statuspgsqlCopyFromArray($table,Array $data,$delimiter,$null, Array $fields)
It uses the native Postgresql copy construct to append $data to $table. It returns boolean.
Parameters:
* (mandatory) $table: table to append data to * (mandatory) $data: Array of rows with data in table field order (or as specified in the $fields array). Fields must be separated by $delimiter or by
postgresql standard \t)
* $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields that are specified in $data parameter. Fields are separated by commapgsqlCopyFromFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to append $filename contents to $table.
It returns boolean.
Parameters:
* (mandatory) $table: table to append data to. * (mandatory) $filename: file with contents to append to $table. See Postgresql documentation for the format. * $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields that are specified in $filename file. Fields are separated by commapgsqlCopyToArray($table,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them to an array.
It returns an array of rows or false in case of problems. The format of the rows into the array is indicated in the $delimiter, $null and $fields parameters.
Parameters:
* (mandatory) $table: table to retrieve data from. * $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields to include in the row of the array. Fields are separated by commapgsqlCopyToFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them into a file.
It returns boolean.
The format of the rows stored into the file is indicated in the $delimiter, $null and $fields parameters. Parameters:
* (mandatory) $table: table to retrieve data from. * (mandatory) $filename: file where to store the contents of the table
* $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields to include in the row of the array. Fields are separated by comma----- Messaggio originale -----
Da: "Ilia Alshanetsky" ilia@prohost.org
A: "Denis Gasparin" denis.gasparin@edistar.com Cc: internals@lists.php.net
Inviato: Martedì, 25 maggio 2010 18:40:09 Oggetto: Re: [PHP-DEV] [PATCH] New PDO methods for PostgreSQL driverGood reason, I'll review the patch in the next day or two.
On Mon, May 24, 2010 at 5:55 PM, Denis Gasparin < denis.gasparin@edistar.com > wrote:
The copy to/from sql statements accept both as main parameter a filename or stdout/stdin respectively.
The filename represents a file in the database filesystem (apache/php and postgresql must reside on the same machine or share the file via shared filesystem). I quote from the postgresql manual:
<<<
COPY with a file name instructs the PostgreSQL server to directly read from or write to a file. The file must be accessible to the server and the name must be specified from the viewpoint of the (database) server.Because of this "limitation", if you'd like to load a csv file into pgsql via copy command, you must before copy into a shared folder and the issue the copy from filename command. Using the methods added to PDO, you can do it directly from the webserver.
About copying to/from stdin and stdout, PostgreSQL enters a particular status after a copy stdin/stdout command has been issued via sql. These status codes are PGRES_COPY_OUT and PGRES_COPY_IN. When in this status, the only way to interact with the database server is via PQgetCopyData and PQputCopyData.
There are not PDO methods or functions that implements these functions and there is no way to share the connection between PDO driver and old pgsql drivers.
These are the relevant PostgreSQL man pages:
http://www.postgresql.org/docs/8.2/interactive/libpq-copy..html http://www.postgresql.org/docs/8.2/interactive/sql-copy.html
Denis
Denis could you elaborate on what makes use of the COPY code via Sql behave differently then a PHP method call?
Ilia Alshanetsky
CIO/CSO Centah Inc.On 2010-05-24, at 15:45, Denis Gasparin < denis.gasparin@edistar.com
wrote:
I'll provide the patches in a single file as soon as possible..
Actually all the methods are wrappers against the native PostgreSQL commands (connection status, copy to/from).
I needed to develop them as methods because it is not possible to get the same results with a sql statement (in particular for connection status).
It was not possible also for COPY TO/FROM because of the way PostgreSQL handle them ( special functions were developed also for the old pgsql driver).
We are currently using them in production and we needed them in order to avoid additional connections to database (one with the old driver and one with PDO).
Denis
----- Messaggio originale -----
Da: "Ilia Alshanetsky" < ilia@prohost.org > A: "Denis Gasparin" < denis.gasparin@edistar.com > Cc: internals@lists.php.net
Inviato: Lunedì, 24 maggio 2010 19:54:46 Oggetto: Re: [PHP-DEV] [PATCH] New PDO methods for PostgreSQL driverDenis,
Could you merge the patches into a single for easier code review. Also, the copy to/from file seems like it would just be a wrapper against the native COPY PostgreSQL command, is there really a need to provide a method for it?
On Mon, May 24, 2010 at 4:57 AM, Denis Gasparin < denis.gasparin@edistar.com > wrote:
Hi.
I developed some patches for PDO/Postgresql driver in order to add some useful methods that were available in the original pgsql driver.
The attached patches apply on 5.3.2 and svn 5.3.x. If needed, i have patches also for 5.2.x.
Please comment and tell me improvements or tips.
Thank you in advance,
Denis Gasparin
Documentation of the added methods follows:
pgsqlIsInTransaction()
It uses the native Postgresql functions to check transaction status..
It returns one of the following status codes:
- PDO::PGSQL_TRANSACTION_IDLE: connection in idle status
- PDO::PGSQL_TRANSACTION_ACTIVE: connection is executing a command * PDO::PGSQL_TRANSACTION_INTRANS: connection is idle in a valid transaction block
- PDO::PGSQL_TRANSACTION_INERROR: connection is idle, in a failed transaction block
- PDO::PGSQL_TRANSACTION_UNKNOWN: connection is in a bad status
pgsqlCopyFromArray($table,Array $data,$delimiter,$null, Array $fields)
It uses the native Postgresql copy construct to append $data to $table. It returns boolean.
Parameters: * (mandatory) $table: table to append data to
- (mandatory) $data: Array of rows with data in table field order (or as specified in the $fields array). Fields must be separated by $delimiter or by
postgresql standard \t)- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields that are specified in $data parameter
pgsqlCopyFromFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to append $filename contents to $table.
It returns boolean.
Parameters: * (mandatory) $table: table to append data to.
- (mandatory) $filename: file with contents to append to $table. See Postgresql documentation for the format.
- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields that are specified in $filename file
pgsqlCopyToArray($table,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them to an array.
It returns an array of rows or false in case of problems. The format of the rows into the array is indicated in the $delimiter, $null and $fields parameters. Parameters: * (mandatory) $table: table to retrieve data from..
- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields to include in the row of the array.
pgsqlCopyToFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them into a file.
It returns boolean.
The format of the rows stored into the file is indicated in the $delimiter, $null and $fields parameters. Parameters: * (mandatory) $table: table to retrieve data from..
- (mandatory) $filename: file where to store the contents of the table * $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields to include in the row of the array.
I've added the transaction code as a generic method inTransaction(), by default it'll just use in_txn internal parameter, but allows the driver to extend this (as was done in PostgreSQL) and provide a detailed status code.
On Wed, May 26, 2010 at 1:11 PM, Denis Gasparin denis.gasparin@edistar.comwrote:
Quoted text · 115 lines
I attached to this mail a new version of the patch both in unified and single file format.
I attached the unit tests for all the new methods too. They are three files: one for pgsqlIsInTransaction(), one for pgsqlCopyFrom* methods and one for pgsqlCopyTo* methods.
I did a typo writing the documentation in my first mail. The typo is about the $fields parameter.
It is actually a string (not an array) with field names separated by comma.If needed, I can write also documentation in a more suitable format for php web site.
The updated documentation of the methods follows.
Any feedback is appreciated.
Thank you in advance,
DenispgsqlIsInTransaction()
It uses the native Postgresql functions to check transaction status. It returns one of the following status codes: * PDO:GSQL_TRANSACTION_IDLE: connection in idle status * PDO:GSQL_TRANSACTION_ACTIVE: connection is executing a command * PDO:GSQL_TRANSACTION_INTRANS: connection is idle in a valid transaction block
* PDO:GSQL_TRANSACTION_INERROR: connection is idle, in a failed transaction block
* PDO:GSQL_TRANSACTION_UNKNOWN: connection is in a bad statuspgsqlCopyFromArray($table,Array $data,$delimiter,$null, Array $fields)
It uses the native Postgresql copy construct to append $data to $table. It returns boolean.
Parameters:
* (mandatory) $table: table to append data to * (mandatory) $data: Array of rows with data in table field order (or as specified in the $fields array). Fields must be separated by $delimiter or by
postgresql standard \t)
* $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields that are specified in $data parameter. Fields are separated by commapgsqlCopyFromFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to append $filename contents to $table.
It returns boolean.
Parameters:
* (mandatory) $table: table to append data to. * (mandatory) $filename: file with contents to append to $table. See Postgresql documentation for the format. * $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields that are specified in $filename file. Fields are separated by commapgsqlCopyToArray($table,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them to an array.
It returns an array of rows or false in case of problems. The format of the rows into the array is indicated in the $delimiter, $null and $fields parameters.
Parameters:
* (mandatory) $table: table to retrieve data from. * $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields to include in the row of the array. Fields are separated by commapgsqlCopyToFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them into a file.
It returns boolean.
The format of the rows stored into the file is indicated in the $delimiter, $null and $fields parameters. Parameters:
* (mandatory) $table: table to retrieve data from. * (mandatory) $filename: file where to store the contents of the table
* $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields to include in the row of the array. Fields are separated by comma----- Messaggio originale -----
Da: "Ilia Alshanetsky" ilia@prohost.org
A: "Denis Gasparin" denis.gasparin@edistar.com Cc: internals@lists.php.net
Inviato: Martedì, 25 maggio 2010 18:40:09 Oggetto: Re: [PHP-DEV] [PATCH] New PDO methods for PostgreSQL driverGood reason, I'll review the patch in the next day or two.
On Mon, May 24, 2010 at 5:55 PM, Denis Gasparin < denis.gasparin@edistar.com > wrote:
The copy to/from sql statements accept both as main parameter a filename or stdout/stdin respectively.
The filename represents a file in the database filesystem (apache/php and postgresql must reside on the same machine or share the file via shared filesystem). I quote from the postgresql manual:
<<<
COPY with a file name instructs the PostgreSQL server to directly read from or write to a file. The file must be accessible to the server and the name must be specified from the viewpoint of the (database) server.Because of this "limitation", if you'd like to load a csv file into pgsql via copy command, you must before copy into a shared folder and the issue the copy from filename command. Using the methods added to PDO, you can do it directly from the webserver.
About copying to/from stdin and stdout, PostgreSQL enters a particular status after a copy stdin/stdout command has been issued via sql. These status codes are PGRES_COPY_OUT and PGRES_COPY_IN. When in this status, the only way to interact with the database server is via PQgetCopyData and PQputCopyData.
There are not PDO methods or functions that implements these functions and there is no way to share the connection between PDO driver and old pgsql drivers.
These are the relevant PostgreSQL man pages:
http://www.postgresql.org/docs/8.2/interactive/libpq-copy..html http://www.postgresql.org/docs/8.2/interactive/sql-copy.html
Denis
Denis could you elaborate on what makes use of the COPY code via Sql behave differently then a PHP method call?
Ilia Alshanetsky
CIO/CSO Centah Inc.On 2010-05-24, at 15:45, Denis Gasparin < denis.gasparin@edistar.com
wrote:
I'll provide the patches in a single file as soon as possible..
Actually all the methods are wrappers against the native PostgreSQL commands (connection status, copy to/from).
I needed to develop them as methods because it is not possible to get the same results with a sql statement (in particular for connection status).
It was not possible also for COPY TO/FROM because of the way PostgreSQL handle them ( special functions were developed also for the old pgsql driver).
We are currently using them in production and we needed them in order to avoid additional connections to database (one with the old driver and one with PDO).
Denis
----- Messaggio originale -----
Da: "Ilia Alshanetsky" < ilia@prohost.org > A: "Denis Gasparin" < denis.gasparin@edistar.com > Cc: internals@lists.php.net
Inviato: Lunedì, 24 maggio 2010 19:54:46 Oggetto: Re: [PHP-DEV] [PATCH] New PDO methods for PostgreSQL driverDenis,
Could you merge the patches into a single for easier code review. Also, the copy to/from file seems like it would just be a wrapper against the native COPY PostgreSQL command, is there really a need to provide a method for it?
On Mon, May 24, 2010 at 4:57 AM, Denis Gasparin < denis.gasparin@edistar.com > wrote:
Hi.
I developed some patches for PDO/Postgresql driver in order to add some useful methods that were available in the original pgsql driver.
The attached patches apply on 5.3.2 and svn 5.3.x. If needed, i have patches also for 5.2.x.
Please comment and tell me improvements or tips.
Thank you in advance,
Denis Gasparin
Documentation of the added methods follows:
pgsqlIsInTransaction()
It uses the native Postgresql functions to check transaction status..
It returns one of the following status codes:
- PDO::PGSQL_TRANSACTION_IDLE: connection in idle status
- PDO::PGSQL_TRANSACTION_ACTIVE: connection is executing a command * PDO::PGSQL_TRANSACTION_INTRANS: connection is idle in a valid transaction block
- PDO::PGSQL_TRANSACTION_INERROR: connection is idle, in a failed transaction block
- PDO::PGSQL_TRANSACTION_UNKNOWN: connection is in a bad status
pgsqlCopyFromArray($table,Array $data,$delimiter,$null, Array $fields)
It uses the native Postgresql copy construct to append $data to $table. It returns boolean.
Parameters: * (mandatory) $table: table to append data to
- (mandatory) $data: Array of rows with data in table field order (or as specified in the $fields array). Fields must be separated by $delimiter or by
postgresql standard \t)- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields that are specified in $data parameter
pgsqlCopyFromFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to append $filename contents to $table.
It returns boolean.
Parameters: * (mandatory) $table: table to append data to.
- (mandatory) $filename: file with contents to append to $table. See Postgresql documentation for the format.
- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields that are specified in $filename file
pgsqlCopyToArray($table,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them to an array.
It returns an array of rows or false in case of problems. The format of the rows into the array is indicated in the $delimiter, $null and $fields parameters. Parameters: * (mandatory) $table: table to retrieve data from..
- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields to include in the row of the array.
pgsqlCopyToFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them into a file.
It returns boolean.
The format of the rows stored into the file is indicated in the $delimiter, $null and $fields parameters. Parameters: * (mandatory) $table: table to retrieve data from..
- (mandatory) $filename: file where to store the contents of the table * $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields to include in the row of the array.
hi Ilia,
So you basically say that the worries and wishes raised here are simply irrelevant and at the end of the day you decide what PDO can or cannot be?
I'm very disappointed by these two commits. I don't think it is the way we should develop PDO and it is clear that I'm not the only one to think that. As it is trunk, I won't battle too much to revert it but be sure that is not something I will let in for any of the upcoming releases as it is clearly bad design.
Cheers,
Pierre
Quoted text · 118 lines
I've added the transaction code as a generic method inTransaction(), by default it'll just use in_txn internal parameter, but allows the driver to extend this (as was done in PostgreSQL) and provide a detailed status code.
On Wed, May 26, 2010 at 1:11 PM, Denis Gasparin denis.gasparin@edistar.comwrote:
I attached to this mail a new version of the patch both in unified and single file format.
I attached the unit tests for all the new methods too. They are three files: one for pgsqlIsInTransaction(), one for pgsqlCopyFrom* methods and one for pgsqlCopyTo* methods.
I did a typo writing the documentation in my first mail. The typo is about the $fields parameter.
It is actually a string (not an array) with field names separated by comma.If needed, I can write also documentation in a more suitable format for php web site.
The updated documentation of the methods follows.
Any feedback is appreciated.
Thank you in advance,
DenispgsqlIsInTransaction()
It uses the native Postgresql functions to check transaction status. It returns one of the following status codes: * PDO:GSQL_TRANSACTION_IDLE: connection in idle status * PDO:GSQL_TRANSACTION_ACTIVE: connection is executing a command * PDO:GSQL_TRANSACTION_INTRANS: connection is idle in a valid transaction block
* PDO:GSQL_TRANSACTION_INERROR: connection is idle, in a failed transaction block
* PDO:GSQL_TRANSACTION_UNKNOWN: connection is in a bad statuspgsqlCopyFromArray($table,Array $data,$delimiter,$null, Array $fields)
It uses the native Postgresql copy construct to append $data to $table. It returns boolean.
Parameters:
* (mandatory) $table: table to append data to * (mandatory) $data: Array of rows with data in table field order (or as specified in the $fields array). Fields must be separated by $delimiter or by
postgresql standard \t)
* $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields that are specified in $data parameter. Fields are separated by commapgsqlCopyFromFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to append $filename contents to $table.
It returns boolean.
Parameters:
* (mandatory) $table: table to append data to. * (mandatory) $filename: file with contents to append to $table. See Postgresql documentation for the format. * $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields that are specified in $filename file. Fields are separated by commapgsqlCopyToArray($table,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them to an array.
It returns an array of rows or false in case of problems. The format of the rows into the array is indicated in the $delimiter, $null and $fields parameters.
Parameters:
* (mandatory) $table: table to retrieve data from. * $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields to include in the row of the array. Fields are separated by commapgsqlCopyToFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them into a file.
It returns boolean.
The format of the rows stored into the file is indicated in the $delimiter, $null and $fields parameters. Parameters:
* (mandatory) $table: table to retrieve data from. * (mandatory) $filename: file where to store the contents of the table
* $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields to include in the row of the array. Fields are separated by comma----- Messaggio originale -----
Da: "Ilia Alshanetsky" ilia@prohost.org
A: "Denis Gasparin" denis.gasparin@edistar.com Cc: internals@lists.php.net
Inviato: Martedì, 25 maggio 2010 18:40:09 Oggetto: Re: [PHP-DEV] [PATCH] New PDO methods for PostgreSQL driverGood reason, I'll review the patch in the next day or two.
On Mon, May 24, 2010 at 5:55 PM, Denis Gasparin < denis.gasparin@edistar.com > wrote:
The copy to/from sql statements accept both as main parameter a filename or stdout/stdin respectively.
The filename represents a file in the database filesystem (apache/php and postgresql must reside on the same machine or share the file via shared filesystem). I quote from the postgresql manual:
<<<
COPY with a file name instructs the PostgreSQL server to directly read from or write to a file. The file must be accessible to the server and the name must be specified from the viewpoint of the (database) server.Because of this "limitation", if you'd like to load a csv file into pgsql via copy command, you must before copy into a shared folder and the issue the copy from filename command. Using the methods added to PDO, you can do it directly from the webserver.
About copying to/from stdin and stdout, PostgreSQL enters a particular status after a copy stdin/stdout command has been issued via sql. These status codes are PGRES_COPY_OUT and PGRES_COPY_IN. When in this status, the only way to interact with the database server is via PQgetCopyData and PQputCopyData.
There are not PDO methods or functions that implements these functions and there is no way to share the connection between PDO driver and old pgsql drivers.
These are the relevant PostgreSQL man pages:
http://www.postgresql.org/docs/8.2/interactive/libpq-copy..html http://www.postgresql.org/docs/8.2/interactive/sql-copy.html
Denis
Denis could you elaborate on what makes use of the COPY code via Sql behave differently then a PHP method call?
Ilia Alshanetsky
CIO/CSO Centah Inc.On 2010-05-24, at 15:45, Denis Gasparin < denis.gasparin@edistar.com
wrote:
I'll provide the patches in a single file as soon as possible..
Actually all the methods are wrappers against the native PostgreSQL commands (connection status, copy to/from).
I needed to develop them as methods because it is not possible to get the same results with a sql statement (in particular for connection status).
It was not possible also for COPY TO/FROM because of the way PostgreSQL handle them ( special functions were developed also for the old pgsql driver).
We are currently using them in production and we needed them in order to avoid additional connections to database (one with the old driver and one with PDO).
Denis
----- Messaggio originale -----
Da: "Ilia Alshanetsky" < ilia@prohost.org > A: "Denis Gasparin" < denis.gasparin@edistar.com > Cc: internals@lists.php.net
Inviato: Lunedì, 24 maggio 2010 19:54:46 Oggetto: Re: [PHP-DEV] [PATCH] New PDO methods for PostgreSQL driverDenis,
Could you merge the patches into a single for easier code review. Also, the copy to/from file seems like it would just be a wrapper against the native COPY PostgreSQL command, is there really a need to provide a method for it?
On Mon, May 24, 2010 at 4:57 AM, Denis Gasparin < denis.gasparin@edistar.com > wrote:
Hi.
I developed some patches for PDO/Postgresql driver in order to add some useful methods that were available in the original pgsql driver.
The attached patches apply on 5.3.2 and svn 5.3.x. If needed, i have patches also for 5.2.x.
Please comment and tell me improvements or tips.
Thank you in advance,
Denis Gasparin
Documentation of the added methods follows:
pgsqlIsInTransaction()
It uses the native Postgresql functions to check transaction status..
It returns one of the following status codes:
- PDO::PGSQL_TRANSACTION_IDLE: connection in idle status
- PDO::PGSQL_TRANSACTION_ACTIVE: connection is executing a command * PDO::PGSQL_TRANSACTION_INTRANS: connection is idle in a valid transaction block
- PDO::PGSQL_TRANSACTION_INERROR: connection is idle, in a failed transaction block
- PDO::PGSQL_TRANSACTION_UNKNOWN: connection is in a bad status
pgsqlCopyFromArray($table,Array $data,$delimiter,$null, Array $fields)
It uses the native Postgresql copy construct to append $data to $table. It returns boolean.
Parameters: * (mandatory) $table: table to append data to
- (mandatory) $data: Array of rows with data in table field order (or as specified in the $fields array). Fields must be separated by $delimiter or by
postgresql standard \t)- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields that are specified in $data parameter
pgsqlCopyFromFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to append $filename contents to $table.
It returns boolean.
Parameters: * (mandatory) $table: table to append data to.
- (mandatory) $filename: file with contents to append to $table. See Postgresql documentation for the format.
- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields that are specified in $filename file
pgsqlCopyToArray($table,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them to an array.
It returns an array of rows or false in case of problems. The format of the rows into the array is indicated in the $delimiter, $null and $fields parameters. Parameters: * (mandatory) $table: table to retrieve data from..
- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields to include in the row of the array.
pgsqlCopyToFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them into a file.
It returns boolean.
The format of the rows stored into the file is indicated in the $delimiter, $null and $fields parameters. Parameters: * (mandatory) $table: table to retrieve data from..
- (mandatory) $filename: file where to store the contents of the table * $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields to include in the row of the array.
--
--
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Same, I am disappointed to see this committed still after the concerns raised here.
- Jon
Quoted text · 141 lines
hi Ilia,
So you basically say that the worries and wishes raised here are simply irrelevant and at the end of the day you decide what PDO can or cannot be?
I'm very disappointed by these two commits. I don't think it is the way we should develop PDO and it is clear that I'm not the only one to think that. As it is trunk, I won't battle too much to revert it but be sure that is not something I will let in for any of the upcoming releases as it is clearly bad design.
Cheers,
Pierre
On Thu, Jun 10, 2010 at 2:12 PM, Ilia Alshanetsky ilia@prohost.org wrote:
I've added the transaction code as a generic method inTransaction(), by default it'll just use in_txn internal parameter, but allows the driver to
extend this (as was done in PostgreSQL) and provide a detailed status code.On Wed, May 26, 2010 at 1:11 PM, Denis Gasparin denis.gasparin@edistar.comwrote:
I attached to this mail a new version of the patch both in unified and single file format.
I attached the unit tests for all the new methods too. They are three files: one for pgsqlIsInTransaction(), one for pgsqlCopyFrom* methods and one for pgsqlCopyTo* methods.
I did a typo writing the documentation in my first mail. The typo is about
the $fields parameter.
It is actually a string (not an array) with field names separated by comma.If needed, I can write also documentation in a more suitable format for php
web site.The updated documentation of the methods follows.
Any feedback is appreciated.
Thank you in advance,
DenispgsqlIsInTransaction()
It uses the native Postgresql functions to check transaction status. It returns one of the following status codes: * PDO:GSQL_TRANSACTION_IDLE: connection in idle status * PDO:GSQL_TRANSACTION_ACTIVE: connection is executing a command * PDO:GSQL_TRANSACTION_INTRANS: connection is idle in a valid transaction block
* PDO:GSQL_TRANSACTION_INERROR: connection is idle, in a failed transaction block
* PDO:GSQL_TRANSACTION_UNKNOWN: connection is in a bad statuspgsqlCopyFromArray($table,Array $data,$delimiter,$null, Array $fields)
It uses the native Postgresql copy construct to append $data to $table.
It returns boolean.
Parameters:
* (mandatory) $table: table to append data to * (mandatory) $data: Array of rows with data in table field order (or as specified in the $fields array). Fields must be separated by $delimiter or by
postgresql standard \t)
* $delimiter: alternative delimiter to use in place of the standard
postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields that are specified in $data parameter. Fields are separated by commapgsqlCopyFromFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to append $filename contents to $table.
It returns boolean.
Parameters:
* (mandatory) $table: table to append data to. * (mandatory) $filename: file with contents to append to $table. See
Postgresql documentation for the format. * $delimiter: alternative delimiter to use in place of the standard
postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields that are specified in $filename
file. Fields are separated by commapgsqlCopyToArray($table,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents
and store them to an array.
It returns an array of rows or false in case of problems. The format of the rows into the array is indicated in the $delimiter, $null and $fields parameters.
Parameters:
* (mandatory) $table: table to retrieve data from. * $delimiter: alternative delimiter to use in place of the standard
postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields to include in the row of the array. Fields are separated by commapgsqlCopyToFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents
and store them into a file.
It returns boolean.
The format of the rows stored into the file is indicated in the $delimiter, $null and $fields parameters. Parameters:
* (mandatory) $table: table to retrieve data from. * (mandatory) $filename: file where to store the contents of the table
* $delimiter: alternative delimiter to use in place of the standard
postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields to include in the row of the array. Fields are separated by comma----- Messaggio originale -----
Da: "Ilia Alshanetsky" ilia@prohost.org
A: "Denis Gasparin" denis.gasparin@edistar.com Cc: internals@lists.php.net
Inviato: Martedì, 25 maggio 2010 18:40:09 Oggetto: Re: [PHP-DEV] [PATCH] New PDO methods for PostgreSQL driverGood reason, I'll review the patch in the next day or two.
On Mon, May 24, 2010 at 5:55 PM, Denis Gasparin < denis.gasparin@edistar.com > wrote:
The copy to/from sql statements accept both as main parameter a filename or stdout/stdin respectively.
The filename represents a file in the database filesystem (apache/php and postgresql must reside on the same machine or share the file via shared filesystem). I quote from the postgresql manual:
<<<
COPY with a file name instructs the PostgreSQL server to directly read from or write to a file. The file must be accessible to the server and the name must be specified from the viewpoint of the (database) server.Because of this "limitation", if you'd like to load a csv file into pgsql via copy command, you must before copy into a shared folder and the issue the copy from filename command. Using the methods added to PDO, you can do it directly from the webserver.
About copying to/from stdin and stdout, PostgreSQL enters a particular status after a copy stdin/stdout command has been issued via sql. These status codes are PGRES_COPY_OUT and PGRES_COPY_IN. When in this status, the only way to interact with the database server is via PQgetCopyData and PQputCopyData.
There are not PDO methods or functions that implements these functions and there is no way to share the connection between PDO driver and old pgsql drivers.
These are the relevant PostgreSQL man pages:
http://www.postgresql.org/docs/8.2/interactive/libpq-copy..html http://www.postgresql.org/docs/8.2/interactive/sql-copy.html
Denis
Denis could you elaborate on what makes use of the COPY code via Sql behave differently then a PHP method call?
Ilia Alshanetsky
CIO/CSO Centah Inc.On 2010-05-24, at 15:45, Denis Gasparin < denis.gasparin@edistar.com
wrote:
I'll provide the patches in a single file as soon as possible..
Actually all the methods are wrappers against the native PostgreSQL commands (connection status, copy to/from).
I needed to develop them as methods because it is not possible to get the same results with a sql statement (in particular for connection status).
It was not possible also for COPY TO/FROM because of the way PostgreSQL handle them ( special functions were developed also for the old pgsql driver).
We are currently using them in production and we needed them in order to avoid additional connections to database (one with the old driver and one with PDO).
Denis
----- Messaggio originale -----
Da: "Ilia Alshanetsky" < ilia@prohost.org > A: "Denis Gasparin" < denis.gasparin@edistar.com > Cc: internals@lists.php.net
Inviato: Lunedì, 24 maggio 2010 19:54:46 Oggetto: Re: [PHP-DEV] [PATCH] New PDO methods for PostgreSQL driverDenis,
Could you merge the patches into a single for easier code review. Also, the copy to/from file seems like it would just be a wrapper against the native COPY PostgreSQL command, is there really a need to provide a method for it?
On Mon, May 24, 2010 at 4:57 AM, Denis Gasparin < denis.gasparin@edistar.com > wrote:
Hi.
I developed some patches for PDO/Postgresql driver in order to add some useful methods that were available in the original pgsql driver.
The attached patches apply on 5.3.2 and svn 5.3.x. If needed, i have patches also for 5.2.x.
Please comment and tell me improvements or tips.
Thank you in advance,
Denis Gasparin
Documentation of the added methods follows:
pgsqlIsInTransaction()
It uses the native Postgresql functions to check transaction status..
It returns one of the following status codes:
- PDO::PGSQL_TRANSACTION_IDLE: connection in idle status
- PDO::PGSQL_TRANSACTION_ACTIVE: connection is executing a command * PDO::PGSQL_TRANSACTION_INTRANS: connection is idle in a valid transaction block
- PDO::PGSQL_TRANSACTION_INERROR: connection is idle, in a failed transaction block
- PDO::PGSQL_TRANSACTION_UNKNOWN: connection is in a bad status
pgsqlCopyFromArray($table,Array $data,$delimiter,$null, Array $fields)
It uses the native Postgresql copy construct to append $data to $table. It returns boolean.
Parameters: * (mandatory) $table: table to append data to
- (mandatory) $data: Array of rows with data in table field order (or as specified in the $fields array). Fields must be separated by $delimiter or by
postgresql standard \t)- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields that are specified in $data parameter
pgsqlCopyFromFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to append $filename contents to $table.
It returns boolean.
Parameters: * (mandatory) $table: table to append data to.
- (mandatory) $filename: file with contents to append to $table. See Postgresql documentation for the format.
- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields that are specified in $filename file
pgsqlCopyToArray($table,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them to an array.
It returns an array of rows or false in case of problems. The format of the rows into the array is indicated in the $delimiter, $null and $fields parameters. Parameters: * (mandatory) $table: table to retrieve data from..
- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields to include in the row of the array.
pgsqlCopyToFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them into a file.
It returns boolean.
The format of the rows stored into the file is indicated in the $delimiter, $null and $fields parameters. Parameters: * (mandatory) $table: table to retrieve data from..
- (mandatory) $filename: file where to store the contents of the table * $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields to include in the row of the array.
--
--
Pierre@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
--
PDO Working Group Mailing List (http://pdo.php.net)
--
Jonathan H. Wage
http://www.twitter.com/jwage
The concerns you raised about custom methods specific to database drivers were not reflective of the PDO's intent as was clarified by Wez and myself.
The code that was introduced was specific to PostgreSQL, the common functionality was introduced in a way that allows each driver to implement.
Quoted text · 139 lines
hi Ilia,
So you basically say that the worries and wishes raised here are simply irrelevant and at the end of the day you decide what PDO can or cannot be?
I'm very disappointed by these two commits. I don't think it is the way we should develop PDO and it is clear that I'm not the only one to think that. As it is trunk, I won't battle too much to revert it but be sure that is not something I will let in for any of the upcoming releases as it is clearly bad design.
Cheers,
Pierre
On Thu, Jun 10, 2010 at 2:12 PM, Ilia Alshanetsky ilia@prohost.org wrote:
I've added the transaction code as a generic method inTransaction(), by default it'll just use in_txn internal parameter, but allows the driver to
extend this (as was done in PostgreSQL) and provide a detailed status code.On Wed, May 26, 2010 at 1:11 PM, Denis Gasparin denis.gasparin@edistar.comwrote:
I attached to this mail a new version of the patch both in unified and single file format.
I attached the unit tests for all the new methods too. They are three files: one for pgsqlIsInTransaction(), one for pgsqlCopyFrom* methods and one for pgsqlCopyTo* methods.
I did a typo writing the documentation in my first mail. The typo is about
the $fields parameter.
It is actually a string (not an array) with field names separated by comma.If needed, I can write also documentation in a more suitable format for php
web site.The updated documentation of the methods follows.
Any feedback is appreciated.
Thank you in advance,
DenispgsqlIsInTransaction()
It uses the native Postgresql functions to check transaction status. It returns one of the following status codes: * PDO:GSQL_TRANSACTION_IDLE: connection in idle status * PDO:GSQL_TRANSACTION_ACTIVE: connection is executing a command * PDO:GSQL_TRANSACTION_INTRANS: connection is idle in a valid transaction block
* PDO:GSQL_TRANSACTION_INERROR: connection is idle, in a failed transaction block
* PDO:GSQL_TRANSACTION_UNKNOWN: connection is in a bad statuspgsqlCopyFromArray($table,Array $data,$delimiter,$null, Array $fields)
It uses the native Postgresql copy construct to append $data to $table.
It returns boolean.
Parameters:
* (mandatory) $table: table to append data to * (mandatory) $data: Array of rows with data in table field order (or as specified in the $fields array). Fields must be separated by $delimiter or by
postgresql standard \t)
* $delimiter: alternative delimiter to use in place of the standard
postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields that are specified in $data parameter. Fields are separated by commapgsqlCopyFromFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to append $filename contents to $table.
It returns boolean.
Parameters:
* (mandatory) $table: table to append data to. * (mandatory) $filename: file with contents to append to $table. See
Postgresql documentation for the format. * $delimiter: alternative delimiter to use in place of the standard
postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields that are specified in $filename
file. Fields are separated by commapgsqlCopyToArray($table,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents
and store them to an array.
It returns an array of rows or false in case of problems. The format of the rows into the array is indicated in the $delimiter, $null and $fields parameters.
Parameters:
* (mandatory) $table: table to retrieve data from. * $delimiter: alternative delimiter to use in place of the standard
postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields to include in the row of the array. Fields are separated by commapgsqlCopyToFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents
and store them into a file.
It returns boolean.
The format of the rows stored into the file is indicated in the $delimiter, $null and $fields parameters. Parameters:
* (mandatory) $table: table to retrieve data from. * (mandatory) $filename: file where to store the contents of the table
* $delimiter: alternative delimiter to use in place of the standard
postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields to include in the row of the array. Fields are separated by comma----- Messaggio originale -----
Da: "Ilia Alshanetsky" ilia@prohost.org
A: "Denis Gasparin" denis.gasparin@edistar.com Cc: internals@lists.php.net
Inviato: Martedì, 25 maggio 2010 18:40:09 Oggetto: Re: [PHP-DEV] [PATCH] New PDO methods for PostgreSQL driverGood reason, I'll review the patch in the next day or two.
On Mon, May 24, 2010 at 5:55 PM, Denis Gasparin < denis.gasparin@edistar.com > wrote:
The copy to/from sql statements accept both as main parameter a filename or stdout/stdin respectively.
The filename represents a file in the database filesystem (apache/php and postgresql must reside on the same machine or share the file via shared filesystem). I quote from the postgresql manual:
<<<
COPY with a file name instructs the PostgreSQL server to directly read from or write to a file. The file must be accessible to the server and the name must be specified from the viewpoint of the (database) server.Because of this "limitation", if you'd like to load a csv file into pgsql via copy command, you must before copy into a shared folder and the issue the copy from filename command. Using the methods added to PDO, you can do it directly from the webserver.
About copying to/from stdin and stdout, PostgreSQL enters a particular status after a copy stdin/stdout command has been issued via sql. These status codes are PGRES_COPY_OUT and PGRES_COPY_IN. When in this status, the only way to interact with the database server is via PQgetCopyData and PQputCopyData.
There are not PDO methods or functions that implements these functions and there is no way to share the connection between PDO driver and old pgsql drivers.
These are the relevant PostgreSQL man pages:
http://www.postgresql.org/docs/8.2/interactive/libpq-copy..html http://www.postgresql.org/docs/8.2/interactive/sql-copy.html
Denis
Denis could you elaborate on what makes use of the COPY code via Sql behave differently then a PHP method call?
Ilia Alshanetsky
CIO/CSO Centah Inc.On 2010-05-24, at 15:45, Denis Gasparin < denis.gasparin@edistar.com
wrote:
I'll provide the patches in a single file as soon as possible..
Actually all the methods are wrappers against the native PostgreSQL commands (connection status, copy to/from).
I needed to develop them as methods because it is not possible to get the same results with a sql statement (in particular for connection status).
It was not possible also for COPY TO/FROM because of the way PostgreSQL handle them ( special functions were developed also for the old pgsql driver).
We are currently using them in production and we needed them in order to avoid additional connections to database (one with the old driver and one with PDO).
Denis
----- Messaggio originale -----
Da: "Ilia Alshanetsky" < ilia@prohost.org > A: "Denis Gasparin" < denis.gasparin@edistar.com > Cc: internals@lists.php.net
Inviato: Lunedì, 24 maggio 2010 19:54:46 Oggetto: Re: [PHP-DEV] [PATCH] New PDO methods for PostgreSQL driverDenis,
Could you merge the patches into a single for easier code review. Also, the copy to/from file seems like it would just be a wrapper against the native COPY PostgreSQL command, is there really a need to provide a method for it?
On Mon, May 24, 2010 at 4:57 AM, Denis Gasparin < denis.gasparin@edistar.com > wrote:
Hi.
I developed some patches for PDO/Postgresql driver in order to add some useful methods that were available in the original pgsql driver.
The attached patches apply on 5.3.2 and svn 5.3.x. If needed, i have patches also for 5.2.x.
Please comment and tell me improvements or tips.
Thank you in advance,
Denis Gasparin
Documentation of the added methods follows:
pgsqlIsInTransaction()
It uses the native Postgresql functions to check transaction status..
It returns one of the following status codes:
- PDO::PGSQL_TRANSACTION_IDLE: connection in idle status
- PDO::PGSQL_TRANSACTION_ACTIVE: connection is executing a command * PDO::PGSQL_TRANSACTION_INTRANS: connection is idle in a valid transaction block
- PDO::PGSQL_TRANSACTION_INERROR: connection is idle, in a failed transaction block
- PDO::PGSQL_TRANSACTION_UNKNOWN: connection is in a bad status
pgsqlCopyFromArray($table,Array $data,$delimiter,$null, Array $fields)
It uses the native Postgresql copy construct to append $data to $table. It returns boolean.
Parameters: * (mandatory) $table: table to append data to
- (mandatory) $data: Array of rows with data in table field order (or as specified in the $fields array). Fields must be separated by $delimiter or by
postgresql standard \t)- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields that are specified in $data parameter
pgsqlCopyFromFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to append $filename contents to $table.
It returns boolean.
Parameters: * (mandatory) $table: table to append data to.
- (mandatory) $filename: file with contents to append to $table. See Postgresql documentation for the format.
- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields that are specified in $filename file
pgsqlCopyToArray($table,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them to an array.
It returns an array of rows or false in case of problems. The format of the rows into the array is indicated in the $delimiter, $null and $fields parameters. Parameters: * (mandatory) $table: table to retrieve data from..
- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields to include in the row of the array.
pgsqlCopyToFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them into a file.
It returns boolean.
The format of the rows stored into the file is indicated in the $delimiter, $null and $fields parameters. Parameters: * (mandatory) $table: table to retrieve data from..
- (mandatory) $filename: file where to store the contents of the table * $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields to include in the row of the array.
--
--
Pierre@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
The concerns you raised about custom methods specific to database drivers were not reflective of the PDO's intent as was clarified by Wez and myself.
The code that was introduced was specific to PostgreSQL, the common functionality was introduced in a way that allows each driver to implement.
I agree with Ilia on this.
Piece of functionality which is "common" was implemented in generic way. Piece of functionality which is not "common" was implemented as postgresql-specific extension. That's exactly how it should be and the fact of updates to PDO is awesome on it's own.
Quoted text · 5 lines
hi Ilia,
So you basically say that the worries and wishes raised here are simply irrelevant and at the end of the day you decide what PDO can or cannot be?
I'm very disappointed by these two commits. I don't think it is the way we should develop PDO and it is clear that I'm not the only one to think that. As it is trunk, I won't battle too much to revert it but be sure that is not something I will let in for any of the upcoming releases as it is clearly bad design.
Cheers,
Pierre
--
Alexey Zakhlestin
http://www.milkfarmsoft.com/
hi Ilia,
Having bad design in the initial PDO implementation does not mean that we have to continue to do it this way.
The concerns raised in this discussion are very valid. I do not see nor understand the need to commit these additions at this stage. It has been obvious that PDO needs discussions about its future and roadmaps. Doing what you just can very badly affect the way we work with our users or vendors.That's not going to help PHP nor PDO.
With the risk of pissing off you, Wez and certainly other, being the initiator of PDO, the main develepers or whatever other role do not give you the rights to choose alone the direction that PDO should take (neither do I). PDO stands for PHP Data Object, key part being "PHP", as in core, standard data object layer.
I won't discuss this any longer in this thread, but please keep in mind what has been said here. And also be ready to discuss these additions again in the near future.
Cheers,
Quoted text · 156 lines
The concerns you raised about custom methods specific to database drivers were not reflective of the PDO's intent as was clarified by Wez and myself. The code that was introduced was specific to PostgreSQL, the common functionality was introduced in a way that allows each driver to implement.
hi Ilia,
So you basically say that the worries and wishes raised here are simply irrelevant and at the end of the day you decide what PDO can or cannot be?
I'm very disappointed by these two commits. I don't think it is the way we should develop PDO and it is clear that I'm not the only one to think that. As it is trunk, I won't battle too much to revert it but be sure that is not something I will let in for any of the upcoming releases as it is clearly bad design.
Cheers,
Pierre
On Thu, Jun 10, 2010 at 2:12 PM, Ilia Alshanetsky ilia@prohost.org wrote:
I've added the transaction code as a generic method inTransaction(), by default it'll just use in_txn internal parameter, but allows the driver to
extend this (as was done in PostgreSQL) and provide a detailed status code.On Wed, May 26, 2010 at 1:11 PM, Denis Gasparin denis.gasparin@edistar.comwrote:
I attached to this mail a new version of the patch both in unified and single file format.
I attached the unit tests for all the new methods too. They are three files: one for pgsqlIsInTransaction(), one for pgsqlCopyFrom* methods and one for pgsqlCopyTo* methods.
I did a typo writing the documentation in my first mail. The typo is about
the $fields parameter.
It is actually a string (not an array) with field names separated by comma.If needed, I can write also documentation in a more suitable format for php
web site.The updated documentation of the methods follows.
Any feedback is appreciated.
Thank you in advance,
DenispgsqlIsInTransaction()
It uses the native Postgresql functions to check transaction status. It returns one of the following status codes: * PDO:GSQL_TRANSACTION_IDLE: connection in idle status * PDO:GSQL_TRANSACTION_ACTIVE: connection is executing a command * PDO:GSQL_TRANSACTION_INTRANS: connection is idle in a valid transaction block
* PDO:GSQL_TRANSACTION_INERROR: connection is idle, in a failed transaction block
* PDO:GSQL_TRANSACTION_UNKNOWN: connection is in a bad statuspgsqlCopyFromArray($table,Array $data,$delimiter,$null, Array $fields)
It uses the native Postgresql copy construct to append $data to $table.
It returns boolean.
Parameters:
* (mandatory) $table: table to append data to * (mandatory) $data: Array of rows with data in table field order (or as specified in the $fields array).
Fields
must be separated by $delimiter or by
postgresql standard \t)
* $delimiter: alternative delimiter to use in place of the standard
postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields that are specified in $data parameter. Fields are separated by commapgsqlCopyFromFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to append $filename contents to $table.
It returns boolean.
Parameters:
* (mandatory) $table: table to append data to. * (mandatory) $filename: file with contents to append to $table. See
Postgresql documentation for the format. * $delimiter: alternative delimiter to use in place of the standard
postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields that are specified in $filename
file. Fields are separated by commapgsqlCopyToArray($table,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents
and store them to an array.
It returns an array of rows or false in case of problems. The format of the rows into the array is indicated in the $delimiter,
$null and $fields parameters.
Parameters:
* (mandatory) $table: table to retrieve data from. * $delimiter: alternative delimiter to use in place of the standard
postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields to include in the row of the array. Fields are separated by commapgsqlCopyToFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents
and store them into a file.
It returns boolean.
The format of the rows stored into the file is indicated in the $delimiter, $null and $fields parameters. Parameters:
* (mandatory) $table: table to retrieve data from. * (mandatory) $filename: file where to store the contents of the table
* $delimiter: alternative delimiter to use in place of the standard
postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields to include in the row of the array. Fields are separated by comma----- Messaggio originale -----
Da: "Ilia Alshanetsky" ilia@prohost.org
A: "Denis Gasparin" denis.gasparin@edistar.com Cc: internals@lists.php.net
Inviato: Martedì, 25 maggio 2010 18:40:09 Oggetto: Re: [PHP-DEV] [PATCH] New PDO methods for PostgreSQL driverGood reason, I'll review the patch in the next day or two.
On Mon, May 24, 2010 at 5:55 PM, Denis Gasparin < denis.gasparin@edistar.com > wrote:
The copy to/from sql statements accept both as main parameter a filename or stdout/stdin respectively.
The filename represents a file in the database filesystem (apache/php and postgresql must reside on the same machine or share the file via shared filesystem). I quote from the postgresql manual:
<<<
COPY with a file name instructs the PostgreSQL server to directly read
from or write to a file. The file must be accessible to the server and
the name must be specified from the viewpoint of the (database) server.Because of this "limitation", if you'd like to load a csv file into pgsql via copy command, you must before copy into a shared folder and the issue the copy from filename command. Using the methods added to PDO, you can do it directly from the webserver.
About copying to/from stdin and stdout, PostgreSQL enters a particular
status after a copy stdin/stdout command has been issued via sql. These status codes are PGRES_COPY_OUT and PGRES_COPY_IN. When in this status, the only way to interact with the database server is via PQgetCopyData and PQputCopyData.There are not PDO methods or functions that implements these functions
and there is no way to share the connection between PDO driver and old
pgsql drivers.These are the relevant PostgreSQL man pages:
http://www.postgresql.org/docs/8.2/interactive/libpq-copy..html http://www.postgresql.org/docs/8.2/interactive/sql-copy.html
Denis
Denis could you elaborate on what makes use of the COPY code via Sql
behave differently then a PHP method call?Ilia Alshanetsky
CIO/CSO Centah Inc.On 2010-05-24, at 15:45, Denis Gasparin < denis.gasparin@edistar.com
wrote:
I'll provide the patches in a single file as soon as possible..
Actually all the methods are wrappers against the native PostgreSQL commands (connection status, copy to/from).
I needed to develop them as methods because it is not possible to get the same results with a sql statement (in particular for connection status).
It was not possible also for COPY TO/FROM because of the way PostgreSQL handle them ( special functions were developed also for
the old pgsql driver).We are currently using them in production and we needed them in order to avoid additional connections to database (one with the old driver and one with PDO).
Denis
----- Messaggio originale -----
Da: "Ilia Alshanetsky" < ilia@prohost.org > A: "Denis Gasparin" < denis.gasparin@edistar.com > Cc: internals@lists.php.net
Inviato: Lunedì, 24 maggio 2010 19:54:46 Oggetto: Re: [PHP-DEV] [PATCH] New PDO methods for PostgreSQL driverDenis,
Could you merge the patches into a single for easier code review.
Also, the copy to/from file seems like it would just be a wrapper
against the native COPY PostgreSQL command, is there really a need to provide a method for it?On Mon, May 24, 2010 at 4:57 AM, Denis Gasparin < denis.gasparin@edistar.com > wrote:
Hi.
I developed some patches for PDO/Postgresql driver in order to add some useful methods that were available in the original pgsql
driver.The attached patches apply on 5.3.2 and svn 5.3.x. If needed, i have patches also for 5.2.x.
Please comment and tell me improvements or tips.
Thank you in advance,
Denis Gasparin
Documentation of the added methods follows:
pgsqlIsInTransaction()
It uses the native Postgresql functions to check transaction status..
It returns one of the following status codes:
- PDO::PGSQL_TRANSACTION_IDLE: connection in idle status
- PDO::PGSQL_TRANSACTION_ACTIVE: connection is executing a command * PDO::PGSQL_TRANSACTION_INTRANS: connection is idle in a
valid transaction block- PDO::PGSQL_TRANSACTION_INERROR: connection is idle, in a failed
transaction block- PDO::PGSQL_TRANSACTION_UNKNOWN: connection is in a bad status
pgsqlCopyFromArray($table,Array $data,$delimiter,$null, Array $fields)
It uses the native Postgresql copy construct to append $data to $table. It returns boolean.
Parameters: * (mandatory) $table: table to append data to
- (mandatory) $data: Array of rows with data in table field order
(or as specified in the $fields array). Fields must be separated by $delimiter or by
postgresql standard \t)- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields that are specified in $data parameter
pgsqlCopyFromFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to append $filename contents to $table.
It returns boolean.
Parameters: * (mandatory) $table: table to append data to.
- (mandatory) $filename: file with contents to append to $table. See Postgresql documentation for the format.
- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields that are specified in $filename file
pgsqlCopyToArray($table,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them to an array.
It returns an array of rows or false in case of problems. The format of the rows into the array is indicated in the $delimiter, $null and $fields parameters. Parameters: * (mandatory) $table: table to retrieve data from..
- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields to include in the row of the array.
pgsqlCopyToFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them into a file.
It returns boolean.
The format of the rows stored into the file is indicated in the $delimiter, $null and $fields parameters. Parameters: * (mandatory) $table: table to retrieve data from..
- (mandatory) $filename: file where to store the contents of the table * $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields to include in the row of the array.
--
--
Pierre@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
--
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
The concerns you raised about custom methods specific to database drivers were not reflective of the PDO's intent as was clarified by Wez and myself.
The code that was introduced was specific to PostgreSQL, the common functionality was introduced in a way that allows each driver to implement.
Yet the rest of the copyFrom, copyTo, etc.. could have ben generic as well. I specifically stated that this could be done at the driver level for FreeTDS using the BCP extensions and/or using "BULK INSERT ". Yet now this is a specific pgsql*** interface that cannot be abstracted for other drivers OR implemented at the driver level. Now if I want a MSSQL / Sybase dump/load method, I need to preface it with dblibCopyFrom, dblibCopyTo.
IMHO, every function should be a generic named interface to the driver or statement level and then throw a "not implemented" if the driver does not support it. This will allow for abstraction at a higher level and give the driver developers an opportunity to implement it. It will also give PDO users a more structured way to deal with unsupported methods with try/catch.
I know I am a noob to the PDO development process, however I have used OO for quite awhile and I have never seen it DB abstractions implemented like this.
Quoted text · 139 lines
hi Ilia,
So you basically say that the worries and wishes raised here are simply irrelevant and at the end of the day you decide what PDO can or cannot be?
I'm very disappointed by these two commits. I don't think it is the way we should develop PDO and it is clear that I'm not the only one to think that. As it is trunk, I won't battle too much to revert it but be sure that is not something I will let in for any of the upcoming releases as it is clearly bad design.
Cheers,
Pierre
On Thu, Jun 10, 2010 at 2:12 PM, Ilia Alshanetsky ilia@prohost.org wrote:
I've added the transaction code as a generic method inTransaction(), by default it'll just use in_txn internal parameter, but allows the driver to
extend this (as was done in PostgreSQL) and provide a detailed status code.On Wed, May 26, 2010 at 1:11 PM, Denis Gasparin denis.gasparin@edistar.comwrote:
I attached to this mail a new version of the patch both in unified and single file format.
I attached the unit tests for all the new methods too. They are three files: one for pgsqlIsInTransaction(), one for pgsqlCopyFrom* methods and one for pgsqlCopyTo* methods.
I did a typo writing the documentation in my first mail. The typo is about
the $fields parameter.
It is actually a string (not an array) with field names separated by comma.If needed, I can write also documentation in a more suitable format for php
web site.The updated documentation of the methods follows.
Any feedback is appreciated.
Thank you in advance,
DenispgsqlIsInTransaction()
It uses the native Postgresql functions to check transaction status. It returns one of the following status codes: * PDO:GSQL_TRANSACTION_IDLE: connection in idle status * PDO:GSQL_TRANSACTION_ACTIVE: connection is executing a command * PDO:GSQL_TRANSACTION_INTRANS: connection is idle in a valid transaction block
* PDO:GSQL_TRANSACTION_INERROR: connection is idle, in a failed transaction block
* PDO:GSQL_TRANSACTION_UNKNOWN: connection is in a bad statuspgsqlCopyFromArray($table,Array $data,$delimiter,$null, Array $fields)
It uses the native Postgresql copy construct to append $data to $table.
It returns boolean.
Parameters:
* (mandatory) $table: table to append data to * (mandatory) $data: Array of rows with data in table field order (or as specified in the $fields array). Fields must be separated by $delimiter or by
postgresql standard \t)
* $delimiter: alternative delimiter to use in place of the standard
postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields that are specified in $data parameter. Fields are separated by commapgsqlCopyFromFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to append $filename contents to $table.
It returns boolean.
Parameters:
* (mandatory) $table: table to append data to. * (mandatory) $filename: file with contents to append to $table. See
Postgresql documentation for the format. * $delimiter: alternative delimiter to use in place of the standard
postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields that are specified in $filename
file. Fields are separated by commapgsqlCopyToArray($table,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents
and store them to an array.
It returns an array of rows or false in case of problems. The format of the rows into the array is indicated in the $delimiter, $null and $fields parameters.
Parameters:
* (mandatory) $table: table to retrieve data from. * $delimiter: alternative delimiter to use in place of the standard
postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields to include in the row of the array. Fields are separated by commapgsqlCopyToFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents
and store them into a file.
It returns boolean.
The format of the rows stored into the file is indicated in the $delimiter, $null and $fields parameters. Parameters:
* (mandatory) $table: table to retrieve data from. * (mandatory) $filename: file where to store the contents of the table
* $delimiter: alternative delimiter to use in place of the standard
postgres delimiter ("\t")
* $null: alternative string to use as null value. Default is "\N" * $fields: string with table fields to include in the row of the array. Fields are separated by comma----- Messaggio originale -----
Da: "Ilia Alshanetsky" ilia@prohost.org
A: "Denis Gasparin" denis.gasparin@edistar.com Cc: internals@lists.php.net
Inviato: Martedì, 25 maggio 2010 18:40:09 Oggetto: Re: [PHP-DEV] [PATCH] New PDO methods for PostgreSQL driverGood reason, I'll review the patch in the next day or two.
On Mon, May 24, 2010 at 5:55 PM, Denis Gasparin < denis.gasparin@edistar.com > wrote:
The copy to/from sql statements accept both as main parameter a filename or stdout/stdin respectively.
The filename represents a file in the database filesystem (apache/php and postgresql must reside on the same machine or share the file via shared filesystem). I quote from the postgresql manual:
<<<
COPY with a file name instructs the PostgreSQL server to directly read from or write to a file. The file must be accessible to the server and the name must be specified from the viewpoint of the (database) server.Because of this "limitation", if you'd like to load a csv file into pgsql via copy command, you must before copy into a shared folder and the issue the copy from filename command. Using the methods added to PDO, you can do it directly from the webserver.
About copying to/from stdin and stdout, PostgreSQL enters a particular status after a copy stdin/stdout command has been issued via sql. These status codes are PGRES_COPY_OUT and PGRES_COPY_IN. When in this status, the only way to interact with the database server is via PQgetCopyData and PQputCopyData.
There are not PDO methods or functions that implements these functions and there is no way to share the connection between PDO driver and old pgsql drivers.
These are the relevant PostgreSQL man pages:
http://www.postgresql.org/docs/8.2/interactive/libpq-copy..html http://www.postgresql.org/docs/8.2/interactive/sql-copy.html
Denis
Denis could you elaborate on what makes use of the COPY code via Sql behave differently then a PHP method call?
Ilia Alshanetsky
CIO/CSO Centah Inc.On 2010-05-24, at 15:45, Denis Gasparin < denis.gasparin@edistar.com
wrote:
I'll provide the patches in a single file as soon as possible..
Actually all the methods are wrappers against the native PostgreSQL commands (connection status, copy to/from).
I needed to develop them as methods because it is not possible to get the same results with a sql statement (in particular for connection status).
It was not possible also for COPY TO/FROM because of the way PostgreSQL handle them ( special functions were developed also for the old pgsql driver).
We are currently using them in production and we needed them in order to avoid additional connections to database (one with the old driver and one with PDO).
Denis
----- Messaggio originale -----
Da: "Ilia Alshanetsky" < ilia@prohost.org > A: "Denis Gasparin" < denis.gasparin@edistar.com > Cc: internals@lists.php.net
Inviato: Lunedì, 24 maggio 2010 19:54:46 Oggetto: Re: [PHP-DEV] [PATCH] New PDO methods for PostgreSQL driverDenis,
Could you merge the patches into a single for easier code review. Also, the copy to/from file seems like it would just be a wrapper against the native COPY PostgreSQL command, is there really a need to provide a method for it?
On Mon, May 24, 2010 at 4:57 AM, Denis Gasparin < denis.gasparin@edistar.com > wrote:
Hi.
I developed some patches for PDO/Postgresql driver in order to add some useful methods that were available in the original pgsql driver.
The attached patches apply on 5.3.2 and svn 5.3.x. If needed, i have patches also for 5.2.x.
Please comment and tell me improvements or tips.
Thank you in advance,
Denis Gasparin
Documentation of the added methods follows:
pgsqlIsInTransaction()
It uses the native Postgresql functions to check transaction status..
It returns one of the following status codes:
- PDO::PGSQL_TRANSACTION_IDLE: connection in idle status
- PDO::PGSQL_TRANSACTION_ACTIVE: connection is executing a command * PDO::PGSQL_TRANSACTION_INTRANS: connection is idle in a valid transaction block
- PDO::PGSQL_TRANSACTION_INERROR: connection is idle, in a failed transaction block
- PDO::PGSQL_TRANSACTION_UNKNOWN: connection is in a bad status
pgsqlCopyFromArray($table,Array $data,$delimiter,$null, Array $fields)
It uses the native Postgresql copy construct to append $data to $table. It returns boolean.
Parameters: * (mandatory) $table: table to append data to
- (mandatory) $data: Array of rows with data in table field order (or as specified in the $fields array). Fields must be separated by $delimiter or by
postgresql standard \t)- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields that are specified in $data parameter
pgsqlCopyFromFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to append $filename contents to $table.
It returns boolean.
Parameters: * (mandatory) $table: table to append data to.
- (mandatory) $filename: file with contents to append to $table. See Postgresql documentation for the format.
- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields that are specified in $filename file
pgsqlCopyToArray($table,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them to an array.
It returns an array of rows or false in case of problems. The format of the rows into the array is indicated in the $delimiter, $null and $fields parameters. Parameters: * (mandatory) $table: table to retrieve data from..
- $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields to include in the row of the array.
pgsqlCopyToFile($table,$filename,$delimiter,$null,$fields)
It uses the native Postgresql copy construct to retrieve $table contents and store them into a file.
It returns boolean.
The format of the rows stored into the file is indicated in the $delimiter, $null and $fields parameters. Parameters: * (mandatory) $table: table to retrieve data from..
- (mandatory) $filename: file where to store the contents of the table * $delimiter: alternative delimiter to use in place of the standard postgres delimiter ("\t")
- $null: alternative string to use as null value. Default is "\N"
- $fields: array with table fields to include in the row of the array.
--
--
Pierre@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
The concerns you raised about custom methods specific to database drivers were not reflective of the PDO's intent as was clarified by Wez and myself.
yeah .. Wez became the ruler of PDO by ignoring others .. one of the reasons why development died when he left .. so in that way its "consistent" to continue the development in a lone wolf manner.
The code that was introduced was specific to PostgreSQL, the common functionality was introduced in a way that allows each driver to implement.
Yet the rest of the copyFrom, copyTo, etc.. could have ben generic as well. I specifically stated that this could be done at the driver level for FreeTDS using the BCP extensions and/or using "BULK INSERT ". Yet now this is a specific pgsql*** interface that cannot be abstracted for other drivers OR implemented at the driver level. Now if I want a MSSQL / Sybase dump/load method, I need to preface it with dblibCopyFrom, dblibCopyTo.
right .. Ilia just chose to ignore the rest of the developers.
regards,
Lukas Kahwe Smith
mls@pooteeweet.org
hi Ilia,
So you basically say that the worries and wishes raised here are simply irrelevant and at the end of the day you decide what PDO can or cannot be?
I'm very disappointed by these two commits. I don't think it is the way we should develop PDO and it is clear that I'm not the only one to think that. As it is trunk, I won't battle too much to revert it but be sure that is not something I will let in for any of the upcoming releases as it is clearly bad design.
I did not see that you even committed that to 5.3. That's definitively a no go.
Cheers,
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Pierre,
That is not your decision, since when do you decide what goes into PDO, that's a decision between the extension maintainer and the release master and since you are neither...
Quoted text · 8 lines
On Sat, Jun 12, 2010 at 12:24 PM, Pierre Joye pierre.php@gmail.com wrote:
hi Ilia,
So you basically say that the worries and wishes raised here are simply irrelevant and at the end of the day you decide what PDO can or cannot be?
I'm very disappointed by these two commits. I don't think it is the way we should develop PDO and it is clear that I'm not the only one to think that. As it is trunk, I won't battle too much to revert it but be sure that is not something I will let in for any of the upcoming releases as it is clearly bad design.
I did not see that you even committed that to 5.3. That's definitively a no go.
Cheers,
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org