Wiki page
[4.1.0 Changes] by
sandro
2013-06-03 18:26:04.
0000: 44 20 32 30 31 33 2d 30 36 2d 30 33 54 31 38 3a D 2013-06-03T18:
0010: 32 36 3a 30 34 2e 30 34 35 0a 4c 20 34 2e 31 2e 26:04.045.L 4.1.
0020: 30 5c 73 43 68 61 6e 67 65 73 0a 50 20 39 39 34 0\sChanges.P 994
0030: 63 65 61 62 36 33 39 66 62 39 34 31 39 36 63 38 ceab639fb94196c8
0040: 32 36 64 38 33 63 61 65 38 39 65 35 33 31 34 66 26d83cae89e5314f
0050: 63 39 30 37 37 0a 55 20 73 61 6e 64 72 6f 0a 57 c9077.U sandro.W
0060: 20 32 31 34 31 33 0a 62 61 63 6b 20 74 6f 20 3c 21413.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 61 6e ="#uuid">UUID an
0190: 64 20 4d 44 35 3c 2f 61 3e 3c 2f 6c 69 3e 0d 0a d MD5</a></li>..
01a0: 3c 6c 69 3e 53 70 61 74 69 61 6c 20 53 51 4c 20 <li>Spatial SQL
01b0: 66 75 6e 63 74 69 6f 6e 73 20 73 75 70 70 6f 72 functions suppor
01c0: 74 69 6e 67 20 3c 61 20 68 72 65 66 3d 22 23 67 ting <a href="#g
01d0: 65 6f 6d 22 3e 47 65 6f 6d 65 74 72 69 65 73 3c eom">Geometries<
01e0: 2f 61 3e 3c 75 6c 3e 0d 0a 3c 6c 69 3e 53 51 4c /a><ul>..<li>SQL
01f0: 20 66 75 6e 63 74 69 6f 6e 73 20 73 75 70 70 6f functions suppo
0200: 72 74 69 6e 67 20 3c 61 20 68 72 65 66 3d 22 68 rting <a href="h
0210: 74 74 70 73 3a 2f 2f 77 77 77 2e 67 61 69 61 2d ttps://www.gaia-
0220: 67 69 73 2e 69 74 2f 66 6f 73 73 69 6c 2f 6c 69 gis.it/fossil/li
0230: 62 73 70 61 74 69 61 6c 69 74 65 2f 77 69 6b 69 bspatialite/wiki
0240: 3f 6e 61 6d 65 3d 63 69 72 63 6c 65 73 2d 65 6c ?name=circles-el
0250: 6c 69 70 73 65 73 22 3e 43 69 72 63 6c 65 73 20 lipses">Circles
0260: 61 6e 64 20 45 6c 6c 69 70 73 65 73 3c 2f 61 3e and Ellipses</a>
0270: 3c 2f 6c 69 3e 3c 2f 75 6c 3e 3c 2f 6c 69 3e 0d </li></ul></li>.
0280: 0a 3c 6c 69 3e 53 51 4c 20 66 75 6e 63 74 69 6f .<li>SQL functio
0290: 6e 73 20 73 75 70 70 6f 72 74 69 6e 67 20 3c 61 ns supporting <a
02a0: 20 68 72 65 66 3d 22 23 75 6e 73 61 66 65 22 3e href="#unsafe">
02b0: 75 6e 73 61 66 65 3c 2f 61 3e 20 64 69 72 65 63 unsafe</a> direc
02c0: 74 20 49 6d 70 6f 72 74 2f 45 78 70 6f 72 74 3c t Import/Export<
02d0: 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 68 33 /li>..</ul>..<h3
02e0: 3e 3c 61 20 6e 61 6d 65 3d 22 67 65 6e 65 72 69 ><a name="generi
02f0: 63 22 3e 63 61 73 74 3c 2f 61 3e 20 53 51 4c 20 c">cast</a> SQL
0300: 66 75 6e 63 74 69 6f 6e 73 20 2d 20 74 79 70 65 functions - type
0310: 20 63 61 73 74 69 6e 67 3c 2f 68 33 3e 0d 0a 53 casting</h3>..S
0320: 51 4c 69 74 65 20 6f 66 66 65 72 73 20 6a 75 73 QLite offers jus
0330: 74 20 61 20 76 65 72 79 20 62 61 73 69 63 20 74 t a very basic t
0340: 79 70 65 20 63 68 65 63 6b 69 6e 67 3b 20 74 68 ype checking; th
0350: 69 73 20 69 73 20 73 6f 6d 65 74 69 6d 65 73 20 is is sometimes
0360: 75 73 65 66 75 6c 2c 20 62 75 74 20 63 6f 75 6c useful, but coul
0370: 64 20 62 65 20 72 65 61 6c 6c 79 20 61 6e 6e 6f d be really anno
0380: 79 69 6e 67 20 76 65 72 79 20 6f 66 74 65 6e 2e ying very often.
0390: 3c 62 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e <br>..<verbatim>
03a0: 0d 0a 53 45 4c 45 43 54 20 27 31 27 2c 20 54 79 ..SELECT '1', Ty
03b0: 70 65 4f 66 28 20 27 31 27 20 29 2c 20 43 41 53 peOf( '1' ), CAS
03c0: 54 20 28 20 27 31 27 20 41 53 20 49 4e 54 45 47 T ( '1' AS INTEG
03d0: 45 52 20 29 2c 20 54 79 70 65 4f 66 28 20 43 41 ER ), TypeOf( CA
03e0: 53 54 20 28 20 27 31 27 20 41 53 20 49 4e 54 45 ST ( '1' AS INTE
03f0: 47 45 52 20 29 20 29 3b 0d 0a 3c 2f 76 65 72 62 GER ) );..</verb
0400: 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c 65 20 62 6f atim>..<table bo
0410: 72 64 65 72 3d 22 31 22 20 63 65 6c 6c 73 70 61 rder="1" cellspa
0420: 63 69 6e 67 3d 22 34 22 20 63 65 6c 6c 70 61 64 cing="4" cellpad
0430: 64 69 6e 67 3d 22 34 22 3e 0d 0a 3c 74 72 3e 3c ding="4">..<tr><
0440: 74 68 3e 27 31 27 3c 2f 74 68 3e 3c 74 68 3e 54 th>'1'</th><th>T
0450: 79 70 65 4f 66 28 20 27 31 27 20 29 3c 2f 74 68 ypeOf( '1' )</th
0460: 3e 3c 74 68 3e 43 41 53 54 20 28 20 27 31 27 20 ><th>CAST ( '1'
0470: 41 53 20 49 4e 54 45 47 45 52 20 29 3c 2f 74 68 AS INTEGER )</th
0480: 3e 3c 74 68 3e 54 79 70 65 4f 66 28 20 43 41 53 ><th>TypeOf( CAS
0490: 54 20 28 20 27 31 27 20 41 53 20 49 4e 54 45 47 T ( '1' AS INTEG
04a0: 45 52 20 29 20 29 3c 2f 74 68 3e 3c 2f 74 72 3e ER ) )</th></tr>
04b0: 0d 0a 3c 74 72 3e 3c 74 64 3e 31 3c 2f 74 64 3e ..<tr><td>1</td>
04c0: 3c 74 64 3e 74 65 78 74 3c 2f 74 64 3e 3c 74 64 <td>text</td><td
04d0: 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 31 align="right">1
04e0: 3c 2f 74 64 3e 3c 74 64 3e 69 6e 74 65 67 65 72 </td><td>integer
04f0: 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c </td></tr></tabl
0500: 65 3e 3c 62 72 3e 0d 0a 54 68 65 20 53 51 4c 20 e><br>..The SQL
0510: 3c 62 3e 43 41 53 54 3c 2f 62 3e 20 6f 70 65 72 <b>CAST</b> oper
0520: 61 74 6f 72 20 61 6c 72 65 61 64 79 20 73 75 70 ator already sup
0530: 70 6f 72 74 73 20 74 68 65 20 70 6f 73 73 69 62 ports the possib
0540: 69 6c 69 74 79 20 74 6f 20 65 78 70 6c 69 63 69 ility to explici
0550: 74 6c 79 20 73 65 74 20 61 20 64 61 74 61 2d 74 tly set a data-t
0560: 79 70 65 3b 20 6e 6f 77 20 73 74 61 72 74 69 6e ype; now startin
0570: 67 20 73 69 6e 63 65 20 34 2e 31 2e 30 20 53 70 g since 4.1.0 Sp
0580: 61 74 69 61 4c 69 74 65 20 73 75 70 70 6f 72 74 atiaLite support
0590: 73 20 66 65 77 20 53 51 4c 20 66 75 6e 63 74 69 s few SQL functi
05a0: 6f 6e 73 20 70 65 72 66 6f 72 6d 69 6e 67 20 74 ons performing t
05b0: 68 65 20 73 61 6d 65 20 74 61 73 6b 2e 3c 62 72 he same task.<br
05c0: 3e 0d 0a 3c 75 3e 50 6c 65 61 73 65 20 6e 6f 74 >..<u>Please not
05d0: 65 3c 2f 75 3e 3a 20 73 6f 6d 65 20 73 75 62 74 e</u>: some subt
05e0: 6c 65 20 64 69 66 66 65 72 65 6e 63 65 73 20 65 le differences e
05f0: 78 69 73 74 73 20 68 65 72 65 20 61 6e 64 20 74 xists here and t
0600: 68 65 72 65 3b 20 70 6c 65 61 73 65 20 63 61 72 here; please car
0610: 65 66 75 6c 6c 79 20 72 65 61 64 20 74 68 69 73 efully read this
0620: 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e 20 70 documentation p
0630: 61 67 65 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e age...<verbatim>
0640: 0d 0a 53 45 4c 45 43 54 20 43 61 73 74 54 6f 49 ..SELECT CastToI
0650: 6e 74 65 67 65 72 28 20 31 20 29 2c 20 43 61 73 nteger( 1 ), Cas
0660: 74 54 6f 49 6e 74 65 67 65 72 28 20 31 2e 34 20 tToInteger( 1.4
0670: 29 2c 20 43 61 73 74 54 6f 49 6e 74 65 67 65 72 ), CastToInteger
0680: 28 20 31 2e 36 20 29 2c 20 0d 0a 20 20 20 20 43 ( 1.6 ), .. C
0690: 61 73 74 54 6f 49 6e 74 65 67 65 72 28 20 27 31 astToInteger( '1
06a0: 32 33 27 20 29 2c 20 43 61 73 74 54 6f 49 6e 74 23' ), CastToInt
06b0: 65 67 65 72 28 20 27 61 6c 70 68 61 27 20 29 2c eger( 'alpha' ),
06c0: 20 43 61 73 74 54 6f 49 6e 74 65 67 65 72 20 28 CastToInteger (
06d0: 20 7a 65 72 6f 62 6c 6f 62 28 34 29 20 29 3b 0d zeroblob(4) );.
06e0: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 74 .</verbatim>..<t
06f0: 61 62 6c 65 20 62 6f 72 64 65 72 3d 22 31 22 20 able border="1"
0700: 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 34 22 20 cellspacing="4"
0710: 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 34 22 3e cellpadding="4">
0720: 0d 0a 3c 74 72 3e 3c 74 68 3e 43 61 73 74 54 6f ..<tr><th>CastTo
0730: 49 6e 74 65 67 65 72 28 20 31 20 29 3c 2f 74 68 Integer( 1 )</th
0740: 3e 3c 74 68 3e 43 61 73 74 54 6f 49 6e 74 65 67 ><th>CastToInteg
0750: 65 72 28 20 31 2e 34 20 29 3c 2f 74 68 3e 3c 74 er( 1.4 )</th><t
0760: 68 3e 43 61 73 74 54 6f 49 6e 74 65 67 65 72 28 h>CastToInteger(
0770: 20 31 2e 36 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 1.6 )</th><th>C
0780: 61 73 74 54 6f 49 6e 74 65 67 65 72 28 20 27 31 astToInteger( '1
0790: 32 33 27 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 61 23' )</th><th>Ca
07a0: 73 74 54 6f 49 6e 74 65 67 65 72 28 20 27 61 6c stToInteger( 'al
07b0: 70 68 61 27 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 pha' )</th><th>C
07c0: 61 73 74 54 6f 49 6e 74 65 67 65 72 20 28 20 7a astToInteger ( z
07d0: 65 72 6f 62 6c 6f 62 28 34 29 20 29 3c 2f 74 68 eroblob(4) )</th
07e0: 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 ></tr>..<tr><td
07f0: 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 31 3c align="right">1<
0800: 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72 /td><td align="r
0810: 69 67 68 74 22 3e 31 3c 2f 74 64 3e 3c 74 64 20 ight">1</td><td
0820: 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 32 3c align="right">2<
0830: 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72 /td><td align="r
0840: 69 67 68 74 22 3e 31 32 33 3c 2f 74 64 3e 3c 74 ight">123</td><t
0850: 64 3e 4e 55 4c 4c 3c 2f 74 64 3e 3c 74 64 3e 4e d>NULL</td><td>N
0860: 55 4c 4c 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 ULL</td></tr></t
0870: 61 62 6c 65 3e 3c 62 72 3e 0d 0a 54 68 65 20 3c able><br>..The <
0880: 62 3e 43 61 73 74 54 6f 49 6e 74 65 67 65 72 28 b>CastToInteger(
0890: 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 )</b> SQL functi
08a0: 6f 6e 20 77 69 6c 6c 20 61 74 74 65 6d 70 74 20 on will attempt
08b0: 74 6f 20 72 65 74 75 72 6e 20 61 20 76 61 6c 75 to return a valu
08c0: 65 20 6f 66 20 74 68 65 20 3c 62 3e 49 6e 74 65 e of the <b>Inte
08d0: 67 65 72 3c 2f 62 3e 20 64 61 74 61 2d 74 79 70 ger</b> data-typ
08e0: 65 2c 20 6f 72 20 3c 62 3e 4e 55 4c 4c 3c 2f 62 e, or <b>NULL</b
08f0: 3e 20 69 66 20 6e 6f 20 63 6f 6e 76 65 72 73 69 > if no conversi
0900: 6f 6e 20 69 73 20 70 6f 73 73 69 62 6c 65 2e 0d on is possible..
0910: 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 6e 20 49 6e .<ul>..<li>an In
0920: 74 65 67 65 72 20 69 6e 70 75 74 20 61 72 67 75 teger input argu
0930: 6d 65 6e 74 20 77 69 6c 6c 20 62 65 20 72 65 74 ment will be ret
0940: 75 72 6e 65 64 20 61 62 73 6f 6c 75 74 65 6c 79 urned absolutely
0950: 20 75 6e 61 66 66 65 63 74 65 64 2e 3c 2f 6c 69 unaffected.</li
0960: 3e 0d 0a 3c 6c 69 3e 61 20 44 6f 75 62 6c 65 20 >..<li>a Double
0970: 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77 input argument w
0980: 69 6c 6c 20 72 65 74 75 72 6e 20 74 68 65 20 3c ill return the <
0990: 75 3e 6e 65 61 72 65 73 74 3c 2f 75 3e 20 49 6e u>nearest</u> In
09a0: 74 65 67 65 72 20 76 61 6c 75 65 20 28 61 66 74 teger value (aft
09b0: 65 72 20 61 70 70 6c 79 69 6e 67 20 3c 62 3e 34 er applying <b>4
09c0: 2f 35 3c 2f 62 3e 20 72 6f 75 6e 64 69 6e 67 29 /5</b> rounding)
09d0: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 54 65 .</li>..<li>a Te
09e0: 78 74 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e xt input argumen
09f0: 74 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 74 68 t will return th
0a00: 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 e corresponding
0a10: 49 6e 74 65 67 65 72 20 76 61 6c 75 65 20 6f 6e Integer value on
0a20: 6c 79 20 69 66 20 74 68 65 20 74 65 78 74 20 73 ly if the text s
0a30: 74 72 69 6e 67 20 72 65 70 72 65 73 65 6e 74 73 tring represents
0a40: 20 61 20 76 61 6c 69 64 20 6e 75 6d 62 65 72 20 a valid number
0a50: 28 65 76 65 6e 20 61 20 64 65 63 69 6d 61 6c 20 (even a decimal
0a60: 6f 6e 65 29 3a 20 69 66 20 74 68 65 20 74 65 78 one): if the tex
0a70: 74 20 73 74 72 69 6e 67 20 63 61 6e 6e 6f 74 20 t string cannot
0a80: 62 65 20 63 6f 6e 76 65 72 74 65 64 20 74 6f 20 be converted to
0a90: 61 20 6e 75 6d 62 65 72 20 4e 55 4c 4c 20 77 69 a number NULL wi
0aa0: 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 2e 3c ll be returned.<
0ab0: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 42 4c /li>..<li>any BL
0ac0: 4f 42 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e OB input argumen
0ad0: 74 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 61 20 t will return a
0ae0: 4e 55 4c 4c 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e NULL value.</li>
0af0: 0d 0a 3c 6c 69 3e 61 6e 79 20 4e 55 4c 4c 20 69 ..<li>any NULL i
0b00: 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 nput argument wi
0b10: 6c 6c 20 72 65 74 75 72 6e 20 61 20 4e 55 4c 4c ll return a NULL
0b20: 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f value.</li>..</
0b30: 75 6c 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c ul><br>..<hr>..<
0b40: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 verbatim>..SELEC
0b50: 54 20 43 61 73 74 54 6f 44 6f 75 62 6c 65 28 20 T CastToDouble(
0b60: 31 20 29 2c 20 43 61 73 74 54 6f 44 6f 75 62 6c 1 ), CastToDoubl
0b70: 65 28 20 31 2e 32 33 20 29 2c 20 43 61 73 74 54 e( 1.23 ), CastT
0b80: 6f 44 6f 75 62 6c 65 28 20 27 31 32 33 2e 34 35 oDouble( '123.45
0b90: 27 20 29 2c 0d 0a 20 20 20 20 43 61 73 74 54 6f ' ),.. CastTo
0ba0: 44 6f 75 62 6c 65 28 20 27 61 6c 70 68 61 27 20 Double( 'alpha'
0bb0: 29 2c 20 43 61 73 74 54 6f 44 6f 75 62 6c 65 20 ), CastToDouble
0bc0: 28 20 7a 65 72 6f 62 6c 6f 62 28 34 29 20 29 3b ( zeroblob(4) );
0bd0: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c ..</verbatim>..<
0be0: 74 61 62 6c 65 20 62 6f 72 64 65 72 3d 22 31 22 table border="1"
0bf0: 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 34 22 cellspacing="4"
0c00: 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 34 22 cellpadding="4"
0c10: 3e 0d 0a 3c 74 72 3e 3c 74 68 3e 43 61 73 74 54 >..<tr><th>CastT
0c20: 6f 44 6f 75 62 6c 65 28 20 31 20 29 3c 2f 74 68 oDouble( 1 )</th
0c30: 3e 3c 74 68 3e 43 61 73 74 54 6f 44 6f 75 62 6c ><th>CastToDoubl
0c40: 65 28 20 31 2e 32 33 20 29 3c 2f 74 68 3e 3c 74 e( 1.23 )</th><t
0c50: 68 3e 43 61 73 74 54 6f 44 6f 75 62 6c 65 28 20 h>CastToDouble(
0c60: 27 31 32 33 2e 34 35 27 20 29 3c 2f 74 68 3e 3c '123.45' )</th><
0c70: 74 68 3e 43 61 73 74 54 6f 44 6f 75 62 6c 65 28 th>CastToDouble(
0c80: 20 27 61 6c 70 68 61 27 20 29 3c 2f 74 68 3e 3c 'alpha' )</th><
0c90: 74 68 3e 43 61 73 74 54 6f 44 6f 75 62 6c 65 20 th>CastToDouble
0ca0: 28 20 7a 65 72 6f 62 6c 6f 62 28 34 29 20 29 3c ( zeroblob(4) )<
0cb0: 2f 74 68 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c /th></tr>..<tr><
0cc0: 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 td align="right"
0cd0: 3e 31 2e 30 30 30 30 30 30 3c 2f 74 64 3e 3c 74 >1.000000</td><t
0ce0: 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e d align="right">
0cf0: 31 2e 32 33 30 30 30 30 3c 2f 74 64 3e 3c 74 64 1.230000</td><td
0d00: 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 31 align="right">1
0d10: 32 33 2e 34 35 30 30 30 3c 2f 74 64 3e 3c 74 64 23.45000</td><td
0d20: 3e 4e 55 4c 4c 3c 2f 74 64 3e 3c 74 64 3e 4e 55 >NULL</td><td>NU
0d30: 4c 4c 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 LL</td></tr></ta
0d40: 62 6c 65 3e 3c 62 72 3e 0d 0a 54 68 65 20 3c 62 ble><br>..The <b
0d50: 3e 43 61 73 74 54 6f 44 6f 75 62 6c 65 28 29 3c >CastToDouble()<
0d60: 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e /b> SQL function
0d70: 20 77 69 6c 6c 20 61 74 74 65 6d 70 74 20 74 6f will attempt to
0d80: 20 72 65 74 75 72 6e 20 61 20 76 61 6c 75 65 20 return a value
0d90: 6f 66 20 74 68 65 20 3c 62 3e 44 6f 75 62 6c 65 of the <b>Double
0da0: 3c 2f 62 3e 20 64 61 74 61 2d 74 79 70 65 2c 20 </b> data-type,
0db0: 6f 72 20 3c 62 3e 4e 55 4c 4c 3c 2f 62 3e 20 69 or <b>NULL</b> i
0dc0: 66 20 6e 6f 20 63 6f 6e 76 65 72 73 69 6f 6e 20 f no conversion
0dd0: 69 73 20 70 6f 73 73 69 62 6c 65 2e 0d 0a 3c 75 is possible...<u
0de0: 6c 3e 0d 0a 3c 6c 69 3e 61 6e 20 49 6e 74 65 67 l>..<li>an Integ
0df0: 65 72 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e er input argumen
0e00: 74 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 74 68 t will return th
0e10: 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 e corresponding
0e20: 44 6f 75 62 6c 65 20 76 61 6c 75 65 2e 3c 2f 6c Double value.</l
0e30: 69 3e 0d 0a 3c 6c 69 3e 61 20 44 6f 75 62 6c 65 i>..<li>a Double
0e40: 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 input argument
0e50: 77 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 will be returned
0e60: 20 61 62 73 6f 6c 75 74 65 6c 79 20 75 6e 61 66 absolutely unaf
0e70: 66 65 63 74 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c fected.</li>..<l
0e80: 69 3e 61 20 54 65 78 74 20 69 6e 70 75 74 20 61 i>a Text input a
0e90: 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 72 65 74 rgument will ret
0ea0: 75 72 6e 20 74 68 65 20 63 6f 72 72 65 73 70 6f urn the correspo
0eb0: 6e 64 69 6e 67 20 44 6f 75 62 6c 65 20 76 61 6c nding Double val
0ec0: 75 65 20 6f 6e 6c 79 20 69 66 20 74 68 65 20 74 ue only if the t
0ed0: 65 78 74 20 73 74 72 69 6e 67 20 72 65 70 72 65 ext string repre
0ee0: 73 65 6e 74 73 20 61 20 76 61 6c 69 64 20 6e 75 sents a valid nu
0ef0: 6d 62 65 72 3a 20 69 66 20 74 68 65 20 74 65 78 mber: if the tex
0f00: 74 20 73 74 72 69 6e 67 20 63 61 6e 6e 6f 74 20 t string cannot
0f10: 62 65 20 63 6f 6e 76 65 72 74 65 64 20 74 6f 20 be converted to
0f20: 61 20 6e 75 6d 62 65 72 20 4e 55 4c 4c 20 77 69 a number NULL wi
0f30: 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 2e 3c ll be returned.<
0f40: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 42 4c /li>..<li>any BL
0f50: 4f 42 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e OB input argumen
0f60: 74 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 61 20 t will return a
0f70: 4e 55 4c 4c 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e NULL value.</li>
0f80: 0d 0a 3c 6c 69 3e 61 6e 79 20 4e 55 4c 4c 20 69 ..<li>any NULL i
0f90: 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 nput argument wi
0fa0: 6c 6c 20 72 65 74 75 72 6e 20 61 20 4e 55 4c 4c ll return a NULL
0fb0: 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f value.</li>..</
0fc0: 75 6c 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c ul><br>..<hr>..<
0fd0: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 verbatim>..SELEC
0fe0: 54 20 43 61 73 74 54 6f 54 65 78 74 28 20 31 20 T CastToText( 1
0ff0: 29 2c 20 43 61 73 74 54 6f 54 65 78 74 28 20 31 ), CastToText( 1
1000: 2e 35 20 29 2c 20 43 61 73 74 54 6f 54 65 78 74 .5 ), CastToText
1010: 28 20 27 61 6c 70 68 61 27 20 29 2c 20 43 61 73 ( 'alpha' ), Cas
1020: 74 54 6f 54 65 78 74 20 28 20 7a 65 72 6f 62 6c tToText ( zerobl
1030: 6f 62 28 34 29 20 29 3b 0d 0a 3c 2f 76 65 72 62 ob(4) );..</verb
1040: 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c 65 20 62 6f atim>..<table bo
1050: 72 64 65 72 3d 22 31 22 20 63 65 6c 6c 73 70 61 rder="1" cellspa
1060: 63 69 6e 67 3d 22 34 22 20 63 65 6c 6c 70 61 64 cing="4" cellpad
1070: 64 69 6e 67 3d 22 34 22 3e 0d 0a 3c 74 72 3e 3c ding="4">..<tr><
1080: 74 68 3e 43 61 73 74 54 6f 54 65 78 74 28 20 31 th>CastToText( 1
1090: 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 61 73 74 54 )</th><th>CastT
10a0: 6f 54 65 78 74 28 20 31 2e 35 20 29 3c 2f 74 68 oText( 1.5 )</th
10b0: 3e 3c 74 68 3e 43 61 73 74 54 6f 54 65 78 74 28 ><th>CastToText(
10c0: 20 27 61 6c 70 68 61 27 20 29 3c 2f 74 68 3e 3c 'alpha' )</th><
10d0: 74 68 3e 43 61 73 74 54 6f 54 65 78 74 20 28 20 th>CastToText (
10e0: 7a 65 72 6f 62 6c 6f 62 28 34 29 20 29 3c 2f 74 zeroblob(4) )</t
10f0: 68 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 h></tr>..<tr><td
1100: 3e 31 3c 2f 74 64 3e 3c 74 64 3e 31 2e 35 3c 2f >1</td><td>1.5</
1110: 74 64 3e 3c 74 64 3e 61 6c 70 68 61 3c 2f 74 64 td><td>alpha</td
1120: 3e 3c 74 64 3e 4e 55 4c 4c 3c 2f 74 64 3e 3c 2f ><td>NULL</td></
1130: 74 72 3e 3c 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d tr></table><br>.
1140: 0a 54 68 65 20 3c 62 3e 43 61 73 74 54 6f 54 65 .The <b>CastToTe
1150: 78 74 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e xt()</b> SQL fun
1160: 63 74 69 6f 6e 20 77 69 6c 6c 20 61 74 74 65 6d ction will attem
1170: 70 74 20 74 6f 20 72 65 74 75 72 6e 20 61 20 76 pt to return a v
1180: 61 6c 75 65 20 6f 66 20 74 68 65 20 3c 62 3e 54 alue of the <b>T
1190: 65 78 74 3c 2f 62 3e 20 64 61 74 61 2d 74 79 70 ext</b> data-typ
11a0: 65 2c 20 6f 72 20 3c 62 3e 4e 55 4c 4c 3c 2f 62 e, or <b>NULL</b
11b0: 3e 20 69 66 20 6e 6f 20 63 6f 6e 76 65 72 73 69 > if no conversi
11c0: 6f 6e 20 69 73 20 70 6f 73 73 69 62 6c 65 2e 0d on is possible..
11d0: 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 6e 20 49 6e .<ul>..<li>an In
11e0: 74 65 67 65 72 20 69 6e 70 75 74 20 61 72 67 75 teger input argu
11f0: 6d 65 6e 74 20 77 69 6c 6c 20 72 65 74 75 72 6e ment will return
1200: 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 the correspondi
1210: 6e 67 20 54 65 78 74 20 76 61 6c 75 65 2e 3c 2f ng Text value.</
1220: 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 44 6f 75 62 6c li>..<li>a Doubl
1230: 65 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 e input argument
1240: 20 77 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 20 will be return
1250: 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e the correspondin
1260: 67 20 54 65 78 74 20 76 61 6c 75 65 3b 20 6e 6f g Text value; no
1270: 20 73 69 67 6e 69 66 69 63 61 6e 74 20 64 65 63 significant dec
1280: 69 6d 61 6c 20 64 69 67 69 74 20 77 69 6c 6c 20 imal digit will
1290: 62 65 20 73 75 70 70 72 65 73 73 65 64 2e 3c 2f be suppressed.</
12a0: 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 54 65 78 74 20 li>..<li>a Text
12b0: 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77 input argument w
12c0: 69 6c 6c 20 72 65 74 75 72 6e 20 74 68 65 20 63 ill return the c
12d0: 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 44 6f 75 orresponding Dou
12e0: 62 6c 65 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d ble value.</li>.
12f0: 0a 3c 6c 69 3e 61 6e 79 20 42 4c 4f 42 20 69 6e .<li>any BLOB in
1300: 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 6c put argument wil
1310: 6c 20 72 65 74 75 72 6e 20 61 20 4e 55 4c 4c 20 l return a NULL
1320: 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 value.</li>..<li
1330: 3e 61 6e 79 20 4e 55 4c 4c 20 69 6e 70 75 74 20 >any NULL input
1340: 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 72 65 argument will re
1350: 74 75 72 6e 20 61 20 4e 55 4c 4c 20 76 61 6c 75 turn a NULL valu
1360: 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a e.</li>..</ul>..
1370: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 <verbatim>..SELE
1380: 43 54 20 43 61 73 74 54 6f 54 65 78 74 28 20 31 CT CastToText( 1
1390: 2c 20 34 20 29 2c 20 43 61 73 74 54 6f 54 65 78 , 4 ), CastToTex
13a0: 74 28 20 31 32 33 34 2c 20 32 20 29 2c 20 43 61 t( 1234, 2 ), Ca
13b0: 73 74 54 6f 54 65 78 74 28 20 31 2c 20 38 20 29 stToText( 1, 8 )
13c0: 2c 20 43 61 73 74 54 6f 54 65 78 74 28 20 31 2e , CastToText( 1.
13d0: 35 2c 20 34 20 29 3b 0d 0a 3c 2f 76 65 72 62 61 5, 4 );..</verba
13e0: 74 69 6d 3e 0d 0a 3c 74 61 62 6c 65 20 62 6f 72 tim>..<table bor
13f0: 64 65 72 3d 22 31 22 20 63 65 6c 6c 73 70 61 63 der="1" cellspac
1400: 69 6e 67 3d 22 34 22 20 63 65 6c 6c 70 61 64 64 ing="4" cellpadd
1410: 69 6e 67 3d 22 34 22 3e 0d 0a 3c 74 72 3e 3c 74 ing="4">..<tr><t
1420: 68 3e 43 61 73 74 54 6f 54 65 78 74 28 20 31 2c h>CastToText( 1,
1430: 20 34 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 61 73 4 )</th><th>Cas
1440: 74 54 6f 54 65 78 74 28 20 31 32 33 34 2c 20 32 tToText( 1234, 2
1450: 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 61 73 74 54 )</th><th>CastT
1460: 6f 54 65 78 74 28 20 31 2c 20 38 20 29 3c 2f 74 oText( 1, 8 )</t
1470: 68 3e 3c 74 68 3e 43 61 73 74 54 6f 54 65 78 74 h><th>CastToText
1480: 28 20 31 2e 35 2c 20 34 20 29 3c 2f 74 68 3e 3c ( 1.5, 4 )</th><
1490: 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 30 30 /tr>..<tr><td>00
14a0: 30 31 3c 2f 74 64 3e 3c 74 64 3e 31 32 33 34 3c 01</td><td>1234<
14b0: 2f 74 64 3e 3c 74 64 3e 30 30 30 30 30 30 30 31 /td><td>00000001
14c0: 3c 2f 74 64 3e 3c 74 64 3e 30 30 30 31 2e 35 3c </td><td>0001.5<
14d0: 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 /td></tr></table
14e0: 3e 3c 62 72 3e 0d 0a 41 6e 20 6f 76 65 72 6c 6f ><br>..An overlo
14f0: 61 64 65 64 20 76 65 72 73 69 6f 6e 20 6f 66 20 aded version of
1500: 3c 62 3e 43 61 73 74 54 6f 54 65 78 74 28 29 3c <b>CastToText()<
1510: 2f 62 3e 20 69 73 20 73 75 70 70 6f 72 74 65 64 /b> is supported
1520: 20 61 73 20 77 65 6c 6c 2c 20 62 75 74 20 6f 6e as well, but on
1530: 6c 79 20 77 68 65 6e 20 74 68 65 20 69 6e 70 75 ly when the inpu
1540: 74 20 61 72 67 75 6d 65 6e 74 20 69 73 20 6f 66 t argument is of
1550: 20 74 68 65 20 49 6e 74 65 67 65 72 20 6f 72 20 the Integer or
1560: 44 6f 75 62 6c 65 20 64 61 74 61 2d 74 79 70 65 Double data-type
1570: 3a 20 69 6e 20 74 68 69 73 20 63 61 73 65 20 61 : in this case a
1580: 20 73 65 63 6f 6e 64 20 49 6e 74 65 67 65 72 20 second Integer
1590: 61 72 67 75 6d 65 6e 74 20 63 6f 75 6c 64 20 62 argument could b
15a0: 65 20 6f 70 74 69 6f 6e 61 6c 6c 79 20 73 70 65 e optionally spe
15b0: 63 69 66 69 65 64 2c 20 61 6e 64 20 77 69 6c 6c cified, and will
15c0: 20 62 65 20 69 6e 74 65 72 70 72 65 74 65 64 20 be interpreted
15d0: 61 64 20 3c 62 3e 7a 65 72 6f 2d 70 61 64 64 69 ad <b>zero-paddi
15e0: 6e 67 2d 6c 65 6e 67 74 68 3c 2f 62 3e 2e 3c 62 ng-length</b>.<b
15f0: 72 3e 0d 0a 69 2e 65 2e 20 74 68 65 20 72 65 74 r>..i.e. the ret
1600: 75 72 6e 65 64 20 54 65 78 74 20 73 74 72 69 6e urned Text strin
1610: 67 20 69 6e 20 74 68 69 73 20 63 61 73 65 20 77 g in this case w
1620: 69 6c 6c 20 68 61 76 65 20 61 6e 20 69 6e 74 65 ill have an inte
1630: 67 65 72 20 70 61 72 74 20 61 74 20 6c 65 61 73 ger part at leas
1640: 74 20 6f 66 20 74 68 65 20 73 70 65 63 69 66 69 t of the specifi
1650: 65 64 20 6c 65 6e 67 74 68 2c 20 61 6e 64 20 65 ed length, and e
1660: 76 65 6e 74 75 61 6c 6c 79 20 70 61 64 64 65 64 ventually padded
1670: 20 62 79 20 69 6e 73 65 72 74 69 6e 67 20 6e 6f by inserting no
1680: 74 20 73 69 67 6e 69 66 69 63 61 6e 74 20 6c 65 t significant le
1690: 61 64 69 6e 67 20 5a 45 52 4f 65 73 2e 3c 62 72 ading ZEROes.<br
16a0: 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 ><br>..<hr>..<ve
16b0: 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 rbatim>..SELECT
16c0: 43 61 73 74 54 6f 42 6c 6f 62 28 20 31 20 29 2c CastToBlob( 1 ),
16d0: 20 43 61 73 74 54 6f 42 6c 6f 62 28 20 31 2e 35 CastToBlob( 1.5
16e0: 20 29 2c 20 48 65 78 28 20 43 61 73 74 54 6f 42 ), Hex( CastToB
16f0: 6c 6f 62 28 20 27 61 6c 70 68 61 27 20 29 20 29 lob( 'alpha' ) )
1700: 2c 20 48 65 78 20 28 20 43 61 73 74 54 6f 42 6c , Hex ( CastToBl
1710: 6f 62 20 28 20 7a 65 72 6f 62 6c 6f 62 28 34 29 ob ( zeroblob(4)
1720: 20 29 20 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 ) );..</verbati
1730: 6d 3e 0d 0a 3c 74 61 62 6c 65 20 62 6f 72 64 65 m>..<table borde
1740: 72 3d 22 31 22 20 63 65 6c 6c 73 70 61 63 69 6e r="1" cellspacin
1750: 67 3d 22 34 22 20 63 65 6c 6c 70 61 64 64 69 6e g="4" cellpaddin
1760: 67 3d 22 34 22 3e 0d 0a 3c 74 72 3e 3c 74 68 3e g="4">..<tr><th>
1770: 43 61 73 74 54 6f 42 6c 6f 62 28 20 31 20 29 3c CastToBlob( 1 )<
1780: 2f 74 68 3e 3c 74 68 3e 43 61 73 74 54 6f 42 6c /th><th>CastToBl
1790: 6f 62 28 20 31 2e 35 20 29 3c 2f 74 68 3e 3c 74 ob( 1.5 )</th><t
17a0: 68 3e 48 65 78 28 20 43 61 73 74 54 6f 42 6c 6f h>Hex( CastToBlo
17b0: 62 28 20 27 61 6c 70 68 61 27 20 29 20 29 3c 2f b( 'alpha' ) )</
17c0: 74 68 3e 3c 74 68 3e 48 65 78 28 20 43 61 73 74 th><th>Hex( Cast
17d0: 54 6f 54 65 78 74 20 28 20 7a 65 72 6f 62 6c 6f ToText ( zeroblo
17e0: 62 28 34 29 20 29 20 29 3c 2f 74 68 3e 3c 2f 74 b(4) ) )</th></t
17f0: 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 4e 55 4c 4c r>..<tr><td>NULL
1800: 3c 2f 74 64 3e 3c 74 64 3e 4e 55 4c 4c 3c 2f 74 </td><td>NULL</t
1810: 64 3e 3c 74 64 3e 36 31 36 43 37 30 36 38 36 31 d><td>616C706861
1820: 3c 2f 74 64 3e 3c 74 64 3e 30 30 30 30 30 30 30 </td><td>0000000
1830: 30 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 0</td></tr></tab
1840: 6c 65 3e 3c 62 72 3e 0d 0a 54 68 65 20 3c 62 3e le><br>..The <b>
1850: 43 61 73 74 54 6f 42 6c 6f 62 28 29 3c 2f 62 3e CastToBlob()</b>
1860: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 77 69 SQL function wi
1870: 6c 6c 20 61 74 74 65 6d 70 74 20 74 6f 20 72 65 ll attempt to re
1880: 74 75 72 6e 20 61 20 76 61 6c 75 65 20 6f 66 20 turn a value of
1890: 74 68 65 20 3c 62 3e 42 4c 4f 42 3c 2f 62 3e 20 the <b>BLOB</b>
18a0: 64 61 74 61 2d 74 79 70 65 2c 20 6f 72 20 3c 62 data-type, or <b
18b0: 3e 4e 55 4c 4c 3c 2f 62 3e 20 69 66 20 6e 6f 20 >NULL</b> if no
18c0: 63 6f 6e 76 65 72 73 69 6f 6e 20 69 73 20 70 6f conversion is po
18d0: 73 73 69 62 6c 65 2e 0d 0a 3c 75 6c 3e 0d 0a 3c ssible...<ul>..<
18e0: 6c 69 3e 61 6e 20 49 6e 74 65 67 65 72 20 69 6e li>an Integer in
18f0: 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 6c put argument wil
1900: 6c 20 72 65 74 75 72 6e 20 61 20 4e 55 4c 4c 20 l return a NULL
1910: 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 value.</li>..<li
1920: 3e 61 20 44 6f 75 62 6c 65 20 69 6e 70 75 74 20 >a Double input
1930: 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 72 65 argument will re
1940: 74 75 72 6e 20 61 20 4e 55 4c 4c 20 76 61 6c 75 turn a NULL valu
1950: 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 54 e.</li>..<li>a T
1960: 65 78 74 20 69 6e 70 75 74 20 61 72 67 75 6d 65 ext input argume
1970: 6e 74 20 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 nt will return
1980: 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e the correspondin
1990: 67 20 42 4c 4f 42 20 76 61 6c 75 65 2e 3c 2f 6c g BLOB value.</l
19a0: 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 42 4c 4f 42 i>..<li>any BLOB
19b0: 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 input argument
19c0: 77 69 6c 6c 20 72 65 74 75 72 6e 20 74 68 65 20 will return the
19d0: 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 42 4c corresponding BL
19e0: 4f 42 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a OB value.</li>..
19f0: 3c 6c 69 3e 61 6e 79 20 4e 55 4c 4c 20 69 6e 70 <li>any NULL inp
1a00: 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c ut argument will
1a10: 20 72 65 74 75 72 6e 20 61 20 4e 55 4c 4c 20 76 return a NULL v
1a20: 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c alue.</li>..</ul
1a30: 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 >..<verbatim>..S
1a40: 45 4c 45 43 54 20 48 65 78 28 20 43 61 73 74 54 ELECT Hex( CastT
1a50: 6f 42 6c 6f 62 28 20 27 30 31 32 33 34 35 36 37 oBlob( '01234567
1a60: 38 39 61 42 63 44 65 46 66 45 64 43 62 41 39 38 89aBcDeFfEdCbA98
1a70: 37 36 35 34 33 32 31 30 27 2c 20 31 20 29 20 29 76543210', 1 ) )
1a80: 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 30 31 32 33 34 35 ;..-----..012345
1a90: 36 37 38 39 41 42 43 44 45 46 46 45 44 43 42 41 6789ABCDEFFEDCBA
1aa0: 39 38 37 36 35 34 33 32 31 30 0d 0a 0d 0a 53 45 9876543210....SE
1ab0: 4c 45 43 54 20 43 61 73 74 54 6f 42 6c 6f 62 28 LECT CastToBlob(
1ac0: 20 27 31 32 66 27 2c 20 31 20 29 3b 0d 0a 2d 2d '12f', 1 );..--
1ad0: 2d 2d 2d 0d 0a 4e 55 4c 4c 0d 0a 0d 0a 53 45 4c ---..NULL....SEL
1ae0: 45 43 54 20 43 61 73 74 54 6f 42 6c 6f 62 28 20 ECT CastToBlob(
1af0: 27 31 32 48 46 27 2c 20 31 20 29 3b 0d 0a 2d 2d '12HF', 1 );..--
1b00: 2d 2d 2d 0d 0a 4e 55 4c 4c 0d 0a 3c 2f 76 65 72 ---..NULL..</ver
1b10: 62 61 74 69 6d 3e 0d 0a 41 20 73 65 63 6f 6e 64 batim>..A second
1b20: 20 6f 76 65 72 6c 6f 61 64 65 64 20 76 65 72 73 overloaded vers
1b30: 69 6f 6e 20 6f 66 20 3c 62 3e 43 61 73 74 54 6f ion of <b>CastTo
1b40: 42 6c 6f 62 28 29 3c 2f 62 3e 20 69 73 20 73 75 Blob()</b> is su
1b50: 70 70 6f 72 74 65 64 20 61 73 20 77 65 6c 6c 3b pported as well;
1b60: 20 62 79 20 73 70 65 63 69 66 79 69 6e 67 20 61 by specifying a
1b70: 20 66 75 72 74 68 65 72 20 3c 62 3e 68 65 78 5f further <b>hex_
1b80: 69 6e 70 75 74 3c 2f 62 3e 20 3c 75 3e 62 6f 6f input</b> <u>boo
1b90: 6c 65 61 6e 3c 2f 75 3e 20 61 72 67 75 6d 65 6e lean</u> argumen
1ba0: 74 20 73 65 74 20 61 73 20 3c 62 3e 54 52 55 45 t set as <b>TRUE
1bb0: 3c 2f 62 3e 20 74 68 65 20 69 6e 70 75 74 20 73 </b> the input s
1bc0: 74 72 69 6e 67 20 77 69 6c 6c 20 62 65 20 61 73 tring will be as
1bd0: 73 75 6d 65 64 20 74 6f 20 62 65 20 3c 75 3e 48 sumed to be <u>H
1be0: 65 78 61 64 65 63 69 6d 61 6c 6c 79 20 65 6e 63 exadecimally enc
1bf0: 6f 64 65 64 3c 2f 75 3e 2e 20 49 6e 20 74 68 69 oded</u>. In thi
1c00: 73 20 63 61 73 65 20 4e 55 4c 4c 20 77 69 6c 6c s case NULL will
1c10: 20 62 65 20 72 65 74 75 72 6e 65 64 20 69 66 20 be returned if
1c20: 74 68 65 20 69 6e 70 75 74 20 73 74 72 69 6e 67 the input string
1c30: 20 64 6f 65 73 6e 27 74 20 63 6f 72 72 65 73 70 doesn't corresp
1c40: 6f 6e 64 73 20 74 6f 20 61 20 76 61 6c 69 64 20 onds to a valid
1c50: 48 65 78 61 64 65 63 69 6d 61 6c 20 6e 6f 74 61 Hexadecimal nota
1c60: 74 69 6f 6e 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c tion.<br><br>..<
1c70: 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d hr>..<verbatim>.
1c80: 0a 53 45 4c 45 43 54 20 46 6f 72 63 65 41 73 4e .SELECT ForceAsN
1c90: 75 6c 6c 28 20 27 61 27 2c 20 27 62 27 20 29 2c ull( 'a', 'b' ),
1ca0: 20 46 6f 72 63 65 41 73 4e 75 6c 6c 28 20 27 61 ForceAsNull( 'a
1cb0: 62 63 64 27 2c 20 27 61 62 63 64 27 20 29 2c 20 bcd', 'abcd' ),
1cc0: 46 6f 72 63 65 41 73 4e 75 6c 6c 28 20 31 2c 20 ForceAsNull( 1,
1cd0: 31 29 2c 20 46 6f 72 63 65 41 73 4e 75 6c 6c 28 1), ForceAsNull(
1ce0: 20 31 2e 31 2c 20 31 20 29 3b 0d 0a 3c 2f 76 65 1.1, 1 );..</ve
1cf0: 72 62 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c 65 20 rbatim>..<table
1d00: 62 6f 72 64 65 72 3d 22 31 22 20 63 65 6c 6c 73 border="1" cells
1d10: 70 61 63 69 6e 67 3d 22 34 22 20 63 65 6c 6c 70 pacing="4" cellp
1d20: 61 64 64 69 6e 67 3d 22 34 22 3e 0d 0a 3c 74 72 adding="4">..<tr
1d30: 3e 3c 74 68 3e 46 6f 72 63 65 41 73 4e 75 6c 6c ><th>ForceAsNull
1d40: 28 20 27 61 27 2c 20 27 62 27 20 29 3c 2f 74 68 ( 'a', 'b' )</th
1d50: 3e 3c 74 68 3e 46 6f 72 63 65 41 73 4e 75 6c 6c ><th>ForceAsNull
1d60: 28 20 27 61 62 63 64 27 2c 20 27 61 62 63 64 27 ( 'abcd', 'abcd'
1d70: 20 29 3c 2f 74 68 3e 3c 74 68 3e 46 6f 72 63 65 )</th><th>Force
1d80: 41 73 4e 75 6c 6c 28 20 31 2c 20 31 29 3c 2f 74 AsNull( 1, 1)</t
1d90: 68 3e 3c 74 68 3e 46 6f 72 63 65 41 73 4e 75 6c h><th>ForceAsNul
1da0: 6c 28 20 31 2e 31 2c 20 2d 39 39 39 39 20 29 3c l( 1.1, -9999 )<
1db0: 2f 74 68 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c /th></tr>..<tr><
1dc0: 74 64 3e 61 3c 2f 74 64 3e 3c 74 64 3e 4e 55 4c td>a</td><td>NUL
1dd0: 4c 3c 2f 74 64 3e 3c 74 64 3e 4e 55 4c 4c 3c 2f L</td><td>NULL</
1de0: 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 td><td align="ri
1df0: 67 68 74 22 3e 31 2e 31 3c 2f 74 64 3e 3c 2f 74 ght">1.1</td></t
1e00: 72 3e 3c 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a r></table><br>..
1e10: 54 68 65 20 3c 62 3e 46 6f 72 63 65 41 73 4e 75 The <b>ForceAsNu
1e20: 6c 6c 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e ll()</b> SQL fun
1e30: 63 74 69 6f 6e 20 77 69 6c 6c 20 65 76 61 6c 75 ction will evalu
1e40: 61 74 65 20 74 77 6f 20 61 72 62 69 74 72 61 72 ate two arbitrar
1e50: 79 20 61 72 67 75 6d 65 6e 74 73 2e 3c 62 72 3e y arguments.<br>
1e60: 0d 0a 49 66 20 74 68 65 79 20 61 72 65 20 65 71 ..If they are eq
1e70: 75 61 6c 20 61 6e 64 20 65 78 61 63 74 6c 79 20 ual and exactly
1e80: 6f 66 20 74 68 65 20 73 61 6d 65 20 64 61 74 61 of the same data
1e90: 2d 74 79 70 65 20 4e 55 4c 4c 20 77 69 6c 6c 20 -type NULL will
1ea0: 62 65 20 72 65 74 75 72 6e 65 64 3b 20 6f 74 68 be returned; oth
1eb0: 65 72 77 69 73 65 20 74 68 65 20 66 69 72 73 74 erwise the first
1ec0: 20 61 72 67 75 6d 65 6e 74 20 76 61 6c 75 65 20 argument value
1ed0: 77 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 will be returned
1ee0: 2e 3c 62 72 3e 0d 0a 55 73 65 66 75 6c 20 65 2e .<br>..Useful e.
1ef0: 67 2e 20 77 68 69 6c 65 20 70 72 6f 63 65 73 73 g. while process
1f00: 69 6e 67 20 64 61 74 61 20 69 6d 70 6f 72 74 65 ing data importe
1f10: 64 20 66 72 6f 6d 20 61 6e 79 20 3c 62 3e 53 68 d from any <b>Sh
1f20: 61 70 65 66 69 6c 65 3c 2f 62 3e 20 6f 72 20 3c apefile</b> or <
1f30: 62 3e 44 42 46 20 66 69 6c 65 3c 2f 62 3e 20 28 b>DBF file</b> (
1f40: 73 75 63 68 20 66 6f 72 6d 61 74 73 20 64 6f 65 such formats doe
1f50: 73 6e 27 74 20 73 75 70 70 6f 72 74 20 61 6e 79 sn't support any
1f60: 20 72 65 61 6c 20 4e 55 4c 4c 20 76 61 6c 75 65 real NULL value
1f70: 2c 20 6f 66 74 65 6e 20 62 65 69 6e 67 20 72 65 , often being re
1f80: 70 6c 61 63 65 64 20 62 79 20 73 6f 6d 65 20 63 placed by some c
1f90: 6f 6e 76 65 6e 74 69 6f 6e 61 6c 20 76 61 6c 75 onventional valu
1fa0: 65 20 65 2e 67 2e 20 3c 62 3e 30 3c 2f 62 3e 20 e e.g. <b>0</b>
1fb0: 6f 72 20 3c 62 3e 2d 39 39 39 39 3c 2f 62 3e 20 or <b>-9999</b>
1fc0: 61 6e 64 20 61 6c 69 6b 65 29 2e 3c 62 72 3e 3c and alike).<br><
1fd0: 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 3c br>..<hr>..<h3><
1fe0: 61 20 6e 61 6d 65 3d 22 75 75 69 64 22 3e 47 65 a name="uuid">Ge
1ff0: 6e 65 72 69 63 3c 2f 61 3e 20 53 51 4c 20 66 75 neric</a> SQL fu
2000: 6e 63 74 69 6f 6e 73 20 2d 20 55 55 49 44 20 67 nctions - UUID g
2010: 65 6e 65 72 61 74 6f 72 3c 2f 68 33 3e 0d 0a 41 enerator</h3>..A
2020: 6e 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 3a n <a href="http:
2030: 2f 2f 65 6e 2e 77 69 6b 69 70 65 64 69 61 2e 6f //en.wikipedia.o
2040: 72 67 2f 77 69 6b 69 2f 55 6e 69 76 65 72 73 61 rg/wiki/Universa
2050: 6c 6c 79 5f 75 6e 69 71 75 65 5f 69 64 65 6e 74 lly_unique_ident
2060: 69 66 69 65 72 22 3e 55 6e 69 76 65 72 73 61 6c ifier">Universal
2070: 6c 79 20 75 6e 69 71 75 65 20 69 64 65 6e 74 69 ly unique identi
2080: 66 69 65 72 3c 2f 61 3e 20 28 61 6b 61 20 3c 62 fier</a> (aka <b
2090: 3e 55 55 49 44 3c 2f 62 3e 29 20 73 69 6d 70 6c >UUID</b>) simpl
20a0: 79 20 69 73 20 61 20 3c 75 3e 31 32 38 20 62 69 y is a <u>128 bi
20b0: 74 3c 2f 75 3e 20 49 6e 74 65 67 65 72 3b 20 61 t</u> Integer; a
20c0: 63 63 6f 72 64 69 6e 67 6c 79 20 74 6f 20 3c 61 ccordingly to <a
20d0: 20 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f 65 6e href="http://en
20e0: 2e 77 69 6b 69 70 65 64 69 61 2e 6f 72 67 2f 77 .wikipedia.org/w
20f0: 69 6b 69 2f 55 55 49 44 23 52 61 6e 64 6f 6d 5f iki/UUID#Random_
2100: 55 55 49 44 5f 70 72 6f 62 61 62 69 6c 69 74 79 UUID_probability
2110: 5f 6f 66 5f 64 75 70 6c 69 63 61 74 65 73 22 3e _of_duplicates">
2120: 74 68 65 6f 72 79 3c 2f 61 3e 2c 20 74 68 65 20 theory</a>, the
2130: 70 72 6f 62 61 62 69 6c 69 74 79 20 74 68 61 74 probability that
2140: 20 74 77 6f 20 72 61 6e 64 6f 6d 6c 79 20 67 65 two randomly ge
2150: 6e 65 72 61 74 65 64 20 55 55 49 44 73 20 63 6f nerated UUIDs co
2160: 75 6c 64 20 61 73 73 75 6d 65 20 74 68 65 20 73 uld assume the s
2170: 61 6d 65 20 76 61 6c 75 65 20 69 73 20 6e 65 61 ame value is nea
2180: 72 20 74 6f 20 7a 65 72 6f 20 66 6f 72 20 6d 61 r to zero for ma
2190: 6e 79 20 70 72 61 63 74 69 63 61 6c 20 70 75 72 ny practical pur
21a0: 70 6f 73 65 73 2e 20 41 6e 64 20 63 6f 6e 73 65 poses. And conse
21b0: 71 75 65 6e 74 6c 79 20 55 55 49 44 73 20 61 72 quently UUIDs ar
21c0: 65 20 77 69 64 65 6c 79 20 75 73 65 64 20 61 73 e widely used as
21d0: 20 3c 75 3e 75 6e 69 76 65 72 73 61 6c 6c 79 20 <u>universally
21e0: 75 6e 69 71 75 65 20 49 44 73 3c 2f 75 3e 2e 3c unique IDs</u>.<
21f0: 62 72 3e 0d 0a 55 73 75 61 6c 6c 79 20 55 55 49 br>..Usually UUI
2200: 44 73 20 61 72 65 20 72 65 70 72 65 73 65 6e 74 Ds are represent
2210: 65 64 20 69 6e 20 74 68 65 69 72 20 3c 75 3e 63 ed in their <u>c
2220: 61 6e 6f 6e 69 63 61 6c 20 66 6f 72 6d 3c 2f 75 anonical form</u
2230: 3e 2c 20 69 2e 65 2e 20 61 73 20 61 20 73 65 71 >, i.e. as a seq
2240: 75 65 6e 63 65 20 6f 66 20 33 32 20 68 65 78 61 uence of 32 hexa
2250: 64 65 63 69 6d 61 6c 20 64 69 67 69 74 73 20 73 decimal digits s
2260: 65 70 61 72 61 74 65 64 20 69 6e 74 6f 20 66 69 eparated into fi
2270: 76 65 20 64 69 73 74 69 6e 63 74 20 62 6c 6f 63 ve distinct bloc
2280: 6b 2c 20 61 63 63 6f 72 64 69 6e 67 6c 79 20 74 k, accordingly t
2290: 6f 20 61 20 3c 62 3e 38 2d 34 2d 34 2d 34 2d 31 o a <b>8-4-4-4-1
22a0: 32 3c 2f 62 3e 20 73 63 68 65 6d 61 2e 0d 0a 3c 2</b> schema...<
22b0: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 verbatim>..SELEC
22c0: 54 20 43 72 65 61 74 65 55 55 49 44 28 29 3b 0d T CreateUUID();.
22d0: 0a 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 66 66 66 35 66 .--------..fff5f
22e0: 61 66 31 2d 64 63 63 30 2d 34 33 39 31 2d 38 30 af1-dcc0-4391-80
22f0: 35 34 2d 36 65 37 64 65 37 35 64 38 35 62 31 0d 54-6e7de75d85b1.
2300: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 .</verbatim>..Th
2310: 65 20 3c 62 3e 43 72 65 61 74 65 55 55 49 44 28 e <b>CreateUUID(
2320: 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 )</b> SQL functi
2330: 6f 6e 20 69 73 20 62 75 69 6c 74 20 6f 6e 20 74 on is built on t
2340: 68 65 20 74 6f 70 20 74 68 65 20 3c 69 3e 48 69 he top the <i>Hi
2350: 67 68 20 51 75 61 6c 69 74 79 20 50 73 65 75 64 gh Quality Pseud
2360: 6f 2d 52 61 6e 64 6f 6d 20 4e 75 6d 62 65 72 20 o-Random Number
2370: 47 65 6e 65 72 61 74 6f 72 3c 2f 69 3e 20 3c 61 Generator</i> <a
2380: 20 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f 77 77 href="http://ww
2390: 77 2e 73 71 6c 69 74 65 2e 6f 72 67 2f 63 33 72 w.sqlite.org/c3r
23a0: 65 66 2f 72 61 6e 64 6f 6d 6e 65 73 73 2e 68 74 ef/randomness.ht
23b0: 6d 6c 22 3e 69 6e 74 65 72 6e 61 6c 6c 79 20 69 ml">internally i
23c0: 6d 70 6c 65 6d 65 6e 74 65 64 3c 2f 61 3e 20 62 mplemented</a> b
23d0: 79 20 53 51 4c 69 74 65 2e 3c 62 72 3e 0d 0a 54 y SQLite.<br>..T
23e0: 68 65 20 72 65 74 75 72 6e 65 64 20 55 55 49 44 he returned UUID
23f0: 20 69 73 20 63 6f 6e 66 6f 72 6d 61 6e 74 20 74 is conformant t
2400: 6f 20 3c 75 3e 56 65 72 73 69 6f 6e 20 34 20 28 o <u>Version 4 (
2410: 72 61 6e 64 6f 6d 29 3c 2f 75 3e 20 28 69 2e 65 random)</u> (i.e
2420: 2e 20 74 68 65 20 66 69 72 73 74 20 64 69 67 69 . the first digi
2430: 74 20 69 6e 74 6f 20 74 68 65 20 74 68 69 72 64 t into the third
2440: 20 62 6c 6f 63 6b 20 77 69 6c 6c 20 61 6c 77 61 block will alwa
2450: 79 73 20 62 65 20 3c 62 3e 34 3c 2f 62 3e 20 61 ys be <b>4</b> a
2460: 6e 64 20 74 68 65 20 66 69 72 73 74 20 64 69 67 nd the first dig
2470: 69 74 20 69 6e 74 6f 20 74 68 65 20 66 6f 75 72 it into the four
2480: 74 68 20 62 6c 6f 63 6b 20 77 69 6c 6c 20 61 6c th block will al
2490: 77 61 79 73 20 62 65 20 3c 62 3e 38 3c 2f 62 3e ways be <b>8</b>
24a0: 29 2e 3c 62 72 3e 0d 0a 3c 68 34 3e 4d 44 35 20 ).<br>..<h4>MD5
24b0: 63 68 65 63 6b 73 75 6d 3c 2f 68 34 3e 0d 0a 54 checksum</h4>..T
24c0: 68 65 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 he <a href="http
24d0: 3a 2f 2f 65 6e 2e 77 69 6b 69 70 65 64 69 61 2e ://en.wikipedia.
24e0: 6f 72 67 2f 77 69 6b 69 2f 4d 44 35 22 3e 4d 44 org/wiki/MD5">MD
24f0: 35 20 61 6c 67 6f 72 69 74 68 6d 3c 2f 61 3e 20 5 algorithm</a>
2500: 69 73 20 77 65 6c 6c 20 6b 6e 6f 77 6e 20 61 6e is well known an
2510: 64 20 77 69 64 65 6c 79 20 75 73 65 64 20 69 6e d widely used in
2520: 20 6f 72 64 65 72 20 74 6f 20 63 6f 6d 70 75 74 order to comput
2530: 65 20 3c 75 3e 3c 69 3e 68 61 73 68 20 2f 20 63 e <u><i>hash / c
2540: 68 65 63 6b 73 75 6d 3c 2f 69 3e 3c 2f 75 3e 20 hecksum</i></u>
2550: 64 69 67 65 73 74 73 2c 20 61 6e 64 20 69 74 20 digests, and it
2560: 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 20 corresponds to
2570: 61 20 66 6f 72 6d 61 6c 6c 79 20 64 65 66 69 6e a formally defin
2580: 65 64 20 73 70 65 63 69 66 69 63 61 74 69 6f 6e ed specification
2590: 20 64 20 28 3c 61 20 68 72 65 66 3d 22 68 74 74 d (<a href="htt
25a0: 70 3a 2f 2f 74 6f 6f 6c 73 2e 69 65 74 66 2e 6f p://tools.ietf.o
25b0: 72 67 2f 68 74 6d 6c 2f 72 66 63 31 33 32 31 22 rg/html/rfc1321"
25c0: 3e 52 46 43 31 33 32 31 3c 2f 61 3e 29 2e 3c 62 >RFC1321</a>).<b
25d0: 72 3e 3c 62 72 3e 0d 0a 41 6e 79 20 3c 62 3e 4d r><br>..Any <b>M
25e0: 44 35 20 63 68 65 63 6b 73 75 6d 3c 2f 62 3e 20 D5 checksum</b>
25f0: 61 6c 77 61 79 73 20 63 6f 72 72 65 73 70 6f 6e always correspon
2600: 64 73 20 74 6f 20 61 20 31 32 38 2d 62 69 74 20 ds to a 128-bit
2610: 6e 75 6d 62 65 72 2c 20 61 6e 64 20 69 73 20 75 number, and is u
2620: 73 75 61 6c 6c 79 20 70 72 69 6e 74 65 64 20 69 sually printed i
2630: 6e 20 69 74 73 20 3c 75 3e 3c 69 3e 68 65 78 61 n its <u><i>hexa
2640: 64 65 63 69 6d 61 6c 3c 2f 69 3e 3c 2f 75 3e 20 decimal</i></u>
2650: 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 2e 3c representation.<
2660: 62 72 3e 0d 0a 41 63 63 6f 72 64 69 6e 67 6c 79 br>..Accordingly
2670: 20 74 6f 20 74 68 65 6f 72 79 2c 20 69 74 27 73 to theory, it's
2680: 20 76 65 72 79 20 69 6d 70 72 6f 62 61 62 6c 65 very improbable
2690: 20 74 68 61 74 20 74 77 6f 20 64 69 66 66 65 72 that two differ
26a0: 65 6e 74 20 3c 69 3e 6d 65 73 73 61 67 65 73 3c ent <i>messages<
26b0: 2f 69 3e 20 63 6f 75 6c 64 20 63 6f 6c 6c 69 64 /i> could collid
26c0: 65 20 67 65 6e 65 72 61 74 69 6e 67 20 74 68 65 e generating the
26d0: 20 73 61 6d 65 20 69 64 65 6e 74 69 63 61 6c 20 same identical
26e0: 63 68 65 63 6b 73 75 6d 3b 20 61 6e 64 20 65 76 checksum; and ev
26f0: 65 6e 20 73 6c 69 67 68 74 6c 79 20 64 69 66 66 en slightly diff
2700: 65 72 65 6e 74 20 3c 69 3e 6d 65 73 73 61 67 65 erent <i>message
2710: 73 3c 2f 69 3e 20 28 6a 75 73 74 20 64 69 66 66 s</i> (just diff
2720: 65 72 69 6e 67 20 66 6f 72 20 66 65 77 20 62 69 ering for few bi
2730: 74 73 29 20 61 72 65 20 65 78 70 65 63 74 65 64 ts) are expected
2740: 20 74 6f 20 70 72 6f 64 75 63 65 20 73 74 72 69 to produce stri
2750: 6b 69 6e 67 6c 79 20 64 69 66 66 65 72 65 6e 74 kingly different
2760: 20 63 68 65 63 6b 73 75 6d 73 2e 3c 62 72 3e 0d checksums.<br>.
2770: 0a 53 6f 20 74 68 65 20 3c 62 3e 4d 44 35 20 63 .So the <b>MD5 c
2780: 68 65 63 6b 73 75 6d 3c 2f 62 3e 20 63 61 6e 20 hecksum</b> can
2790: 62 65 20 73 61 66 65 6c 79 20 61 73 73 75 6d 65 be safely assume
27a0: 64 20 74 6f 20 72 65 70 72 65 73 65 6e 74 20 61 d to represent a
27b0: 20 3c 75 3e 3c 69 3e 64 69 67 69 74 61 6c 20 73 <u><i>digital s
27c0: 69 67 6e 61 74 75 72 65 3c 2f 69 3e 3c 2f 75 3e ignature</i></u>
27d0: 20 75 6e 69 71 75 65 6c 79 20 69 64 65 6e 74 69 uniquely identi
27e0: 66 79 69 6e 67 20 61 6e 79 20 67 65 6e 65 72 69 fying any generi
27f0: 63 20 62 69 6e 61 72 79 20 6f 62 6a 65 63 74 2e c binary object.
2800: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 ..<verbatim>..SE
2810: 4c 45 43 54 20 4d 44 35 43 68 65 63 6b 73 75 6d LECT MD5Checksum
2820: 28 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 27 4c (GeomFromText('L
2830: 49 4e 45 53 54 52 49 4e 47 28 31 31 20 34 31 2c INESTRING(11 41,
2840: 20 31 32 20 34 32 29 27 2c 20 34 33 32 36 29 29 12 42)', 4326))
2850: 3b 0d 0a 2d 2d 2d 2d 2d 2d 0d 0a 37 30 31 66 32 ;..------..701f2
2860: 63 32 33 31 61 35 66 62 34 38 39 62 65 31 63 37 c231a5fb489be1c7
2870: 38 34 65 32 34 31 65 61 39 35 38 0d 0a 3c 2f 76 84e241ea958..</v
2880: 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 erbatim>..The <b
2890: 3e 4d 44 35 43 68 65 63 6b 73 75 6d 28 29 3c 2f >MD5Checksum()</
28a0: 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 b> SQL function
28b0: 77 69 6c 6c 20 72 65 74 75 72 6e 20 74 68 65 20 will return the
28c0: 63 68 65 63 6b 73 75 6d 20 63 6f 72 72 65 73 70 checksum corresp
28d0: 6f 6e 64 69 6e 67 20 74 6f 20 61 6e 79 20 67 65 onding to any ge
28e0: 6e 65 72 69 63 20 42 4c 4f 42 20 28 74 68 69 73 neric BLOB (this
28f0: 20 6f 62 76 69 6f 75 73 6c 79 20 69 6e 63 6c 75 obviously inclu
2900: 64 69 6e 67 20 47 65 6f 6d 65 74 72 69 65 73 29 ding Geometries)
2910: 20 6f 72 20 54 45 58 54 20 73 74 72 69 6e 67 2e or TEXT string.
2920: 3c 62 72 3e 0d 0a 54 68 65 20 75 6e 64 65 72 6c <br>..The underl
2930: 79 69 6e 67 20 69 6d 70 6c 65 6d 65 6e 74 61 74 ying implementat
2940: 69 6f 6e 20 69 73 20 64 69 72 65 63 74 6c 79 20 ion is directly
2950: 62 61 73 65 64 20 6f 6e 20 74 68 65 20 3c 61 20 based on the <a
2960: 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f 6f 70 65 href="http://ope
2970: 6e 77 61 6c 6c 2e 69 6e 66 6f 2f 77 69 6b 69 2f nwall.info/wiki/
2980: 70 65 6f 70 6c 65 2f 73 6f 6c 61 72 2f 73 6f 66 people/solar/sof
2990: 74 77 61 72 65 2f 70 75 62 6c 69 63 2d 64 6f 6d tware/public-dom
29a0: 61 69 6e 2d 73 6f 75 72 63 65 2d 63 6f 64 65 2f ain-source-code/
29b0: 6d 64 35 22 3e 63 6f 64 65 3c 2f 61 3e 20 64 65 md5">code</a> de
29c0: 76 65 6c 6f 70 65 64 20 62 79 20 41 6c 65 78 61 veloped by Alexa
29d0: 6e 64 65 72 20 50 65 73 6c 79 61 6b 20 61 6e 64 nder Peslyak and
29e0: 20 72 65 6c 65 61 73 65 64 20 6f 6e 20 74 68 65 released on the
29f0: 20 50 75 62 6c 69 63 20 44 6f 6d 61 69 6e 2e 0d Public Domain..
2a00: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c .<verbatim>..SEL
2a10: 45 43 54 20 4d 44 35 54 6f 74 61 6c 43 68 65 63 ECT MD5TotalChec
2a20: 6b 73 75 6d 28 67 65 6f 6d 65 74 72 79 29 0d 0a ksum(geometry)..
2a30: 46 52 4f 4d 20 63 6f 6d 32 30 31 31 3b 0d 0a 2d FROM com2011;..-
2a40: 2d 2d 2d 2d 2d 0d 0a 38 65 62 30 30 32 36 35 38 -----..8eb002658
2a50: 39 39 30 30 32 32 61 36 66 30 63 31 63 62 32 34 990022a6f0c1cb24
2a60: 61 36 30 66 62 66 36 0d 0a 3c 2f 76 65 72 62 61 a60fbf6..</verba
2a70: 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 4d 44 35 tim>..The <b>MD5
2a80: 54 6f 74 61 6c 43 68 65 63 6b 73 75 6d 28 29 3c TotalChecksum()<
2a90: 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e /b> SQL function
2aa0: 20 77 69 6c 6c 20 70 65 72 66 6f 72 6d 20 65 78 will perform ex
2ab0: 61 63 74 6c 79 20 74 68 65 20 73 61 6d 65 20 69 actly the same i
2ac0: 64 65 6e 74 69 63 61 6c 20 74 61 73 6b 20 62 75 dentical task bu
2ad0: 74 20 69 73 20 69 6d 70 6c 65 6d 65 6e 74 65 64 t is implemented
2ae0: 20 61 73 20 61 6e 20 3c 75 3e 3c 69 3e 61 67 67 as an <u><i>agg
2af0: 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 3c regate function<
2b00: 2f 69 3e 3c 2f 75 3e 2e 0d 0a 3c 62 72 3e 3c 62 /i></u>...<br><b
2b10: 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 3c 61 r>..<hr>..<h3><a
2b20: 20 6e 61 6d 65 3d 22 67 65 6f 6d 22 3e 53 70 61 name="geom">Spa
2b30: 74 69 61 6c 3c 2f 61 3e 20 53 51 4c 20 66 75 6e tial</a> SQL fun
2b40: 63 74 69 6f 6e 73 3c 2f 68 33 3e 0d 0a 46 65 77 ctions</h3>..Few
2b50: 20 6d 6f 72 65 20 53 70 61 74 69 61 6c 20 53 51 more Spatial SQ
2b60: 4c 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 65 20 L functions are
2b70: 6e 6f 77 20 73 75 70 70 6f 72 74 65 64 2e 0d 0a now supported...
2b80: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 <verbatim>..SELE
2b90: 43 54 20 53 54 5f 41 73 54 65 78 74 28 20 53 54 CT ST_AsText( ST
2ba0: 5f 41 64 64 50 6f 69 6e 74 28 20 0d 0a 20 20 53 _AddPoint( .. S
2bb0: 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 T_GeomFromText(
2bc0: 27 4c 49 4e 45 53 54 52 49 4e 47 28 20 30 20 30 'LINESTRING( 0 0
2bd0: 2c 20 31 20 30 20 29 27 20 29 2c 20 0d 0a 20 20 , 1 0 )' ), ..
2be0: 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 ST_GeomFromText(
2bf0: 20 27 50 4f 49 4e 54 28 20 31 20 31 20 29 27 20 'POINT( 1 1 )'
2c00: 29 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d ) ) );..--------
2c10: 0d 0a 4c 49 4e 45 53 54 52 49 4e 47 28 30 20 30 ..LINESTRING(0 0
2c20: 2c 20 31 20 30 2c 20 31 20 31 29 0d 0a 3c 2f 76 , 1 0, 1 1)..</v
2c30: 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 erbatim>..The <b
2c40: 3e 53 54 5f 41 64 64 50 6f 69 6e 74 28 29 3c 2f >ST_AddPoint()</
2c50: 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 b> SQL function
2c60: 61 64 64 73 20 61 20 66 75 72 74 68 65 72 20 50 adds a further P
2c70: 6f 69 6e 74 2f 56 65 72 74 65 78 20 61 74 20 74 oint/Vertex at t
2c80: 68 65 20 65 6e 64 20 6f 66 20 61 20 4c 69 6e 65 he end of a Line
2c90: 73 74 72 69 6e 67 3b 20 74 68 65 20 66 69 72 73 string; the firs
2ca0: 74 20 61 72 67 75 6d 65 6e 74 20 69 73 20 61 6c t argument is al
2cb0: 77 61 79 73 20 65 78 70 65 63 74 65 64 20 74 6f ways expected to
2cc0: 20 62 65 20 6f 66 20 74 68 65 20 4c 69 6e 65 73 be of the Lines
2cd0: 74 72 69 6e 67 20 74 79 70 65 2c 20 74 68 65 20 tring type, the
2ce0: 73 65 63 6f 6e 64 20 6f 6e 65 20 6d 75 73 74 20 second one must
2cf0: 62 65 20 61 20 50 6f 69 6e 74 2e 0d 0a 3c 76 65 be a Point...<ve
2d00: 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 rbatim>..SELECT
2d10: 53 54 5f 41 73 54 65 78 74 28 20 53 54 5f 41 64 ST_AsText( ST_Ad
2d20: 64 50 6f 69 6e 74 28 20 0d 0a 20 20 53 54 5f 47 dPoint( .. ST_G
2d30: 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27 4c 49 eomFromText( 'LI
2d40: 4e 45 53 54 52 49 4e 47 28 20 31 20 30 2c 20 31 NESTRING( 1 0, 1
2d50: 20 31 20 29 27 20 29 2c 20 0d 0a 20 20 53 54 5f 1 )' ), .. ST_
2d60: 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27 50 GeomFromText( 'P
2d70: 4f 49 4e 54 28 20 30 20 30 20 29 27 20 29 2c 20 OINT( 0 0 )' ),
2d80: 30 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 0 ) );..--------
2d90: 2d 0d 0a 4c 49 4e 45 53 54 52 49 4e 47 28 30 20 -..LINESTRING(0
2da0: 30 2c 20 31 20 30 2c 20 31 20 31 29 0d 0a 3c 2f 0, 1 0, 1 1)..</
2db0: 76 65 72 62 61 74 69 6d 3e 0d 0a 49 66 20 61 6e verbatim>..If an
2dc0: 20 6f 70 74 69 6f 6e 61 6c 20 74 68 69 72 64 20 optional third
2dd0: 61 72 67 75 6d 65 6e 74 20 28 6f 66 20 74 68 65 argument (of the
2de0: 20 49 6e 74 65 67 65 72 20 74 79 70 65 29 20 69 Integer type) i
2df0: 73 20 70 61 73 73 65 64 20 74 6f 20 3c 62 3e 53 s passed to <b>S
2e00: 54 5f 41 64 64 50 6f 69 6e 74 28 29 3c 2f 62 3e T_AddPoint()</b>
2e10: 20 69 74 27 73 20 69 6e 74 65 6e 64 65 64 20 74 it's intended t
2e20: 6f 20 73 70 65 63 69 66 79 20 74 68 65 20 3c 75 o specify the <u
2e30: 3e 69 6e 64 65 78 3c 2f 75 3e 20 6f 66 20 74 68 >index</u> of th
2e40: 65 20 6e 65 77 20 56 65 72 74 65 78 20 28 66 69 e new Vertex (fi
2e50: 72 73 74 20 56 65 72 74 65 78 20 68 61 73 20 69 rst Vertex has i
2e60: 6e 64 65 78 20 30 2c 20 73 65 63 6f 6e 64 20 56 ndex 0, second V
2e70: 65 72 74 65 78 20 68 61 73 20 69 6e 64 65 78 20 ertex has index
2e80: 31 20 61 6e 64 20 73 6f 20 6f 6e 29 2e 3c 62 72 1 and so on).<br
2e90: 3e 0d 0a 52 65 66 65 72 65 6e 63 69 6e 67 20 61 >..Referencing a
2ea0: 20 6e 6f 74 20 65 78 69 73 74 69 6e 67 20 69 6e not existing in
2eb0: 64 65 78 20 69 73 20 61 6e 20 65 72 72 6f 72 2c dex is an error,
2ec0: 20 61 6e 64 20 77 69 6c 6c 20 72 65 74 75 72 6e and will return
2ed0: 20 4e 55 4c 4c 2e 0d 0a 3c 76 65 72 62 61 74 69 NULL...<verbati
2ee0: 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 54 5f 41 73 m>..SELECT ST_As
2ef0: 54 65 78 74 28 20 53 54 5f 41 64 64 50 6f 69 6e Text( ST_AddPoin
2f00: 74 28 20 0d 0a 20 20 53 54 5f 47 65 6f 6d 46 72 t( .. ST_GeomFr
2f10: 6f 6d 54 65 78 74 28 20 27 4c 49 4e 45 53 54 52 omText( 'LINESTR
2f20: 49 4e 47 28 20 30 20 30 2c 20 31 20 30 20 29 27 ING( 0 0, 1 0 )'
2f30: 20 29 2c 20 0d 0a 20 20 53 54 5f 47 65 6f 6d 46 ), .. ST_GeomF
2f40: 72 6f 6d 54 65 78 74 28 20 27 50 4f 49 4e 54 28 romText( 'POINT(
2f50: 20 31 20 31 20 29 27 20 29 2c 20 2d 31 20 29 20 1 1 )' ), -1 )
2f60: 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 );..--------..LI
2f70: 4e 45 53 54 52 49 4e 47 28 30 20 30 2c 20 31 20 NESTRING(0 0, 1
2f80: 30 2c 20 31 20 31 29 0d 0a 3c 2f 76 65 72 62 61 0, 1 1)..</verba
2f90: 74 69 6d 3e 0d 0a 50 61 73 73 69 6e 67 20 61 20 tim>..Passing a
2fa0: 6e 65 67 61 74 69 76 65 20 69 6e 64 65 78 20 69 negative index i
2fb0: 73 20 61 20 73 75 70 70 6f 72 74 65 64 20 6f 70 s a supported op
2fc0: 74 69 6f 6e 2c 20 61 6e 64 20 73 69 6d 70 6c 79 tion, and simply
2fd0: 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 corresponds to
2fe0: 74 68 65 20 64 65 66 61 75 6c 74 20 62 65 68 61 the default beha
2ff0: 76 69 6f 75 72 20 28 69 2e 65 2e 20 3c 69 3e 61 viour (i.e. <i>a
3000: 70 70 65 6e 64 69 6e 67 20 74 68 65 20 50 6f 69 ppending the Poi
3010: 6e 74 20 74 6f 20 74 68 65 20 65 6e 64 20 6f 66 nt to the end of
3020: 20 74 68 65 20 4c 69 6e 65 73 74 72 69 6e 67 3c the Linestring<
3030: 2f 69 3e 29 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c /i>).<br><br>..<
3040: 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d hr>..<verbatim>.
3050: 0a 53 45 4c 45 43 54 20 53 54 5f 41 73 54 65 78 .SELECT ST_AsTex
3060: 74 28 20 53 54 5f 53 65 74 50 6f 69 6e 74 28 20 t( ST_SetPoint(
3070: 0d 0a 20 20 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 .. ST_GeomFromT
3080: 65 78 74 28 20 27 4c 49 4e 45 53 54 52 49 4e 47 ext( 'LINESTRING
3090: 28 20 30 20 30 2c 20 31 20 30 2c 20 31 20 31 20 ( 0 0, 1 0, 1 1
30a0: 29 27 20 29 2c 20 0d 0a 20 20 31 2c 20 53 54 5f )' ), .. 1, ST_
30b0: 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27 50 GeomFromText( 'P
30c0: 4f 49 4e 54 28 20 32 20 31 20 29 27 20 29 20 29 OINT( 2 1 )' ) )
30d0: 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a );..---------..
30e0: 4c 49 4e 45 53 54 52 49 4e 47 28 30 20 30 2c 20 LINESTRING(0 0,
30f0: 32 20 31 2c 20 31 20 31 29 0d 0a 3c 2f 76 65 72 2 1, 1 1)..</ver
3100: 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 53 batim>..The <b>S
3110: 54 5f 53 65 74 50 6f 69 6e 74 28 29 3c 2f 62 3e T_SetPoint()</b>
3120: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 63 61 SQL function ca
3130: 6e 20 72 65 70 6c 61 63 65 20 61 20 50 6f 69 6e n replace a Poin
3140: 74 2f 56 65 72 74 65 78 20 66 72 6f 6d 20 77 69 t/Vertex from wi
3150: 74 68 69 6e 20 61 20 4c 69 6e 65 73 74 72 69 6e thin a Linestrin
3160: 67 3b 20 74 68 65 20 66 69 72 73 74 20 61 72 67 g; the first arg
3170: 75 6d 65 6e 74 20 69 73 20 61 6c 77 61 79 73 20 ument is always
3180: 65 78 70 65 63 74 65 64 20 74 6f 20 62 65 20 6f expected to be o
3190: 66 20 74 68 65 20 4c 69 6e 65 73 74 72 69 6e 67 f the Linestring
31a0: 20 74 79 70 65 2c 20 74 68 65 20 73 65 63 6f 6e type, the secon
31b0: 64 20 69 73 20 61 6e 20 49 6e 74 65 67 65 72 20 d is an Integer
31c0: 73 70 65 63 69 66 79 69 6e 67 20 74 68 65 20 3c specifying the <
31d0: 75 3e 69 6e 64 65 78 3c 2f 75 3e 20 6f 66 20 74 u>index</u> of t
31e0: 68 65 20 61 66 66 65 63 74 65 64 20 56 65 72 74 he affected Vert
31f0: 65 78 20 61 6e 64 20 74 68 65 20 74 68 69 72 64 ex and the third
3200: 20 6f 6e 65 20 6d 75 73 74 20 62 65 20 61 20 50 one must be a P
3210: 6f 69 6e 74 2e 3c 62 72 3e 0d 0a 52 65 66 65 72 oint.<br>..Refer
3220: 65 6e 63 69 6e 67 20 61 20 6e 6f 74 20 65 78 69 encing a not exi
3230: 73 74 69 6e 67 20 69 6e 64 65 78 20 69 73 20 61 sting index is a
3240: 6e 20 65 72 72 6f 72 2c 20 61 6e 64 20 77 69 6c n error, and wil
3250: 6c 20 72 65 74 75 72 6e 20 4e 55 4c 4c 2e 3c 62 l return NULL.<b
3260: 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 76 r><br>..<hr>..<v
3270: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 erbatim>..SELECT
3280: 20 53 54 5f 41 73 54 65 78 74 28 20 53 54 5f 52 ST_AsText( ST_R
3290: 65 6d 6f 76 65 50 6f 69 6e 74 28 20 0d 0a 20 20 emovePoint( ..
32a0: 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 ST_GeomFromText(
32b0: 20 27 4c 49 4e 45 53 54 52 49 4e 47 28 20 30 20 'LINESTRING( 0
32c0: 30 2c 20 31 20 30 2c 20 31 20 31 20 29 27 20 29 0, 1 0, 1 1 )' )
32d0: 2c 20 31 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d , 1 ) );..------
32e0: 2d 2d 2d 0d 0a 4c 49 4e 45 53 54 52 49 4e 47 28 ---..LINESTRING(
32f0: 30 20 30 2c 20 31 20 31 29 0d 0a 3c 2f 76 65 72 0 0, 1 1)..</ver
3300: 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 53 batim>..The <b>S
3310: 54 5f 52 65 6d 6f 76 65 50 6f 69 6e 74 28 29 3c T_RemovePoint()<
3320: 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e /b> SQL function
3330: 20 63 61 6e 20 72 65 6d 6f 76 65 20 61 20 50 6f can remove a Po
3340: 69 6e 74 2f 56 65 72 74 65 78 20 66 72 6f 6d 20 int/Vertex from
3350: 77 69 74 68 69 6e 20 61 20 4c 69 6e 65 73 74 72 within a Linestr
3360: 69 6e 67 3b 20 74 68 65 20 66 69 72 73 74 20 61 ing; the first a
3370: 72 67 75 6d 65 6e 74 20 69 73 20 61 6c 77 61 79 rgument is alway
3380: 73 20 65 78 70 65 63 74 65 64 20 74 6f 20 62 65 s expected to be
3390: 20 6f 66 20 74 68 65 20 4c 69 6e 65 73 74 72 69 of the Linestri
33a0: 6e 67 20 74 79 70 65 2c 20 74 68 65 20 73 65 63 ng type, the sec
33b0: 6f 6e 64 20 69 73 20 61 6e 20 49 6e 74 65 67 65 ond is an Intege
33c0: 72 20 73 70 65 63 69 66 79 69 6e 67 20 74 68 65 r specifying the
33d0: 20 3c 75 3e 69 6e 64 65 78 3c 2f 75 3e 20 6f 66 <u>index</u> of
33e0: 20 74 68 65 20 61 66 66 65 63 74 65 64 20 56 65 the affected Ve
33f0: 72 74 65 78 2e 3c 62 72 3e 0d 0a 52 65 66 65 72 rtex.<br>..Refer
3400: 65 6e 63 69 6e 67 20 61 20 6e 6f 74 20 65 78 69 encing a not exi
3410: 73 74 69 6e 67 20 69 6e 64 65 78 20 69 73 20 61 sting index is a
3420: 6e 20 65 72 72 6f 72 2c 20 61 6e 64 20 77 69 6c n error, and wil
3430: 6c 20 72 65 74 75 72 6e 20 4e 55 4c 4c 2e 3c 62 l return NULL.<b
3440: 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 76 r><br>..<hr>..<v
3450: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 erbatim>..SELECT
3460: 20 53 54 5f 41 73 54 65 78 74 28 20 53 54 5f 50 ST_AsText( ST_P
3470: 6f 69 6e 74 28 31 30 2c 20 32 30 29 20 29 3b 0d oint(10, 20) );.
3480: 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 50 4f 49 .----------..POI
3490: 4e 54 28 31 30 20 31 30 29 0d 0a 3c 2f 76 65 72 NT(10 10)..</ver
34a0: 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 53 batim>..The <b>S
34b0: 54 5f 50 6f 69 6e 74 28 29 3c 2f 62 3e 20 53 51 T_Point()</b> SQ
34c0: 4c 20 66 75 6e 63 74 69 6f 6e 20 73 69 6d 70 6c L function simpl
34d0: 79 20 69 73 20 79 65 74 20 61 6e 6f 74 68 65 72 y is yet another
34e0: 20 3c 69 3e 61 6c 69 61 73 2d 6e 61 6d 65 3c 2f <i>alias-name</
34f0: 69 3e 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 i> corresponding
3500: 20 74 6f 20 3c 62 3e 4d 61 6b 65 50 6f 69 6e 74 to <b>MakePoint
3510: 28 29 3c 2f 62 3e 3b 20 74 68 69 73 20 66 75 72 ()</b>; this fur
3520: 74 68 65 72 20 61 6c 69 61 73 20 68 61 73 20 62 ther alias has b
3530: 65 65 6e 20 69 6e 74 72 6f 64 75 63 65 64 20 73 een introduced s
3540: 6f 20 74 6f 20 73 75 70 70 6f 72 74 20 61 20 73 o to support a s
3550: 74 72 69 63 74 20 50 6f 73 74 47 49 53 20 63 6f trict PostGIS co
3560: 6e 66 6f 72 6d 61 6e 63 65 2e 3c 62 72 3e 0d 0a nformance.<br>..
3570: 3c 75 3e 50 6c 65 61 73 65 20 6e 6f 74 65 3c 2f <u>Please note</
3580: 75 3e 3a 20 64 69 66 66 65 72 65 6e 74 6c 79 20 u>: differently
3590: 66 72 6f 6d 20 4d 61 6b 65 50 6f 69 6e 74 28 29 from MakePoint()
35a0: 2c 20 53 54 5f 50 6f 69 6e 74 28 29 20 64 6f 6e , ST_Point() don
35b0: 27 74 20 73 75 70 70 6f 72 74 73 20 74 68 65 20 't supports the
35c0: 6f 70 74 69 6f 6e 61 6c 20 3c 62 3e 53 52 49 44 optional <b>SRID
35d0: 3c 2f 62 3e 20 61 72 67 75 6d 65 6e 74 2e 3c 62 </b> argument.<b
35e0: 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 76 r><br>..<hr>..<v
35f0: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 erbatim>..SELECT
3600: 20 53 54 5f 41 73 54 65 78 74 28 20 4d 61 6b 65 ST_AsText( Make
3610: 4c 69 6e 65 28 20 53 54 5f 47 65 6f 6d 46 72 6f Line( ST_GeomFro
3620: 6d 54 65 78 74 28 20 27 4d 55 4c 54 49 50 4f 49 mText( 'MULTIPOI
3630: 4e 54 28 30 20 30 2c 20 31 20 30 2c 20 31 20 31 NT(0 0, 1 0, 1 1
3640: 29 27 20 29 20 29 20 2c 20 31 20 29 3b 0d 0a 2d )' ) ) , 1 );..-
3650: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45 53 ---------..LINES
3660: 54 52 49 4e 47 28 30 20 30 2c 20 31 20 30 2c 20 TRING(0 0, 1 0,
3670: 31 20 31 29 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 1 1)....SELECT S
3680: 54 5f 41 73 54 65 78 74 28 20 4d 61 6b 65 4c 69 T_AsText( MakeLi
3690: 6e 65 28 20 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 ne( ST_GeomFromT
36a0: 65 78 74 28 20 27 4d 55 4c 54 49 50 4f 49 4e 54 ext( 'MULTIPOINT
36b0: 28 30 20 30 2c 20 31 20 30 2c 20 31 20 31 29 27 (0 0, 1 0, 1 1)'
36c0: 20 29 20 29 20 2c 20 30 20 29 3b 0d 0a 2d 2d 2d ) ) , 0 );..---
36d0: 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45 53 54 52 -------..LINESTR
36e0: 49 4e 47 28 31 20 31 2c 20 31 20 30 2c 20 30 20 ING(1 1, 1 0, 0
36f0: 30 29 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0)..</verbatim>.
3700: 0a 4e 6f 74 20 72 65 61 6c 6c 79 20 61 20 62 72 .Not really a br
3710: 61 6e 64 20 6e 65 77 20 53 51 4c 20 66 75 6e 63 and new SQL func
3720: 74 69 6f 6e 3b 20 6d 6f 72 65 20 73 69 6d 70 6c tion; more simpl
3730: 79 20 61 20 66 75 72 74 68 65 72 20 6f 76 65 72 y a further over
3740: 6c 6f 61 64 65 64 20 66 6c 61 76 6f 72 20 6f 66 loaded flavor of
3750: 20 74 68 65 20 61 6c 72 65 61 64 79 20 65 78 69 the already exi
3760: 73 74 69 6e 67 20 3c 62 3e 4d 61 6b 65 4c 69 6e sting <b>MakeLin
3770: 65 28 29 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a 4e 6f e()</b>.<br>..No
3780: 77 20 74 68 65 20 69 6e 70 75 74 20 47 65 6f 6d w the input Geom
3790: 65 74 72 79 20 28 66 69 72 73 74 20 61 72 67 75 etry (first argu
37a0: 6d 65 6e 74 29 20 63 6f 75 6c 64 20 62 65 20 6f ment) could be o
37b0: 66 20 74 68 65 20 4d 55 4c 54 49 50 4f 49 4e 54 f the MULTIPOINT
37c0: 20 74 79 70 65 20 61 6e 64 20 74 68 65 20 73 65 type and the se
37d0: 63 6f 6e 64 20 61 72 67 75 6d 65 6e 74 20 69 66 cond argument if
37e0: 20 6f 66 20 74 68 65 20 3c 62 3e 42 6f 6f 6c 65 of the <b>Boole
37f0: 61 6e 3c 2f 62 3e 20 74 79 70 65 3b 20 69 66 20 an</b> type; if
3800: 74 68 65 20 73 65 63 6f 6e 64 20 61 72 67 75 6d the second argum
3810: 65 6e 74 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 ent corresponds
3820: 74 6f 20 3c 62 3e 54 52 55 45 3c 2f 62 3e 20 74 to <b>TRUE</b> t
3830: 68 65 20 72 65 74 75 72 6e 65 64 20 4c 49 4e 45 he returned LINE
3840: 53 54 52 49 4e 47 20 77 69 6c 6c 20 62 65 20 6f STRING will be o
3850: 72 69 65 6e 74 65 64 20 61 63 63 6f 72 64 69 6e riented accordin
3860: 67 6c 79 20 74 6f 20 74 68 65 20 50 6f 69 6e 74 gly to the Point
3870: 2d 73 65 71 75 65 6e 63 65 20 61 73 20 73 70 65 -sequence as spe
3880: 63 69 66 69 65 64 20 62 79 20 74 68 65 20 4d 75 cified by the Mu
3890: 6c 74 69 50 6f 69 6e 74 2c 20 6f 74 68 65 72 77 ltiPoint, otherw
38a0: 69 73 65 20 3c 75 3e 72 65 76 65 72 73 65 20 6f ise <u>reverse o
38b0: 72 64 65 72 3c 2f 75 3e 20 77 69 6c 6c 20 62 65 rder</u> will be
38c0: 20 61 73 73 75 6d 65 64 2c 20 74 68 75 73 20 72 assumed, thus r
38d0: 65 74 75 72 6e 69 6e 67 20 61 20 4c 69 6e 65 73 eturning a Lines
38e0: 74 72 69 6e 67 20 6f 66 20 6f 70 70 6f 73 69 74 tring of opposit
38f0: 65 20 6f 72 69 65 6e 74 61 74 69 6f 6e 2e 3c 62 e orientation.<b
3900: 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 76 r><br>..<hr>..<v
3910: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 erbatim>..SELECT
3920: 20 53 54 5f 41 72 65 61 28 20 53 54 5f 47 65 6f ST_Area( ST_Geo
3930: 6d 46 72 6f 6d 54 65 78 74 28 20 27 50 4f 4c 59 mFromText( 'POLY
3940: 47 4f 4e 28 28 32 30 20 32 30 2c 20 32 31 20 32 GON((20 20, 21 2
3950: 30 2c 20 32 31 20 32 31 2c 20 32 30 20 32 31 2c 0, 21 21, 20 21,
3960: 20 32 30 20 32 30 29 29 27 2c 20 34 33 32 36 20 20 20))', 4326
3970: 29 2c 20 31 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d ), 1 );..-------
3980: 2d 2d 2d 0d 0a 31 31 35 34 38 35 35 35 39 32 36 ---..11548555926
3990: 2e 36 34 37 37 33 36 0d 0a 0d 0a 0d 0a 53 45 4c .647736......SEL
39a0: 45 43 54 20 53 54 5f 41 72 65 61 28 20 53 54 5f ECT ST_Area( ST_
39b0: 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27 50 GeomFromText( 'P
39c0: 4f 4c 59 47 4f 4e 28 28 32 30 20 32 30 2c 20 32 OLYGON((20 20, 2
39d0: 31 20 32 30 2c 20 32 31 20 32 31 2c 20 32 30 20 1 20, 21 21, 20
39e0: 32 31 2c 20 32 30 20 32 30 29 29 27 2c 20 34 33 21, 20 20))', 43
39f0: 32 36 20 29 2c 20 30 20 29 3b 0d 0a 2d 2d 2d 2d 26 ), 0 );..----
3a00: 2d 2d 2d 2d 2d 2d 0d 0a 31 31 35 38 31 33 37 37 ------..11581377
3a10: 36 32 33 2e 31 31 34 31 38 39 0d 0a 3c 2f 76 65 623.114189..</ve
3a20: 72 62 61 74 69 6d 3e 0d 0a 4f 6e 63 65 20 61 67 rbatim>..Once ag
3a30: 61 69 6e 2c 20 73 69 6d 70 6c 79 20 61 20 66 75 ain, simply a fu
3a40: 72 74 68 65 72 20 65 78 74 65 6e 73 69 6f 6e 20 rther extension
3a50: 6f 66 20 74 68 65 20 61 6c 72 65 61 64 79 20 65 of the already e
3a60: 78 69 73 74 69 6e 67 20 3c 62 3e 53 54 5f 41 72 xisting <b>ST_Ar
3a70: 65 61 28 29 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a 4e ea()</b>.<br>..N
3a80: 6f 77 20 69 66 20 74 68 65 20 69 6e 70 75 74 20 ow if the input
3a90: 47 65 6f 6d 65 74 72 79 20 61 64 6f 70 74 73 20 Geometry adopts
3aa0: 3c 75 3e 67 65 6f 67 72 61 70 68 69 63 20 63 6f <u>geographic co
3ab0: 6f 72 64 69 6e 61 74 65 73 3c 2f 75 3e 20 28 69 ordinates</u> (i
3ac0: 2e 65 2e 20 62 61 73 65 64 20 6f 6e 20 3c 75 3e .e. based on <u>
3ad0: 6c 6f 6e 67 69 74 75 64 65 3c 2f 75 3e 20 61 6e longitude</u> an
3ae0: 64 20 3c 75 3e 6c 61 74 69 74 75 64 65 3c 2f 75 d <u>latitude</u
3af0: 3e 20 61 6e 67 6c 65 73 29 2c 20 61 20 73 65 63 > angles), a sec
3b00: 6f 6e 64 20 61 72 67 75 6d 65 6e 74 20 6f 66 20 ond argument of
3b10: 74 68 65 20 3c 62 3e 42 6f 6f 6c 65 61 6e 3c 2f the <b>Boolean</
3b20: 62 3e 20 64 61 74 61 2d 74 79 70 65 20 63 6f 75 b> data-type cou
3b30: 6c 64 20 62 65 20 6f 70 74 69 6f 6e 61 6c 6c 79 ld be optionally
3b40: 20 73 70 65 63 69 66 69 65 64 2e 3c 62 72 3e 0d specified.<br>.
3b50: 0a 49 6e 20 74 68 69 73 20 63 61 73 65 20 74 68 .In this case th
3b60: 65 20 72 65 74 75 72 6e 65 64 20 41 72 65 61 20 e returned Area
3b70: 77 69 6c 6c 20 62 65 20 6d 65 61 73 75 72 65 64 will be measured
3b80: 20 69 6e 20 3c 62 3e 6d 65 74 65 72 73 3c 2f 62 in <b>meters</b
3b90: 3e 2e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 69 66 >...<ul>..<li>if
3ba0: 20 74 68 65 20 73 65 63 6f 6e 64 20 61 72 67 20 the second arg
3bb0: 69 73 20 3c 62 3e 54 52 55 45 3c 2f 62 3e 20 74 is <b>TRUE</b> t
3bc0: 68 65 20 41 72 65 61 20 77 69 6c 6c 20 62 65 20 he Area will be
3bd0: 6d 65 61 73 75 72 65 64 20 3c 75 3e 6f 6e 20 74 measured <u>on t
3be0: 68 65 20 45 6c 6c 69 70 73 6f 69 64 3c 2f 75 3e he Ellipsoid</u>
3bf0: 20 28 6d 6f 72 65 20 61 63 63 75 72 61 74 65 2c (more accurate,
3c00: 20 62 75 74 20 73 6c 6f 77 65 72 29 2e 3c 2f 6c but slower).</l
3c10: 69 3e 0d 0a 3c 6c 69 3e 69 66 20 74 68 65 20 73 i>..<li>if the s
3c20: 65 63 6f 6e 64 20 61 72 67 20 69 73 20 3c 62 3e econd arg is <b>
3c30: 46 41 4c 53 45 3c 2f 62 3e 20 74 68 65 20 41 72 FALSE</b> the Ar
3c40: 65 61 20 77 69 6c 6c 20 62 65 20 6d 65 61 73 75 ea will be measu
3c50: 72 65 20 3c 75 3e 6f 6e 20 74 68 65 20 53 70 68 re <u>on the Sph
3c60: 65 72 65 3c 2f 75 3e 20 28 66 61 73 74 65 72 2c ere</u> (faster,
3c70: 20 62 75 74 20 6c 65 73 73 20 61 63 63 75 72 61 but less accura
3c80: 74 65 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 4e te).</li>..<li>N
3c90: 55 4c 4c 20 77 69 6c 6c 20 62 65 20 72 65 74 75 ULL will be retu
3ca0: 72 6e 65 64 20 6f 6e 20 69 6e 76 61 6c 69 64 20 rned on invalid
3cb0: 61 72 67 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e args.</li>..<li>
3cc0: 3c 75 3e 50 6c 65 61 73 65 20 6e 6f 74 65 3c 2f <u>Please note</
3cd0: 75 3e 3a 20 74 68 69 73 20 73 70 65 63 69 66 69 u>: this specifi
3ce0: 63 20 66 6c 61 76 6f 72 20 6f 66 20 3c 62 3e 53 c flavor of <b>S
3cf0: 54 5f 41 72 65 61 28 29 3c 2f 62 3e 20 6e 65 63 T_Area()</b> nec
3d00: 65 73 73 61 72 69 6c 79 20 72 65 71 75 69 72 65 essarily require
3d10: 73 20 74 68 65 20 3c 62 3e 4c 57 47 45 4f 4d 3c s the <b>LWGEOM<
3d20: 2f 62 3e 20 73 75 70 70 6f 72 74 20 74 6f 20 62 /b> support to b
3d30: 65 20 61 63 74 69 76 61 74 65 64 20 61 74 20 62 e activated at b
3d40: 75 69 6c 64 20 74 69 6d 65 2e 3c 2f 6c 69 3e 0d uild time.</li>.
3d50: 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d 0a 3c 68 72 3e .</ul><br>..<hr>
3d60: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 ..<verbatim>..SE
3d70: 4c 45 43 54 20 53 54 5f 41 73 54 65 78 74 28 20 LECT ST_AsText(
3d80: 53 54 5f 50 72 6f 6a 65 63 74 28 20 4d 61 6b 65 ST_Project( Make
3d90: 50 6f 69 6e 74 28 20 31 31 2e 35 32 2c 20 34 32 Point( 11.52, 42
3da0: 2e 33 38 2c 20 34 33 32 36 20 29 2c 20 35 30 30 .38, 4326 ), 500
3db0: 30 30 2c 20 52 61 64 69 61 6e 73 28 20 34 35 20 00, Radians( 45
3dc0: 29 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d ) ) );..--------
3dd0: 2d 2d 0d 0a 50 4f 49 4e 54 28 31 31 2e 39 35 31 --..POINT(11.951
3de0: 34 37 39 20 34 32 2e 36 39 37 34 36 37 29 0d 0a 479 42.697467)..
3df0: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65 </verbatim>..The
3e00: 20 3c 62 3e 53 54 5f 50 72 6f 6a 65 63 74 28 29 <b>ST_Project()
3e10: 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f </b> SQL functio
3e20: 6e 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 74 68 n will return th
3e30: 65 20 64 65 73 74 69 6e 61 74 69 6f 6e 20 50 6f e destination Po
3e40: 69 6e 74 20 3c 75 3e 6f 6e 20 74 68 65 20 65 6c int <u>on the el
3e50: 6c 69 70 73 6f 69 64 3c 2f 75 3e 20 63 6f 72 72 lipsoid</u> corr
3e60: 65 73 70 6f 6e 64 69 6e 67 20 74 6f 20 61 20 3c esponding to a <
3e70: 62 3e 73 74 61 72 74 5f 70 6f 69 6e 74 3c 2f 62 b>start_point</b
3e80: 3e 2c 20 61 20 3c 62 3e 64 69 73 74 61 6e 63 65 >, a <b>distance
3e90: 3c 2f 62 3e 20 61 6e 64 20 61 20 3c 62 3e 62 65 </b> and a <b>be
3ea0: 61 72 69 6e 67 3c 2f 62 3e 20 28 61 6b 61 20 3c aring</b> (aka <
3eb0: 75 3e 61 7a 69 6d 75 74 68 3c 2f 75 3e 20 61 6b u>azimuth</u> ak
3ec0: 61 20 3c 75 3e 64 69 72 65 63 74 69 6f 6e 3c 2f a <u>direction</
3ed0: 75 3e 20 61 6b 61 20 3c 75 3e 68 65 61 64 69 6e u> aka <u>headin
3ee0: 67 3c 2f 75 3e 29 2e 0d 0a 3c 75 6c 3e 0d 0a 3c g</u>)...<ul>..<
3ef0: 6c 69 3e 74 68 65 20 3c 62 3e 73 74 61 72 74 5f li>the <b>start_
3f00: 70 6f 69 6e 74 3c 2f 62 3e 20 69 73 20 65 78 70 point</b> is exp
3f10: 65 63 74 65 64 20 74 6f 20 61 64 6f 70 74 20 3c ected to adopt <
3f20: 75 3e 67 65 6f 67 72 61 70 68 69 63 20 63 6f 6f u>geographic coo
3f30: 72 64 69 6e 61 74 65 73 3c 2f 75 3e 20 28 69 2e rdinates</u> (i.
3f40: 65 2e 20 62 61 73 65 64 20 6f 6e 20 3c 75 3e 6c e. based on <u>l
3f50: 6f 6e 67 69 74 75 64 65 3c 2f 75 3e 20 61 6e 64 ongitude</u> and
3f60: 20 3c 75 3e 6c 61 74 69 74 75 64 65 3c 2f 75 3e <u>latitude</u>
3f70: 20 61 6e 67 6c 65 73 29 2e 3c 2f 6c 69 3e 0d 0a angles).</li>..
3f80: 3c 6c 69 3e 74 68 65 20 3c 62 3e 64 69 73 74 61 <li>the <b>dista
3f90: 6e 63 65 3c 2f 62 3e 20 69 73 20 61 6c 77 61 79 nce</b> is alway
3fa0: 73 20 65 78 70 65 63 74 65 64 20 74 6f 20 62 65 s expected to be
3fb0: 20 65 78 70 72 65 73 73 65 64 20 69 6e 20 3c 62 expressed in <b
3fc0: 3e 6d 65 74 65 72 73 3c 2f 62 3e 2e 3c 2f 6c 69 >meters</b>.</li
3fd0: 3e 0d 0a 3c 6c 69 3e 74 68 65 20 3c 62 3e 61 7a >..<li>the <b>az
3fe0: 69 6d 75 74 68 3c 2f 62 3e 20 61 6e 67 6c 65 20 imuth</b> angle
3ff0: 69 73 20 65 78 70 65 63 74 65 64 20 74 6f 20 62 is expected to b
4000: 65 20 65 78 70 72 65 73 73 65 64 20 69 6e 20 3c e expressed in <
4010: 62 3e 72 61 64 69 61 6e 73 3c 2f 62 3e 3a 0d 0a b>radians</b>:..
4020: 3c 75 6c 3e 0d 0a 3c 6c 69 3e 4e 6f 72 74 68 20 <ul>..<li>North
4030: 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 30 corresponds to 0
4040: 20 64 65 67 72 65 65 73 20 28 30 20 72 61 64 69 degrees (0 radi
4050: 61 6e 73 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e ans).</li>..<li>
4060: 45 61 73 74 20 63 6f 72 72 65 73 70 6f 6e 64 73 East corresponds
4070: 20 74 6f 20 39 30 20 64 65 67 72 65 65 73 20 28 to 90 degrees (
4080: 50 49 2f 32 20 72 61 64 69 61 6e 73 29 2e 3c 2f PI/2 radians).</
4090: 6c 69 3e 0d 0a 3c 6c 69 3e 53 6f 75 74 68 20 63 li>..<li>South c
40a0: 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 31 38 orresponds to 18
40b0: 30 20 64 65 67 72 65 65 73 20 28 50 49 20 72 61 0 degrees (PI ra
40c0: 64 69 61 6e 73 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c dians).</li>..<l
40d0: 69 3e 57 65 73 74 20 63 6f 72 72 65 73 70 6f 6e i>West correspon
40e0: 64 73 20 74 6f 20 32 37 30 20 64 65 67 72 65 65 ds to 270 degree
40f0: 73 20 28 33 50 49 2f 32 20 72 61 64 69 61 6e 73 s (3PI/2 radians
4100: 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 69 2e 65 ).</li>..<li>i.e
4110: 2e 20 69 74 20 68 61 73 20 74 68 65 20 73 61 6d . it has the sam
4120: 65 20 69 64 65 6e 74 69 63 61 6c 20 6d 65 61 6e e identical mean
4130: 69 6e 67 20 61 73 20 69 6e 20 3c 62 3e 53 54 5f ing as in <b>ST_
4140: 41 7a 69 6d 75 74 68 28 29 3c 2f 62 3e 2e 3c 2f Azimuth()</b>.</
4150: 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 2f 6c 69 3e 0d li>..</ul></li>.
4160: 0a 3c 6c 69 3e 74 68 69 73 20 66 75 6e 63 74 69 .<li>this functi
4170: 6f 6e 20 65 78 61 63 74 6c 79 20 63 6f 72 72 65 on exactly corre
4180: 73 70 6f 6e 64 73 20 74 6f 20 74 68 65 20 6f 6e sponds to the on
4190: 65 20 73 75 70 70 6f 72 74 65 64 20 62 79 20 3c e supported by <
41a0: 62 3e 50 6f 73 74 47 49 53 3c 2f 62 3e 2e 3c 2f b>PostGIS</b>.</
41b0: 6c 69 3e 0d 0a 3c 6c 69 3e 3c 75 3e 50 6c 65 61 li>..<li><u>Plea
41c0: 73 65 20 6e 6f 74 65 3c 2f 75 3e 3a 20 3c 62 3e se note</u>: <b>
41d0: 53 54 5f 50 72 6f 6a 65 63 74 28 29 3c 2f 62 3e ST_Project()</b>
41e0: 20 6e 65 63 65 73 73 61 72 69 6c 79 20 72 65 71 necessarily req
41f0: 75 69 72 65 73 20 74 68 65 20 3c 62 3e 4c 57 47 uires the <b>LWG
4200: 45 4f 4d 3c 2f 62 3e 20 73 75 70 70 6f 72 74 20 EOM</b> support
4210: 74 6f 20 62 65 20 61 63 74 69 76 61 74 65 64 20 to be activated
4220: 61 74 20 62 75 69 6c 64 20 74 69 6d 65 2e 3c 2f at build time.</
4230: 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d 0a li>..</ul><br>..
4240: 3c 68 72 3e 0d 0a 3c 68 33 3e 3c 61 20 6e 61 6d <hr>..<h3><a nam
4250: 65 3d 22 75 6e 73 61 66 65 22 3e 55 6e 73 61 66 e="unsafe">Unsaf
4260: 65 3c 2f 61 3e 20 28 62 75 74 20 75 73 65 66 75 e</a> (but usefu
4270: 6c 29 20 49 6d 70 6f 72 74 2f 45 78 70 6f 72 74 l) Import/Export
4280: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 73 3c 2f SQL functions</
4290: 68 33 3e 0d 0a 41 6c 6c 20 74 68 65 20 66 6f 6c h3>..All the fol
42a0: 6c 6f 77 69 6e 67 20 53 51 4c 20 66 75 6e 63 74 lowing SQL funct
42b0: 69 6f 6e 73 20 63 6f 75 6c 64 20 62 65 20 72 65 ions could be re
42c0: 61 6c 6c 79 20 75 73 65 66 75 6c 20 69 6e 20 6f ally useful in o
42d0: 72 64 65 72 20 74 6f 20 73 75 70 70 6f 72 74 20 rder to support
42e0: 49 6d 70 6f 72 74 2f 45 78 70 6f 72 74 20 6f 70 Import/Export op
42f0: 65 72 61 74 69 6f 6e 73 2e 3c 62 72 3e 0d 0a 41 erations.<br>..A
4300: 6e 79 77 61 79 20 79 6f 75 20 73 68 6f 75 6c 64 nyway you should
4310: 20 62 65 20 3c 75 3e 77 65 6c 6c 20 61 77 61 72 be <u>well awar
4320: 65 3c 2f 75 3e 20 74 68 61 74 20 61 6c 6c 20 74 e</u> that all t
4330: 68 65 6d 20 63 6f 75 6c 64 20 62 65 20 70 6f 74 hem could be pot
4340: 65 6e 74 69 61 6c 6c 79 20 3c 75 3e 75 6e 73 61 entially <u>unsa
4350: 66 65 3c 2f 75 3e 20 61 6e 64 20 63 6f 75 6c 64 fe</u> and could
4360: 20 62 65 20 70 6f 74 65 6e 74 69 61 6c 6c 79 20 be potentially
4370: 75 73 65 64 20 62 79 20 73 6f 6d 65 20 3c 75 3e used by some <u>
4380: 6d 61 6c 69 63 69 6f 75 73 20 68 61 63 6b 65 72 malicious hacker
4390: 3c 2f 75 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f </u> in order to
43a0: 20 63 72 65 61 74 65 20 61 6e 64 20 65 78 70 6c create and expl
43b0: 6f 69 74 20 73 6f 6d 65 20 3c 75 3e 73 65 63 75 oit some <u>secu
43c0: 72 69 74 79 20 62 72 65 61 63 68 3c 2f 75 3e 2e rity breach</u>.
43d0: 3c 62 72 3e 0d 0a 54 68 65 20 63 61 75 73 65 20 <br>..The cause
43e0: 69 73 20 76 65 72 79 20 65 61 73 79 20 74 6f 20 is very easy to
43f0: 62 65 20 75 6e 64 65 72 73 74 6f 6f 64 3a 20 74 be understood: t
4400: 68 65 73 65 20 66 75 6e 63 74 69 6f 6e 73 20 61 hese functions a
4410: 6c 6c 6f 77 20 74 6f 20 74 72 61 6e 73 66 65 72 llow to transfer
4420: 20 61 72 62 69 74 72 61 72 79 20 70 61 79 6c 6f arbitrary paylo
4430: 61 64 73 20 66 72 6f 6d 20 2f 20 74 6f 20 74 68 ads from / to th
4440: 65 20 44 61 74 61 62 61 73 65 20 61 6e 64 20 74 e Database and t
4450: 68 65 20 6c 6f 63 61 6c 20 46 69 6c 65 2d 53 79 he local File-Sy
4460: 73 74 65 6d 2e 0d 0a 41 20 6d 61 6c 69 63 69 6f stem...A malicio
4470: 75 73 20 61 74 74 61 63 6b 20 63 6f 75 6c 64 20 us attack could
4480: 62 65 20 74 68 75 73 20 69 6d 70 6c 65 6d 65 6e be thus implemen
4490: 74 65 64 20 65 2e 67 2e 20 62 79 20 65 78 65 63 ted e.g. by exec
44a0: 75 74 69 6e 67 20 73 6f 6d 65 20 53 51 4c 20 73 uting some SQL s
44b0: 63 72 69 70 74 20 6f 72 20 62 79 20 64 65 66 69 cript or by defi
44c0: 6e 69 6e 67 20 61 20 70 75 72 70 6f 73 65 6c 79 ning a purposely
44d0: 20 66 6f 72 67 65 64 20 54 72 69 67 67 65 72 2c forged Trigger,
44e0: 20 61 6e 64 20 74 68 65 20 65 6e 64 20 75 73 65 and the end use
44f0: 72 73 20 77 6f 75 6c 64 20 62 65 20 61 62 73 6f rs would be abso
4500: 6c 75 74 65 6c 79 20 75 6e 61 77 61 72 65 20 6f lutely unaware o
4510: 66 20 77 68 61 74 20 69 73 20 72 65 61 6c 6c 79 f what is really
4520: 20 68 61 70 70 65 6e 69 6e 67 2e 0d 0a 53 6f 20 happening...So
4530: 69 6e 20 6f 72 64 65 72 20 74 6f 20 65 66 66 65 in order to effe
4540: 63 74 69 76 65 6c 79 20 73 68 69 65 6c 64 20 75 ctively shield u
4550: 73 65 72 73 20 61 67 61 69 6e 73 74 20 74 68 65 sers against the
4560: 73 65 20 70 6f 74 65 6e 74 69 61 6c 6c 79 20 64 se potentially d
4570: 61 6e 67 65 72 6f 75 73 20 73 65 63 75 72 69 74 angerous securit
4580: 79 20 70 69 74 66 61 6c 6c 73 20 61 6c 6c 20 74 y pitfalls all t
4590: 68 65 73 65 20 53 51 4c 20 66 75 6e 63 74 69 6f hese SQL functio
45a0: 6e 73 20 61 72 65 20 61 6c 77 61 79 73 20 3c 75 ns are always <u
45b0: 3e 64 69 73 61 62 6c 65 64 20 62 79 20 64 65 66 >disabled by def
45c0: 61 75 6c 74 3c 2f 75 3e 2e 0d 0a 3c 76 65 72 62 ault</u>...<verb
45d0: 61 74 69 6d 3e 0d 0a 65 78 70 6f 72 74 20 22 53 atim>..export "S
45e0: 50 41 54 49 41 4c 49 54 45 5f 53 45 43 55 52 49 PATIALITE_SECURI
45f0: 54 59 3d 72 65 6c 61 78 65 64 22 0d 0a 3c 2f 76 TY=relaxed"..</v
4600: 65 72 62 61 74 69 6d 3e 0d 0a 49 6e 20 6f 72 64 erbatim>..In ord
4610: 65 72 20 74 6f 20 72 65 61 6c 6c 79 20 65 6e 61 er to really ena
4620: 62 6c 65 20 74 68 65 73 65 20 66 75 6e 63 74 69 ble these functi
4630: 6f 6e 73 20 74 68 65 20 75 73 65 72 20 69 73 20 ons the user is
4640: 72 65 71 75 69 72 65 64 20 74 6f 20 74 61 6b 65 required to take
4650: 20 61 6e 20 65 78 70 6c 69 63 69 74 20 61 63 74 an explicit act
4660: 69 6f 6e 3b 20 69 2e 65 2e 20 74 68 65 20 3c 75 ion; i.e. the <u
4670: 3e 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 76 61 72 >environment var
4680: 69 61 62 6c 65 3c 2f 75 3e 20 3c 62 3e 53 50 41 iable</u> <b>SPA
4690: 54 49 41 4c 49 54 45 5f 53 45 43 55 52 49 54 59 TIALITE_SECURITY
46a0: 3d 72 65 6c 61 78 65 64 3c 2f 62 3e 20 68 61 73 =relaxed</b> has
46b0: 20 74 6f 20 62 65 20 64 65 66 69 6e 65 64 2e 0d to be defined..
46c0: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c .<verbatim>..SEL
46d0: 45 43 54 20 43 6f 75 6e 74 55 6e 73 61 66 65 54 ECT CountUnsafeT
46e0: 72 69 67 67 65 72 73 28 29 3b 0d 0a 2d 2d 2d 2d riggers();..----
46f0: 2d 2d 2d 2d 2d 0d 0a 30 0d 0a 3c 2f 76 65 72 62 -----..0..</verb
4700: 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 43 6f atim>..The <b>Co
4710: 75 6e 74 55 6e 73 61 66 65 54 72 69 67 67 65 72 untUnsafeTrigger
4720: 73 28 29 3c 2f 62 3e 20 61 63 74 75 61 6c 6c 79 s()</b> actually
4730: 20 63 68 65 63 6b 73 20 69 66 20 74 68 65 20 63 checks if the c
4740: 6f 6e 6e 65 63 74 65 64 20 44 61 74 61 62 61 73 onnected Databas
4750: 65 20 64 6f 65 73 20 63 6f 6e 74 61 69 6e 73 20 e does contains
4760: 61 6e 79 20 73 75 73 70 65 63 74 20 54 72 69 67 any suspect Trig
4770: 67 65 72 3b 20 63 68 65 63 6b 69 6e 67 20 74 68 ger; checking th
4780: 69 73 20 76 65 72 73 69 6f 6e 20 62 65 66 6f 72 is version befor
4790: 65 20 65 6e 61 62 6c 69 6e 67 20 74 68 65 20 75 e enabling the u
47a0: 6e 73 61 66 65 20 53 51 4c 20 46 75 6e 63 74 69 nsafe SQL Functi
47b0: 6f 6e 73 20 69 73 20 61 6c 77 61 79 73 20 68 69 ons is always hi
47c0: 67 68 6c 79 20 72 65 63 6f 6d 6d 65 6e 64 65 64 ghly recommended
47d0: 2e 3c 62 72 3e 0d 0a 41 20 72 65 73 75 6c 74 20 .<br>..A result
47e0: 64 69 66 66 65 72 65 6e 74 20 66 72 6f 6d 20 5a different from Z
47f0: 45 52 4f 20 69 6d 70 6c 69 65 73 20 74 68 61 74 ERO implies that
4800: 20 73 6f 6d 65 20 6d 61 6c 69 63 69 6f 75 73 20 some malicious
4810: 54 72 69 67 67 65 72 20 68 61 73 20 62 65 65 6e Trigger has been
4820: 20 69 64 65 6e 74 69 66 69 65 64 3b 20 69 6e 20 identified; in
4830: 74 68 69 73 20 63 61 73 65 20 79 6f 75 20 63 61 this case you ca
4840: 6e 20 70 65 72 66 6f 72 6d 20 61 20 64 65 65 70 n perform a deep
4850: 65 73 74 20 69 6e 73 70 65 63 74 69 6f 6e 20 62 est inspection b
4860: 79 20 65 78 65 63 75 74 69 6e 67 20 74 68 65 20 y executing the
4870: 66 6f 6c 6c 6f 77 69 6e 67 20 53 51 4c 20 71 75 following SQL qu
4880: 65 72 79 3a 0d 0a 3c 76 65 72 62 61 74 69 6d 3e ery:..<verbatim>
4890: 0d 0a 53 45 4c 45 43 54 20 74 79 70 65 2c 20 6e ..SELECT type, n
48a0: 61 6d 65 2c 20 74 62 6c 5f 6e 61 6d 65 2c 20 73 ame, tbl_name, s
48b0: 71 6c 20 0d 0a 46 52 4f 4d 20 73 71 6c 69 74 65 ql ..FROM sqlite
48c0: 5f 6d 61 73 74 65 72 20 0d 0a 57 48 45 52 45 20 _master ..WHERE
48d0: 74 79 70 65 20 49 4e 20 28 27 74 72 69 67 67 65 type IN ('trigge
48e0: 72 27 2c 20 27 76 69 65 77 27 29 20 41 4e 44 20 r', 'view') AND
48f0: 28 73 71 6c 20 4c 49 4b 45 20 27 25 42 6c 6f 62 (sql LIKE '%Blob
4900: 46 72 6f 6d 46 69 6c 65 25 27 20 0d 0a 20 20 20 FromFile%' ..
4910: 4f 52 20 73 71 6c 20 4c 49 4b 45 20 27 25 42 6c OR sql LIKE '%Bl
4920: 6f 62 54 6f 46 69 6c 65 25 27 20 4f 52 20 73 71 obToFile%' OR sq
4930: 6c 20 4c 49 4b 45 20 27 25 58 42 5f 4c 6f 61 64 l LIKE '%XB_Load
4940: 58 4d 4c 25 27 20 0d 0a 20 20 20 4f 52 20 73 71 XML%' .. OR sq
4950: 6c 20 4c 49 4b 45 20 27 25 58 42 5f 53 74 6f 72 l LIKE '%XB_Stor
4960: 65 58 4d 4c 25 27 29 3b 0d 0a 3c 2f 76 65 72 62 eXML%');..</verb
4970: 61 74 69 6d 3e 0d 0a 74 68 69 73 20 77 69 6c 6c atim>..this will
4980: 20 67 69 76 65 20 61 20 66 75 6c 6c 20 72 65 70 give a full rep
4990: 6f 72 74 20 66 6f 72 20 61 6e 79 20 6d 61 6c 69 ort for any mali
49a0: 63 69 6f 75 73 20 54 72 69 67 67 65 72 20 65 76 cious Trigger ev
49b0: 65 6e 74 75 61 6c 6c 79 20 66 6f 75 6e 64 2e 3c entually found.<
49c0: 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c br><br>..<hr>..<
49d0: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 verbatim>..SELEC
49e0: 54 20 42 6c 6f 62 46 72 6f 6d 46 69 6c 65 28 20 T BlobFromFile(
49f0: 27 43 3a 2f 6d 79 70 69 63 74 75 72 65 73 2f 73 'C:/mypictures/s
4a00: 75 6e 73 65 74 2e 6a 70 67 27 20 29 3b 0d 0a 2d unset.jpg' );..-
4a10: 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 42 4c 4f 42 2d 76 --------..BLOB-v
4a20: 61 6c 75 65 0d 0a 3c 2f 76 65 72 62 61 74 69 6d alue..</verbatim
4a30: 3e 0d 0a 54 68 65 20 3c 62 3e 42 6c 6f 62 46 72 >..The <b>BlobFr
4a40: 6f 6d 46 69 6c 65 28 29 3c 2f 62 3e 20 53 51 4c omFile()</b> SQL
4a50: 20 66 75 6e 63 74 69 6f 6e 20 61 6c 6c 6f 77 73 function allows
4a60: 20 74 6f 20 69 6d 70 6f 72 74 20 61 20 77 68 6f to import a who
4a70: 6c 65 20 66 69 6c 65 20 69 6e 20 61 20 73 69 6e le file in a sin
4a80: 67 6c 65 20 73 74 65 70 3b 20 74 68 65 20 66 75 gle step; the fu
4a90: 6c 6c 20 66 69 6c 65 20 70 61 79 6c 6f 61 64 20 ll file payload
4aa0: 77 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 will be returned
4ab0: 20 61 73 20 61 20 42 4c 4f 42 20 76 61 6c 75 65 as a BLOB value
4ac0: 2e 3c 62 72 3e 0d 0a 49 66 20 74 68 65 20 61 72 .<br>..If the ar
4ad0: 67 75 6d 65 6e 74 20 28 3c 62 3e 66 69 6c 65 2d gument (<b>file-
4ae0: 70 61 74 68 3c 2f 62 3e 29 20 64 6f 65 73 6e 27 path</b>) doesn'
4af0: 74 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f t corresponds to
4b00: 20 61 20 76 61 6c 69 64 20 66 69 6c 65 20 6f 72 a valid file or
4b10: 20 69 66 20 74 68 65 20 65 78 74 65 72 6e 61 6c if the external
4b20: 20 66 69 6c 65 20 63 61 6e 6e 6f 74 20 62 65 20 file cannot be
4b30: 61 63 63 65 73 73 65 64 20 66 6f 72 20 61 6e 79 accessed for any
4b40: 20 72 65 61 73 6f 6e 20 4e 55 4c 4c 20 77 69 6c reason NULL wil
4b50: 6c 20 62 65 20 72 65 74 75 72 6e 65 64 2e 3c 62 l be returned.<b
4b60: 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 76 r><br>..<hr>..<v
4b70: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 erbatim>..SELECT
4b80: 20 42 6c 6f 62 54 6f 46 69 6c 65 28 20 73 6f 6d BlobToFile( som
4b90: 65 42 6c 6f 62 20 2c 20 27 43 3a 2f 6d 79 70 69 eBlob , 'C:/mypi
4ba0: 63 74 75 72 65 73 2f 73 75 6e 73 65 74 2e 6a 70 ctures/sunset.jp
4bb0: 67 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d g' );..---------
4bc0: 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e ..1..</verbatim>
4bd0: 0d 0a 54 68 65 20 3c 62 3e 42 6c 6f 62 54 6f 46 ..The <b>BlobToF
4be0: 69 6c 65 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 ile()</b> SQL fu
4bf0: 6e 63 74 69 6f 6e 20 70 65 72 66 6f 72 6d 73 20 nction performs
4c00: 74 68 65 20 6f 70 70 6f 73 69 74 65 20 74 61 73 the opposite tas
4c10: 6b 2c 20 69 2e 65 2e 20 69 74 20 65 78 70 6f 72 k, i.e. it expor
4c20: 74 73 20 61 20 77 68 6f 6c 65 20 42 4c 4f 42 20 ts a whole BLOB
4c30: 69 6e 74 6f 20 61 6e 20 65 78 74 65 72 6e 61 6c into an external
4c40: 20 66 69 6c 65 3b 20 74 68 65 20 66 69 72 73 74 file; the first
4c50: 20 61 72 67 75 6d 65 6e 74 20 6d 75 73 74 20 63 argument must c
4c60: 6f 72 72 65 73 70 6f 6e 64 20 74 6f 20 73 6f 6d orrespond to som
4c70: 65 20 42 4c 4f 42 2c 20 74 68 65 20 73 65 63 6f e BLOB, the seco
4c80: 6e 64 20 6f 6e 65 20 69 73 20 74 68 65 20 3c 62 nd one is the <b
4c90: 3e 66 69 6c 65 2d 70 61 74 68 3c 2f 62 3e 20 69 >file-path</b> i
4ca0: 64 65 6e 74 69 66 79 69 6e 67 20 74 68 65 20 66 dentifying the f
4cb0: 69 6c 65 20 74 6f 20 62 65 20 63 72 65 61 74 65 ile to be create
4cc0: 64 20 6f 72 20 6f 76 65 72 77 72 69 74 74 65 6e d or overwritten
4cd0: 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 75 3e 50 6c .<br><br>..<u>Pl
4ce0: 65 61 73 65 20 6e 6f 74 65 3c 2f 75 3e 3a 20 62 ease note</u>: b
4cf0: 6f 74 68 20 3c 62 3e 42 6c 6f 62 46 72 6f 6d 46 oth <b>BlobFromF
4d00: 69 6c 65 28 29 3c 2f 62 3e 20 61 6e 64 20 3c 62 ile()</b> and <b
4d10: 3e 42 6c 6f 62 54 6f 46 69 6c 65 28 29 3c 2f 62 >BlobToFile()</b
4d20: 3e 20 77 65 72 65 20 61 6c 72 65 61 64 79 20 73 > were already s
4d30: 75 70 70 6f 72 74 65 64 20 62 79 20 34 2e 30 2e upported by 4.0.
4d40: 30 2c 20 62 75 74 20 61 20 71 75 69 63 6b 20 72 0, but a quick r
4d50: 65 63 61 6c 6c 20 69 73 20 61 6e 79 77 61 79 20 ecall is anyway
4d60: 75 73 65 66 75 6c 20 73 6f 20 74 6f 20 72 65 63 useful so to rec
4d70: 61 6c 6c 20 61 20 63 6c 65 61 72 65 72 20 63 6f all a clearer co
4d80: 6e 74 65 78 74 2e 3c 62 72 3e 3c 62 72 3e 0d 0a ntext.<br><br>..
4d90: 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e <hr>..<verbatim>
4da0: 0d 0a 53 45 4c 45 43 54 20 58 42 5f 4c 6f 61 64 ..SELECT XB_Load
4db0: 58 4d 4c 28 20 27 43 3a 2f 6d 79 64 6f 63 73 2f XML( 'C:/mydocs/
4dc0: 69 73 6f 6d 65 74 61 64 61 74 61 2d 73 61 6d 70 isometadata-samp
4dd0: 6c 65 2e 78 6d 6c 27 20 29 3b 0d 0a 2d 2d 2d 2d le.xml' );..----
4de0: 2d 2d 2d 2d 0d 0a 42 4c 4f 42 2d 76 61 6c 75 65 ----..BLOB-value
4df0: 0d 0a 0d 0a 53 45 4c 45 43 54 20 58 42 5f 4c 6f ....SELECT XB_Lo
4e00: 61 64 58 4d 4c 28 20 27 68 74 74 70 3a 2f 2f 77 adXML( 'http://w
4e10: 77 77 2e 61 63 6d 65 2e 63 6f 6d 2f 70 75 62 6c ww.acme.com/publ
4e20: 69 63 2f 69 73 6f 6d 65 74 61 64 61 74 61 2d 73 ic/isometadata-s
4e30: 61 6d 70 6c 65 2e 78 6d 6c 27 20 29 3b 0d 0a 2d ample.xml' );..-
4e40: 2d 2d 2d 2d 2d 2d 2d 0d 0a 42 4c 4f 42 2d 76 61 -------..BLOB-va
4e50: 6c 75 65 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e lue..</verbatim>
4e60: 0d 0a 54 68 65 20 3c 62 3e 58 42 5f 4c 6f 61 64 ..The <b>XB_Load
4e70: 58 4d 4c 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 XML()</b> SQL fu
4e80: 6e 63 74 69 6f 6e 20 61 6c 6c 6f 77 73 20 74 6f nction allows to
4e90: 20 69 6d 70 6f 72 74 20 61 6e 20 58 4d 4c 20 44 import an XML D
4ea0: 6f 63 75 6d 65 6e 74 20 69 6e 20 61 20 73 69 6e ocument in a sin
4eb0: 67 6c 65 20 73 74 65 70 3a 20 74 68 65 20 66 75 gle step: the fu
4ec0: 6c 6c 20 58 4d 4c 20 44 6f 63 75 6d 65 6e 74 20 ll XML Document
4ed0: 70 61 79 6c 6f 61 64 20 77 69 6c 6c 20 62 65 20 payload will be
4ee0: 72 65 74 75 72 6e 65 64 20 61 73 20 61 20 42 4c returned as a BL
4ef0: 4f 42 20 76 61 6c 75 65 2e 3c 62 72 3e 0d 0a 54 OB value.<br>..T
4f00: 68 65 20 70 61 73 73 65 64 20 61 72 67 75 6d 65 he passed argume
4f10: 6e 74 20 63 61 6e 20 69 6e 64 69 66 66 65 72 65 nt can indiffere
4f20: 6e 74 6c 79 20 62 65 20 61 20 3c 62 3e 66 69 6c ntly be a <b>fil
4f30: 65 2d 70 61 74 68 3c 2f 62 3e 20 6f 72 20 61 20 e-path</b> or a
4f40: 3c 62 3e 55 52 4c 3c 2f 62 3e 3b 20 69 66 20 74 <b>URL</b>; if t
4f50: 68 65 20 64 61 74 61 73 6f 75 72 63 65 20 63 61 he datasource ca
4f60: 6e 6e 6f 74 20 62 65 20 61 63 63 65 73 73 65 64 nnot be accessed
4f70: 2c 20 6f 72 20 69 66 20 69 74 20 64 6f 65 73 6e , or if it doesn
4f80: 27 74 20 63 6f 6e 74 61 69 6e 73 20 61 20 3c 75 't contains a <u
4f90: 3e 77 65 6c 6c 2d 66 6f 72 6d 65 64 3c 2f 75 3e >well-formed</u>
4fa0: 20 58 4d 4c 20 44 6f 63 75 6d 65 6e 74 20 4e 55 XML Document NU
4fb0: 4c 4c 20 77 69 6c 6c 20 62 65 20 72 65 74 75 72 LL will be retur
4fc0: 6e 65 64 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 ned.<br><br>..<h
4fd0: 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a r>..<verbatim>..
4fe0: 53 45 4c 45 43 54 20 58 42 5f 53 74 6f 72 65 58 SELECT XB_StoreX
4ff0: 4d 4c 28 20 73 6f 6d 65 58 6d 6c 42 6c 6f 62 2c ML( someXmlBlob,
5000: 20 27 43 3a 2f 6d 79 64 6f 63 73 2f 69 73 6f 6d 'C:/mydocs/isom
5010: 65 74 61 64 61 74 61 2d 73 61 6d 70 6c 65 2e 78 etadata-sample.x
5020: 6d 6c 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d ml' );..--------
5030: 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69 6d -..1..</verbatim
5040: 3e 0d 0a 54 68 65 20 3c 62 3e 58 42 5f 53 74 6f >..The <b>XB_Sto
5050: 72 65 58 4d 4c 28 29 3c 2f 62 3e 20 53 51 4c 20 reXML()</b> SQL
5060: 66 75 6e 63 74 69 6f 6e 20 70 65 72 66 6f 72 6d function perform
5070: 73 20 74 68 65 20 6f 70 70 6f 73 69 74 65 20 74 s the opposite t
5080: 61 73 6b 2c 20 69 2e 65 2e 20 69 74 20 65 78 70 ask, i.e. it exp
5090: 6f 72 74 73 20 61 20 77 68 6f 6c 65 20 58 6d 6c orts a whole Xml
50a0: 42 4c 4f 42 20 69 6e 74 6f 20 61 6e 20 65 78 74 BLOB into an ext
50b0: 65 72 6e 61 6c 20 66 69 6c 65 20 61 73 20 61 6e ernal file as an
50c0: 20 58 4d 4c 20 44 6f 63 75 6d 65 6e 74 3b 20 74 XML Document; t
50d0: 68 65 20 66 69 72 73 74 20 61 72 67 75 6d 65 6e he first argumen
50e0: 74 20 6d 75 73 74 20 63 6f 72 72 65 73 70 6f 6e t must correspon
50f0: 64 20 74 6f 20 73 6f 6d 65 20 76 61 6c 69 64 20 d to some valid
5100: 58 6d 6c 42 4c 4f 42 2c 20 74 68 65 20 73 65 63 XmlBLOB, the sec
5110: 6f 6e 64 20 6f 6e 65 20 69 73 20 74 68 65 20 3c ond one is the <
5120: 62 3e 66 69 6c 65 2d 70 61 74 68 3c 2f 62 3e 20 b>file-path</b>
5130: 69 64 65 6e 74 69 66 79 69 6e 67 20 74 68 65 20 identifying the
5140: 66 69 6c 65 20 74 6f 20 62 65 20 63 72 65 61 74 file to be creat
5150: 65 64 20 6f 72 20 6f 76 65 72 77 72 69 74 74 65 ed or overwritte
5160: 6e 2e 20 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d n. ..<verbatim>.
5170: 0a 53 45 4c 45 43 54 20 58 42 5f 53 74 6f 72 65 .SELECT XB_Store
5180: 58 4d 4c 28 20 73 6f 6d 65 58 6d 6c 42 6c 6f 62 XML( someXmlBlob
5190: 2c 20 27 43 3a 2f 6d 79 64 6f 63 73 2f 69 73 6f , 'C:/mydocs/iso
51a0: 6d 65 74 61 64 61 74 61 2d 73 61 6d 70 6c 65 2e metadata-sample.
51b0: 78 6d 6c 27 2c 20 34 20 29 3b 0d 0a 2d 2d 2d 2d xml', 4 );..----
51c0: 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 -----..1..</verb
51d0: 61 74 69 6d 3e 0d 0a 41 20 66 75 72 74 68 65 72 atim>..A further
51e0: 20 6f 70 74 69 6f 6e 61 6c 20 3c 62 3e 69 6e 64 optional <b>ind
51f0: 65 6e 74 61 74 69 6f 6e 3c 2f 62 3e 20 61 72 67 entation</b> arg
5200: 75 6d 65 6e 74 20 63 61 6e 20 62 65 20 65 76 65 ument can be eve
5210: 6e 74 75 61 6c 6c 79 20 73 70 65 63 69 66 69 65 ntually specifie
5220: 64 3b 20 74 68 69 73 20 61 72 67 75 6d 65 6e 74 d; this argument
5230: 20 77 69 6c 6c 20 62 65 20 68 61 6e 64 6c 65 64 will be handled
5240: 20 65 78 61 63 74 6c 79 20 69 6e 20 74 68 65 20 exactly in the
5250: 73 61 6d 65 20 77 61 79 20 61 6c 72 65 61 64 79 same way already
5260: 20 73 70 65 63 69 66 69 65 64 20 66 6f 72 20 62 specified for b
5270: 6f 74 68 20 3c 62 3e 58 42 5f 47 65 74 50 61 79 oth <b>XB_GetPay
5280: 6c 6f 61 64 28 29 3c 2f 62 3e 20 61 6e 64 20 3c load()</b> and <
5290: 62 3e 58 42 5f 47 65 74 44 6f 63 75 6d 65 6e 74 b>XB_GetDocument
52a0: 28 29 3c 2f 62 3e 20 66 75 6e 63 74 69 6f 6e 73 ()</b> functions
52b0: 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d .<br><br>..<hr>.
52c0: 0a 3c 62 72 3e 41 20 66 75 72 74 68 65 72 20 3c .<br>A further <
52d0: 75 3e 3c 69 3e 75 6e 73 61 66 65 3c 2f 69 3e 3c u><i>unsafe</i><
52e0: 2f 75 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e /u> SQL function
52f0: 20 69 73 20 3c 62 3e 45 78 70 6f 72 74 44 58 46 is <b>ExportDXF
5300: 28 29 3c 2f 62 3e 2c 20 77 68 69 63 68 20 69 73 ()</b>, which is
5310: 20 73 65 70 61 72 61 74 65 6c 79 20 64 6f 63 75 separately docu
5320: 6d 65 6e 74 65 64 20 69 6e 74 6f 20 74 68 65 20 mented into the
5330: 6d 6f 72 65 20 61 70 70 72 6f 70 72 69 61 74 65 more appropriate
5340: 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 73 3a <a href="https:
5350: 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73 2e 69 //www.gaia-gis.i
5360: 74 2f 66 6f 73 73 69 6c 2f 6c 69 62 73 70 61 74 t/fossil/libspat
5370: 69 61 6c 69 74 65 2f 77 69 6b 69 3f 6e 61 6d 65 ialite/wiki?name
5380: 3d 44 58 46 22 3e 44 58 46 20 57 69 6b 69 20 70 =DXF">DXF Wiki p
5390: 61 67 65 3c 2f 61 3e 2e 3c 62 72 3e 3c 62 72 3e age</a>.<br><br>
53a0: 0d 0a 3c 68 72 3e 3c 62 72 3e 0d 0a 62 61 63 6b ..<hr><br>..back
53b0: 20 74 6f 20 3c 61 20 68 72 65 66 3d 22 68 74 74 to <a href="htt
53c0: 70 73 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 ps://www.gaia-gi
53d0: 73 2e 69 74 2f 66 6f 73 73 69 6c 2f 6c 69 62 73 s.it/fossil/libs
53e0: 70 61 74 69 61 6c 69 74 65 2f 77 69 6b 69 3f 6e patialite/wiki?n
53f0: 61 6d 65 3d 34 2e 31 2e 30 2d 64 6f 63 22 3e 34 ame=4.1.0-doc">4
5400: 2e 31 2e 30 2d 64 6f 63 3c 2f 61 3e 0a 5a 20 37 .1.0-doc</a>.Z 7
5410: 34 31 63 35 61 66 36 35 35 37 38 62 62 39 35 31 41c5af65578bb951
5420: 62 37 34 38 36 38 38 65 32 39 64 66 35 65 38 0a b748688e29df5e8.