| 1 | package DBIx::dbMan::Extension::SQLHelp; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use base 'DBIx::dbMan::Extension'; | ||
| 5 | |||
| 6 | our $VERSION = '0.03'; | ||
| 7 | |||
| 8 | 1; | ||
| 9 | |||
| 10 | sub IDENTIFICATION { return "000001-000059-000003"; } | ||
| 11 | |||
| 12 | sub preference { return 0; } | ||
| 13 | |||
| 14 | sub known_actions { return [ qw/HELP/ ]; } | ||
| 15 | |||
| 16 | sub init { | ||
| 17 | my $obj = shift; | ||
| 18 | |||
| 19 | $obj->{help_texts} = <<EOF; | ||
| 20 | ***select | ||
| 21 | Command: select | ||
| 22 | Description: retrieve tuples | ||
| 23 | Syntax: | ||
| 24 | select [distinct on <attr>] <expr1> [as <attr1>], ... <exprN> [as <attrN>] | ||
| 25 | [into [table] <class_name>] | ||
| 26 | [from <from_list>] | ||
| 27 | [where <qual>] | ||
| 28 | [group by <group_list>] | ||
| 29 | [having <having_clause>] | ||
| 30 | [order by <attr1> [ASC | DESC] [using <op1>], ... <attrN> ] | ||
| 31 | [union [all] select ...] | ||
| 32 | ***insert | ||
| 33 | Command: insert | ||
| 34 | Description: insert tuples | ||
| 35 | Syntax: | ||
| 36 | insert into <class_name> [(<attr1>...<attrN>)] | ||
| 37 | values (<expr1>...<exprN>); | | ||
| 38 | select [distinct] | ||
| 39 | <expr1>,...<exprN> | ||
| 40 | [from <from_clause>] | ||
| 41 | [where <qual>] | ||
| 42 | [group by <group_list>] | ||
| 43 | [having <having_clause>] | ||
| 44 | [union [all] select ...] | ||
| 45 | ***delete | ||
| 46 | Command: delete | ||
| 47 | Description: delete tuples | ||
| 48 | Syntax: | ||
| 49 | delete from <class_name> [where <qual>] | ||
| 50 | ***update | ||
| 51 | Command: update | ||
| 52 | Description: update tuples | ||
| 53 | Syntax: | ||
| 54 | update <class_name> set <attr1>=<expr1>,...<attrN>=<exprN> [from <from_clause>] | ||
| 55 | [where <qual>] | ||
| 56 | ***create | ||
| 57 | create function | ||
| 58 | create index | ||
| 59 | create sequence | ||
| 60 | create table | ||
| 61 | create trigger | ||
| 62 | create view | ||
| 63 | ***create table | ||
| 64 | Command: create table | ||
| 65 | Description: create a new table | ||
| 66 | Syntax: | ||
| 67 | create table <class_name> | ||
| 68 | (<attr1> <type1> [default <expression>] [not null] [,...]) | ||
| 69 | [inherits (<class_name1>,...<class_nameN>) | ||
| 70 | [[constraint <name>] check <condition> [,...] ] | ||
| 71 | ***create view | ||
| 72 | Command: create view | ||
| 73 | Description: create a view | ||
| 74 | Syntax: | ||
| 75 | create view <view_name> as | ||
| 76 | select | ||
| 77 | <expr1>[as <attr1>][,... <exprN>[as <attrN>]] | ||
| 78 | [from <from_list>] | ||
| 79 | [where <qual>] | ||
| 80 | [group by <group_list>] | ||
| 81 | ***alter table | ||
| 82 | Command: alter table | ||
| 83 | Description: add/rename attributes, rename tables | ||
| 84 | Syntax: | ||
| 85 | alter table <class_name> [*] add column <attr> <type>; | ||
| 86 | alter table <class_name> [*] rename [column] <attr1> to <attr2>; | ||
| 87 | alter table <class_name1> rename to <class_name2> | ||
| 88 | ***create function | ||
| 89 | Command: create function | ||
| 90 | Description: create a user-defined function | ||
| 91 | Syntax: | ||
| 92 | create function <function_name> ([<type1>,...<typeN>]) returns <return_type> | ||
| 93 | as '<object_filename>'|'<sql-queries>' | ||
| 94 | language 'c'|'sql'|'internal' | ||
| 95 | ***create sequence | ||
| 96 | Command: create sequence | ||
| 97 | Description: create a new sequence number generator | ||
| 98 | Syntax: | ||
| 99 | create sequence <sequence_name> | ||
| 100 | [increment <NUMBER>] | ||
| 101 | [start <NUMBER>] | ||
| 102 | [minvalue <NUMBER>] | ||
| 103 | [maxvalue <NUMBER>] | ||
| 104 | [cache <NUMBER>] | ||
| 105 | [cycle] | ||
| 106 | ***create trigger | ||
| 107 | Command: create trigger | ||
| 108 | Description: create a new trigger | ||
| 109 | Syntax: | ||
| 110 | create trigger <trigger_name> after|before event1 [or event2 [or event3] ] | ||
| 111 | on <class_name> for each row|statement | ||
| 112 | execute procedure <func_name> ([arguments]) | ||
| 113 | |||
| 114 | eventX is one of INSERT, DELETE, UPDATE | ||
| 115 | ***drop | ||
| 116 | drop function | ||
| 117 | drop index | ||
| 118 | drop sequence | ||
| 119 | drop table | ||
| 120 | drop trigger | ||
| 121 | drop view | ||
| 122 | ***drop function | ||
| 123 | Command: drop function | ||
| 124 | Description: remove a user-defined function | ||
| 125 | Syntax: | ||
| 126 | drop function <funcname> ([<type1>,....<typeN>]) | ||
| 127 | ***drop index | ||
| 128 | Command: drop index | ||
| 129 | Description: remove an existing index | ||
| 130 | Syntax: | ||
| 131 | drop index <indexname> | ||
| 132 | ***drop sequence | ||
| 133 | Command: drop sequence | ||
| 134 | Description: remove a sequence number generator | ||
| 135 | Syntax: | ||
| 136 | drop sequence <sequence_name>[,...<sequence_nameN] | ||
| 137 | ***drop table | ||
| 138 | Command: drop table | ||
| 139 | Description: remove a table | ||
| 140 | Syntax: | ||
| 141 | drop table <class_name>[,...<class_nameN] | ||
| 142 | ***drop trigger | ||
| 143 | Command: drop trigger | ||
| 144 | Description: remove a trigger | ||
| 145 | Syntax: | ||
| 146 | drop trigger <trigger_name> on <class_name> | ||
| 147 | ***drop view | ||
| 148 | Command: drop view | ||
| 149 | Description: remove a view | ||
| 150 | Syntax: | ||
| 151 | drop view <view_name> | ||
| 152 | ***create index | ||
| 153 | Command: create index | ||
| 154 | Description: construct an index | ||
| 155 | Syntax: | ||
| 156 | create [unique] index <indexname> on <class_name> [using <access_method>] | ||
| 157 | ( <attr1> [<type_class1>] [,...] | | ||
| 158 | <funcname>(<attr1>,...) [<type_class>] ) | ||
| 159 | ***grant | ||
| 160 | Command: grant | ||
| 161 | Description: grant access control to a user or group | ||
| 162 | Syntax: | ||
| 163 | grant <privilege[,privilege,...]> on <rel1>[,...<reln>] to | ||
| 164 | [public | group <group> | <username>] | ||
| 165 | privilege is {ALL | SELECT | INSERT | UPDATE | DELETE | RULE} | ||
| 166 | ***revoke | ||
| 167 | Command: revoke | ||
| 168 | Description: revoke access control from a user or group | ||
| 169 | Syntax: | ||
| 170 | revoke <privilege[,privilege,...]> on <rel1>[,...<reln>] from | ||
| 171 | [public | group <group> | <username>] | ||
| 172 | privilege is {ALL | SELECT | INSERT | UPDATE | DELETE | RULE} | ||
| 173 | ***fetch | ||
| 174 | Command: fetch | ||
| 175 | Description: retrieve tuples from a cursor | ||
| 176 | Syntax: | ||
| 177 | fetch [forward|backward] [<number>|all] [in <cursorname>] | ||
| 178 | ***lock | ||
| 179 | Command: lock | ||
| 180 | Description: exclusive lock a table inside a transaction | ||
| 181 | Syntax: | ||
| 182 | lock [table] <class_name> | ||
| 183 | ***move | ||
| 184 | Command: move | ||
| 185 | Description: move an cursor position | ||
| 186 | Syntax: | ||
| 187 | move [forward|backward] [<number>|all] [in <cursorname>] | ||
| 188 | ***vacuum | ||
| 189 | Command: vacuum | ||
| 190 | Description: vacuum the database, i.e. cleans out deleted records, updates statistics | ||
| 191 | Syntax: | ||
| 192 | vacuum [verbose] [analyze] [table] | ||
| 193 | or | ||
| 194 | vacuum [verbose] analyze [table [(attr1, ... attrN)]] | ||
| 195 | ***declare | ||
| 196 | Command: declare | ||
| 197 | Description: set up a cursor | ||
| 198 | Syntax: | ||
| 199 | declare <cursorname> [binary] cursor for | ||
| 200 | select [distinct] | ||
| 201 | <expr1> [as <attr1>],...<exprN> [as <attrN>] | ||
| 202 | [from <from_list>] | ||
| 203 | [where <qual>] | ||
| 204 | [group by <group_list>] | ||
| 205 | [having <having_clause>] | ||
| 206 | [order by <attr1> [using <op1>],... <attrN> [using <opN>]] | ||
| 207 | [union [all] select ...] | ||
| 208 | EOF | ||
| 209 | my $now = ''; | ||
| 210 | my %line = (); | ||
| 211 | for (split /\n/,$obj->{help_texts}) { | ||
| 212 | if (/^\*\*\*(.*)/) { $now = $1; next; } | ||
| 213 | next unless $now; | ||
| 214 | s/\s+$//; | ||
| 215 | $line{$now} .= $_."\n"; | ||
| 216 | } | ||
| 217 | $obj->{lines} = \%line; | ||
| 218 | } | ||
| 219 | |||
| 220 | sub handle_action { | ||
| 221 | my ($obj,%action) = @_; | ||
| 222 | |||
| 223 | if ($action{action} eq 'HELP') { | ||
| 224 | if ($action{type} eq 'sql') { | ||
| 225 | my $out = ''; | ||
| 226 | for (sort keys %{$obj->{lines}}) { | ||
| 227 | $out .= $obj->{lines}->{$_} if /^\Q$action{what}/; | ||
| 228 | } | ||
| 229 | $action{action} = 'OUTPUT'; | ||
| 230 | $action{output} = $out; | ||
| 231 | } | ||
| 232 | } | ||
| 233 | |||
| 234 | $action{processed} = 1; | ||
| 235 | return %action; | ||
| 236 | } | ||
| 237 | |||
| 238 | sub cmdcomplete { | ||
| 239 | my ($obj,$text,$line,$start) = @_; | ||
| 240 | return sort keys %{$obj->{lines}} if $line =~ /^\s*\\h\s+[A-Z]*$/i; | ||
| 241 | return (); | ||
| 242 | # tady by to chtelo zlepsit - ty vracene klice jsou i vice retezcove a museji se vracet prubezne znovu | ||
| 243 | } |