Re: pg_query and COPY in transaction

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Luis Magaña wrote:
> It is a PHP question because the Postgres querys do work, I ran them
> directly on the postgres server and there is no problem, but if you use
> pg_query then it does not work, and pg_query is a PHP function, is it no t?
> 
> Any way, I've tried already giving each query in separate function
> calls, and it does not work either. As the rollback you suggest, I
> haven't tried that since it is suppoused to be automatic. So I will try
> that and it might work but that does not change the fact that the
> pg_query function is not doing what the manual says it should do, or at
> least does not beheave as expected.

so it seems that you _may_ have a bug. what version of php are you using?
and do pg_last_error() and/or pg_last_notice() offer any useful info?

(having read the pg_*() docs somewhat I can only - ouch! makes firebird
look even simpler than it is already)

I don't know what the COPY syntax in your SQL does exactly but have you looked
at pg_copy_from() and pg_copy_to() ?

> 
> thank you very much for your help.
> 
> regards.
> 
> Jochem Maas wrote:
>> Luis Magaña wrote:
>>> I have the following code:
>>>
>>> pg_query($conn,"BEGIN TRANSACTION;
>>>           DELETE FROM codigo_postal;
>>>           COPY
>>> codigo_postal(codigo_postal,asentamiento,tipo_asentamiento,municipio,estado)
>>> FROM '$tmpfname2' DELIMITER '|';
>>>           COMMIT");
>>>
>>> It is suppoused as I understand it, that if an error occurs on the copy
>>> statement, then the codigo_postal table should still have all of the
>>> previous records. Actually I've tested it within psql and it works as
>>> expected.
>>>
>>> However, the shown code does not. If an error occurs on the copy
>>> transaction, the data on the table gets deleted.
>> wrapping an SQL question in a php function doesn't make it a php question. ;-)
>>
>> $apps = array("apache", "mysql", "windows"); $i = 0;
>> while ($i++ < 100) printf("how do I install %s?\n", $apps[ rand(0,2) ]);
>>
>> // I ran that code for a laugh a number of times - seems to a bias towards
>> // asking how to install windows... go figure on a php list.
>>
>>> I'm certainly lost on this one, is it a bug ?, am I doing something
>>> wrong ? (most likely I guess)
>> you are wrong. there is no ROLLBACK specified. I suggest you
>> do the queries one by one (i.e. one call to pg_query() for each statement)
>> and if the 'COPY' fails call a 'ROLLBACK'
>>
>> disclaimer: I know nothing about PG as such - I mostly use Firebird;
>>
>>> Any help will be apprecciated.
>>>
>>> PHP: 5.1.2
>>> PostgreSQL: 8.1.4
>>> Apache: 2.0.55
>>> Debian Linux with Kernel 2.6.16
>>>
>>>
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux