Thread: [PATCH] Improve autocompletion for SELECT statements

[PATCH] Improve autocompletion for SELECT statements

From
Wander Winkelhorst
Date:
Hello,

A big part of my job is creating simple select statements with a few joins in them. Unfortunately, the existing autocomplete functionality of pgadmin was a bit too limited for my use case. A relatively simple query like: select * from person p join company c on p.company_id = c.id where p.name = 'John'  would be enough to completely throw the autocompletion off.

So I started working on a patch to improve the autocompletion a bit and the result is attached. It doesn't have all the features I would like it to have (no support for table aliases, for example) but it is already a big improvement for my use case.

Please comment if I need to change anything to get this patch into pgadmin.

This patch is against pgadmin3-1.14.0.tar.gz

Regards,
Wander Winkelhorst. 
Attachment

[PATCH] Improve autocompletion for SELECT statements

From
Wander Winkelhorst
Date:
Hello,

A big part of my job is creating simple select statements with a few joins in them. Unfortunately, the existing autocomplete functionality of pgadmin was a bit too limited for my use case. A relatively simple query like: select * from person p join company c on p.company_id = c.id where p.name = 'John'  would be enough to completely throw the autocompletion off.

So I started working on a patch to improve the autocompletion a bit and the result is attached. It doesn't have all the features I would like it to have (no support for table aliases, for example) but it is already a big improvement for my use case.

Please comment if I need to change anything to get this patch into pgadmin.

This patch is against pgadmin3-1.14.0.tar.gz

Regards,
Wander Winkelhorst. 

Attachment

Re: [PATCH] Improve autocompletion for SELECT statements

From
Guillaume Lelarge
Date:
Hi,

On Mon, 2011-10-31 at 20:23 +0100, Wander Winkelhorst wrote:
> Hello,
>
> A big part of my job is creating simple select statements with a few joins
> in them. Unfortunately, the existing autocomplete functionality of pgadmin
> was a bit too limited for my use case. A relatively simple query like:
> select * from person p join company c on p.company_id = c.id where p.name =
> 'John'  would be enough to completely throw the autocompletion off.
>
> So I started working on a patch to improve the autocompletion a bit and the
> result is attached. It doesn't have all the features I would like it to
> have (no support for table aliases, for example) but it is already a big
> improvement for my use case.
>
> Please comment if I need to change anything to get this patch into pgadmin.
>
> This patch is against pgadmin3-1.14.0.tar.gz
>

I tried with a simple database. Thats simple database contains only one
table (t1, with two columns c1 integer, c2 text).

I put "SELECT * FROM t1 WHERE " and I hit Ctrl-Space. It displays the
two columns which is great.

I put "SELECT * FROM t1 WHERE c" and I hit Ctrl-Space. It crashes. Here
is a part of the backtrace:

Program received signal SIGABRT, Aborted.
0x00000030522352d5 in raise () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install
PackageKit-gtk-module-0.6.17-1.fc15.x86_64 atk-2.0.0-1.fc15.x86_64
cairo-1.10.2-3.fc15.x86_64 dbus-glib-0.92-2.fc15.x86_64
dbus-libs-1.4.6-5.fc15.x86_64 expat-2.0.1-11.fc15.x86_64
fontconfig-2.8.0-3.fc15.x86_64 freetype-2.4.4-5.fc15.x86_64
gamin-0.1.10-9.fc15.x86_64 gdk-pixbuf2-2.23.3-2.fc15.x86_64
glib2-2.28.8-1.fc15.x86_64 glibc-2.14-5.x86_64 gtk2-2.24.7-1.fc15.x86_64
gtk2-engines-2.20.2-2.fc15.x86_64 gvfs-1.8.2-1.fc15.x86_64
ibus-gtk2-1.4.0-2.fc15.x86_64 ibus-libs-1.4.0-2.fc15.x86_64
keyutils-libs-1.2-7.fc15.x86_64 krb5-libs-1.9.1-5.fc15.x86_64
libX11-1.4.3-1.fc15.x86_64 libXau-1.0.6-2.fc15.x86_64
libXcomposite-0.4.3-2.fc15.x86_64 libXcursor-1.1.11-3.fc15.x86_64
libXdamage-1.1.3-2.fc15.x86_64 libXext-1.2.0-2.fc15.x86_64
libXfixes-5.0-1.fc15.x86_64 libXi-1.4.3-2.fc15.x86_64
libXinerama-1.1.1-2.fc15.x86_64 libXrandr-1.3.1-2.fc15.x86_64
libXrender-0.9.6-2.fc15.x86_64 libcanberra-0.28-3.fc15.x86_64
libcanberra-gtk2-0.28-3.fc15.x86_64 libcom_err-1.41.14-2.fc15.x86_64
libgcc-4.6.1-9.fc15.x86_64 libogg-1.2.2-3.fc15.x86_64
libpng-1.2.46-1.fc15.x86_64 libselinux-2.0.99-4.fc15.x86_64 libstdc
++-4.6.1-9.fc15.x86_64 libtdb-1.2.9-9.fc15.x86_64
libtool-ltdl-2.4-6.fc15.x86_64 libudev-167-6.fc15.x86_64
libvorbis-1.3.2-1.fc15.x86_64 libxcb-1.7-2.fc15.x86_64
libxml2-2.7.8-6.fc15.x86_64 libxslt-1.1.26-8.fc15.x86_64
nss-softokn-freebl-3.12.10-2.fc15.x86_64 openssl-1.0.0e-1.fc15.x86_64
pango-1.28.4-1.fc15.x86_64 pixman-0.20.2-2.fc15.x86_64
zlib-1.2.5-3.fc15.x86_64
(gdb) bt
#0  0x00000030522352d5 in raise () from /lib64/libc.so.6
#1  0x0000003052236beb in abort () from /lib64/libc.so.6
#2  0x0000003052270bce in __libc_message () from /lib64/libc.so.6
#3  0x000000305227703a in malloc_printerr () from /lib64/libc.so.6
#4  0x00000000008cb0c4 in psql_completion (text=0x1d0e197 "c", start=23,
end=25, dbptr=0x1b510d0) at ./utils/tab-complete.inc:482
#5  0x00000000008cff0f in tab_complete (allstr=0x1d0e180 "select * from
t1 where c", startptr=23, endptr=25, dbptr=0x1b510d0)
    at ./utils/tabcomplete.c:414
