mirror of
https://github.com/jackfoxy/urQL.git
synced 2024-09-11 11:55:33 +03:00
drop view
This commit is contained in:
parent
e511c8ea5f
commit
0584a53f17
@ -66,6 +66,20 @@ Tables in the namespace *sys* cannot be merged into.
|
||||
### _______________________________
|
||||
|
||||
|
||||
```
|
||||
{ CREATE | ALTER } { PROC | PROCEDURE }
|
||||
[<db-qualifer>]<procedure-name>
|
||||
[ { #<parameter-name> <data-type> } ] [ ,...n ]
|
||||
AS { sql_statement [ ;...n ] }
|
||||
```
|
||||
|
||||
Discussion:
|
||||
TBD
|
||||
Cannot create database.
|
||||
|
||||
### _______________________________
|
||||
|
||||
|
||||
`TRUNCATE TABLE [ <ship-qualifer> ]<table-name>`
|
||||
|
||||
Discussion:
|
||||
|
@ -53,6 +53,6 @@ Cannot drop if type-name is in use.
|
||||
### _______________________________
|
||||
|
||||
|
||||
`DROP VIEW [ <db-qualifer> ] <view-name>`
|
||||
`DROP VIEW [ FORCE ] [ <db-qualifer> ] <view-name>`
|
||||
|
||||
Discussion: Cannot drop if view is in use by another view,
|
||||
Discussion: Cannot drop if used in another view, unless `FORCE` is specified, resulting in cascading object drops.
|
@ -51,4 +51,5 @@ Reading and/or updating data on foreign ships is allowed provided the ship's pil
|
||||
## Issues
|
||||
|
||||
1. how to handle views shadowing tables
|
||||
2. relational division
|
||||
2. relational division
|
||||
3. stored procedures
|
||||
|
@ -7,6 +7,11 @@
|
||||
create-namespace:ast
|
||||
create-table:ast
|
||||
create-view:ast
|
||||
drop-database:ast
|
||||
drop-index:ast
|
||||
drop-namespace:ast
|
||||
drop-table:ast
|
||||
drop-view:ast
|
||||
==
|
||||
+$ command
|
||||
$%
|
||||
@ -15,8 +20,33 @@
|
||||
%create-namespace
|
||||
%create-table
|
||||
%create-view
|
||||
%drop-database
|
||||
%drop-index
|
||||
%drop-namespace
|
||||
%drop-table
|
||||
%drop-view
|
||||
==
|
||||
::
|
||||
:: turn an atom into upper case cord
|
||||
:: (this has got to be super inefficient, but it was easy)
|
||||
++ trip-cuss-crip
|
||||
|= target=@
|
||||
^- @t
|
||||
(crip (cuss (trip `@t`target)))
|
||||
::
|
||||
:: match a cord, case agnostic
|
||||
::
|
||||
++ jester
|
||||
|= daf=@t
|
||||
|= tub=nail
|
||||
=+ fad=daf
|
||||
|- ^- (like @t)
|
||||
?: =(`@`0 daf)
|
||||
[p=p.tub q=[~ u=[p=fad q=tub]]]
|
||||
?: |(?=(~ q.tub) !=((trip-cuss-crip (end 3 daf)) (trip-cuss-crip i.q.tub)))
|
||||
(fail tub)
|
||||
$(p.tub (lust i.q.tub p.tub), q.tub t.q.tub, daf (rsh 3 daf))
|
||||
::
|
||||
:: the main event
|
||||
::
|
||||
++ parse
|
||||
@ -32,14 +62,26 @@
|
||||
=/ whitespace (star ;~(pose gah (just '\09') (just '\0d')))
|
||||
=/ end-or-next-command ;~(pose ;~(plug whitespace mic) whitespace mic)
|
||||
=/ parse-face ;~(pfix whitespace sym)
|
||||
=/ parse-qualified ;~(pfix whitespace ;~((glue dot) parse-face parse-face))
|
||||
=/ parse-db-qualified-name ;~(pose parse-qualified parse-face)
|
||||
=/ parse-qualified-2-name ;~(pose ;~(pfix whitespace ;~((glue dot) sym sym)) parse-face)
|
||||
=/ parse-qualified-3 ;~ pose
|
||||
;~(plug (star sym) dot dot (star sym))
|
||||
;~((glue dot) (star sym) (star sym) (star sym))
|
||||
;~((glue dot) (star sym) (star sym))
|
||||
(star sym)
|
||||
==
|
||||
=/ parse-qualified-3-name ;~(pfix whitespace parse-qualified-3)
|
||||
=/ parse-force-or-3-name ;~(pose ;~(pfix whitespace (jester 'force')) parse-qualified-3-name)
|
||||
=/ parse-command ;~ pose
|
||||
(cold %create-database ;~(plug whitespace (jester 'create') whitespace (jester 'database')))
|
||||
(cold %create-index ;~(plug whitespace (jester 'create') whitespace (jester 'index')))
|
||||
(cold %create-namespace ;~(plug whitespace (jester 'create') whitespace (jester 'namespace')))
|
||||
(cold %create-table ;~(plug whitespace (jester 'create') whitespace (jester 'table')))
|
||||
(cold %create-view ;~(plug whitespace (jester 'create') whitespace (jester 'view')))
|
||||
(cold %drop-database ;~(plug whitespace (jester 'drop') whitespace (jester 'database')))
|
||||
(cold %drop-index ;~(plug whitespace (jester 'drop') whitespace (jester 'index')))
|
||||
(cold %drop-namespace ;~(plug whitespace (jester 'drop') whitespace (jester 'namespace')))
|
||||
(cold %drop-table ;~(plug whitespace (jester 'drop') whitespace (jester 'table')))
|
||||
(cold %drop-view ;~(plug whitespace (jester 'drop') whitespace (jester 'view')))
|
||||
:: (cold ;~(plug whitespace (jester '') whitespace (jester '')))
|
||||
==
|
||||
~| 'Current database name is not a proper face'
|
||||
@ -55,17 +97,16 @@
|
||||
%create-database
|
||||
~| 'Create database must be only statement in script'
|
||||
?> =((lent commands) 0)
|
||||
=/ database-name p.u.+3:q.+3:(parse-db-qualified-name [[1 1] q.q.command-nail])
|
||||
=/ database-ast (create-database:ast %create-database database-name)
|
||||
%= $
|
||||
script ""
|
||||
commands [`command-ast`database-ast commands]
|
||||
script ""
|
||||
commands
|
||||
[`command-ast`(create-database:ast %create-database p.u.+3:q.+3:(parse-face [[1 1] q.q.command-nail])) commands]
|
||||
==
|
||||
%create-index
|
||||
!!
|
||||
%create-namespace
|
||||
~| "Cannot parse name to face in create-namespace {<p.q.command-nail>}"
|
||||
=/ qualified-name-nail u.+3:q.+3:(parse-db-qualified-name [[1 1] q.q.command-nail])
|
||||
=/ qualified-name-nail u.+3:q.+3:(parse-qualified-2-name [[1 1] q.q.command-nail])
|
||||
=/ namespace-ast ?@ p.qualified-name-nail
|
||||
(create-namespace:ast %create-namespace current-database p.qualified-name-nail)
|
||||
(create-namespace:ast %create-namespace -:p.qualified-name-nail +:p.qualified-name-nail)
|
||||
@ -85,25 +126,98 @@
|
||||
!!
|
||||
%create-view
|
||||
!!
|
||||
%drop-database
|
||||
!!
|
||||
%drop-index
|
||||
!!
|
||||
%drop-namespace
|
||||
!!
|
||||
%drop-table
|
||||
!!
|
||||
%drop-view
|
||||
=/ parse-drop-view ;~ sfix
|
||||
;~(pose ;~(plug parse-force-or-3-name parse-qualified-3-name) parse-qualified-3-name)
|
||||
end-or-next-command
|
||||
==
|
||||
~| "Cannot parse drop-view {<p.q.command-nail>}"
|
||||
=/ drop-view-nail (parse-drop-view [[1 1] q.q.command-nail])
|
||||
=/ parsed p.u.+3:q.+3:drop-view-nail
|
||||
=/ cursor p.q.u.+3:q.+3:drop-view-nail
|
||||
=/ next-cursor ?: (gth -.cursor -.script-position) :: if we advanced to next input line
|
||||
cursor
|
||||
[-.cursor (add +.cursor +.script-position)]
|
||||
::
|
||||
:: "drop view force db.ns.name"
|
||||
?: ?=([@ [[@ %~] [@ %~] [@ %~]]] parsed)
|
||||
%= $
|
||||
script q.q.u.+3.q:drop-view-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(drop-view:ast %drop-view i.+<.parsed i.+>-.parsed i.+>+.parsed %.y) commands]
|
||||
==
|
||||
::
|
||||
:: "drop view force db..name"
|
||||
?: ?=([@ [[@ %~] @ @ [@ %~]]] parsed)
|
||||
%= $
|
||||
script q.q.u.+3.q:drop-view-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(drop-view:ast %drop-view i.+<.parsed 'dbo' +>+>-.parsed %.y) commands]
|
||||
==
|
||||
::
|
||||
:: "drop view force ns.name"
|
||||
?: ?=([@ [[@ %~] [@ %~]]] parsed)
|
||||
%= $
|
||||
script q.q.u.+3.q:drop-view-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(drop-view:ast %drop-view current-database i.+<.parsed +>-.parsed %.y) commands]
|
||||
==
|
||||
::
|
||||
:: "drop view force name"
|
||||
?: ?=([@ [@ %~]] parsed)
|
||||
%= $
|
||||
script q.q.u.+3.q:drop-view-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(drop-view:ast %drop-view current-database 'dbo' +<.parsed %.y) commands]
|
||||
==
|
||||
::
|
||||
:: "drop view db.ns.name"
|
||||
?: ?=([[[@ %~] [@ %~] [@ %~]] %~] parsed)
|
||||
%= $
|
||||
script q.q.u.+3.q:drop-view-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(drop-view:ast %drop-view i.-<.parsed i.->-.parsed i.->+.parsed %.n) commands]
|
||||
==
|
||||
::
|
||||
:: "drop view db..name"
|
||||
?: ?=([[[@ %~] @ @ [@ %~]] %~] parsed)
|
||||
%= $
|
||||
script q.q.u.+3.q:drop-view-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(drop-view:ast %drop-view i.-<.parsed 'dbo' ->+>-.parsed %.n) commands]
|
||||
==
|
||||
::
|
||||
:: "drop view ns.name"
|
||||
?: ?=([[[@ %~] [@ %~]] %~] parsed)
|
||||
%= $
|
||||
script q.q.u.+3.q:drop-view-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(drop-view:ast %drop-view current-database i.-<.parsed ->-.parsed %.n) commands]
|
||||
==
|
||||
::
|
||||
:: "drop view name"
|
||||
?: ?=([[@ %~] %~] parsed)
|
||||
%= $
|
||||
script q.q.u.+3.q:drop-view-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(drop-view:ast %drop-view current-database 'dbo' -<.parsed %.n) commands]
|
||||
==
|
||||
!!
|
||||
==
|
||||
::
|
||||
:: turn an atom into upper case cord
|
||||
::
|
||||
++ trip-cuss-crip
|
||||
|= target=@
|
||||
^- @t
|
||||
(crip (cuss (trip `@t`target)))
|
||||
::
|
||||
:: match a cord, case agnostic
|
||||
::
|
||||
++ jester
|
||||
|= daf=@t
|
||||
|= tub=nail
|
||||
=+ fad=daf
|
||||
|- ^- (like @t)
|
||||
?: =(`@`0 daf)
|
||||
[p=p.tub q=[~ u=[p=fad q=tub]]]
|
||||
?: |(?=(~ q.tub) !=((trip-cuss-crip (end 3 daf)) (trip-cuss-crip i.q.tub)))
|
||||
(fail tub)
|
||||
$(p.tub (lust i.q.tub p.tub), q.tub t.q.tub, daf (rsh 3 daf))
|
||||
--
|
||||
|
@ -216,9 +216,9 @@
|
||||
+$ create-index
|
||||
$:
|
||||
%create-index
|
||||
name=@t
|
||||
database-name=@t
|
||||
namespace=@t
|
||||
name=@t
|
||||
object-name=@t :: because index can be over table or view
|
||||
is-unique=?
|
||||
is-clustered=?
|
||||
@ -228,9 +228,9 @@
|
||||
+$ foreign-key
|
||||
$:
|
||||
%create-foreign-key
|
||||
name=@t
|
||||
database-name=@t
|
||||
namespace=@t
|
||||
name=@t
|
||||
table-name=@t
|
||||
columns=(list @t) :: the source columns
|
||||
reference-namespace=@t :: reference table and columns
|
||||
@ -242,9 +242,9 @@
|
||||
+$ create-table
|
||||
$:
|
||||
%create-table
|
||||
name=@t
|
||||
database-name=@t
|
||||
namespace=@t :: defaults to 'dbo'
|
||||
name=@t
|
||||
columns=(list column)
|
||||
primary-key=create-index
|
||||
foreign-keys=(list foreign-key)
|
||||
@ -252,9 +252,9 @@
|
||||
+$ create-trigger
|
||||
$:
|
||||
%create-trigger
|
||||
name=@t
|
||||
database-name=@t
|
||||
namespace=@t
|
||||
name=@t
|
||||
object-name=@t :: because trigger can be over table or view
|
||||
enabled=?
|
||||
==
|
||||
@ -262,47 +262,48 @@
|
||||
+$ create-view
|
||||
$:
|
||||
%create-view
|
||||
name=@t
|
||||
database-name=@t
|
||||
namespace=@t
|
||||
name=@t
|
||||
query=query :: awaiting construction of query
|
||||
==
|
||||
::
|
||||
:: drop ASTs
|
||||
::
|
||||
+$ drop-database $:([%drop-database name=@t warn=?])
|
||||
+$ drop-database $:([%drop-database name=@t force=?])
|
||||
+$ drop-index
|
||||
$:
|
||||
%drop-index
|
||||
name=@t
|
||||
database-name=@t
|
||||
name=@t
|
||||
namespace=@t
|
||||
object-name=@t :: because index can be over table or view
|
||||
==
|
||||
+$ drop-namespace $:([%drop-namespace database-name=@t name=@t force=?])
|
||||
+$ drop-table
|
||||
$:
|
||||
%drop-table
|
||||
name=@t
|
||||
database-name=@t
|
||||
namespace=@t
|
||||
warn=?
|
||||
name=@t
|
||||
force=?
|
||||
==
|
||||
+$ drop-namespace $:([%drop-namespace name=@t database-name=@t])
|
||||
+$ drop-trigger
|
||||
$:
|
||||
%drop-trigger
|
||||
name=@t
|
||||
database-name=@t
|
||||
namespace=@t
|
||||
name=@t
|
||||
object-name=@t :: because trigger can be over table or view
|
||||
==
|
||||
+$ drop-type $:([%drop-type name=@t])
|
||||
+$ drop-view
|
||||
$:
|
||||
%drop-view
|
||||
name=@t
|
||||
database-name=@t
|
||||
namespace=@t
|
||||
name=@t
|
||||
force=?
|
||||
==
|
||||
::
|
||||
:: alter ASTs
|
||||
@ -310,9 +311,9 @@
|
||||
+$ alter-index
|
||||
$:
|
||||
%alter-index
|
||||
name=@t
|
||||
database-name=@t
|
||||
namespace=@t
|
||||
name=@t
|
||||
object-name=@t :: because index can be over table or view
|
||||
action=index-action
|
||||
==
|
||||
@ -328,9 +329,9 @@
|
||||
+$ alter-table
|
||||
$:
|
||||
%alter-table
|
||||
name=@t
|
||||
database-name=@t
|
||||
namespace=@t :: defaults to 'dbo'
|
||||
name=@t
|
||||
alter-columns=(unit (list column))
|
||||
add-columns=(unit (list column))
|
||||
drop-columns=(unit (list @t))
|
||||
@ -340,18 +341,18 @@
|
||||
+$ alter-trigger
|
||||
$:
|
||||
%alter-trigger
|
||||
name=@t
|
||||
database-name=@t
|
||||
namespace=@t
|
||||
name=@t
|
||||
object-name=@t :: because trigger can be over table or view
|
||||
enabled=?
|
||||
==
|
||||
+$ alter-view
|
||||
$:
|
||||
%alter-view
|
||||
name=@t
|
||||
database-name=@t
|
||||
namespace=@t
|
||||
name=@t
|
||||
query=query :: awaiting construction of query
|
||||
==
|
||||
::
|
||||
|
@ -35,7 +35,7 @@
|
||||
:: fail when database name is not a face
|
||||
++ test-create-database-3
|
||||
%- expect-fail
|
||||
|. (parse:parse ['dummy' "cReate datAbase my+database"])
|
||||
|. (parse:parse ['dummy' "cReate datAbase My-database"])
|
||||
::
|
||||
:: fail when commands are prior to create database
|
||||
++ test-create-database-4
|
||||
@ -55,8 +55,7 @@
|
||||
++ test-create-namespace-2
|
||||
%+ expect-eq
|
||||
!> ~[[%create-namespace database-name='other-db' name='my-namespace']]
|
||||
!> %- parse:parse
|
||||
['other-db' " \09cReate\0d\09 namespace my-namespace "]
|
||||
!> (parse:parse ['other-db' " \09cReate\0d\09 namespace my-namespace "])
|
||||
::
|
||||
:: fail when database qualifier is not a face
|
||||
++ test-create-namespace-3
|
||||
@ -67,5 +66,62 @@
|
||||
++ test-create-namespace-4
|
||||
%- expect-fail
|
||||
|. (parse:parse ['other-db' "cReate namesPace my-db.Bad-face"])
|
||||
::
|
||||
:: tests 1, 2, 3, 5, and extra whitespace characters
|
||||
++ test-drop-view-1
|
||||
=/ expected1 [%drop-view database-name='db' namespace='ns' name='name' force=%.y]
|
||||
=/ expected2 [%drop-view database-name='db' namespace='ns' name='name' force=%.n]
|
||||
%+ expect-eq
|
||||
!> ~[expected1 expected2]
|
||||
!> %- parse:parse
|
||||
['other-db' "droP View FORce db.ns.name;droP View \0a db.ns.name"]
|
||||
::
|
||||
:: leading and trailing whitespace characters, end delimiter not required on single
|
||||
++ test-drop-view-2
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-view database-name='db' namespace='dbo' name='name' force=%.y]]
|
||||
!> (parse:parse ['other-db' " \09drop\0d\09 vIew\0aforce db..name "])
|
||||
++ test-drop-view-3
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-view database-name='db' namespace='dbo' name='name' force=%.n]]
|
||||
!> (parse:parse ['other-db' "drop view db..name"])
|
||||
++ test-drop-view-4
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-view database-name='other-db' namespace='ns' name='name' force=%.y]]
|
||||
!> (parse:parse ['other-db' "drop view force ns.name"])
|
||||
++ test-drop-view-5
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-view database-name='other-db' namespace='ns' name='name' force=%.n]]
|
||||
!> (parse:parse ['other-db' "drop view ns.name"])
|
||||
++ test-drop-view-6
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-view database-name='other-db' namespace='ns' name='name' force=%.y]]
|
||||
!> (parse:parse ['other-db' "drop view force ns.name"])
|
||||
++ test-drop-view-7
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-view database-name='other-db' namespace='ns' name='name' force=%.n]]
|
||||
!> (parse:parse ['other-db' "drop view ns.name"])
|
||||
++ test-drop-view-8
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-view database-name='other-db' namespace='dbo' name='name' force=%.y]]
|
||||
!> (parse:parse ['other-db' "DROP VIEW FORCE name"])
|
||||
++ test-drop-view-9
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-view database-name='other-db' namespace='dbo' name='name' force=%.n]]
|
||||
!> (parse:parse ['other-db' "DROP VIEW name"])
|
||||
::
|
||||
:: fail when database qualifier is not a face
|
||||
++ test-drop-view-10
|
||||
%- expect-fail
|
||||
|. (parse:parse ['other-db' "DROP VIEW Db.ns.name"])
|
||||
|
||||
:: fail when namespace qualifier is not a face
|
||||
++ test-drop-view-11
|
||||
%- expect-fail
|
||||
|. (parse:parse ['other-db' "DROP VIEW db.nS.name"])
|
||||
::
|
||||
:: fail when view name is not a face
|
||||
++ test-drop-view-12
|
||||
%- expect-fail
|
||||
|. (parse:parse ['other-db' "DROP VIEW db.ns.nAme"])
|
||||
--
|
||||
|
Loading…
Reference in New Issue
Block a user