Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bmIT4-0004TO-GT for pgadmin-hackers@arkaria.postgresql.org; Tue, 20 Sep 2016 10:40:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bmIT4-0000X6-1m for pgadmin-hackers@arkaria.postgresql.org; Tue, 20 Sep 2016 10:40:02 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bmIT3-0000Wx-1h for pgadmin-hackers@postgresql.org; Tue, 20 Sep 2016 10:40:01 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bmISz-00037i-Ju for pgadmin-hackers@postgresql.org; Tue, 20 Sep 2016 10:39:59 +0000 Received: by mail-wm0-x234.google.com with SMTP id a25so10295278wmi.1 for ; Tue, 20 Sep 2016 03:39:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=cFl+p/sjXFmSMfvS6zup8C6sSOQPLpLvhxNP4vqq6m4=; b=B+D5MnpAm+q8ErktAAttuycYD0a2O+5Iwl2i15RtHS4CHdUhCkFHnHcNRDO9qgGbDQ i+SrbY7F2buvoLCxM60DLpiLfH2sH+xifiKrCWakkHTvBoS2izPnhW7i02SpqDSJPxaM eHQMRW6Bt4umj2WidsDnw024Cg1fu7xQwiAaSpFkVSrUI6LdD3KJa3IbtmzLn6M1bKr5 1kAg6tsSvir3tATlsV6j0cO/36WB/ciFVSOLx0AMA0A4sQCv8SMY8V1Wk38fJMAgGW9M X6sPE6bbmVwTVmnKKZK+rfGjsUJpTUQHAI612kkzcQI/3+oo8m/jp6Z4EUoMlPnXCkn5 8Rfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=cFl+p/sjXFmSMfvS6zup8C6sSOQPLpLvhxNP4vqq6m4=; b=W2gfYJm5PVp4M0mL7TBeLycCmo7LOI7KWfe7OFmJtMf2QoSc73gFDDVV0Lsi+0YiTN XTdbtNjnyhlH9lONGBI5Kru/KnddaG3IrcBjj7lfYf0CpQk86AB+UMvQZypjbWIXNFsw UD/52kxbFKv0a7vTstAmhqfoCciWNOZt2enGBulmNdjlZpY3PUle+sIAzaEiGYzMGDzb L+Y+CTgVmk+Di43O9R4cMfUnG67bBIElVVRRq6P44aX5+nPxkTqnZJSMuUR2md+A+7vN f6OcbvcCtGtLR6ym166hSlyTlZ7uroT6bqWugKjtnEy8WZ4W5mILbvTY/Ei1NBG7CEMQ bFgw== X-Gm-Message-State: AE9vXwMsa3STYXtRxy6b+bkkcZtdcmALw8UXeXxclxZz8RDyt1QTfaUyVA+AO54ISOnjxguQdU6f5xpDebWuyJgh X-Received: by 10.194.89.228 with SMTP id br4mr26925607wjb.187.1474367995749; Tue, 20 Sep 2016 03:39:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.172.198 with HTTP; Tue, 20 Sep 2016 03:39:25 -0700 (PDT) In-Reply-To: References: From: Surinder Kumar Date: Tue, 20 Sep 2016 16:09:25 +0530 Message-ID: Subject: Re: [pgAdmin4][Patch]: RM1592 - Download as CSV should be supported for DDL To: Dave Page Cc: pgadmin-hackers Content-Type: multipart/mixed; boundary=047d7bf10adaaa5813053cee0c5b X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgadmin-hackers Precedence: bulk Sender: pgadmin-hackers-owner@postgresql.org --047d7bf10adaaa5813053cee0c5b Content-Type: multipart/alternative; boundary=047d7bf10adaaa580f053cee0c59 --047d7bf10adaaa580f053cee0c59 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Please find updated patch with suggested changes and inline comments. Also, Incase if user tries to download csv on queries other than select, we are catching that exception and write into 'csv' with name 'error.csv'. On Tue, Sep 20, 2016 at 2:33 PM, Dave Page wrote: > On Tue, Sep 20, 2016 at 6:43 AM, Surinder Kumar > wrote: > > > > On Mon, Sep 19, 2016 at 8:59 PM, Surinder Kumar > > wrote: > >> > >> On Mon, Sep 19, 2016 at 8:48 PM, Dave Page wrote: > >>> > >>> Hi > >>> > >>> On Mon, Sep 19, 2016 at 3:03 PM, Surinder Kumar > >>> wrote: > >>> > Hi > >>> > > >>> > Please find attached patch with fix. > >>> >> > >>> >> Download as CSV > >>> >> button should be enabled only for SELECT queries. > >>> > >>> I'm not sure there's a way to do this without parsing the query. > >>> Simply matching on ^select certainly won't work reliably - for > >>> example, there could be multiple statements in the script, or it could > >>> be PERFORM ... or UPDATE ... RETURNING ... > >> > >> I wasn't aware of such cases. > >>> > >>> > >>> I think we need to leave the button enabled, but give the user a > >>> message if no data is returned, e.g. > >> > >> ok. sure. > > > > I discussed the issue with Harshal and this is how download csv works: > > We just hit the url to download csv, and let the browser handle the > response > > from the server side. we don't have access to response data to check if > no > > data is returned. > > Hmm, yeah that's true. > > > The other approach is to hit the same query twice. First time an ajax > query > > to check if data is returned or not. if returned, fire another query to > > download csv otherwise set message in message panel. > > But the limitation with this approach is that we are just increasing lo= ad > > over server by hitting same query twice, incase returned data rows in > > billions. > > Thoughts ? > > Yeah, we can't do that. > > The only thing I can think of right now is to simply write the error > message to the CSV file, e.g. > > "The query executed did not return any data." > > (with the quotes, so it's valid CSV). That way at least the user will > always get a file downloaded, and will see the error when they open > it. > =E2=80=8BThats' done.=E2=80=8B > > -- > Dave Page > Blog: http://pgsnake.blogspot.com > Twitter: @pgsnake > > EnterpriseDB UK: http://www.enterprisedb.com > The Enterprise PostgreSQL Company > --047d7bf10adaaa580f053cee0c59 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Ple= ase find updated patch with suggested changes and inline comments.