#6  0x0000000000486d02 in ctlSQLBox::OnAutoComplete (this=0x1bc9500,
rev=...) at ./ctl/ctlSQLBox.cpp:649
#7  0x00007ffff6119a17 in wxAppConsole::HandleEvent (this=0xfe70e0,
handler=0x1bc9500, func=
    (void (wxEvtHandler::*)(wxEvtHandler * const, wxEvent &)) 0x486b40
<ctlSQLBox::OnAutoComplete(wxCommandEvent&)>, event=...)
    at ./src/common/appbase.cpp:322

Line 482 is when you freed the buffer. Not sure it's relevant to this
issue, but you have a bug in your code.

I'm really interested in commiting new autocompletion stuff. So, thanks
for your work.


--
Guillaume
  http://blog.guillaume.lelarge.info
  http://www.dalibo.com


Re: [PATCH] Improve autocompletion for SELECT statements

From
Wander Winkelhorst
Date:
Hi,

On Tue, Nov 1, 2011 at 2:50 PM, Guillaume Lelarge <guillaume@lelarge.info> wrote:

Line 482 is when you freed the buffer. Not sure it's relevant to this
issue, but you have a bug in your code.

Sorry; seems like the allocation was off by one.

Attached is the updated patch.

Regards,
Wander Winkelhorst.

Attachment

Re: [PATCH] Improve autocompletion for SELECT statements

From
Guillaume Lelarge
Date:
On Tue, 2011-11-01 at 15:11 +0100, Wander Winkelhorst wrote:
> Hi,
>
> On Tue, Nov 1, 2011 at 2:50 PM, Guillaume Lelarge <guillaume@lelarge.info>wrote:
>
> >
> > Line 482 is when you freed the buffer. Not sure it's relevant to this
> > issue, but you have a bug in your code.
> >
>
> Sorry; seems like the allocation was off by one.
>
> Attached is the updated patch.
>

OK, it works now. I understand a lot of improvements could come later,
but there is one thing that bugs me. And I think it should be fixed
before applying.

Let's say I wrote this:

SELECT * FROM person JOIN company ON

and try autocompletion afterwards. I get the list of columns in person
and company, which is great. The issue is that you only have the
column's name, not the table's name. So you don't know if the column
refers to the first table or the second. We could say it's not an issue
if we were sure they were all different. But if I have two times the id
column, it gets kinda weird. Maybe you should show the table's name in
front of the column's name.

Moreover, I'm not sure this is done or not. But having the columns in
order (of attnum) would be great.


--
Guillaume
  http://blog.guillaume.lelarge.info
  http://www.dalibo.com


Re: [PATCH] Improve autocompletion for SELECT statements

From
Wander Winkelhorst
Date:

On Tue, Nov 1, 2011 at 4:31 PM, Guillaume Lelarge <guillaume@lelarge.info> wrote:

OK, it works now. I understand a lot of improvements could come later,
but there is one thing that bugs me. And I think it should be fixed
before applying.

Let's say I wrote this:

SELECT * FROM person JOIN company ON

and try autocompletion afterwards. I get the list of columns in person
and company, which is great. The issue is that you only have the
column's name, not the table's name. So you don't know if the column
refers to the first table or the second. We could say it's not an issue
if we were sure they were all different. But if I have two times the id
column, it gets kinda weird. Maybe you should show the table's name in
front of the column's name.
 
Allright, another week, another patch :-)

Changes since last time:
- Support for aliasses (autocompletion on "select * from person p join company c on ...) will present a list of "p.id, p.name, c.id, c.name etc.)
- Support for queries without aliasses (select * from person where ...) 
- Support for queries without aliasses but with joins (select * from person join company on ...) 
- Support for queries with mixed versions (select * from person p join company on ...)
- Support for update statements (update person set ...)
- Support for autocompletion after SELECT (select ... from person)
- Fixed a crash

Regards,
Wander Winkelhorst. 
Attachment

