From 7737dfd35acc559bcbce3fe96925336784259dbd Mon Sep 17 00:00:00 2001 From: "Marc G. Fournier" Date: Mon, 20 Sep 1999 22:28:11 +0000 Subject: [PATCH] bring in missing files ... this isn't very clean, but :( --- src/bin/pgaccess/Makefile | 2 +- src/bin/pgaccess/README | 133 ++++---------------- src/bin/pgaccess/main.tcl | 250 ++++++++++++++++++++++++++++++++++++++ src/bin/pgaccess/pgaccess | 10 ++ 4 files changed, 285 insertions(+), 110 deletions(-) create mode 100644 src/bin/pgaccess/main.tcl create mode 100755 src/bin/pgaccess/pgaccess diff --git a/src/bin/pgaccess/Makefile b/src/bin/pgaccess/Makefile index 4abcd02986..d8c316b6c3 100644 --- a/src/bin/pgaccess/Makefile +++ b/src/bin/pgaccess/Makefile @@ -6,7 +6,7 @@ # Copyright (c) 1994, Regents of the University of California # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/pgaccess/Attic/Makefile,v 1.1 1998/12/18 17:54:42 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/pgaccess/Attic/Makefile,v 1.2 1999/09/20 22:28:11 scrappy Exp $ # #------------------------------------------------------------------------- diff --git a/src/bin/pgaccess/README b/src/bin/pgaccess/README index 1ad06ca202..69a920ab67 100644 --- a/src/bin/pgaccess/README +++ b/src/bin/pgaccess/README @@ -22,7 +22,7 @@ PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. --------------------------------------------------------------------------- -PGACCESS 0.96 9 March 1999 +PGACCESS 0.98 29 August 1999 ================================ I dedicate this program to my little daughters Ana-Maria and Emilia and to my wife for their understanding. I hope they will forgive me for spending so many @@ -30,130 +30,45 @@ time far from them. -1.Why PgAccess ? +1. How to INSTALL ? -First of all because PostgreSQL lacks a graphical interface where you -can manage your tables, edit them, define queries, sequences and -functions. +You will need a Tcl/Tk package, at least Tcl 7.6 and Tk 4.2, recommended +Tcl/Tk 8.x + +For Unix users, unpack the pgaccess-xxx.tar.gz archieve in you preferred +directory (usually /usr/local). + +Check where your "wish" program is and modify (if needed) the file +/usr/local/pgaccess/pgaccess and set variables PGACCESS_HOME and +PATH_TO_WISH to the appropriate directories. + +Include the /usr/local/pgaccess directory into your PATH or make a +symbolic link to it wherever you want (in PATH directories). +Example: + +$ ln -s /usr/local/pgaccess/pgaccess /usr/bin/pgaccess + +You will find also some documentation and FAQ in the doc directory. -2.How to INSTALL ? - -You will need Tcl/Tk package, I am using now Tcl 7.6 and Tk 4.2. -PgAccess is running fine also on Tcl/Tk 8.0 - -Also, you will need the PostgreSQL to Tcl interface library, lined as a -Tcl/Tk 'load'-able module. It is called libpgtcl and the source is -located in the PostgreSQL directory /src/interfaces/libpgtcl. -Specifically, you will need a libpgtcl library that is 'load'-able from -Tcl/Tk. This is technically different from an ordinary PostgreSQL -loadable object file, because libpgtcl is a collection of object files. - -Under Linux, this is called libpgtcl.so. You will find a pre-compiled -copy of it for Linux i386 systems at : http://www.flex.ro/pgaccess. -Just copy libpgtcl.so into your system library directory /usr/lib or -/lib and go for it. - -Under Windows, copy libpgtcl.dll and libpq.dll into C:\WINDOWS\SYSTEM directory. -Make sure you have Tcl/Tk at least version 8.0.0 for Microsoft Windows 95 & NT. -PgAccess has been checked with Tcl/Tk 8.0.4 version on Windows95 and Windows98 -platforms. - -Tcl/Tk 8.0.4 for Windows95 & NT can be downloaded from -ftp://ftp.scriptics.com/pub/tcl/tcl8_0/tcl804.exe -It is 1833712 bytes long. - - -3.How to run it? +2. Usage You run it with the command: - wish -f pgaccess.tcl [database] + pgaccess [database] [database] is optional. -Another way of loading the PostgreSQL library is running it with pgwish. -It's a wish compiled with libpgtcl library so it could understand the -commands for working with PostgreSQL. For this, remove the line "load -libpgtcl.so" from the source. If your operating system has a different -library name or location, change the 'load libpgtcl.so' line in the -pgaccess.tcl file. -4.What does it now ? +3. Bug reporting -- Opens any database on a specified host at the specified port, username and password -- Perform vacuum command. -- Saves preferences in ~/.pgaccessrc file - -Tables -- opening multiple tables for viewing, max n records (configurable) -- column resizing by dragging the vertical grid lines -- text will wrap in cells now -- dynamic row height when editing -- table layout saved for every table -- import/export to external files (SDF,CSV) -- filter capabilities ,enter filter like price>3.14 -- sort order capabilities ,enter manually the sort field(s) -- editing in place, double click the text you want to change -- record deleting , point the record, press Del key -- adding new records ,save new row with right-button-click on table for the moment -- table generator assistant -- table renaming and deleting (dropping) -- table information retrieving : owner, field information, indexes - -Queries -- define, edit and store "user defined queries" -- save view layout -- can store queries as views -- execution of queries with optional user input parameters ( select * from invoices where year=[parameter "Year of selection"] ) -- viewing of select type queries result -- running action queries (insert, update, delete) -- visual query builder with drag & drop support, table aliasing - -Sequences -- define -- inspect -- delete - -Views -- defining them saving queries as views -- view them , with filtering and sorting capabilities -- design views -- delete them - -Functions -- define , inspect , delete - -Reports -- simple reports from a table (beta stage) -- change font,size and style of fields and labels -- load and save reports from the database -- table previews, sample postscript print - -Forms -- open user defined forms -- form design module available -- query widget allowing access to a record set - -Scripts -- define, modify and call user defined scripts - -5.What it should do in the future ? - -- sequence and function renaming -- more powerful report generator and viewer -- help on line - - - -6. How you should report the errors? First of all : operating system, PostgreSQL version,Tcl/Tk version. -A more detailed story of what have you done when error had occurred. +A more detailed story of what have you done when error occurred. Tcl/Tk stops usually with a error message and there is a button there "Stack Trace" and if you press it, you will see a detailed information -about the place where it stuck. Please send it to me. +about the procedure containing the error. Please send it to me. Some information about table structure, no. of fields, records would be also good. diff --git a/src/bin/pgaccess/main.tcl b/src/bin/pgaccess/main.tcl new file mode 100644 index 0000000000..1a3d84e7eb --- /dev/null +++ b/src/bin/pgaccess/main.tcl @@ -0,0 +1,250 @@ +#!/bin/sh +# the next line restarts using wish \ +exec wish "$0" "$@" + +image create bitmap dnarw -data { +#define down_arrow_width 15 +#define down_arrow_height 15 +static char down_arrow_bits[] = { + 0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80, + 0x00,0x80,0xf8,0x8f,0xf0,0x87,0xe0,0x83, + 0xc0,0x81,0x80,0x80,0x00,0x80,0x00,0x80, + 0x00,0x80,0x00,0x80,0x00,0x80 + } +} + + +proc {intlmsg} {msg} { +global PgAcVar Messages + if {$PgAcVar(pref,language)=="english"} { return $msg } + if { ! [array exists Messages] } { return $msg } + if { ! [info exists Messages($msg)] } { return $msg } + return $Messages($msg) +} + +proc {PgAcVar:clean} {prefix} { +global PgAcVar + foreach key [array names PgAcVar $prefix] { + set PgAcVar($key) {} + unset PgAcVar($key) + } +} + + +proc {find_PGACCESS_HOME} {} { +global PgAcVar env + if {! [info exists env(PGACCESS_HOME)]} { + set home [file dirname [info script]] + switch [file pathtype $home] { + absolute {set env(PGACCESS_HOME) $home} + relative {set env(PGACCESS_HOME) [file join [pwd] $home]} + volumerelative { + set curdir [pwd] + cd $home + set env(PGACCESS_HOME) [file join [pwd] [file dirname [file join [lrange [file split $home] 1 end]]]] + cd $curdir + } + } + } + if {![file isdir $env(PGACCESS_HOME)]} { + set PgAcVar(PGACCESS_HOME) [pwd] + } else { + set PgAcVar(PGACCESS_HOME) $env(PGACCESS_HOME) + } +} + + +proc init {argc argv} { +global PgAcVar CurrentDB + find_PGACCESS_HOME + # Loading all defined namespaces + foreach module {mainlib database tables queries visualqb forms views functions reports scripts users sequences schema help preferences} { + source [file join $PgAcVar(PGACCESS_HOME) lib $module.tcl] + } + set PgAcVar(currentdb,host) localhost + set PgAcVar(currentdb,pgport) 5432 + set CurrentDB {} + set PgAcVar(tablist) [list Tables Queries Views Sequences Functions Reports Forms Scripts Users Schema] + set PgAcVar(activetab) {} + set PgAcVar(query,tables) {} + set PgAcVar(query,links) {} + set PgAcVar(query,results) {} + set PgAcVar(mwcount) 0 + Preferences::load +} + +proc {wpg_exec} {db cmd} { +global PgAcVar + set PgAcVar(pgsql,cmd) "never executed" + set PgAcVar(pgsql,status) "no status yet" + set PgAcVar(pgsql,errmsg) "no error message yet" + if {[catch { + Mainlib::sqlw_display $cmd + set PgAcVar(pgsql,cmd) $cmd + set PgAcVar(pgsql,res) [pg_exec $db $cmd] + set PgAcVar(pgsql,status) [pg_result $PgAcVar(pgsql,res) -status] + set PgAcVar(pgsql,errmsg) [pg_result $PgAcVar(pgsql,res) -error] + } tclerrmsg]} { + showError [format [intlmsg "Tcl error executing pg_exec %s\n\n%s"] $cmd $tclerrmsg] + return 0 + } + return $PgAcVar(pgsql,res) +} + + +proc {wpg_select} {args} { + Mainlib::sqlw_display "[lindex $args 1]" + uplevel pg_select $args +} + + +proc {create_drop_down} {base x y w} { +global PgAcVar + if {[winfo exists $base.ddf]} return; + frame $base.ddf -borderwidth 1 -height 75 -relief raised -width 55 + listbox $base.ddf.lb -background #fefefe -foreground #000000 -selectbackground #c3c3c3 -borderwidth 1 -font $PgAcVar(pref,font_normal) -highlightthickness 0 -selectborderwidth 0 -yscrollcommand [subst {$base.ddf.sb set}] + scrollbar $base.ddf.sb -borderwidth 1 -command [subst {$base.ddf.lb yview}] -highlightthickness 0 -orient vert + place $base.ddf -x $x -y $y -width $w -height 185 -anchor nw -bordermode ignore + place $base.ddf.lb -x 1 -y 1 -width [expr $w-18] -height 182 -anchor nw -bordermode ignore + place $base.ddf.sb -x [expr $w-15] -y 1 -width 14 -height 183 -anchor nw -bordermode ignore +} + + +proc {setCursor} {{type NORMAL}} { + if {[lsearch -exact "CLOCK WAIT WATCH" [string toupper $type]] != -1} { + set type watch + } else { + set type left_ptr + } + foreach wn [winfo children .] { + catch {$wn configure -cursor $type} + } + update ; update idletasks +} + + +proc {parameter} {msg} { +global PgAcVar + Window show .pgaw:GetParameter + focus .pgaw:GetParameter.e1 + set PgAcVar(getqueryparam,var) "" + set PgAcVar(getqueryparam,flag) 0 + set PgAcVar(getqueryparam,msg) $msg + bind .pgaw:GetParameter "set PgAcVar(getqueryparam,flag) 1" + grab .pgaw:GetParameter + tkwait variable PgAcVar(getqueryparam,flag) + if {$PgAcVar(getqueryparam,result)} { + return $PgAcVar(getqueryparam,var) + } else { + return "" + } +} + + +proc {showError} {emsg} { + bell ; tk_messageBox -title [intlmsg Error] -icon error -message $emsg +} + + +proc {sql_exec} {how cmd} { +global PgAcVar CurrentDB + if {[set pgr [wpg_exec $CurrentDB $cmd]]==0} { + return 0 + } + if {($PgAcVar(pgsql,status)=="PGRES_COMMAND_OK") || ($PgAcVar(pgsql,status)=="PGRES_TUPLES_OK")} { + pg_result $pgr -clear + return 1 + } + if {$how != "quiet"} { + showError [format [intlmsg "Error executing query\n\n%s\n\nPostgreSQL error message:\n%s\nPostgreSQL status:%s"] $cmd $PgAcVar(pgsql,errmsg) $PgAcVar(pgsql,status)] + } + pg_result $pgr -clear + return 0 +} + + + +proc {main} {argc argv} { +global PgAcVar CurrentDB tcl_platform + load libpgtcl[info sharedlibextension] + catch {Mainlib::draw_tabs} + set PgAcVar(opendb,username) {} + set PgAcVar(opendb,password) {} + if {$argc>0} { + set PgAcVar(opendb,dbname) [lindex $argv 0] + set PgAcVar(opendb,host) localhost + set PgAcVar(opendb,pgport) 5432 + Mainlib::open_database + } elseif {$PgAcVar(pref,autoload) && ($PgAcVar(pref,lastdb)!="")} { + set PgAcVar(opendb,dbname) $PgAcVar(pref,lastdb) + set PgAcVar(opendb,host) $PgAcVar(pref,lasthost) + set PgAcVar(opendb,pgport) $PgAcVar(pref,lastport) + catch {set PgAcVar(opendb,username) $PgAcVar(pref,lastusername)} + if {[set openmsg [Mainlib::open_database]]!=""} { + if {[regexp "no password supplied" $openmsg]} { + Window show .pgaw:OpenDB + focus .pgaw:OpenDB.f1.e5 + wm transient .pgaw:OpenDB .pgaw:Main + } + } + + } + wm protocol .pgaw:Main WM_DELETE_WINDOW { + catch {pg_disconnect $CurrentDB} + exit + } +} + + +proc {Window} {args} { +global vTcl + set cmd [lindex $args 0] + set name [lindex $args 1] + set newname [lindex $args 2] + set rest [lrange $args 3 end] + if {$name == "" || $cmd == ""} {return} + if {$newname == ""} { + set newname $name + } + set exists [winfo exists $newname] + switch $cmd { + show { + if {$exists == "1" && $name != "."} {wm deiconify $name; return} + if {[info procs vTclWindow(pre)$name] != ""} { + eval "vTclWindow(pre)$name $newname $rest" + } + if {[info procs vTclWindow$name] != ""} { + eval "vTclWindow$name $newname $rest" + } + if {[info procs vTclWindow(post)$name] != ""} { + eval "vTclWindow(post)$name $newname $rest" + } + } + hide { if $exists {wm withdraw $newname; return} } + iconify { if $exists {wm iconify $newname; return} } + destroy { if $exists {destroy $newname; return} } + } +} + +proc vTclWindow. {base} { + if {$base == ""} { + set base . + } + wm focusmodel $base passive + wm geometry $base 1x1+0+0 + wm maxsize $base 1009 738 + wm minsize $base 1 1 + wm overrideredirect $base 0 + wm resizable $base 1 1 + wm withdraw $base + wm title $base "vt.tcl" +} + + +init $argc $argv + +Window show . +Window show .pgaw:Main + +main $argc $argv + diff --git a/src/bin/pgaccess/pgaccess b/src/bin/pgaccess/pgaccess new file mode 100755 index 0000000000..41fd5cae16 --- /dev/null +++ b/src/bin/pgaccess/pgaccess @@ -0,0 +1,10 @@ +#!/bin/sh + +PATH_TO_WISH=/usr/bin/wish +PGACCESS_HOME=/usr/local/pgaccess + +export PATH_TO_WISH +export PGACCESS_HOME + +exec ${PATH_TO_WISH} ${PGACCESS_HOME}/main.tcl "$@" +