Wiki page
[4.1.0 Changes] by
sandro
2013-05-08 22:29:09.
0000: 44 20 32 30 31 33 2d 30 35 2d 30 38 54 32 32 3a D 2013-05-08T22:
0010: 32 39 3a 30 39 2e 33 38 34 0a 4c 20 34 2e 31 2e 29:09.384.L 4.1.
0020: 30 5c 73 43 68 61 6e 67 65 73 0a 50 20 66 64 65 0\sChanges.P fde
0030: 65 39 33 64 39 65 33 33 38 39 38 61 31 32 31 63 e93d9e33898a121c
0040: 30 61 38 66 31 61 62 34 66 35 35 64 63 66 62 34 0a8f1ab4f55dcfb4
0050: 30 33 36 31 34 0a 55 20 73 61 6e 64 72 6f 0a 57 03614.U sandro.W
0060: 20 31 39 33 39 33 0a 62 61 63 6b 20 74 6f 20 3c 19393.back to <
0070: 61 20 68 72 65 66 3d 22 68 74 74 70 73 3a 2f 2f a href="https://
0080: 77 77 77 2e 67 61 69 61 2d 67 69 73 2e 69 74 2f www.gaia-gis.it/
0090: 66 6f 73 73 69 6c 2f 6c 69 62 73 70 61 74 69 61 fossil/libspatia
00a0: 6c 69 74 65 2f 77 69 6b 69 3f 6e 61 6d 65 3d 34 lite/wiki?name=4
00b0: 2e 31 2e 30 2d 64 6f 63 22 3e 34 2e 31 2e 30 2d .1.0-doc">4.1.0-
00c0: 64 6f 63 3c 2f 61 3e 0d 0a 3c 68 32 3e 4e 65 77 doc</a>..<h2>New
00d0: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 73 20 69 SQL functions i
00e0: 6e 74 72 6f 64 75 63 65 64 20 69 6e 20 34 2e 31 ntroduced in 4.1
00f0: 2e 30 3c 2f 68 32 3e 0d 0a 54 61 62 6c 65 20 6f .0</h2>..Table o
0100: 66 20 63 6f 6e 74 65 6e 74 73 3a 0d 0a 3c 75 6c f contents:..<ul
0110: 3e 0d 0a 3c 6c 69 3e 53 51 4c 20 66 75 6e 63 74 >..<li>SQL funct
0120: 69 6f 6e 73 20 73 75 70 70 6f 72 74 69 6e 67 20 ions supporting
0130: 3c 61 20 68 72 65 66 3d 22 23 63 61 73 74 22 3e <a href="#cast">
0140: 64 61 74 61 2d 74 79 70 65 20 63 61 73 74 69 6e data-type castin
0150: 67 3c 2f 61 3e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e g</a></li>..<li>
0160: 53 51 4c 20 66 75 6e 63 74 69 6f 6e 73 20 73 75 SQL functions su
0170: 70 70 6f 72 74 69 6e 67 20 3c 61 20 68 72 65 66 pporting <a href
0180: 3d 22 23 75 75 69 64 22 3e 55 55 49 44 20 67 65 ="#uuid">UUID ge
0190: 6e 65 72 61 74 69 6f 6e 3c 2f 61 3e 3c 2f 6c 69 neration</a></li
01a0: 3e 0d 0a 3c 6c 69 3e 53 70 61 74 69 61 6c 20 53 >..<li>Spatial S
01b0: 51 4c 20 66 75 6e 63 74 69 6f 6e 73 20 73 75 70 QL functions sup
01c0: 70 6f 72 74 69 6e 67 20 3c 61 20 68 72 65 66 3d porting <a href=
01d0: 22 23 67 65 6f 6d 22 3e 47 65 6f 6d 65 74 72 69 "#geom">Geometri
01e0: 65 73 3c 2f 61 3e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 es</a></li>..<li
01f0: 3e 53 51 4c 20 66 75 6e 63 74 69 6f 6e 73 20 73 >SQL functions s
0200: 75 70 70 6f 72 74 69 6e 67 20 3c 61 20 68 72 65 upporting <a hre
0210: 66 3d 22 23 75 6e 73 61 66 65 22 3e 75 6e 73 61 f="#unsafe">unsa
0220: 66 65 3c 2f 61 3e 20 64 69 72 65 63 74 20 49 6d fe</a> direct Im
0230: 70 6f 72 74 2f 45 78 70 6f 72 74 3c 2f 6c 69 3e port/Export</li>
0240: 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 68 33 3e 3c 61 20 ..</ul>..<h3><a
0250: 6e 61 6d 65 3d 22 67 65 6e 65 72 69 63 22 3e 63 name="generic">c
0260: 61 73 74 3c 2f 61 3e 20 53 51 4c 20 66 75 6e 63 ast</a> SQL func
0270: 74 69 6f 6e 73 20 2d 20 74 79 70 65 20 63 61 73 tions - type cas
0280: 74 69 6e 67 3c 2f 68 33 3e 0d 0a 53 51 4c 69 74 ting</h3>..SQLit
0290: 65 20 6f 66 66 65 72 73 20 6a 75 73 74 20 61 20 e offers just a
02a0: 76 65 72 79 20 62 61 73 69 63 20 74 79 70 65 20 very basic type
02b0: 63 68 65 63 6b 69 6e 67 3b 20 74 68 69 73 20 69 checking; this i
02c0: 73 20 73 6f 6d 65 74 69 6d 65 73 20 75 73 65 66 s sometimes usef
02d0: 75 6c 2c 20 62 75 74 20 63 6f 75 6c 64 20 62 65 ul, but could be
02e0: 20 72 65 61 6c 6c 79 20 61 6e 6e 6f 79 69 6e 67 really annoying
02f0: 20 76 65 72 79 20 6f 66 74 65 6e 2e 3c 62 72 3e very often.<br>
0300: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 ..<verbatim>..SE
0310: 4c 45 43 54 20 27 31 27 2c 20 54 79 70 65 4f 66 LECT '1', TypeOf
0320: 28 20 27 31 27 20 29 2c 20 43 41 53 54 20 28 20 ( '1' ), CAST (
0330: 27 31 27 20 41 53 20 49 4e 54 45 47 45 52 20 29 '1' AS INTEGER )
0340: 2c 20 54 79 70 65 4f 66 28 20 43 41 53 54 20 28 , TypeOf( CAST (
0350: 20 27 31 27 20 41 53 20 49 4e 54 45 47 45 52 20 '1' AS INTEGER
0360: 29 20 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d ) );..</verbatim
0370: 3e 0d 0a 3c 74 61 62 6c 65 20 62 6f 72 64 65 72 >..<table border
0380: 3d 22 31 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 ="1" cellspacing
0390: 3d 22 34 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 ="4" cellpadding
03a0: 3d 22 34 22 3e 0d 0a 3c 74 72 3e 3c 74 68 3e 27 ="4">..<tr><th>'
03b0: 31 27 3c 2f 74 68 3e 3c 74 68 3e 54 79 70 65 4f 1'</th><th>TypeO
03c0: 66 28 20 27 31 27 20 29 3c 2f 74 68 3e 3c 74 68 f( '1' )</th><th
03d0: 3e 43 41 53 54 20 28 20 27 31 27 20 41 53 20 49 >CAST ( '1' AS I
03e0: 4e 54 45 47 45 52 20 29 3c 2f 74 68 3e 3c 74 68 NTEGER )</th><th
03f0: 3e 54 79 70 65 4f 66 28 20 43 41 53 54 20 28 20 >TypeOf( CAST (
0400: 27 31 27 20 41 53 20 49 4e 54 45 47 45 52 20 29 '1' AS INTEGER )
0410: 20 29 3c 2f 74 68 3e 3c 2f 74 72 3e 0d 0a 3c 74 )</th></tr>..<t
0420: 72 3e 3c 74 64 3e 31 3c 2f 74 64 3e 3c 74 64 3e r><td>1</td><td>
0430: 74 65 78 74 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 text</td><td ali
0440: 67 6e 3d 22 72 69 67 68 74 22 3e 31 3c 2f 74 64 gn="right">1</td
0450: 3e 3c 74 64 3e 69 6e 74 65 67 65 72 3c 2f 74 64 ><td>integer</td
0460: 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 3c 62 ></tr></table><b
0470: 72 3e 0d 0a 54 68 65 20 53 51 4c 20 3c 62 3e 43 r>..The SQL <b>C
0480: 41 53 54 3c 2f 62 3e 20 6f 70 65 72 61 74 6f 72 AST</b> operator
0490: 20 61 6c 72 65 61 64 79 20 73 75 70 70 6f 72 74 already support
04a0: 73 20 74 68 65 20 70 6f 73 73 69 62 69 6c 69 74 s the possibilit
04b0: 79 20 74 6f 20 65 78 70 6c 69 63 69 74 6c 79 20 y to explicitly
04c0: 73 65 74 20 61 20 64 61 74 61 2d 74 79 70 65 3b set a data-type;
04d0: 20 6e 6f 77 20 73 74 61 72 74 69 6e 67 20 73 69 now starting si
04e0: 6e 63 65 20 34 2e 31 2e 30 20 53 70 61 74 69 61 nce 4.1.0 Spatia
04f0: 4c 69 74 65 20 73 75 70 70 6f 72 74 73 20 66 65 Lite supports fe
0500: 77 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 73 20 w SQL functions
0510: 70 65 72 66 6f 72 6d 69 6e 67 20 74 68 65 20 73 performing the s
0520: 61 6d 65 20 74 61 73 6b 2e 3c 62 72 3e 0d 0a 3c ame task.<br>..<
0530: 75 3e 50 6c 65 61 73 65 20 6e 6f 74 65 3c 2f 75 u>Please note</u
0540: 3e 3a 20 73 6f 6d 65 20 73 75 62 74 6c 65 20 64 >: some subtle d
0550: 69 66 66 65 72 65 6e 63 65 73 20 65 78 69 73 74 ifferences exist
0560: 73 20 68 65 72 65 20 61 6e 64 20 74 68 65 72 65 s here and there
0570: 3b 20 70 6c 65 61 73 65 20 63 61 72 65 66 75 6c ; please careful
0580: 6c 79 20 72 65 61 64 20 74 68 69 73 20 64 6f 63 ly read this doc
0590: 75 6d 65 6e 74 61 74 69 6f 6e 20 70 61 67 65 2e umentation page.
05a0: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 ..<verbatim>..SE
05b0: 4c 45 43 54 20 43 61 73 74 54 6f 49 6e 74 65 67 LECT CastToInteg
05c0: 65 72 28 20 31 20 29 2c 20 43 61 73 74 54 6f 49 er( 1 ), CastToI
05d0: 6e 74 65 67 65 72 28 20 31 2e 34 20 29 2c 20 43 nteger( 1.4 ), C
05e0: 61 73 74 54 6f 49 6e 74 65 67 65 72 28 20 31 2e astToInteger( 1.
05f0: 36 20 29 2c 20 0d 0a 20 20 20 20 43 61 73 74 54 6 ), .. CastT
0600: 6f 49 6e 74 65 67 65 72 28 20 27 31 32 33 27 20 oInteger( '123'
0610: 29 2c 20 43 61 73 74 54 6f 49 6e 74 65 67 65 72 ), CastToInteger
0620: 28 20 27 61 6c 70 68 61 27 20 29 2c 20 43 61 73 ( 'alpha' ), Cas
0630: 74 54 6f 49 6e 74 65 67 65 72 20 28 20 7a 65 72 tToInteger ( zer
0640: 6f 62 6c 6f 62 28 34 29 20 29 3b 0d 0a 3c 2f 76 oblob(4) );..</v
0650: 65 72 62 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c 65 erbatim>..<table
0660: 20 62 6f 72 64 65 72 3d 22 31 22 20 63 65 6c 6c border="1" cell
0670: 73 70 61 63 69 6e 67 3d 22 34 22 20 63 65 6c 6c spacing="4" cell
0680: 70 61 64 64 69 6e 67 3d 22 34 22 3e 0d 0a 3c 74 padding="4">..<t
0690: 72 3e 3c 74 68 3e 43 61 73 74 54 6f 49 6e 74 65 r><th>CastToInte
06a0: 67 65 72 28 20 31 20 29 3c 2f 74 68 3e 3c 74 68 ger( 1 )</th><th
06b0: 3e 43 61 73 74 54 6f 49 6e 74 65 67 65 72 28 20 >CastToInteger(
06c0: 31 2e 34 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 61 1.4 )</th><th>Ca
06d0: 73 74 54 6f 49 6e 74 65 67 65 72 28 20 31 2e 36 stToInteger( 1.6
06e0: 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 61 73 74 54 )</th><th>CastT
06f0: 6f 49 6e 74 65 67 65 72 28 20 27 31 32 33 27 20 oInteger( '123'
0700: 29 3c 2f 74 68 3e 3c 74 68 3e 43 61 73 74 54 6f )</th><th>CastTo
0710: 49 6e 74 65 67 65 72 28 20 27 61 6c 70 68 61 27 Integer( 'alpha'
0720: 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 61 73 74 54 )</th><th>CastT
0730: 6f 49 6e 74 65 67 65 72 20 28 20 7a 65 72 6f 62 oInteger ( zerob
0740: 6c 6f 62 28 34 29 20 29 3c 2f 74 68 3e 3c 2f 74 lob(4) )</th></t
0750: 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 6c 69 67 r>..<tr><td alig
0760: 6e 3d 22 72 69 67 68 74 22 3e 31 3c 2f 74 64 3e n="right">1</td>
0770: 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 <td align="right
0780: 22 3e 31 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 67 ">1</td><td alig
0790: 6e 3d 22 72 69 67 68 74 22 3e 32 3c 2f 74 64 3e n="right">2</td>
07a0: 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 <td align="right
07b0: 22 3e 31 32 33 3c 2f 74 64 3e 3c 74 64 3e 4e 55 ">123</td><td>NU
07c0: 4c 4c 3c 2f 74 64 3e 3c 74 64 3e 4e 55 4c 4c 3c LL</td><td>NULL<
07d0: 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 /td></tr></table
07e0: 3e 3c 62 72 3e 0d 0a 54 68 65 20 3c 62 3e 43 61 ><br>..The <b>Ca
07f0: 73 74 54 6f 49 6e 74 65 67 65 72 28 29 3c 2f 62 stToInteger()</b
0800: 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 77 > SQL function w
0810: 69 6c 6c 20 61 74 74 65 6d 70 74 20 74 6f 20 72 ill attempt to r
0820: 65 74 75 72 6e 20 61 20 76 61 6c 75 65 20 6f 66 eturn a value of
0830: 20 74 68 65 20 3c 62 3e 49 6e 74 65 67 65 72 3c the <b>Integer<
0840: 2f 62 3e 20 64 61 74 61 2d 74 79 70 65 2c 20 6f /b> data-type, o
0850: 72 20 3c 62 3e 4e 55 4c 4c 3c 2f 62 3e 20 69 66 r <b>NULL</b> if
0860: 20 6e 6f 20 63 6f 6e 76 65 72 73 69 6f 6e 20 69 no conversion i
0870: 73 20 70 6f 73 73 69 62 6c 65 2e 0d 0a 3c 75 6c s possible...<ul
0880: 3e 0d 0a 3c 6c 69 3e 61 6e 20 49 6e 74 65 67 65 >..<li>an Intege
0890: 72 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 r input argument
08a0: 20 77 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 will be returne
08b0: 64 20 61 62 73 6f 6c 75 74 65 6c 79 20 75 6e 61 d absolutely una
08c0: 66 66 65 63 74 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c ffected.</li>..<
08d0: 6c 69 3e 61 20 44 6f 75 62 6c 65 20 69 6e 70 75 li>a Double inpu
08e0: 74 20 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 t argument will
08f0: 72 65 74 75 72 6e 20 74 68 65 20 3c 75 3e 6e 65 return the <u>ne
0900: 61 72 65 73 74 3c 2f 75 3e 20 49 6e 74 65 67 65 arest</u> Intege
0910: 72 20 76 61 6c 75 65 20 28 61 66 74 65 72 20 61 r value (after a
0920: 70 70 6c 79 69 6e 67 20 3c 62 3e 34 2f 35 3c 2f pplying <b>4/5</
0930: 62 3e 20 72 6f 75 6e 64 69 6e 67 29 2e 3c 2f 6c b> rounding).</l
0940: 69 3e 0d 0a 3c 6c 69 3e 61 20 54 65 78 74 20 69 i>..<li>a Text i
0950: 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 nput argument wi
0960: 6c 6c 20 72 65 74 75 72 6e 20 74 68 65 20 63 6f ll return the co
0970: 72 72 65 73 70 6f 6e 64 69 6e 67 20 49 6e 74 65 rresponding Inte
0980: 67 65 72 20 76 61 6c 75 65 20 6f 6e 6c 79 20 69 ger value only i
0990: 66 20 74 68 65 20 74 65 78 74 20 73 74 72 69 6e f the text strin
09a0: 67 20 72 65 70 72 65 73 65 6e 74 73 20 61 20 76 g represents a v
09b0: 61 6c 69 64 20 6e 75 6d 62 65 72 20 28 65 76 65 alid number (eve
09c0: 6e 20 61 20 64 65 63 69 6d 61 6c 20 6f 6e 65 29 n a decimal one)
09d0: 3a 20 69 66 20 74 68 65 20 74 65 78 74 20 73 74 : if the text st
09e0: 72 69 6e 67 20 63 61 6e 6e 6f 74 20 62 65 20 63 ring cannot be c
09f0: 6f 6e 76 65 72 74 65 64 20 74 6f 20 61 20 6e 75 onverted to a nu
0a00: 6d 62 65 72 20 4e 55 4c 4c 20 77 69 6c 6c 20 62 mber NULL will b
0a10: 65 20 72 65 74 75 72 6e 65 64 2e 3c 2f 6c 69 3e e returned.</li>
0a20: 0d 0a 3c 6c 69 3e 61 6e 79 20 42 4c 4f 42 20 69 ..<li>any BLOB i
0a30: 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 nput argument wi
0a40: 6c 6c 20 72 65 74 75 72 6e 20 61 20 4e 55 4c 4c ll return a NULL
0a50: 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c value.</li>..<l
0a60: 69 3e 61 6e 79 20 4e 55 4c 4c 20 69 6e 70 75 74 i>any NULL input
0a70: 20 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 72 argument will r
0a80: 65 74 75 72 6e 20 61 20 4e 55 4c 4c 20 76 61 6c eturn a NULL val
0a90: 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c ue.</li>..</ul><
0aa0: 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 br>..<hr>..<verb
0ab0: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 43 61 atim>..SELECT Ca
0ac0: 73 74 54 6f 44 6f 75 62 6c 65 28 20 31 20 29 2c stToDouble( 1 ),
0ad0: 20 43 61 73 74 54 6f 44 6f 75 62 6c 65 28 20 31 CastToDouble( 1
0ae0: 2e 32 33 20 29 2c 20 43 61 73 74 54 6f 44 6f 75 .23 ), CastToDou
0af0: 62 6c 65 28 20 27 31 32 33 2e 34 35 27 20 29 2c ble( '123.45' ),
0b00: 0d 0a 20 20 20 20 43 61 73 74 54 6f 44 6f 75 62 .. CastToDoub
0b10: 6c 65 28 20 27 61 6c 70 68 61 27 20 29 2c 20 43 le( 'alpha' ), C
0b20: 61 73 74 54 6f 44 6f 75 62 6c 65 20 28 20 7a 65 astToDouble ( ze
0b30: 72 6f 62 6c 6f 62 28 34 29 20 29 3b 0d 0a 3c 2f roblob(4) );..</
0b40: 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c verbatim>..<tabl
0b50: 65 20 62 6f 72 64 65 72 3d 22 31 22 20 63 65 6c e border="1" cel
0b60: 6c 73 70 61 63 69 6e 67 3d 22 34 22 20 63 65 6c lspacing="4" cel
0b70: 6c 70 61 64 64 69 6e 67 3d 22 34 22 3e 0d 0a 3c lpadding="4">..<
0b80: 74 72 3e 3c 74 68 3e 43 61 73 74 54 6f 44 6f 75 tr><th>CastToDou
0b90: 62 6c 65 28 20 31 20 29 3c 2f 74 68 3e 3c 74 68 ble( 1 )</th><th
0ba0: 3e 43 61 73 74 54 6f 44 6f 75 62 6c 65 28 20 31 >CastToDouble( 1
0bb0: 2e 32 33 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 61 .23 )</th><th>Ca
0bc0: 73 74 54 6f 44 6f 75 62 6c 65 28 20 27 31 32 33 stToDouble( '123
0bd0: 2e 34 35 27 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 .45' )</th><th>C
0be0: 61 73 74 54 6f 44 6f 75 62 6c 65 28 20 27 61 6c astToDouble( 'al
0bf0: 70 68 61 27 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 pha' )</th><th>C
0c00: 61 73 74 54 6f 44 6f 75 62 6c 65 20 28 20 7a 65 astToDouble ( ze
0c10: 72 6f 62 6c 6f 62 28 34 29 20 29 3c 2f 74 68 3e roblob(4) )</th>
0c20: 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 </tr>..<tr><td a
0c30: 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 31 2e 30 lign="right">1.0
0c40: 30 30 30 30 30 3c 2f 74 64 3e 3c 74 64 20 61 6c 00000</td><td al
0c50: 69 67 6e 3d 22 72 69 67 68 74 22 3e 31 2e 32 33 ign="right">1.23
0c60: 30 30 30 30 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 0000</td><td ali
0c70: 67 6e 3d 22 72 69 67 68 74 22 3e 31 32 33 2e 34 gn="right">123.4
0c80: 35 30 30 30 3c 2f 74 64 3e 3c 74 64 3e 4e 55 4c 5000</td><td>NUL
0c90: 4c 3c 2f 74 64 3e 3c 74 64 3e 4e 55 4c 4c 3c 2f L</td><td>NULL</
0ca0: 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e td></tr></table>
0cb0: 3c 62 72 3e 0d 0a 54 68 65 20 3c 62 3e 43 61 73 <br>..The <b>Cas
0cc0: 74 54 6f 44 6f 75 62 6c 65 28 29 3c 2f 62 3e 20 tToDouble()</b>
0cd0: 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 77 69 6c SQL function wil
0ce0: 6c 20 61 74 74 65 6d 70 74 20 74 6f 20 72 65 74 l attempt to ret
0cf0: 75 72 6e 20 61 20 76 61 6c 75 65 20 6f 66 20 74 urn a value of t
0d00: 68 65 20 3c 62 3e 44 6f 75 62 6c 65 3c 2f 62 3e he <b>Double</b>
0d10: 20 64 61 74 61 2d 74 79 70 65 2c 20 6f 72 20 3c data-type, or <
0d20: 62 3e 4e 55 4c 4c 3c 2f 62 3e 20 69 66 20 6e 6f b>NULL</b> if no
0d30: 20 63 6f 6e 76 65 72 73 69 6f 6e 20 69 73 20 70 conversion is p
0d40: 6f 73 73 69 62 6c 65 2e 0d 0a 3c 75 6c 3e 0d 0a ossible...<ul>..
0d50: 3c 6c 69 3e 61 6e 20 49 6e 74 65 67 65 72 20 69 <li>an Integer i
0d60: 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 nput argument wi
0d70: 6c 6c 20 72 65 74 75 72 6e 20 74 68 65 20 63 6f ll return the co
0d80: 72 72 65 73 70 6f 6e 64 69 6e 67 20 44 6f 75 62 rresponding Doub
0d90: 6c 65 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a le value.</li>..
0da0: 3c 6c 69 3e 61 20 44 6f 75 62 6c 65 20 69 6e 70 <li>a Double inp
0db0: 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c ut argument will
0dc0: 20 62 65 20 72 65 74 75 72 6e 65 64 20 61 62 73 be returned abs
0dd0: 6f 6c 75 74 65 6c 79 20 75 6e 61 66 66 65 63 74 olutely unaffect
0de0: 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 ed.</li>..<li>a
0df0: 54 65 78 74 20 69 6e 70 75 74 20 61 72 67 75 6d Text input argum
0e00: 65 6e 74 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 ent will return
0e10: 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e the correspondin
0e20: 67 20 44 6f 75 62 6c 65 20 76 61 6c 75 65 20 6f g Double value o
0e30: 6e 6c 79 20 69 66 20 74 68 65 20 74 65 78 74 20 nly if the text
0e40: 73 74 72 69 6e 67 20 72 65 70 72 65 73 65 6e 74 string represent
0e50: 73 20 61 20 76 61 6c 69 64 20 6e 75 6d 62 65 72 s a valid number
0e60: 3a 20 69 66 20 74 68 65 20 74 65 78 74 20 73 74 : if the text st
0e70: 72 69 6e 67 20 63 61 6e 6e 6f 74 20 62 65 20 63 ring cannot be c
0e80: 6f 6e 76 65 72 74 65 64 20 74 6f 20 61 20 6e 75 onverted to a nu
0e90: 6d 62 65 72 20 4e 55 4c 4c 20 77 69 6c 6c 20 62 mber NULL will b
0ea0: 65 20 72 65 74 75 72 6e 65 64 2e 3c 2f 6c 69 3e e returned.</li>
0eb0: 0d 0a 3c 6c 69 3e 61 6e 79 20 42 4c 4f 42 20 69 ..<li>any BLOB i
0ec0: 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 nput argument wi
0ed0: 6c 6c 20 72 65 74 75 72 6e 20 61 20 4e 55 4c 4c ll return a NULL
0ee0: 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c value.</li>..<l
0ef0: 69 3e 61 6e 79 20 4e 55 4c 4c 20 69 6e 70 75 74 i>any NULL input
0f00: 20 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 72 argument will r
0f10: 65 74 75 72 6e 20 61 20 4e 55 4c 4c 20 76 61 6c eturn a NULL val
0f20: 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c ue.</li>..</ul><
0f30: 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 br>..<hr>..<verb
0f40: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 43 61 atim>..SELECT Ca
0f50: 73 74 54 6f 54 65 78 74 28 20 31 20 29 2c 20 43 stToText( 1 ), C
0f60: 61 73 74 54 6f 54 65 78 74 28 20 31 2e 35 20 29 astToText( 1.5 )
0f70: 2c 20 43 61 73 74 54 6f 54 65 78 74 28 20 27 61 , CastToText( 'a
0f80: 6c 70 68 61 27 20 29 2c 20 43 61 73 74 54 6f 54 lpha' ), CastToT
0f90: 65 78 74 20 28 20 7a 65 72 6f 62 6c 6f 62 28 34 ext ( zeroblob(4
0fa0: 29 20 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d ) );..</verbatim
0fb0: 3e 0d 0a 3c 74 61 62 6c 65 20 62 6f 72 64 65 72 >..<table border
0fc0: 3d 22 31 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 ="1" cellspacing
0fd0: 3d 22 34 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 ="4" cellpadding
0fe0: 3d 22 34 22 3e 0d 0a 3c 74 72 3e 3c 74 68 3e 43 ="4">..<tr><th>C
0ff0: 61 73 74 54 6f 54 65 78 74 28 20 31 20 29 3c 2f astToText( 1 )</
1000: 74 68 3e 3c 74 68 3e 43 61 73 74 54 6f 54 65 78 th><th>CastToTex
1010: 74 28 20 31 2e 35 20 29 3c 2f 74 68 3e 3c 74 68 t( 1.5 )</th><th
1020: 3e 43 61 73 74 54 6f 54 65 78 74 28 20 27 61 6c >CastToText( 'al
1030: 70 68 61 27 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 pha' )</th><th>C
1040: 61 73 74 54 6f 54 65 78 74 20 28 20 7a 65 72 6f astToText ( zero
1050: 62 6c 6f 62 28 34 29 20 29 3c 2f 74 68 3e 3c 2f blob(4) )</th></
1060: 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 31 3c 2f tr>..<tr><td>1</
1070: 74 64 3e 3c 74 64 3e 31 2e 35 3c 2f 74 64 3e 3c td><td>1.5</td><
1080: 74 64 3e 61 6c 70 68 61 3c 2f 74 64 3e 3c 74 64 td>alpha</td><td
1090: 3e 4e 55 4c 4c 3c 2f 74 64 3e 3c 2f 74 72 3e 3c >NULL</td></tr><
10a0: 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 54 68 65 /table><br>..The
10b0: 20 3c 62 3e 43 61 73 74 54 6f 54 65 78 74 28 29 <b>CastToText()
10c0: 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f </b> SQL functio
10d0: 6e 20 77 69 6c 6c 20 61 74 74 65 6d 70 74 20 74 n will attempt t
10e0: 6f 20 72 65 74 75 72 6e 20 61 20 76 61 6c 75 65 o return a value
10f0: 20 6f 66 20 74 68 65 20 3c 62 3e 54 65 78 74 3c of the <b>Text<
1100: 2f 62 3e 20 64 61 74 61 2d 74 79 70 65 2c 20 6f /b> data-type, o
1110: 72 20 3c 62 3e 4e 55 4c 4c 3c 2f 62 3e 20 69 66 r <b>NULL</b> if
1120: 20 6e 6f 20 63 6f 6e 76 65 72 73 69 6f 6e 20 69 no conversion i
1130: 73 20 70 6f 73 73 69 62 6c 65 2e 0d 0a 3c 75 6c s possible...<ul
1140: 3e 0d 0a 3c 6c 69 3e 61 6e 20 49 6e 74 65 67 65 >..<li>an Intege
1150: 72 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 r input argument
1160: 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 74 68 65 will return the
1170: 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 54 corresponding T
1180: 65 78 74 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d ext value.</li>.
1190: 0a 3c 6c 69 3e 61 20 44 6f 75 62 6c 65 20 69 6e .<li>a Double in
11a0: 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 6c put argument wil
11b0: 6c 20 62 65 20 72 65 74 75 72 6e 20 74 68 65 20 l be return the
11c0: 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 54 65 corresponding Te
11d0: 78 74 20 76 61 6c 75 65 3b 20 6e 6f 20 73 69 67 xt value; no sig
11e0: 6e 69 66 69 63 61 6e 74 20 64 65 63 69 6d 61 6c nificant decimal
11f0: 20 64 69 67 69 74 20 77 69 6c 6c 20 62 65 20 73 digit will be s
1200: 75 70 70 72 65 73 73 65 64 2e 3c 2f 6c 69 3e 0d uppressed.</li>.
1210: 0a 3c 6c 69 3e 61 20 54 65 78 74 20 69 6e 70 75 .<li>a Text inpu
1220: 74 20 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 t argument will
1230: 72 65 74 75 72 6e 20 74 68 65 20 63 6f 72 72 65 return the corre
1240: 73 70 6f 6e 64 69 6e 67 20 44 6f 75 62 6c 65 20 sponding Double
1250: 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 value.</li>..<li
1260: 3e 61 6e 79 20 42 4c 4f 42 20 69 6e 70 75 74 20 >any BLOB input
1270: 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 72 65 argument will re
1280: 74 75 72 6e 20 61 20 4e 55 4c 4c 20 76 61 6c 75 turn a NULL valu
1290: 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 e.</li>..<li>any
12a0: 20 4e 55 4c 4c 20 69 6e 70 75 74 20 61 72 67 75 NULL input argu
12b0: 6d 65 6e 74 20 77 69 6c 6c 20 72 65 74 75 72 6e ment will return
12c0: 20 61 20 4e 55 4c 4c 20 76 61 6c 75 65 2e 3c 2f a NULL value.</
12d0: 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 76 65 72 li>..</ul>..<ver
12e0: 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 43 batim>..SELECT C
12f0: 61 73 74 54 6f 54 65 78 74 28 20 31 2c 20 34 20 astToText( 1, 4
1300: 29 2c 20 43 61 73 74 54 6f 54 65 78 74 28 20 31 ), CastToText( 1
1310: 32 33 34 2c 20 32 20 29 2c 20 43 61 73 74 54 6f 234, 2 ), CastTo
1320: 54 65 78 74 28 20 31 2c 20 38 20 29 2c 20 43 61 Text( 1, 8 ), Ca
1330: 73 74 54 6f 54 65 78 74 28 20 31 2e 35 2c 20 34 stToText( 1.5, 4
1340: 20 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e );..</verbatim>
1350: 0d 0a 3c 74 61 62 6c 65 20 62 6f 72 64 65 72 3d ..<table border=
1360: 22 31 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d "1" cellspacing=
1370: 22 34 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d "4" cellpadding=
1380: 22 34 22 3e 0d 0a 3c 74 72 3e 3c 74 68 3e 43 61 "4">..<tr><th>Ca
1390: 73 74 54 6f 54 65 78 74 28 20 31 2c 20 34 20 29 stToText( 1, 4 )
13a0: 3c 2f 74 68 3e 3c 74 68 3e 43 61 73 74 54 6f 54 </th><th>CastToT
13b0: 65 78 74 28 20 31 32 33 34 2c 20 32 20 29 3c 2f ext( 1234, 2 )</
13c0: 74 68 3e 3c 74 68 3e 43 61 73 74 54 6f 54 65 78 th><th>CastToTex
13d0: 74 28 20 31 2c 20 38 20 29 3c 2f 74 68 3e 3c 74 t( 1, 8 )</th><t
13e0: 68 3e 43 61 73 74 54 6f 54 65 78 74 28 20 31 2e h>CastToText( 1.
13f0: 35 2c 20 34 20 29 3c 2f 74 68 3e 3c 2f 74 72 3e 5, 4 )</th></tr>
1400: 0d 0a 3c 74 72 3e 3c 74 64 3e 30 30 30 31 3c 2f ..<tr><td>0001</
1410: 74 64 3e 3c 74 64 3e 31 32 33 34 3c 2f 74 64 3e td><td>1234</td>
1420: 3c 74 64 3e 30 30 30 30 30 30 30 31 3c 2f 74 64 <td>00000001</td
1430: 3e 3c 74 64 3e 30 30 30 31 2e 35 3c 2f 74 64 3e ><td>0001.5</td>
1440: 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 3c 62 72 </tr></table><br
1450: 3e 0d 0a 41 6e 20 6f 76 65 72 6c 6f 61 64 65 64 >..An overloaded
1460: 20 76 65 72 73 69 6f 6e 20 6f 66 20 3c 62 3e 43 version of <b>C
1470: 61 73 74 54 6f 54 65 78 74 28 29 3c 2f 62 3e 20 astToText()</b>
1480: 69 73 20 73 75 70 70 6f 72 74 65 64 20 61 73 20 is supported as
1490: 77 65 6c 6c 2c 20 62 75 74 20 6f 6e 6c 79 20 77 well, but only w
14a0: 68 65 6e 20 74 68 65 20 69 6e 70 75 74 20 61 72 hen the input ar
14b0: 67 75 6d 65 6e 74 20 69 73 20 6f 66 20 74 68 65 gument is of the
14c0: 20 49 6e 74 65 67 65 72 20 6f 72 20 44 6f 75 62 Integer or Doub
14d0: 6c 65 20 64 61 74 61 2d 74 79 70 65 3a 20 69 6e le data-type: in
14e0: 20 74 68 69 73 20 63 61 73 65 20 61 20 73 65 63 this case a sec
14f0: 6f 6e 64 20 49 6e 74 65 67 65 72 20 61 72 67 75 ond Integer argu
1500: 6d 65 6e 74 20 63 6f 75 6c 64 20 62 65 20 6f 70 ment could be op
1510: 74 69 6f 6e 61 6c 6c 79 20 73 70 65 63 69 66 69 tionally specifi
1520: 65 64 2c 20 61 6e 64 20 77 69 6c 6c 20 62 65 20 ed, and will be
1530: 69 6e 74 65 72 70 72 65 74 65 64 20 61 64 20 3c interpreted ad <
1540: 62 3e 7a 65 72 6f 2d 70 61 64 64 69 6e 67 2d 6c b>zero-padding-l
1550: 65 6e 67 74 68 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a ength</b>.<br>..
1560: 69 2e 65 2e 20 74 68 65 20 72 65 74 75 72 6e 65 i.e. the returne
1570: 64 20 54 65 78 74 20 73 74 72 69 6e 67 20 69 6e d Text string in
1580: 20 74 68 69 73 20 63 61 73 65 20 77 69 6c 6c 20 this case will
1590: 68 61 76 65 20 61 6e 20 69 6e 74 65 67 65 72 20 have an integer
15a0: 70 61 72 74 20 61 74 20 6c 65 61 73 74 20 6f 66 part at least of
15b0: 20 74 68 65 20 73 70 65 63 69 66 69 65 64 20 6c the specified l
15c0: 65 6e 67 74 68 2c 20 61 6e 64 20 65 76 65 6e 74 ength, and event
15d0: 75 61 6c 6c 79 20 70 61 64 64 65 64 20 62 79 20 ually padded by
15e0: 69 6e 73 65 72 74 69 6e 67 20 6e 6f 74 20 73 69 inserting not si
15f0: 67 6e 69 66 69 63 61 6e 74 20 6c 65 61 64 69 6e gnificant leadin
1600: 67 20 5a 45 52 4f 65 73 2e 3c 62 72 3e 3c 62 72 g ZEROes.<br><br
1610: 3e 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 >..<hr>..<verbat
1620: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 43 61 73 74 im>..SELECT Cast
1630: 54 6f 42 6c 6f 62 28 20 31 20 29 2c 20 43 61 73 ToBlob( 1 ), Cas
1640: 74 54 6f 42 6c 6f 62 28 20 31 2e 35 20 29 2c 20 tToBlob( 1.5 ),
1650: 48 65 78 28 20 43 61 73 74 54 6f 42 6c 6f 62 28 Hex( CastToBlob(
1660: 20 27 61 6c 70 68 61 27 20 29 20 29 2c 20 48 65 'alpha' ) ), He
1670: 78 20 28 20 43 61 73 74 54 6f 42 6c 6f 62 20 28 x ( CastToBlob (
1680: 20 7a 65 72 6f 62 6c 6f 62 28 34 29 20 29 20 29 zeroblob(4) ) )
1690: 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a ;..</verbatim>..
16a0: 3c 74 61 62 6c 65 20 62 6f 72 64 65 72 3d 22 31 <table border="1
16b0: 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 34 " cellspacing="4
16c0: 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 34 " cellpadding="4
16d0: 22 3e 0d 0a 3c 74 72 3e 3c 74 68 3e 43 61 73 74 ">..<tr><th>Cast
16e0: 54 6f 42 6c 6f 62 28 20 31 20 29 3c 2f 74 68 3e ToBlob( 1 )</th>
16f0: 3c 74 68 3e 43 61 73 74 54 6f 42 6c 6f 62 28 20 <th>CastToBlob(
1700: 31 2e 35 20 29 3c 2f 74 68 3e 3c 74 68 3e 48 65 1.5 )</th><th>He
1710: 78 28 20 43 61 73 74 54 6f 42 6c 6f 62 28 20 27 x( CastToBlob( '
1720: 61 6c 70 68 61 27 20 29 20 29 3c 2f 74 68 3e 3c alpha' ) )</th><
1730: 74 68 3e 48 65 78 28 20 43 61 73 74 54 6f 54 65 th>Hex( CastToTe
1740: 78 74 20 28 20 7a 65 72 6f 62 6c 6f 62 28 34 29 xt ( zeroblob(4)
1750: 20 29 20 29 3c 2f 74 68 3e 3c 2f 74 72 3e 0d 0a ) )</th></tr>..
1760: 3c 74 72 3e 3c 74 64 3e 4e 55 4c 4c 3c 2f 74 64 <tr><td>NULL</td
1770: 3e 3c 74 64 3e 4e 55 4c 4c 3c 2f 74 64 3e 3c 74 ><td>NULL</td><t
1780: 64 3e 36 31 36 43 37 30 36 38 36 31 3c 2f 74 64 d>616C706861</td
1790: 3e 3c 74 64 3e 30 30 30 30 30 30 30 30 3c 2f 74 ><td>00000000</t
17a0: 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 3c d></tr></table><
17b0: 62 72 3e 0d 0a 54 68 65 20 3c 62 3e 43 61 73 74 br>..The <b>Cast
17c0: 54 6f 42 6c 6f 62 28 29 3c 2f 62 3e 20 53 51 4c ToBlob()</b> SQL
17d0: 20 66 75 6e 63 74 69 6f 6e 20 77 69 6c 6c 20 61 function will a
17e0: 74 74 65 6d 70 74 20 74 6f 20 72 65 74 75 72 6e ttempt to return
17f0: 20 61 20 76 61 6c 75 65 20 6f 66 20 74 68 65 20 a value of the
1800: 3c 62 3e 42 4c 4f 42 3c 2f 62 3e 20 64 61 74 61 <b>BLOB</b> data
1810: 2d 74 79 70 65 2c 20 6f 72 20 3c 62 3e 4e 55 4c -type, or <b>NUL
1820: 4c 3c 2f 62 3e 20 69 66 20 6e 6f 20 63 6f 6e 76 L</b> if no conv
1830: 65 72 73 69 6f 6e 20 69 73 20 70 6f 73 73 69 62 ersion is possib
1840: 6c 65 2e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 le...<ul>..<li>a
1850: 6e 20 49 6e 74 65 67 65 72 20 69 6e 70 75 74 20 n Integer input
1860: 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 72 65 argument will re
1870: 74 75 72 6e 20 61 20 4e 55 4c 4c 20 76 61 6c 75 turn a NULL valu
1880: 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 44 e.</li>..<li>a D
1890: 6f 75 62 6c 65 20 69 6e 70 75 74 20 61 72 67 75 ouble input argu
18a0: 6d 65 6e 74 20 77 69 6c 6c 20 72 65 74 75 72 6e ment will return
18b0: 20 61 20 4e 55 4c 4c 20 76 61 6c 75 65 2e 3c 2f a NULL value.</
18c0: 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 54 65 78 74 20 li>..<li>a Text
18d0: 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 20 input argument
18e0: 77 69 6c 6c 20 72 65 74 75 72 6e 20 74 68 65 20 will return the
18f0: 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 42 4c corresponding BL
1900: 4f 42 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a OB value.</li>..
1910: 3c 6c 69 3e 61 6e 79 20 42 4c 4f 42 20 69 6e 70 <li>any BLOB inp
1920: 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c ut argument will
1930: 20 72 65 74 75 72 6e 20 74 68 65 20 63 6f 72 72 return the corr
1940: 65 73 70 6f 6e 64 69 6e 67 20 42 4c 4f 42 20 76 esponding BLOB v
1950: 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e alue.</li>..<li>
1960: 61 6e 79 20 4e 55 4c 4c 20 69 6e 70 75 74 20 61 any NULL input a
1970: 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 72 65 74 rgument will ret
1980: 75 72 6e 20 61 20 4e 55 4c 4c 20 76 61 6c 75 65 urn a NULL value
1990: 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c .</li>..</ul>..<
19a0: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 verbatim>..SELEC
19b0: 54 20 48 65 78 28 20 43 61 73 74 54 6f 42 6c 6f T Hex( CastToBlo
19c0: 62 28 20 27 30 31 32 33 34 35 36 37 38 39 61 42 b( '0123456789aB
19d0: 63 44 65 46 66 45 64 43 62 41 39 38 37 36 35 34 cDeFfEdCbA987654
19e0: 33 32 31 30 27 2c 20 31 20 29 20 29 3b 0d 0a 2d 3210', 1 ) );..-
19f0: 2d 2d 2d 2d 0d 0a 30 31 32 33 34 35 36 37 38 39 ----..0123456789
1a00: 41 42 43 44 45 46 46 45 44 43 42 41 39 38 37 36 ABCDEFFEDCBA9876
1a10: 35 34 33 32 31 30 0d 0a 0d 0a 53 45 4c 45 43 54 543210....SELECT
1a20: 20 43 61 73 74 54 6f 42 6c 6f 62 28 20 27 31 32 CastToBlob( '12
1a30: 66 27 2c 20 31 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d f', 1 );..-----.
1a40: 0a 4e 55 4c 4c 0d 0a 0d 0a 53 45 4c 45 43 54 20 .NULL....SELECT
1a50: 43 61 73 74 54 6f 42 6c 6f 62 28 20 27 31 32 48 CastToBlob( '12H
1a60: 46 27 2c 20 31 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d F', 1 );..-----.
1a70: 0a 4e 55 4c 4c 0d 0a 3c 2f 76 65 72 62 61 74 69 .NULL..</verbati
1a80: 6d 3e 0d 0a 41 20 73 65 63 6f 6e 64 20 6f 76 65 m>..A second ove
1a90: 72 6c 6f 61 64 65 64 20 76 65 72 73 69 6f 6e 20 rloaded version
1aa0: 6f 66 20 3c 62 3e 43 61 73 74 54 6f 42 6c 6f 62 of <b>CastToBlob
1ab0: 28 29 3c 2f 62 3e 20 69 73 20 73 75 70 70 6f 72 ()</b> is suppor
1ac0: 74 65 64 20 61 73 20 77 65 6c 6c 3b 20 62 79 20 ted as well; by
1ad0: 73 70 65 63 69 66 79 69 6e 67 20 61 20 66 75 72 specifying a fur
1ae0: 74 68 65 72 20 3c 62 3e 68 65 78 5f 69 6e 70 75 ther <b>hex_inpu
1af0: 74 3c 2f 62 3e 20 3c 75 3e 62 6f 6f 6c 65 61 6e t</b> <u>boolean
1b00: 3c 2f 75 3e 20 61 72 67 75 6d 65 6e 74 20 73 65 </u> argument se
1b10: 74 20 61 73 20 3c 62 3e 54 52 55 45 3c 2f 62 3e t as <b>TRUE</b>
1b20: 20 74 68 65 20 69 6e 70 75 74 20 73 74 72 69 6e the input strin
1b30: 67 20 77 69 6c 6c 20 62 65 20 61 73 73 75 6d 65 g will be assume
1b40: 64 20 74 6f 20 62 65 20 3c 75 3e 48 65 78 61 64 d to be <u>Hexad
1b50: 65 63 69 6d 61 6c 6c 79 20 65 6e 63 6f 64 65 64 ecimally encoded
1b60: 3c 2f 75 3e 2e 20 49 6e 20 74 68 69 73 20 63 61 </u>. In this ca
1b70: 73 65 20 4e 55 4c 4c 20 77 69 6c 6c 20 62 65 20 se NULL will be
1b80: 72 65 74 75 72 6e 65 64 20 69 66 20 74 68 65 20 returned if the
1b90: 69 6e 70 75 74 20 73 74 72 69 6e 67 20 64 6f 65 input string doe
1ba0: 73 6e 27 74 20 63 6f 72 72 65 73 70 6f 6e 64 73 sn't corresponds
1bb0: 20 74 6f 20 61 20 76 61 6c 69 64 20 48 65 78 61 to a valid Hexa
1bc0: 64 65 63 69 6d 61 6c 20 6e 6f 74 61 74 69 6f 6e decimal notation
1bd0: 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d .<br><br>..<hr>.
1be0: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c .<verbatim>..SEL
1bf0: 45 43 54 20 46 6f 72 63 65 41 73 4e 75 6c 6c 28 ECT ForceAsNull(
1c00: 20 27 61 27 2c 20 27 62 27 20 29 2c 20 46 6f 72 'a', 'b' ), For
1c10: 63 65 41 73 4e 75 6c 6c 28 20 27 61 62 63 64 27 ceAsNull( 'abcd'
1c20: 2c 20 27 61 62 63 64 27 20 29 2c 20 46 6f 72 63 , 'abcd' ), Forc
1c30: 65 41 73 4e 75 6c 6c 28 20 31 2c 20 31 29 2c 20 eAsNull( 1, 1),
1c40: 46 6f 72 63 65 41 73 4e 75 6c 6c 28 20 31 2e 31 ForceAsNull( 1.1
1c50: 2c 20 31 20 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 , 1 );..</verbat
1c60: 69 6d 3e 0d 0a 3c 74 61 62 6c 65 20 62 6f 72 64 im>..<table bord
1c70: 65 72 3d 22 31 22 20 63 65 6c 6c 73 70 61 63 69 er="1" cellspaci
1c80: 6e 67 3d 22 34 22 20 63 65 6c 6c 70 61 64 64 69 ng="4" cellpaddi
1c90: 6e 67 3d 22 34 22 3e 0d 0a 3c 74 72 3e 3c 74 68 ng="4">..<tr><th
1ca0: 3e 46 6f 72 63 65 41 73 4e 75 6c 6c 28 20 27 61 >ForceAsNull( 'a
1cb0: 27 2c 20 27 62 27 20 29 3c 2f 74 68 3e 3c 74 68 ', 'b' )</th><th
1cc0: 3e 46 6f 72 63 65 41 73 4e 75 6c 6c 28 20 27 61 >ForceAsNull( 'a
1cd0: 62 63 64 27 2c 20 27 61 62 63 64 27 20 29 3c 2f bcd', 'abcd' )</
1ce0: 74 68 3e 3c 74 68 3e 46 6f 72 63 65 41 73 4e 75 th><th>ForceAsNu
1cf0: 6c 6c 28 20 31 2c 20 31 29 3c 2f 74 68 3e 3c 74 ll( 1, 1)</th><t
1d00: 68 3e 46 6f 72 63 65 41 73 4e 75 6c 6c 28 20 31 h>ForceAsNull( 1
1d10: 2e 31 2c 20 2d 39 39 39 39 20 29 3c 2f 74 68 3e .1, -9999 )</th>
1d20: 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 61 </tr>..<tr><td>a
1d30: 3c 2f 74 64 3e 3c 74 64 3e 4e 55 4c 4c 3c 2f 74 </td><td>NULL</t
1d40: 64 3e 3c 74 64 3e 4e 55 4c 4c 3c 2f 74 64 3e 3c d><td>NULL</td><
1d50: 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 td align="right"
1d60: 3e 31 2e 31 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f >1.1</td></tr></
1d70: 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 54 68 65 20 table><br>..The
1d80: 3c 62 3e 46 6f 72 63 65 41 73 4e 75 6c 6c 28 29 <b>ForceAsNull()
1d90: 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f </b> SQL functio
1da0: 6e 20 77 69 6c 6c 20 65 76 61 6c 75 61 74 65 20 n will evaluate
1db0: 74 77 6f 20 61 72 62 69 74 72 61 72 79 20 61 72 two arbitrary ar
1dc0: 67 75 6d 65 6e 74 73 2e 3c 62 72 3e 0d 0a 49 66 guments.<br>..If
1dd0: 20 74 68 65 79 20 61 72 65 20 65 71 75 61 6c 20 they are equal
1de0: 61 6e 64 20 65 78 61 63 74 6c 79 20 6f 66 20 74 and exactly of t
1df0: 68 65 20 73 61 6d 65 20 64 61 74 61 2d 74 79 70 he same data-typ
1e00: 65 20 4e 55 4c 4c 20 77 69 6c 6c 20 62 65 20 72 e NULL will be r
1e10: 65 74 75 72 6e 65 64 3b 20 6f 74 68 65 72 77 69 eturned; otherwi
1e20: 73 65 20 74 68 65 20 66 69 72 73 74 20 61 72 67 se the first arg
1e30: 75 6d 65 6e 74 20 76 61 6c 75 65 20 77 69 6c 6c ument value will
1e40: 20 62 65 20 72 65 74 75 72 6e 65 64 2e 3c 62 72 be returned.<br
1e50: 3e 0d 0a 55 73 65 66 75 6c 20 65 2e 67 2e 20 77 >..Useful e.g. w
1e60: 68 69 6c 65 20 70 72 6f 63 65 73 73 69 6e 67 20 hile processing
1e70: 64 61 74 61 20 69 6d 70 6f 72 74 65 64 20 66 72 data imported fr
1e80: 6f 6d 20 61 6e 79 20 3c 62 3e 53 68 61 70 65 66 om any <b>Shapef
1e90: 69 6c 65 3c 2f 62 3e 20 6f 72 20 3c 62 3e 44 42 ile</b> or <b>DB
1ea0: 46 20 66 69 6c 65 3c 2f 62 3e 20 28 73 75 63 68 F file</b> (such
1eb0: 20 66 6f 72 6d 61 74 73 20 64 6f 65 73 6e 27 74 formats doesn't
1ec0: 20 73 75 70 70 6f 72 74 20 61 6e 79 20 72 65 61 support any rea
1ed0: 6c 20 4e 55 4c 4c 20 76 61 6c 75 65 2c 20 6f 66 l NULL value, of
1ee0: 74 65 6e 20 62 65 69 6e 67 20 72 65 70 6c 61 63 ten being replac
1ef0: 65 64 20 62 79 20 73 6f 6d 65 20 63 6f 6e 76 65 ed by some conve
1f00: 6e 74 69 6f 6e 61 6c 20 76 61 6c 75 65 20 65 2e ntional value e.
1f10: 67 2e 20 3c 62 3e 30 3c 2f 62 3e 20 6f 72 20 3c g. <b>0</b> or <
1f20: 62 3e 2d 39 39 39 39 3c 2f 62 3e 20 61 6e 64 20 b>-9999</b> and
1f30: 61 6c 69 6b 65 29 2e 3c 62 72 3e 3c 62 72 3e 0d alike).<br><br>.
1f40: 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 3c 61 20 6e 61 .<hr>..<h3><a na
1f50: 6d 65 3d 22 75 75 69 64 22 3e 47 65 6e 65 72 69 me="uuid">Generi
1f60: 63 3c 2f 61 3e 20 53 51 4c 20 66 75 6e 63 74 69 c</a> SQL functi
1f70: 6f 6e 20 2d 20 55 55 49 44 20 67 65 6e 65 72 61 on - UUID genera
1f80: 74 6f 72 3c 2f 68 33 3e 0d 0a 41 6e 20 3c 61 20 tor</h3>..An <a
1f90: 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f 65 6e 2e href="http://en.
1fa0: 77 69 6b 69 70 65 64 69 61 2e 6f 72 67 2f 77 69 wikipedia.org/wi
1fb0: 6b 69 2f 55 6e 69 76 65 72 73 61 6c 6c 79 5f 75 ki/Universally_u
1fc0: 6e 69 71 75 65 5f 69 64 65 6e 74 69 66 69 65 72 nique_identifier
1fd0: 22 3e 55 6e 69 76 65 72 73 61 6c 6c 79 20 75 6e ">Universally un
1fe0: 69 71 75 65 20 69 64 65 6e 74 69 66 69 65 72 3c ique identifier<
1ff0: 2f 61 3e 20 28 61 6b 61 20 3c 62 3e 55 55 49 44 /a> (aka <b>UUID
2000: 3c 2f 62 3e 29 20 73 69 6d 70 6c 79 20 69 73 20 </b>) simply is
2010: 61 20 3c 75 3e 31 32 38 20 62 69 74 3c 2f 75 3e a <u>128 bit</u>
2020: 20 49 6e 74 65 67 65 72 3b 20 61 63 63 6f 72 64 Integer; accord
2030: 69 6e 67 6c 79 20 74 6f 20 3c 61 20 68 72 65 66 ingly to <a href
2040: 3d 22 68 74 74 70 3a 2f 2f 65 6e 2e 77 69 6b 69 ="http://en.wiki
2050: 70 65 64 69 61 2e 6f 72 67 2f 77 69 6b 69 2f 55 pedia.org/wiki/U
2060: 55 49 44 23 52 61 6e 64 6f 6d 5f 55 55 49 44 5f UID#Random_UUID_
2070: 70 72 6f 62 61 62 69 6c 69 74 79 5f 6f 66 5f 64 probability_of_d
2080: 75 70 6c 69 63 61 74 65 73 22 3e 74 68 65 6f 72 uplicates">theor
2090: 79 3c 2f 61 3e 2c 20 74 68 65 20 70 72 6f 62 61 y</a>, the proba
20a0: 62 69 6c 69 74 79 20 74 68 61 74 20 74 77 6f 20 bility that two
20b0: 72 61 6e 64 6f 6d 6c 79 20 67 65 6e 65 72 61 74 randomly generat
20c0: 65 64 20 55 55 49 44 73 20 63 6f 75 6c 64 20 61 ed UUIDs could a
20d0: 73 73 75 6d 65 20 74 68 65 20 73 61 6d 65 20 76 ssume the same v
20e0: 61 6c 75 65 20 69 73 20 6e 65 61 72 20 74 6f 20 alue is near to
20f0: 7a 65 72 6f 20 66 6f 72 20 6d 61 6e 79 20 70 72 zero for many pr
2100: 61 63 74 69 63 61 6c 20 70 75 72 70 6f 73 65 73 actical purposes
2110: 2e 20 41 6e 64 20 63 6f 6e 73 65 71 75 65 6e 74 . And consequent
2120: 6c 79 20 55 55 49 44 73 20 61 72 65 20 77 69 64 ly UUIDs are wid
2130: 65 6c 79 20 75 73 65 64 20 61 73 20 3c 75 3e 75 ely used as <u>u
2140: 6e 69 76 65 72 73 61 6c 6c 79 20 75 6e 69 71 75 niversally uniqu
2150: 65 20 49 44 73 3c 2f 75 3e 2e 3c 62 72 3e 0d 0a e IDs</u>.<br>..
2160: 55 73 75 61 6c 6c 79 20 55 55 49 44 73 20 61 72 Usually UUIDs ar
2170: 65 20 72 65 70 72 65 73 65 6e 74 65 64 20 69 6e e represented in
2180: 20 74 68 65 69 72 20 3c 75 3e 63 61 6e 6f 6e 69 their <u>canoni
2190: 63 61 6c 20 66 6f 72 6d 3c 2f 75 3e 2c 20 69 2e cal form</u>, i.
21a0: 65 2e 20 61 73 20 61 20 73 65 71 75 65 6e 63 65 e. as a sequence
21b0: 20 6f 66 20 33 32 20 68 65 78 61 64 65 63 69 6d of 32 hexadecim
21c0: 61 6c 20 64 69 67 69 74 73 20 73 65 70 61 72 61 al digits separa
21d0: 74 65 64 20 69 6e 74 6f 20 66 69 76 65 20 64 69 ted into five di
21e0: 73 74 69 6e 63 74 20 62 6c 6f 63 6b 2c 20 61 63 stinct block, ac
21f0: 63 6f 72 64 69 6e 67 6c 79 20 74 6f 20 61 20 3c cordingly to a <
2200: 62 3e 38 2d 34 2d 34 2d 34 2d 31 32 3c 2f 62 3e b>8-4-4-4-12</b>
2210: 20 73 63 68 65 6d 61 2e 0d 0a 3c 76 65 72 62 61 schema...<verba
2220: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 43 72 65 tim>..SELECT Cre
2230: 61 74 65 55 55 49 44 28 29 3b 0d 0a 2d 2d 2d 2d ateUUID();..----
2240: 2d 2d 2d 2d 0d 0a 66 66 66 35 66 61 66 31 2d 64 ----..fff5faf1-d
2250: 63 63 30 2d 34 33 39 31 2d 38 30 35 34 2d 36 65 cc0-4391-8054-6e
2260: 37 64 65 37 35 64 38 35 62 31 0d 0a 3c 2f 76 65 7de75d85b1..</ve
2270: 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e rbatim>..The <b>
2280: 43 72 65 61 74 65 55 55 49 44 28 29 3c 2f 62 3e CreateUUID()</b>
2290: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 69 73 SQL function is
22a0: 20 62 75 69 6c 74 20 6f 6e 20 74 68 65 20 74 6f built on the to
22b0: 70 20 74 68 65 20 3c 69 3e 48 69 67 68 20 51 75 p the <i>High Qu
22c0: 61 6c 69 74 79 20 50 73 65 75 64 6f 2d 52 61 6e ality Pseudo-Ran
22d0: 64 6f 6d 20 4e 75 6d 62 65 72 20 47 65 6e 65 72 dom Number Gener
22e0: 61 74 6f 72 3c 2f 69 3e 20 3c 61 20 68 72 65 66 ator</i> <a href
22f0: 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 73 71 6c ="http://www.sql
2300: 69 74 65 2e 6f 72 67 2f 63 33 72 65 66 2f 72 61 ite.org/c3ref/ra
2310: 6e 64 6f 6d 6e 65 73 73 2e 68 74 6d 6c 22 3e 69 ndomness.html">i
2320: 6e 74 65 72 6e 61 6c 6c 79 20 69 6d 70 6c 65 6d nternally implem
2330: 65 6e 74 65 64 3c 2f 61 3e 20 62 79 20 53 51 4c ented</a> by SQL
2340: 69 74 65 2e 3c 62 72 3e 0d 0a 54 68 65 20 72 65 ite.<br>..The re
2350: 74 75 72 6e 65 64 20 55 55 49 44 20 69 73 20 63 turned UUID is c
2360: 6f 6e 66 6f 72 6d 61 6e 74 20 74 6f 20 3c 75 3e onformant to <u>
2370: 56 65 72 73 69 6f 6e 20 34 20 28 72 61 6e 64 6f Version 4 (rando
2380: 6d 29 3c 2f 75 3e 20 28 69 2e 65 2e 20 74 68 65 m)</u> (i.e. the
2390: 20 66 69 72 73 74 20 64 69 67 69 74 20 69 6e 74 first digit int
23a0: 6f 20 74 68 65 20 74 68 69 72 64 20 62 6c 6f 63 o the third bloc
23b0: 6b 20 77 69 6c 6c 20 61 6c 77 61 79 73 20 62 65 k will always be
23c0: 20 3c 62 3e 34 3c 2f 62 3e 20 61 6e 64 20 74 68 <b>4</b> and th
23d0: 65 20 66 69 72 73 74 20 64 69 67 69 74 20 69 6e e first digit in
23e0: 74 6f 20 74 68 65 20 66 6f 75 72 74 68 20 62 6c to the fourth bl
23f0: 6f 63 6b 20 77 69 6c 6c 20 61 6c 77 61 79 73 20 ock will always
2400: 62 65 20 3c 62 3e 38 3c 2f 62 3e 29 2e 3c 62 72 be <b>8</b>).<br
2410: 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 33 ><br>..<hr>..<h3
2420: 3e 3c 61 20 6e 61 6d 65 3d 22 67 65 6f 6d 22 3e ><a name="geom">
2430: 53 70 61 74 69 61 6c 3c 2f 61 3e 20 53 51 4c 20 Spatial</a> SQL
2440: 66 75 6e 63 74 69 6f 6e 73 3c 2f 68 33 3e 0d 0a functions</h3>..
2450: 46 65 77 20 6d 6f 72 65 20 53 70 61 74 69 61 6c Few more Spatial
2460: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 73 20 61 SQL functions a
2470: 72 65 20 6e 6f 77 20 73 75 70 70 6f 72 74 65 64 re now supported
2480: 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 ...<verbatim>..S
2490: 45 4c 45 43 54 20 53 54 5f 41 73 54 65 78 74 28 ELECT ST_AsText(
24a0: 20 53 54 5f 41 64 64 50 6f 69 6e 74 28 20 0d 0a ST_AddPoint( ..
24b0: 20 20 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 ST_GeomFromTex
24c0: 74 28 20 27 4c 49 4e 45 53 54 52 49 4e 47 28 20 t( 'LINESTRING(
24d0: 30 20 30 2c 20 31 20 30 20 29 27 20 29 2c 20 0d 0 0, 1 0 )' ), .
24e0: 0a 20 20 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 . ST_GeomFromTe
24f0: 78 74 28 20 27 50 4f 49 4e 54 28 20 31 20 31 20 xt( 'POINT( 1 1
2500: 29 27 20 29 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d )' ) ) );..-----
2510: 2d 2d 2d 0d 0a 4c 49 4e 45 53 54 52 49 4e 47 28 ---..LINESTRING(
2520: 30 20 30 2c 20 31 20 30 2c 20 31 20 31 29 0d 0a 0 0, 1 0, 1 1)..
2530: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65 </verbatim>..The
2540: 20 3c 62 3e 53 54 5f 41 64 64 50 6f 69 6e 74 28 <b>ST_AddPoint(
2550: 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 )</b> SQL functi
2560: 6f 6e 20 61 64 64 73 20 61 20 66 75 72 74 68 65 on adds a furthe
2570: 72 20 50 6f 69 6e 74 2f 56 65 72 74 65 78 20 61 r Point/Vertex a
2580: 74 20 74 68 65 20 65 6e 64 20 6f 66 20 61 20 4c t the end of a L
2590: 69 6e 65 73 74 72 69 6e 67 3b 20 74 68 65 20 66 inestring; the f
25a0: 69 72 73 74 20 61 72 67 75 6d 65 6e 74 20 69 73 irst argument is
25b0: 20 61 6c 77 61 79 73 20 65 78 70 65 63 74 65 64 always expected
25c0: 20 74 6f 20 62 65 20 6f 66 20 74 68 65 20 4c 69 to be of the Li
25d0: 6e 65 73 74 72 69 6e 67 20 74 79 70 65 2c 20 74 nestring type, t
25e0: 68 65 20 73 65 63 6f 6e 64 20 6f 6e 65 20 6d 75 he second one mu
25f0: 73 74 20 62 65 20 61 20 50 6f 69 6e 74 2e 0d 0a st be a Point...
2600: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 <verbatim>..SELE
2610: 43 54 20 53 54 5f 41 73 54 65 78 74 28 20 53 54 CT ST_AsText( ST
2620: 5f 41 64 64 50 6f 69 6e 74 28 20 0d 0a 20 20 53 _AddPoint( .. S
2630: 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 T_GeomFromText(
2640: 27 4c 49 4e 45 53 54 52 49 4e 47 28 20 31 20 30 'LINESTRING( 1 0
2650: 2c 20 31 20 31 20 29 27 20 29 2c 20 0d 0a 20 20 , 1 1 )' ), ..
2660: 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 ST_GeomFromText(
2670: 20 27 50 4f 49 4e 54 28 20 30 20 30 20 29 27 20 'POINT( 0 0 )'
2680: 29 2c 20 30 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d ), 0 ) );..-----
2690: 2d 2d 2d 2d 0d 0a 4c 49 4e 45 53 54 52 49 4e 47 ----..LINESTRING
26a0: 28 30 20 30 2c 20 31 20 30 2c 20 31 20 31 29 0d (0 0, 1 0, 1 1).
26b0: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 49 66 .</verbatim>..If
26c0: 20 61 6e 20 6f 70 74 69 6f 6e 61 6c 20 74 68 69 an optional thi
26d0: 72 64 20 61 72 67 75 6d 65 6e 74 20 28 6f 66 20 rd argument (of
26e0: 74 68 65 20 49 6e 74 65 67 65 72 20 74 79 70 65 the Integer type
26f0: 29 20 69 73 20 70 61 73 73 65 64 20 74 6f 20 3c ) is passed to <
2700: 62 3e 53 54 5f 41 64 64 50 6f 69 6e 74 28 29 3c b>ST_AddPoint()<
2710: 2f 62 3e 20 69 74 27 73 20 69 6e 74 65 6e 64 65 /b> it's intende
2720: 64 20 74 6f 20 73 70 65 63 69 66 79 20 74 68 65 d to specify the
2730: 20 3c 75 3e 69 6e 64 65 78 3c 2f 75 3e 20 6f 66 <u>index</u> of
2740: 20 74 68 65 20 6e 65 77 20 56 65 72 74 65 78 20 the new Vertex
2750: 28 66 69 72 73 74 20 56 65 72 74 65 78 20 68 61 (first Vertex ha
2760: 73 20 69 6e 64 65 78 20 30 2c 20 73 65 63 6f 6e s index 0, secon
2770: 64 20 56 65 72 74 65 78 20 68 61 73 20 69 6e 64 d Vertex has ind
2780: 65 78 20 31 20 61 6e 64 20 73 6f 20 6f 6e 29 2e ex 1 and so on).
2790: 3c 62 72 3e 0d 0a 52 65 66 65 72 65 6e 63 69 6e <br>..Referencin
27a0: 67 20 61 20 6e 6f 74 20 65 78 69 73 74 69 6e 67 g a not existing
27b0: 20 69 6e 64 65 78 20 69 73 20 61 6e 20 65 72 72 index is an err
27c0: 6f 72 2c 20 61 6e 64 20 77 69 6c 6c 20 72 65 74 or, and will ret
27d0: 75 72 6e 20 4e 55 4c 4c 2e 0d 0a 3c 76 65 72 62 urn NULL...<verb
27e0: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 54 atim>..SELECT ST
27f0: 5f 41 73 54 65 78 74 28 20 53 54 5f 41 64 64 50 _AsText( ST_AddP
2800: 6f 69 6e 74 28 20 0d 0a 20 20 53 54 5f 47 65 6f oint( .. ST_Geo
2810: 6d 46 72 6f 6d 54 65 78 74 28 20 27 4c 49 4e 45 mFromText( 'LINE
2820: 53 54 52 49 4e 47 28 20 30 20 30 2c 20 31 20 30 STRING( 0 0, 1 0
2830: 20 29 27 20 29 2c 20 0d 0a 20 20 53 54 5f 47 65 )' ), .. ST_Ge
2840: 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27 50 4f 49 omFromText( 'POI
2850: 4e 54 28 20 31 20 31 20 29 27 20 29 2c 20 2d 31 NT( 1 1 )' ), -1
2860: 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 0d ) );..--------.
2870: 0a 4c 49 4e 45 53 54 52 49 4e 47 28 30 20 30 2c .LINESTRING(0 0,
2880: 20 31 20 30 2c 20 31 20 31 29 0d 0a 3c 2f 76 65 1 0, 1 1)..</ve
2890: 72 62 61 74 69 6d 3e 0d 0a 50 61 73 73 69 6e 67 rbatim>..Passing
28a0: 20 61 20 6e 65 67 61 74 69 76 65 20 69 6e 64 65 a negative inde
28b0: 78 20 69 73 20 61 20 73 75 70 70 6f 72 74 65 64 x is a supported
28c0: 20 6f 70 74 69 6f 6e 2c 20 61 6e 64 20 73 69 6d option, and sim
28d0: 70 6c 79 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 ply corresponds
28e0: 74 6f 20 74 68 65 20 64 65 66 61 75 6c 74 20 62 to the default b
28f0: 65 68 61 76 69 6f 75 72 20 28 69 2e 65 2e 20 3c ehaviour (i.e. <
2900: 69 3e 61 70 70 65 6e 64 69 6e 67 20 74 68 65 20 i>appending the
2910: 50 6f 69 6e 74 20 74 6f 20 74 68 65 20 65 6e 64 Point to the end
2920: 20 6f 66 20 74 68 65 20 4c 69 6e 65 73 74 72 69 of the Linestri
2930: 6e 67 3c 2f 69 3e 29 2e 3c 62 72 3e 3c 62 72 3e ng</i>).<br><br>
2940: 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 ..<hr>..<verbati
2950: 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 54 5f 41 73 m>..SELECT ST_As
2960: 54 65 78 74 28 20 53 54 5f 53 65 74 50 6f 69 6e Text( ST_SetPoin
2970: 74 28 20 0d 0a 20 20 53 54 5f 47 65 6f 6d 46 72 t( .. ST_GeomFr
2980: 6f 6d 54 65 78 74 28 20 27 4c 49 4e 45 53 54 52 omText( 'LINESTR
2990: 49 4e 47 28 20 30 20 30 2c 20 31 20 30 2c 20 31 ING( 0 0, 1 0, 1
29a0: 20 31 20 29 27 20 29 2c 20 0d 0a 20 20 31 2c 20 1 )' ), .. 1,
29b0: 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 ST_GeomFromText(
29c0: 20 27 50 4f 49 4e 54 28 20 32 20 31 20 29 27 20 'POINT( 2 1 )'
29d0: 29 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d ) ) );..--------
29e0: 2d 0d 0a 4c 49 4e 45 53 54 52 49 4e 47 28 30 20 -..LINESTRING(0
29f0: 30 2c 20 32 20 31 2c 20 31 20 31 29 0d 0a 3c 2f 0, 2 1, 1 1)..</
2a00: 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c verbatim>..The <
2a10: 62 3e 53 54 5f 53 65 74 50 6f 69 6e 74 28 29 3c b>ST_SetPoint()<
2a20: 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e /b> SQL function
2a30: 20 63 61 6e 20 72 65 70 6c 61 63 65 20 61 20 50 can replace a P
2a40: 6f 69 6e 74 2f 56 65 72 74 65 78 20 66 72 6f 6d oint/Vertex from
2a50: 20 77 69 74 68 69 6e 20 61 20 4c 69 6e 65 73 74 within a Linest
2a60: 72 69 6e 67 3b 20 74 68 65 20 66 69 72 73 74 20 ring; the first
2a70: 61 72 67 75 6d 65 6e 74 20 69 73 20 61 6c 77 61 argument is alwa
2a80: 79 73 20 65 78 70 65 63 74 65 64 20 74 6f 20 62 ys expected to b
2a90: 65 20 6f 66 20 74 68 65 20 4c 69 6e 65 73 74 72 e of the Linestr
2aa0: 69 6e 67 20 74 79 70 65 2c 20 74 68 65 20 73 65 ing type, the se
2ab0: 63 6f 6e 64 20 69 73 20 61 6e 20 49 6e 74 65 67 cond is an Integ
2ac0: 65 72 20 73 70 65 63 69 66 79 69 6e 67 20 74 68 er specifying th
2ad0: 65 20 3c 75 3e 69 6e 64 65 78 3c 2f 75 3e 20 6f e <u>index</u> o
2ae0: 66 20 74 68 65 20 61 66 66 65 63 74 65 64 20 56 f the affected V
2af0: 65 72 74 65 78 20 61 6e 64 20 74 68 65 20 74 68 ertex and the th
2b00: 69 72 64 20 6f 6e 65 20 6d 75 73 74 20 62 65 20 ird one must be
2b10: 61 20 50 6f 69 6e 74 2e 3c 62 72 3e 0d 0a 52 65 a Point.<br>..Re
2b20: 66 65 72 65 6e 63 69 6e 67 20 61 20 6e 6f 74 20 ferencing a not
2b30: 65 78 69 73 74 69 6e 67 20 69 6e 64 65 78 20 69 existing index i
2b40: 73 20 61 6e 20 65 72 72 6f 72 2c 20 61 6e 64 20 s an error, and
2b50: 77 69 6c 6c 20 72 65 74 75 72 6e 20 4e 55 4c 4c will return NULL
2b60: 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d .<br><br>..<hr>.
2b70: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c .<verbatim>..SEL
2b80: 45 43 54 20 53 54 5f 41 73 54 65 78 74 28 20 53 ECT ST_AsText( S
2b90: 54 5f 52 65 6d 6f 76 65 50 6f 69 6e 74 28 20 0d T_RemovePoint( .
2ba0: 0a 20 20 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 . ST_GeomFromTe
2bb0: 78 74 28 20 27 4c 49 4e 45 53 54 52 49 4e 47 28 xt( 'LINESTRING(
2bc0: 20 30 20 30 2c 20 31 20 30 2c 20 31 20 31 20 29 0 0, 1 0, 1 1 )
2bd0: 27 20 29 2c 20 31 20 29 20 29 3b 0d 0a 2d 2d 2d ' ), 1 ) );..---
2be0: 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45 53 54 52 49 ------..LINESTRI
2bf0: 4e 47 28 30 20 30 2c 20 31 20 31 29 0d 0a 3c 2f NG(0 0, 1 1)..</
2c00: 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c verbatim>..The <
2c10: 62 3e 53 54 5f 52 65 6d 6f 76 65 50 6f 69 6e 74 b>ST_RemovePoint
2c20: 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 ()</b> SQL funct
2c30: 69 6f 6e 20 63 61 6e 20 72 65 6d 6f 76 65 20 61 ion can remove a
2c40: 20 50 6f 69 6e 74 2f 56 65 72 74 65 78 20 66 72 Point/Vertex fr
2c50: 6f 6d 20 77 69 74 68 69 6e 20 61 20 4c 69 6e 65 om within a Line
2c60: 73 74 72 69 6e 67 3b 20 74 68 65 20 66 69 72 73 string; the firs
2c70: 74 20 61 72 67 75 6d 65 6e 74 20 69 73 20 61 6c t argument is al
2c80: 77 61 79 73 20 65 78 70 65 63 74 65 64 20 74 6f ways expected to
2c90: 20 62 65 20 6f 66 20 74 68 65 20 4c 69 6e 65 73 be of the Lines
2ca0: 74 72 69 6e 67 20 74 79 70 65 2c 20 74 68 65 20 tring type, the
2cb0: 73 65 63 6f 6e 64 20 69 73 20 61 6e 20 49 6e 74 second is an Int
2cc0: 65 67 65 72 20 73 70 65 63 69 66 79 69 6e 67 20 eger specifying
2cd0: 74 68 65 20 3c 75 3e 69 6e 64 65 78 3c 2f 75 3e the <u>index</u>
2ce0: 20 6f 66 20 74 68 65 20 61 66 66 65 63 74 65 64 of the affected
2cf0: 20 56 65 72 74 65 78 2e 3c 62 72 3e 0d 0a 52 65 Vertex.<br>..Re
2d00: 66 65 72 65 6e 63 69 6e 67 20 61 20 6e 6f 74 20 ferencing a not
2d10: 65 78 69 73 74 69 6e 67 20 69 6e 64 65 78 20 69 existing index i
2d20: 73 20 61 6e 20 65 72 72 6f 72 2c 20 61 6e 64 20 s an error, and
2d30: 77 69 6c 6c 20 72 65 74 75 72 6e 20 4e 55 4c 4c will return NULL
2d40: 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d .<br><br>..<hr>.
2d50: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c .<verbatim>..SEL
2d60: 45 43 54 20 53 54 5f 41 73 54 65 78 74 28 20 53 ECT ST_AsText( S
2d70: 54 5f 50 6f 69 6e 74 28 31 30 2c 20 32 30 29 20 T_Point(10, 20)
2d80: 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a );..----------..
2d90: 50 4f 49 4e 54 28 31 30 20 31 30 29 0d 0a 3c 2f POINT(10 10)..</
2da0: 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c verbatim>..The <
2db0: 62 3e 53 54 5f 50 6f 69 6e 74 28 29 3c 2f 62 3e b>ST_Point()</b>
2dc0: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 73 69 SQL function si
2dd0: 6d 70 6c 79 20 69 73 20 79 65 74 20 61 6e 6f 74 mply is yet anot
2de0: 68 65 72 20 3c 69 3e 61 6c 69 61 73 2d 6e 61 6d her <i>alias-nam
2df0: 65 3c 2f 69 3e 20 63 6f 72 72 65 73 70 6f 6e 64 e</i> correspond
2e00: 69 6e 67 20 74 6f 20 3c 62 3e 4d 61 6b 65 50 6f ing to <b>MakePo
2e10: 69 6e 74 28 29 3c 2f 62 3e 3b 20 74 68 69 73 20 int()</b>; this
2e20: 66 75 72 74 68 65 72 20 61 6c 69 61 73 20 68 61 further alias ha
2e30: 73 20 62 65 65 6e 20 69 6e 74 72 6f 64 75 63 65 s been introduce
2e40: 64 20 73 6f 20 74 6f 20 73 75 70 70 6f 72 74 20 d so to support
2e50: 61 20 73 74 72 69 63 74 20 50 6f 73 74 47 49 53 a strict PostGIS
2e60: 20 63 6f 6e 66 6f 72 6d 61 6e 63 65 2e 3c 62 72 conformance.<br
2e70: 3e 0d 0a 3c 75 3e 50 6c 65 61 73 65 20 6e 6f 74 >..<u>Please not
2e80: 65 3c 2f 75 3e 3a 20 64 69 66 66 65 72 65 6e 74 e</u>: different
2e90: 6c 79 20 66 72 6f 6d 20 4d 61 6b 65 50 6f 69 6e ly from MakePoin
2ea0: 74 28 29 2c 20 53 54 5f 50 6f 69 6e 74 28 29 20 t(), ST_Point()
2eb0: 64 6f 6e 27 74 20 73 75 70 70 6f 72 74 73 20 74 don't supports t
2ec0: 68 65 20 6f 70 74 69 6f 6e 61 6c 20 3c 62 3e 53 he optional <b>S
2ed0: 52 49 44 3c 2f 62 3e 20 61 72 67 75 6d 65 6e 74 RID</b> argument
2ee0: 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d .<br><br>..<hr>.
2ef0: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c .<verbatim>..SEL
2f00: 45 43 54 20 53 54 5f 41 73 54 65 78 74 28 20 4d ECT ST_AsText( M
2f10: 61 6b 65 4c 69 6e 65 28 20 53 54 5f 47 65 6f 6d akeLine( ST_Geom
2f20: 46 72 6f 6d 54 65 78 74 28 20 27 4d 55 4c 54 49 FromText( 'MULTI
2f30: 50 4f 49 4e 54 28 30 20 30 2c 20 31 20 30 2c 20 POINT(0 0, 1 0,
2f40: 31 20 31 29 27 20 29 20 29 20 2c 20 31 20 29 3b 1 1)' ) ) , 1 );
2f50: 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 ..----------..LI
2f60: 4e 45 53 54 52 49 4e 47 28 30 20 30 2c 20 31 20 NESTRING(0 0, 1
2f70: 30 2c 20 31 20 31 29 0d 0a 0d 0a 53 45 4c 45 43 0, 1 1)....SELEC
2f80: 54 20 53 54 5f 41 73 54 65 78 74 28 20 4d 61 6b T ST_AsText( Mak
2f90: 65 4c 69 6e 65 28 20 53 54 5f 47 65 6f 6d 46 72 eLine( ST_GeomFr
2fa0: 6f 6d 54 65 78 74 28 20 27 4d 55 4c 54 49 50 4f omText( 'MULTIPO
2fb0: 49 4e 54 28 30 20 30 2c 20 31 20 30 2c 20 31 20 INT(0 0, 1 0, 1
2fc0: 31 29 27 20 29 20 29 20 2c 20 30 20 29 3b 0d 0a 1)' ) ) , 0 );..
2fd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45 ----------..LINE
2fe0: 53 54 52 49 4e 47 28 31 20 31 2c 20 31 20 30 2c STRING(1 1, 1 0,
2ff0: 20 30 20 30 29 0d 0a 3c 2f 76 65 72 62 61 74 69 0 0)..</verbati
3000: 6d 3e 0d 0a 4e 6f 74 20 72 65 61 6c 6c 79 20 61 m>..Not really a
3010: 20 62 72 61 6e 64 20 6e 65 77 20 53 51 4c 20 66 brand new SQL f
3020: 75 6e 63 74 69 6f 6e 3b 20 6d 6f 72 65 20 73 69 unction; more si
3030: 6d 70 6c 79 20 61 20 66 75 72 74 68 65 72 20 6f mply a further o
3040: 76 65 72 6c 6f 61 64 65 64 20 66 6c 61 76 6f 72 verloaded flavor
3050: 20 6f 66 20 74 68 65 20 61 6c 72 65 61 64 79 20 of the already
3060: 65 78 69 73 74 69 6e 67 20 3c 62 3e 4d 61 6b 65 existing <b>Make
3070: 4c 69 6e 65 28 29 3c 2f 62 3e 2e 3c 62 72 3e 0d Line()</b>.<br>.
3080: 0a 4e 6f 77 20 74 68 65 20 69 6e 70 75 74 20 47 .Now the input G
3090: 65 6f 6d 65 74 72 79 20 28 66 69 72 73 74 20 61 eometry (first a
30a0: 72 67 75 6d 65 6e 74 29 20 63 6f 75 6c 64 20 62 rgument) could b
30b0: 65 20 6f 66 20 74 68 65 20 4d 55 4c 54 49 50 4f e of the MULTIPO
30c0: 49 4e 54 20 74 79 70 65 20 61 6e 64 20 74 68 65 INT type and the
30d0: 20 73 65 63 6f 6e 64 20 61 72 67 75 6d 65 6e 74 second argument
30e0: 20 69 66 20 6f 66 20 74 68 65 20 3c 62 3e 42 6f if of the <b>Bo
30f0: 6f 6c 65 61 6e 3c 2f 62 3e 20 74 79 70 65 3b 20 olean</b> type;
3100: 69 66 20 74 68 65 20 73 65 63 6f 6e 64 20 61 72 if the second ar
3110: 67 75 6d 65 6e 74 20 63 6f 72 72 65 73 70 6f 6e gument correspon
3120: 64 73 20 74 6f 20 3c 62 3e 54 52 55 45 3c 2f 62 ds to <b>TRUE</b
3130: 3e 20 74 68 65 20 72 65 74 75 72 6e 65 64 20 4c > the returned L
3140: 49 4e 45 53 54 52 49 4e 47 20 77 69 6c 6c 20 62 INESTRING will b
3150: 65 20 6f 72 69 65 6e 74 65 64 20 61 63 63 6f 72 e oriented accor
3160: 64 69 6e 67 6c 79 20 74 6f 20 74 68 65 20 50 6f dingly to the Po
3170: 69 6e 74 2d 73 65 71 75 65 6e 63 65 20 61 73 20 int-sequence as
3180: 73 70 65 63 69 66 69 65 64 20 62 79 20 74 68 65 specified by the
3190: 20 4d 75 6c 74 69 50 6f 69 6e 74 2c 20 6f 74 68 MultiPoint, oth
31a0: 65 72 77 69 73 65 20 3c 75 3e 72 65 76 65 72 73 erwise <u>revers
31b0: 65 20 6f 72 64 65 72 3c 2f 75 3e 20 77 69 6c 6c e order</u> will
31c0: 20 62 65 20 61 73 73 75 6d 65 64 2c 20 74 68 75 be assumed, thu
31d0: 73 20 72 65 74 75 72 6e 69 6e 67 20 61 20 4c 69 s returning a Li
31e0: 6e 65 73 74 72 69 6e 67 20 6f 66 20 6f 70 70 6f nestring of oppo
31f0: 73 69 74 65 20 6f 72 69 65 6e 74 61 74 69 6f 6e site orientation
3200: 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d .<br><br>..<hr>.
3210: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c .<verbatim>..SEL
3220: 45 43 54 20 53 54 5f 41 72 65 61 28 20 53 54 5f ECT ST_Area( ST_
3230: 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27 50 GeomFromText( 'P
3240: 4f 4c 59 47 4f 4e 28 28 32 30 20 32 30 2c 20 32 OLYGON((20 20, 2
3250: 31 20 32 30 2c 20 32 31 20 32 31 2c 20 32 30 20 1 20, 21 21, 20
3260: 32 31 2c 20 32 30 20 32 30 29 29 27 2c 20 34 33 21, 20 20))', 43
3270: 32 36 20 29 2c 20 31 20 29 3b 0d 0a 2d 2d 2d 2d 26 ), 1 );..----
3280: 2d 2d 2d 2d 2d 2d 0d 0a 31 31 35 34 38 35 35 35 ------..11548555
3290: 39 32 36 2e 36 34 37 37 33 36 0d 0a 0d 0a 0d 0a 926.647736......
32a0: 53 45 4c 45 43 54 20 53 54 5f 41 72 65 61 28 20 SELECT ST_Area(
32b0: 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 ST_GeomFromText(
32c0: 20 27 50 4f 4c 59 47 4f 4e 28 28 32 30 20 32 30 'POLYGON((20 20
32d0: 2c 20 32 31 20 32 30 2c 20 32 31 20 32 31 2c 20 , 21 20, 21 21,
32e0: 32 30 20 32 31 2c 20 32 30 20 32 30 29 29 27 2c 20 21, 20 20))',
32f0: 20 34 33 32 36 20 29 2c 20 30 20 29 3b 0d 0a 2d 4326 ), 0 );..-
3300: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 31 35 38 31 ---------..11581
3310: 33 37 37 36 32 33 2e 31 31 34 31 38 39 0d 0a 3c 377623.114189..<
3320: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 4f 6e 63 65 /verbatim>..Once
3330: 20 61 67 61 69 6e 2c 20 73 69 6d 70 6c 79 20 61 again, simply a
3340: 20 66 75 72 74 68 65 72 20 65 78 74 65 6e 73 69 further extensi
3350: 6f 6e 20 6f 66 20 74 68 65 20 61 6c 72 65 61 64 on of the alread
3360: 79 20 65 78 69 73 74 69 6e 67 20 3c 62 3e 53 54 y existing <b>ST
3370: 5f 41 72 65 61 28 29 3c 2f 62 3e 2e 3c 62 72 3e _Area()</b>.<br>
3380: 0d 0a 4e 6f 77 20 69 66 20 74 68 65 20 69 6e 70 ..Now if the inp
3390: 75 74 20 47 65 6f 6d 65 74 72 79 20 61 64 6f 70 ut Geometry adop
33a0: 74 73 20 3c 75 3e 67 65 6f 67 72 61 70 68 69 63 ts <u>geographic
33b0: 20 63 6f 6f 72 64 69 6e 61 74 65 73 3c 2f 75 3e coordinates</u>
33c0: 20 28 69 2e 65 2e 20 62 61 73 65 64 20 6f 6e 20 (i.e. based on
33d0: 3c 75 3e 6c 6f 6e 67 69 74 75 64 65 3c 2f 75 3e <u>longitude</u>
33e0: 20 61 6e 64 20 3c 75 3e 6c 61 74 69 74 75 64 65 and <u>latitude
33f0: 3c 2f 75 3e 20 61 6e 67 6c 65 73 29 2c 20 61 20 </u> angles), a
3400: 73 65 63 6f 6e 64 20 61 72 67 75 6d 65 6e 74 20 second argument
3410: 6f 66 20 74 68 65 20 3c 62 3e 42 6f 6f 6c 65 61 of the <b>Boolea
3420: 6e 3c 2f 62 3e 20 64 61 74 61 2d 74 79 70 65 20 n</b> data-type
3430: 63 6f 75 6c 64 20 62 65 20 6f 70 74 69 6f 6e 61 could be optiona
3440: 6c 6c 79 20 73 70 65 63 69 66 69 65 64 2e 3c 62 lly specified.<b
3450: 72 3e 0d 0a 49 6e 20 74 68 69 73 20 63 61 73 65 r>..In this case
3460: 20 74 68 65 20 72 65 74 75 72 6e 65 64 20 41 72 the returned Ar
3470: 65 61 20 77 69 6c 6c 20 62 65 20 6d 65 61 73 75 ea will be measu
3480: 72 65 64 20 69 6e 20 3c 62 3e 6d 65 74 65 72 73 red in <b>meters
3490: 3c 2f 62 3e 2e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 </b>...<ul>..<li
34a0: 3e 69 66 20 74 68 65 20 73 65 63 6f 6e 64 20 61 >if the second a
34b0: 72 67 20 69 73 20 3c 62 3e 54 52 55 45 3c 2f 62 rg is <b>TRUE</b
34c0: 3e 20 74 68 65 20 41 72 65 61 20 77 69 6c 6c 20 > the Area will
34d0: 62 65 20 6d 65 61 73 75 72 65 64 20 3c 75 3e 6f be measured <u>o
34e0: 6e 20 74 68 65 20 45 6c 6c 69 70 73 6f 69 64 3c n the Ellipsoid<
34f0: 2f 75 3e 20 28 6d 6f 72 65 20 61 63 63 75 72 61 /u> (more accura
3500: 74 65 2c 20 62 75 74 20 73 6c 6f 77 65 72 29 2e te, but slower).
3510: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 69 66 20 74 68 </li>..<li>if th
3520: 65 20 73 65 63 6f 6e 64 20 61 72 67 20 69 73 20 e second arg is
3530: 3c 62 3e 46 41 4c 53 45 3c 2f 62 3e 20 74 68 65 <b>FALSE</b> the
3540: 20 41 72 65 61 20 77 69 6c 6c 20 62 65 20 6d 65 Area will be me
3550: 61 73 75 72 65 20 3c 75 3e 6f 6e 20 74 68 65 20 asure <u>on the
3560: 53 70 68 65 72 65 3c 2f 75 3e 20 28 66 61 73 74 Sphere</u> (fast
3570: 65 72 2c 20 62 75 74 20 6c 65 73 73 20 61 63 63 er, but less acc
3580: 75 72 61 74 65 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c urate).</li>..<l
3590: 69 3e 4e 55 4c 4c 20 77 69 6c 6c 20 62 65 20 72 i>NULL will be r
35a0: 65 74 75 72 6e 65 64 20 6f 6e 20 69 6e 76 61 6c eturned on inval
35b0: 69 64 20 61 72 67 73 2e 3c 2f 6c 69 3e 0d 0a 3c id args.</li>..<
35c0: 6c 69 3e 3c 75 3e 50 6c 65 61 73 65 20 6e 6f 74 li><u>Please not
35d0: 65 3c 2f 75 3e 3a 20 74 68 69 73 20 73 70 65 63 e</u>: this spec
35e0: 69 66 69 63 20 66 6c 61 76 6f 72 20 6f 66 20 3c ific flavor of <
35f0: 62 3e 53 54 5f 41 72 65 61 28 29 3c 2f 62 3e 20 b>ST_Area()</b>
3600: 6e 65 63 65 73 73 61 72 69 6c 79 20 72 65 71 75 necessarily requ
3610: 69 72 65 73 20 74 68 65 20 3c 62 3e 4c 57 47 45 ires the <b>LWGE
3620: 4f 4d 3c 2f 62 3e 20 73 75 70 70 6f 72 74 20 74 OM</b> support t
3630: 6f 20 62 65 20 61 63 74 69 76 61 74 65 64 20 61 o be activated a
3640: 74 20 62 75 69 6c 64 20 74 69 6d 65 2e 3c 2f 6c t build time.</l
3650: 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d 0a 3c i>..</ul><br>..<
3660: 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d hr>..<verbatim>.
3670: 0a 53 45 4c 45 43 54 20 53 54 5f 41 73 54 65 78 .SELECT ST_AsTex
3680: 74 28 20 53 54 5f 50 72 6f 6a 65 63 74 28 20 4d t( ST_Project( M
3690: 61 6b 65 50 6f 69 6e 74 28 20 31 31 2e 35 32 2c akePoint( 11.52,
36a0: 20 34 32 2e 33 38 2c 20 34 33 32 36 20 29 2c 20 42.38, 4326 ),
36b0: 35 30 30 30 30 2c 20 52 61 64 69 61 6e 73 28 20 50000, Radians(
36c0: 34 35 20 29 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 45 ) ) );..-----
36d0: 2d 2d 2d 2d 2d 0d 0a 50 4f 49 4e 54 28 31 31 2e -----..POINT(11.
36e0: 39 35 31 34 37 39 20 34 32 2e 36 39 37 34 36 37 951479 42.697467
36f0: 29 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a )..</verbatim>..
3700: 54 68 65 20 3c 62 3e 53 54 5f 50 72 6f 6a 65 63 The <b>ST_Projec
3710: 74 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 t()</b> SQL func
3720: 74 69 6f 6e 20 77 69 6c 6c 20 72 65 74 75 72 6e tion will return
3730: 20 74 68 65 20 64 65 73 74 69 6e 61 74 69 6f 6e the destination
3740: 20 50 6f 69 6e 74 20 3c 75 3e 6f 6e 20 74 68 65 Point <u>on the
3750: 20 65 6c 6c 69 70 73 6f 69 64 3c 2f 75 3e 20 63 ellipsoid</u> c
3760: 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 74 6f 20 orresponding to
3770: 61 20 3c 62 3e 73 74 61 72 74 5f 70 6f 69 6e 74 a <b>start_point
3780: 3c 2f 62 3e 2c 20 61 20 3c 62 3e 64 69 73 74 61 </b>, a <b>dista
3790: 6e 63 65 3c 2f 62 3e 20 61 6e 64 20 61 20 3c 62 nce</b> and a <b
37a0: 3e 62 65 61 72 69 6e 67 3c 2f 62 3e 20 28 61 6b >bearing</b> (ak
37b0: 61 20 3c 75 3e 61 7a 69 6d 75 74 68 3c 2f 75 3e a <u>azimuth</u>
37c0: 20 61 6b 61 20 3c 75 3e 64 69 72 65 63 74 69 6f aka <u>directio
37d0: 6e 3c 2f 75 3e 20 61 6b 61 20 3c 75 3e 68 65 61 n</u> aka <u>hea
37e0: 64 69 6e 67 3c 2f 75 3e 29 2e 0d 0a 3c 75 6c 3e ding</u>)...<ul>
37f0: 0d 0a 3c 6c 69 3e 74 68 65 20 3c 62 3e 73 74 61 ..<li>the <b>sta
3800: 72 74 5f 70 6f 69 6e 74 3c 2f 62 3e 20 69 73 20 rt_point</b> is
3810: 65 78 70 65 63 74 65 64 20 74 6f 20 61 64 6f 70 expected to adop
3820: 74 20 3c 75 3e 67 65 6f 67 72 61 70 68 69 63 20 t <u>geographic
3830: 63 6f 6f 72 64 69 6e 61 74 65 73 3c 2f 75 3e 20 coordinates</u>
3840: 28 69 2e 65 2e 20 62 61 73 65 64 20 6f 6e 20 3c (i.e. based on <
3850: 75 3e 6c 6f 6e 67 69 74 75 64 65 3c 2f 75 3e 20 u>longitude</u>
3860: 61 6e 64 20 3c 75 3e 6c 61 74 69 74 75 64 65 3c and <u>latitude<
3870: 2f 75 3e 20 61 6e 67 6c 65 73 29 2e 3c 2f 6c 69 /u> angles).</li
3880: 3e 0d 0a 3c 6c 69 3e 74 68 65 20 3c 62 3e 64 69 >..<li>the <b>di
3890: 73 74 61 6e 63 65 3c 2f 62 3e 20 69 73 20 61 6c stance</b> is al
38a0: 77 61 79 73 20 65 78 70 65 63 74 65 64 20 74 6f ways expected to
38b0: 20 62 65 20 65 78 70 72 65 73 73 65 64 20 69 6e be expressed in
38c0: 20 3c 62 3e 6d 65 74 65 72 73 3c 2f 62 3e 2e 3c <b>meters</b>.<
38d0: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 74 68 65 20 3c 62 /li>..<li>the <b
38e0: 3e 61 7a 69 6d 75 74 68 3c 2f 62 3e 20 61 6e 67 >azimuth</b> ang
38f0: 6c 65 20 69 73 20 65 78 70 65 63 74 65 64 20 74 le is expected t
3900: 6f 20 62 65 20 65 78 70 72 65 73 73 65 64 20 69 o be expressed i
3910: 6e 20 3c 62 3e 72 61 64 69 61 6e 73 3c 2f 62 3e n <b>radians</b>
3920: 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 4e 6f 72 :..<ul>..<li>Nor
3930: 74 68 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 th corresponds t
3940: 6f 20 30 20 64 65 67 72 65 65 73 20 28 30 20 72 o 0 degrees (0 r
3950: 61 64 69 61 6e 73 29 2e 3c 2f 6c 69 3e 0d 0a 3c adians).</li>..<
3960: 6c 69 3e 45 61 73 74 20 63 6f 72 72 65 73 70 6f li>East correspo
3970: 6e 64 73 20 74 6f 20 39 30 20 64 65 67 72 65 65 nds to 90 degree
3980: 73 20 28 50 49 2f 32 20 72 61 64 69 61 6e 73 29 s (PI/2 radians)
3990: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 53 6f 75 74 .</li>..<li>Sout
39a0: 68 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f h corresponds to
39b0: 20 31 38 30 20 64 65 67 72 65 65 73 20 28 50 49 180 degrees (PI
39c0: 20 72 61 64 69 61 6e 73 29 2e 3c 2f 6c 69 3e 0d radians).</li>.
39d0: 0a 3c 6c 69 3e 57 65 73 74 20 63 6f 72 72 65 73 .<li>West corres
39e0: 70 6f 6e 64 73 20 74 6f 20 32 37 30 20 64 65 67 ponds to 270 deg
39f0: 72 65 65 73 20 28 33 50 49 2f 32 20 72 61 64 69 rees (3PI/2 radi
3a00: 61 6e 73 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e ans).</li>..<li>
3a10: 69 2e 65 2e 20 69 74 20 68 61 73 20 74 68 65 20 i.e. it has the
3a20: 73 61 6d 65 20 69 64 65 6e 74 69 63 61 6c 20 6d same identical m
3a30: 65 61 6e 69 6e 67 20 61 73 20 69 6e 20 3c 62 3e eaning as in <b>
3a40: 53 54 5f 41 7a 69 6d 75 74 68 28 29 3c 2f 62 3e ST_Azimuth()</b>
3a50: 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 2f 6c .</li>..</ul></l
3a60: 69 3e 0d 0a 3c 6c 69 3e 74 68 69 73 20 66 75 6e i>..<li>this fun
3a70: 63 74 69 6f 6e 20 65 78 61 63 74 6c 79 20 63 6f ction exactly co
3a80: 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 74 68 65 rresponds to the
3a90: 20 6f 6e 65 20 73 75 70 70 6f 72 74 65 64 20 62 one supported b
3aa0: 79 20 3c 62 3e 50 6f 73 74 47 49 53 3c 2f 62 3e y <b>PostGIS</b>
3ab0: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 75 3e 50 .</li>..<li><u>P
3ac0: 6c 65 61 73 65 20 6e 6f 74 65 3c 2f 75 3e 3a 20 lease note</u>:
3ad0: 3c 62 3e 53 54 5f 50 72 6f 6a 65 63 74 28 29 3c <b>ST_Project()<
3ae0: 2f 62 3e 20 6e 65 63 65 73 73 61 72 69 6c 79 20 /b> necessarily
3af0: 72 65 71 75 69 72 65 73 20 74 68 65 20 3c 62 3e requires the <b>
3b00: 4c 57 47 45 4f 4d 3c 2f 62 3e 20 73 75 70 70 6f LWGEOM</b> suppo
3b10: 72 74 20 74 6f 20 62 65 20 61 63 74 69 76 61 74 rt to be activat
3b20: 65 64 20 61 74 20 62 75 69 6c 64 20 74 69 6d 65 ed at build time
3b30: 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62 72 .</li>..</ul><br
3b40: 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 3c 61 20 >..<hr>..<h3><a
3b50: 6e 61 6d 65 3d 22 75 6e 73 61 66 65 22 3e 55 6e name="unsafe">Un
3b60: 73 61 66 65 3c 2f 61 3e 20 28 62 75 74 20 75 73 safe</a> (but us
3b70: 65 66 75 6c 29 20 49 6d 70 6f 72 74 2f 45 78 70 eful) Import/Exp
3b80: 6f 72 74 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e ort SQL function
3b90: 73 3c 2f 68 33 3e 0d 0a 41 6c 6c 20 74 68 65 20 s</h3>..All the
3ba0: 66 6f 6c 6c 6f 77 69 6e 67 20 53 51 4c 20 66 75 following SQL fu
3bb0: 6e 63 74 69 6f 6e 73 20 63 6f 75 6c 64 20 62 65 nctions could be
3bc0: 20 72 65 61 6c 6c 79 20 75 73 65 66 75 6c 20 69 really useful i
3bd0: 6e 20 6f 72 64 65 72 20 74 6f 20 73 75 70 70 6f n order to suppo
3be0: 72 74 20 49 6d 70 6f 72 74 2f 45 78 70 6f 72 74 rt Import/Export
3bf0: 20 6f 70 65 72 61 74 69 6f 6e 73 2e 3c 62 72 3e operations.<br>
3c00: 0d 0a 41 6e 79 77 61 79 20 79 6f 75 20 73 68 6f ..Anyway you sho
3c10: 75 6c 64 20 62 65 20 3c 75 3e 77 65 6c 6c 20 61 uld be <u>well a
3c20: 77 61 72 65 3c 2f 75 3e 20 74 68 61 74 20 61 6c ware</u> that al
3c30: 6c 20 74 68 65 6d 20 63 6f 75 6c 64 20 62 65 20 l them could be
3c40: 70 6f 74 65 6e 74 69 61 6c 6c 79 20 3c 75 3e 75 potentially <u>u
3c50: 6e 73 61 66 65 3c 2f 75 3e 20 61 6e 64 20 63 6f nsafe</u> and co
3c60: 75 6c 64 20 62 65 20 70 6f 74 65 6e 74 69 61 6c uld be potential
3c70: 6c 79 20 75 73 65 64 20 62 79 20 73 6f 6d 65 20 ly used by some
3c80: 3c 75 3e 6d 61 6c 69 63 69 6f 75 73 20 68 61 63 <u>malicious hac
3c90: 6b 65 72 3c 2f 75 3e 20 69 6e 20 6f 72 64 65 72 ker</u> in order
3ca0: 20 74 6f 20 63 72 65 61 74 65 20 61 6e 64 20 65 to create and e
3cb0: 78 70 6c 6f 69 74 20 73 6f 6d 65 20 3c 75 3e 73 xploit some <u>s
3cc0: 65 63 75 72 69 74 79 20 62 72 65 61 63 68 3c 2f ecurity breach</
3cd0: 75 3e 2e 3c 62 72 3e 0d 0a 54 68 65 20 63 61 75 u>.<br>..The cau
3ce0: 73 65 20 69 73 20 76 65 72 79 20 65 61 73 79 20 se is very easy
3cf0: 74 6f 20 62 65 20 75 6e 64 65 72 73 74 6f 6f 64 to be understood
3d00: 3a 20 74 68 65 73 65 20 66 75 6e 63 74 69 6f 6e : these function
3d10: 73 20 61 6c 6c 6f 77 20 74 6f 20 74 72 61 6e 73 s allow to trans
3d20: 66 65 72 20 61 72 62 69 74 72 61 72 79 20 70 61 fer arbitrary pa
3d30: 79 6c 6f 61 64 73 20 66 72 6f 6d 20 2f 20 74 6f yloads from / to
3d40: 20 74 68 65 20 44 61 74 61 62 61 73 65 20 61 6e the Database an
3d50: 64 20 74 68 65 20 6c 6f 63 61 6c 20 46 69 6c 65 d the local File
3d60: 2d 53 79 73 74 65 6d 2e 0d 0a 41 20 6d 61 6c 69 -System...A mali
3d70: 63 69 6f 75 73 20 61 74 74 61 63 6b 20 63 6f 75 cious attack cou
3d80: 6c 64 20 62 65 20 74 68 75 73 20 69 6d 70 6c 65 ld be thus imple
3d90: 6d 65 6e 74 65 64 20 65 2e 67 2e 20 62 79 20 65 mented e.g. by e
3da0: 78 65 63 75 74 69 6e 67 20 73 6f 6d 65 20 53 51 xecuting some SQ
3db0: 4c 20 73 63 72 69 70 74 20 6f 72 20 62 79 20 64 L script or by d
3dc0: 65 66 69 6e 69 6e 67 20 61 20 70 75 72 70 6f 73 efining a purpos
3dd0: 65 6c 79 20 66 6f 72 67 65 64 20 54 72 69 67 67 ely forged Trigg
3de0: 65 72 2c 20 61 6e 64 20 74 68 65 20 65 6e 64 20 er, and the end
3df0: 75 73 65 72 73 20 77 6f 75 6c 64 20 62 65 20 61 users would be a
3e00: 62 73 6f 6c 75 74 65 6c 79 20 75 6e 61 77 61 72 bsolutely unawar
3e10: 65 20 6f 66 20 77 68 61 74 20 69 73 20 72 65 61 e of what is rea
3e20: 6c 6c 79 20 68 61 70 70 65 6e 69 6e 67 2e 0d 0a lly happening...
3e30: 53 6f 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 65 So in order to e
3e40: 66 66 65 63 74 69 76 65 6c 79 20 73 68 69 65 6c ffectively shiel
3e50: 64 20 75 73 65 72 73 20 61 67 61 69 6e 73 74 20 d users against
3e60: 74 68 65 73 65 20 70 6f 74 65 6e 74 69 61 6c 6c these potentiall
3e70: 79 20 64 61 6e 67 65 72 6f 75 73 20 73 65 63 75 y dangerous secu
3e80: 72 69 74 79 20 70 69 74 66 61 6c 6c 73 20 61 6c rity pitfalls al
3e90: 6c 20 74 68 65 73 65 20 53 51 4c 20 66 75 6e 63 l these SQL func
3ea0: 74 69 6f 6e 73 20 61 72 65 20 61 6c 77 61 79 73 tions are always
3eb0: 20 3c 75 3e 64 69 73 61 62 6c 65 64 20 62 79 20 <u>disabled by
3ec0: 64 65 66 61 75 6c 74 3c 2f 75 3e 2e 0d 0a 3c 76 default</u>...<v
3ed0: 65 72 62 61 74 69 6d 3e 0d 0a 65 78 70 6f 72 74 erbatim>..export
3ee0: 20 22 53 50 41 54 49 41 4c 49 54 45 5f 53 45 43 "SPATIALITE_SEC
3ef0: 55 52 49 54 59 3d 72 65 6c 61 78 65 64 22 0d 0a URITY=relaxed"..
3f00: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 49 6e 20 </verbatim>..In
3f10: 6f 72 64 65 72 20 74 6f 20 72 65 61 6c 6c 79 20 order to really
3f20: 65 6e 61 62 6c 65 20 74 68 65 73 65 20 66 75 6e enable these fun
3f30: 63 74 69 6f 6e 73 20 74 68 65 20 75 73 65 72 20 ctions the user
3f40: 69 73 20 72 65 71 75 69 72 65 64 20 74 6f 20 74 is required to t
3f50: 61 6b 65 20 61 6e 20 65 78 70 6c 69 63 69 74 20 ake an explicit
3f60: 61 63 74 69 6f 6e 3b 20 69 2e 65 2e 20 74 68 65 action; i.e. the
3f70: 20 3c 75 3e 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 <u>environment
3f80: 76 61 72 69 61 62 6c 65 3c 2f 75 3e 20 3c 62 3e variable</u> <b>
3f90: 53 50 41 54 49 41 4c 49 54 45 5f 53 45 43 55 52 SPATIALITE_SECUR
3fa0: 49 54 59 3d 72 65 6c 61 78 65 64 3c 2f 62 3e 20 ITY=relaxed</b>
3fb0: 68 61 73 20 74 6f 20 62 65 20 64 65 66 69 6e 65 has to be define
3fc0: 64 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a d...<verbatim>..
3fd0: 53 45 4c 45 43 54 20 43 6f 75 6e 74 55 6e 73 61 SELECT CountUnsa
3fe0: 66 65 54 72 69 67 67 65 72 73 28 29 3b 0d 0a 2d feTriggers();..-
3ff0: 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 30 0d 0a 3c 2f 76 --------..0..</v
4000: 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 erbatim>..The <b
4010: 3e 43 6f 75 6e 74 55 6e 73 61 66 65 54 72 69 67 >CountUnsafeTrig
4020: 67 65 72 73 28 29 3c 2f 62 3e 20 61 63 74 75 61 gers()</b> actua
4030: 6c 6c 79 20 63 68 65 63 6b 73 20 69 66 20 74 68 lly checks if th
4040: 65 20 63 6f 6e 6e 65 63 74 65 64 20 44 61 74 61 e connected Data
4050: 62 61 73 65 20 64 6f 65 73 20 63 6f 6e 74 61 69 base does contai
4060: 6e 73 20 61 6e 79 20 73 75 73 70 65 63 74 20 54 ns any suspect T
4070: 72 69 67 67 65 72 3b 20 63 68 65 63 6b 69 6e 67 rigger; checking
4080: 20 74 68 69 73 20 76 65 72 73 69 6f 6e 20 62 65 this version be
4090: 66 6f 72 65 20 65 6e 61 62 6c 69 6e 67 20 74 68 fore enabling th
40a0: 65 20 75 6e 73 61 66 65 20 53 51 4c 20 46 75 6e e unsafe SQL Fun
40b0: 63 74 69 6f 6e 73 20 69 73 20 61 6c 77 61 79 73 ctions is always
40c0: 20 68 69 67 68 6c 79 20 72 65 63 6f 6d 6d 65 6e highly recommen
40d0: 64 65 64 2e 3c 62 72 3e 0d 0a 41 20 72 65 73 75 ded.<br>..A resu
40e0: 6c 74 20 64 69 66 66 65 72 65 6e 74 20 66 72 6f lt different fro
40f0: 6d 20 5a 45 52 4f 20 69 6d 70 6c 69 65 73 20 74 m ZERO implies t
4100: 68 61 74 20 73 6f 6d 65 20 6d 61 6c 69 63 69 6f hat some malicio
4110: 75 73 20 54 72 69 67 67 65 72 20 68 61 73 20 62 us Trigger has b
4120: 65 65 6e 20 69 64 65 6e 74 69 66 69 65 64 3b 20 een identified;
4130: 69 6e 20 74 68 69 73 20 63 61 73 65 20 79 6f 75 in this case you
4140: 20 63 61 6e 20 70 65 72 66 6f 72 6d 20 61 20 64 can perform a d
4150: 65 65 70 65 73 74 20 69 6e 73 70 65 63 74 69 6f eepest inspectio
4160: 6e 20 62 79 20 65 78 65 63 75 74 69 6e 67 20 74 n by executing t
4170: 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 53 51 4c he following SQL
4180: 20 71 75 65 72 79 3a 0d 0a 3c 76 65 72 62 61 74 query:..<verbat
4190: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 74 79 70 65 im>..SELECT type
41a0: 2c 20 6e 61 6d 65 2c 20 74 62 6c 5f 6e 61 6d 65 , name, tbl_name
41b0: 2c 20 73 71 6c 20 0d 0a 46 52 4f 4d 20 73 71 6c , sql ..FROM sql
41c0: 69 74 65 5f 6d 61 73 74 65 72 20 0d 0a 57 48 45 ite_master ..WHE
41d0: 52 45 20 74 79 70 65 20 49 4e 20 28 27 74 72 69 RE type IN ('tri
41e0: 67 67 65 72 27 2c 20 27 76 69 65 77 27 29 20 41 gger', 'view') A
41f0: 4e 44 20 28 73 71 6c 20 4c 49 4b 45 20 27 25 42 ND (sql LIKE '%B
4200: 6c 6f 62 46 72 6f 6d 46 69 6c 65 25 27 20 0d 0a lobFromFile%' ..
4210: 20 20 20 4f 52 20 73 71 6c 20 4c 49 4b 45 20 27 OR sql LIKE '
4220: 25 42 6c 6f 62 54 6f 46 69 6c 65 25 27 20 4f 52 %BlobToFile%' OR
4230: 20 73 71 6c 20 4c 49 4b 45 20 27 25 58 42 5f 4c sql LIKE '%XB_L
4240: 6f 61 64 58 4d 4c 25 27 20 0d 0a 20 20 20 4f 52 oadXML%' .. OR
4250: 20 73 71 6c 20 4c 49 4b 45 20 27 25 58 42 5f 53 sql LIKE '%XB_S
4260: 74 6f 72 65 58 4d 4c 25 27 29 3b 0d 0a 3c 2f 76 toreXML%');..</v
4270: 65 72 62 61 74 69 6d 3e 0d 0a 74 68 69 73 20 77 erbatim>..this w
4280: 69 6c 6c 20 67 69 76 65 20 61 20 66 75 6c 6c 20 ill give a full
4290: 72 65 70 6f 72 74 20 66 6f 72 20 61 6e 79 20 6d report for any m
42a0: 61 6c 69 63 69 6f 75 73 20 54 72 69 67 67 65 72 alicious Trigger
42b0: 20 65 76 65 6e 74 75 61 6c 6c 79 20 66 6f 75 6e eventually foun
42c0: 64 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e d.<br><br>..<hr>
42d0: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 ..<verbatim>..SE
42e0: 4c 45 43 54 20 42 6c 6f 62 46 72 6f 6d 46 69 6c LECT BlobFromFil
42f0: 65 28 20 27 43 3a 2f 6d 79 70 69 63 74 75 72 65 e( 'C:/mypicture
4300: 73 2f 73 75 6e 73 65 74 2e 6a 70 67 27 20 29 3b s/sunset.jpg' );
4310: 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 42 4c 4f ..---------..BLO
4320: 42 2d 76 61 6c 75 65 0d 0a 3c 2f 76 65 72 62 61 B-value..</verba
4330: 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 42 6c 6f tim>..The <b>Blo
4340: 62 46 72 6f 6d 46 69 6c 65 28 29 3c 2f 62 3e 20 bFromFile()</b>
4350: 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 61 6c 6c SQL function all
4360: 6f 77 73 20 74 6f 20 69 6d 70 6f 72 74 20 61 20 ows to import a
4370: 77 68 6f 6c 65 20 66 69 6c 65 20 69 6e 20 61 20 whole file in a
4380: 73 69 6e 67 6c 65 20 73 74 65 70 3b 20 74 68 65 single step; the
4390: 20 66 75 6c 6c 20 66 69 6c 65 20 70 61 79 6c 6f full file paylo
43a0: 61 64 20 77 69 6c 6c 20 62 65 20 72 65 74 75 72 ad will be retur
43b0: 6e 65 64 20 61 73 20 61 20 42 4c 4f 42 20 76 61 ned as a BLOB va
43c0: 6c 75 65 2e 3c 62 72 3e 0d 0a 49 66 20 74 68 65 lue.<br>..If the
43d0: 20 61 72 67 75 6d 65 6e 74 20 28 3c 62 3e 66 69 argument (<b>fi
43e0: 6c 65 2d 70 61 74 68 3c 2f 62 3e 29 20 64 6f 65 le-path</b>) doe
43f0: 73 6e 27 74 20 63 6f 72 72 65 73 70 6f 6e 64 73 sn't corresponds
4400: 20 74 6f 20 61 20 76 61 6c 69 64 20 66 69 6c 65 to a valid file
4410: 20 6f 72 20 69 66 20 74 68 65 20 65 78 74 65 72 or if the exter
4420: 6e 61 6c 20 66 69 6c 65 20 63 61 6e 6e 6f 74 20 nal file cannot
4430: 62 65 20 61 63 63 65 73 73 65 64 20 66 6f 72 20 be accessed for
4440: 61 6e 79 20 72 65 61 73 6f 6e 20 4e 55 4c 4c 20 any reason NULL
4450: 77 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 will be returned
4460: 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d .<br><br>..<hr>.
4470: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c .<verbatim>..SEL
4480: 45 43 54 20 42 6c 6f 62 54 6f 46 69 6c 65 28 20 ECT BlobToFile(
4490: 73 6f 6d 65 42 6c 6f 62 20 2c 20 27 43 3a 2f 6d someBlob , 'C:/m
44a0: 79 70 69 63 74 75 72 65 73 2f 73 75 6e 73 65 74 ypictures/sunset
44b0: 2e 6a 70 67 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d .jpg' );..------
44c0: 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 ---..1..</verbat
44d0: 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 42 6c 6f 62 im>..The <b>Blob
44e0: 54 6f 46 69 6c 65 28 29 3c 2f 62 3e 20 53 51 4c ToFile()</b> SQL
44f0: 20 66 75 6e 63 74 69 6f 6e 20 70 65 72 66 6f 72 function perfor
4500: 6d 73 20 74 68 65 20 6f 70 70 6f 73 69 74 65 20 ms the opposite
4510: 74 61 73 6b 2c 20 69 2e 65 2e 20 69 74 20 65 78 task, i.e. it ex
4520: 70 6f 72 74 73 20 61 20 77 68 6f 6c 65 20 42 4c ports a whole BL
4530: 4f 42 20 69 6e 74 6f 20 61 6e 20 65 78 74 65 72 OB into an exter
4540: 6e 61 6c 20 66 69 6c 65 3b 20 74 68 65 20 66 69 nal file; the fi
4550: 72 73 74 20 61 72 67 75 6d 65 6e 74 20 6d 75 73 rst argument mus
4560: 74 20 63 6f 72 72 65 73 70 6f 6e 64 20 74 6f 20 t correspond to
4570: 73 6f 6d 65 20 42 4c 4f 42 2c 20 74 68 65 20 73 some BLOB, the s
4580: 65 63 6f 6e 64 20 6f 6e 65 20 69 73 20 74 68 65 econd one is the
4590: 20 3c 62 3e 66 69 6c 65 2d 70 61 74 68 3c 2f 62 <b>file-path</b
45a0: 3e 20 69 64 65 6e 74 69 66 79 69 6e 67 20 74 68 > identifying th
45b0: 65 20 66 69 6c 65 20 74 6f 20 62 65 20 63 72 65 e file to be cre
45c0: 61 74 65 64 20 6f 72 20 6f 76 65 72 77 72 69 74 ated or overwrit
45d0: 74 65 6e 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 75 ten.<br><br>..<u
45e0: 3e 50 6c 65 61 73 65 20 6e 6f 74 65 3c 2f 75 3e >Please note</u>
45f0: 3a 20 62 6f 74 68 20 3c 62 3e 42 6c 6f 62 46 72 : both <b>BlobFr
4600: 6f 6d 46 69 6c 65 28 29 3c 2f 62 3e 20 61 6e 64 omFile()</b> and
4610: 20 3c 62 3e 42 6c 6f 62 54 6f 46 69 6c 65 28 29 <b>BlobToFile()
4620: 3c 2f 62 3e 20 77 65 72 65 20 61 6c 72 65 61 64 </b> were alread
4630: 79 20 73 75 70 70 6f 72 74 65 64 20 62 79 20 34 y supported by 4
4640: 2e 30 2e 30 2c 20 62 75 74 20 61 20 71 75 69 63 .0.0, but a quic
4650: 6b 20 72 65 63 61 6c 6c 20 69 73 20 61 6e 79 77 k recall is anyw
4660: 61 79 20 75 73 65 66 75 6c 20 73 6f 20 74 6f 20 ay useful so to
4670: 72 65 63 61 6c 6c 20 61 20 63 6c 65 61 72 65 72 recall a clearer
4680: 20 63 6f 6e 74 65 78 74 2e 3c 62 72 3e 3c 62 72 context.<br><br
4690: 3e 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 >..<hr>..<verbat
46a0: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 58 42 5f 4c im>..SELECT XB_L
46b0: 6f 61 64 58 4d 4c 28 20 27 43 3a 2f 6d 79 64 6f oadXML( 'C:/mydo
46c0: 63 73 2f 69 73 6f 6d 65 74 61 64 61 74 61 2d 73 cs/isometadata-s
46d0: 61 6d 70 6c 65 2e 78 6d 6c 27 20 29 3b 0d 0a 2d ample.xml' );..-
46e0: 2d 2d 2d 2d 2d 2d 2d 0d 0a 42 4c 4f 42 2d 76 61 -------..BLOB-va
46f0: 6c 75 65 0d 0a 0d 0a 53 45 4c 45 43 54 20 58 42 lue....SELECT XB
4700: 5f 4c 6f 61 64 58 4d 4c 28 20 27 68 74 74 70 3a _LoadXML( 'http:
4710: 2f 2f 77 77 77 2e 61 63 6d 65 2e 63 6f 6d 2f 70 //www.acme.com/p
4720: 75 62 6c 69 63 2f 69 73 6f 6d 65 74 61 64 61 74 ublic/isometadat
4730: 61 2d 73 61 6d 70 6c 65 2e 78 6d 6c 27 20 29 3b a-sample.xml' );
4740: 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 42 4c 4f 42 ..--------..BLOB
4750: 2d 76 61 6c 75 65 0d 0a 3c 2f 76 65 72 62 61 74 -value..</verbat
4760: 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 58 42 5f 4c im>..The <b>XB_L
4770: 6f 61 64 58 4d 4c 28 29 3c 2f 62 3e 20 53 51 4c oadXML()</b> SQL
4780: 20 66 75 6e 63 74 69 6f 6e 20 61 6c 6c 6f 77 73 function allows
4790: 20 74 6f 20 69 6d 70 6f 72 74 20 61 6e 20 58 4d to import an XM
47a0: 4c 20 44 6f 63 75 6d 65 6e 74 20 69 6e 20 61 20 L Document in a
47b0: 73 69 6e 67 6c 65 20 73 74 65 70 3a 20 74 68 65 single step: the
47c0: 20 66 75 6c 6c 20 58 4d 4c 20 44 6f 63 75 6d 65 full XML Docume
47d0: 6e 74 20 70 61 79 6c 6f 61 64 20 77 69 6c 6c 20 nt payload will
47e0: 62 65 20 72 65 74 75 72 6e 65 64 20 61 73 20 61 be returned as a
47f0: 20 42 4c 4f 42 20 76 61 6c 75 65 2e 3c 62 72 3e BLOB value.<br>
4800: 0d 0a 54 68 65 20 70 61 73 73 65 64 20 61 72 67 ..The passed arg
4810: 75 6d 65 6e 74 20 63 61 6e 20 69 6e 64 69 66 66 ument can indiff
4820: 65 72 65 6e 74 6c 79 20 62 65 20 61 20 3c 62 3e erently be a <b>
4830: 66 69 6c 65 2d 70 61 74 68 3c 2f 62 3e 20 6f 72 file-path</b> or
4840: 20 61 20 3c 62 3e 55 52 4c 3c 2f 62 3e 3b 20 69 a <b>URL</b>; i
4850: 66 20 74 68 65 20 64 61 74 61 73 6f 75 72 63 65 f the datasource
4860: 20 63 61 6e 6e 6f 74 20 62 65 20 61 63 63 65 73 cannot be acces
4870: 73 65 64 2c 20 6f 72 20 69 66 20 69 74 20 64 6f sed, or if it do
4880: 65 73 6e 27 74 20 63 6f 6e 74 61 69 6e 73 20 61 esn't contains a
4890: 20 3c 75 3e 77 65 6c 6c 2d 66 6f 72 6d 65 64 3c <u>well-formed<
48a0: 2f 75 3e 20 58 4d 4c 20 44 6f 63 75 6d 65 6e 74 /u> XML Document
48b0: 20 4e 55 4c 4c 20 77 69 6c 6c 20 62 65 20 72 65 NULL will be re
48c0: 74 75 72 6e 65 64 2e 3c 62 72 3e 3c 62 72 3e 0d turned.<br><br>.
48d0: 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d .<hr>..<verbatim
48e0: 3e 0d 0a 53 45 4c 45 43 54 20 58 42 5f 53 74 6f >..SELECT XB_Sto
48f0: 72 65 58 4d 4c 28 20 73 6f 6d 65 58 6d 6c 42 6c reXML( someXmlBl
4900: 6f 62 2c 20 27 43 3a 2f 6d 79 64 6f 63 73 2f 69 ob, 'C:/mydocs/i
4910: 73 6f 6d 65 74 61 64 61 74 61 2d 73 61 6d 70 6c sometadata-sampl
4920: 65 2e 78 6d 6c 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d e.xml' );..-----
4930: 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 ----..1..</verba
4940: 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 58 42 5f tim>..The <b>XB_
4950: 53 74 6f 72 65 58 4d 4c 28 29 3c 2f 62 3e 20 53 StoreXML()</b> S
4960: 51 4c 20 66 75 6e 63 74 69 6f 6e 20 70 65 72 66 QL function perf
4970: 6f 72 6d 73 20 74 68 65 20 6f 70 70 6f 73 69 74 orms the opposit
4980: 65 20 74 61 73 6b 2c 20 69 2e 65 2e 20 69 74 20 e task, i.e. it
4990: 65 78 70 6f 72 74 73 20 61 20 77 68 6f 6c 65 20 exports a whole
49a0: 58 6d 6c 42 4c 4f 42 20 69 6e 74 6f 20 61 6e 20 XmlBLOB into an
49b0: 65 78 74 65 72 6e 61 6c 20 66 69 6c 65 20 61 73 external file as
49c0: 20 61 6e 20 58 4d 4c 20 44 6f 63 75 6d 65 6e 74 an XML Document
49d0: 3b 20 74 68 65 20 66 69 72 73 74 20 61 72 67 75 ; the first argu
49e0: 6d 65 6e 74 20 6d 75 73 74 20 63 6f 72 72 65 73 ment must corres
49f0: 70 6f 6e 64 20 74 6f 20 73 6f 6d 65 20 76 61 6c pond to some val
4a00: 69 64 20 58 6d 6c 42 4c 4f 42 2c 20 74 68 65 20 id XmlBLOB, the
4a10: 73 65 63 6f 6e 64 20 6f 6e 65 20 69 73 20 74 68 second one is th
4a20: 65 20 3c 62 3e 66 69 6c 65 2d 70 61 74 68 3c 2f e <b>file-path</
4a30: 62 3e 20 69 64 65 6e 74 69 66 79 69 6e 67 20 74 b> identifying t
4a40: 68 65 20 66 69 6c 65 20 74 6f 20 62 65 20 63 72 he file to be cr
4a50: 65 61 74 65 64 20 6f 72 20 6f 76 65 72 77 72 69 eated or overwri
4a60: 74 74 65 6e 2e 20 0d 0a 3c 76 65 72 62 61 74 69 tten. ..<verbati
4a70: 6d 3e 0d 0a 53 45 4c 45 43 54 20 58 42 5f 53 74 m>..SELECT XB_St
4a80: 6f 72 65 58 4d 4c 28 20 73 6f 6d 65 58 6d 6c 42 oreXML( someXmlB
4a90: 6c 6f 62 2c 20 27 43 3a 2f 6d 79 64 6f 63 73 2f lob, 'C:/mydocs/
4aa0: 69 73 6f 6d 65 74 61 64 61 74 61 2d 73 61 6d 70 isometadata-samp
4ab0: 6c 65 2e 78 6d 6c 27 2c 20 34 20 29 3b 0d 0a 2d le.xml', 4 );..-
4ac0: 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 --------..1..</v
4ad0: 65 72 62 61 74 69 6d 3e 0d 0a 41 20 66 75 72 74 erbatim>..A furt
4ae0: 68 65 72 20 6f 70 74 69 6f 6e 61 6c 20 3c 62 3e her optional <b>
4af0: 69 6e 64 65 6e 74 61 74 69 6f 6e 3c 2f 62 3e 20 indentation</b>
4b00: 61 72 67 75 6d 65 6e 74 20 63 61 6e 20 62 65 20 argument can be
4b10: 65 76 65 6e 74 75 61 6c 6c 79 20 73 70 65 63 69 eventually speci
4b20: 66 69 65 64 3b 20 74 68 69 73 20 61 72 67 75 6d fied; this argum
4b30: 65 6e 74 20 77 69 6c 6c 20 62 65 20 68 61 6e 64 ent will be hand
4b40: 6c 65 64 20 65 78 61 63 74 6c 79 20 69 6e 20 74 led exactly in t
4b50: 68 65 20 73 61 6d 65 20 77 61 79 20 61 6c 72 65 he same way alre
4b60: 61 64 79 20 73 70 65 63 69 66 69 65 64 20 66 6f ady specified fo
4b70: 72 20 62 6f 74 68 20 3c 62 3e 58 42 5f 47 65 74 r both <b>XB_Get
4b80: 50 61 79 6c 6f 61 64 28 29 3c 2f 62 3e 20 61 6e Payload()</b> an
4b90: 64 20 3c 62 3e 58 42 5f 47 65 74 44 6f 63 75 6d d <b>XB_GetDocum
4ba0: 65 6e 74 28 29 3c 2f 62 3e 20 66 75 6e 63 74 69 ent()</b> functi
4bb0: 6f 6e 73 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 ons.<br><br>..<h
4bc0: 72 3e 3c 62 72 3e 0d 0a 62 61 63 6b 20 74 6f 20 r><br>..back to
4bd0: 3c 61 20 68 72 65 66 3d 22 68 74 74 70 73 3a 2f <a href="https:/
4be0: 2f 77 77 77 2e 67 61 69 61 2d 67 69 73 2e 69 74 /www.gaia-gis.it
4bf0: 2f 66 6f 73 73 69 6c 2f 6c 69 62 73 70 61 74 69 /fossil/libspati
4c00: 61 6c 69 74 65 2f 77 69 6b 69 3f 6e 61 6d 65 3d alite/wiki?name=
4c10: 34 2e 31 2e 30 2d 64 6f 63 22 3e 34 2e 31 2e 30 4.1.0-doc">4.1.0
4c20: 2d 64 6f 63 3c 2f 61 3e 0a 5a 20 62 30 34 62 61 -doc</a>.Z b04ba
4c30: 37 36 36 65 31 39 35 35 35 65 62 37 30 37 65 38 766e19555eb707e8
4c40: 30 64 65 65 32 63 37 38 64 64 33 0a 0dee2c78dd3.