Re: [PATCH] Improve autocompletion for SELECT statements

From
Guillaume Lelarge
Date:
On Thu, 2011-11-10 at 22:51 +0100, Wander Winkelhorst wrote:
>
> On Tue, Nov 1, 2011 at 4:31 PM, Guillaume Lelarge
> <guillaume@lelarge.info> wrote:
>
>
>
>         OK, it works now. I understand a lot of improvements could
>         come later,
>         but there is one thing that bugs me. And I think it should be
>         fixed
>         before applying.
>
>         Let's say I wrote this:
>
>         SELECT * FROM person JOIN company ON
>
>         and try autocompletion afterwards. I get the list of columns
>         in person
>         and company, which is great. The issue is that you only have
>         the
>         column's name, not the table's name. So you don't know if the
>         column
>         refers to the first table or the second. We could say it's not
>         an issue
>         if we were sure they were all different. But if I have two
>         times the id
>         column, it gets kinda weird. Maybe you should show the table's
>         name in
>         front of the column's name.
>
> Allright, another week, another patch :-)
>
>
> Changes since last time:
> - Support for aliasses (autocompletion on "select * from person p join
> company c on ...) will present a list of "p.id, p.name, c.id, c.name
> etc.)
> - Support for queries without aliasses (select * from person
> where ...)
> - Support for queries without aliasses but with joins (select * from
> person join company on ...)
> - Support for queries with mixed versions (select * from person p join
> company on ...)
> - Support for update statements (update person set ...)
> - Support for autocompletion after SELECT (select ... from person)
> - Fixed a crash
>

Quite interesting, but alas I found two bugs:

1. select  from fbb_categories , fbb_posts
   I put my cursor between select and from, and ask for autocomplete,
   and I get

,.catname
,.disp_position
,.id

They all are part of fbb_categories. Unfortunately, that doesn't explain
the comma

* select  from fbb_categories, fbb_posts
  I put my cursor between select and from, and ask for autocomplete,
   and I get nothing (but it works with only one table).

* select * from fbb_topics c left join fbb_posts p on p.
  I put my cursor right after "p.". I was expecting to get the columns
  of fbb_posts, but got nothing.

