Hex Artifact Content
Not logged in

Artifact 994ceab639fb94196c826d83cae89e5314fc9077:

Wiki page [4.1.0 Changes] by sandro 2013-06-03 16:23:04.
0000: 44 20 32 30 31 33 2d 30 36 2d 30 33 54 31 36 3a  D 2013-06-03T16:
0010: 32 33 3a 30 34 2e 34 39 32 0a 4c 20 34 2e 31 2e  23:04.492.L 4.1.
0020: 30 5c 73 43 68 61 6e 67 65 73 0a 50 20 34 38 35  0\sChanges.P 485
0030: 39 35 39 65 62 33 63 62 33 30 66 64 65 63 36 66  959eb3cb30fdec6f
0040: 38 63 30 30 32 35 33 35 65 33 34 61 62 66 33 31  8c002535e34abf31
0050: 31 63 64 32 61 0a 55 20 73 61 6e 64 72 6f 0a 57  1cd2a.U sandro.W
0060: 20 32 31 33 39 38 0a 62 61 63 6b 20 74 6f 20 3c   21398.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: 2e 3c 62 72 3e 0d 0a 54 68 65 20 75 6e 64 65 72  .<br>..The under
2920: 6c 79 69 6e 67 20 69 6d 70 6c 65 6d 65 6e 74 61  lying implementa
2930: 74 69 6f 6e 20 69 73 20 64 69 72 65 63 74 6c 79  tion is directly
2940: 20 62 61 73 65 64 20 6f 6e 20 74 68 65 20 3c 61   based on the <a
2950: 20 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f 6f 70   href="http://op
2960: 65 6e 77 61 6c 6c 2e 69 6e 66 6f 2f 77 69 6b 69  enwall.info/wiki
2970: 2f 70 65 6f 70 6c 65 2f 73 6f 6c 61 72 2f 73 6f  /people/solar/so
2980: 66 74 77 61 72 65 2f 70 75 62 6c 69 63 2d 64 6f  ftware/public-do
2990: 6d 61 69 6e 2d 73 6f 75 72 63 65 2d 63 6f 64 65  main-source-code
29a0: 2f 6d 64 35 22 3e 63 6f 64 65 3c 2f 61 3e 20 64  /md5">code</a> d
29b0: 65 76 65 6c 6f 70 65 64 20 62 79 20 41 6c 65 78  eveloped by Alex
29c0: 61 6e 64 65 72 20 50 65 73 6c 79 61 6b 20 61 6e  ander Peslyak an
29d0: 64 20 72 65 6c 65 61 73 65 64 20 6f 6e 20 74 68  d released on th
29e0: 65 20 50 75 62 6c 69 63 20 44 6f 6d 61 69 6e 2e  e Public Domain.
29f0: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45  ..<verbatim>..SE
2a00: 4c 45 43 54 20 4d 44 35 54 6f 74 61 6c 43 68 65  LECT MD5TotalChe
2a10: 63 6b 73 75 6d 28 67 65 6f 6d 65 74 72 79 29 0d  cksum(geometry).
2a20: 0a 46 52 4f 4d 20 63 6f 6d 32 30 31 31 3b 0d 0a  .FROM com2011;..
2a30: 2d 2d 2d 2d 2d 2d 0d 0a 38 65 62 30 30 32 36 35  ------..8eb00265
2a40: 38 39 39 30 30 32 32 61 36 66 30 63 31 63 62 32  8990022a6f0c1cb2
2a50: 34 61 36 30 66 62 66 36 0d 0a 3c 2f 76 65 72 62  4a60fbf6..</verb
2a60: 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 4d 44  atim>..The <b>MD
2a70: 35 54 6f 74 61 6c 43 68 65 63 6b 73 75 6d 28 29  5TotalChecksum()
2a80: 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f  </b> SQL functio
2a90: 6e 20 77 69 6c 6c 20 70 65 72 66 6f 72 6d 20 65  n will perform e
2aa0: 78 61 63 74 6c 79 20 74 68 65 20 73 61 6d 65 20  xactly the same 
2ab0: 69 64 65 6e 74 69 63 61 6c 20 74 61 73 6b 20 62  identical task b
2ac0: 75 74 20 69 73 20 69 6d 70 6c 65 6d 65 6e 74 65  ut is implemente
2ad0: 64 20 61 73 20 61 6e 20 3c 75 3e 3c 69 3e 61 67  d as an <u><i>ag
2ae0: 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e  gregate function
2af0: 3c 2f 69 3e 3c 2f 75 3e 2e 0d 0a 3c 62 72 3e 3c  </i></u>...<br><
2b00: 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 3c  br>..<hr>..<h3><
2b10: 61 20 6e 61 6d 65 3d 22 67 65 6f 6d 22 3e 53 70  a name="geom">Sp
2b20: 61 74 69 61 6c 3c 2f 61 3e 20 53 51 4c 20 66 75  atial</a> SQL fu
2b30: 6e 63 74 69 6f 6e 73 3c 2f 68 33 3e 0d 0a 46 65  nctions</h3>..Fe
2b40: 77 20 6d 6f 72 65 20 53 70 61 74 69 61 6c 20 53  w more Spatial S
2b50: 51 4c 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 65  QL functions are
2b60: 20 6e 6f 77 20 73 75 70 70 6f 72 74 65 64 2e 0d   now supported..
2b70: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c  .<verbatim>..SEL
2b80: 45 43 54 20 53 54 5f 41 73 54 65 78 74 28 20 53  ECT ST_AsText( S
2b90: 54 5f 41 64 64 50 6f 69 6e 74 28 20 0d 0a 20 20  T_AddPoint( ..  
2ba0: 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28  ST_GeomFromText(
2bb0: 20 27 4c 49 4e 45 53 54 52 49 4e 47 28 20 30 20   'LINESTRING( 0 
2bc0: 30 2c 20 31 20 30 20 29 27 20 29 2c 20 0d 0a 20  0, 1 0 )' ), .. 
2bd0: 20 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74   ST_GeomFromText
2be0: 28 20 27 50 4f 49 4e 54 28 20 31 20 31 20 29 27  ( 'POINT( 1 1 )'
2bf0: 20 29 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d   ) ) );..-------
2c00: 2d 0d 0a 4c 49 4e 45 53 54 52 49 4e 47 28 30 20  -..LINESTRING(0 
2c10: 30 2c 20 31 20 30 2c 20 31 20 31 29 0d 0a 3c 2f  0, 1 0, 1 1)..</
2c20: 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c  verbatim>..The <
2c30: 62 3e 53 54 5f 41 64 64 50 6f 69 6e 74 28 29 3c  b>ST_AddPoint()<
2c40: 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e  /b> SQL function
2c50: 20 61 64 64 73 20 61 20 66 75 72 74 68 65 72 20   adds a further 
2c60: 50 6f 69 6e 74 2f 56 65 72 74 65 78 20 61 74 20  Point/Vertex at 
2c70: 74 68 65 20 65 6e 64 20 6f 66 20 61 20 4c 69 6e  the end of a Lin
2c80: 65 73 74 72 69 6e 67 3b 20 74 68 65 20 66 69 72  estring; the fir
2c90: 73 74 20 61 72 67 75 6d 65 6e 74 20 69 73 20 61  st argument is a
2ca0: 6c 77 61 79 73 20 65 78 70 65 63 74 65 64 20 74  lways expected t
2cb0: 6f 20 62 65 20 6f 66 20 74 68 65 20 4c 69 6e 65  o be of the Line
2cc0: 73 74 72 69 6e 67 20 74 79 70 65 2c 20 74 68 65  string type, the
2cd0: 20 73 65 63 6f 6e 64 20 6f 6e 65 20 6d 75 73 74   second one must
2ce0: 20 62 65 20 61 20 50 6f 69 6e 74 2e 0d 0a 3c 76   be a Point...<v
2cf0: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54  erbatim>..SELECT
2d00: 20 53 54 5f 41 73 54 65 78 74 28 20 53 54 5f 41   ST_AsText( ST_A
2d10: 64 64 50 6f 69 6e 74 28 20 0d 0a 20 20 53 54 5f  ddPoint( ..  ST_
2d20: 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27 4c  GeomFromText( 'L
2d30: 49 4e 45 53 54 52 49 4e 47 28 20 31 20 30 2c 20  INESTRING( 1 0, 
2d40: 31 20 31 20 29 27 20 29 2c 20 0d 0a 20 20 53 54  1 1 )' ), ..  ST
2d50: 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27  _GeomFromText( '
2d60: 50 4f 49 4e 54 28 20 30 20 30 20 29 27 20 29 2c  POINT( 0 0 )' ),
2d70: 20 30 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d   0 ) );..-------
2d80: 2d 2d 0d 0a 4c 49 4e 45 53 54 52 49 4e 47 28 30  --..LINESTRING(0
2d90: 20 30 2c 20 31 20 30 2c 20 31 20 31 29 0d 0a 3c   0, 1 0, 1 1)..<
2da0: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 49 66 20 61  /verbatim>..If a
2db0: 6e 20 6f 70 74 69 6f 6e 61 6c 20 74 68 69 72 64  n optional third
2dc0: 20 61 72 67 75 6d 65 6e 74 20 28 6f 66 20 74 68   argument (of th
2dd0: 65 20 49 6e 74 65 67 65 72 20 74 79 70 65 29 20  e Integer type) 
2de0: 69 73 20 70 61 73 73 65 64 20 74 6f 20 3c 62 3e  is passed to <b>
2df0: 53 54 5f 41 64 64 50 6f 69 6e 74 28 29 3c 2f 62  ST_AddPoint()</b
2e00: 3e 20 69 74 27 73 20 69 6e 74 65 6e 64 65 64 20  > it's intended 
2e10: 74 6f 20 73 70 65 63 69 66 79 20 74 68 65 20 3c  to specify the <
2e20: 75 3e 69 6e 64 65 78 3c 2f 75 3e 20 6f 66 20 74  u>index</u> of t
2e30: 68 65 20 6e 65 77 20 56 65 72 74 65 78 20 28 66  he new Vertex (f
2e40: 69 72 73 74 20 56 65 72 74 65 78 20 68 61 73 20  irst Vertex has 
2e50: 69 6e 64 65 78 20 30 2c 20 73 65 63 6f 6e 64 20  index 0, second 
2e60: 56 65 72 74 65 78 20 68 61 73 20 69 6e 64 65 78  Vertex has index
2e70: 20 31 20 61 6e 64 20 73 6f 20 6f 6e 29 2e 3c 62   1 and so on).<b
2e80: 72 3e 0d 0a 52 65 66 65 72 65 6e 63 69 6e 67 20  r>..Referencing 
2e90: 61 20 6e 6f 74 20 65 78 69 73 74 69 6e 67 20 69  a not existing i
2ea0: 6e 64 65 78 20 69 73 20 61 6e 20 65 72 72 6f 72  ndex is an error
2eb0: 2c 20 61 6e 64 20 77 69 6c 6c 20 72 65 74 75 72  , and will retur
2ec0: 6e 20 4e 55 4c 4c 2e 0d 0a 3c 76 65 72 62 61 74  n NULL...<verbat
2ed0: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 54 5f 41  im>..SELECT ST_A
2ee0: 73 54 65 78 74 28 20 53 54 5f 41 64 64 50 6f 69  sText( ST_AddPoi
2ef0: 6e 74 28 20 0d 0a 20 20 53 54 5f 47 65 6f 6d 46  nt( ..  ST_GeomF
2f00: 72 6f 6d 54 65 78 74 28 20 27 4c 49 4e 45 53 54  romText( 'LINEST
2f10: 52 49 4e 47 28 20 30 20 30 2c 20 31 20 30 20 29  RING( 0 0, 1 0 )
2f20: 27 20 29 2c 20 0d 0a 20 20 53 54 5f 47 65 6f 6d  ' ), ..  ST_Geom
2f30: 46 72 6f 6d 54 65 78 74 28 20 27 50 4f 49 4e 54  FromText( 'POINT
2f40: 28 20 31 20 31 20 29 27 20 29 2c 20 2d 31 20 29  ( 1 1 )' ), -1 )
2f50: 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c   );..--------..L
2f60: 49 4e 45 53 54 52 49 4e 47 28 30 20 30 2c 20 31  INESTRING(0 0, 1
2f70: 20 30 2c 20 31 20 31 29 0d 0a 3c 2f 76 65 72 62   0, 1 1)..</verb
2f80: 61 74 69 6d 3e 0d 0a 50 61 73 73 69 6e 67 20 61  atim>..Passing a
2f90: 20 6e 65 67 61 74 69 76 65 20 69 6e 64 65 78 20   negative index 
2fa0: 69 73 20 61 20 73 75 70 70 6f 72 74 65 64 20 6f  is a supported o
2fb0: 70 74 69 6f 6e 2c 20 61 6e 64 20 73 69 6d 70 6c  ption, and simpl
2fc0: 79 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f  y corresponds to
2fd0: 20 74 68 65 20 64 65 66 61 75 6c 74 20 62 65 68   the default beh
2fe0: 61 76 69 6f 75 72 20 28 69 2e 65 2e 20 3c 69 3e  aviour (i.e. <i>
2ff0: 61 70 70 65 6e 64 69 6e 67 20 74 68 65 20 50 6f  appending the Po
3000: 69 6e 74 20 74 6f 20 74 68 65 20 65 6e 64 20 6f  int to the end o
3010: 66 20 74 68 65 20 4c 69 6e 65 73 74 72 69 6e 67  f the Linestring
3020: 3c 2f 69 3e 29 2e 3c 62 72 3e 3c 62 72 3e 0d 0a  </i>).<br><br>..
3030: 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e  <hr>..<verbatim>
3040: 0d 0a 53 45 4c 45 43 54 20 53 54 5f 41 73 54 65  ..SELECT ST_AsTe
3050: 78 74 28 20 53 54 5f 53 65 74 50 6f 69 6e 74 28  xt( ST_SetPoint(
3060: 20 0d 0a 20 20 53 54 5f 47 65 6f 6d 46 72 6f 6d   ..  ST_GeomFrom
3070: 54 65 78 74 28 20 27 4c 49 4e 45 53 54 52 49 4e  Text( 'LINESTRIN
3080: 47 28 20 30 20 30 2c 20 31 20 30 2c 20 31 20 31  G( 0 0, 1 0, 1 1
3090: 20 29 27 20 29 2c 20 0d 0a 20 20 31 2c 20 53 54   )' ), ..  1, ST
30a0: 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27  _GeomFromText( '
30b0: 50 4f 49 4e 54 28 20 32 20 31 20 29 27 20 29 20  POINT( 2 1 )' ) 
30c0: 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d  ) );..---------.
30d0: 0a 4c 49 4e 45 53 54 52 49 4e 47 28 30 20 30 2c  .LINESTRING(0 0,
30e0: 20 32 20 31 2c 20 31 20 31 29 0d 0a 3c 2f 76 65   2 1, 1 1)..</ve
30f0: 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e  rbatim>..The <b>
3100: 53 54 5f 53 65 74 50 6f 69 6e 74 28 29 3c 2f 62  ST_SetPoint()</b
3110: 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 63  > SQL function c
3120: 61 6e 20 72 65 70 6c 61 63 65 20 61 20 50 6f 69  an replace a Poi
3130: 6e 74 2f 56 65 72 74 65 78 20 66 72 6f 6d 20 77  nt/Vertex from w
3140: 69 74 68 69 6e 20 61 20 4c 69 6e 65 73 74 72 69  ithin a Linestri
3150: 6e 67 3b 20 74 68 65 20 66 69 72 73 74 20 61 72  ng; the first ar
3160: 67 75 6d 65 6e 74 20 69 73 20 61 6c 77 61 79 73  gument is always
3170: 20 65 78 70 65 63 74 65 64 20 74 6f 20 62 65 20   expected to be 
3180: 6f 66 20 74 68 65 20 4c 69 6e 65 73 74 72 69 6e  of the Linestrin
3190: 67 20 74 79 70 65 2c 20 74 68 65 20 73 65 63 6f  g type, the seco
31a0: 6e 64 20 69 73 20 61 6e 20 49 6e 74 65 67 65 72  nd is an Integer
31b0: 20 73 70 65 63 69 66 79 69 6e 67 20 74 68 65 20   specifying the 
31c0: 3c 75 3e 69 6e 64 65 78 3c 2f 75 3e 20 6f 66 20  <u>index</u> of 
31d0: 74 68 65 20 61 66 66 65 63 74 65 64 20 56 65 72  the affected Ver
31e0: 74 65 78 20 61 6e 64 20 74 68 65 20 74 68 69 72  tex and the thir
31f0: 64 20 6f 6e 65 20 6d 75 73 74 20 62 65 20 61 20  d one must be a 
3200: 50 6f 69 6e 74 2e 3c 62 72 3e 0d 0a 52 65 66 65  Point.<br>..Refe
3210: 72 65 6e 63 69 6e 67 20 61 20 6e 6f 74 20 65 78  rencing a not ex
3220: 69 73 74 69 6e 67 20 69 6e 64 65 78 20 69 73 20  isting index is 
3230: 61 6e 20 65 72 72 6f 72 2c 20 61 6e 64 20 77 69  an error, and wi
3240: 6c 6c 20 72 65 74 75 72 6e 20 4e 55 4c 4c 2e 3c  ll return NULL.<
3250: 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c  br><br>..<hr>..<
3260: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43  verbatim>..SELEC
3270: 54 20 53 54 5f 41 73 54 65 78 74 28 20 53 54 5f  T ST_AsText( ST_
3280: 52 65 6d 6f 76 65 50 6f 69 6e 74 28 20 0d 0a 20  RemovePoint( .. 
3290: 20 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74   ST_GeomFromText
32a0: 28 20 27 4c 49 4e 45 53 54 52 49 4e 47 28 20 30  ( 'LINESTRING( 0
32b0: 20 30 2c 20 31 20 30 2c 20 31 20 31 20 29 27 20   0, 1 0, 1 1 )' 
32c0: 29 2c 20 31 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d  ), 1 ) );..-----
32d0: 2d 2d 2d 2d 0d 0a 4c 49 4e 45 53 54 52 49 4e 47  ----..LINESTRING
32e0: 28 30 20 30 2c 20 31 20 31 29 0d 0a 3c 2f 76 65  (0 0, 1 1)..</ve
32f0: 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e  rbatim>..The <b>
3300: 53 54 5f 52 65 6d 6f 76 65 50 6f 69 6e 74 28 29  ST_RemovePoint()
3310: 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f  </b> SQL functio
3320: 6e 20 63 61 6e 20 72 65 6d 6f 76 65 20 61 20 50  n can remove a P
3330: 6f 69 6e 74 2f 56 65 72 74 65 78 20 66 72 6f 6d  oint/Vertex from
3340: 20 77 69 74 68 69 6e 20 61 20 4c 69 6e 65 73 74   within a Linest
3350: 72 69 6e 67 3b 20 74 68 65 20 66 69 72 73 74 20  ring; the first 
3360: 61 72 67 75 6d 65 6e 74 20 69 73 20 61 6c 77 61  argument is alwa
3370: 79 73 20 65 78 70 65 63 74 65 64 20 74 6f 20 62  ys expected to b
3380: 65 20 6f 66 20 74 68 65 20 4c 69 6e 65 73 74 72  e of the Linestr
3390: 69 6e 67 20 74 79 70 65 2c 20 74 68 65 20 73 65  ing type, the se
33a0: 63 6f 6e 64 20 69 73 20 61 6e 20 49 6e 74 65 67  cond is an Integ
33b0: 65 72 20 73 70 65 63 69 66 79 69 6e 67 20 74 68  er specifying th
33c0: 65 20 3c 75 3e 69 6e 64 65 78 3c 2f 75 3e 20 6f  e <u>index</u> o
33d0: 66 20 74 68 65 20 61 66 66 65 63 74 65 64 20 56  f the affected V
33e0: 65 72 74 65 78 2e 3c 62 72 3e 0d 0a 52 65 66 65  ertex.<br>..Refe
33f0: 72 65 6e 63 69 6e 67 20 61 20 6e 6f 74 20 65 78  rencing a not ex
3400: 69 73 74 69 6e 67 20 69 6e 64 65 78 20 69 73 20  isting index is 
3410: 61 6e 20 65 72 72 6f 72 2c 20 61 6e 64 20 77 69  an error, and wi
3420: 6c 6c 20 72 65 74 75 72 6e 20 4e 55 4c 4c 2e 3c  ll return NULL.<
3430: 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c  br><br>..<hr>..<
3440: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43  verbatim>..SELEC
3450: 54 20 53 54 5f 41 73 54 65 78 74 28 20 53 54 5f  T ST_AsText( ST_
3460: 50 6f 69 6e 74 28 31 30 2c 20 32 30 29 20 29 3b  Point(10, 20) );
3470: 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 50 4f  ..----------..PO
3480: 49 4e 54 28 31 30 20 31 30 29 0d 0a 3c 2f 76 65  INT(10 10)..</ve
3490: 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e  rbatim>..The <b>
34a0: 53 54 5f 50 6f 69 6e 74 28 29 3c 2f 62 3e 20 53  ST_Point()</b> S
34b0: 51 4c 20 66 75 6e 63 74 69 6f 6e 20 73 69 6d 70  QL function simp
34c0: 6c 79 20 69 73 20 79 65 74 20 61 6e 6f 74 68 65  ly is yet anothe
34d0: 72 20 3c 69 3e 61 6c 69 61 73 2d 6e 61 6d 65 3c  r <i>alias-name<
34e0: 2f 69 3e 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e  /i> correspondin
34f0: 67 20 74 6f 20 3c 62 3e 4d 61 6b 65 50 6f 69 6e  g to <b>MakePoin
3500: 74 28 29 3c 2f 62 3e 3b 20 74 68 69 73 20 66 75  t()</b>; this fu
3510: 72 74 68 65 72 20 61 6c 69 61 73 20 68 61 73 20  rther alias has 
3520: 62 65 65 6e 20 69 6e 74 72 6f 64 75 63 65 64 20  been introduced 
3530: 73 6f 20 74 6f 20 73 75 70 70 6f 72 74 20 61 20  so to support a 
3540: 73 74 72 69 63 74 20 50 6f 73 74 47 49 53 20 63  strict PostGIS c
3550: 6f 6e 66 6f 72 6d 61 6e 63 65 2e 3c 62 72 3e 0d  onformance.<br>.
3560: 0a 3c 75 3e 50 6c 65 61 73 65 20 6e 6f 74 65 3c  .<u>Please note<
3570: 2f 75 3e 3a 20 64 69 66 66 65 72 65 6e 74 6c 79  /u>: differently
3580: 20 66 72 6f 6d 20 4d 61 6b 65 50 6f 69 6e 74 28   from MakePoint(
3590: 29 2c 20 53 54 5f 50 6f 69 6e 74 28 29 20 64 6f  ), ST_Point() do
35a0: 6e 27 74 20 73 75 70 70 6f 72 74 73 20 74 68 65  n't supports the
35b0: 20 6f 70 74 69 6f 6e 61 6c 20 3c 62 3e 53 52 49   optional <b>SRI
35c0: 44 3c 2f 62 3e 20 61 72 67 75 6d 65 6e 74 2e 3c  D</b> argument.<
35d0: 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c  br><br>..<hr>..<
35e0: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43  verbatim>..SELEC
35f0: 54 20 53 54 5f 41 73 54 65 78 74 28 20 4d 61 6b  T ST_AsText( Mak
3600: 65 4c 69 6e 65 28 20 53 54 5f 47 65 6f 6d 46 72  eLine( ST_GeomFr
3610: 6f 6d 54 65 78 74 28 20 27 4d 55 4c 54 49 50 4f  omText( 'MULTIPO
3620: 49 4e 54 28 30 20 30 2c 20 31 20 30 2c 20 31 20  INT(0 0, 1 0, 1 
3630: 31 29 27 20 29 20 29 20 2c 20 31 20 29 3b 0d 0a  1)' ) ) , 1 );..
3640: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45  ----------..LINE
3650: 53 54 52 49 4e 47 28 30 20 30 2c 20 31 20 30 2c  STRING(0 0, 1 0,
3660: 20 31 20 31 29 0d 0a 0d 0a 53 45 4c 45 43 54 20   1 1)....SELECT 
3670: 53 54 5f 41 73 54 65 78 74 28 20 4d 61 6b 65 4c  ST_AsText( MakeL
3680: 69 6e 65 28 20 53 54 5f 47 65 6f 6d 46 72 6f 6d  ine( ST_GeomFrom
3690: 54 65 78 74 28 20 27 4d 55 4c 54 49 50 4f 49 4e  Text( 'MULTIPOIN
36a0: 54 28 30 20 30 2c 20 31 20 30 2c 20 31 20 31 29  T(0 0, 1 0, 1 1)
36b0: 27 20 29 20 29 20 2c 20 30 20 29 3b 0d 0a 2d 2d  ' ) ) , 0 );..--
36c0: 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45 53 54  --------..LINEST
36d0: 52 49 4e 47 28 31 20 31 2c 20 31 20 30 2c 20 30  RING(1 1, 1 0, 0
36e0: 20 30 29 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e   0)..</verbatim>
36f0: 0d 0a 4e 6f 74 20 72 65 61 6c 6c 79 20 61 20 62  ..Not really a b
3700: 72 61 6e 64 20 6e 65 77 20 53 51 4c 20 66 75 6e  rand new SQL fun
3710: 63 74 69 6f 6e 3b 20 6d 6f 72 65 20 73 69 6d 70  ction; more simp
3720: 6c 79 20 61 20 66 75 72 74 68 65 72 20 6f 76 65  ly a further ove
3730: 72 6c 6f 61 64 65 64 20 66 6c 61 76 6f 72 20 6f  rloaded flavor o
3740: 66 20 74 68 65 20 61 6c 72 65 61 64 79 20 65 78  f the already ex
3750: 69 73 74 69 6e 67 20 3c 62 3e 4d 61 6b 65 4c 69  isting <b>MakeLi
3760: 6e 65 28 29 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a 4e  ne()</b>.<br>..N
3770: 6f 77 20 74 68 65 20 69 6e 70 75 74 20 47 65 6f  ow the input Geo
3780: 6d 65 74 72 79 20 28 66 69 72 73 74 20 61 72 67  metry (first arg
3790: 75 6d 65 6e 74 29 20 63 6f 75 6c 64 20 62 65 20  ument) could be 
37a0: 6f 66 20 74 68 65 20 4d 55 4c 54 49 50 4f 49 4e  of the MULTIPOIN
37b0: 54 20 74 79 70 65 20 61 6e 64 20 74 68 65 20 73  T type and the s
37c0: 65 63 6f 6e 64 20 61 72 67 75 6d 65 6e 74 20 69  econd argument i
37d0: 66 20 6f 66 20 74 68 65 20 3c 62 3e 42 6f 6f 6c  f of the <b>Bool
37e0: 65 61 6e 3c 2f 62 3e 20 74 79 70 65 3b 20 69 66  ean</b> type; if
37f0: 20 74 68 65 20 73 65 63 6f 6e 64 20 61 72 67 75   the second argu
3800: 6d 65 6e 74 20 63 6f 72 72 65 73 70 6f 6e 64 73  ment corresponds
3810: 20 74 6f 20 3c 62 3e 54 52 55 45 3c 2f 62 3e 20   to <b>TRUE</b> 
3820: 74 68 65 20 72 65 74 75 72 6e 65 64 20 4c 49 4e  the returned LIN
3830: 45 53 54 52 49 4e 47 20 77 69 6c 6c 20 62 65 20  ESTRING will be 
3840: 6f 72 69 65 6e 74 65 64 20 61 63 63 6f 72 64 69  oriented accordi
3850: 6e 67 6c 79 20 74 6f 20 74 68 65 20 50 6f 69 6e  ngly to the Poin
3860: 74 2d 73 65 71 75 65 6e 63 65 20 61 73 20 73 70  t-sequence as sp
3870: 65 63 69 66 69 65 64 20 62 79 20 74 68 65 20 4d  ecified by the M
3880: 75 6c 74 69 50 6f 69 6e 74 2c 20 6f 74 68 65 72  ultiPoint, other
3890: 77 69 73 65 20 3c 75 3e 72 65 76 65 72 73 65 20  wise <u>reverse 
38a0: 6f 72 64 65 72 3c 2f 75 3e 20 77 69 6c 6c 20 62  order</u> will b
38b0: 65 20 61 73 73 75 6d 65 64 2c 20 74 68 75 73 20  e assumed, thus 
38c0: 72 65 74 75 72 6e 69 6e 67 20 61 20 4c 69 6e 65  returning a Line
38d0: 73 74 72 69 6e 67 20 6f 66 20 6f 70 70 6f 73 69  string of opposi
38e0: 74 65 20 6f 72 69 65 6e 74 61 74 69 6f 6e 2e 3c  te orientation.<
38f0: 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c  br><br>..<hr>..<
3900: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43  verbatim>..SELEC
3910: 54 20 53 54 5f 41 72 65 61 28 20 53 54 5f 47 65  T ST_Area( ST_Ge
3920: 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27 50 4f 4c  omFromText( 'POL
3930: 59 47 4f 4e 28 28 32 30 20 32 30 2c 20 32 31 20  YGON((20 20, 21 
3940: 32 30 2c 20 32 31 20 32 31 2c 20 32 30 20 32 31  20, 21 21, 20 21
3950: 2c 20 32 30 20 32 30 29 29 27 2c 20 34 33 32 36  , 20 20))', 4326
3960: 20 29 2c 20 31 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d   ), 1 );..------
3970: 2d 2d 2d 2d 0d 0a 31 31 35 34 38 35 35 35 39 32  ----..1154855592
3980: 36 2e 36 34 37 37 33 36 0d 0a 0d 0a 0d 0a 53 45  6.647736......SE
3990: 4c 45 43 54 20 53 54 5f 41 72 65 61 28 20 53 54  LECT ST_Area( ST
39a0: 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27  _GeomFromText( '
39b0: 50 4f 4c 59 47 4f 4e 28 28 32 30 20 32 30 2c 20  POLYGON((20 20, 
39c0: 32 31 20 32 30 2c 20 32 31 20 32 31 2c 20 32 30  21 20, 21 21, 20
39d0: 20 32 31 2c 20 32 30 20 32 30 29 29 27 2c 20 34   21, 20 20))', 4
39e0: 33 32 36 20 29 2c 20 30 20 29 3b 0d 0a 2d 2d 2d  326 ), 0 );..---
39f0: 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 31 35 38 31 33 37  -------..1158137
3a00: 37 36 32 33 2e 31 31 34 31 38 39 0d 0a 3c 2f 76  7623.114189..</v
3a10: 65 72 62 61 74 69 6d 3e 0d 0a 4f 6e 63 65 20 61  erbatim>..Once a
3a20: 67 61 69 6e 2c 20 73 69 6d 70 6c 79 20 61 20 66  gain, simply a f
3a30: 75 72 74 68 65 72 20 65 78 74 65 6e 73 69 6f 6e  urther extension
3a40: 20 6f 66 20 74 68 65 20 61 6c 72 65 61 64 79 20   of the already 
3a50: 65 78 69 73 74 69 6e 67 20 3c 62 3e 53 54 5f 41  existing <b>ST_A
3a60: 72 65 61 28 29 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a  rea()</b>.<br>..
3a70: 4e 6f 77 20 69 66 20 74 68 65 20 69 6e 70 75 74  Now if the input
3a80: 20 47 65 6f 6d 65 74 72 79 20 61 64 6f 70 74 73   Geometry adopts
3a90: 20 3c 75 3e 67 65 6f 67 72 61 70 68 69 63 20 63   <u>geographic c
3aa0: 6f 6f 72 64 69 6e 61 74 65 73 3c 2f 75 3e 20 28  oordinates</u> (
3ab0: 69 2e 65 2e 20 62 61 73 65 64 20 6f 6e 20 3c 75  i.e. based on <u
3ac0: 3e 6c 6f 6e 67 69 74 75 64 65 3c 2f 75 3e 20 61  >longitude</u> a
3ad0: 6e 64 20 3c 75 3e 6c 61 74 69 74 75 64 65 3c 2f  nd <u>latitude</
3ae0: 75 3e 20 61 6e 67 6c 65 73 29 2c 20 61 20 73 65  u> angles), a se
3af0: 63 6f 6e 64 20 61 72 67 75 6d 65 6e 74 20 6f 66  cond argument of
3b00: 20 74 68 65 20 3c 62 3e 42 6f 6f 6c 65 61 6e 3c   the <b>Boolean<
3b10: 2f 62 3e 20 64 61 74 61 2d 74 79 70 65 20 63 6f  /b> data-type co
3b20: 75 6c 64 20 62 65 20 6f 70 74 69 6f 6e 61 6c 6c  uld be optionall
3b30: 79 20 73 70 65 63 69 66 69 65 64 2e 3c 62 72 3e  y specified.<br>
3b40: 0d 0a 49 6e 20 74 68 69 73 20 63 61 73 65 20 74  ..In this case t
3b50: 68 65 20 72 65 74 75 72 6e 65 64 20 41 72 65 61  he returned Area
3b60: 20 77 69 6c 6c 20 62 65 20 6d 65 61 73 75 72 65   will be measure
3b70: 64 20 69 6e 20 3c 62 3e 6d 65 74 65 72 73 3c 2f  d in <b>meters</
3b80: 62 3e 2e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 69  b>...<ul>..<li>i
3b90: 66 20 74 68 65 20 73 65 63 6f 6e 64 20 61 72 67  f the second arg
3ba0: 20 69 73 20 3c 62 3e 54 52 55 45 3c 2f 62 3e 20   is <b>TRUE</b> 
3bb0: 74 68 65 20 41 72 65 61 20 77 69 6c 6c 20 62 65  the Area will be
3bc0: 20 6d 65 61 73 75 72 65 64 20 3c 75 3e 6f 6e 20   measured <u>on 
3bd0: 74 68 65 20 45 6c 6c 69 70 73 6f 69 64 3c 2f 75  the Ellipsoid</u
3be0: 3e 20 28 6d 6f 72 65 20 61 63 63 75 72 61 74 65  > (more accurate
3bf0: 2c 20 62 75 74 20 73 6c 6f 77 65 72 29 2e 3c 2f  , but slower).</
3c00: 6c 69 3e 0d 0a 3c 6c 69 3e 69 66 20 74 68 65 20  li>..<li>if the 
3c10: 73 65 63 6f 6e 64 20 61 72 67 20 69 73 20 3c 62  second arg is <b
3c20: 3e 46 41 4c 53 45 3c 2f 62 3e 20 74 68 65 20 41  >FALSE</b> the A
3c30: 72 65 61 20 77 69 6c 6c 20 62 65 20 6d 65 61 73  rea will be meas
3c40: 75 72 65 20 3c 75 3e 6f 6e 20 74 68 65 20 53 70  ure <u>on the Sp
3c50: 68 65 72 65 3c 2f 75 3e 20 28 66 61 73 74 65 72  here</u> (faster
3c60: 2c 20 62 75 74 20 6c 65 73 73 20 61 63 63 75 72  , but less accur
3c70: 61 74 65 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e  ate).</li>..<li>
3c80: 4e 55 4c 4c 20 77 69 6c 6c 20 62 65 20 72 65 74  NULL will be ret
3c90: 75 72 6e 65 64 20 6f 6e 20 69 6e 76 61 6c 69 64  urned on invalid
3ca0: 20 61 72 67 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69   args.</li>..<li
3cb0: 3e 3c 75 3e 50 6c 65 61 73 65 20 6e 6f 74 65 3c  ><u>Please note<
3cc0: 2f 75 3e 3a 20 74 68 69 73 20 73 70 65 63 69 66  /u>: this specif
3cd0: 69 63 20 66 6c 61 76 6f 72 20 6f 66 20 3c 62 3e  ic flavor of <b>
3ce0: 53 54 5f 41 72 65 61 28 29 3c 2f 62 3e 20 6e 65  ST_Area()</b> ne
3cf0: 63 65 73 73 61 72 69 6c 79 20 72 65 71 75 69 72  cessarily requir
3d00: 65 73 20 74 68 65 20 3c 62 3e 4c 57 47 45 4f 4d  es the <b>LWGEOM
3d10: 3c 2f 62 3e 20 73 75 70 70 6f 72 74 20 74 6f 20  </b> support to 
3d20: 62 65 20 61 63 74 69 76 61 74 65 64 20 61 74 20  be activated at 
3d30: 62 75 69 6c 64 20 74 69 6d 65 2e 3c 2f 6c 69 3e  build time.</li>
3d40: 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d 0a 3c 68 72  ..</ul><br>..<hr
3d50: 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53  >..<verbatim>..S
3d60: 45 4c 45 43 54 20 53 54 5f 41 73 54 65 78 74 28  ELECT ST_AsText(
3d70: 20 53 54 5f 50 72 6f 6a 65 63 74 28 20 4d 61 6b   ST_Project( Mak
3d80: 65 50 6f 69 6e 74 28 20 31 31 2e 35 32 2c 20 34  ePoint( 11.52, 4
3d90: 32 2e 33 38 2c 20 34 33 32 36 20 29 2c 20 35 30  2.38, 4326 ), 50
3da0: 30 30 30 2c 20 52 61 64 69 61 6e 73 28 20 34 35  000, Radians( 45
3db0: 20 29 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d   ) ) );..-------
3dc0: 2d 2d 2d 0d 0a 50 4f 49 4e 54 28 31 31 2e 39 35  ---..POINT(11.95
3dd0: 31 34 37 39 20 34 32 2e 36 39 37 34 36 37 29 0d  1479 42.697467).
3de0: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68  .</verbatim>..Th
3df0: 65 20 3c 62 3e 53 54 5f 50 72 6f 6a 65 63 74 28  e <b>ST_Project(
3e00: 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69  )</b> SQL functi
3e10: 6f 6e 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 74  on will return t
3e20: 68 65 20 64 65 73 74 69 6e 61 74 69 6f 6e 20 50  he destination P
3e30: 6f 69 6e 74 20 3c 75 3e 6f 6e 20 74 68 65 20 65  oint <u>on the e
3e40: 6c 6c 69 70 73 6f 69 64 3c 2f 75 3e 20 63 6f 72  llipsoid</u> cor
3e50: 72 65 73 70 6f 6e 64 69 6e 67 20 74 6f 20 61 20  responding to a 
3e60: 3c 62 3e 73 74 61 72 74 5f 70 6f 69 6e 74 3c 2f  <b>start_point</
3e70: 62 3e 2c 20 61 20 3c 62 3e 64 69 73 74 61 6e 63  b>, a <b>distanc
3e80: 65 3c 2f 62 3e 20 61 6e 64 20 61 20 3c 62 3e 62  e</b> and a <b>b
3e90: 65 61 72 69 6e 67 3c 2f 62 3e 20 28 61 6b 61 20  earing</b> (aka 
3ea0: 3c 75 3e 61 7a 69 6d 75 74 68 3c 2f 75 3e 20 61  <u>azimuth</u> a
3eb0: 6b 61 20 3c 75 3e 64 69 72 65 63 74 69 6f 6e 3c  ka <u>direction<
3ec0: 2f 75 3e 20 61 6b 61 20 3c 75 3e 68 65 61 64 69  /u> aka <u>headi
3ed0: 6e 67 3c 2f 75 3e 29 2e 0d 0a 3c 75 6c 3e 0d 0a  ng</u>)...<ul>..
3ee0: 3c 6c 69 3e 74 68 65 20 3c 62 3e 73 74 61 72 74  <li>the <b>start
3ef0: 5f 70 6f 69 6e 74 3c 2f 62 3e 20 69 73 20 65 78  _point</b> is ex
3f00: 70 65 63 74 65 64 20 74 6f 20 61 64 6f 70 74 20  pected to adopt 
3f10: 3c 75 3e 67 65 6f 67 72 61 70 68 69 63 20 63 6f  <u>geographic co
3f20: 6f 72 64 69 6e 61 74 65 73 3c 2f 75 3e 20 28 69  ordinates</u> (i
3f30: 2e 65 2e 20 62 61 73 65 64 20 6f 6e 20 3c 75 3e  .e. based on <u>
3f40: 6c 6f 6e 67 69 74 75 64 65 3c 2f 75 3e 20 61 6e  longitude</u> an
3f50: 64 20 3c 75 3e 6c 61 74 69 74 75 64 65 3c 2f 75  d <u>latitude</u
3f60: 3e 20 61 6e 67 6c 65 73 29 2e 3c 2f 6c 69 3e 0d  > angles).</li>.
3f70: 0a 3c 6c 69 3e 74 68 65 20 3c 62 3e 64 69 73 74  .<li>the <b>dist
3f80: 61 6e 63 65 3c 2f 62 3e 20 69 73 20 61 6c 77 61  ance</b> is alwa
3f90: 79 73 20 65 78 70 65 63 74 65 64 20 74 6f 20 62  ys expected to b
3fa0: 65 20 65 78 70 72 65 73 73 65 64 20 69 6e 20 3c  e expressed in <
3fb0: 62 3e 6d 65 74 65 72 73 3c 2f 62 3e 2e 3c 2f 6c  b>meters</b>.</l
3fc0: 69 3e 0d 0a 3c 6c 69 3e 74 68 65 20 3c 62 3e 61  i>..<li>the <b>a
3fd0: 7a 69 6d 75 74 68 3c 2f 62 3e 20 61 6e 67 6c 65  zimuth</b> angle
3fe0: 20 69 73 20 65 78 70 65 63 74 65 64 20 74 6f 20   is expected to 
3ff0: 62 65 20 65 78 70 72 65 73 73 65 64 20 69 6e 20  be expressed in 
4000: 3c 62 3e 72 61 64 69 61 6e 73 3c 2f 62 3e 3a 0d  <b>radians</b>:.
4010: 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 4e 6f 72 74 68  .<ul>..<li>North
4020: 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20   corresponds to 
4030: 30 20 64 65 67 72 65 65 73 20 28 30 20 72 61 64  0 degrees (0 rad
4040: 69 61 6e 73 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  ians).</li>..<li
4050: 3e 45 61 73 74 20 63 6f 72 72 65 73 70 6f 6e 64  >East correspond
4060: 73 20 74 6f 20 39 30 20 64 65 67 72 65 65 73 20  s to 90 degrees 
4070: 28 50 49 2f 32 20 72 61 64 69 61 6e 73 29 2e 3c  (PI/2 radians).<
4080: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 53 6f 75 74 68 20  /li>..<li>South 
4090: 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 31  corresponds to 1
40a0: 38 30 20 64 65 67 72 65 65 73 20 28 50 49 20 72  80 degrees (PI r
40b0: 61 64 69 61 6e 73 29 2e 3c 2f 6c 69 3e 0d 0a 3c  adians).</li>..<
40c0: 6c 69 3e 57 65 73 74 20 63 6f 72 72 65 73 70 6f  li>West correspo
40d0: 6e 64 73 20 74 6f 20 32 37 30 20 64 65 67 72 65  nds to 270 degre
40e0: 65 73 20 28 33 50 49 2f 32 20 72 61 64 69 61 6e  es (3PI/2 radian
40f0: 73 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 69 2e  s).</li>..<li>i.
4100: 65 2e 20 69 74 20 68 61 73 20 74 68 65 20 73 61  e. it has the sa
4110: 6d 65 20 69 64 65 6e 74 69 63 61 6c 20 6d 65 61  me identical mea
4120: 6e 69 6e 67 20 61 73 20 69 6e 20 3c 62 3e 53 54  ning as in <b>ST
4130: 5f 41 7a 69 6d 75 74 68 28 29 3c 2f 62 3e 2e 3c  _Azimuth()</b>.<
4140: 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 2f 6c 69 3e  /li>..</ul></li>
4150: 0d 0a 3c 6c 69 3e 74 68 69 73 20 66 75 6e 63 74  ..<li>this funct
4160: 69 6f 6e 20 65 78 61 63 74 6c 79 20 63 6f 72 72  ion exactly corr
4170: 65 73 70 6f 6e 64 73 20 74 6f 20 74 68 65 20 6f  esponds to the o
4180: 6e 65 20 73 75 70 70 6f 72 74 65 64 20 62 79 20  ne supported by 
4190: 3c 62 3e 50 6f 73 74 47 49 53 3c 2f 62 3e 2e 3c  <b>PostGIS</b>.<
41a0: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 75 3e 50 6c 65  /li>..<li><u>Ple
41b0: 61 73 65 20 6e 6f 74 65 3c 2f 75 3e 3a 20 3c 62  ase note</u>: <b
41c0: 3e 53 54 5f 50 72 6f 6a 65 63 74 28 29 3c 2f 62  >ST_Project()</b
41d0: 3e 20 6e 65 63 65 73 73 61 72 69 6c 79 20 72 65  > necessarily re
41e0: 71 75 69 72 65 73 20 74 68 65 20 3c 62 3e 4c 57  quires the <b>LW
41f0: 47 45 4f 4d 3c 2f 62 3e 20 73 75 70 70 6f 72 74  GEOM</b> support
4200: 20 74 6f 20 62 65 20 61 63 74 69 76 61 74 65 64   to be activated
4210: 20 61 74 20 62 75 69 6c 64 20 74 69 6d 65 2e 3c   at build time.<
4220: 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d  /li>..</ul><br>.
4230: 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 3c 61 20 6e 61  .<hr>..<h3><a na
4240: 6d 65 3d 22 75 6e 73 61 66 65 22 3e 55 6e 73 61  me="unsafe">Unsa
4250: 66 65 3c 2f 61 3e 20 28 62 75 74 20 75 73 65 66  fe</a> (but usef
4260: 75 6c 29 20 49 6d 70 6f 72 74 2f 45 78 70 6f 72  ul) Import/Expor
4270: 74 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 73 3c  t SQL functions<
4280: 2f 68 33 3e 0d 0a 41 6c 6c 20 74 68 65 20 66 6f  /h3>..All the fo
4290: 6c 6c 6f 77 69 6e 67 20 53 51 4c 20 66 75 6e 63  llowing SQL func
42a0: 74 69 6f 6e 73 20 63 6f 75 6c 64 20 62 65 20 72  tions could be r
42b0: 65 61 6c 6c 79 20 75 73 65 66 75 6c 20 69 6e 20  eally useful in 
42c0: 6f 72 64 65 72 20 74 6f 20 73 75 70 70 6f 72 74  order to support
42d0: 20 49 6d 70 6f 72 74 2f 45 78 70 6f 72 74 20 6f   Import/Export o
42e0: 70 65 72 61 74 69 6f 6e 73 2e 3c 62 72 3e 0d 0a  perations.<br>..
42f0: 41 6e 79 77 61 79 20 79 6f 75 20 73 68 6f 75 6c  Anyway you shoul
4300: 64 20 62 65 20 3c 75 3e 77 65 6c 6c 20 61 77 61  d be <u>well awa
4310: 72 65 3c 2f 75 3e 20 74 68 61 74 20 61 6c 6c 20  re</u> that all 
4320: 74 68 65 6d 20 63 6f 75 6c 64 20 62 65 20 70 6f  them could be po
4330: 74 65 6e 74 69 61 6c 6c 79 20 3c 75 3e 75 6e 73  tentially <u>uns
4340: 61 66 65 3c 2f 75 3e 20 61 6e 64 20 63 6f 75 6c  afe</u> and coul
4350: 64 20 62 65 20 70 6f 74 65 6e 74 69 61 6c 6c 79  d be potentially
4360: 20 75 73 65 64 20 62 79 20 73 6f 6d 65 20 3c 75   used by some <u
4370: 3e 6d 61 6c 69 63 69 6f 75 73 20 68 61 63 6b 65  >malicious hacke
4380: 72 3c 2f 75 3e 20 69 6e 20 6f 72 64 65 72 20 74  r</u> in order t
4390: 6f 20 63 72 65 61 74 65 20 61 6e 64 20 65 78 70  o create and exp
43a0: 6c 6f 69 74 20 73 6f 6d 65 20 3c 75 3e 73 65 63  loit some <u>sec
43b0: 75 72 69 74 79 20 62 72 65 61 63 68 3c 2f 75 3e  urity breach</u>
43c0: 2e 3c 62 72 3e 0d 0a 54 68 65 20 63 61 75 73 65  .<br>..The cause
43d0: 20 69 73 20 76 65 72 79 20 65 61 73 79 20 74 6f   is very easy to
43e0: 20 62 65 20 75 6e 64 65 72 73 74 6f 6f 64 3a 20   be understood: 
43f0: 74 68 65 73 65 20 66 75 6e 63 74 69 6f 6e 73 20  these functions 
4400: 61 6c 6c 6f 77 20 74 6f 20 74 72 61 6e 73 66 65  allow to transfe
4410: 72 20 61 72 62 69 74 72 61 72 79 20 70 61 79 6c  r arbitrary payl
4420: 6f 61 64 73 20 66 72 6f 6d 20 2f 20 74 6f 20 74  oads from / to t
4430: 68 65 20 44 61 74 61 62 61 73 65 20 61 6e 64 20  he Database and 
4440: 74 68 65 20 6c 6f 63 61 6c 20 46 69 6c 65 2d 53  the local File-S
4450: 79 73 74 65 6d 2e 0d 0a 41 20 6d 61 6c 69 63 69  ystem...A malici
4460: 6f 75 73 20 61 74 74 61 63 6b 20 63 6f 75 6c 64  ous attack could
4470: 20 62 65 20 74 68 75 73 20 69 6d 70 6c 65 6d 65   be thus impleme
4480: 6e 74 65 64 20 65 2e 67 2e 20 62 79 20 65 78 65  nted e.g. by exe
4490: 63 75 74 69 6e 67 20 73 6f 6d 65 20 53 51 4c 20  cuting some SQL 
44a0: 73 63 72 69 70 74 20 6f 72 20 62 79 20 64 65 66  script or by def
44b0: 69 6e 69 6e 67 20 61 20 70 75 72 70 6f 73 65 6c  ining a purposel
44c0: 79 20 66 6f 72 67 65 64 20 54 72 69 67 67 65 72  y forged Trigger
44d0: 2c 20 61 6e 64 20 74 68 65 20 65 6e 64 20 75 73  , and the end us
44e0: 65 72 73 20 77 6f 75 6c 64 20 62 65 20 61 62 73  ers would be abs
44f0: 6f 6c 75 74 65 6c 79 20 75 6e 61 77 61 72 65 20  olutely unaware 
4500: 6f 66 20 77 68 61 74 20 69 73 20 72 65 61 6c 6c  of what is reall
4510: 79 20 68 61 70 70 65 6e 69 6e 67 2e 0d 0a 53 6f  y happening...So
4520: 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 65 66 66   in order to eff
4530: 65 63 74 69 76 65 6c 79 20 73 68 69 65 6c 64 20  ectively shield 
4540: 75 73 65 72 73 20 61 67 61 69 6e 73 74 20 74 68  users against th
4550: 65 73 65 20 70 6f 74 65 6e 74 69 61 6c 6c 79 20  ese potentially 
4560: 64 61 6e 67 65 72 6f 75 73 20 73 65 63 75 72 69  dangerous securi
4570: 74 79 20 70 69 74 66 61 6c 6c 73 20 61 6c 6c 20  ty pitfalls all 
4580: 74 68 65 73 65 20 53 51 4c 20 66 75 6e 63 74 69  these SQL functi
4590: 6f 6e 73 20 61 72 65 20 61 6c 77 61 79 73 20 3c  ons are always <
45a0: 75 3e 64 69 73 61 62 6c 65 64 20 62 79 20 64 65  u>disabled by de
45b0: 66 61 75 6c 74 3c 2f 75 3e 2e 0d 0a 3c 76 65 72  fault</u>...<ver
45c0: 62 61 74 69 6d 3e 0d 0a 65 78 70 6f 72 74 20 22  batim>..export "
45d0: 53 50 41 54 49 41 4c 49 54 45 5f 53 45 43 55 52  SPATIALITE_SECUR
45e0: 49 54 59 3d 72 65 6c 61 78 65 64 22 0d 0a 3c 2f  ITY=relaxed"..</
45f0: 76 65 72 62 61 74 69 6d 3e 0d 0a 49 6e 20 6f 72  verbatim>..In or
4600: 64 65 72 20 74 6f 20 72 65 61 6c 6c 79 20 65 6e  der to really en
4610: 61 62 6c 65 20 74 68 65 73 65 20 66 75 6e 63 74  able these funct
4620: 69 6f 6e 73 20 74 68 65 20 75 73 65 72 20 69 73  ions the user is
4630: 20 72 65 71 75 69 72 65 64 20 74 6f 20 74 61 6b   required to tak
4640: 65 20 61 6e 20 65 78 70 6c 69 63 69 74 20 61 63  e an explicit ac
4650: 74 69 6f 6e 3b 20 69 2e 65 2e 20 74 68 65 20 3c  tion; i.e. the <
4660: 75 3e 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 76 61  u>environment va
4670: 72 69 61 62 6c 65 3c 2f 75 3e 20 3c 62 3e 53 50  riable</u> <b>SP
4680: 41 54 49 41 4c 49 54 45 5f 53 45 43 55 52 49 54  ATIALITE_SECURIT
4690: 59 3d 72 65 6c 61 78 65 64 3c 2f 62 3e 20 68 61  Y=relaxed</b> ha
46a0: 73 20 74 6f 20 62 65 20 64 65 66 69 6e 65 64 2e  s to be defined.
46b0: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45  ..<verbatim>..SE
46c0: 4c 45 43 54 20 43 6f 75 6e 74 55 6e 73 61 66 65  LECT CountUnsafe
46d0: 54 72 69 67 67 65 72 73 28 29 3b 0d 0a 2d 2d 2d  Triggers();..---
46e0: 2d 2d 2d 2d 2d 2d 0d 0a 30 0d 0a 3c 2f 76 65 72  ------..0..</ver
46f0: 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 43  batim>..The <b>C
4700: 6f 75 6e 74 55 6e 73 61 66 65 54 72 69 67 67 65  ountUnsafeTrigge
4710: 72 73 28 29 3c 2f 62 3e 20 61 63 74 75 61 6c 6c  rs()</b> actuall
4720: 79 20 63 68 65 63 6b 73 20 69 66 20 74 68 65 20  y checks if the 
4730: 63 6f 6e 6e 65 63 74 65 64 20 44 61 74 61 62 61  connected Databa
4740: 73 65 20 64 6f 65 73 20 63 6f 6e 74 61 69 6e 73  se does contains
4750: 20 61 6e 79 20 73 75 73 70 65 63 74 20 54 72 69   any suspect Tri
4760: 67 67 65 72 3b 20 63 68 65 63 6b 69 6e 67 20 74  gger; checking t
4770: 68 69 73 20 76 65 72 73 69 6f 6e 20 62 65 66 6f  his version befo
4780: 72 65 20 65 6e 61 62 6c 69 6e 67 20 74 68 65 20  re enabling the 
4790: 75 6e 73 61 66 65 20 53 51 4c 20 46 75 6e 63 74  unsafe SQL Funct
47a0: 69 6f 6e 73 20 69 73 20 61 6c 77 61 79 73 20 68  ions is always h
47b0: 69 67 68 6c 79 20 72 65 63 6f 6d 6d 65 6e 64 65  ighly recommende
47c0: 64 2e 3c 62 72 3e 0d 0a 41 20 72 65 73 75 6c 74  d.<br>..A result
47d0: 20 64 69 66 66 65 72 65 6e 74 20 66 72 6f 6d 20   different from 
47e0: 5a 45 52 4f 20 69 6d 70 6c 69 65 73 20 74 68 61  ZERO implies tha
47f0: 74 20 73 6f 6d 65 20 6d 61 6c 69 63 69 6f 75 73  t some malicious
4800: 20 54 72 69 67 67 65 72 20 68 61 73 20 62 65 65   Trigger has bee
4810: 6e 20 69 64 65 6e 74 69 66 69 65 64 3b 20 69 6e  n identified; in
4820: 20 74 68 69 73 20 63 61 73 65 20 79 6f 75 20 63   this case you c
4830: 61 6e 20 70 65 72 66 6f 72 6d 20 61 20 64 65 65  an perform a dee
4840: 70 65 73 74 20 69 6e 73 70 65 63 74 69 6f 6e 20  pest inspection 
4850: 62 79 20 65 78 65 63 75 74 69 6e 67 20 74 68 65  by executing the
4860: 20 66 6f 6c 6c 6f 77 69 6e 67 20 53 51 4c 20 71   following SQL q
4870: 75 65 72 79 3a 0d 0a 3c 76 65 72 62 61 74 69 6d  uery:..<verbatim
4880: 3e 0d 0a 53 45 4c 45 43 54 20 74 79 70 65 2c 20  >..SELECT type, 
4890: 6e 61 6d 65 2c 20 74 62 6c 5f 6e 61 6d 65 2c 20  name, tbl_name, 
48a0: 73 71 6c 20 0d 0a 46 52 4f 4d 20 73 71 6c 69 74  sql ..FROM sqlit
48b0: 65 5f 6d 61 73 74 65 72 20 0d 0a 57 48 45 52 45  e_master ..WHERE
48c0: 20 74 79 70 65 20 49 4e 20 28 27 74 72 69 67 67   type IN ('trigg
48d0: 65 72 27 2c 20 27 76 69 65 77 27 29 20 41 4e 44  er', 'view') AND
48e0: 20 28 73 71 6c 20 4c 49 4b 45 20 27 25 42 6c 6f   (sql LIKE '%Blo
48f0: 62 46 72 6f 6d 46 69 6c 65 25 27 20 0d 0a 20 20  bFromFile%' ..  
4900: 20 4f 52 20 73 71 6c 20 4c 49 4b 45 20 27 25 42   OR sql LIKE '%B
4910: 6c 6f 62 54 6f 46 69 6c 65 25 27 20 4f 52 20 73  lobToFile%' OR s
4920: 71 6c 20 4c 49 4b 45 20 27 25 58 42 5f 4c 6f 61  ql LIKE '%XB_Loa
4930: 64 58 4d 4c 25 27 20 0d 0a 20 20 20 4f 52 20 73  dXML%' ..   OR s
4940: 71 6c 20 4c 49 4b 45 20 27 25 58 42 5f 53 74 6f  ql LIKE '%XB_Sto
4950: 72 65 58 4d 4c 25 27 29 3b 0d 0a 3c 2f 76 65 72  reXML%');..</ver
4960: 62 61 74 69 6d 3e 0d 0a 74 68 69 73 20 77 69 6c  batim>..this wil
4970: 6c 20 67 69 76 65 20 61 20 66 75 6c 6c 20 72 65  l give a full re
4980: 70 6f 72 74 20 66 6f 72 20 61 6e 79 20 6d 61 6c  port for any mal
4990: 69 63 69 6f 75 73 20 54 72 69 67 67 65 72 20 65  icious Trigger e
49a0: 76 65 6e 74 75 61 6c 6c 79 20 66 6f 75 6e 64 2e  ventually found.
49b0: 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a  <br><br>..<hr>..
49c0: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45  <verbatim>..SELE
49d0: 43 54 20 42 6c 6f 62 46 72 6f 6d 46 69 6c 65 28  CT BlobFromFile(
49e0: 20 27 43 3a 2f 6d 79 70 69 63 74 75 72 65 73 2f   'C:/mypictures/
49f0: 73 75 6e 73 65 74 2e 6a 70 67 27 20 29 3b 0d 0a  sunset.jpg' );..
4a00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 42 4c 4f 42 2d  ---------..BLOB-
4a10: 76 61 6c 75 65 0d 0a 3c 2f 76 65 72 62 61 74 69  value..</verbati
4a20: 6d 3e 0d 0a 54 68 65 20 3c 62 3e 42 6c 6f 62 46  m>..The <b>BlobF
4a30: 72 6f 6d 46 69 6c 65 28 29 3c 2f 62 3e 20 53 51  romFile()</b> SQ
4a40: 4c 20 66 75 6e 63 74 69 6f 6e 20 61 6c 6c 6f 77  L function allow
4a50: 73 20 74 6f 20 69 6d 70 6f 72 74 20 61 20 77 68  s to import a wh
4a60: 6f 6c 65 20 66 69 6c 65 20 69 6e 20 61 20 73 69  ole file in a si
4a70: 6e 67 6c 65 20 73 74 65 70 3b 20 74 68 65 20 66  ngle step; the f
4a80: 75 6c 6c 20 66 69 6c 65 20 70 61 79 6c 6f 61 64  ull file payload
4a90: 20 77 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65   will be returne
4aa0: 64 20 61 73 20 61 20 42 4c 4f 42 20 76 61 6c 75  d as a BLOB valu
4ab0: 65 2e 3c 62 72 3e 0d 0a 49 66 20 74 68 65 20 61  e.<br>..If the a
4ac0: 72 67 75 6d 65 6e 74 20 28 3c 62 3e 66 69 6c 65  rgument (<b>file
4ad0: 2d 70 61 74 68 3c 2f 62 3e 29 20 64 6f 65 73 6e  -path</b>) doesn
4ae0: 27 74 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74  't corresponds t
4af0: 6f 20 61 20 76 61 6c 69 64 20 66 69 6c 65 20 6f  o a valid file o
4b00: 72 20 69 66 20 74 68 65 20 65 78 74 65 72 6e 61  r if the externa
4b10: 6c 20 66 69 6c 65 20 63 61 6e 6e 6f 74 20 62 65  l file cannot be
4b20: 20 61 63 63 65 73 73 65 64 20 66 6f 72 20 61 6e   accessed for an
4b30: 79 20 72 65 61 73 6f 6e 20 4e 55 4c 4c 20 77 69  y reason NULL wi
4b40: 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 2e 3c  ll be returned.<
4b50: 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c  br><br>..<hr>..<
4b60: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43  verbatim>..SELEC
4b70: 54 20 42 6c 6f 62 54 6f 46 69 6c 65 28 20 73 6f  T BlobToFile( so
4b80: 6d 65 42 6c 6f 62 20 2c 20 27 43 3a 2f 6d 79 70  meBlob , 'C:/myp
4b90: 69 63 74 75 72 65 73 2f 73 75 6e 73 65 74 2e 6a  ictures/sunset.j
4ba0: 70 67 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d  pg' );..--------
4bb0: 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69 6d  -..1..</verbatim
4bc0: 3e 0d 0a 54 68 65 20 3c 62 3e 42 6c 6f 62 54 6f  >..The <b>BlobTo
4bd0: 46 69 6c 65 28 29 3c 2f 62 3e 20 53 51 4c 20 66  File()</b> SQL f
4be0: 75 6e 63 74 69 6f 6e 20 70 65 72 66 6f 72 6d 73  unction performs
4bf0: 20 74 68 65 20 6f 70 70 6f 73 69 74 65 20 74 61   the opposite ta
4c00: 73 6b 2c 20 69 2e 65 2e 20 69 74 20 65 78 70 6f  sk, i.e. it expo
4c10: 72 74 73 20 61 20 77 68 6f 6c 65 20 42 4c 4f 42  rts a whole BLOB
4c20: 20 69 6e 74 6f 20 61 6e 20 65 78 74 65 72 6e 61   into an externa
4c30: 6c 20 66 69 6c 65 3b 20 74 68 65 20 66 69 72 73  l file; the firs
4c40: 74 20 61 72 67 75 6d 65 6e 74 20 6d 75 73 74 20  t argument must 
4c50: 63 6f 72 72 65 73 70 6f 6e 64 20 74 6f 20 73 6f  correspond to so
4c60: 6d 65 20 42 4c 4f 42 2c 20 74 68 65 20 73 65 63  me BLOB, the sec
4c70: 6f 6e 64 20 6f 6e 65 20 69 73 20 74 68 65 20 3c  ond one is the <
4c80: 62 3e 66 69 6c 65 2d 70 61 74 68 3c 2f 62 3e 20  b>file-path</b> 
4c90: 69 64 65 6e 74 69 66 79 69 6e 67 20 74 68 65 20  identifying the 
4ca0: 66 69 6c 65 20 74 6f 20 62 65 20 63 72 65 61 74  file to be creat
4cb0: 65 64 20 6f 72 20 6f 76 65 72 77 72 69 74 74 65  ed or overwritte
4cc0: 6e 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 75 3e 50  n.<br><br>..<u>P
4cd0: 6c 65 61 73 65 20 6e 6f 74 65 3c 2f 75 3e 3a 20  lease note</u>: 
4ce0: 62 6f 74 68 20 3c 62 3e 42 6c 6f 62 46 72 6f 6d  both <b>BlobFrom
4cf0: 46 69 6c 65 28 29 3c 2f 62 3e 20 61 6e 64 20 3c  File()</b> and <
4d00: 62 3e 42 6c 6f 62 54 6f 46 69 6c 65 28 29 3c 2f  b>BlobToFile()</
4d10: 62 3e 20 77 65 72 65 20 61 6c 72 65 61 64 79 20  b> were already 
4d20: 73 75 70 70 6f 72 74 65 64 20 62 79 20 34 2e 30  supported by 4.0
4d30: 2e 30 2c 20 62 75 74 20 61 20 71 75 69 63 6b 20  .0, but a quick 
4d40: 72 65 63 61 6c 6c 20 69 73 20 61 6e 79 77 61 79  recall is anyway
4d50: 20 75 73 65 66 75 6c 20 73 6f 20 74 6f 20 72 65   useful so to re
4d60: 63 61 6c 6c 20 61 20 63 6c 65 61 72 65 72 20 63  call a clearer c
4d70: 6f 6e 74 65 78 74 2e 3c 62 72 3e 3c 62 72 3e 0d  ontext.<br><br>.
4d80: 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d  .<hr>..<verbatim
4d90: 3e 0d 0a 53 45 4c 45 43 54 20 58 42 5f 4c 6f 61  >..SELECT XB_Loa
4da0: 64 58 4d 4c 28 20 27 43 3a 2f 6d 79 64 6f 63 73  dXML( 'C:/mydocs
4db0: 2f 69 73 6f 6d 65 74 61 64 61 74 61 2d 73 61 6d  /isometadata-sam
4dc0: 70 6c 65 2e 78 6d 6c 27 20 29 3b 0d 0a 2d 2d 2d  ple.xml' );..---
4dd0: 2d 2d 2d 2d 2d 0d 0a 42 4c 4f 42 2d 76 61 6c 75  -----..BLOB-valu
4de0: 65 0d 0a 0d 0a 53 45 4c 45 43 54 20 58 42 5f 4c  e....SELECT XB_L
4df0: 6f 61 64 58 4d 4c 28 20 27 68 74 74 70 3a 2f 2f  oadXML( 'http://
4e00: 77 77 77 2e 61 63 6d 65 2e 63 6f 6d 2f 70 75 62  www.acme.com/pub
4e10: 6c 69 63 2f 69 73 6f 6d 65 74 61 64 61 74 61 2d  lic/isometadata-
4e20: 73 61 6d 70 6c 65 2e 78 6d 6c 27 20 29 3b 0d 0a  sample.xml' );..
4e30: 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 42 4c 4f 42 2d 76  --------..BLOB-v
4e40: 61 6c 75 65 0d 0a 3c 2f 76 65 72 62 61 74 69 6d  alue..</verbatim
4e50: 3e 0d 0a 54 68 65 20 3c 62 3e 58 42 5f 4c 6f 61  >..The <b>XB_Loa
4e60: 64 58 4d 4c 28 29 3c 2f 62 3e 20 53 51 4c 20 66  dXML()</b> SQL f
4e70: 75 6e 63 74 69 6f 6e 20 61 6c 6c 6f 77 73 20 74  unction allows t
4e80: 6f 20 69 6d 70 6f 72 74 20 61 6e 20 58 4d 4c 20  o import an XML 
4e90: 44 6f 63 75 6d 65 6e 74 20 69 6e 20 61 20 73 69  Document in a si
4ea0: 6e 67 6c 65 20 73 74 65 70 3a 20 74 68 65 20 66  ngle step: the f
4eb0: 75 6c 6c 20 58 4d 4c 20 44 6f 63 75 6d 65 6e 74  ull XML Document
4ec0: 20 70 61 79 6c 6f 61 64 20 77 69 6c 6c 20 62 65   payload will be
4ed0: 20 72 65 74 75 72 6e 65 64 20 61 73 20 61 20 42   returned as a B
4ee0: 4c 4f 42 20 76 61 6c 75 65 2e 3c 62 72 3e 0d 0a  LOB value.<br>..
4ef0: 54 68 65 20 70 61 73 73 65 64 20 61 72 67 75 6d  The passed argum
4f00: 65 6e 74 20 63 61 6e 20 69 6e 64 69 66 66 65 72  ent can indiffer
4f10: 65 6e 74 6c 79 20 62 65 20 61 20 3c 62 3e 66 69  ently be a <b>fi
4f20: 6c 65 2d 70 61 74 68 3c 2f 62 3e 20 6f 72 20 61  le-path</b> or a
4f30: 20 3c 62 3e 55 52 4c 3c 2f 62 3e 3b 20 69 66 20   <b>URL</b>; if 
4f40: 74 68 65 20 64 61 74 61 73 6f 75 72 63 65 20 63  the datasource c
4f50: 61 6e 6e 6f 74 20 62 65 20 61 63 63 65 73 73 65  annot be accesse
4f60: 64 2c 20 6f 72 20 69 66 20 69 74 20 64 6f 65 73  d, or if it does
4f70: 6e 27 74 20 63 6f 6e 74 61 69 6e 73 20 61 20 3c  n't contains a <
4f80: 75 3e 77 65 6c 6c 2d 66 6f 72 6d 65 64 3c 2f 75  u>well-formed</u
4f90: 3e 20 58 4d 4c 20 44 6f 63 75 6d 65 6e 74 20 4e  > XML Document N
4fa0: 55 4c 4c 20 77 69 6c 6c 20 62 65 20 72 65 74 75  ULL will be retu
4fb0: 72 6e 65 64 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c  rned.<br><br>..<
4fc0: 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d  hr>..<verbatim>.
4fd0: 0a 53 45 4c 45 43 54 20 58 42 5f 53 74 6f 72 65  .SELECT XB_Store
4fe0: 58 4d 4c 28 20 73 6f 6d 65 58 6d 6c 42 6c 6f 62  XML( someXmlBlob
4ff0: 2c 20 27 43 3a 2f 6d 79 64 6f 63 73 2f 69 73 6f  , 'C:/mydocs/iso
5000: 6d 65 74 61 64 61 74 61 2d 73 61 6d 70 6c 65 2e  metadata-sample.
5010: 78 6d 6c 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d  xml' );..-------
5020: 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69  --..1..</verbati
5030: 6d 3e 0d 0a 54 68 65 20 3c 62 3e 58 42 5f 53 74  m>..The <b>XB_St
5040: 6f 72 65 58 4d 4c 28 29 3c 2f 62 3e 20 53 51 4c  oreXML()</b> SQL
5050: 20 66 75 6e 63 74 69 6f 6e 20 70 65 72 66 6f 72   function perfor
5060: 6d 73 20 74 68 65 20 6f 70 70 6f 73 69 74 65 20  ms the opposite 
5070: 74 61 73 6b 2c 20 69 2e 65 2e 20 69 74 20 65 78  task, i.e. it ex
5080: 70 6f 72 74 73 20 61 20 77 68 6f 6c 65 20 58 6d  ports a whole Xm
5090: 6c 42 4c 4f 42 20 69 6e 74 6f 20 61 6e 20 65 78  lBLOB into an ex
50a0: 74 65 72 6e 61 6c 20 66 69 6c 65 20 61 73 20 61  ternal file as a
50b0: 6e 20 58 4d 4c 20 44 6f 63 75 6d 65 6e 74 3b 20  n XML Document; 
50c0: 74 68 65 20 66 69 72 73 74 20 61 72 67 75 6d 65  the first argume
50d0: 6e 74 20 6d 75 73 74 20 63 6f 72 72 65 73 70 6f  nt must correspo
50e0: 6e 64 20 74 6f 20 73 6f 6d 65 20 76 61 6c 69 64  nd to some valid
50f0: 20 58 6d 6c 42 4c 4f 42 2c 20 74 68 65 20 73 65   XmlBLOB, the se
5100: 63 6f 6e 64 20 6f 6e 65 20 69 73 20 74 68 65 20  cond one is the 
5110: 3c 62 3e 66 69 6c 65 2d 70 61 74 68 3c 2f 62 3e  <b>file-path</b>
5120: 20 69 64 65 6e 74 69 66 79 69 6e 67 20 74 68 65   identifying the
5130: 20 66 69 6c 65 20 74 6f 20 62 65 20 63 72 65 61   file to be crea
5140: 74 65 64 20 6f 72 20 6f 76 65 72 77 72 69 74 74  ted or overwritt
5150: 65 6e 2e 20 0d 0a 3c 76 65 72 62 61 74 69 6d 3e  en. ..<verbatim>
5160: 0d 0a 53 45 4c 45 43 54 20 58 42 5f 53 74 6f 72  ..SELECT XB_Stor
5170: 65 58 4d 4c 28 20 73 6f 6d 65 58 6d 6c 42 6c 6f  eXML( someXmlBlo
5180: 62 2c 20 27 43 3a 2f 6d 79 64 6f 63 73 2f 69 73  b, 'C:/mydocs/is
5190: 6f 6d 65 74 61 64 61 74 61 2d 73 61 6d 70 6c 65  ometadata-sample
51a0: 2e 78 6d 6c 27 2c 20 34 20 29 3b 0d 0a 2d 2d 2d  .xml', 4 );..---
51b0: 2d 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72  ------..1..</ver
51c0: 62 61 74 69 6d 3e 0d 0a 41 20 66 75 72 74 68 65  batim>..A furthe
51d0: 72 20 6f 70 74 69 6f 6e 61 6c 20 3c 62 3e 69 6e  r optional <b>in
51e0: 64 65 6e 74 61 74 69 6f 6e 3c 2f 62 3e 20 61 72  dentation</b> ar
51f0: 67 75 6d 65 6e 74 20 63 61 6e 20 62 65 20 65 76  gument can be ev
5200: 65 6e 74 75 61 6c 6c 79 20 73 70 65 63 69 66 69  entually specifi
5210: 65 64 3b 20 74 68 69 73 20 61 72 67 75 6d 65 6e  ed; this argumen
5220: 74 20 77 69 6c 6c 20 62 65 20 68 61 6e 64 6c 65  t will be handle
5230: 64 20 65 78 61 63 74 6c 79 20 69 6e 20 74 68 65  d exactly in the
5240: 20 73 61 6d 65 20 77 61 79 20 61 6c 72 65 61 64   same way alread
5250: 79 20 73 70 65 63 69 66 69 65 64 20 66 6f 72 20  y specified for 
5260: 62 6f 74 68 20 3c 62 3e 58 42 5f 47 65 74 50 61  both <b>XB_GetPa
5270: 79 6c 6f 61 64 28 29 3c 2f 62 3e 20 61 6e 64 20  yload()</b> and 
5280: 3c 62 3e 58 42 5f 47 65 74 44 6f 63 75 6d 65 6e  <b>XB_GetDocumen
5290: 74 28 29 3c 2f 62 3e 20 66 75 6e 63 74 69 6f 6e  t()</b> function
52a0: 73 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e  s.<br><br>..<hr>
52b0: 0d 0a 3c 62 72 3e 41 20 66 75 72 74 68 65 72 20  ..<br>A further 
52c0: 3c 75 3e 3c 69 3e 75 6e 73 61 66 65 3c 2f 69 3e  <u><i>unsafe</i>
52d0: 3c 2f 75 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f  </u> SQL functio
52e0: 6e 20 69 73 20 3c 62 3e 45 78 70 6f 72 74 44 58  n is <b>ExportDX
52f0: 46 28 29 3c 2f 62 3e 2c 20 77 68 69 63 68 20 69  F()</b>, which i
5300: 73 20 73 65 70 61 72 61 74 65 6c 79 20 64 6f 63  s separately doc
5310: 75 6d 65 6e 74 65 64 20 69 6e 74 6f 20 74 68 65  umented into the
5320: 20 6d 6f 72 65 20 61 70 70 72 6f 70 72 69 61 74   more appropriat
5330: 65 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 73  e <a href="https
5340: 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73 2e  ://www.gaia-gis.
5350: 69 74 2f 66 6f 73 73 69 6c 2f 6c 69 62 73 70 61  it/fossil/libspa
5360: 74 69 61 6c 69 74 65 2f 77 69 6b 69 3f 6e 61 6d  tialite/wiki?nam
5370: 65 3d 44 58 46 22 3e 44 58 46 20 57 69 6b 69 20  e=DXF">DXF Wiki 
5380: 70 61 67 65 3c 2f 61 3e 2e 3c 62 72 3e 3c 62 72  page</a>.<br><br
5390: 3e 0d 0a 3c 68 72 3e 3c 62 72 3e 0d 0a 62 61 63  >..<hr><br>..bac
53a0: 6b 20 74 6f 20 3c 61 20 68 72 65 66 3d 22 68 74  k to <a href="ht
53b0: 74 70 73 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67  tps://www.gaia-g
53c0: 69 73 2e 69 74 2f 66 6f 73 73 69 6c 2f 6c 69 62  is.it/fossil/lib
53d0: 73 70 61 74 69 61 6c 69 74 65 2f 77 69 6b 69 3f  spatialite/wiki?
53e0: 6e 61 6d 65 3d 34 2e 31 2e 30 2d 64 6f 63 22 3e  name=4.1.0-doc">
53f0: 34 2e 31 2e 30 2d 64 6f 63 3c 2f 61 3e 0a 5a 20  4.1.0-doc</a>.Z 
5400: 61 35 63 63 33 36 30 39 36 37 33 66 33 39 38 36  a5cc3609673f3986
5410: 64 30 62 33 64 62 38 38 31 66 36 35 64 65 37 37  d0b3db881f65de77
5420: 0a                                               .