Re: [PATCH] Improve autocompletion for SELECT statements

From: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
To: Wander Winkelhorst <w(dot)winkelhorst(at)gmail(dot)com>
Cc: pgadmin-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Improve autocompletion for SELECT statements
Date: 2011-11-01 13:50:37
Message-ID: 1320155438.2122.36.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgadmin-hackers

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

In response to

Responses

Browse pgadmin-hackers by date

  From Date Subject
Next Message Vinicius Santos 2011-11-01 14:07:24 Re: Option "Nulls First" in the ordering screen.
Previous Message Wander Winkelhorst 2011-11-01 13:42:34 [PATCH] Improve autocompletion for SELECT statements