* select * from fbb_topics c left join fbb_posts p on p
  I put my cursor right after "p". I was expecting to get the columns
  of fbb_posts, but got columns from p (as long as they contain a p
  themselves, and columns from c when they contain a p in their name.
  I was only expecting columns of fbb_posts.

Can you get a look at those? Thanks.


--
Guillaume
  http://blog.guillaume.lelarge.info
  http://www.dalibo.com


Re: [PATCH] Improve autocompletion for SELECT statements

From
Dave Page
Date:
I just noticed this thread. Does the patch update the tab completion code (tab-complete.inc, iirc) to the latest from PG 9.1? I don't think we remembered to do that this release, so it probably should.

On Sunday, November 13, 2011, Guillaume Lelarge <guillaume@lelarge.info> wrote:
> On Thu, 2011-11-10 at 22:51 +0100, Wander Winkelhorst wrote:
>>
>> On Tue, Nov 1, 2011 at 4:31 PM, Guillaume Lelarge
>> <guillaume@lelarge.info> wrote:
>>
>>
>>
>>         OK, it works now. I understand a lot of improvements could
>>         come later,
>>         but there is one thing that bugs me. And I think it should be
>>         fixed
>>         before applying.
>>
>>         Let's say I wrote this:
>>
>>         SELECT * FROM person JOIN company ON
>>
>>         and try autocompletion afterwards. I get the list of columns
>>         in person
>>         and company, which is great. The issue is that you only have
>>         the
>>         column's name, not the table's name. So you don't know if the
>>         column
>>         refers to the first table or the second. We could say it's not
>>         an issue
>>         if we were sure they were all different. But if I have two
>>         times the id
>>         column, it gets kinda weird. Maybe you should show the table's
>>         name in
>>         front of the column's name.
>>
>> Allright, another week, another patch :-)
>>
>>
>> Changes since last time:
>> - Support for aliasses (autocompletion on "select * from person p join
>> company c on ...) will present a list of "p.id, p.name, c.id, c.name
>> etc.)
>> - Support for queries without aliasses (select * from person
>> where ...)
>> - Support for queries without aliasses but with joins (select * from
>> person join company on ...)
>> - Support for queries with mixed versions (select * from person p join
>> company on ...)
>> - Support for update statements (update person set ...)
>> - Support for autocompletion after SELECT (select ... from person)
>> - Fixed a crash
>>
>
> Quite interesting, but alas I found two bugs:
>
> 1. select  from fbb_categories , fbb_posts
>   I put my cursor between select and from, and ask for autocomplete,
>   and I get
>
> ,.catname
> ,.disp_position
> ,.id
>
> They all are part of fbb_categories. Unfortunately, that doesn't explain
> the comma
>
> * select  from fbb_categories, fbb_posts
>  I put my cursor between select and from, and ask for autocomplete,
>   and I get nothing (but it works with only one table).
>
> * select * from fbb_topics c left join fbb_posts p on p.
>  I put my cursor right after "p.". I was expecting to get the columns
>  of fbb_posts, but got nothing.
>
> * select * from fbb_topics c left join fbb_posts p on p
>  I put my cursor right after "p". I was expecting to get the columns
>  of fbb_posts, but got columns from p (as long as they contain a p
>  themselves, and columns from c when they contain a p in their name.
>  I was only expecting columns of fbb_posts.
>
> Can you get a look at those? Thanks.
>
>
> --
> Guillaume
>  http://blog.guillaume.lelarge.info
>  http://www.dalibo.com
>
>
> --
> Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgadmin-hackers
>

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

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

Re: [PATCH] Improve autocompletion for SELECT statements

From
Guillaume Lelarge
Date:
On Sun, 2011-11-13 at 22:10 +0000, Dave Page wrote:
> I just noticed this thread. Does the patch update the tab completion
> code (tab-complete.inc, iirc) to the latest from PG 9.1? I don't think
> we remembered to do that this release, so it probably should.
>

This patch shouldn't. It adds new features on the autocompletion,
features that have nothing to do with the autocompletion code from 9.1.

But I agree we forgot to update this file, and that it should be done
soon. I'm not sure if we should do that also for the 1.14 branch? any
opinions on this one?


--
Guillaume
  http://blog.guillaume.lelarge.info
  http://www.dalibo.com


Re: [PATCH] Improve autocompletion for SELECT statements

From
Dave Page
Date:
On Mon, Nov 14, 2011 at 8:19 AM, Guillaume Lelarge
<guillaume@lelarge.info> wrote:
> On Sun, 2011-11-13 at 22:10 +0000, Dave Page wrote:
>> I just noticed this thread. Does the patch update the tab completion
>> code (tab-complete.inc, iirc) to the latest from PG 9.1? I don't think
>> we remembered to do that this release, so it probably should.
>>
>
> This patch shouldn't. It adds new features on the autocompletion,
> features that have nothing to do with the autocompletion code from 9.1.

Even if the patch doesn't directly update the file, it should be updated first.

FYI, I just took a look at the patch and it does touch
tab-complete.inc - it certainly should *not* do that, as
tab-complete.inc is generated with tabcomplete.pl from the upstream
tab-complete.c. Any changes made to it are likely to be lost the next
time it's updated. If that file must be changed, then it should be
done by tab-complete.pl, though frankly it would be better to push the
changes into psql first.

> But I agree we forgot to update this file, and that it should be done
> soon. I'm not sure if we should do that also for the 1.14 branch? any
> opinions on this one?

If it updates cleanly, I don't mind.

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

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

Re: [PATCH] Improve autocompletion for SELECT statements

From
Wander Winkelhorst
Date:


On Mon, Nov 14, 2011 at 10:16 AM, Dave Page <dpage@pgadmin.org> wrote:

FYI, I just took a look at the patch and it does touch
tab-complete.inc - it certainly should *not* do that, as
tab-complete.inc is generated with tabcomplete.pl from the upstream
tab-complete.c. Any changes made to it are likely to be lost the next
time it's updated. If that file must be changed, then it should be
done by tab-complete.pl, though frankly it would be better to push the
changes into psql first.

Could you please tell me how I'm supposed to use tabcomplete.pl, and where I can get the correct version of  tab-complete.c?

On Sun, Nov 13, 2011 at 11:06 PM, Guillaume Lelarge <guillaume@lelarge.info> wrote:
> They all are part of fbb_categories. Unfortunately, that doesn't explain
> the comma

That's because the comma gets recognized as a table alias :)
I'm going to take a look at these issues soon.

Regards,
Wander WInkelhorst.

Re: [PATCH] Improve autocompletion for SELECT statements

From
Guillaume Lelarge
Date:
On Mon, 2011-11-14 at 21:15 +0100, Wander Winkelhorst wrote:
> On Mon, Nov 14, 2011 at 10:16 AM, Dave Page <dpage@pgadmin.org> wrote:
> >
> >
> > FYI, I just took a look at the patch and it does touch
> > tab-complete.inc - it certainly should *not* do that, as
> > tab-complete.inc is generated with tabcomplete.pl from the upstream
> > tab-complete.c. Any changes made to it are likely to be lost the next
> > time it's updated. If that file must be changed, then it should be
> > done by tab-complete.pl, though frankly it would be better to push the
> > changes into psql first.
> >
>
> Could you please tell me how I'm supposed to use tabcomplete.pl, and where
> I can get the correct version of  tab-complete.c?
>

I suppose it comes from the psql source files, but I don't know more.

You'll need to wait Dave for a more complete answer.

BTW, it means the previous patch needs to follow the same path.

> On Sun, Nov 13, 2011 at 11:06 PM, Guillaume Lelarge <guillaume@lelarge.info>
>  wrote:
> > They all are part of fbb_categories. Unfortunately, that doesn't explain
> > the comma
>
> That's because the comma gets recognized as a table alias :)
> I'm going to take a look at these issues soon.
>

Yeah, I guessed that was the issue :)


--
Guillaume
  http://blog.guillaume.lelarge.info
  http://www.dalibo.com


Re: [PATCH] Improve autocompletion for SELECT statements

