diff --git a/Language/SQL/SimpleSQL/Lexer.lhs b/Language/SQL/SimpleSQL/Lexer.lhs
index 35a94ac..eb6340a 100644
--- a/Language/SQL/SimpleSQL/Lexer.lhs
+++ b/Language/SQL/SimpleSQL/Lexer.lhs
@@ -111,6 +111,13 @@ parsec
> prettyTokens :: Dialect -> [Token] -> String
> prettyTokens d ts = concat $ map (prettyToken d) ts
+When parsing a quoted identifier, you can have a double quote
+character in the identifier like this: "quotes""identifier" ->
+quoted"identifer. The double double quotes character is changed to a
+single character in the lexer and expanded back to two characters in
+the pretty printer. This also applies to strings, which can embed a
+single quote like this: 'string''with quote'.
+
> doubleChars :: Char -> String -> String
> doubleChars _ [] = []
> doubleChars c (d:ds) | c == d = c:d:doubleChars c ds
@@ -142,6 +149,14 @@ TODO: try to make all parsers applicative only
> sqlToken d = do
> p' <- getPosition
> let p = ("",sourceLine p', sourceColumn p')
+
+The order of parsers is important: strings and quoted identifiers can
+start out looking like normal identifiers, so we try to parse these
+first and use a little bit of try. Line and block comments start like
+symbols, so we try these before symbol. Numbers can start with a . so
+this is also tried before symbol (a .1 will be parsed as a number, but
+. otherwise will be parsed as a symbol).
+
> (p,) <$> choice [sqlString d
> ,identifier d
> ,hostParam d
@@ -151,10 +166,20 @@ TODO: try to make all parsers applicative only
> ,symbol d
> ,sqlWhitespace d]
+Parses identifiers:
+
+simple_identifier_23
+u&"unicode quoted identifier"
+"quoted identifier"
+"quoted identifier "" with double quote char"
+`mysql quoted identifier`
+
> identifier :: Dialect -> Parser Token
> identifier d =
> choice
> [QIdentifier <$> qiden
+> -- try is used here to avoid a conflict with identifiers
+> -- and quoted strings which also start with a 'u'
> ,UQIdentifier <$> ((try (string "u&" <|> string "U&")) *> qiden)
> ,Identifier <$> identifierString
> ,DQIdentifier "`" "`" <$> mySqlQIden
@@ -174,12 +199,23 @@ TODO: try to make all parsers applicative only
> guard (d == MySQL)
> char '`' *> takeWhile1 (/='`') <* char '`'
+This parses a valid identifier without quotes.
+
> identifierString :: Parser String
> identifierString =
> startsWith (\c -> c == '_' || isAlpha c)
> (\c -> c == '_' || isAlphaNum c)
+Parse a SQL string. Examples:
+
+'basic string'
+'string with '' a quote'
+n'international text'
+b'binary string'
+x'hexidecimal string'
+
+
> sqlString :: Dialect -> Parser Token
> sqlString _ =
> choice [csString
@@ -195,6 +231,10 @@ TODO: try to make all parsers applicative only
> void $ char '\''
> normalStringSuffix $ concat [t,s,"'"]
> ,return $ concat [t,s]]
+> -- try is used to to avoid conflicts with
+> -- identifiers which can start with n,b,x,u
+> -- once we read the quote type and the starting '
+> -- then we commit to a string
> csString = CSSqlString <$> try (cs <* char '\'') <*> normalStringSuffix ""
> cs = choice [(:[]) <$> oneOf "nNbBxX"
> ,string "u&"
@@ -204,17 +244,6 @@ TODO: try to make all parsers applicative only
> hostParam _ = HostParam <$> (char ':' *> identifierString)
-> sqlNumber :: Dialect -> Parser Token
-> sqlNumber _ = SqlNumber <$>
-> (int ?> (pp dot ?.> pp int)
-> <|> try ((++) <$> dot <*> int))
-> ?> pp expon
-> where
-> int = many1 digit
-> dot = string "."
-> expon = (:) <$> oneOf "eE" <*> sInt
-> sInt = (++) <$> option "" (string "+" <|> string "-") <*> int
-> pp = (<$$> (++))
digits
digits.[digits][e[+-]digits]
@@ -229,12 +258,32 @@ the constant. Note that any leading plus or minus sign is not actually
considered part of the constant; it is an operator applied to the
constant.
+> sqlNumber :: Dialect -> Parser Token
+> sqlNumber _ = SqlNumber <$>
+> (int ?> (pp dot ?.> pp int)
+> -- try is used in case we read a dot
+> -- and it isn't part of a number
+> -- if there are any following digits, then we commit
+> -- to it being a number and not something else
+> <|> try ((++) <$> dot <*> int))
+> ?> pp expon
+> where
+> int = many1 digit
+> dot = string "."
+> expon = (:) <$> oneOf "eE" <*> sInt
+> sInt = (++) <$> option "" (string "+" <|> string "-") <*> int
+> pp = (<$$> (++))
+
A symbol is one of the two character symbols, or one of the single
character symbols in the two lists below.
> symbol :: Dialect -> Parser Token
> symbol _ = Symbol <$> choice (many1 (char '.') :
+> -- try is used because most of the first
+> -- characters of the two character symbols
+> -- can also be part of a single character symbol
+> -- maybe this would be better with left factoring?
> map (try . string) [">=","<=","!=","<>","||"]
> ++ map (string . (:[])) "+-^*/%~&|?<>[]=,;()")
@@ -244,9 +293,15 @@ character symbols in the two lists below.
> lineComment :: Dialect -> Parser Token
> lineComment _ =
> (\s -> LineComment $ concat ["--",s]) <$>
+> -- try is used here in case we see a - symbol
+> -- once we read two -- then we commit to the comment token
> (try (string "--") *>
> manyTill anyChar (void (char '\n') <|> eof))
+Try is used in the block comment for the two symbol bits because we
+want to backtrack if we read the first symbol but the second symbol
+isn't there.
+
> blockComment :: Dialect -> Parser Token
> blockComment _ =
> (\s -> BlockComment $ concat ["/*",s]) <$>
@@ -268,6 +323,8 @@ character symbols in the two lists below.
> ,(\c s -> x ++ [c] ++ s) <$> anyChar <*> commentSuffix n]
+Some helper combinators
+
> startsWith :: (Char -> Bool) -> (Char -> Bool) -> Parser String
> startsWith p ps = do
> c <- satisfy p
diff --git a/Language/SQL/SimpleSQL/Parser.lhs b/Language/SQL/SimpleSQL/Parser.lhs
index a766f8e..eb046b1 100644
--- a/Language/SQL/SimpleSQL/Parser.lhs
+++ b/Language/SQL/SimpleSQL/Parser.lhs
@@ -1984,3 +1984,6 @@ dialect (for instance, string and identifier parsing rules vary from
dialect to dialect and version to version, and most or all SQL DBMSs
appear to have a set of flags to further enable or disable variations
for quoting and escaping strings and identifiers).
+
+The dialect stuff can also be used for custom options: e.g. to only
+parse dml for instance.
diff --git a/Language/SQL/SimpleSQL/Syntax.lhs b/Language/SQL/SimpleSQL/Syntax.lhs
index d7d7e80..c1e076b 100644
--- a/Language/SQL/SimpleSQL/Syntax.lhs
+++ b/Language/SQL/SimpleSQL/Syntax.lhs
@@ -1,5 +1,5 @@
-> -- | The AST for SQL queries.
+> -- | The AST for SQL.
> {-# LANGUAGE DeriveDataTypeable #-}
> module Language.SQL.SimpleSQL.Syntax
> (-- * Value expressions
diff --git a/simple-sql-parser.cabal b/simple-sql-parser.cabal
index dcd35db..ea9d9f2 100644
--- a/simple-sql-parser.cabal
+++ b/simple-sql-parser.cabal
@@ -1,9 +1,12 @@
name: simple-sql-parser
-version: 0.4.1
-synopsis: A parser for SQL queries
+version: 0.5.0
+synopsis: A parser for SQL.
-description: A parser for SQL queries. Parses most SQL:2011
- queries. Please see the homepage for more information
+description: A parser for SQL. Parses most SQL:2011
+ queries, DML, schema/DDL, transaction control,
+ session and connection management, access
+ control. Please see the homepage for more
+ information
.
homepage: http://jakewheat.github.io/simple-sql-parser/
@@ -68,7 +71,11 @@ Test-Suite Tests
Language.SQL.SimpleSQL.Postgres,
Language.SQL.SimpleSQL.QueryExprComponents,
Language.SQL.SimpleSQL.QueryExprs,
- Language.SQL.SimpleSQL.SQL2011,
+ Language.SQL.SimpleSQL.SQL2011Queries,
+ Language.SQL.SimpleSQL.SQL2011AccessControl,
+ Language.SQL.SimpleSQL.SQL2011Bits,
+ Language.SQL.SimpleSQL.SQL2011DataManipulation,
+ Language.SQL.SimpleSQL.SQL2011Schema,
Language.SQL.SimpleSQL.TableRefs,
Language.SQL.SimpleSQL.TestTypes,
Language.SQL.SimpleSQL.Tests,
diff --git a/tools/Language/SQL/SimpleSQL/SQL2011AccessControl.lhs b/tools/Language/SQL/SimpleSQL/SQL2011AccessControl.lhs
new file mode 100644
index 0000000..f443d81
--- /dev/null
+++ b/tools/Language/SQL/SimpleSQL/SQL2011AccessControl.lhs
@@ -0,0 +1,12 @@
+
+Section 12 in Foundation
+
+grant, etc
+
+
+> module Language.SQL.SimpleSQL.SQL2011AccessControl (sql2011AccessControlTests) where
+
+> import Language.SQL.SimpleSQL.TestTypes
+
+> sql2011AccessControlTests :: TestItem
+> sql2011AccessControlTests = Group "sql 2011 access control tests" []
diff --git a/tools/Language/SQL/SimpleSQL/SQL2011Bits.lhs b/tools/Language/SQL/SimpleSQL/SQL2011Bits.lhs
new file mode 100644
index 0000000..e3bc18f
--- /dev/null
+++ b/tools/Language/SQL/SimpleSQL/SQL2011Bits.lhs
@@ -0,0 +1,15 @@
+
+Sections 16, 17, 18 and 19 in Foundation
+
+This module covers the tests for control statements (call and return),
+transaction management (begin, commit, savepoint, etc.), connection
+management, and session management (set).
+
+
+> module Language.SQL.SimpleSQL.SQL2011Bits (sql2011BitsTests) where
+
+> import Language.SQL.SimpleSQL.TestTypes
+
+> sql2011BitsTests :: TestItem
+> sql2011BitsTests = Group "sql 2011 bits tests" []
+
diff --git a/tools/Language/SQL/SimpleSQL/SQL2011DataManipulation.lhs b/tools/Language/SQL/SimpleSQL/SQL2011DataManipulation.lhs
new file mode 100644
index 0000000..17aeb05
--- /dev/null
+++ b/tools/Language/SQL/SimpleSQL/SQL2011DataManipulation.lhs
@@ -0,0 +1,2497 @@
+
+Section 14 in Foundation
+
+
+> module Language.SQL.SimpleSQL.SQL2011DataManipulation (sql2011DataManipulationTests) where
+
+> import Language.SQL.SimpleSQL.TestTypes
+
+> sql2011DataManipulationTests :: TestItem
+> sql2011DataManipulationTests = Group "sql 2011 data manipulation tests" []
+
+
+14 Data manipulation
+
+
+14.1
+
+This Subclause is modified by Subclause 12.1, “”, in ISO/IEC 9075-4.
+
+
+Function
+Declare a standing cursor.
+
+
+Format
+ ::=
+ DECLARE
+ FOR
+
+
+Syntax Rules
+1) 04 If a is contained in an M, then:
+ a) The shall not be equivalent to the of any other ,
+ , or in M.
+ b) The scope of the is M with the exception of any contained
+ in M.
+ c) Any contained in the shall be defined in a in the that contains an that
+ specifies the and is contained in the scope of that .
+ NOTE 463 — See the Syntax Rules of Subclause 13.1, “”.
+
+
+Access Rules
+ None.
+
+
+General Rules
+1) A cursor declaration descriptor CDD is created. CDD includes indications that:
+ a) The kind of cursor is a standing cursor.
+ b) 04 The provenance of the cursor is an indication of the SQL-client module whose contains the .
+
+
+ Data manipulation 929
+IWD 9075-2:201?(E)
+14.1
+
+ c) The name of the cursor is the .
+ d) The cursor's origin is the contained in the .
+ e) The cursor's declared properties are as determined by the .
+
+
+Conformance Rules
+1) Without Feature F831, “Full cursor update”, conforming SQL language shall not contain a
+ that contains both a that contains an that specifies FOR
+ UPDATE and that contain a .
+
+
+
+
+930 Foundation (SQL/Foundation)
+ IWD 9075-2:201?(E)
+ 14.2
+
+
+14.2
+
+Function
+Specify the declared properties of a cursor.
+
+
+Format
+ ::=
+ [ ] [ ] CURSOR
+ [ ]
+ [ ]
+
+ ::=
+ SENSITIVE
+ | INSENSITIVE
+ | ASENSITIVE
+
+ ::=
+ SCROLL
+ | NO SCROLL
+
+ ::=
+ WITH HOLD
+ | WITHOUT HOLD
+
+ ::=
+ WITH RETURN
+ | WITHOUT RETURN
+
+
+Syntax Rules
+1) If is not specified, then ASENSITIVE is implicit.
+2) If is not specified, then NO SCROLL is implicit.
+3) If is not specified, then WITHOUT HOLD is implicit.
+4) If is not specified, then WITHOUT RETURN is implicit.
+
+
+Access Rules
+ None.
+
+
+General Rules
+1) The declared properties of the cursor declaration descriptor associated with are given
+ by:
+ a) The declared sensitivity property is the explicit or implicit .
+ b) The declared scrollability property is the explicit or implicit .
+
+
+ Data manipulation 931
+IWD 9075-2:201?(E)
+14.2
+
+ c) The declared holdability property is the explicit or implicit .
+ d) The declared returnability property is the explicit or implicit .
+
+
+Conformance Rules
+1) Without Feature T231, “Sensitive cursors”, conforming SQL language shall not contain a
+ that immediately contains SENSITIVE.
+2) Without Feature F791, “Insensitive cursors”, conforming SQL language shall not contain a that immediately contains INSENSITIVE.
+3) Without Feature F791, “Insensitive cursors”, or Feature T231, “Sensitive cursors”, conforming SQL language
+ shall not contain a that immediately contains ASENSITIVE.
+4) Without Feature F431, “Read-only scrollable cursors”, conforming SQL language shall not contain a
+ .
+5) Without Feature T471, “Result sets return value”, conforming SQL language shall not contain a .
+6) Without Feature T551, “Optional key words for default syntax”, conforming SQL language shall not contain
+ a that immediately contains WITHOUT HOLD.
+
+
+
+
+932 Foundation (SQL/Foundation)
+ IWD 9075-2:201?(E)
+ 14.3
+
+
+14.3
+
+Function
+Define a result set.
+
+
+Format
+ ::=
+ [ ]
+
+ ::=
+ FOR { READ ONLY | UPDATE [ OF ] }
+
+
+Syntax Rules
+1) Let CS be the .
+2) Let QE be the immediately contained in CS.
+3) Case:
+ a) If CS is contained in a DC that contains a , then let CP be that
+ .
+ b) If CS is a being prepared by a or re-prepared by an
+ or a , then:
+ i) Let STMT be the that is preparing CS, or the or that is re-preparing CS. Let SCMD be the
+ that contains STMT.
+ ii) Case:
+ 1) If CS is being prepared by a , then let PS be that .
+ 2) Otherwise, let PS be the that previously prepared CS.
+ iii) Let SSV be the contained in PS.
+ iv) Case:
+ 1) If CS is being prepared by a , then:
+ Case:
+ A) If SSV is a and there is exactly one DDC
+ contained in SCMD whose is equivalent to SSV, then let CP1 be
+ the contained in DDC.
+ B) If SSV is an that specifies or implies a
+ that is LOCAL, and there is exactly one
+ ACS contained in SCMD whose specifies or implies
+ LOCAL, then let CP1 be the contained in ACS.
+
+
+ Data manipulation 933
+IWD 9075-2:201?(E)
+14.3
+
+ C) Otherwise, let CP1 be a zero-length string.
+ 2) If CS is being re-prepared by an ACS, then
+ let CP1 be the contained in ACS.
+ 3) If CS is being re-prepared by a , then let DDC be the whose is equivalent to the contained in
+ STMT. Let CP1 be the contained in DDC.
+ v) If PS contains an , then let CP2 be the value of that ;
+ otherwise, let CP2 be the zero-length string.
+ vi) Case:
+ 1) If CP2 contains , then let SENS be that .
+ 2) If CP1 contains , then let SENS be that .
+ 3) Otherwise, let SENS be the zero-length string.
+ vii) Case:
+ 1) If CP2 contains , then let SCRO be that .
+ 2) If CP1 contains , then let SCRO be that .
+ 3) Otherwise, let SCRO be the zero-length string.
+ viii) Case:
+ 1) If CP2 contains , then let HOLD be that .
+ 2) If CP1 contains , then let HOLD be that .
+ 3) Otherwise, let HOLD be the zero-length string.
+ ix) Case:
+ 1) If CP2 contains , then let RET be that .
+ 2) If CP1 contains , then let RET be that .
+ 3) Otherwise, let RET be the zero-length string.
+ x) Let CP be the :
+
+ SENS SCRO CURSOR HOLD RET
+
+4) If is not specified and either CS is contained in a or is being re-
+ prepared by an or a , then
+ Case:
+ a) If CP contains INSENSITIVE or SCROLL, or QE immediately contains an , or QE
+ is not a simply updatable , then an of READ ONLY is
+ implicit.
+ b) Otherwise, an of FOR UPDATE without a is implicit.
+
+
+
+934 Foundation (SQL/Foundation)
+ IWD 9075-2:201?(E)
+ 14.3
+
+ NOTE 464 — If CS is being prepared by a , then defaulting the is postponed until
+ CS is re-prepared.
+
+5) If an of FOR UPDATE with or without a is specified, then CP
+ shall not contain INSENSITIVE, QE shall be updatable, and QE shall have only one leaf underlying table
+ LUT such that QE is one-to-one with respect to LUT.
+6) Case:
+ a) If an specifying FOR UPDATE is specified or implicit, then CS is updatable.
+ b) If an specifying FOR READ ONLY is specified or implicit, then CS is not
+ updatable.
+ c) Otherwise, the determination of updatability of CS is postponed until CS is re-prepared.
+7) If CS is updatable, then let LUTN be a
that references LUT. LUTN is an exposed
whose scope is .
+8) If an of FOR UPDATE without a is specified or implicit, then
+ a that consists of the of every column of LUT is implicit.
+9) If an of FOR UPDATE with a is specified, then each in the shall be the of a column of LUT.
+
+
+Access Rules
+ None.
+
+
+General Rules
+ None.
+
+
+Conformance Rules
+1) Without Feature F831, “Full cursor update”, conforming SQL language shall not contain a that contains both an that specifies FOR UPDATE and an .
+2) Without Feature T111, “Updatable joins, unions, and columns”, in conforming SQL language, if FOR
+ UPDATE is specified, then QE shall be simply updatable.
+
+
+
+
+ Data manipulation 935
+IWD 9075-2:201?(E)
+14.4
+
+
+14.4
+
+This Subclause is modified by Subclause 12.2, “”, in ISO/IEC 9075-4.
+
+
+Function
+Open a standing cursor.
+
+
+Format
+ ::=
+ OPEN
+
+
+Syntax Rules
+1) 04 Let CN be the in the . CN shall be contained within the scope of a
+
+ that is equivalent to CN.
+2) CN shall identify a standing cursor.
+3) Let CDD be the cursor declaration descriptor of the standing cursor identified by CN.
+
+
+Access Rules
+1) The Access Rules for the simply contained in the identified by the
+ are applied.
+
+
+General Rules
+1) Let CR be the cursor instance descriptor in the current SQL-session whose cursor declaration descriptor
+ is CDD.
+2) The General Rules of Subclause 15.1, “Effect of opening a cursor”, are applied with CR as CURSOR.
+
+
+Conformance Rules
+ None.
+
+
+
+
+936 Foundation (SQL/Foundation)
+ IWD 9075-2:201?(E)
+ 14.5
+
+
+14.5
+
+This Subclause is modified by Subclause 12.3, “”, in ISO/IEC 9075-4.
+This Subclause is modified by Subclause 11.15, “”, in ISO/IEC 9075-10.
+This Subclause is modified by Subclause 14.1, “”, in ISO/IEC 9075-14.
+
+
+Function
+Position a standing cursor on a specified row of the standing cursor's result set and retrieve values from that
+row.
+
+
+Format
+ 10 ::=
+ FETCH [ [ ] FROM ] INTO
+
+ ::=
+ NEXT
+ | PRIOR
+ | FIRST
+ | LAST
+ | { ABSOLUTE | RELATIVE }
+
+ 14 ::=
+ [ { }... ]
+
+
+Syntax Rules
+1) shall not contain a that specifies a .
+2) If the is omitted, then NEXT is implicit.
+3) 04 10 Let CN be the in the . CN shall be contained within the scope of a
+
+ that is equivalent to CN.
+4) CN shall identify a standing cursor.
+5) Let CDD be the cursor declaration descriptor of the standing cursor identified by CN.
+6) Let T be the result set defined by the of CDD.
+7) If the implicit or explicit is not NEXT, then the declared scrollability property of CDD
+ shall be SCROLL.
+8) If a that contains a is specified, then the declared type of
+ that shall be exact numeric with a scale of 0 (zero).
+9) Case:
+ a) If the contains a single TS and the degree of T is greater than
+ 1 (one), then the declared type of TS shall be a row type.
+ Case:
+
+
+
+ Data manipulation 937
+IWD 9075-2:201?(E)
+14.5
+
+ i) 04 If TS is an , then the Syntax Rules of Subclause 9.2, “Store
+
+ assignment”, are applied with TS as TARGET and an arbitrary value of the row type of T as
+ VALUE.
+ ii) Otherwise, the Syntax Rules of Subclause 9.1, “Retrieval assignment”, are applied with TS as
+ TARGET and an arbitrary value of the row type of T as VALUE.
+ b) Otherwise:
+ i) The number of s NTS in the shall be the same as the
+ degree of T. The i-th , 1 (one) ≤ i ≤ NTS, in the corre-
+ sponds with the i-th column of T.
+ ii) For i varying from 1 (one) to NTS, let CSi be an arbitrary value of the declared type of the i-th
+ column of T.
+ iii) 04 For each TS1i, 1 (one) ≤ i ≤ NTS, that is either an or a ,
+ Case:
+ 1) If TS1i contains a , then the Syntax Rules of Subclause 9.2,
+ “Store assignment”, are applied with an arbitrary site whose declared type is the declared
+ type of TS1i as TARGET and CSi as VALUE.
+
+ 2) Otherwise, the Syntax Rules of Subclause 9.2, “Store assignment”, are applied with TS1i
+ as TARGET and CSi as VALUE.
+
+ iv) 10 For each TS2i, 1 (one) ≤ i ≤ NTS, that is a , the Syntax Rules of Subclause 9.1, “Retrieval assignment”, are applied with TS2i as
+ TARGET and CSi as VALUE.
+
+ v) For each TS2i, 1 (one) ≤ i, ≤ NTS, that is an , the Syntax Rules of Subclause 9.1, “Retrieval assignment”, are applied with TS2i as
+ TARGET and CSi as VALUE.
+
+
+Access Rules
+ None.
+
+
+General Rules
+1) Let CR be the cursor instance descriptor of the current SQL-session whose cursor declaration descriptor
+ is CDD.
+2) If CR is not in the open state, then an exception condition is raised: invalid cursor state.
+3) The General Rules of Subclause 15.3, “Determination of the current row of a cursor”, are applied with CR
+ as CURSOR and as FETCH ORIENTATION.
+4) If a completion condition no data has been raised, then no further General Rules of this Subclause are
+ applied.
+
+
+938 Foundation (SQL/Foundation)
+ IWD 9075-2:201?(E)
+ 14.5
+
+5) Case:
+ a) If the contains a single TS and the degree of T is greater than
+ 1 (one), then the current row is assigned to TS and
+ Case:
+ i) 04 14 If TS is an , then the General Rules of Subclause 9.2, “Store
+
+ assignment”, are applied with TS as TARGET and the current row as VALUE.
+ ii) Otherwise, the General Rules of Subclause 9.1, “Retrieval assignment”, are applied with TS as
+ TARGET and the current row as VALUE.
+ b) 10 Otherwise, if the contains more than one , then values from
+
+ the current row are assigned to their corresponding targets identified by the . The
+ assignments are made in an implementation-dependent order. Let TV be a target and let SV denote its
+ corresponding value in the current row of CR.
+ Case:
+ i) 04 If TV is either an or a , then
+
+ for each in the , let TVi be the i-th
+ in the and let SVi denote the i-th corresponding value in the current row of
+ CR.
+ Case:
+ 1) If is specified, then
+ Case:
+ A) If the value of TVi is the null value, then an exception condition is raised: data
+ exception — null value in array target.
+ B) Otherwise:
+ I) Let N be the maximum cardinality of TVi.
+
+ II) Let M be the cardinality of the value of TVi.
+
+ III) Let I be the value of the immediately contained
+ in TVi.
+
+ IV) Let EDT be the element type of TVi.
+
+ V) Case:
+ 1) If I is greater than zero and less than or equal to M, then the value of TVi
+ is replaced by an array A with element type EDT and cardinality M derived
+ as follows:
+ a) For j varying from 1 (one) to I–1 and from I+1 to M, the j-th element
+ in A is the value of the j-th element in TVi.
+
+ b) 14 The General Rules of Subclause 9.2, “Store assignment”, are applied
+
+ with I-th element of A as TARGET and SVi as VALUE.
+
+
+
+ Data manipulation 939
+IWD 9075-2:201?(E)
+14.5
+
+ 2) If I is greater than M and less than or equal to N, then the value of TVi is
+ replaced by an array A with element type EDT and cardinality I derived
+ as follows:
+ a) For j varying from 1 (one) to M, the j-th element in A is the value of
+ the j-th element in TVi.
+
+ b) For j varying from M+1 to I, the j-th element in A is the null value.
+ c) 14 The General Rules of Subclause 9.2, “Store assignment”, are applied
+
+ with I-th element of A as TARGET and SVi as VALUE.
+
+ 3) Otherwise, an exception condition is raised: data exception — array element
+ error.
+ 2) 14 Otherwise, the General Rules of Subclause 9.2, “Store assignment”, are applied with
+
+ TVi as TARGET and SVi as VALUE.
+
+ ii) If TV is a , then the General Rules of Subclause 9.1, “Retrieval assign-
+ ment”, are applied with TV as TARGET and SV as VALUE.
+ iii) If TV is an , then the General Rules of Subclause 9.1,
+ “Retrieval assignment”, are applied with TV as TARGET and SV as VALUE.
+ NOTE 465 — SQL parameters cannot have as their data types any row type.
+
+6) If an exception condition occurs during the assignment of a value to a target, then the values of all targets
+ are implementation-dependent.
+ NOTE 466 — It is implementation-dependent whether CR remains positioned on the current row when an exception condition
+ is raised during the derivation of any .
+
+
+Conformance Rules
+1) Without Feature F431, “Read-only scrollable cursors”, in conforming SQL language, a
+ shall not contain a .
+
+
+
+
+940 Foundation (SQL/Foundation)
+ IWD 9075-2:201?(E)
+ 14.6
+
+
+14.6
+
+This Subclause is modified by Subclause 12.4, “”, in ISO/IEC 9075-4.
+
+
+Function
+Close a standing cursor.
+
+
+Format
+ ::=
+ CLOSE
+
+
+Syntax Rules
+1) 04 Let CN be the in the . CN shall be contained within the scope of a
+
+ that is equivalent to CN.
+2) CN shall identify a standing cursor.
+3) Let CDD be the cursor declaration descriptor of the standing cursor identified by CN.
+
+
+Access Rules
+ None.
+
+
+General Rules
+1) Let CR be the cursor instance descriptor of the current SQL-session whose cursor declaration descriptor
+ is CDD.
+2) The General Rules of Subclause 15.4, “Effect of closing a cursor”, are applied with CR as CURSOR and
+ DESTROY as DISPOSITION.
+
+
+Conformance Rules
+ None.
+
+
+
+
+ Data manipulation 941
+IWD 9075-2:201?(E)
+14.7