Also, Incase if user tries to dow= nload csv on queries other than select, we are catching that exception and = write into 'csv' with name 'error.csv'.

On Tue, Sep 20, 2016 at 2:33 PM, Dave Page <dpage@pgadmin.org> wrote:
O= n Tue, Sep 20, 2016 at 6:43 AM, Surinder Kumar
<sur= inder.kumar@enterprisedb.com> wrote:
>
> On Mon, Sep 19, 2016 at 8:59 PM, Surinder Kumar
> <surinder.kumar@= enterprisedb.com> wrote:
>>
>> On Mon, Sep 19, 2016 at 8:48 PM, Dave Page <dpage@pgadmin.org> wrote:
>>>
>>> Hi
>>>
>>> On Mon, Sep 19, 2016 at 3:03 PM, Surinder Kumar
>>> <surinde= r.kumar@enterprisedb.com> wrote:
>>> > Hi
>>> >
>>> > Please find attached patch with fix.
>>> >>
>>> >> Download as CSV
>>> >>=C2=A0 button should be enabled only for SELECT querie= s.
>>>
>>> I'm not sure there's a way to do this without parsing = the query.
>>> Simply matching on ^select certainly won't work reliably -= for
>>> example, there could be multiple statements in the script, or = it could
>>> be PERFORM ...=C2=A0 or UPDATE ... RETURNING ...
>>
>> I wasn't aware of such cases.
>>>
>>>
>>> I think we need to leave the button enabled, but give the user= a
>>> message if no data is returned, e.g.
>>
>> ok. sure.
>
> I discussed the issue with Harshal and this is how download csv works:=
> We just hit the url to download csv, and let the browser handle the re= sponse
> from the server side. we don't have access to response data to che= ck if no
> data is returned.

Hmm, yeah that's true.

> The other approach is to hit the same query twice. First time an ajax = query
> to check if data is returned or not. if returned, fire another query t= o
> download csv otherwise set message in message panel.
> But the limitation with this approach is that we are just increasing l= oad
> over server by hitting same query twice, incase returned data rows in<= br> > billions.
> Thoughts ?

Yeah, we can't do that.

The only thing I can think of right now is to simply write the error
message to the CSV file, e.g.

"The query executed did not return any data."