From
Dave Page
Date:
On Mon, Nov 14, 2011 at 8:15 PM, Wander Winkelhorst
<w.winkelhorst@gmail.com> wrote:
>
>
> On Mon, Nov 14, 2011 at 10:16 AM, Dave Page <dpage@pgadmin.org> wrote:
>>
>> FYI, I just took a look at the patch and it does touch
>> tab-complete.inc - it certainly should *not* do that, as
>> tab-complete.inc is generated with tabcomplete.pl from the upstream
>> tab-complete.c. Any changes made to it are likely to be lost the next
>> time it's updated. If that file must be changed, then it should be
>> done by tab-complete.pl, though frankly it would be better to push the
>> changes into psql first.
>
> Could you please tell me how I'm supposed to use tabcomplete.pl, and where I
> can get the correct version of  tab-complete.c?

I'm not sure I've ever used it - that was originally written by Magnus
so I think he handled it originally.

The top of the script has this:

# This script builds tab-complete.inc from tab-complete.c. The
# source file (tab-complete.c) should be copied from the latest
# PostgreSQL sources (src/bin/psql/tab-complete.c), so we don't
# have to do all the work ourselves...

By the looks of it you copy tab-complete.c to pgadmin/utils, and then
run the script in that directory. I wouldn't be surprised if it needs
updating though; the tab completion code does get hacked on quite
regularly in PostgreSQL.

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

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

Re: [PATCH] Improve autocompletion for SELECT statements

From
Wander Winkelhorst
Date:


On Tue, Nov 15, 2011 at 10:03 AM, Dave Page <dpage@pgadmin.org> wrote:
On Mon, Nov 14, 2011 at 8:15 PM, Wander Winkelhorst
<w.winkelhorst@gmail.com> wrote:
>
>
> On Mon, Nov 14, 2011 at 10:16 AM, Dave Page <dpage@pgadmin.org> wrote:
>>
>> FYI, I just took a look at the patch and it does touch
>> tab-complete.inc - it certainly should *not* do that, as
>> tab-complete.inc is generated with tabcomplete.pl from the upstream
>> tab-complete.c. Any changes made to it are likely to be lost the next
>> time it's updated. If that file must be changed, then it should be
>> done by tab-complete.pl, though frankly it would be better to push the
>> changes into psql first.
>
> Could you please tell me how I'm supposed to use tabcomplete.pl, and where I
> can get the correct version of  tab-complete.c?

I'm not sure I've ever used it - that was originally written by Magnus
so I think he handled it originally.

The top of the script has this:

# This script builds tab-complete.inc from tab-complete.c. The
# source file (tab-complete.c) should be copied from the latest
# PostgreSQL sources (src/bin/psql/tab-complete.c), so we don't
# have to do all the work ourselves...

By the looks of it you copy tab-complete.c to pgadmin/utils, and then
run the script in that directory.
 
Yeah, I've tried that, didn't work. tabcomplete.pl says "Failed match 1 at tabcomplete.pl line 28."

I wouldn't be surprised if it needs
updating though; the tab completion code does get hacked on quite
regularly in PostgreSQL.

So, should I just get the latest version of tab-complete.c, and base my work on that? I'd be doing to separate things in one patch, which I don't like, but if this is what gets my changes in pgadmin, I'd do it.

Regards,
Wander Winkelhorst.

Re: [PATCH] Improve autocompletion for SELECT statements

From
Dave Page
Date:
On Tue, Nov 15, 2011 at 9:31 AM, Wander Winkelhorst
<w.winkelhorst+pgadmin@gmail.com> wrote:
>
>
> On Tue, Nov 15, 2011 at 10:03 AM, Dave Page <dpage@pgadmin.org> wrote:
>>
>> On Mon, Nov 14, 2011 at 8:15 PM, Wander Winkelhorst
>> <w.winkelhorst@gmail.com> wrote:
>> >
>> >
>> > On Mon, Nov 14, 2011 at 10:16 AM, Dave Page <dpage@pgadmin.org> wrote:
>> >>
>> >> FYI, I just took a look at the patch and it does touch
>> >> tab-complete.inc - it certainly should *not* do that, as
>> >> tab-complete.inc is generated with tabcomplete.pl from the upstream
>> >> tab-complete.c. Any changes made to it are likely to be lost the next
>> >> time it's updated. If that file must be changed, then it should be
>> >> done by tab-complete.pl, though frankly it would be better to push the
>> >> changes into psql first.
>> >
>> > Could you please tell me how I'm supposed to use tabcomplete.pl, and
>> > where I
>> > can get the correct version of  tab-complete.c?
>>
>> I'm not sure I've ever used it - that was originally written by Magnus
>> so I think he handled it originally.
>>
>> The top of the script has this:
>>
>> # This script builds tab-complete.inc from tab-complete.c. The
>> # source file (tab-complete.c) should be copied from the latest
>> # PostgreSQL sources (src/bin/psql/tab-complete.c), so we don't
>> # have to do all the work ourselves...
>>
>> By the looks of it you copy tab-complete.c to pgadmin/utils, and then
>> run the script in that directory.
>
>
> Yeah, I've tried that, didn't work. tabcomplete.pl says "Failed match 1 at
> tabcomplete.pl line 28."

