Wiki page
[4.1.0 Changes] by
sandro
2013-03-14 13:39:59.
0000: 44 20 32 30 31 33 2d 30 33 2d 31 34 54 31 33 3a D 2013-03-14T13:
0010: 33 39 3a 35 39 2e 30 39 39 0a 4c 20 34 2e 31 2e 39:59.099.L 4.1.
0020: 30 5c 73 43 68 61 6e 67 65 73 0a 50 20 63 30 35 0\sChanges.P c05
0030: 62 64 33 61 66 36 36 37 33 64 35 34 32 39 36 35 bd3af6673d542965
0040: 33 64 38 65 64 63 61 35 30 39 34 35 36 35 33 32 3d8edca509456532
0050: 65 36 39 61 30 0a 55 20 73 61 6e 64 72 6f 0a 57 e69a0.U sandro.W
0060: 20 31 39 34 33 39 0a 62 61 63 6b 20 74 6f 20 58 19439.back to X
0070: 6d 6c 42 6c 6f 62 20 3c 61 20 68 72 65 66 3d 22 mlBlob <a href="
0080: 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67 61 69 61 https://www.gaia
0090: 2d 67 69 73 2e 69 74 2f 66 6f 73 73 69 6c 2f 6c -gis.it/fossil/l
00a0: 69 62 73 70 61 74 69 61 6c 69 74 65 2f 77 69 6b ibspatialite/wik
00b0: 69 3f 6e 61 6d 65 3d 58 6d 6c 42 6c 6f 62 2b 61 i?name=XmlBlob+a
00c0: 6e 64 2b 56 69 72 74 75 61 6c 58 50 61 74 68 22 nd+VirtualXPath"
00d0: 3e 6d 61 69 6e 20 70 61 67 65 3c 2f 61 3e 0d 0a >main page</a>..
00e0: 3c 68 32 3e 4e 65 77 20 53 51 4c 20 66 75 6e 63 <h2>New SQL func
00f0: 74 69 6f 6e 73 20 69 6e 74 72 6f 64 75 63 65 64 tions introduced
0100: 20 69 6e 20 34 2e 31 2e 30 3c 2f 68 32 3e 0d 0a in 4.1.0</h2>..
0110: 54 61 62 6c 65 20 6f 66 20 63 6f 6e 74 65 6e 74 Table of content
0120: 73 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 53 51 s:..<ul>..<li>SQ
0130: 4c 20 66 75 6e 63 74 69 6f 6e 73 20 73 75 70 70 L functions supp
0140: 6f 72 74 69 6e 67 20 3c 61 20 68 72 65 66 3d 22 orting <a href="
0150: 23 63 61 73 74 22 3e 64 61 74 61 2d 74 79 70 65 #cast">data-type
0160: 20 63 61 73 74 69 6e 67 3c 2f 61 3e 3c 2f 6c 69 casting</a></li
0170: 3e 0d 0a 3c 6c 69 3e 53 51 4c 20 66 75 6e 63 74 >..<li>SQL funct
0180: 69 6f 6e 73 20 73 75 70 70 6f 72 74 69 6e 67 20 ions supporting
0190: 3c 61 20 68 72 65 66 3d 22 23 75 75 69 64 22 3e <a href="#uuid">
01a0: 55 55 49 44 20 67 65 6e 65 72 61 74 69 6f 6e 3c UUID generation<
01b0: 2f 61 3e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 53 70 /a></li>..<li>Sp
01c0: 61 74 69 61 6c 20 53 51 4c 20 66 75 6e 63 74 69 atial SQL functi
01d0: 6f 6e 73 20 73 75 70 70 6f 72 74 69 6e 67 20 3c ons supporting <
01e0: 61 20 68 72 65 66 3d 22 23 67 65 6f 6d 22 3e 47 a href="#geom">G
01f0: 65 6f 6d 65 74 72 69 65 73 3c 2f 61 3e 3c 2f 6c eometries</a></l
0200: 69 3e 0d 0a 3c 6c 69 3e 53 51 4c 20 66 75 6e 63 i>..<li>SQL func
0210: 74 69 6f 6e 73 20 73 75 70 70 6f 72 74 69 6e 67 tions supporting
0220: 20 3c 61 20 68 72 65 66 3d 22 23 75 6e 73 61 66 <a href="#unsaf
0230: 65 22 3e 75 6e 73 61 66 65 3c 2f 61 3e 20 64 69 e">unsafe</a> di
0240: 72 65 63 74 20 49 6d 70 6f 72 74 2f 45 78 70 6f rect Import/Expo
0250: 72 74 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a rt</li>..</ul>..
0260: 3c 68 33 3e 3c 61 20 6e 61 6d 65 3d 22 67 65 6e <h3><a name="gen
0270: 65 72 69 63 22 3e 63 61 73 74 3c 2f 61 3e 20 53 eric">cast</a> S
0280: 51 4c 20 66 75 6e 63 74 69 6f 6e 73 20 2d 20 74 QL functions - t
0290: 79 70 65 20 63 61 73 74 69 6e 67 3c 2f 68 33 3e ype casting</h3>
02a0: 0d 0a 53 51 4c 69 74 65 20 6f 66 66 65 72 73 20 ..SQLite offers
02b0: 6a 75 73 74 20 61 20 76 65 72 79 20 62 61 73 69 just a very basi
02c0: 63 20 74 79 70 65 20 63 68 65 63 6b 69 6e 67 3b c type checking;
02d0: 20 74 68 69 73 20 69 73 20 73 6f 6d 65 74 69 6d this is sometim
02e0: 65 73 20 75 73 65 66 75 6c 2c 20 62 75 74 20 63 es useful, but c
02f0: 6f 75 6c 64 20 62 65 20 72 65 61 6c 6c 79 20 61 ould be really a
0300: 6e 6e 6f 79 69 6e 67 20 76 65 72 79 20 6f 66 74 nnoying very oft
0310: 65 6e 2e 3c 62 72 3e 0d 0a 3c 76 65 72 62 61 74 en.<br>..<verbat
0320: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 27 31 27 2c im>..SELECT '1',
0330: 20 54 79 70 65 4f 66 28 20 27 31 27 20 29 2c 20 TypeOf( '1' ),
0340: 43 41 53 54 20 28 20 27 31 27 20 41 53 20 49 4e CAST ( '1' AS IN
0350: 54 45 47 45 52 20 29 2c 20 54 79 70 65 4f 66 28 TEGER ), TypeOf(
0360: 20 43 41 53 54 20 28 20 27 31 27 20 41 53 20 49 CAST ( '1' AS I
0370: 4e 54 45 47 45 52 20 29 20 29 3b 0d 0a 3c 2f 76 NTEGER ) );..</v
0380: 65 72 62 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c 65 erbatim>..<table
0390: 20 62 6f 72 64 65 72 3d 22 31 22 20 63 65 6c 6c border="1" cell
03a0: 73 70 61 63 69 6e 67 3d 22 34 22 20 63 65 6c 6c spacing="4" cell
03b0: 70 61 64 64 69 6e 67 3d 22 34 22 3e 0d 0a 3c 74 padding="4">..<t
03c0: 72 3e 3c 74 68 3e 27 31 27 3c 2f 74 68 3e 3c 74 r><th>'1'</th><t
03d0: 68 3e 54 79 70 65 4f 66 28 20 27 31 27 20 29 3c h>TypeOf( '1' )<
03e0: 2f 74 68 3e 3c 74 68 3e 43 41 53 54 20 28 20 27 /th><th>CAST ( '
03f0: 31 27 20 41 53 20 49 4e 54 45 47 45 52 20 29 3c 1' AS INTEGER )<
0400: 2f 74 68 3e 3c 74 68 3e 54 79 70 65 4f 66 28 20 /th><th>TypeOf(
0410: 43 41 53 54 20 28 20 27 31 27 20 41 53 20 49 4e CAST ( '1' AS IN
0420: 54 45 47 45 52 20 29 20 29 3c 2f 74 68 3e 3c 2f TEGER ) )</th></
0430: 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 31 3c 2f tr>..<tr><td>1</
0440: 74 64 3e 3c 74 64 3e 74 65 78 74 3c 2f 74 64 3e td><td>text</td>
0450: 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 <td align="right
0460: 22 3e 31 3c 2f 74 64 3e 3c 74 64 3e 69 6e 74 65 ">1</td><td>inte
0470: 67 65 72 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 ger</td></tr></t
0480: 61 62 6c 65 3e 3c 62 72 3e 0d 0a 54 68 65 20 53 able><br>..The S
0490: 51 4c 20 3c 62 3e 43 41 53 54 3c 2f 62 3e 20 6f QL <b>CAST</b> o
04a0: 70 65 72 61 74 6f 72 20 61 6c 72 65 61 64 79 20 perator already
04b0: 73 75 70 70 6f 72 74 73 20 74 68 65 20 70 6f 73 supports the pos
04c0: 73 69 62 69 6c 69 74 79 20 74 6f 20 65 78 70 6c sibility to expl
04d0: 69 63 69 74 6c 79 20 73 65 74 20 61 20 64 61 74 icitly set a dat
04e0: 61 2d 74 79 70 65 3b 20 6e 6f 77 20 73 74 61 72 a-type; now star
04f0: 74 69 6e 67 20 73 69 6e 63 65 20 34 2e 31 2e 30 ting since 4.1.0
0500: 20 53 70 61 74 69 61 4c 69 74 65 20 73 75 70 70 SpatiaLite supp
0510: 6f 72 74 73 20 66 65 77 20 53 51 4c 20 66 75 6e orts few SQL fun
0520: 63 74 69 6f 6e 73 20 70 65 72 66 6f 72 6d 69 6e ctions performin
0530: 67 20 74 68 65 20 73 61 6d 65 20 74 61 73 6b 2e g the same task.
0540: 3c 62 72 3e 0d 0a 3c 75 3e 50 6c 65 61 73 65 20 <br>..<u>Please
0550: 6e 6f 74 65 3c 2f 75 3e 3a 20 73 6f 6d 65 20 73 note</u>: some s
0560: 75 62 74 6c 65 20 64 69 66 66 65 72 65 6e 63 65 ubtle difference
0570: 73 20 65 78 69 73 74 73 20 68 65 72 65 20 61 6e s exists here an
0580: 64 20 74 68 65 72 65 3b 20 70 6c 65 61 73 65 20 d there; please
0590: 63 61 72 65 66 75 6c 6c 79 20 72 65 61 64 20 74 carefully read t
05a0: 68 69 73 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f his documentatio
05b0: 6e 20 70 61 67 65 2e 0d 0a 3c 76 65 72 62 61 74 n page...<verbat
05c0: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 43 61 73 74 im>..SELECT Cast
05d0: 54 6f 49 6e 74 65 67 65 72 28 20 31 20 29 2c 20 ToInteger( 1 ),
05e0: 43 61 73 74 54 6f 49 6e 74 65 67 65 72 28 20 31 CastToInteger( 1
05f0: 2e 34 20 29 2c 20 43 61 73 74 54 6f 49 6e 74 65 .4 ), CastToInte
0600: 67 65 72 28 20 31 2e 36 20 29 2c 20 0d 0a 20 20 ger( 1.6 ), ..
0610: 20 20 43 61 73 74 54 6f 49 6e 74 65 67 65 72 28 CastToInteger(
0620: 20 27 31 32 33 27 20 29 2c 20 43 61 73 74 54 6f '123' ), CastTo
0630: 49 6e 74 65 67 65 72 28 20 27 61 6c 70 68 61 27 Integer( 'alpha'
0640: 20 29 2c 20 43 61 73 74 54 6f 49 6e 74 65 67 65 ), CastToIntege
0650: 72 20 28 20 7a 65 72 6f 62 6c 6f 62 28 34 29 20 r ( zeroblob(4)
0660: 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d );..</verbatim>.
0670: 0a 3c 74 61 62 6c 65 20 62 6f 72 64 65 72 3d 22 .<table border="
0680: 31 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 1" cellspacing="
0690: 34 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 4" cellpadding="
06a0: 34 22 3e 0d 0a 3c 74 72 3e 3c 74 68 3e 43 61 73 4">..<tr><th>Cas
06b0: 74 54 6f 49 6e 74 65 67 65 72 28 20 31 20 29 3c tToInteger( 1 )<
06c0: 2f 74 68 3e 3c 74 68 3e 43 61 73 74 54 6f 49 6e /th><th>CastToIn
06d0: 74 65 67 65 72 28 20 31 2e 34 20 29 3c 2f 74 68 teger( 1.4 )</th
06e0: 3e 3c 74 68 3e 43 61 73 74 54 6f 49 6e 74 65 67 ><th>CastToInteg
06f0: 65 72 28 20 31 2e 36 20 29 3c 2f 74 68 3e 3c 74 er( 1.6 )</th><t
0700: 68 3e 43 61 73 74 54 6f 49 6e 74 65 67 65 72 28 h>CastToInteger(
0710: 20 27 31 32 33 27 20 29 3c 2f 74 68 3e 3c 74 68 '123' )</th><th
0720: 3e 43 61 73 74 54 6f 49 6e 74 65 67 65 72 28 20 >CastToInteger(
0730: 27 61 6c 70 68 61 27 20 29 3c 2f 74 68 3e 3c 74 'alpha' )</th><t
0740: 68 3e 43 61 73 74 54 6f 49 6e 74 65 67 65 72 20 h>CastToInteger
0750: 28 20 7a 65 72 6f 62 6c 6f 62 28 34 29 20 29 3c ( zeroblob(4) )<
0760: 2f 74 68 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c /th></tr>..<tr><
0770: 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 td align="right"
0780: 3e 31 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e >1</td><td align
0790: 3d 22 72 69 67 68 74 22 3e 31 3c 2f 74 64 3e 3c ="right">1</td><
07a0: 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 td align="right"
07b0: 3e 32 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e >2</td><td align
07c0: 3d 22 72 69 67 68 74 22 3e 31 32 33 3c 2f 74 64 ="right">123</td
07d0: 3e 3c 74 64 3e 4e 55 4c 4c 3c 2f 74 64 3e 3c 74 ><td>NULL</td><t
07e0: 64 3e 4e 55 4c 4c 3c 2f 74 64 3e 3c 2f 74 72 3e d>NULL</td></tr>
07f0: 3c 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 54 68 </table><br>..Th
0800: 65 20 3c 62 3e 43 61 73 74 54 6f 49 6e 74 65 67 e <b>CastToInteg
0810: 65 72 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e er()</b> SQL fun
0820: 63 74 69 6f 6e 20 77 69 6c 6c 20 61 74 74 65 6d ction will attem
0830: 70 74 20 74 6f 20 72 65 74 75 72 6e 20 61 20 76 pt to return a v
0840: 61 6c 75 65 20 6f 66 20 74 68 65 20 3c 62 3e 49 alue of the <b>I
0850: 6e 74 65 67 65 72 3c 2f 62 3e 20 64 61 74 61 2d nteger</b> data-
0860: 74 79 70 65 2c 20 6f 72 20 3c 62 3e 4e 55 4c 4c type, or <b>NULL
0870: 3c 2f 62 3e 20 69 66 20 6e 6f 20 63 6f 6e 76 65 </b> if no conve
0880: 72 73 69 6f 6e 20 69 73 20 70 6f 73 73 69 62 6c rsion is possibl
0890: 65 2e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 6e e...<ul>..<li>an
08a0: 20 49 6e 74 65 67 65 72 20 69 6e 70 75 74 20 61 Integer input a
08b0: 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 62 65 20 rgument will be
08c0: 72 65 74 75 72 6e 65 64 20 61 62 73 6f 6c 75 74 returned absolut
08d0: 65 6c 79 20 75 6e 61 66 66 65 63 74 65 64 2e 3c ely unaffected.<
08e0: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 44 6f 75 62 /li>..<li>a Doub
08f0: 6c 65 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e le input argumen
0900: 74 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 74 68 t will return th
0910: 65 20 3c 75 3e 6e 65 61 72 65 73 74 3c 2f 75 3e e <u>nearest</u>
0920: 20 49 6e 74 65 67 65 72 20 76 61 6c 75 65 20 28 Integer value (
0930: 61 66 74 65 72 20 61 70 70 6c 79 69 6e 67 20 3c after applying <
0940: 62 3e 34 2f 35 3c 2f 62 3e 20 72 6f 75 6e 64 69 b>4/5</b> roundi
0950: 6e 67 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 ng).</li>..<li>a
0960: 20 54 65 78 74 20 69 6e 70 75 74 20 61 72 67 75 Text input argu
0970: 6d 65 6e 74 20 77 69 6c 6c 20 72 65 74 75 72 6e ment will return
0980: 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 the correspondi
0990: 6e 67 20 49 6e 74 65 67 65 72 20 76 61 6c 75 65 ng Integer value
09a0: 20 6f 6e 6c 79 20 69 66 20 74 68 65 20 74 65 78 only if the tex
09b0: 74 20 73 74 72 69 6e 67 20 72 65 70 72 65 73 65 t string represe
09c0: 6e 74 73 20 61 20 76 61 6c 69 64 20 6e 75 6d 62 nts a valid numb
09d0: 65 72 20 28 65 76 65 6e 20 61 20 64 65 63 69 6d er (even a decim
09e0: 61 6c 20 6f 6e 65 29 3a 20 69 66 20 74 68 65 20 al one): if the
09f0: 74 65 78 74 20 73 74 72 69 6e 67 20 63 61 6e 6e text string cann
0a00: 6f 74 20 62 65 20 63 6f 6e 76 65 72 74 65 64 20 ot be converted
0a10: 74 6f 20 61 20 6e 75 6d 62 65 72 20 4e 55 4c 4c to a number NULL
0a20: 20 77 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 will be returne
0a30: 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 d.</li>..<li>any
0a40: 20 42 4c 4f 42 20 69 6e 70 75 74 20 61 72 67 75 BLOB input argu
0a50: 6d 65 6e 74 20 77 69 6c 6c 20 72 65 74 75 72 6e ment will return
0a60: 20 61 20 4e 55 4c 4c 20 76 61 6c 75 65 2e 3c 2f a NULL value.</
0a70: 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 4e 55 4c li>..<li>any NUL
0a80: 4c 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 L input argument
0a90: 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 61 20 4e will return a N
0aa0: 55 4c 4c 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d ULL value.</li>.
0ab0: 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d 0a 3c 68 72 3e .</ul><br>..<hr>
0ac0: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 ..<verbatim>..SE
0ad0: 4c 45 43 54 20 43 61 73 74 54 6f 44 6f 75 62 6c LECT CastToDoubl
0ae0: 65 28 20 31 20 29 2c 20 43 61 73 74 54 6f 44 6f e( 1 ), CastToDo
0af0: 75 62 6c 65 28 20 31 2e 32 33 20 29 2c 20 43 61 uble( 1.23 ), Ca
0b00: 73 74 54 6f 44 6f 75 62 6c 65 28 20 27 31 32 33 stToDouble( '123
0b10: 2e 34 35 27 20 29 2c 0d 0a 20 20 20 20 43 61 73 .45' ),.. Cas
0b20: 74 54 6f 44 6f 75 62 6c 65 28 20 27 61 6c 70 68 tToDouble( 'alph
0b30: 61 27 20 29 2c 20 43 61 73 74 54 6f 44 6f 75 62 a' ), CastToDoub
0b40: 6c 65 20 28 20 7a 65 72 6f 62 6c 6f 62 28 34 29 le ( zeroblob(4)
0b50: 20 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e );..</verbatim>
0b60: 0d 0a 3c 74 61 62 6c 65 20 62 6f 72 64 65 72 3d ..<table border=
0b70: 22 31 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d "1" cellspacing=
0b80: 22 34 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d "4" cellpadding=
0b90: 22 34 22 3e 0d 0a 3c 74 72 3e 3c 74 68 3e 43 61 "4">..<tr><th>Ca
0ba0: 73 74 54 6f 44 6f 75 62 6c 65 28 20 31 20 29 3c stToDouble( 1 )<
0bb0: 2f 74 68 3e 3c 74 68 3e 43 61 73 74 54 6f 44 6f /th><th>CastToDo
0bc0: 75 62 6c 65 28 20 31 2e 32 33 20 29 3c 2f 74 68 uble( 1.23 )</th
0bd0: 3e 3c 74 68 3e 43 61 73 74 54 6f 44 6f 75 62 6c ><th>CastToDoubl
0be0: 65 28 20 27 31 32 33 2e 34 35 27 20 29 3c 2f 74 e( '123.45' )</t
0bf0: 68 3e 3c 74 68 3e 43 61 73 74 54 6f 44 6f 75 62 h><th>CastToDoub
0c00: 6c 65 28 20 27 61 6c 70 68 61 27 20 29 3c 2f 74 le( 'alpha' )</t
0c10: 68 3e 3c 74 68 3e 43 61 73 74 54 6f 44 6f 75 62 h><th>CastToDoub
0c20: 6c 65 20 28 20 7a 65 72 6f 62 6c 6f 62 28 34 29 le ( zeroblob(4)
0c30: 20 29 3c 2f 74 68 3e 3c 2f 74 72 3e 0d 0a 3c 74 )</th></tr>..<t
0c40: 72 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 r><td align="rig
0c50: 68 74 22 3e 31 2e 30 30 30 30 30 30 3c 2f 74 64 ht">1.000000</td
0c60: 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 ><td align="righ
0c70: 74 22 3e 31 2e 32 33 30 30 30 30 3c 2f 74 64 3e t">1.230000</td>
0c80: 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 <td align="right
0c90: 22 3e 31 32 33 2e 34 35 30 30 30 3c 2f 74 64 3e ">123.45000</td>
0ca0: 3c 74 64 3e 4e 55 4c 4c 3c 2f 74 64 3e 3c 74 64 <td>NULL</td><td
0cb0: 3e 4e 55 4c 4c 3c 2f 74 64 3e 3c 2f 74 72 3e 3c >NULL</td></tr><
0cc0: 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 54 68 65 /table><br>..The
0cd0: 20 3c 62 3e 43 61 73 74 54 6f 44 6f 75 62 6c 65 <b>CastToDouble
0ce0: 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 ()</b> SQL funct
0cf0: 69 6f 6e 20 77 69 6c 6c 20 61 74 74 65 6d 70 74 ion will attempt
0d00: 20 74 6f 20 72 65 74 75 72 6e 20 61 20 76 61 6c to return a val
0d10: 75 65 20 6f 66 20 74 68 65 20 3c 62 3e 44 6f 75 ue of the <b>Dou
0d20: 62 6c 65 3c 2f 62 3e 20 64 61 74 61 2d 74 79 70 ble</b> data-typ
0d30: 65 2c 20 6f 72 20 3c 62 3e 4e 55 4c 4c 3c 2f 62 e, or <b>NULL</b
0d40: 3e 20 69 66 20 6e 6f 20 63 6f 6e 76 65 72 73 69 > if no conversi
0d50: 6f 6e 20 69 73 20 70 6f 73 73 69 62 6c 65 2e 0d on is possible..
0d60: 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 6e 20 49 6e .<ul>..<li>an In
0d70: 74 65 67 65 72 20 69 6e 70 75 74 20 61 72 67 75 teger input argu
0d80: 6d 65 6e 74 20 77 69 6c 6c 20 72 65 74 75 72 6e ment will return
0d90: 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 the correspondi
0da0: 6e 67 20 44 6f 75 62 6c 65 20 76 61 6c 75 65 2e ng Double value.
0db0: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 44 6f 75 </li>..<li>a Dou
0dc0: 62 6c 65 20 69 6e 70 75 74 20 61 72 67 75 6d 65 ble input argume
0dd0: 6e 74 20 77 69 6c 6c 20 62 65 20 72 65 74 75 72 nt will be retur
0de0: 6e 65 64 20 61 62 73 6f 6c 75 74 65 6c 79 20 75 ned absolutely u
0df0: 6e 61 66 66 65 63 74 65 64 2e 3c 2f 6c 69 3e 0d naffected.</li>.
0e00: 0a 3c 6c 69 3e 61 20 54 65 78 74 20 69 6e 70 75 .<li>a Text inpu
0e10: 74 20 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 t argument will
0e20: 72 65 74 75 72 6e 20 74 68 65 20 63 6f 72 72 65 return the corre
0e30: 73 70 6f 6e 64 69 6e 67 20 44 6f 75 62 6c 65 20 sponding Double
0e40: 76 61 6c 75 65 20 6f 6e 6c 79 20 69 66 20 74 68 value only if th
0e50: 65 20 74 65 78 74 20 73 74 72 69 6e 67 20 72 65 e text string re
0e60: 70 72 65 73 65 6e 74 73 20 61 20 76 61 6c 69 64 presents a valid
0e70: 20 6e 75 6d 62 65 72 3a 20 69 66 20 74 68 65 20 number: if the
0e80: 74 65 78 74 20 73 74 72 69 6e 67 20 63 61 6e 6e text string cann
0e90: 6f 74 20 62 65 20 63 6f 6e 76 65 72 74 65 64 20 ot be converted
0ea0: 74 6f 20 61 20 6e 75 6d 62 65 72 20 4e 55 4c 4c to a number NULL
0eb0: 20 77 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 will be returne
0ec0: 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 d.</li>..<li>any
0ed0: 20 42 4c 4f 42 20 69 6e 70 75 74 20 61 72 67 75 BLOB input argu
0ee0: 6d 65 6e 74 20 77 69 6c 6c 20 72 65 74 75 72 6e ment will return
0ef0: 20 61 20 4e 55 4c 4c 20 76 61 6c 75 65 2e 3c 2f a NULL value.</
0f00: 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 4e 55 4c li>..<li>any NUL
0f10: 4c 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 L input argument
0f20: 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 61 20 4e will return a N
0f30: 55 4c 4c 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d ULL value.</li>.
0f40: 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d 0a 3c 68 72 3e .</ul><br>..<hr>
0f50: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 ..<verbatim>..SE
0f60: 4c 45 43 54 20 43 61 73 74 54 6f 54 65 78 74 28 LECT CastToText(
0f70: 20 31 20 29 2c 20 43 61 73 74 54 6f 54 65 78 74 1 ), CastToText
0f80: 28 20 31 2e 35 20 29 2c 20 43 61 73 74 54 6f 54 ( 1.5 ), CastToT
0f90: 65 78 74 28 20 27 61 6c 70 68 61 27 20 29 2c 20 ext( 'alpha' ),
0fa0: 43 61 73 74 54 6f 54 65 78 74 20 28 20 7a 65 72 CastToText ( zer
0fb0: 6f 62 6c 6f 62 28 34 29 20 29 3b 0d 0a 3c 2f 76 oblob(4) );..</v
0fc0: 65 72 62 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c 65 erbatim>..<table
0fd0: 20 62 6f 72 64 65 72 3d 22 31 22 20 63 65 6c 6c border="1" cell
0fe0: 73 70 61 63 69 6e 67 3d 22 34 22 20 63 65 6c 6c spacing="4" cell
0ff0: 70 61 64 64 69 6e 67 3d 22 34 22 3e 0d 0a 3c 74 padding="4">..<t
1000: 72 3e 3c 74 68 3e 43 61 73 74 54 6f 54 65 78 74 r><th>CastToText
1010: 28 20 31 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 61 ( 1 )</th><th>Ca
1020: 73 74 54 6f 54 65 78 74 28 20 31 2e 35 20 29 3c stToText( 1.5 )<
1030: 2f 74 68 3e 3c 74 68 3e 43 61 73 74 54 6f 54 65 /th><th>CastToTe
1040: 78 74 28 20 27 61 6c 70 68 61 27 20 29 3c 2f 74 xt( 'alpha' )</t
1050: 68 3e 3c 74 68 3e 43 61 73 74 54 6f 54 65 78 74 h><th>CastToText
1060: 20 28 20 7a 65 72 6f 62 6c 6f 62 28 34 29 20 29 ( zeroblob(4) )
1070: 3c 2f 74 68 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e </th></tr>..<tr>
1080: 3c 74 64 3e 31 3c 2f 74 64 3e 3c 74 64 3e 31 2e <td>1</td><td>1.
1090: 35 3c 2f 74 64 3e 3c 74 64 3e 61 6c 70 68 61 3c 5</td><td>alpha<
10a0: 2f 74 64 3e 3c 74 64 3e 4e 55 4c 4c 3c 2f 74 64 /td><td>NULL</td
10b0: 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 3c 62 ></tr></table><b
10c0: 72 3e 0d 0a 54 68 65 20 3c 62 3e 43 61 73 74 54 r>..The <b>CastT
10d0: 6f 54 65 78 74 28 29 3c 2f 62 3e 20 53 51 4c 20 oText()</b> SQL
10e0: 66 75 6e 63 74 69 6f 6e 20 77 69 6c 6c 20 61 74 function will at
10f0: 74 65 6d 70 74 20 74 6f 20 72 65 74 75 72 6e 20 tempt to return
1100: 61 20 76 61 6c 75 65 20 6f 66 20 74 68 65 20 3c a value of the <
1110: 62 3e 54 65 78 74 3c 2f 62 3e 20 64 61 74 61 2d b>Text</b> data-
1120: 74 79 70 65 2c 20 6f 72 20 3c 62 3e 4e 55 4c 4c type, or <b>NULL
1130: 3c 2f 62 3e 20 69 66 20 6e 6f 20 63 6f 6e 76 65 </b> if no conve
1140: 72 73 69 6f 6e 20 69 73 20 70 6f 73 73 69 62 6c rsion is possibl
1150: 65 2e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 6e e...<ul>..<li>an
1160: 20 49 6e 74 65 67 65 72 20 69 6e 70 75 74 20 61 Integer input a
1170: 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 72 65 74 rgument will ret
1180: 75 72 6e 20 74 68 65 20 63 6f 72 72 65 73 70 6f urn the correspo
1190: 6e 64 69 6e 67 20 54 65 78 74 20 76 61 6c 75 65 nding Text value
11a0: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 44 6f .</li>..<li>a Do
11b0: 75 62 6c 65 20 69 6e 70 75 74 20 61 72 67 75 6d uble input argum
11c0: 65 6e 74 20 77 69 6c 6c 20 62 65 20 72 65 74 75 ent will be retu
11d0: 72 6e 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e rn the correspon
11e0: 64 69 6e 67 20 54 65 78 74 20 76 61 6c 75 65 3b ding Text value;
11f0: 20 6e 6f 20 73 69 67 6e 69 66 69 63 61 6e 74 20 no significant
1200: 64 65 63 69 6d 61 6c 20 64 69 67 69 74 20 77 69 decimal digit wi
1210: 6c 6c 20 62 65 20 73 75 70 70 72 65 73 73 65 64 ll be suppressed
1220: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 54 65 .</li>..<li>a Te
1230: 78 74 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e xt input argumen
1240: 74 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 74 68 t will return th
1250: 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 e corresponding
1260: 44 6f 75 62 6c 65 20 76 61 6c 75 65 2e 3c 2f 6c Double value.</l
1270: 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 42 4c 4f 42 i>..<li>any BLOB
1280: 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 input argument
1290: 77 69 6c 6c 20 72 65 74 75 72 6e 20 61 20 4e 55 will return a NU
12a0: 4c 4c 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a LL value.</li>..
12b0: 3c 6c 69 3e 61 6e 79 20 4e 55 4c 4c 20 69 6e 70 <li>any NULL inp
12c0: 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c ut argument will
12d0: 20 72 65 74 75 72 6e 20 61 20 4e 55 4c 4c 20 76 return a NULL v
12e0: 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c alue.</li>..</ul
12f0: 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 >..<verbatim>..S
1300: 45 4c 45 43 54 20 43 61 73 74 54 6f 54 65 78 74 ELECT CastToText
1310: 28 20 31 2c 20 34 20 29 2c 20 43 61 73 74 54 6f ( 1, 4 ), CastTo
1320: 54 65 78 74 28 20 31 32 33 34 2c 20 32 20 29 2c Text( 1234, 2 ),
1330: 20 43 61 73 74 54 6f 54 65 78 74 28 20 31 2c 20 CastToText( 1,
1340: 38 20 29 2c 20 43 61 73 74 54 6f 54 65 78 74 28 8 ), CastToText(
1350: 20 31 2e 35 2c 20 34 20 29 3b 0d 0a 3c 2f 76 65 1.5, 4 );..</ve
1360: 72 62 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c 65 20 rbatim>..<table
1370: 62 6f 72 64 65 72 3d 22 31 22 20 63 65 6c 6c 73 border="1" cells
1380: 70 61 63 69 6e 67 3d 22 34 22 20 63 65 6c 6c 70 pacing="4" cellp
1390: 61 64 64 69 6e 67 3d 22 34 22 3e 0d 0a 3c 74 72 adding="4">..<tr
13a0: 3e 3c 74 68 3e 43 61 73 74 54 6f 54 65 78 74 28 ><th>CastToText(
13b0: 20 31 2c 20 34 20 29 3c 2f 74 68 3e 3c 74 68 3e 1, 4 )</th><th>
13c0: 43 61 73 74 54 6f 54 65 78 74 28 20 31 32 33 34 CastToText( 1234
13d0: 2c 20 32 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 61 , 2 )</th><th>Ca
13e0: 73 74 54 6f 54 65 78 74 28 20 31 2c 20 38 20 29 stToText( 1, 8 )
13f0: 3c 2f 74 68 3e 3c 74 68 3e 43 61 73 74 54 6f 54 </th><th>CastToT
1400: 65 78 74 28 20 31 2e 35 2c 20 34 20 29 3c 2f 74 ext( 1.5, 4 )</t
1410: 68 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 h></tr>..<tr><td
1420: 3e 30 30 30 31 3c 2f 74 64 3e 3c 74 64 3e 31 32 >0001</td><td>12
1430: 33 34 3c 2f 74 64 3e 3c 74 64 3e 30 30 30 30 30 34</td><td>00000
1440: 30 30 31 3c 2f 74 64 3e 3c 74 64 3e 30 30 30 31 001</td><td>0001
1450: 2e 35 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 .5</td></tr></ta
1460: 62 6c 65 3e 3c 62 72 3e 0d 0a 41 6e 20 6f 76 65 ble><br>..An ove
1470: 72 6c 6f 61 64 65 64 20 76 65 72 73 69 6f 6e 20 rloaded version
1480: 6f 66 20 3c 62 3e 43 61 73 74 54 6f 54 65 78 74 of <b>CastToText
1490: 28 29 3c 2f 62 3e 20 69 73 20 73 75 70 70 6f 72 ()</b> is suppor
14a0: 74 65 64 20 61 73 20 77 65 6c 6c 2c 20 62 75 74 ted as well, but
14b0: 20 6f 6e 6c 79 20 77 68 65 6e 20 74 68 65 20 69 only when the i
14c0: 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 69 73 nput argument is
14d0: 20 6f 66 20 74 68 65 20 49 6e 74 65 67 65 72 20 of the Integer
14e0: 6f 72 20 44 6f 75 62 6c 65 20 64 61 74 61 2d 74 or Double data-t
14f0: 79 70 65 3a 20 69 6e 20 74 68 69 73 20 63 61 73 ype: in this cas
1500: 65 20 61 20 73 65 63 6f 6e 64 20 49 6e 74 65 67 e a second Integ
1510: 65 72 20 61 72 67 75 6d 65 6e 74 20 63 6f 75 6c er argument coul
1520: 64 20 62 65 20 6f 70 74 69 6f 6e 61 6c 6c 79 20 d be optionally
1530: 73 70 65 63 69 66 69 65 64 2c 20 61 6e 64 20 77 specified, and w
1540: 69 6c 6c 20 62 65 20 69 6e 74 65 72 70 72 65 74 ill be interpret
1550: 65 64 20 61 64 20 3c 62 3e 7a 65 72 6f 2d 70 61 ed ad <b>zero-pa
1560: 64 64 69 6e 67 2d 6c 65 6e 67 74 68 3c 2f 62 3e dding-length</b>
1570: 2e 3c 62 72 3e 0d 0a 69 2e 65 2e 20 74 68 65 20 .<br>..i.e. the
1580: 72 65 74 75 72 6e 65 64 20 54 65 78 74 20 73 74 returned Text st
1590: 72 69 6e 67 20 69 6e 20 74 68 69 73 20 63 61 73 ring in this cas
15a0: 65 20 77 69 6c 6c 20 68 61 76 65 20 61 6e 20 69 e will have an i
15b0: 6e 74 65 67 65 72 20 70 61 72 74 20 61 74 20 6c nteger part at l
15c0: 65 61 73 74 20 6f 66 20 74 68 65 20 73 70 65 63 east of the spec
15d0: 69 66 69 65 64 20 6c 65 6e 67 74 68 2c 20 61 6e ified length, an
15e0: 64 20 65 76 65 6e 74 75 61 6c 6c 79 20 70 61 64 d eventually pad
15f0: 64 65 64 20 62 79 20 69 6e 73 65 72 74 69 6e 67 ded by inserting
1600: 20 6e 6f 74 20 73 69 67 6e 69 66 69 63 61 6e 74 not significant
1610: 20 6c 65 61 64 69 6e 67 20 5a 45 52 4f 65 73 2e leading ZEROes.
1620: 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a <br><br>..<hr>..
1630: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 <verbatim>..SELE
1640: 43 54 20 43 61 73 74 54 6f 42 6c 6f 62 28 20 31 CT CastToBlob( 1
1650: 20 29 2c 20 43 61 73 74 54 6f 42 6c 6f 62 28 20 ), CastToBlob(
1660: 31 2e 35 20 29 2c 20 48 65 78 28 20 43 61 73 74 1.5 ), Hex( Cast
1670: 54 6f 42 6c 6f 62 28 20 27 61 6c 70 68 61 27 20 ToBlob( 'alpha'
1680: 29 20 29 2c 20 48 65 78 20 28 20 43 61 73 74 54 ) ), Hex ( CastT
1690: 6f 42 6c 6f 62 20 28 20 7a 65 72 6f 62 6c 6f 62 oBlob ( zeroblob
16a0: 28 34 29 20 29 20 29 3b 0d 0a 3c 2f 76 65 72 62 (4) ) );..</verb
16b0: 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c 65 20 62 6f atim>..<table bo
16c0: 72 64 65 72 3d 22 31 22 20 63 65 6c 6c 73 70 61 rder="1" cellspa
16d0: 63 69 6e 67 3d 22 34 22 20 63 65 6c 6c 70 61 64 cing="4" cellpad
16e0: 64 69 6e 67 3d 22 34 22 3e 0d 0a 3c 74 72 3e 3c ding="4">..<tr><
16f0: 74 68 3e 43 61 73 74 54 6f 42 6c 6f 62 28 20 31 th>CastToBlob( 1
1700: 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 61 73 74 54 )</th><th>CastT
1710: 6f 42 6c 6f 62 28 20 31 2e 35 20 29 3c 2f 74 68 oBlob( 1.5 )</th
1720: 3e 3c 74 68 3e 48 65 78 28 20 43 61 73 74 54 6f ><th>Hex( CastTo
1730: 42 6c 6f 62 28 20 27 61 6c 70 68 61 27 20 29 20 Blob( 'alpha' )
1740: 29 3c 2f 74 68 3e 3c 74 68 3e 48 65 78 28 20 43 )</th><th>Hex( C
1750: 61 73 74 54 6f 54 65 78 74 20 28 20 7a 65 72 6f astToText ( zero
1760: 62 6c 6f 62 28 34 29 20 29 20 29 3c 2f 74 68 3e blob(4) ) )</th>
1770: 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 4e </tr>..<tr><td>N
1780: 55 4c 4c 3c 2f 74 64 3e 3c 74 64 3e 4e 55 4c 4c ULL</td><td>NULL
1790: 3c 2f 74 64 3e 3c 74 64 3e 36 31 36 43 37 30 36 </td><td>616C706
17a0: 38 36 31 3c 2f 74 64 3e 3c 74 64 3e 30 30 30 30 861</td><td>0000
17b0: 30 30 30 30 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 0000</td></tr></
17c0: 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 54 68 65 20 table><br>..The
17d0: 3c 62 3e 43 61 73 74 54 6f 42 6c 6f 62 28 29 3c <b>CastToBlob()<
17e0: 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e /b> SQL function
17f0: 20 77 69 6c 6c 20 61 74 74 65 6d 70 74 20 74 6f will attempt to
1800: 20 72 65 74 75 72 6e 20 61 20 76 61 6c 75 65 20 return a value
1810: 6f 66 20 74 68 65 20 3c 62 3e 42 4c 4f 42 3c 2f of the <b>BLOB</
1820: 62 3e 20 64 61 74 61 2d 74 79 70 65 2c 20 6f 72 b> data-type, or
1830: 20 3c 62 3e 4e 55 4c 4c 3c 2f 62 3e 20 69 66 20 <b>NULL</b> if
1840: 6e 6f 20 63 6f 6e 76 65 72 73 69 6f 6e 20 69 73 no conversion is
1850: 20 70 6f 73 73 69 62 6c 65 2e 0d 0a 3c 75 6c 3e possible...<ul>
1860: 0d 0a 3c 6c 69 3e 61 6e 20 49 6e 74 65 67 65 72 ..<li>an Integer
1870: 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 input argument
1880: 77 69 6c 6c 20 72 65 74 75 72 6e 20 61 20 4e 55 will return a NU
1890: 4c 4c 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a LL value.</li>..
18a0: 3c 6c 69 3e 61 20 44 6f 75 62 6c 65 20 69 6e 70 <li>a Double inp
18b0: 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c ut argument will
18c0: 20 72 65 74 75 72 6e 20 61 20 4e 55 4c 4c 20 76 return a NULL v
18d0: 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e alue.</li>..<li>
18e0: 61 20 54 65 78 74 20 69 6e 70 75 74 20 61 72 67 a Text input arg
18f0: 75 6d 65 6e 74 20 20 77 69 6c 6c 20 72 65 74 75 ument will retu
1900: 72 6e 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e rn the correspon
1910: 64 69 6e 67 20 42 4c 4f 42 20 76 61 6c 75 65 2e ding BLOB value.
1920: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 42 </li>..<li>any B
1930: 4c 4f 42 20 69 6e 70 75 74 20 61 72 67 75 6d 65 LOB input argume
1940: 6e 74 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 74 nt will return t
1950: 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 he corresponding
1960: 20 42 4c 4f 42 20 76 61 6c 75 65 2e 3c 2f 6c 69 BLOB value.</li
1970: 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 4e 55 4c 4c 20 >..<li>any NULL
1980: 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77 input argument w
1990: 69 6c 6c 20 72 65 74 75 72 6e 20 61 20 4e 55 4c ill return a NUL
19a0: 4c 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c L value.</li>..<
19b0: 2f 75 6c 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e /ul>..<verbatim>
19c0: 0d 0a 53 45 4c 45 43 54 20 48 65 78 28 20 43 61 ..SELECT Hex( Ca
19d0: 73 74 54 6f 42 6c 6f 62 28 20 27 30 31 32 33 34 stToBlob( '01234
19e0: 35 36 37 38 39 61 42 63 44 65 46 66 45 64 43 62 56789aBcDeFfEdCb
19f0: 41 39 38 37 36 35 34 33 32 31 30 27 2c 20 31 20 A9876543210', 1
1a00: 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 30 31 32 ) );..-----..012
1a10: 33 34 35 36 37 38 39 41 42 43 44 45 46 46 45 44 3456789ABCDEFFED
1a20: 43 42 41 39 38 37 36 35 34 33 32 31 30 0d 0a 0d CBA9876543210...
1a30: 0a 53 45 4c 45 43 54 20 43 61 73 74 54 6f 42 6c .SELECT CastToBl
1a40: 6f 62 28 20 27 31 32 66 27 2c 20 31 20 29 3b 0d ob( '12f', 1 );.
1a50: 0a 2d 2d 2d 2d 2d 0d 0a 4e 55 4c 4c 0d 0a 0d 0a .-----..NULL....
1a60: 53 45 4c 45 43 54 20 43 61 73 74 54 6f 42 6c 6f SELECT CastToBlo
1a70: 62 28 20 27 31 32 48 46 27 2c 20 31 20 29 3b 0d b( '12HF', 1 );.
1a80: 0a 2d 2d 2d 2d 2d 0d 0a 4e 55 4c 4c 0d 0a 3c 2f .-----..NULL..</
1a90: 76 65 72 62 61 74 69 6d 3e 0d 0a 41 20 73 65 63 verbatim>..A sec
1aa0: 6f 6e 64 20 6f 76 65 72 6c 6f 61 64 65 64 20 76 ond overloaded v
1ab0: 65 72 73 69 6f 6e 20 6f 66 20 3c 62 3e 43 61 73 ersion of <b>Cas
1ac0: 74 54 6f 42 6c 6f 62 28 29 3c 2f 62 3e 20 69 73 tToBlob()</b> is
1ad0: 20 73 75 70 70 6f 72 74 65 64 20 61 73 20 77 65 supported as we
1ae0: 6c 6c 3b 20 62 79 20 73 70 65 63 69 66 79 69 6e ll; by specifyin
1af0: 67 20 61 20 66 75 72 74 68 65 72 20 3c 62 3e 68 g a further <b>h
1b00: 65 78 5f 69 6e 70 75 74 3c 2f 62 3e 20 3c 75 3e ex_input</b> <u>
1b10: 62 6f 6f 6c 65 61 6e 3c 2f 75 3e 20 61 72 67 75 boolean</u> argu
1b20: 6d 65 6e 74 20 73 65 74 20 61 73 20 3c 62 3e 54 ment set as <b>T
1b30: 52 55 45 3c 2f 62 3e 20 74 68 65 20 69 6e 70 75 RUE</b> the inpu
1b40: 74 20 73 74 72 69 6e 67 20 77 69 6c 6c 20 62 65 t string will be
1b50: 20 61 73 73 75 6d 65 64 20 74 6f 20 62 65 20 3c assumed to be <
1b60: 75 3e 48 65 78 61 64 65 63 69 6d 61 6c 6c 79 20 u>Hexadecimally
1b70: 65 6e 63 6f 64 65 64 3c 2f 75 3e 2e 20 49 6e 20 encoded</u>. In
1b80: 74 68 69 73 20 63 61 73 65 20 4e 55 4c 4c 20 77 this case NULL w
1b90: 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 20 ill be returned
1ba0: 69 66 20 74 68 65 20 69 6e 70 75 74 20 73 74 72 if the input str
1bb0: 69 6e 67 20 64 6f 65 73 6e 27 74 20 63 6f 72 72 ing doesn't corr
1bc0: 65 73 70 6f 6e 64 73 20 74 6f 20 61 20 76 61 6c esponds to a val
1bd0: 69 64 20 48 65 78 61 64 65 63 69 6d 61 6c 20 6e id Hexadecimal n
1be0: 6f 74 61 74 69 6f 6e 2e 3c 62 72 3e 3c 62 72 3e otation.<br><br>
1bf0: 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 ..<hr>..<verbati
1c00: 6d 3e 0d 0a 53 45 4c 45 43 54 20 46 6f 72 63 65 m>..SELECT Force
1c10: 41 73 4e 75 6c 6c 28 20 27 61 27 2c 20 27 62 27 AsNull( 'a', 'b'
1c20: 20 29 2c 20 46 6f 72 63 65 41 73 4e 75 6c 6c 28 ), ForceAsNull(
1c30: 20 27 61 62 63 64 27 2c 20 27 61 62 63 64 27 20 'abcd', 'abcd'
1c40: 29 2c 20 46 6f 72 63 65 41 73 4e 75 6c 6c 28 20 ), ForceAsNull(
1c50: 31 2c 20 31 29 2c 20 46 6f 72 63 65 41 73 4e 75 1, 1), ForceAsNu
1c60: 6c 6c 28 20 31 2e 31 2c 20 31 20 29 3b 0d 0a 3c ll( 1.1, 1 );..<
1c70: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 74 61 62 /verbatim>..<tab
1c80: 6c 65 20 62 6f 72 64 65 72 3d 22 31 22 20 63 65 le border="1" ce
1c90: 6c 6c 73 70 61 63 69 6e 67 3d 22 34 22 20 63 65 llspacing="4" ce
1ca0: 6c 6c 70 61 64 64 69 6e 67 3d 22 34 22 3e 0d 0a llpadding="4">..
1cb0: 3c 74 72 3e 3c 74 68 3e 46 6f 72 63 65 41 73 4e <tr><th>ForceAsN
1cc0: 75 6c 6c 28 20 27 61 27 2c 20 27 62 27 20 29 3c ull( 'a', 'b' )<
1cd0: 2f 74 68 3e 3c 74 68 3e 46 6f 72 63 65 41 73 4e /th><th>ForceAsN
1ce0: 75 6c 6c 28 20 27 61 62 63 64 27 2c 20 27 61 62 ull( 'abcd', 'ab
1cf0: 63 64 27 20 29 3c 2f 74 68 3e 3c 74 68 3e 46 6f cd' )</th><th>Fo
1d00: 72 63 65 41 73 4e 75 6c 6c 28 20 31 2c 20 31 29 rceAsNull( 1, 1)
1d10: 3c 2f 74 68 3e 3c 74 68 3e 46 6f 72 63 65 41 73 </th><th>ForceAs
1d20: 4e 75 6c 6c 28 20 31 2e 31 2c 20 2d 39 39 39 39 Null( 1.1, -9999
1d30: 20 29 3c 2f 74 68 3e 3c 2f 74 72 3e 0d 0a 3c 74 )</th></tr>..<t
1d40: 72 3e 3c 74 64 3e 61 3c 2f 74 64 3e 3c 74 64 3e r><td>a</td><td>
1d50: 4e 55 4c 4c 3c 2f 74 64 3e 3c 74 64 3e 4e 55 4c NULL</td><td>NUL
1d60: 4c 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d L</td><td align=
1d70: 22 72 69 67 68 74 22 3e 31 2e 31 3c 2f 74 64 3e "right">1.1</td>
1d80: 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 3c 62 72 </tr></table><br
1d90: 3e 0d 0a 54 68 65 20 3c 62 3e 46 6f 72 63 65 41 >..The <b>ForceA
1da0: 73 4e 75 6c 6c 28 29 3c 2f 62 3e 20 53 51 4c 20 sNull()</b> SQL
1db0: 66 75 6e 63 74 69 6f 6e 20 77 69 6c 6c 20 65 76 function will ev
1dc0: 61 6c 75 61 74 65 20 74 77 6f 20 61 72 62 69 74 aluate two arbit
1dd0: 72 61 72 79 20 61 72 67 75 6d 65 6e 74 73 2e 3c rary arguments.<
1de0: 62 72 3e 0d 0a 49 66 20 74 68 65 79 20 61 72 65 br>..If they are
1df0: 20 65 71 75 61 6c 20 61 6e 64 20 65 78 61 63 74 equal and exact
1e00: 6c 79 20 6f 66 20 74 68 65 20 73 61 6d 65 20 64 ly of the same d
1e10: 61 74 61 2d 74 79 70 65 20 4e 55 4c 4c 20 77 69 ata-type NULL wi
1e20: 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 3b 20 ll be returned;
1e30: 6f 74 68 65 72 77 69 73 65 20 74 68 65 20 66 69 otherwise the fi
1e40: 72 73 74 20 61 72 67 75 6d 65 6e 74 20 76 61 6c rst argument val
1e50: 75 65 20 77 69 6c 6c 20 62 65 20 72 65 74 75 72 ue will be retur
1e60: 6e 65 64 2e 3c 62 72 3e 0d 0a 55 73 65 66 75 6c ned.<br>..Useful
1e70: 20 65 2e 67 2e 20 77 68 69 6c 65 20 70 72 6f 63 e.g. while proc
1e80: 65 73 73 69 6e 67 20 64 61 74 61 20 69 6d 70 6f essing data impo
1e90: 72 74 65 64 20 66 72 6f 6d 20 61 6e 79 20 3c 62 rted from any <b
1ea0: 3e 53 68 61 70 65 66 69 6c 65 3c 2f 62 3e 20 6f >Shapefile</b> o
1eb0: 72 20 3c 62 3e 44 42 46 20 66 69 6c 65 3c 2f 62 r <b>DBF file</b
1ec0: 3e 20 28 73 75 63 68 20 66 6f 72 6d 61 74 73 20 > (such formats
1ed0: 64 6f 65 73 6e 27 74 20 73 75 70 70 6f 72 74 20 doesn't support
1ee0: 61 6e 79 20 72 65 61 6c 20 4e 55 4c 4c 20 76 61 any real NULL va
1ef0: 6c 75 65 2c 20 6f 66 74 65 6e 20 62 65 69 6e 67 lue, often being
1f00: 20 72 65 70 6c 61 63 65 64 20 62 79 20 73 6f 6d replaced by som
1f10: 65 20 63 6f 6e 76 65 6e 74 69 6f 6e 61 6c 20 76 e conventional v
1f20: 61 6c 75 65 20 65 2e 67 2e 20 3c 62 3e 30 3c 2f alue e.g. <b>0</
1f30: 62 3e 20 6f 72 20 3c 62 3e 2d 39 39 39 39 3c 2f b> or <b>-9999</
1f40: 62 3e 20 61 6e 64 20 61 6c 69 6b 65 29 2e 3c 62 b> and alike).<b
1f50: 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 r><br>..<hr>..<h
1f60: 33 3e 3c 61 20 6e 61 6d 65 3d 22 75 75 69 64 22 3><a name="uuid"
1f70: 3e 47 65 6e 65 72 69 63 3c 2f 61 3e 20 53 51 4c >Generic</a> SQL
1f80: 20 66 75 6e 63 74 69 6f 6e 20 2d 20 55 55 49 44 function - UUID
1f90: 20 67 65 6e 65 72 61 74 6f 72 3c 2f 68 33 3e 0d generator</h3>.
1fa0: 0a 41 6e 20 3c 61 20 68 72 65 66 3d 22 68 74 74 .An <a href="htt
1fb0: 70 3a 2f 2f 65 6e 2e 77 69 6b 69 70 65 64 69 61 p://en.wikipedia
1fc0: 2e 6f 72 67 2f 77 69 6b 69 2f 55 6e 69 76 65 72 .org/wiki/Univer
1fd0: 73 61 6c 6c 79 5f 75 6e 69 71 75 65 5f 69 64 65 sally_unique_ide
1fe0: 6e 74 69 66 69 65 72 22 3e 55 6e 69 76 65 72 73 ntifier">Univers
1ff0: 61 6c 6c 79 20 75 6e 69 71 75 65 20 69 64 65 6e ally unique iden
2000: 74 69 66 69 65 72 3c 2f 61 3e 20 28 61 6b 61 20 tifier</a> (aka
2010: 3c 62 3e 55 55 49 44 3c 2f 62 3e 29 20 73 69 6d <b>UUID</b>) sim
2020: 70 6c 79 20 69 73 20 61 20 3c 75 3e 31 32 38 20 ply is a <u>128
2030: 62 69 74 3c 2f 75 3e 20 49 6e 74 65 67 65 72 3b bit</u> Integer;
2040: 20 61 63 63 6f 72 64 69 6e 67 6c 79 20 74 6f 20 accordingly to
2050: 3c 61 20 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f <a href="http://
2060: 65 6e 2e 77 69 6b 69 70 65 64 69 61 2e 6f 72 67 en.wikipedia.org
2070: 2f 77 69 6b 69 2f 55 55 49 44 23 52 61 6e 64 6f /wiki/UUID#Rando
2080: 6d 5f 55 55 49 44 5f 70 72 6f 62 61 62 69 6c 69 m_UUID_probabili
2090: 74 79 5f 6f 66 5f 64 75 70 6c 69 63 61 74 65 73 ty_of_duplicates
20a0: 22 3e 74 68 65 6f 72 79 3c 2f 61 3e 2c 20 74 68 ">theory</a>, th
20b0: 65 20 70 72 6f 62 61 62 69 6c 69 74 79 20 74 68 e probability th
20c0: 61 74 20 74 77 6f 20 72 61 6e 64 6f 6d 6c 79 20 at two randomly
20d0: 67 65 6e 65 72 61 74 65 64 20 55 55 49 44 73 20 generated UUIDs
20e0: 63 6f 75 6c 64 20 61 73 73 75 6d 65 20 74 68 65 could assume the
20f0: 20 73 61 6d 65 20 76 61 6c 75 65 20 69 73 20 6e same value is n
2100: 65 61 72 20 74 6f 20 7a 65 72 6f 20 66 6f 72 20 ear to zero for
2110: 6d 61 6e 79 20 70 72 61 63 74 69 63 61 6c 20 70 many practical p
2120: 75 72 70 6f 73 65 73 2e 20 41 6e 64 20 63 6f 6e urposes. And con
2130: 73 65 71 75 65 6e 74 6c 79 20 55 55 49 44 73 20 sequently UUIDs
2140: 61 72 65 20 77 69 64 65 6c 79 20 75 73 65 64 20 are widely used
2150: 61 73 20 3c 75 3e 75 6e 69 76 65 72 73 61 6c 6c as <u>universall
2160: 79 20 75 6e 69 71 75 65 20 49 44 73 3c 2f 75 3e y unique IDs</u>
2170: 2e 3c 62 72 3e 0d 0a 55 73 75 61 6c 6c 79 20 55 .<br>..Usually U
2180: 55 49 44 73 20 61 72 65 20 72 65 70 72 65 73 65 UIDs are represe
2190: 6e 74 65 64 20 69 6e 20 74 68 65 69 72 20 3c 75 nted in their <u
21a0: 3e 63 61 6e 6f 6e 69 63 61 6c 20 66 6f 72 6d 3c >canonical form<
21b0: 2f 75 3e 2c 20 69 2e 65 2e 20 61 73 20 61 20 73 /u>, i.e. as a s
21c0: 65 71 75 65 6e 63 65 20 6f 66 20 33 32 20 68 65 equence of 32 he
21d0: 78 61 64 65 63 69 6d 61 6c 20 64 69 67 69 74 73 xadecimal digits
21e0: 20 73 65 70 61 72 61 74 65 64 20 69 6e 74 6f 20 separated into
21f0: 66 69 76 65 20 64 69 73 74 69 6e 63 74 20 62 6c five distinct bl
2200: 6f 63 6b 2c 20 61 63 63 6f 72 64 69 6e 67 6c 79 ock, accordingly
2210: 20 74 6f 20 61 20 3c 62 3e 38 2d 34 2d 34 2d 34 to a <b>8-4-4-4
2220: 2d 31 32 3c 2f 62 3e 20 73 63 68 65 6d 61 2e 0d -12</b> schema..
2230: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c .<verbatim>..SEL
2240: 45 43 54 20 43 72 65 61 74 65 55 55 49 44 28 29 ECT CreateUUID()
2250: 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 66 66 66 ;..--------..fff
2260: 35 66 61 66 31 2d 64 63 63 30 2d 34 33 39 31 2d 5faf1-dcc0-4391-
2270: 38 30 35 34 2d 36 65 37 64 65 37 35 64 38 35 62 8054-6e7de75d85b
2280: 31 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 1..</verbatim>..
2290: 54 68 65 20 3c 62 3e 43 72 65 61 74 65 55 55 49 The <b>CreateUUI
22a0: 44 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 D()</b> SQL func
22b0: 74 69 6f 6e 20 69 73 20 62 75 69 6c 74 20 6f 6e tion is built on
22c0: 20 74 68 65 20 74 6f 70 20 74 68 65 20 3c 69 3e the top the <i>
22d0: 48 69 67 68 20 51 75 61 6c 69 74 79 20 50 73 65 High Quality Pse
22e0: 75 64 6f 2d 52 61 6e 64 6f 6d 20 4e 75 6d 62 65 udo-Random Numbe
22f0: 72 20 47 65 6e 65 72 61 74 6f 72 3c 2f 69 3e 20 r Generator</i>
2300: 3c 61 20 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f <a href="http://
2310: 77 77 77 2e 73 71 6c 69 74 65 2e 6f 72 67 2f 63 www.sqlite.org/c
2320: 33 72 65 66 2f 72 61 6e 64 6f 6d 6e 65 73 73 2e 3ref/randomness.
2330: 68 74 6d 6c 22 3e 69 6e 74 65 72 6e 61 6c 6c 79 html">internally
2340: 20 69 6d 70 6c 65 6d 65 6e 74 65 64 3c 2f 61 3e implemented</a>
2350: 20 62 79 20 53 51 4c 69 74 65 2e 3c 62 72 3e 0d by SQLite.<br>.
2360: 0a 54 68 65 20 72 65 74 75 72 6e 65 64 20 55 55 .The returned UU
2370: 49 44 20 69 73 20 63 6f 6e 66 6f 72 6d 61 6e 74 ID is conformant
2380: 20 74 6f 20 3c 75 3e 56 65 72 73 69 6f 6e 20 34 to <u>Version 4
2390: 20 28 72 61 6e 64 6f 6d 29 3c 2f 75 3e 20 28 69 (random)</u> (i
23a0: 2e 65 2e 20 74 68 65 20 66 69 72 73 74 20 64 69 .e. the first di
23b0: 67 69 74 20 69 6e 74 6f 20 74 68 65 20 74 68 69 git into the thi
23c0: 72 64 20 62 6c 6f 63 6b 20 77 69 6c 6c 20 61 6c rd block will al
23d0: 77 61 79 73 20 62 65 20 3c 62 3e 34 3c 2f 62 3e ways be <b>4</b>
23e0: 20 61 6e 64 20 74 68 65 20 66 69 72 73 74 20 64 and the first d
23f0: 69 67 69 74 20 69 6e 74 6f 20 74 68 65 20 66 6f igit into the fo
2400: 75 72 74 68 20 62 6c 6f 63 6b 20 77 69 6c 6c 20 urth block will
2410: 61 6c 77 61 79 73 20 62 65 20 3c 62 3e 38 3c 2f always be <b>8</
2420: 62 3e 29 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 b>).<br><br>..<h
2430: 72 3e 0d 0a 3c 68 33 3e 3c 61 20 6e 61 6d 65 3d r>..<h3><a name=
2440: 22 67 65 6f 6d 22 3e 53 70 61 74 69 61 6c 3c 2f "geom">Spatial</
2450: 61 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 73 a> SQL functions
2460: 3c 2f 68 33 3e 0d 0a 46 65 77 20 6d 6f 72 65 20 </h3>..Few more
2470: 53 70 61 74 69 61 6c 20 53 51 4c 20 66 75 6e 63 Spatial SQL func
2480: 74 69 6f 6e 73 20 61 72 65 20 6e 6f 77 20 73 75 tions are now su
2490: 70 70 6f 72 74 65 64 2e 0d 0a 3c 76 65 72 62 61 pported...<verba
24a0: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 54 5f tim>..SELECT ST_
24b0: 41 73 54 65 78 74 28 20 53 54 5f 41 64 64 50 6f AsText( ST_AddPo
24c0: 69 6e 74 28 20 0d 0a 20 20 53 54 5f 47 65 6f 6d int( .. ST_Geom
24d0: 46 72 6f 6d 54 65 78 74 28 20 27 4c 49 4e 45 53 FromText( 'LINES
24e0: 54 52 49 4e 47 28 20 30 20 30 2c 20 31 20 30 20 TRING( 0 0, 1 0
24f0: 29 27 20 29 2c 20 0d 0a 20 20 53 54 5f 47 65 6f )' ), .. ST_Geo
2500: 6d 46 72 6f 6d 54 65 78 74 28 20 27 50 4f 49 4e mFromText( 'POIN
2510: 54 28 20 31 20 31 20 29 27 20 29 20 29 20 29 3b T( 1 1 )' ) ) );
2520: 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45 ..--------..LINE
2530: 53 54 52 49 4e 47 28 30 20 30 2c 20 31 20 30 2c STRING(0 0, 1 0,
2540: 20 31 20 31 29 0d 0a 3c 2f 76 65 72 62 61 74 69 1 1)..</verbati
2550: 6d 3e 0d 0a 54 68 65 20 3c 62 3e 53 54 5f 41 64 m>..The <b>ST_Ad
2560: 64 50 6f 69 6e 74 28 29 3c 2f 62 3e 20 53 51 4c dPoint()</b> SQL
2570: 20 66 75 6e 63 74 69 6f 6e 20 61 64 64 73 20 61 function adds a
2580: 20 66 75 72 74 68 65 72 20 50 6f 69 6e 74 2f 56 further Point/V
2590: 65 72 74 65 78 20 61 74 20 74 68 65 20 65 6e 64 ertex at the end
25a0: 20 6f 66 20 61 20 4c 69 6e 65 73 74 72 69 6e 67 of a Linestring
25b0: 3b 20 74 68 65 20 66 69 72 73 74 20 61 72 67 75 ; the first argu
25c0: 6d 65 6e 74 20 69 73 20 61 6c 77 61 79 73 20 65 ment is always e
25d0: 78 70 65 63 74 65 64 20 74 6f 20 62 65 20 6f 66 xpected to be of
25e0: 20 74 68 65 20 4c 69 6e 65 73 74 72 69 6e 67 20 the Linestring
25f0: 74 79 70 65 2c 20 74 68 65 20 73 65 63 6f 6e 64 type, the second
2600: 20 6f 6e 65 20 6d 75 73 74 20 62 65 20 61 20 50 one must be a P
2610: 6f 69 6e 74 2e 0d 0a 3c 76 65 72 62 61 74 69 6d oint...<verbatim
2620: 3e 0d 0a 53 45 4c 45 43 54 20 53 54 5f 41 73 54 >..SELECT ST_AsT
2630: 65 78 74 28 20 53 54 5f 41 64 64 50 6f 69 6e 74 ext( ST_AddPoint
2640: 28 20 0d 0a 20 20 53 54 5f 47 65 6f 6d 46 72 6f ( .. ST_GeomFro
2650: 6d 54 65 78 74 28 20 27 4c 49 4e 45 53 54 52 49 mText( 'LINESTRI
2660: 4e 47 28 20 31 20 30 2c 20 31 20 31 20 29 27 20 NG( 1 0, 1 1 )'
2670: 29 2c 20 0d 0a 20 20 53 54 5f 47 65 6f 6d 46 72 ), .. ST_GeomFr
2680: 6f 6d 54 65 78 74 28 20 27 50 4f 49 4e 54 28 20 omText( 'POINT(
2690: 30 20 30 20 29 27 20 29 2c 20 30 20 29 20 29 3b 0 0 )' ), 0 ) );
26a0: 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e ..---------..LIN
26b0: 45 53 54 52 49 4e 47 28 30 20 30 2c 20 31 20 30 ESTRING(0 0, 1 0
26c0: 2c 20 31 20 31 29 0d 0a 3c 2f 76 65 72 62 61 74 , 1 1)..</verbat
26d0: 69 6d 3e 0d 0a 49 66 20 61 6e 20 6f 70 74 69 6f im>..If an optio
26e0: 6e 61 6c 20 74 68 69 72 64 20 61 72 67 75 6d 65 nal third argume
26f0: 6e 74 20 28 6f 66 20 74 68 65 20 49 6e 74 65 67 nt (of the Integ
2700: 65 72 20 74 79 70 65 29 20 69 73 20 70 61 73 73 er type) is pass
2710: 65 64 20 74 6f 20 3c 62 3e 53 54 5f 41 64 64 50 ed to <b>ST_AddP
2720: 6f 69 6e 74 28 29 3c 2f 62 3e 20 69 74 27 73 20 oint()</b> it's
2730: 69 6e 74 65 6e 64 65 64 20 74 6f 20 73 70 65 63 intended to spec
2740: 69 66 79 20 74 68 65 20 3c 75 3e 69 6e 64 65 78 ify the <u>index
2750: 3c 2f 75 3e 20 6f 66 20 74 68 65 20 6e 65 77 20 </u> of the new
2760: 56 65 72 74 65 78 20 28 66 69 72 73 74 20 56 65 Vertex (first Ve
2770: 72 74 65 78 20 68 61 73 20 69 6e 64 65 78 20 30 rtex has index 0
2780: 2c 20 73 65 63 6f 6e 64 20 56 65 72 74 65 78 20 , second Vertex
2790: 68 61 73 20 69 6e 64 65 78 20 31 20 61 6e 64 20 has index 1 and
27a0: 73 6f 20 6f 6e 29 2e 3c 62 72 3e 0d 0a 52 65 66 so on).<br>..Ref
27b0: 65 72 65 6e 63 69 6e 67 20 61 20 6e 6f 74 20 65 erencing a not e
27c0: 78 69 73 74 69 6e 67 20 69 6e 64 65 78 20 69 73 xisting index is
27d0: 20 61 6e 20 65 72 72 6f 72 2c 20 61 6e 64 20 77 an error, and w
27e0: 69 6c 6c 20 72 65 74 75 72 6e 20 4e 55 4c 4c 2e ill return NULL.
27f0: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 ..<verbatim>..SE
2800: 4c 45 43 54 20 53 54 5f 41 73 54 65 78 74 28 20 LECT ST_AsText(
2810: 53 54 5f 41 64 64 50 6f 69 6e 74 28 20 0d 0a 20 ST_AddPoint( ..
2820: 20 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 ST_GeomFromText
2830: 28 20 27 4c 49 4e 45 53 54 52 49 4e 47 28 20 30 ( 'LINESTRING( 0
2840: 20 30 2c 20 31 20 30 20 29 27 20 29 2c 20 0d 0a 0, 1 0 )' ), ..
2850: 20 20 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 ST_GeomFromTex
2860: 74 28 20 27 50 4f 49 4e 54 28 20 31 20 31 20 29 t( 'POINT( 1 1 )
2870: 27 20 29 2c 20 2d 31 20 29 20 29 3b 0d 0a 2d 2d ' ), -1 ) );..--
2880: 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45 53 54 52 49 ------..LINESTRI
2890: 4e 47 28 30 20 30 2c 20 31 20 30 2c 20 31 20 31 NG(0 0, 1 0, 1 1
28a0: 29 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a )..</verbatim>..
28b0: 50 61 73 73 69 6e 67 20 61 20 6e 65 67 61 74 69 Passing a negati
28c0: 76 65 20 69 6e 64 65 78 20 69 73 20 61 20 73 75 ve index is a su
28d0: 70 70 6f 72 74 65 64 20 6f 70 74 69 6f 6e 2c 20 pported option,
28e0: 61 6e 64 20 73 69 6d 70 6c 79 20 63 6f 72 72 65 and simply corre
28f0: 73 70 6f 6e 64 73 20 74 6f 20 74 68 65 20 64 65 sponds to the de
2900: 66 61 75 6c 74 20 62 65 68 61 76 69 6f 75 72 20 fault behaviour
2910: 28 69 2e 65 2e 20 3c 69 3e 61 70 70 65 6e 64 69 (i.e. <i>appendi
2920: 6e 67 20 74 68 65 20 50 6f 69 6e 74 20 74 6f 20 ng the Point to
2930: 74 68 65 20 65 6e 64 20 6f 66 20 74 68 65 20 4c the end of the L
2940: 69 6e 65 73 74 72 69 6e 67 3c 2f 69 3e 29 2e 3c inestring</i>).<
2950: 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c br><br>..<hr>..<
2960: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 verbatim>..SELEC
2970: 54 20 53 54 5f 41 73 54 65 78 74 28 20 53 54 5f T ST_AsText( ST_
2980: 53 65 74 50 6f 69 6e 74 28 20 0d 0a 20 20 53 54 SetPoint( .. ST
2990: 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27 _GeomFromText( '
29a0: 4c 49 4e 45 53 54 52 49 4e 47 28 20 30 20 30 2c LINESTRING( 0 0,
29b0: 20 31 20 30 2c 20 31 20 31 20 29 27 20 29 2c 20 1 0, 1 1 )' ),
29c0: 0d 0a 20 20 31 2c 20 53 54 5f 47 65 6f 6d 46 72 .. 1, ST_GeomFr
29d0: 6f 6d 54 65 78 74 28 20 27 50 4f 49 4e 54 28 20 omText( 'POINT(
29e0: 32 20 31 20 29 27 20 29 20 29 20 29 3b 0d 0a 2d 2 1 )' ) ) );..-
29f0: 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45 53 54 --------..LINEST
2a00: 52 49 4e 47 28 30 20 30 2c 20 32 20 31 2c 20 31 RING(0 0, 2 1, 1
2a10: 20 31 29 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 1)..</verbatim>
2a20: 0d 0a 54 68 65 20 3c 62 3e 53 54 5f 53 65 74 50 ..The <b>ST_SetP
2a30: 6f 69 6e 74 28 29 3c 2f 62 3e 20 53 51 4c 20 66 oint()</b> SQL f
2a40: 75 6e 63 74 69 6f 6e 20 63 61 6e 20 72 65 70 6c unction can repl
2a50: 61 63 65 20 61 20 50 6f 69 6e 74 2f 56 65 72 74 ace a Point/Vert
2a60: 65 78 20 66 72 6f 6d 20 77 69 74 68 69 6e 20 61 ex from within a
2a70: 20 4c 69 6e 65 73 74 72 69 6e 67 3b 20 74 68 65 Linestring; the
2a80: 20 66 69 72 73 74 20 61 72 67 75 6d 65 6e 74 20 first argument
2a90: 69 73 20 61 6c 77 61 79 73 20 65 78 70 65 63 74 is always expect
2aa0: 65 64 20 74 6f 20 62 65 20 6f 66 20 74 68 65 20 ed to be of the
2ab0: 4c 69 6e 65 73 74 72 69 6e 67 20 74 79 70 65 2c Linestring type,
2ac0: 20 74 68 65 20 73 65 63 6f 6e 64 20 69 73 20 61 the second is a
2ad0: 6e 20 49 6e 74 65 67 65 72 20 73 70 65 63 69 66 n Integer specif
2ae0: 79 69 6e 67 20 74 68 65 20 3c 75 3e 69 6e 64 65 ying the <u>inde
2af0: 78 3c 2f 75 3e 20 6f 66 20 74 68 65 20 61 66 66 x</u> of the aff
2b00: 65 63 74 65 64 20 56 65 72 74 65 78 20 61 6e 64 ected Vertex and
2b10: 20 74 68 65 20 74 68 69 72 64 20 6f 6e 65 20 6d the third one m
2b20: 75 73 74 20 62 65 20 61 20 50 6f 69 6e 74 2e 3c ust be a Point.<
2b30: 62 72 3e 0d 0a 52 65 66 65 72 65 6e 63 69 6e 67 br>..Referencing
2b40: 20 61 20 6e 6f 74 20 65 78 69 73 74 69 6e 67 20 a not existing
2b50: 69 6e 64 65 78 20 69 73 20 61 6e 20 65 72 72 6f index is an erro
2b60: 72 2c 20 61 6e 64 20 77 69 6c 6c 20 72 65 74 75 r, and will retu
2b70: 72 6e 20 4e 55 4c 4c 2e 3c 62 72 3e 3c 62 72 3e rn NULL.<br><br>
2b80: 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 ..<hr>..<verbati
2b90: 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 54 5f 41 73 m>..SELECT ST_As
2ba0: 54 65 78 74 28 20 53 54 5f 52 65 6d 6f 76 65 50 Text( ST_RemoveP
2bb0: 6f 69 6e 74 28 20 0d 0a 20 20 53 54 5f 47 65 6f oint( .. ST_Geo
2bc0: 6d 46 72 6f 6d 54 65 78 74 28 20 27 4c 49 4e 45 mFromText( 'LINE
2bd0: 53 54 52 49 4e 47 28 20 30 20 30 2c 20 31 20 30 STRING( 0 0, 1 0
2be0: 2c 20 31 20 31 20 29 27 20 29 2c 20 31 20 29 20 , 1 1 )' ), 1 )
2bf0: 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c );..---------..L
2c00: 49 4e 45 53 54 52 49 4e 47 28 30 20 30 2c 20 31 INESTRING(0 0, 1
2c10: 20 31 29 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 1)..</verbatim>
2c20: 0d 0a 54 68 65 20 3c 62 3e 53 54 5f 52 65 6d 6f ..The <b>ST_Remo
2c30: 76 65 50 6f 69 6e 74 28 29 3c 2f 62 3e 20 53 51 vePoint()</b> SQ
2c40: 4c 20 66 75 6e 63 74 69 6f 6e 20 63 61 6e 20 72 L function can r
2c50: 65 6d 6f 76 65 20 61 20 50 6f 69 6e 74 2f 56 65 emove a Point/Ve
2c60: 72 74 65 78 20 66 72 6f 6d 20 77 69 74 68 69 6e rtex from within
2c70: 20 61 20 4c 69 6e 65 73 74 72 69 6e 67 3b 20 74 a Linestring; t
2c80: 68 65 20 66 69 72 73 74 20 61 72 67 75 6d 65 6e he first argumen
2c90: 74 20 69 73 20 61 6c 77 61 79 73 20 65 78 70 65 t is always expe
2ca0: 63 74 65 64 20 74 6f 20 62 65 20 6f 66 20 74 68 cted to be of th
2cb0: 65 20 4c 69 6e 65 73 74 72 69 6e 67 20 74 79 70 e Linestring typ
2cc0: 65 2c 20 74 68 65 20 73 65 63 6f 6e 64 20 69 73 e, the second is
2cd0: 20 61 6e 20 49 6e 74 65 67 65 72 20 73 70 65 63 an Integer spec
2ce0: 69 66 79 69 6e 67 20 74 68 65 20 3c 75 3e 69 6e ifying the <u>in
2cf0: 64 65 78 3c 2f 75 3e 20 6f 66 20 74 68 65 20 61 dex</u> of the a
2d00: 66 66 65 63 74 65 64 20 56 65 72 74 65 78 2e 3c ffected Vertex.<
2d10: 62 72 3e 0d 0a 52 65 66 65 72 65 6e 63 69 6e 67 br>..Referencing
2d20: 20 61 20 6e 6f 74 20 65 78 69 73 74 69 6e 67 20 a not existing
2d30: 69 6e 64 65 78 20 69 73 20 61 6e 20 65 72 72 6f index is an erro
2d40: 72 2c 20 61 6e 64 20 77 69 6c 6c 20 72 65 74 75 r, and will retu
2d50: 72 6e 20 4e 55 4c 4c 2e 3c 62 72 3e 3c 62 72 3e rn NULL.<br><br>
2d60: 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 ..<hr>..<verbati
2d70: 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 54 5f 41 73 m>..SELECT ST_As
2d80: 54 65 78 74 28 20 53 54 5f 50 6f 69 6e 74 28 31 Text( ST_Point(1
2d90: 30 2c 20 32 30 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0, 20) );..-----
2da0: 2d 2d 2d 2d 2d 0d 0a 50 4f 49 4e 54 28 31 30 20 -----..POINT(10
2db0: 31 30 29 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 10)..</verbatim>
2dc0: 0d 0a 54 68 65 20 3c 62 3e 53 54 5f 50 6f 69 6e ..The <b>ST_Poin
2dd0: 74 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 t()</b> SQL func
2de0: 74 69 6f 6e 20 73 69 6d 70 6c 79 20 69 73 20 79 tion simply is y
2df0: 65 74 20 61 6e 6f 74 68 65 72 20 3c 69 3e 61 6c et another <i>al
2e00: 69 61 73 2d 6e 61 6d 65 3c 2f 69 3e 20 63 6f 72 ias-name</i> cor
2e10: 72 65 73 70 6f 6e 64 69 6e 67 20 74 6f 20 3c 62 responding to <b
2e20: 3e 4d 61 6b 65 50 6f 69 6e 74 28 29 3c 2f 62 3e >MakePoint()</b>
2e30: 3b 20 74 68 69 73 20 66 75 72 74 68 65 72 20 61 ; this further a
2e40: 6c 69 61 73 20 68 61 73 20 62 65 65 6e 20 69 6e lias has been in
2e50: 74 72 6f 64 75 63 65 64 20 73 6f 20 74 6f 20 73 troduced so to s
2e60: 75 70 70 6f 72 74 20 61 20 73 74 72 69 63 74 20 upport a strict
2e70: 50 6f 73 74 47 49 53 20 63 6f 6e 66 6f 72 6d 61 PostGIS conforma
2e80: 6e 63 65 2e 3c 62 72 3e 0d 0a 3c 75 3e 50 6c 65 nce.<br>..<u>Ple
2e90: 61 73 65 20 6e 6f 74 65 3c 2f 75 3e 3a 20 64 69 ase note</u>: di
2ea0: 66 66 65 72 65 6e 74 6c 79 20 66 72 6f 6d 20 4d fferently from M
2eb0: 61 6b 65 50 6f 69 6e 74 28 29 2c 20 53 54 5f 50 akePoint(), ST_P
2ec0: 6f 69 6e 74 28 29 20 64 6f 6e 27 74 20 73 75 70 oint() don't sup
2ed0: 70 6f 72 74 73 20 74 68 65 20 6f 70 74 69 6f 6e ports the option
2ee0: 61 6c 20 3c 62 3e 53 52 49 44 3c 2f 62 3e 20 61 al <b>SRID</b> a
2ef0: 72 67 75 6d 65 6e 74 2e 3c 62 72 3e 3c 62 72 3e rgument.<br><br>
2f00: 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 ..<hr>..<verbati
2f10: 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 54 5f 41 73 m>..SELECT ST_As
2f20: 54 65 78 74 28 20 4d 61 6b 65 4c 69 6e 65 28 20 Text( MakeLine(
2f30: 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 ST_GeomFromText(
2f40: 20 27 4d 55 4c 54 49 50 4f 49 4e 54 28 30 20 30 'MULTIPOINT(0 0
2f50: 2c 20 31 20 30 2c 20 31 20 31 29 27 20 29 20 29 , 1 0, 1 1)' ) )
2f60: 20 2c 20 31 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d , 1 );..-------
2f70: 2d 2d 2d 0d 0a 4c 49 4e 45 53 54 52 49 4e 47 28 ---..LINESTRING(
2f80: 30 20 30 2c 20 31 20 30 2c 20 31 20 31 29 0d 0a 0 0, 1 0, 1 1)..
2f90: 0d 0a 53 45 4c 45 43 54 20 53 54 5f 41 73 54 65 ..SELECT ST_AsTe
2fa0: 78 74 28 20 4d 61 6b 65 4c 69 6e 65 28 20 53 54 xt( MakeLine( ST
2fb0: 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27 _GeomFromText( '
2fc0: 4d 55 4c 54 49 50 4f 49 4e 54 28 30 20 30 2c 20 MULTIPOINT(0 0,
2fd0: 31 20 30 2c 20 31 20 31 29 27 20 29 20 29 20 2c 1 0, 1 1)' ) ) ,
2fe0: 20 30 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0 );..---------
2ff0: 2d 0d 0a 4c 49 4e 45 53 54 52 49 4e 47 28 31 20 -..LINESTRING(1
3000: 31 2c 20 31 20 30 2c 20 30 20 30 29 0d 0a 3c 2f 1, 1 0, 0 0)..</
3010: 76 65 72 62 61 74 69 6d 3e 0d 0a 4e 6f 74 20 72 verbatim>..Not r
3020: 65 61 6c 6c 79 20 61 20 62 72 61 6e 64 20 6e 65 eally a brand ne
3030: 77 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 3b 20 w SQL function;
3040: 6d 6f 72 65 20 73 69 6d 70 6c 79 20 61 20 66 75 more simply a fu
3050: 72 74 68 65 72 20 6f 76 65 72 6c 6f 61 64 65 64 rther overloaded
3060: 20 66 6c 61 76 6f 72 20 6f 66 20 74 68 65 20 61 flavor of the a
3070: 6c 72 65 61 64 79 20 65 78 69 73 74 69 6e 67 20 lready existing
3080: 3c 62 3e 4d 61 6b 65 4c 69 6e 65 28 29 3c 2f 62 <b>MakeLine()</b
3090: 3e 2e 3c 62 72 3e 0d 0a 4e 6f 77 20 74 68 65 20 >.<br>..Now the
30a0: 69 6e 70 75 74 20 47 65 6f 6d 65 74 72 79 20 28 input Geometry (
30b0: 66 69 72 73 74 20 61 72 67 75 6d 65 6e 74 29 20 first argument)
30c0: 63 6f 75 6c 64 20 62 65 20 6f 66 20 74 68 65 20 could be of the
30d0: 4d 55 4c 54 49 50 4f 49 4e 54 20 74 79 70 65 20 MULTIPOINT type
30e0: 61 6e 64 20 74 68 65 20 73 65 63 6f 6e 64 20 61 and the second a
30f0: 72 67 75 6d 65 6e 74 20 69 66 20 6f 66 20 74 68 rgument if of th
3100: 65 20 3c 62 3e 42 6f 6f 6c 65 61 6e 3c 2f 62 3e e <b>Boolean</b>
3110: 20 74 79 70 65 3b 20 69 66 20 74 68 65 20 73 65 type; if the se
3120: 63 6f 6e 64 20 61 72 67 75 6d 65 6e 74 20 63 6f cond argument co
3130: 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 3c 62 3e rresponds to <b>
3140: 54 52 55 45 3c 2f 62 3e 20 74 68 65 20 72 65 74 TRUE</b> the ret
3150: 75 72 6e 65 64 20 4c 49 4e 45 53 54 52 49 4e 47 urned LINESTRING
3160: 20 77 69 6c 6c 20 62 65 20 6f 72 69 65 6e 74 65 will be oriente
3170: 64 20 61 63 63 6f 72 64 69 6e 67 6c 79 20 74 6f d accordingly to
3180: 20 74 68 65 20 50 6f 69 6e 74 2d 73 65 71 75 65 the Point-seque
3190: 6e 63 65 20 61 73 20 73 70 65 63 69 66 69 65 64 nce as specified
31a0: 20 62 79 20 74 68 65 20 4d 75 6c 74 69 50 6f 69 by the MultiPoi
31b0: 6e 74 2c 20 6f 74 68 65 72 77 69 73 65 20 3c 75 nt, otherwise <u
31c0: 3e 72 65 76 65 72 73 65 20 6f 72 64 65 72 3c 2f >reverse order</
31d0: 75 3e 20 77 69 6c 6c 20 62 65 20 61 73 73 75 6d u> will be assum
31e0: 65 64 2c 20 74 68 75 73 20 72 65 74 75 72 6e 69 ed, thus returni
31f0: 6e 67 20 61 20 4c 69 6e 65 73 74 72 69 6e 67 20 ng a Linestring
3200: 6f 66 20 6f 70 70 6f 73 69 74 65 20 6f 72 69 65 of opposite orie
3210: 6e 74 61 74 69 6f 6e 2e 3c 62 72 3e 3c 62 72 3e ntation.<br><br>
3220: 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 ..<hr>..<verbati
3230: 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 54 5f 41 72 m>..SELECT ST_Ar
3240: 65 61 28 20 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 ea( ST_GeomFromT
3250: 65 78 74 28 20 27 50 4f 4c 59 47 4f 4e 28 28 32 ext( 'POLYGON((2
3260: 30 20 32 30 2c 20 32 31 20 32 30 2c 20 32 31 20 0 20, 21 20, 21
3270: 32 31 2c 20 32 30 20 32 31 2c 20 32 30 20 32 30 21, 20 21, 20 20
3280: 29 29 27 2c 20 34 33 32 36 20 29 2c 20 31 20 29 ))', 4326 ), 1 )
3290: 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 ;..----------..1
32a0: 31 35 34 38 35 35 35 39 32 36 2e 36 34 37 37 33 1548555926.64773
32b0: 36 0d 0a 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 54 6......SELECT ST
32c0: 5f 41 72 65 61 28 20 53 54 5f 47 65 6f 6d 46 72 _Area( ST_GeomFr
32d0: 6f 6d 54 65 78 74 28 20 27 50 4f 4c 59 47 4f 4e omText( 'POLYGON
32e0: 28 28 32 30 20 32 30 2c 20 32 31 20 32 30 2c 20 ((20 20, 21 20,
32f0: 32 31 20 32 31 2c 20 32 30 20 32 31 2c 20 32 30 21 21, 20 21, 20
3300: 20 32 30 29 29 27 2c 20 34 33 32 36 20 29 2c 20 20))', 4326 ),
3310: 30 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0 );..----------
3320: 0d 0a 31 31 35 38 31 33 37 37 36 32 33 2e 31 31 ..11581377623.11
3330: 34 31 38 39 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 4189..</verbatim
3340: 3e 0d 0a 4f 6e 63 65 20 61 67 61 69 6e 2c 20 73 >..Once again, s
3350: 69 6d 70 6c 79 20 61 20 66 75 72 74 68 65 72 20 imply a further
3360: 65 78 74 65 6e 73 69 6f 6e 20 6f 66 20 74 68 65 extension of the
3370: 20 61 6c 72 65 61 64 79 20 65 78 69 73 74 69 6e already existin
3380: 67 20 3c 62 3e 53 54 5f 41 72 65 61 28 29 3c 2f g <b>ST_Area()</
3390: 62 3e 2e 3c 62 72 3e 0d 0a 4e 6f 77 20 69 66 20 b>.<br>..Now if
33a0: 74 68 65 20 69 6e 70 75 74 20 47 65 6f 6d 65 74 the input Geomet
33b0: 72 79 20 61 64 6f 70 74 73 20 3c 75 3e 67 65 6f ry adopts <u>geo
33c0: 67 72 61 70 68 69 63 20 63 6f 6f 72 64 69 6e 61 graphic coordina
33d0: 74 65 73 3c 2f 75 3e 20 28 69 2e 65 2e 20 62 61 tes</u> (i.e. ba
33e0: 73 65 64 20 6f 6e 20 3c 75 3e 6c 6f 6e 67 69 74 sed on <u>longit
33f0: 75 64 65 3c 2f 75 3e 20 61 6e 64 20 3c 75 3e 6c ude</u> and <u>l
3400: 61 74 69 74 75 64 65 3c 2f 75 3e 20 61 6e 67 6c atitude</u> angl
3410: 65 73 29 2c 20 61 20 73 65 63 6f 6e 64 20 61 72 es), a second ar
3420: 67 75 6d 65 6e 74 20 6f 66 20 74 68 65 20 3c 62 gument of the <b
3430: 3e 42 6f 6f 6c 65 61 6e 3c 2f 62 3e 20 64 61 74 >Boolean</b> dat
3440: 61 2d 74 79 70 65 20 63 6f 75 6c 64 20 62 65 20 a-type could be
3450: 6f 70 74 69 6f 6e 61 6c 6c 79 20 73 70 65 63 69 optionally speci
3460: 66 69 65 64 2e 3c 62 72 3e 0d 0a 49 6e 20 74 68 fied.<br>..In th
3470: 69 73 20 63 61 73 65 20 74 68 65 20 72 65 74 75 is case the retu
3480: 72 6e 65 64 20 41 72 65 61 20 77 69 6c 6c 20 62 rned Area will b
3490: 65 20 6d 65 61 73 75 72 65 64 20 69 6e 20 3c 62 e measured in <b
34a0: 3e 6d 65 74 65 72 73 3c 2f 62 3e 2e 0d 0a 3c 75 >meters</b>...<u
34b0: 6c 3e 0d 0a 3c 6c 69 3e 69 66 20 74 68 65 20 73 l>..<li>if the s
34c0: 65 63 6f 6e 64 20 61 72 67 20 69 73 20 3c 62 3e econd arg is <b>
34d0: 54 52 55 45 3c 2f 62 3e 20 74 68 65 20 41 72 65 TRUE</b> the Are
34e0: 61 20 77 69 6c 6c 20 62 65 20 6d 65 61 73 75 72 a will be measur
34f0: 65 64 20 3c 75 3e 6f 6e 20 74 68 65 20 45 6c 6c ed <u>on the Ell
3500: 69 70 73 6f 69 64 3c 2f 75 3e 20 28 6d 6f 72 65 ipsoid</u> (more
3510: 20 61 63 63 75 72 61 74 65 2c 20 62 75 74 20 73 accurate, but s
3520: 6c 6f 77 65 72 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c lower).</li>..<l
3530: 69 3e 69 66 20 74 68 65 20 73 65 63 6f 6e 64 20 i>if the second
3540: 61 72 67 20 69 73 20 3c 62 3e 46 41 4c 53 45 3c arg is <b>FALSE<
3550: 2f 62 3e 20 74 68 65 20 41 72 65 61 20 77 69 6c /b> the Area wil
3560: 6c 20 62 65 20 6d 65 61 73 75 72 65 20 3c 75 3e l be measure <u>
3570: 6f 6e 20 74 68 65 20 53 70 68 65 72 65 3c 2f 75 on the Sphere</u
3580: 3e 20 28 66 61 73 74 65 72 2c 20 62 75 74 20 6c > (faster, but l
3590: 65 73 73 20 61 63 63 75 72 61 74 65 29 2e 3c 2f ess accurate).</
35a0: 6c 69 3e 0d 0a 3c 6c 69 3e 4e 55 4c 4c 20 77 69 li>..<li>NULL wi
35b0: 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 20 6f ll be returned o
35c0: 6e 20 69 6e 76 61 6c 69 64 20 61 72 67 73 2e 3c n invalid args.<
35d0: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 75 3e 50 6c 65 /li>..<li><u>Ple
35e0: 61 73 65 20 6e 6f 74 65 3c 2f 75 3e 3a 20 74 68 ase note</u>: th
35f0: 69 73 20 73 70 65 63 69 66 69 63 20 66 6c 61 76 is specific flav
3600: 6f 72 20 6f 66 20 3c 62 3e 53 54 5f 41 72 65 61 or of <b>ST_Area
3610: 28 29 3c 2f 62 3e 20 6e 65 63 65 73 73 61 72 69 ()</b> necessari
3620: 6c 79 20 72 65 71 75 69 72 65 73 20 74 68 65 20 ly requires the
3630: 3c 62 3e 4c 57 47 45 4f 4d 3c 2f 62 3e 20 73 75 <b>LWGEOM</b> su
3640: 70 70 6f 72 74 20 74 6f 20 62 65 20 61 63 74 69 pport to be acti
3650: 76 61 74 65 64 20 61 74 20 62 75 69 6c 64 20 74 vated at build t
3660: 69 6d 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e ime.</li>..</ul>
3670: 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 <br>..<hr>..<ver
3680: 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 batim>..SELECT S
3690: 54 5f 41 73 54 65 78 74 28 20 53 54 5f 50 72 6f T_AsText( ST_Pro
36a0: 6a 65 63 74 28 20 4d 61 6b 65 50 6f 69 6e 74 28 ject( MakePoint(
36b0: 20 31 31 2e 35 32 2c 20 34 32 2e 33 38 2c 20 34 11.52, 42.38, 4
36c0: 33 32 36 20 29 2c 20 35 30 30 30 30 2c 20 52 61 326 ), 50000, Ra
36d0: 64 69 61 6e 73 28 20 34 35 20 29 20 29 20 29 3b dians( 45 ) ) );
36e0: 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 50 4f ..----------..PO
36f0: 49 4e 54 28 31 31 2e 39 35 31 34 37 39 20 34 32 INT(11.951479 42
3700: 2e 36 39 37 34 36 37 29 0d 0a 3c 2f 76 65 72 62 .697467)..</verb
3710: 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 53 54 atim>..The <b>ST
3720: 5f 50 72 6f 6a 65 63 74 28 29 3c 2f 62 3e 20 53 _Project()</b> S
3730: 51 4c 20 66 75 6e 63 74 69 6f 6e 20 77 69 6c 6c QL function will
3740: 20 72 65 74 75 72 6e 20 74 68 65 20 64 65 73 74 return the dest
3750: 69 6e 61 74 69 6f 6e 20 50 6f 69 6e 74 20 3c 75 ination Point <u
3760: 3e 6f 6e 20 74 68 65 20 65 6c 6c 69 70 73 6f 69 >on the ellipsoi
3770: 64 3c 2f 75 3e 20 63 6f 72 72 65 73 70 6f 6e 64 d</u> correspond
3780: 69 6e 67 20 74 6f 20 61 20 3c 62 3e 73 74 61 72 ing to a <b>star
3790: 74 5f 70 6f 69 6e 74 3c 2f 62 3e 2c 20 61 20 3c t_point</b>, a <
37a0: 62 3e 64 69 73 74 61 6e 63 65 3c 2f 62 3e 20 61 b>distance</b> a
37b0: 6e 64 20 61 20 3c 62 3e 62 65 61 72 69 6e 67 3c nd a <b>bearing<
37c0: 2f 62 3e 20 28 61 6b 61 20 3c 75 3e 61 7a 69 6d /b> (aka <u>azim
37d0: 75 74 68 3c 2f 75 3e 20 61 6b 61 20 3c 75 3e 64 uth</u> aka <u>d
37e0: 69 72 65 63 74 69 6f 6e 3c 2f 75 3e 20 61 6b 61 irection</u> aka
37f0: 20 3c 75 3e 68 65 61 64 69 6e 67 3c 2f 75 3e 29 <u>heading</u>)
3800: 2e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 74 68 65 ...<ul>..<li>the
3810: 20 3c 62 3e 73 74 61 72 74 5f 70 6f 69 6e 74 3c <b>start_point<
3820: 2f 62 3e 20 69 73 20 65 78 70 65 63 74 65 64 20 /b> is expected
3830: 74 6f 20 61 64 6f 70 74 20 3c 75 3e 67 65 6f 67 to adopt <u>geog
3840: 72 61 70 68 69 63 20 63 6f 6f 72 64 69 6e 61 74 raphic coordinat
3850: 65 73 3c 2f 75 3e 20 28 69 2e 65 2e 20 62 61 73 es</u> (i.e. bas
3860: 65 64 20 6f 6e 20 3c 75 3e 6c 6f 6e 67 69 74 75 ed on <u>longitu
3870: 64 65 3c 2f 75 3e 20 61 6e 64 20 3c 75 3e 6c 61 de</u> and <u>la
3880: 74 69 74 75 64 65 3c 2f 75 3e 20 61 6e 67 6c 65 titude</u> angle
3890: 73 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 74 68 s).</li>..<li>th
38a0: 65 20 3c 62 3e 64 69 73 74 61 6e 63 65 3c 2f 62 e <b>distance</b
38b0: 3e 20 69 73 20 61 6c 77 61 79 73 20 65 78 70 65 > is always expe
38c0: 63 74 65 64 20 74 6f 20 62 65 20 65 78 70 72 65 cted to be expre
38d0: 73 73 65 64 20 69 6e 20 3c 62 3e 6d 65 74 65 72 ssed in <b>meter
38e0: 73 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 s</b>.</li>..<li
38f0: 3e 74 68 65 20 3c 62 3e 61 7a 69 6d 75 74 68 3c >the <b>azimuth<
3900: 2f 62 3e 20 61 6e 67 6c 65 20 69 73 20 65 78 70 /b> angle is exp
3910: 65 63 74 65 64 20 74 6f 20 62 65 20 65 78 70 72 ected to be expr
3920: 65 73 73 65 64 20 69 6e 20 3c 62 3e 72 61 64 69 essed in <b>radi
3930: 61 6e 73 3c 2f 62 3e 3a 0d 0a 3c 75 6c 3e 0d 0a ans</b>:..<ul>..
3940: 3c 6c 69 3e 4e 6f 72 74 68 20 63 6f 72 72 65 73 <li>North corres
3950: 70 6f 6e 64 73 20 74 6f 20 30 20 64 65 67 72 65 ponds to 0 degre
3960: 65 73 20 28 30 20 72 61 64 69 61 6e 73 29 2e 3c es (0 radians).<
3970: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 45 61 73 74 20 63 /li>..<li>East c
3980: 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 39 30 orresponds to 90
3990: 20 64 65 67 72 65 65 73 20 28 50 49 2f 32 20 72 degrees (PI/2 r
39a0: 61 64 69 61 6e 73 29 2e 3c 2f 6c 69 3e 0d 0a 3c adians).</li>..<
39b0: 6c 69 3e 53 6f 75 74 68 20 63 6f 72 72 65 73 70 li>South corresp
39c0: 6f 6e 64 73 20 74 6f 20 31 38 30 20 64 65 67 72 onds to 180 degr
39d0: 65 65 73 20 28 50 49 20 72 61 64 69 61 6e 73 29 ees (PI radians)
39e0: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 57 65 73 74 .</li>..<li>West
39f0: 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 corresponds to
3a00: 32 37 30 20 64 65 67 72 65 65 73 20 28 33 50 49 270 degrees (3PI
3a10: 2f 32 20 72 61 64 69 61 6e 73 29 2e 3c 2f 6c 69 /2 radians).</li
3a20: 3e 0d 0a 3c 6c 69 3e 69 2e 65 2e 20 69 74 20 68 >..<li>i.e. it h
3a30: 61 73 20 74 68 65 20 73 61 6d 65 20 69 64 65 6e as the same iden
3a40: 74 69 63 61 6c 20 6d 65 61 6e 69 6e 67 20 61 73 tical meaning as
3a50: 20 69 6e 20 3c 62 3e 53 54 5f 41 7a 69 6d 75 74 in <b>ST_Azimut
3a60: 68 28 29 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c h()</b>.</li>..<
3a70: 2f 75 6c 3e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 74 /ul></li>..<li>t
3a80: 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 65 78 61 his function exa
3a90: 63 74 6c 79 20 63 6f 72 72 65 73 70 6f 6e 64 73 ctly corresponds
3aa0: 20 74 6f 20 74 68 65 20 6f 6e 65 20 73 75 70 70 to the one supp
3ab0: 6f 72 74 65 64 20 62 79 20 3c 62 3e 50 6f 73 74 orted by <b>Post
3ac0: 47 49 53 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c GIS</b>.</li>..<
3ad0: 6c 69 3e 3c 75 3e 50 6c 65 61 73 65 20 6e 6f 74 li><u>Please not
3ae0: 65 3c 2f 75 3e 3a 20 3c 62 3e 53 54 5f 50 72 6f e</u>: <b>ST_Pro
3af0: 6a 65 63 74 28 29 3c 2f 62 3e 20 6e 65 63 65 73 ject()</b> neces
3b00: 73 61 72 69 6c 79 20 72 65 71 75 69 72 65 73 20 sarily requires
3b10: 74 68 65 20 3c 62 3e 4c 57 47 45 4f 4d 3c 2f 62 the <b>LWGEOM</b
3b20: 3e 20 73 75 70 70 6f 72 74 20 74 6f 20 62 65 20 > support to be
3b30: 61 63 74 69 76 61 74 65 64 20 61 74 20 62 75 69 activated at bui
3b40: 6c 64 20 74 69 6d 65 2e 3c 2f 6c 69 3e 0d 0a 3c ld time.</li>..<
3b50: 2f 75 6c 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a /ul><br>..<hr>..
3b60: 3c 68 33 3e 3c 61 20 6e 61 6d 65 3d 22 75 6e 73 <h3><a name="uns
3b70: 61 66 65 22 3e 55 6e 73 61 66 65 3c 2f 61 3e 20 afe">Unsafe</a>
3b80: 28 62 75 74 20 75 73 65 66 75 6c 29 20 49 6d 70 (but useful) Imp
3b90: 6f 72 74 2f 45 78 70 6f 72 74 20 53 51 4c 20 66 ort/Export SQL f
3ba0: 75 6e 63 74 69 6f 6e 73 3c 2f 68 33 3e 0d 0a 41 unctions</h3>..A
3bb0: 6c 6c 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 ll the following
3bc0: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 73 20 63 SQL functions c
3bd0: 6f 75 6c 64 20 62 65 20 72 65 61 6c 6c 79 20 75 ould be really u
3be0: 73 65 66 75 6c 20 69 6e 20 6f 72 64 65 72 20 74 seful in order t
3bf0: 6f 20 73 75 70 70 6f 72 74 20 49 6d 70 6f 72 74 o support Import
3c00: 2f 45 78 70 6f 72 74 20 6f 70 65 72 61 74 69 6f /Export operatio
3c10: 6e 73 2e 3c 62 72 3e 0d 0a 41 6e 79 77 61 79 20 ns.<br>..Anyway
3c20: 79 6f 75 20 73 68 6f 75 6c 64 20 62 65 20 3c 75 you should be <u
3c30: 3e 77 65 6c 6c 20 61 77 61 72 65 3c 2f 75 3e 20 >well aware</u>
3c40: 74 68 61 74 20 61 6c 6c 20 74 68 65 6d 20 63 6f that all them co
3c50: 75 6c 64 20 62 65 20 70 6f 74 65 6e 74 69 61 6c uld be potential
3c60: 6c 79 20 3c 75 3e 75 6e 73 61 66 65 3c 2f 75 3e ly <u>unsafe</u>
3c70: 20 61 6e 64 20 63 6f 75 6c 64 20 62 65 20 70 6f and could be po
3c80: 74 65 6e 74 69 61 6c 6c 79 20 75 73 65 64 20 62 tentially used b
3c90: 79 20 73 6f 6d 65 20 3c 75 3e 6d 61 6c 69 63 69 y some <u>malici
3ca0: 6f 75 73 20 68 61 63 6b 65 72 3c 2f 75 3e 20 69 ous hacker</u> i
3cb0: 6e 20 6f 72 64 65 72 20 74 6f 20 63 72 65 61 74 n order to creat
3cc0: 65 20 61 6e 64 20 65 78 70 6c 6f 69 74 20 73 6f e and exploit so
3cd0: 6d 65 20 3c 75 3e 73 65 63 75 72 69 74 79 20 62 me <u>security b
3ce0: 72 65 61 63 68 3c 2f 75 3e 2e 3c 62 72 3e 0d 0a reach</u>.<br>..
3cf0: 54 68 65 20 63 61 75 73 65 20 69 73 20 76 65 72 The cause is ver
3d00: 79 20 65 61 73 79 20 74 6f 20 62 65 20 75 6e 64 y easy to be und
3d10: 65 72 73 74 6f 6f 64 3a 20 74 68 65 73 65 20 66 erstood: these f
3d20: 75 6e 63 74 69 6f 6e 73 20 61 6c 6c 6f 77 20 74 unctions allow t
3d30: 6f 20 74 72 61 6e 73 66 65 72 20 61 72 62 69 74 o transfer arbit
3d40: 72 61 72 79 20 70 61 79 6c 6f 61 64 73 20 66 72 rary payloads fr
3d50: 6f 6d 20 2f 20 74 6f 20 74 68 65 20 44 61 74 61 om / to the Data
3d60: 62 61 73 65 20 61 6e 64 20 74 68 65 20 6c 6f 63 base and the loc
3d70: 61 6c 20 46 69 6c 65 2d 53 79 73 74 65 6d 2e 0d al File-System..
3d80: 0a 41 20 6d 61 6c 69 63 69 6f 75 73 20 61 74 74 .A malicious att
3d90: 61 63 6b 20 63 6f 75 6c 64 20 62 65 20 74 68 75 ack could be thu
3da0: 73 20 69 6d 70 6c 65 6d 65 6e 74 65 64 20 65 2e s implemented e.
3db0: 67 2e 20 62 79 20 65 78 65 63 75 74 69 6e 67 20 g. by executing
3dc0: 73 6f 6d 65 20 53 51 4c 20 73 63 72 69 70 74 20 some SQL script
3dd0: 6f 72 20 62 79 20 64 65 66 69 6e 69 6e 67 20 61 or by defining a
3de0: 20 70 75 72 70 6f 73 65 6c 79 20 66 6f 72 67 65 purposely forge
3df0: 64 20 54 72 69 67 67 65 72 2c 20 61 6e 64 20 74 d Trigger, and t
3e00: 68 65 20 65 6e 64 20 75 73 65 72 73 20 77 6f 75 he end users wou
3e10: 6c 64 20 62 65 20 61 62 73 6f 6c 75 74 65 6c 79 ld be absolutely
3e20: 20 75 6e 61 77 61 72 65 20 6f 66 20 77 68 61 74 unaware of what
3e30: 20 69 73 20 72 65 61 6c 6c 79 20 68 61 70 70 65 is really happe
3e40: 6e 69 6e 67 2e 0d 0a 53 6f 20 69 6e 20 6f 72 64 ning...So in ord
3e50: 65 72 20 74 6f 20 65 66 66 65 63 74 69 76 65 6c er to effectivel
3e60: 79 20 73 68 69 65 6c 64 20 75 73 65 72 73 20 61 y shield users a
3e70: 67 61 69 6e 73 74 20 74 68 65 73 65 20 70 6f 74 gainst these pot
3e80: 65 6e 74 69 61 6c 6c 79 20 64 61 6e 67 65 72 6f entially dangero
3e90: 75 73 20 73 65 63 75 72 69 74 79 20 70 69 74 66 us security pitf
3ea0: 61 6c 6c 73 20 61 6c 6c 20 74 68 65 73 65 20 53 alls all these S
3eb0: 51 4c 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 65 QL functions are
3ec0: 20 61 6c 77 61 79 73 20 3c 75 3e 64 69 73 61 62 always <u>disab
3ed0: 6c 65 64 20 62 79 20 64 65 66 61 75 6c 74 3c 2f led by default</
3ee0: 75 3e 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d u>...<verbatim>.
3ef0: 0a 65 78 70 6f 72 74 20 22 53 50 41 54 49 41 4c .export "SPATIAL
3f00: 49 54 45 5f 53 45 43 55 52 49 54 59 3d 72 65 6c ITE_SECURITY=rel
3f10: 61 78 65 64 22 0d 0a 3c 2f 76 65 72 62 61 74 69 axed"..</verbati
3f20: 6d 3e 0d 0a 49 6e 20 6f 72 64 65 72 20 74 6f 20 m>..In order to
3f30: 72 65 61 6c 6c 79 20 65 6e 61 62 6c 65 20 74 68 really enable th
3f40: 65 73 65 20 66 75 6e 63 74 69 6f 6e 73 20 74 68 ese functions th
3f50: 65 20 75 73 65 72 20 69 73 20 72 65 71 75 69 72 e user is requir
3f60: 65 64 20 74 6f 20 74 61 6b 65 20 61 6e 20 65 78 ed to take an ex
3f70: 70 6c 69 63 69 74 20 61 63 74 69 6f 6e 3b 20 69 plicit action; i
3f80: 2e 65 2e 20 74 68 65 20 3c 75 3e 65 6e 76 69 72 .e. the <u>envir
3f90: 6f 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c 65 3c onment variable<
3fa0: 2f 75 3e 20 3c 62 3e 53 50 41 54 49 41 4c 49 54 /u> <b>SPATIALIT
3fb0: 45 5f 53 45 43 55 52 49 54 59 3d 72 65 6c 61 78 E_SECURITY=relax
3fc0: 65 64 3c 2f 62 3e 20 68 61 73 20 74 6f 20 62 65 ed</b> has to be
3fd0: 20 64 65 66 69 6e 65 64 2e 0d 0a 3c 76 65 72 62 defined...<verb
3fe0: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 43 6f atim>..SELECT Co
3ff0: 75 6e 74 55 6e 73 61 66 65 54 72 69 67 67 65 72 untUnsafeTrigger
4000: 73 28 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d s();..---------.
4010: 0a 30 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d .0..</verbatim>.
4020: 0a 54 68 65 20 3c 62 3e 43 6f 75 6e 74 55 6e 73 .The <b>CountUns
4030: 61 66 65 54 72 69 67 67 65 72 73 28 29 3c 2f 62 afeTriggers()</b
4040: 3e 20 61 63 74 75 61 6c 6c 79 20 63 68 65 63 6b > actually check
4050: 73 20 69 66 20 74 68 65 20 63 6f 6e 6e 65 63 74 s if the connect
4060: 65 64 20 44 61 74 61 62 61 73 65 20 64 6f 65 73 ed Database does
4070: 20 63 6f 6e 74 61 69 6e 73 20 61 6e 79 20 73 75 contains any su
4080: 73 70 65 63 74 20 54 72 69 67 67 65 72 3b 20 63 spect Trigger; c
4090: 68 65 63 6b 69 6e 67 20 74 68 69 73 20 76 65 72 hecking this ver
40a0: 73 69 6f 6e 20 62 65 66 6f 72 65 20 65 6e 61 62 sion before enab
40b0: 6c 69 6e 67 20 74 68 65 20 75 6e 73 61 66 65 20 ling the unsafe
40c0: 53 51 4c 20 46 75 6e 63 74 69 6f 6e 73 20 69 73 SQL Functions is
40d0: 20 61 6c 77 61 79 73 20 68 69 67 68 6c 79 20 72 always highly r
40e0: 65 63 6f 6d 6d 65 6e 64 65 64 2e 3c 62 72 3e 0d ecommended.<br>.
40f0: 0a 41 20 72 65 73 75 6c 74 20 64 69 66 66 65 72 .A result differ
4100: 65 6e 74 20 66 72 6f 6d 20 5a 45 52 4f 20 69 6d ent from ZERO im
4110: 70 6c 69 65 73 20 74 68 61 74 20 73 6f 6d 65 20 plies that some
4120: 6d 61 6c 69 63 69 6f 75 73 20 54 72 69 67 67 65 malicious Trigge
4130: 72 20 68 61 73 20 62 65 65 6e 20 69 64 65 6e 74 r has been ident
4140: 69 66 69 65 64 3b 20 69 6e 20 74 68 69 73 20 63 ified; in this c
4150: 61 73 65 20 79 6f 75 20 63 61 6e 20 70 65 72 66 ase you can perf
4160: 6f 72 6d 20 61 20 64 65 65 70 65 73 74 20 69 6e orm a deepest in
4170: 73 70 65 63 74 69 6f 6e 20 62 79 20 65 78 65 63 spection by exec
4180: 75 74 69 6e 67 20 74 68 65 20 66 6f 6c 6c 6f 77 uting the follow
4190: 69 6e 67 20 53 51 4c 20 71 75 65 72 79 3a 0d 0a ing SQL query:..
41a0: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 <verbatim>..SELE
41b0: 43 54 20 74 79 70 65 2c 20 6e 61 6d 65 2c 20 74 CT type, name, t
41c0: 62 6c 5f 6e 61 6d 65 2c 20 73 71 6c 20 0d 0a 46 bl_name, sql ..F
41d0: 52 4f 4d 20 73 71 6c 69 74 65 5f 6d 61 73 74 65 ROM sqlite_maste
41e0: 72 20 0d 0a 57 48 45 52 45 20 74 79 70 65 20 49 r ..WHERE type I
41f0: 4e 20 28 27 74 72 69 67 67 65 72 27 2c 20 27 76 N ('trigger', 'v
4200: 69 65 77 27 29 20 41 4e 44 20 28 73 71 6c 20 4c iew') AND (sql L
4210: 49 4b 45 20 27 25 42 6c 6f 62 46 72 6f 6d 46 69 IKE '%BlobFromFi
4220: 6c 65 25 27 20 0d 0a 20 20 20 4f 52 20 73 71 6c le%' .. OR sql
4230: 20 4c 49 4b 45 20 27 25 42 6c 6f 62 54 6f 46 69 LIKE '%BlobToFi
4240: 6c 65 25 27 20 4f 52 20 73 71 6c 20 4c 49 4b 45 le%' OR sql LIKE
4250: 20 27 25 58 42 5f 4c 6f 61 64 58 4d 4c 25 27 20 '%XB_LoadXML%'
4260: 0d 0a 20 20 20 4f 52 20 73 71 6c 20 4c 49 4b 45 .. OR sql LIKE
4270: 20 27 25 58 42 5f 53 74 6f 72 65 58 4d 4c 25 27 '%XB_StoreXML%'
4280: 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d );..</verbatim>.
4290: 0a 74 68 69 73 20 77 69 6c 6c 20 67 69 76 65 20 .this will give
42a0: 61 20 66 75 6c 6c 20 72 65 70 6f 72 74 20 66 6f a full report fo
42b0: 72 20 61 6e 79 20 6d 61 6c 69 63 69 6f 75 73 20 r any malicious
42c0: 54 72 69 67 67 65 72 20 65 76 65 6e 74 75 61 6c Trigger eventual
42d0: 6c 79 20 66 6f 75 6e 64 2e 3c 62 72 3e 3c 62 72 ly found.<br><br
42e0: 3e 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 >..<hr>..<verbat
42f0: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 42 6c 6f 62 im>..SELECT Blob
4300: 46 72 6f 6d 46 69 6c 65 28 20 27 43 3a 2f 6d 79 FromFile( 'C:/my
4310: 70 69 63 74 75 72 65 73 2f 73 75 6e 73 65 74 2e pictures/sunset.
4320: 6a 70 67 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d jpg' );..-------
4330: 2d 2d 0d 0a 42 4c 4f 42 2d 76 61 6c 75 65 0d 0a --..BLOB-value..
4340: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65 </verbatim>..The
4350: 20 3c 62 3e 42 6c 6f 62 46 72 6f 6d 46 69 6c 65 <b>BlobFromFile
4360: 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 ()</b> SQL funct
4370: 69 6f 6e 20 61 6c 6c 6f 77 73 20 74 6f 20 69 6d ion allows to im
4380: 70 6f 72 74 20 61 20 77 68 6f 6c 65 20 66 69 6c port a whole fil
4390: 65 20 69 6e 20 61 20 73 69 6e 67 6c 65 20 73 74 e in a single st
43a0: 65 70 3b 20 74 68 65 20 66 75 6c 6c 20 66 69 6c ep; the full fil
43b0: 65 20 70 61 79 6c 6f 61 64 20 77 69 6c 6c 20 62 e payload will b
43c0: 65 20 72 65 74 75 72 6e 65 64 20 61 73 20 61 20 e returned as a
43d0: 42 4c 4f 42 20 76 61 6c 75 65 2e 3c 62 72 3e 0d BLOB value.<br>.
43e0: 0a 49 66 20 74 68 65 20 61 72 67 75 6d 65 6e 74 .If the argument
43f0: 20 28 3c 62 3e 66 69 6c 65 2d 70 61 74 68 3c 2f (<b>file-path</
4400: 62 3e 29 20 64 6f 65 73 6e 27 74 20 63 6f 72 72 b>) doesn't corr
4410: 65 73 70 6f 6e 64 73 20 74 6f 20 61 20 76 61 6c esponds to a val
4420: 69 64 20 66 69 6c 65 20 6f 72 20 69 66 20 74 68 id file or if th
4430: 65 20 65 78 74 65 72 6e 61 6c 20 66 69 6c 65 20 e external file
4440: 63 61 6e 6e 6f 74 20 62 65 20 61 63 63 65 73 73 cannot be access
4450: 65 64 20 66 6f 72 20 61 6e 79 20 72 65 61 73 6f ed for any reaso
4460: 6e 20 4e 55 4c 4c 20 77 69 6c 6c 20 62 65 20 72 n NULL will be r
4470: 65 74 75 72 6e 65 64 2e 3c 62 72 3e 3c 62 72 3e eturned.<br><br>
4480: 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 ..<hr>..<verbati
4490: 6d 3e 0d 0a 53 45 4c 45 43 54 20 42 6c 6f 62 54 m>..SELECT BlobT
44a0: 6f 46 69 6c 65 28 20 73 6f 6d 65 42 6c 6f 62 20 oFile( someBlob
44b0: 2c 20 27 43 3a 2f 6d 79 70 69 63 74 75 72 65 73 , 'C:/mypictures
44c0: 2f 73 75 6e 73 65 74 2e 6a 70 67 27 20 29 3b 0d /sunset.jpg' );.
44d0: 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c .---------..1..<
44e0: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 /verbatim>..The
44f0: 3c 62 3e 42 6c 6f 62 54 6f 46 69 6c 65 28 29 3c <b>BlobToFile()<
4500: 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e /b> SQL function
4510: 20 70 65 72 66 6f 72 6d 73 20 74 68 65 20 6f 70 performs the op
4520: 70 6f 73 69 74 65 20 74 61 73 6b 2c 20 69 2e 65 posite task, i.e
4530: 2e 20 69 74 20 65 78 70 6f 72 74 73 20 61 20 77 . it exports a w
4540: 68 6f 6c 65 20 42 4c 4f 42 20 69 6e 74 6f 20 61 hole BLOB into a
4550: 6e 20 65 78 74 65 72 6e 61 6c 20 66 69 6c 65 3b n external file;
4560: 20 74 68 65 20 66 69 72 73 74 20 61 72 67 75 6d the first argum
4570: 65 6e 74 20 6d 75 73 74 20 63 6f 72 72 65 73 70 ent must corresp
4580: 6f 6e 64 20 74 6f 20 73 6f 6d 65 20 42 4c 4f 42 ond to some BLOB
4590: 2c 20 74 68 65 20 73 65 63 6f 6e 64 20 6f 6e 65 , the second one
45a0: 20 69 73 20 74 68 65 20 3c 62 3e 66 69 6c 65 2d is the <b>file-
45b0: 70 61 74 68 3c 2f 62 3e 20 69 64 65 6e 74 69 66 path</b> identif
45c0: 79 69 6e 67 20 74 68 65 20 66 69 6c 65 20 74 6f ying the file to
45d0: 20 62 65 20 63 72 65 61 74 65 64 20 6f 72 20 6f be created or o
45e0: 76 65 72 77 72 69 74 74 65 6e 2e 3c 62 72 3e 3c verwritten.<br><
45f0: 62 72 3e 0d 0a 3c 75 3e 50 6c 65 61 73 65 20 6e br>..<u>Please n
4600: 6f 74 65 3c 2f 75 3e 3a 20 62 6f 74 68 20 3c 62 ote</u>: both <b
4610: 3e 42 6c 6f 62 46 72 6f 6d 46 69 6c 65 28 29 3c >BlobFromFile()<
4620: 2f 62 3e 20 61 6e 64 20 3c 62 3e 42 6c 6f 62 54 /b> and <b>BlobT
4630: 6f 46 69 6c 65 28 29 3c 2f 62 3e 20 77 65 72 65 oFile()</b> were
4640: 20 61 6c 72 65 61 64 79 20 73 75 70 70 6f 72 74 already support
4650: 65 64 20 62 79 20 34 2e 30 2e 30 2c 20 62 75 74 ed by 4.0.0, but
4660: 20 61 20 71 75 69 63 6b 20 72 65 63 61 6c 6c 20 a quick recall
4670: 69 73 20 61 6e 79 77 61 79 20 75 73 65 66 75 6c is anyway useful
4680: 20 73 6f 20 74 6f 20 72 65 63 61 6c 6c 20 61 20 so to recall a
4690: 63 6c 65 61 72 65 72 20 63 6f 6e 74 65 78 74 2e clearer context.
46a0: 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a <br><br>..<hr>..
46b0: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 <verbatim>..SELE
46c0: 43 54 20 58 42 5f 4c 6f 61 64 58 4d 4c 28 20 27 CT XB_LoadXML( '
46d0: 43 3a 2f 6d 79 64 6f 63 73 2f 69 73 6f 6d 65 74 C:/mydocs/isomet
46e0: 61 64 61 74 61 2d 73 61 6d 70 6c 65 2e 78 6d 6c adata-sample.xml
46f0: 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a ' );..--------..
4700: 42 4c 4f 42 2d 76 61 6c 75 65 0d 0a 0d 0a 53 45 BLOB-value....SE
4710: 4c 45 43 54 20 58 42 5f 4c 6f 61 64 58 4d 4c 28 LECT XB_LoadXML(
4720: 20 27 68 74 74 70 3a 2f 2f 77 77 77 2e 61 63 6d 'http://www.acm
4730: 65 2e 63 6f 6d 2f 70 75 62 6c 69 63 2f 69 73 6f e.com/public/iso
4740: 6d 65 74 61 64 61 74 61 2d 73 61 6d 70 6c 65 2e metadata-sample.
4750: 78 6d 6c 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d xml' );..-------
4760: 2d 0d 0a 42 4c 4f 42 2d 76 61 6c 75 65 0d 0a 3c -..BLOB-value..<
4770: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 /verbatim>..The
4780: 3c 62 3e 58 42 5f 4c 6f 61 64 58 4d 4c 28 29 3c <b>XB_LoadXML()<
4790: 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e /b> SQL function
47a0: 20 61 6c 6c 6f 77 73 20 74 6f 20 69 6d 70 6f 72 allows to impor
47b0: 74 20 61 6e 20 58 4d 4c 20 44 6f 63 75 6d 65 6e t an XML Documen
47c0: 74 20 69 6e 20 61 20 73 69 6e 67 6c 65 20 73 74 t in a single st
47d0: 65 70 3a 20 74 68 65 20 66 75 6c 6c 20 58 4d 4c ep: the full XML
47e0: 20 44 6f 63 75 6d 65 6e 74 20 70 61 79 6c 6f 61 Document payloa
47f0: 64 20 77 69 6c 6c 20 62 65 20 72 65 74 75 72 6e d will be return
4800: 65 64 20 61 73 20 61 20 42 4c 4f 42 20 76 61 6c ed as a BLOB val
4810: 75 65 2e 3c 62 72 3e 0d 0a 54 68 65 20 70 61 73 ue.<br>..The pas
4820: 73 65 64 20 61 72 67 75 6d 65 6e 74 20 63 61 6e sed argument can
4830: 20 69 6e 64 69 66 66 65 72 65 6e 74 6c 79 20 62 indifferently b
4840: 65 20 61 20 3c 62 3e 66 69 6c 65 2d 70 61 74 68 e a <b>file-path
4850: 3c 2f 62 3e 20 6f 72 20 61 20 3c 62 3e 55 52 4c </b> or a <b>URL
4860: 3c 2f 62 3e 3b 20 69 66 20 74 68 65 20 64 61 74 </b>; if the dat
4870: 61 73 6f 75 72 63 65 20 63 61 6e 6e 6f 74 20 62 asource cannot b
4880: 65 20 61 63 63 65 73 73 65 64 2c 20 6f 72 20 69 e accessed, or i
4890: 66 20 69 74 20 64 6f 65 73 6e 27 74 20 63 6f 6e f it doesn't con
48a0: 74 61 69 6e 73 20 61 20 3c 75 3e 77 65 6c 6c 2d tains a <u>well-
48b0: 66 6f 72 6d 65 64 3c 2f 75 3e 20 58 4d 4c 20 44 formed</u> XML D
48c0: 6f 63 75 6d 65 6e 74 20 4e 55 4c 4c 20 77 69 6c ocument NULL wil
48d0: 6c 20 62 65 20 72 65 74 75 72 6e 65 64 2e 3c 62 l be returned.<b
48e0: 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 76 r><br>..<hr>..<v
48f0: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 erbatim>..SELECT
4900: 20 58 42 5f 53 74 6f 72 65 58 4d 4c 28 20 73 6f XB_StoreXML( so
4910: 6d 65 58 6d 6c 42 6c 6f 62 2c 20 27 43 3a 2f 6d meXmlBlob, 'C:/m
4920: 79 64 6f 63 73 2f 69 73 6f 6d 65 74 61 64 61 74 ydocs/isometadat
4930: 61 2d 73 61 6d 70 6c 65 2e 78 6d 6c 27 20 29 3b a-sample.xml' );
4940: 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 0d 0a ..---------..1..
4950: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65 </verbatim>..The
4960: 20 3c 62 3e 58 42 5f 53 74 6f 72 65 58 4d 4c 28 <b>XB_StoreXML(
4970: 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 )</b> SQL functi
4980: 6f 6e 20 70 65 72 66 6f 72 6d 73 20 74 68 65 20 on performs the
4990: 6f 70 70 6f 73 69 74 65 20 74 61 73 6b 2c 20 69 opposite task, i
49a0: 2e 65 2e 20 69 74 20 65 78 70 6f 72 74 73 20 61 .e. it exports a
49b0: 20 77 68 6f 6c 65 20 58 6d 6c 42 4c 4f 42 20 69 whole XmlBLOB i
49c0: 6e 74 6f 20 61 6e 20 65 78 74 65 72 6e 61 6c 20 nto an external
49d0: 66 69 6c 65 20 61 73 20 61 6e 20 58 4d 4c 20 44 file as an XML D
49e0: 6f 63 75 6d 65 6e 74 3b 20 74 68 65 20 66 69 72 ocument; the fir
49f0: 73 74 20 61 72 67 75 6d 65 6e 74 20 6d 75 73 74 st argument must
4a00: 20 63 6f 72 72 65 73 70 6f 6e 64 20 74 6f 20 73 correspond to s
4a10: 6f 6d 65 20 76 61 6c 69 64 20 58 6d 6c 42 4c 4f ome valid XmlBLO
4a20: 42 2c 20 74 68 65 20 73 65 63 6f 6e 64 20 6f 6e B, the second on
4a30: 65 20 69 73 20 74 68 65 20 3c 62 3e 66 69 6c 65 e is the <b>file
4a40: 2d 70 61 74 68 3c 2f 62 3e 20 69 64 65 6e 74 69 -path</b> identi
4a50: 66 79 69 6e 67 20 74 68 65 20 66 69 6c 65 20 74 fying the file t
4a60: 6f 20 62 65 20 63 72 65 61 74 65 64 20 6f 72 20 o be created or
4a70: 6f 76 65 72 77 72 69 74 74 65 6e 2e 20 0d 0a 3c overwritten. ..<
4a80: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 verbatim>..SELEC
4a90: 54 20 58 42 5f 53 74 6f 72 65 58 4d 4c 28 20 73 T XB_StoreXML( s
4aa0: 6f 6d 65 58 6d 6c 42 6c 6f 62 2c 20 27 43 3a 2f omeXmlBlob, 'C:/
4ab0: 6d 79 64 6f 63 73 2f 69 73 6f 6d 65 74 61 64 61 mydocs/isometada
4ac0: 74 61 2d 73 61 6d 70 6c 65 2e 78 6d 6c 27 2c 20 ta-sample.xml',
4ad0: 34 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 4 );..---------.
4ae0: 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d .1..</verbatim>.
4af0: 0a 41 20 66 75 72 74 68 65 72 20 6f 70 74 69 6f .A further optio
4b00: 6e 61 6c 20 3c 62 3e 69 6e 64 65 6e 74 61 74 69 nal <b>indentati
4b10: 6f 6e 3c 2f 62 3e 20 61 72 67 75 6d 65 6e 74 20 on</b> argument
4b20: 63 61 6e 20 62 65 20 65 76 65 6e 74 75 61 6c 6c can be eventuall
4b30: 79 20 73 70 65 63 69 66 69 65 64 3b 20 74 68 69 y specified; thi
4b40: 73 20 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 s argument will
4b50: 62 65 20 68 61 6e 64 6c 65 64 20 65 78 61 63 74 be handled exact
4b60: 6c 79 20 69 6e 20 74 68 65 20 73 61 6d 65 20 77 ly in the same w
4b70: 61 79 20 61 6c 72 65 61 64 79 20 73 70 65 63 69 ay already speci
4b80: 66 69 65 64 20 66 6f 72 20 62 6f 74 68 20 3c 62 fied for both <b
4b90: 3e 58 42 5f 47 65 74 50 61 79 6c 6f 61 64 28 29 >XB_GetPayload()
4ba0: 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e 58 42 5f 47 </b> and <b>XB_G
4bb0: 65 74 44 6f 63 75 6d 65 6e 74 28 29 3c 2f 62 3e etDocument()</b>
4bc0: 20 66 75 6e 63 74 69 6f 6e 73 2e 3c 62 72 3e 3c functions.<br><
4bd0: 62 72 3e 0d 0a 3c 68 72 3e 3c 62 72 3e 0d 0a 62 br>..<hr><br>..b
4be0: 61 63 6b 20 74 6f 20 58 6d 6c 42 6c 6f 62 20 3c ack to XmlBlob <
4bf0: 61 20 68 72 65 66 3d 22 68 74 74 70 73 3a 2f 2f a href="https://
4c00: 77 77 77 2e 67 61 69 61 2d 67 69 73 2e 69 74 2f www.gaia-gis.it/
4c10: 66 6f 73 73 69 6c 2f 6c 69 62 73 70 61 74 69 61 fossil/libspatia
4c20: 6c 69 74 65 2f 77 69 6b 69 3f 6e 61 6d 65 3d 58 lite/wiki?name=X
4c30: 6d 6c 42 6c 6f 62 2b 61 6e 64 2b 56 69 72 74 75 mlBlob+and+Virtu
4c40: 61 6c 58 50 61 74 68 22 3e 6d 61 69 6e 20 70 61 alXPath">main pa
4c50: 67 65 3c 2f 61 3e 0a 5a 20 66 62 32 66 33 63 63 ge</a>.Z fb2f3cc
4c60: 38 35 36 36 31 30 66 62 63 65 38 63 35 38 34 38 856610fbce8c5848
4c70: 32 61 34 30 65 64 35 33 37 0a 2a40ed537.