(with the quotes, so it's valid CSV). That way at least the user= will
always get a file downloaded, and will see the error when they open
it.
= =E2=80=8BThats' done.=E2=80=8B

--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--047d7bf10adaaa580f053cee0c59-- --047d7bf10adaaa5813053cee0c5b Content-Type: application/octet-stream; name="RM1592_v1.patch" Content-Disposition: attachment; filename="RM1592_v1.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_itbcm5a30 ZGlmZiAtLWdpdCBhL3dlYi9wZ2FkbWluL3Rvb2xzL3NxbGVkaXRvci9fX2lu aXRfXy5weSBiL3dlYi9wZ2FkbWluL3Rvb2xzL3NxbGVkaXRvci9fX2luaXRf Xy5weQppbmRleCAyYzk2ZGVhLi44ZTc4OTY3IDEwMDY0NAotLS0gYS93ZWIv cGdhZG1pbi90b29scy9zcWxlZGl0b3IvX19pbml0X18ucHkKKysrIGIvd2Vi L3BnYWRtaW4vdG9vbHMvc3FsZWRpdG9yL19faW5pdF9fLnB5CkBAIC0xMzA0 LDE2ICsxMzA0LDE4IEBAIGRlZiBzdGFydF9xdWVyeV9kb3dubG9hZF90b29s KHRyYW5zX2lkKToKCiAgICAgICAgICAgICAgICAgc3luY19jb25uLmNvbm5l Y3QoYXV0b2NvbW1pdD1GYWxzZSkKCisgICAgICAgICAgICAgICAgZGVmIGNs ZWFudXAoKToKKyAgICAgICAgICAgICAgICAgICAgY29ubi5tYW5hZ2VyLmNv bm5lY3Rpb25zW3N5bmNfY29ubi5jb25uX2lkXS5fcmVsZWFzZSgpCisgICAg ICAgICAgICAgICAgICAgIGRlbCBjb25uLm1hbmFnZXIuY29ubmVjdGlvbnNb c3luY19jb25uLmNvbm5faWRdCisKICAgICAgICAgICAgICAgICAjIFRoaXMg cmV0dXJucyBnZW5lcmF0b3Igb2YgcmVjb3Jkcy4KICAgICAgICAgICAgICAg ICBzdGF0dXMsIGdlbiA9IHN5bmNfY29ubi5leGVjdXRlX29uX3NlcnZlcl9h c19jc3Yoc3FsLCByZWNvcmRzPTIwMDApCgogICAgICAgICAgICAgICAgIGlm IG5vdCBzdGF0dXM6Ci0gICAgICAgICAgICAgICAgICAgIGNvbm4ubWFuYWdl ci5yZWxlYXNlKGNvbm5faWQ9Y29ubl9pZCwgZGlkPXRyYW5zX29iai5kaWQp Ci0gICAgICAgICAgICAgICAgICAgIHJldHVybiBpbnRlcm5hbF9zZXJ2ZXJf ZXJyb3IoZXJyb3Jtc2c9c3RyKGdlbikpCi0KLSAgICAgICAgICAgICAgICBk ZWYgY2xlYW51cCgpOgotICAgICAgICAgICAgICAgICAgICBjb25uLm1hbmFn ZXIuY29ubmVjdGlvbnNbc3luY19jb25uLmNvbm5faWRdLl9yZWxlYXNlKCkK LSAgICAgICAgICAgICAgICAgICAgZGVsIGNvbm4ubWFuYWdlci5jb25uZWN0 aW9uc1tzeW5jX2Nvbm4uY29ubl9pZF0KKyAgICAgICAgICAgICAgICAgICAg ciA9IFJlc3BvbnNlKCciezB9IicuZm9ybWF0KGdlbiksIG1pbWV0eXBlPSd0 ZXh0L2NzdicpCisgICAgICAgICAgICAgICAgICAgIHIuaGVhZGVyc1siQ29u dGVudC1EaXNwb3NpdGlvbiJdID0gImF0dGFjaG1lbnQ7ZmlsZW5hbWU9ZXJy b3IuY3N2IgorICAgICAgICAgICAgICAgICAgICByLmNhbGxfb25fY2xvc2Uo Y2xlYW51cCkKKyAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHIKCiAgICAg ICAgICAgICAgICAgciA9IFJlc3BvbnNlKGdlbigpLCBtaW1ldHlwZT0ndGV4 dC9jc3YnKQoKQEAgLTEzMjYsMTEgKzEzMjgsMTIgQEAgZGVmIHN0YXJ0X3F1 ZXJ5X2Rvd25sb2FkX3Rvb2wodHJhbnNfaWQpOgogICAgICAgICAgICAgICAg IHIuaGVhZGVyc1siQ29udGVudC1EaXNwb3NpdGlvbiJdID0gImF0dGFjaG1l bnQ7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IC02MDksNiArNjA5LDcgQEAgV0hFUkUKICAgICAgICAgICAg IGlmIG5vdCByZXN1bHRzOgogICAgICAgICAgICAgICAgIGlmIG5vdCBjdXIu Y2xvc2VkOgogICAgICAgICAgICAgICAgICAgICBjdXIuY2xvc2UoKQorICAg ICAgICAgICAgICAgIHlpZWxkIGdldHRleHQoJyJUaGUgcXVlcnkgZXhlY3V0 ZWQgZGlkIG5vdCByZXR1cm4gYW55IGRhdGEuIicpCiAgICAgICAgICAgICAg ICAgcmV0dXJuCgogICAgICAgICAgICAgaGVhZGVyID0gW2MudG9fZGljdCgp WyduYW1lJ10gZm9yIGMgaW4gY3VyLm9yZGVyZWRfZGVzY3JpcHRpb24oKV0K --047d7bf10adaaa5813053cee0c5b Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgadmin-hackers --047d7bf10adaaa5813053cee0c5b--