:-(

>> I wouldn't be surprised if it needs
>> updating though; the tab completion code does get hacked on quite
>> regularly in PostgreSQL.
>
> So, should I just get the latest version of tab-complete.c, and base my work
> on that? I'd be doing to separate things in one patch, which I don't like,
> but if this is what gets my changes in pgadmin, I'd do it.

Well you can always update tab-complete.c, send that patch, and then
continue to work on top of that.


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

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

Re: [PATCH] Improve autocompletion for SELECT statements

From
Guillaume Lelarge
Date:
On Tue, 2011-11-15 at 09:36 +0000, Dave Page wrote:
> On Tue, Nov 15, 2011 at 9:31 AM, Wander Winkelhorst
> <w.winkelhorst+pgadmin@gmail.com> wrote:
> >
> >
> > On Tue, Nov 15, 2011 at 10:03 AM, Dave Page <dpage@pgadmin.org> wrote:
> >>
> >> On Mon, Nov 14, 2011 at 8:15 PM, Wander Winkelhorst
> >> <w.winkelhorst@gmail.com> wrote:
> >> >
> >> >
> >> > On Mon, Nov 14, 2011 at 10:16 AM, Dave Page <dpage@pgadmin.org> wrote:
> >> >>
> >> >> FYI, I just took a look at the patch and it does touch
> >> >> tab-complete.inc - it certainly should *not* do that, as
> >> >> tab-complete.inc is generated with tabcomplete.pl from the upstream
> >> >> tab-complete.c. Any changes made to it are likely to be lost the next
> >> >> time it's updated. If that file must be changed, then it should be
> >> >> done by tab-complete.pl, though frankly it would be better to push the
> >> >> changes into psql first.
> >> >
> >> > Could you please tell me how I'm supposed to use tabcomplete.pl, and
> >> > where I
> >> > can get the correct version of  tab-complete.c?
> >>
> >> I'm not sure I've ever used it - that was originally written by Magnus
> >> so I think he handled it originally.
> >>
> >> The top of the script has this:
> >>
> >> # This script builds tab-complete.inc from tab-complete.c. The
> >> # source file (tab-complete.c) should be copied from the latest
> >> # PostgreSQL sources (src/bin/psql/tab-complete.c), so we don't
> >> # have to do all the work ourselves...
> >>
> >> By the looks of it you copy tab-complete.c to pgadmin/utils, and then
> >> run the script in that directory.
> >
> >
> > Yeah, I've tried that, didn't work. tabcomplete.pl says "Failed match 1 at
> > tabcomplete.pl line 28."
>
> :-(
>

I tried too, and it starts to work with release 8.3. Makes you wonder
when was the last time it got updated. git log doesn't seem to give any
commit since 2007.

> >> I wouldn't be surprised if it needs
> >> updating though; the tab completion code does get hacked on quite
> >> regularly in PostgreSQL.
> >
> > So, should I just get the latest version of tab-complete.c, and base my work
> > on that? I'd be doing to separate things in one patch, which I don't like,
> > but if this is what gets my changes in pgadmin, I'd do it.
>
> Well you can always update tab-complete.c, send that patch, and then
> continue to work on top of that.
>

Just to make sureI get that right. The job to do is to update this file
in the PostgreSQL source files, so that we can grab that and push it
into pgAdmin's repository. Right?

If that's right, it's no wonder why this code doesn't get updated that
much.


--
Guillaume
  http://blog.guillaume.lelarge.info
  http://www.dalibo.com


Re: [PATCH] Improve autocompletion for SELECT statements

From
Guillaume Lelarge
Date:
On Tue, 2011-11-15 at 09:36 +0000, Dave Page wrote:
> On Tue, Nov 15, 2011 at 9:31 AM, Wander Winkelhorst
> <w.winkelhorst+pgadmin@gmail.com> wrote:
> >
> >
> > On Tue, Nov 15, 2011 at 10:03 AM, Dave Page <dpage@pgadmin.org> wrote:
> >>
> >> On Mon, Nov 14, 2011 at 8:15 PM, Wander Winkelhorst
> >> <w.winkelhorst@gmail.com> wrote:
> >> >
> >> >
> >> > On Mon, Nov 14, 2011 at 10:16 AM, Dave Page <dpage@pgadmin.org> wrote:
> >> >>
> >> >> FYI, I just took a look at the patch and it does touch
> >> >> tab-complete.inc - it certainly should *not* do that, as
> >> >> tab-complete.inc is generated with tabcomplete.pl from the upstream
> >> >> tab-complete.c. Any changes made to it are likely to be lost the next
> >> >> time it's updated. If that file must be changed, then it should be
> >> >> done by tab-complete.pl, though frankly it would be better to push the
> >> >> changes into psql first.
> >> >
> >> > Could you please tell me how I'm supposed to use tabcomplete.pl, and
> >> > where I
> >> > can get the correct version of  tab-complete.c?
> >>
> >> I'm not sure I've ever used it - that was originally written by Magnus
> >> so I think he handled it originally.
> >>
> >> The top of the script has this:
> >>
> >> # This script builds tab-complete.inc from tab-complete.c. The
> >> # source file (tab-complete.c) should be copied from the latest
> >> # PostgreSQL sources (src/bin/psql/tab-complete.c), so we don't
> >> # have to do all the work ourselves...
> >>
> >> By the looks of it you copy tab-complete.c to pgadmin/utils, and then
> >> run the script in that directory.
> >
> >
> > Yeah, I've tried that, didn't work. tabcomplete.pl says "Failed match 1 at
> > tabcomplete.pl line 28."
>
> :-(
>

I tried too, and it starts to work with release 8.3. Makes you wonder
when was the last time it got updated. git log doesn't seem to give any
commit since 2007.

> >> I wouldn't be surprised if it needs
> >> updating though; the tab completion code does get hacked on quite
> >> regularly in PostgreSQL.
> >
> > So, should I just get the latest version of tab-complete.c, and base my work
> > on that? I'd be doing to separate things in one patch, which I don't like,
> > but if this is what gets my changes in pgadmin, I'd do it.
>
> Well you can always update tab-complete.c, send that patch, and then
> continue to work on top of that.
>

Just to make sureI get that right. The job to do is to update this file
in the PostgreSQL source files, so that we can grab that and push it
into pgAdmin's repository. Right?

If that's right, it's no wonder why this code doesn't get updated that


--
Guillaume
  http://blog.guillaume.lelarge.info
  http://www.dalibo.com


Re: [PATCH] Improve autocompletion for SELECT statements

From
Kris Shannon
Date:
On 15 November 2011 20:31, Wander Winkelhorst
<w.winkelhorst+pgadmin@gmail.com> wrote:
> Yeah, I've tried that, didn't work. tabcomplete.pl says "Failed match 1 at
> tabcomplete.pl line 28."

Here's a fix for tabcomplete.pl which lets it work for all versions of
tab-complete.c from 8.0.0 to current HEAD

Attachment

Re: [PATCH] Improve autocompletion for SELECT statements

From
Kris Shannon
Date:
On 16 November 2011 13:47, Kris Shannon <kris@shannon.id.au> wrote:
> On 15 November 2011 20:31, Wander Winkelhorst
> <w.winkelhorst+pgadmin@gmail.com> wrote:
>> Yeah, I've tried that, didn't work. tabcomplete.pl says "Failed match 1 at
>> tabcomplete.pl line 28."
>
> Here's a fix for tabcomplete.pl which lets it work for all versions of
> tab-complete.c from 8.0.0 to current HEAD
>

BTW,  I just love git bisect run.
It let me find the reason for the failures really quickly.

Re: [PATCH] Improve autocompletion for SELECT statements

From
Dave Page
Date:
On Tue, Nov 15, 2011 at 9:01 PM, Guillaume Lelarge
<guillaume@lelarge.info> wrote:
>
>
> Just to make sureI get that right. The job to do is to update this file
> in the PostgreSQL source files, so that we can grab that and push it
> into pgAdmin's repository. Right?
>
> If that's right, it's no wonder why this code doesn't get updated that
> much.

Well the point is that there are new additions and improvements to the
upstream autocomplete code every release - far more than we're ever
likely to do. We want to benefit from that effort, which is why our
code was designed to be updated regularly with the latest changes from
upstream. The downside is that on the rare occasion that someone wants
to update our version of the code with a new feature, it becomes
somewhat more painful.


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

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

Re: [PATCH] Improve autocompletion for SELECT statements

From
Dave Page
Date:
Cool - thanks Kris.

Guillaume, are you taking the lead on this work in general, or should
I add this to my queue?

On Wed, Nov 16, 2011 at 2:47 AM, Kris Shannon <kris@shannon.id.au> wrote:
> On 15 November 2011 20:31, Wander Winkelhorst
> <w.winkelhorst+pgadmin@gmail.com> wrote:
>> Yeah, I've tried that, didn't work. tabcomplete.pl says "Failed match 1 at
>> tabcomplete.pl line 28."
>
> Here's a fix for tabcomplete.pl which lets it work for all versions of
> tab-complete.c from 8.0.0 to current HEAD
>



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

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

Re: [PATCH] Improve autocompletion for SELECT statements

From
Guillaume Lelarge
Date:
On Wed, 2011-11-16 at 09:21 +0000, Dave Page wrote:
> Cool - thanks Kris.
>
> Guillaume, are you taking the lead on this work in general, or should
> I add this to my queue?
>

Sorry for the reply two weeks after. If you can put it on your queue, it
would be great. As you probably noticed, I don't have much time recently
to work on pgAdmin. I still have a few bugs to fix.


--
Guillaume
  http://blog.guillaume.lelarge.info
  http://www.dalibo.com


Re: [PATCH] Improve autocompletion for SELECT statements

From
Dave Page
Date:
On Wed, Nov 16, 2011 at 2:47 AM, Kris Shannon <kris@shannon.id.au> wrote:
> On 15 November 2011 20:31, Wander Winkelhorst
> <w.winkelhorst+pgadmin@gmail.com> wrote:
>> Yeah, I've tried that, didn't work. tabcomplete.pl says "Failed match 1 at
>> tabcomplete.pl line 28."
>
> Here's a fix for tabcomplete.pl which lets it work for all versions of
> tab-complete.c from 8.0.0 to current HEAD

Hi,

I just got round to testing this. It fails to produce a usable output
file for me with tab-complete.c from 9.1.2. Did you check the
resulting file as well, or just that the script ran without error?

ccache gcc -DHAVE_CONFIG_H -I. -I..
-DDATA_DIR=\"/usr/local/pgadmin3/share/pgadmin3/\"
-I../pgadmin/include   -I/usr/local/pgsql/include
-I/usr/local/pgsql/include/server -I/usr/local/pgsql/include -DSSL
-DHAVE_CONNINFO_PARSE
-I/usr/local/lib/wx/include/mac-unicode-release-static-2.8
-I/usr/local/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES
-D__WXMAC__ -DEMBED_XRC  -arch i386 -I/usr/local/include/libxml2
-I/usr/local/include -I/usr/local/include/libxml2  -O2 -MT
tabcomplete.o -MD -MP -MF .deps/tabcomplete.Tpo -c -o tabcomplete.o
`test -f './utils/tabcomplete.c' || echo './'`./utils/tabcomplete.c
In file included from ./utils/tabcomplete.c:176:
./utils/tab-complete.inc:464: error: expected ‘:’, ‘,’, ‘;’, ‘}’ or
‘__attribute__’ before ‘flags’
./utils/tab-complete.inc:481: warning: excess elements in struct initializer
./utils/tab-complete.inc:481: warning: (near initialization for
‘words_after_create[3]’)
./utils/tab-complete.inc:484: warning: excess elements in struct initializer
./utils/tab-complete.inc:484: warning: (near initialization for
‘words_after_create[6]’)
./utils/tab-complete.inc:495: warning: excess elements in struct initializer
./utils/tab-complete.inc:495: warning: (near initialization for
‘words_after_create[16]’)
./utils/tab-complete.inc:496: warning: excess elements in struct initializer
./utils/tab-complete.inc:496: warning: (near initialization for
‘words_after_create[17]’)
./utils/tab-complete.inc:504: warning: excess elements in struct initializer
./utils/tab-complete.inc:504: warning: (near initialization for
‘words_after_create[25]’)
./utils/tab-complete.inc:505: warning: excess elements in struct initializer
./utils/tab-complete.inc:505: warning: (near initialization for
‘words_after_create[26]’)
./utils/tab-complete.inc:509: warning: excess elements in struct initializer
./utils/tab-complete.inc:509: warning: (near initialization for
‘words_after_create[30]’)
./utils/tab-complete.inc:510: warning: excess elements in struct initializer
./utils/tab-complete.inc:510: warning: (near initialization for
‘words_after_create[31]’)
./utils/tab-complete.inc: In function ‘psql_completion’:
./utils/tab-complete.inc:596: warning: assignment makes pointer from
integer without a cast
./utils/tab-complete.inc:598: warning: assignment makes pointer from
integer without a cast
./utils/tab-complete.inc:600: warning: assignment makes pointer from
integer without a cast
./utils/tab-complete.inc:616: error: ‘drop_command_generator’
undeclared (first use in this function)
./utils/tab-complete.inc:616: error: (Each undeclared identifier is
reported only once
./utils/tab-complete.inc:616: error: for each function it appears in.)
./utils/tab-complete.inc:616: warning: assignment makes pointer from
integer without a cast
In file included from ./utils/tabcomplete.c:176:
./utils/tab-complete.inc:999:56: error: macro "COMPLETE_WITH_ATTR"
passed 2 arguments, but takes just 1
./utils/tab-complete.inc:999: error: ‘COMPLETE_WITH_ATTR’ undeclared
(first use in this function)
./utils/tab-complete.inc:1009:34: error: macro "COMPLETE_WITH_ATTR"
passed 2 arguments, but takes just 1
./utils/tab-complete.inc:1037:34: error: macro "COMPLETE_WITH_ATTR"
passed 2 arguments, but takes just 1
./utils/tab-complete.inc:1285:34: error: macro "COMPLETE_WITH_ATTR"
passed 2 arguments, but takes just 1
./utils/tab-complete.inc:1565:34: error: macro "COMPLETE_WITH_ATTR"
passed 2 arguments, but takes just 1
./utils/tab-complete.inc:1570:34: error: macro "COMPLETE_WITH_ATTR"
passed 2 arguments, but takes just 1
./utils/tab-complete.inc:2128:34: error: macro "COMPLETE_WITH_ATTR"
passed 2 arguments, but takes just 1
./utils/tab-complete.inc:2216:34: error: macro "COMPLETE_WITH_ATTR"
passed 2 arguments, but takes just 1
./utils/tab-complete.inc:2492:34: error: macro "COMPLETE_WITH_ATTR"
passed 2 arguments, but takes just 1
./utils/tab-complete.inc:2582:34: error: macro "COMPLETE_WITH_ATTR"
passed 2 arguments, but takes just 1
./utils/tab-complete.inc:2688: warning: assignment makes pointer from
integer without a cast
make[3]: *** [tabcomplete.o] Error 1
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [all] Error 2
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

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

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