Hex Artifact Content
Not logged in

Artifact ece9ebdf8b43745affa9ab4d7101621aca0bceee:

Wiki page [4.1.0 Changes] by sandro 2013-03-12 08:41:18.
0000: 44 20 32 30 31 33 2d 30 33 2d 31 32 54 30 38 3a  D 2013-03-12T08:
0010: 34 31 3a 31 38 2e 32 39 36 0a 4c 20 34 2e 31 2e  41:18.296.L 4.1.
0020: 30 5c 73 43 68 61 6e 67 65 73 0a 50 20 32 32 37  0\sChanges.P 227
0030: 36 32 63 39 62 65 33 64 36 31 33 65 38 63 36 33  62c9be3d613e8c63
0040: 62 66 34 30 38 37 39 66 63 63 37 35 38 62 66 30  bf40879fcc758bf0
0050: 65 35 34 39 39 0a 55 20 73 61 6e 64 72 6f 0a 57  e5499.U sandro.W
0060: 20 31 35 33 35 31 0a 62 61 63 6b 20 74 6f 20 58   15351.back to X
0070: 6d 6c 42 6c 6f 62 20 3c 61 20 68 72 65 66 3d 22  mlBlob <a href="
0080: 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67 61 69 61  https://www.gaia
0090: 2d 67 69 73 2e 69 74 2f 66 6f 73 73 69 6c 2f 6c  -gis.it/fossil/l
00a0: 69 62 73 70 61 74 69 61 6c 69 74 65 2f 77 69 6b  ibspatialite/wik
00b0: 69 3f 6e 61 6d 65 3d 58 6d 6c 42 6c 6f 62 2b 61  i?name=XmlBlob+a
00c0: 6e 64 2b 56 69 72 74 75 61 6c 58 50 61 74 68 22  nd+VirtualXPath"
00d0: 3e 6d 61 69 6e 20 70 61 67 65 3c 2f 61 3e 0d 0a  >main page</a>..
00e0: 3c 68 32 3e 4e 65 77 20 53 51 4c 20 66 75 6e 63  <h2>New SQL func
00f0: 74 69 6f 6e 73 20 69 6e 74 72 6f 64 75 63 65 64  tions introduced
0100: 20 69 6e 20 34 2e 31 2e 30 3c 2f 68 32 3e 0d 0a   in 4.1.0</h2>..
0110: 3c 68 33 3e 47 65 6e 65 72 69 63 20 53 51 4c 20  <h3>Generic SQL 
0120: 66 75 6e 63 74 69 6f 6e 73 20 2d 20 74 79 70 65  functions - type
0130: 20 63 61 73 74 69 6e 67 3c 2f 68 33 3e 0d 0a 53   casting</h3>..S
0140: 51 4c 69 74 65 20 6f 66 66 65 72 73 20 6a 75 73  QLite offers jus
0150: 74 20 61 20 76 65 72 79 20 62 61 73 69 63 20 74  t a very basic t
0160: 79 70 65 20 63 68 65 63 6b 69 6e 67 3b 20 74 68  ype checking; th
0170: 69 73 20 69 73 20 73 6f 6d 65 74 69 6d 65 73 20  is is sometimes 
0180: 75 73 65 66 75 6c 2c 20 62 75 74 20 63 6f 75 6c  useful, but coul
0190: 64 20 62 65 20 72 65 61 6c 6c 79 20 61 6e 6e 6f  d be really anno
01a0: 79 69 6e 67 20 76 65 72 79 20 6f 66 74 65 6e 2e  ying very often.
01b0: 3c 62 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e  <br>..<verbatim>
01c0: 0d 0a 53 45 4c 45 43 54 20 27 31 27 2c 20 54 79  ..SELECT '1', Ty
01d0: 70 65 4f 66 28 20 27 31 27 20 29 2c 20 43 41 53  peOf( '1' ), CAS
01e0: 54 20 28 20 27 31 27 20 41 53 20 49 4e 54 45 47  T ( '1' AS INTEG
01f0: 45 52 20 29 2c 20 54 79 70 65 4f 66 28 20 43 41  ER ), TypeOf( CA
0200: 53 54 20 28 20 27 31 27 20 41 53 20 49 4e 54 45  ST ( '1' AS INTE
0210: 47 45 52 20 29 20 29 3b 0d 0a 3c 2f 76 65 72 62  GER ) );..</verb
0220: 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c 65 20 62 6f  atim>..<table bo
0230: 72 64 65 72 3d 22 31 22 20 63 65 6c 6c 73 70 61  rder="1" cellspa
0240: 63 69 6e 67 3d 22 34 22 20 63 65 6c 6c 70 61 64  cing="4" cellpad
0250: 64 69 6e 67 3d 22 34 22 3e 0d 0a 3c 74 72 3e 3c  ding="4">..<tr><
0260: 74 68 3e 27 31 27 3c 2f 74 68 3e 3c 74 68 3e 54  th>'1'</th><th>T
0270: 79 70 65 4f 66 28 20 27 31 27 20 29 3c 2f 74 68  ypeOf( '1' )</th
0280: 3e 3c 74 68 3e 43 41 53 54 20 28 20 27 31 27 20  ><th>CAST ( '1' 
0290: 41 53 20 49 4e 54 45 47 45 52 20 29 3c 2f 74 68  AS INTEGER )</th
02a0: 3e 3c 74 68 3e 54 79 70 65 4f 66 28 20 43 41 53  ><th>TypeOf( CAS
02b0: 54 20 28 20 27 31 27 20 41 53 20 49 4e 54 45 47  T ( '1' AS INTEG
02c0: 45 52 20 29 20 29 3c 2f 74 68 3e 3c 2f 74 72 3e  ER ) )</th></tr>
02d0: 0d 0a 3c 74 72 3e 3c 74 64 3e 31 3c 2f 74 64 3e  ..<tr><td>1</td>
02e0: 3c 74 64 3e 74 65 78 74 3c 2f 74 64 3e 3c 74 64  <td>text</td><td
02f0: 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 31   align="right">1
0300: 3c 2f 74 64 3e 3c 74 64 3e 69 6e 74 65 67 65 72  </td><td>integer
0310: 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c  </td></tr></tabl
0320: 65 3e 3c 62 72 3e 0d 0a 54 68 65 20 53 51 4c 20  e><br>..The SQL 
0330: 3c 62 3e 43 41 53 54 3c 2f 62 3e 20 6f 70 65 72  <b>CAST</b> oper
0340: 61 74 6f 72 20 61 6c 72 65 61 64 79 20 73 75 70  ator already sup
0350: 70 6f 72 74 73 20 74 68 65 20 70 6f 73 73 69 62  ports the possib
0360: 69 6c 69 74 79 20 74 6f 20 65 78 70 6c 69 63 69  ility to explici
0370: 74 6c 79 20 73 65 74 20 61 20 64 61 74 61 2d 74  tly set a data-t
0380: 79 70 65 3b 20 6e 6f 77 20 73 74 61 72 74 69 6e  ype; now startin
0390: 67 20 73 69 6e 63 65 20 34 2e 31 2e 30 20 53 70  g since 4.1.0 Sp
03a0: 61 74 69 61 4c 69 74 65 20 73 75 70 70 6f 72 74  atiaLite support
03b0: 73 20 66 65 77 20 53 51 4c 20 66 75 6e 63 74 69  s few SQL functi
03c0: 6f 6e 73 20 70 65 72 66 6f 72 6d 69 6e 67 20 74  ons performing t
03d0: 68 65 20 73 61 6d 65 20 74 61 73 6b 2e 3c 62 72  he same task.<br
03e0: 3e 0d 0a 3c 75 3e 50 6c 65 61 73 65 20 6e 6f 74  >..<u>Please not
03f0: 65 3c 2f 75 3e 3a 20 73 6f 6d 65 20 73 75 62 74  e</u>: some subt
0400: 6c 65 20 64 69 66 66 65 72 65 6e 63 65 73 20 65  le differences e
0410: 78 69 73 74 73 20 68 65 72 65 20 61 6e 64 20 74  xists here and t
0420: 68 65 72 65 3b 20 70 6c 65 61 73 65 20 63 61 72  here; please car
0430: 65 66 75 6c 6c 79 20 72 65 61 64 20 74 68 69 73  efully read this
0440: 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e 20 70   documentation p
0450: 61 67 65 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e  age...<verbatim>
0460: 0d 0a 53 45 4c 45 43 54 20 43 61 73 74 54 6f 49  ..SELECT CastToI
0470: 6e 74 65 67 65 72 28 20 31 20 29 2c 20 43 61 73  nteger( 1 ), Cas
0480: 74 54 6f 49 6e 74 65 67 65 72 28 20 31 2e 34 20  tToInteger( 1.4 
0490: 29 2c 20 43 61 73 74 54 6f 49 6e 74 65 67 65 72  ), CastToInteger
04a0: 28 20 31 2e 36 20 29 2c 20 0d 0a 20 20 20 20 43  ( 1.6 ), ..    C
04b0: 61 73 74 54 6f 49 6e 74 65 67 65 72 28 20 27 31  astToInteger( '1
04c0: 32 33 27 20 29 2c 20 43 61 73 74 54 6f 49 6e 74  23' ), CastToInt
04d0: 65 67 65 72 28 20 27 61 6c 70 68 61 27 20 29 2c  eger( 'alpha' ),
04e0: 20 43 61 73 74 54 6f 49 6e 74 65 67 65 72 20 28   CastToInteger (
04f0: 20 7a 65 72 6f 62 6c 6f 62 28 34 29 20 29 3b 0d   zeroblob(4) );.
0500: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 74  .</verbatim>..<t
0510: 61 62 6c 65 20 62 6f 72 64 65 72 3d 22 31 22 20  able border="1" 
0520: 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 34 22 20  cellspacing="4" 
0530: 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 34 22 3e  cellpadding="4">
0540: 0d 0a 3c 74 72 3e 3c 74 68 3e 43 61 73 74 54 6f  ..<tr><th>CastTo
0550: 49 6e 74 65 67 65 72 28 20 31 20 29 3c 2f 74 68  Integer( 1 )</th
0560: 3e 3c 74 68 3e 43 61 73 74 54 6f 49 6e 74 65 67  ><th>CastToInteg
0570: 65 72 28 20 31 2e 34 20 29 3c 2f 74 68 3e 3c 74  er( 1.4 )</th><t
0580: 68 3e 43 61 73 74 54 6f 49 6e 74 65 67 65 72 28  h>CastToInteger(
0590: 20 31 2e 36 20 29 3c 2f 74 68 3e 3c 74 68 3e 43   1.6 )</th><th>C
05a0: 61 73 74 54 6f 49 6e 74 65 67 65 72 28 20 27 31  astToInteger( '1
05b0: 32 33 27 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 61  23' )</th><th>Ca
05c0: 73 74 54 6f 49 6e 74 65 67 65 72 28 20 27 61 6c  stToInteger( 'al
05d0: 70 68 61 27 20 29 3c 2f 74 68 3e 3c 74 68 3e 43  pha' )</th><th>C
05e0: 61 73 74 54 6f 49 6e 74 65 67 65 72 20 28 20 7a  astToInteger ( z
05f0: 65 72 6f 62 6c 6f 62 28 34 29 20 29 3c 2f 74 68  eroblob(4) )</th
0600: 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20  ></tr>..<tr><td 
0610: 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 31 3c  align="right">1<
0620: 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72  /td><td align="r
0630: 69 67 68 74 22 3e 31 3c 2f 74 64 3e 3c 74 64 20  ight">1</td><td 
0640: 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 32 3c  align="right">2<
0650: 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72  /td><td align="r
0660: 69 67 68 74 22 3e 31 32 33 3c 2f 74 64 3e 3c 74  ight">123</td><t
0670: 64 3e 4e 55 4c 4c 3c 2f 74 64 3e 3c 74 64 3e 4e  d>NULL</td><td>N
0680: 55 4c 4c 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74  ULL</td></tr></t
0690: 61 62 6c 65 3e 3c 62 72 3e 0d 0a 54 68 65 20 3c  able><br>..The <
06a0: 62 3e 43 61 73 74 54 6f 49 6e 74 65 67 65 72 28  b>CastToInteger(
06b0: 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69  )</b> SQL functi
06c0: 6f 6e 20 77 69 6c 6c 20 61 74 74 65 6d 70 74 20  on will attempt 
06d0: 74 6f 20 72 65 74 75 72 6e 20 61 20 76 61 6c 75  to return a valu
06e0: 65 20 6f 66 20 74 68 65 20 3c 62 3e 49 6e 74 65  e of the <b>Inte
06f0: 67 65 72 3c 2f 62 3e 20 64 61 74 61 2d 74 79 70  ger</b> data-typ
0700: 65 2c 20 6f 72 20 3c 62 3e 4e 55 4c 4c 3c 2f 62  e, or <b>NULL</b
0710: 3e 20 69 66 20 6e 6f 20 63 6f 6e 76 65 72 73 69  > if no conversi
0720: 6f 6e 20 69 73 20 70 6f 73 73 69 62 6c 65 2e 0d  on is possible..
0730: 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 6e 20 49 6e  .<ul>..<li>an In
0740: 74 65 67 65 72 20 69 6e 70 75 74 20 61 72 67 75  teger input argu
0750: 6d 65 6e 74 20 77 69 6c 6c 20 62 65 20 72 65 74  ment will be ret
0760: 75 72 6e 65 64 20 61 62 73 6f 6c 75 74 65 6c 79  urned absolutely
0770: 20 75 6e 61 66 66 65 63 74 65 64 2e 3c 2f 6c 69   unaffected.</li
0780: 3e 0d 0a 3c 6c 69 3e 61 20 44 6f 75 62 6c 65 20  >..<li>a Double 
0790: 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77  input argument w
07a0: 69 6c 6c 20 72 65 74 75 72 6e 20 74 68 65 20 3c  ill return the <
07b0: 75 3e 6e 65 61 72 65 73 74 3c 2f 75 3e 20 49 6e  u>nearest</u> In
07c0: 74 65 67 65 72 20 76 61 6c 75 65 20 28 61 66 74  teger value (aft
07d0: 65 72 20 61 70 70 6c 79 69 6e 67 20 3c 62 3e 34  er applying <b>4
07e0: 2f 35 3c 2f 62 3e 20 72 6f 75 6e 64 69 6e 67 29  /5</b> rounding)
07f0: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 54 65  .</li>..<li>a Te
0800: 78 74 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e  xt input argumen
0810: 74 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 74 68  t will return th
0820: 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20  e corresponding 
0830: 49 6e 74 65 67 65 72 20 76 61 6c 75 65 20 6f 6e  Integer value on
0840: 6c 79 20 69 66 20 74 68 65 20 74 65 78 74 20 73  ly if the text s
0850: 74 72 69 6e 67 20 72 65 70 72 65 73 65 6e 74 73  tring represents
0860: 20 61 20 76 61 6c 69 64 20 6e 75 6d 62 65 72 20   a valid number 
0870: 28 65 76 65 6e 20 61 20 64 65 63 69 6d 61 6c 20  (even a decimal 
0880: 6f 6e 65 29 3a 20 69 66 20 74 68 65 20 74 65 78  one): if the tex
0890: 74 20 73 74 72 69 6e 67 20 63 61 6e 6e 6f 74 20  t string cannot 
08a0: 62 65 20 63 6f 6e 76 65 72 74 65 64 20 74 6f 20  be converted to 
08b0: 61 20 6e 75 6d 62 65 72 20 4e 55 4c 4c 20 77 69  a number NULL wi
08c0: 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 2e 3c  ll be returned.<
08d0: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 42 4c  /li>..<li>any BL
08e0: 4f 42 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e  OB input argumen
08f0: 74 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 61 20  t will return a 
0900: 4e 55 4c 4c 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e  NULL value.</li>
0910: 0d 0a 3c 6c 69 3e 61 6e 79 20 4e 55 4c 4c 20 69  ..<li>any NULL i
0920: 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69  nput argument wi
0930: 6c 6c 20 72 65 74 75 72 6e 20 61 20 4e 55 4c 4c  ll return a NULL
0940: 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f   value.</li>..</
0950: 75 6c 3e 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62  ul>..<hr>..<verb
0960: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 43 61  atim>..SELECT Ca
0970: 73 74 54 6f 44 6f 75 62 6c 65 28 20 31 20 29 2c  stToDouble( 1 ),
0980: 20 43 61 73 74 54 6f 44 6f 75 62 6c 65 28 20 31   CastToDouble( 1
0990: 2e 32 33 20 29 2c 20 43 61 73 74 54 6f 44 6f 75  .23 ), CastToDou
09a0: 62 6c 65 28 20 27 31 32 33 2e 34 35 27 20 29 2c  ble( '123.45' ),
09b0: 0d 0a 20 20 20 20 43 61 73 74 54 6f 44 6f 75 62  ..    CastToDoub
09c0: 6c 65 28 20 27 61 6c 70 68 61 27 20 29 2c 20 43  le( 'alpha' ), C
09d0: 61 73 74 54 6f 44 6f 75 62 6c 65 20 28 20 7a 65  astToDouble ( ze
09e0: 72 6f 62 6c 6f 62 28 34 29 20 29 3b 0d 0a 3c 2f  roblob(4) );..</
09f0: 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c  verbatim>..<tabl
0a00: 65 20 62 6f 72 64 65 72 3d 22 31 22 20 63 65 6c  e border="1" cel
0a10: 6c 73 70 61 63 69 6e 67 3d 22 34 22 20 63 65 6c  lspacing="4" cel
0a20: 6c 70 61 64 64 69 6e 67 3d 22 34 22 3e 0d 0a 3c  lpadding="4">..<
0a30: 74 72 3e 3c 74 68 3e 43 61 73 74 54 6f 44 6f 75  tr><th>CastToDou
0a40: 62 6c 65 28 20 31 20 29 3c 2f 74 68 3e 3c 74 68  ble( 1 )</th><th
0a50: 3e 43 61 73 74 54 6f 44 6f 75 62 6c 65 28 20 31  >CastToDouble( 1
0a60: 2e 32 33 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 61  .23 )</th><th>Ca
0a70: 73 74 54 6f 44 6f 75 62 6c 65 28 20 27 31 32 33  stToDouble( '123
0a80: 2e 34 35 27 20 29 3c 2f 74 68 3e 3c 74 68 3e 43  .45' )</th><th>C
0a90: 61 73 74 54 6f 44 6f 75 62 6c 65 28 20 27 61 6c  astToDouble( 'al
0aa0: 70 68 61 27 20 29 3c 2f 74 68 3e 3c 74 68 3e 43  pha' )</th><th>C
0ab0: 61 73 74 54 6f 44 6f 75 62 6c 65 20 28 20 7a 65  astToDouble ( ze
0ac0: 72 6f 62 6c 6f 62 28 34 29 20 29 3c 2f 74 68 3e  roblob(4) )</th>
0ad0: 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61  </tr>..<tr><td a
0ae0: 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 31 2e 30  lign="right">1.0
0af0: 30 30 30 30 30 3c 2f 74 64 3e 3c 74 64 20 61 6c  00000</td><td al
0b00: 69 67 6e 3d 22 72 69 67 68 74 22 3e 31 2e 32 33  ign="right">1.23
0b10: 30 30 30 30 3c 2f 74 64 3e 3c 74 64 20 61 6c 69  0000</td><td ali
0b20: 67 6e 3d 22 72 69 67 68 74 22 3e 31 32 33 2e 34  gn="right">123.4
0b30: 35 30 30 30 3c 2f 74 64 3e 3c 74 64 3e 4e 55 4c  5000</td><td>NUL
0b40: 4c 3c 2f 74 64 3e 3c 74 64 3e 4e 55 4c 4c 3c 2f  L</td><td>NULL</
0b50: 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e  td></tr></table>
0b60: 3c 62 72 3e 0d 0a 54 68 65 20 3c 62 3e 43 61 73  <br>..The <b>Cas
0b70: 74 54 6f 44 6f 75 62 6c 65 28 29 3c 2f 62 3e 20  tToDouble()</b> 
0b80: 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 77 69 6c  SQL function wil
0b90: 6c 20 61 74 74 65 6d 70 74 20 74 6f 20 72 65 74  l attempt to ret
0ba0: 75 72 6e 20 61 20 76 61 6c 75 65 20 6f 66 20 74  urn a value of t
0bb0: 68 65 20 3c 62 3e 44 6f 75 62 6c 65 3c 2f 62 3e  he <b>Double</b>
0bc0: 20 64 61 74 61 2d 74 79 70 65 2c 20 6f 72 20 3c   data-type, or <
0bd0: 62 3e 4e 55 4c 4c 3c 2f 62 3e 20 69 66 20 6e 6f  b>NULL</b> if no
0be0: 20 63 6f 6e 76 65 72 73 69 6f 6e 20 69 73 20 70   conversion is p
0bf0: 6f 73 73 69 62 6c 65 2e 0d 0a 3c 75 6c 3e 0d 0a  ossible...<ul>..
0c00: 3c 6c 69 3e 61 6e 20 49 6e 74 65 67 65 72 20 69  <li>an Integer i
0c10: 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69  nput argument wi
0c20: 6c 6c 20 72 65 74 75 72 6e 20 74 68 65 20 63 6f  ll return the co
0c30: 72 72 65 73 70 6f 6e 64 69 6e 67 20 44 6f 75 62  rresponding Doub
0c40: 6c 65 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a  le value.</li>..
0c50: 3c 6c 69 3e 61 20 44 6f 75 62 6c 65 20 69 6e 70  <li>a Double inp
0c60: 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c  ut argument will
0c70: 20 62 65 20 72 65 74 75 72 6e 65 64 20 61 62 73   be returned abs
0c80: 6f 6c 75 74 65 6c 79 20 75 6e 61 66 66 65 63 74  olutely unaffect
0c90: 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 20  ed.</li>..<li>a 
0ca0: 54 65 78 74 20 69 6e 70 75 74 20 61 72 67 75 6d  Text input argum
0cb0: 65 6e 74 20 77 69 6c 6c 20 72 65 74 75 72 6e 20  ent will return 
0cc0: 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e  the correspondin
0cd0: 67 20 44 6f 75 62 6c 65 20 76 61 6c 75 65 20 6f  g Double value o
0ce0: 6e 6c 79 20 69 66 20 74 68 65 20 74 65 78 74 20  nly if the text 
0cf0: 73 74 72 69 6e 67 20 72 65 70 72 65 73 65 6e 74  string represent
0d00: 73 20 61 20 76 61 6c 69 64 20 6e 75 6d 62 65 72  s a valid number
0d10: 3a 20 69 66 20 74 68 65 20 74 65 78 74 20 73 74  : if the text st
0d20: 72 69 6e 67 20 63 61 6e 6e 6f 74 20 62 65 20 63  ring cannot be c
0d30: 6f 6e 76 65 72 74 65 64 20 74 6f 20 61 20 6e 75  onverted to a nu
0d40: 6d 62 65 72 20 4e 55 4c 4c 20 77 69 6c 6c 20 62  mber NULL will b
0d50: 65 20 72 65 74 75 72 6e 65 64 2e 3c 2f 6c 69 3e  e returned.</li>
0d60: 0d 0a 3c 6c 69 3e 61 6e 79 20 42 4c 4f 42 20 69  ..<li>any BLOB i
0d70: 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69  nput argument wi
0d80: 6c 6c 20 72 65 74 75 72 6e 20 61 20 4e 55 4c 4c  ll return a NULL
0d90: 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c   value.</li>..<l
0da0: 69 3e 61 6e 79 20 4e 55 4c 4c 20 69 6e 70 75 74  i>any NULL input
0db0: 20 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 72   argument will r
0dc0: 65 74 75 72 6e 20 61 20 4e 55 4c 4c 20 76 61 6c  eturn a NULL val
0dd0: 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d  ue.</li>..</ul>.
0de0: 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d  .<hr>..<verbatim
0df0: 3e 0d 0a 53 45 4c 45 43 54 20 43 61 73 74 54 6f  >..SELECT CastTo
0e00: 54 65 78 74 28 20 31 20 29 2c 20 43 61 73 74 54  Text( 1 ), CastT
0e10: 6f 54 65 78 74 28 20 31 2e 35 20 29 2c 20 43 61  oText( 1.5 ), Ca
0e20: 73 74 54 6f 54 65 78 74 28 20 27 61 6c 70 68 61  stToText( 'alpha
0e30: 27 20 29 2c 20 43 61 73 74 54 6f 54 65 78 74 20  ' ), CastToText 
0e40: 28 20 7a 65 72 6f 62 6c 6f 62 28 34 29 20 29 3b  ( zeroblob(4) );
0e50: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c  ..</verbatim>..<
0e60: 74 61 62 6c 65 20 62 6f 72 64 65 72 3d 22 31 22  table border="1"
0e70: 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 34 22   cellspacing="4"
0e80: 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 34 22   cellpadding="4"
0e90: 3e 0d 0a 3c 74 72 3e 3c 74 68 3e 43 61 73 74 54  >..<tr><th>CastT
0ea0: 6f 54 65 78 74 28 20 31 20 29 3c 2f 74 68 3e 3c  oText( 1 )</th><
0eb0: 74 68 3e 43 61 73 74 54 6f 54 65 78 74 28 20 31  th>CastToText( 1
0ec0: 2e 35 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 61 73  .5 )</th><th>Cas
0ed0: 74 54 6f 54 65 78 74 28 20 27 61 6c 70 68 61 27  tToText( 'alpha'
0ee0: 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 61 73 74 54   )</th><th>CastT
0ef0: 6f 54 65 78 74 20 28 20 7a 65 72 6f 62 6c 6f 62  oText ( zeroblob
0f00: 28 34 29 20 29 3c 2f 74 68 3e 3c 2f 74 72 3e 0d  (4) )</th></tr>.
0f10: 0a 3c 74 72 3e 3c 74 64 3e 31 3c 2f 74 64 3e 3c  .<tr><td>1</td><
0f20: 74 64 3e 31 2e 35 3c 2f 74 64 3e 3c 74 64 3e 61  td>1.5</td><td>a
0f30: 6c 70 68 61 3c 2f 74 64 3e 3c 74 64 3e 4e 55 4c  lpha</td><td>NUL
0f40: 4c 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62  L</td></tr></tab
0f50: 6c 65 3e 3c 62 72 3e 0d 0a 54 68 65 20 3c 62 3e  le><br>..The <b>
0f60: 43 61 73 74 54 6f 54 65 78 74 28 29 3c 2f 62 3e  CastToText()</b>
0f70: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 77 69   SQL function wi
0f80: 6c 6c 20 61 74 74 65 6d 70 74 20 74 6f 20 72 65  ll attempt to re
0f90: 74 75 72 6e 20 61 20 76 61 6c 75 65 20 6f 66 20  turn a value of 
0fa0: 74 68 65 20 3c 62 3e 54 65 78 74 3c 2f 62 3e 20  the <b>Text</b> 
0fb0: 64 61 74 61 2d 74 79 70 65 2c 20 6f 72 20 3c 62  data-type, or <b
0fc0: 3e 4e 55 4c 4c 3c 2f 62 3e 20 69 66 20 6e 6f 20  >NULL</b> if no 
0fd0: 63 6f 6e 76 65 72 73 69 6f 6e 20 69 73 20 70 6f  conversion is po
0fe0: 73 73 69 62 6c 65 2e 0d 0a 3c 75 6c 3e 0d 0a 3c  ssible...<ul>..<
0ff0: 6c 69 3e 61 6e 20 49 6e 74 65 67 65 72 20 69 6e  li>an Integer in
1000: 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 6c  put argument wil
1010: 6c 20 72 65 74 75 72 6e 20 74 68 65 20 63 6f 72  l return the cor
1020: 72 65 73 70 6f 6e 64 69 6e 67 20 54 65 78 74 20  responding Text 
1030: 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  value.</li>..<li
1040: 3e 61 20 44 6f 75 62 6c 65 20 69 6e 70 75 74 20  >a Double input 
1050: 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 62 65  argument will be
1060: 20 72 65 74 75 72 6e 20 74 68 65 20 63 6f 72 72   return the corr
1070: 65 73 70 6f 6e 64 69 6e 67 20 54 65 78 74 20 76  esponding Text v
1080: 61 6c 75 65 3b 20 6e 6f 20 73 69 67 6e 69 66 69  alue; no signifi
1090: 63 61 6e 74 20 64 65 63 69 6d 61 6c 20 64 69 67  cant decimal dig
10a0: 69 74 20 77 69 6c 6c 20 62 65 20 73 75 70 70 72  it will be suppr
10b0: 65 73 73 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  essed.</li>..<li
10c0: 3e 61 20 54 65 78 74 20 69 6e 70 75 74 20 61 72  >a Text input ar
10d0: 67 75 6d 65 6e 74 20 77 69 6c 6c 20 72 65 74 75  gument will retu
10e0: 72 6e 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e  rn the correspon
10f0: 64 69 6e 67 20 44 6f 75 62 6c 65 20 76 61 6c 75  ding Double valu
1100: 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79  e.</li>..<li>any
1110: 20 42 4c 4f 42 20 69 6e 70 75 74 20 61 72 67 75   BLOB input argu
1120: 6d 65 6e 74 20 77 69 6c 6c 20 72 65 74 75 72 6e  ment will return
1130: 20 61 20 4e 55 4c 4c 20 76 61 6c 75 65 2e 3c 2f   a NULL value.</
1140: 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 4e 55 4c  li>..<li>any NUL
1150: 4c 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74  L input argument
1160: 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 61 20 4e   will return a N
1170: 55 4c 4c 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d  ULL value.</li>.
1180: 0a 3c 2f 75 6c 3e 0d 0a 3c 76 65 72 62 61 74 69  .</ul>..<verbati
1190: 6d 3e 0d 0a 53 45 4c 45 43 54 20 43 61 73 74 54  m>..SELECT CastT
11a0: 6f 54 65 78 74 28 20 31 2c 20 34 20 29 2c 20 43  oText( 1, 4 ), C
11b0: 61 73 74 54 6f 54 65 78 74 28 20 31 32 33 34 2c  astToText( 1234,
11c0: 20 32 20 29 2c 20 43 61 73 74 54 6f 54 65 78 74   2 ), CastToText
11d0: 28 20 31 2c 20 38 20 29 2c 20 43 61 73 74 54 6f  ( 1, 8 ), CastTo
11e0: 54 65 78 74 28 20 31 2e 35 2c 20 34 20 29 3b 0d  Text( 1.5, 4 );.
11f0: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 74  .</verbatim>..<t
1200: 61 62 6c 65 20 62 6f 72 64 65 72 3d 22 31 22 20  able border="1" 
1210: 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 34 22 20  cellspacing="4" 
1220: 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 34 22 3e  cellpadding="4">
1230: 0d 0a 3c 74 72 3e 3c 74 68 3e 43 61 73 74 54 6f  ..<tr><th>CastTo
1240: 54 65 78 74 28 20 31 2c 20 34 20 29 3c 2f 74 68  Text( 1, 4 )</th
1250: 3e 3c 74 68 3e 43 61 73 74 54 6f 54 65 78 74 28  ><th>CastToText(
1260: 20 31 32 33 34 2c 20 32 20 29 3c 2f 74 68 3e 3c   1234, 2 )</th><
1270: 74 68 3e 43 61 73 74 54 6f 54 65 78 74 28 20 31  th>CastToText( 1
1280: 2c 20 38 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 61  , 8 )</th><th>Ca
1290: 73 74 54 6f 54 65 78 74 28 20 31 2e 35 2c 20 34  stToText( 1.5, 4
12a0: 20 29 3c 2f 74 68 3e 3c 2f 74 72 3e 0d 0a 3c 74   )</th></tr>..<t
12b0: 72 3e 3c 74 64 3e 30 30 30 31 3c 2f 74 64 3e 3c  r><td>0001</td><
12c0: 74 64 3e 31 32 33 34 3c 2f 74 64 3e 3c 74 64 3e  td>1234</td><td>
12d0: 30 30 30 30 30 30 30 31 3c 2f 74 64 3e 3c 74 64  00000001</td><td
12e0: 3e 30 30 30 31 2e 35 3c 2f 74 64 3e 3c 2f 74 72  >0001.5</td></tr
12f0: 3e 3c 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 41  ></table><br>..A
1300: 6e 20 6f 76 65 72 6c 6f 61 64 65 64 20 76 65 72  n overloaded ver
1310: 73 69 6f 6e 20 6f 66 20 3c 62 3e 43 61 73 74 54  sion of <b>CastT
1320: 6f 54 65 78 74 28 29 3c 2f 62 3e 20 69 73 20 73  oText()</b> is s
1330: 75 70 70 6f 72 74 65 64 20 61 73 20 77 65 6c 6c  upported as well
1340: 2c 20 62 75 74 20 6f 6e 6c 79 20 77 68 65 6e 20  , but only when 
1350: 74 68 65 20 69 6e 70 75 74 20 61 72 67 75 6d 65  the input argume
1360: 6e 74 20 69 73 20 6f 66 20 74 68 65 20 49 6e 74  nt is of the Int
1370: 65 67 65 72 20 6f 72 20 44 6f 75 62 6c 65 20 64  eger or Double d
1380: 61 74 61 2d 74 79 70 65 3a 20 69 6e 20 74 68 69  ata-type: in thi
1390: 73 20 63 61 73 65 20 61 20 73 65 63 6f 6e 64 20  s case a second 
13a0: 49 6e 74 65 67 65 72 20 61 72 67 75 6d 65 6e 74  Integer argument
13b0: 20 63 6f 75 6c 64 20 62 65 20 6f 70 74 69 6f 6e   could be option
13c0: 61 6c 6c 79 20 73 70 65 63 69 66 69 65 64 2c 20  ally specified, 
13d0: 61 6e 64 20 77 69 6c 6c 20 62 65 20 69 6e 74 65  and will be inte
13e0: 72 70 72 65 74 65 64 20 61 64 20 3c 62 3e 7a 65  rpreted ad <b>ze
13f0: 72 6f 2d 70 61 64 64 69 6e 67 2d 6c 65 6e 67 74  ro-padding-lengt
1400: 68 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a 69 2e 65 2e  h</b>.<br>..i.e.
1410: 20 74 68 65 20 72 65 74 75 72 6e 65 64 20 54 65   the returned Te
1420: 78 74 20 73 74 72 69 6e 67 20 69 6e 20 74 68 69  xt string in thi
1430: 73 20 63 61 73 65 20 77 69 6c 6c 20 68 61 76 65  s case will have
1440: 20 61 6e 20 69 6e 74 65 67 65 72 20 70 61 72 74   an integer part
1450: 20 61 74 20 6c 65 61 73 74 20 6f 66 20 74 68 65   at least of the
1460: 20 73 70 65 63 69 66 69 65 64 20 6c 65 6e 67 74   specified lengt
1470: 68 2c 20 61 6e 64 20 65 76 65 6e 74 75 61 6c 6c  h, and eventuall
1480: 79 20 70 61 64 64 65 64 20 62 79 20 69 6e 73 65  y padded by inse
1490: 72 74 69 6e 67 20 6e 6f 74 20 73 69 67 6e 69 66  rting not signif
14a0: 69 63 61 6e 74 20 6c 65 61 64 69 6e 67 20 5a 45  icant leading ZE
14b0: 52 4f 65 73 2e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d  ROes.<br>..<hr>.
14c0: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c  .<verbatim>..SEL
14d0: 45 43 54 20 43 61 73 74 54 6f 42 6c 6f 62 28 20  ECT CastToBlob( 
14e0: 31 20 29 2c 20 43 61 73 74 54 6f 42 6c 6f 62 28  1 ), CastToBlob(
14f0: 20 31 2e 35 20 29 2c 20 48 65 78 28 20 43 61 73   1.5 ), Hex( Cas
1500: 74 54 6f 42 6c 6f 62 28 20 27 61 6c 70 68 61 27  tToBlob( 'alpha'
1510: 20 29 20 29 2c 20 48 65 78 20 28 20 43 61 73 74   ) ), Hex ( Cast
1520: 54 6f 42 6c 6f 62 20 28 20 7a 65 72 6f 62 6c 6f  ToBlob ( zeroblo
1530: 62 28 34 29 20 29 20 29 3b 0d 0a 3c 2f 76 65 72  b(4) ) );..</ver
1540: 62 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c 65 20 62  batim>..<table b
1550: 6f 72 64 65 72 3d 22 31 22 20 63 65 6c 6c 73 70  order="1" cellsp
1560: 61 63 69 6e 67 3d 22 34 22 20 63 65 6c 6c 70 61  acing="4" cellpa
1570: 64 64 69 6e 67 3d 22 34 22 3e 0d 0a 3c 74 72 3e  dding="4">..<tr>
1580: 3c 74 68 3e 43 61 73 74 54 6f 42 6c 6f 62 28 20  <th>CastToBlob( 
1590: 31 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 61 73 74  1 )</th><th>Cast
15a0: 54 6f 42 6c 6f 62 28 20 31 2e 35 20 29 3c 2f 74  ToBlob( 1.5 )</t
15b0: 68 3e 3c 74 68 3e 48 65 78 28 20 43 61 73 74 54  h><th>Hex( CastT
15c0: 6f 42 6c 6f 62 28 20 27 61 6c 70 68 61 27 20 29  oBlob( 'alpha' )
15d0: 20 29 3c 2f 74 68 3e 3c 74 68 3e 48 65 78 28 20   )</th><th>Hex( 
15e0: 43 61 73 74 54 6f 54 65 78 74 20 28 20 7a 65 72  CastToText ( zer
15f0: 6f 62 6c 6f 62 28 34 29 20 29 20 29 3c 2f 74 68  oblob(4) ) )</th
1600: 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e  ></tr>..<tr><td>
1610: 4e 55 4c 4c 3c 2f 74 64 3e 3c 74 64 3e 4e 55 4c  NULL</td><td>NUL
1620: 4c 3c 2f 74 64 3e 3c 74 64 3e 36 31 36 43 37 30  L</td><td>616C70
1630: 36 38 36 31 3c 2f 74 64 3e 3c 74 64 3e 30 30 30  6861</td><td>000
1640: 30 30 30 30 30 3c 2f 74 64 3e 3c 2f 74 72 3e 3c  00000</td></tr><
1650: 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 54 68 65  /table><br>..The
1660: 20 3c 62 3e 43 61 73 74 54 6f 42 6c 6f 62 28 29   <b>CastToBlob()
1670: 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f  </b> SQL functio
1680: 6e 20 77 69 6c 6c 20 61 74 74 65 6d 70 74 20 74  n will attempt t
1690: 6f 20 72 65 74 75 72 6e 20 61 20 76 61 6c 75 65  o return a value
16a0: 20 6f 66 20 74 68 65 20 3c 62 3e 42 4c 4f 42 3c   of the <b>BLOB<
16b0: 2f 62 3e 20 64 61 74 61 2d 74 79 70 65 2c 20 6f  /b> data-type, o
16c0: 72 20 3c 62 3e 4e 55 4c 4c 3c 2f 62 3e 20 69 66  r <b>NULL</b> if
16d0: 20 6e 6f 20 63 6f 6e 76 65 72 73 69 6f 6e 20 69   no conversion i
16e0: 73 20 70 6f 73 73 69 62 6c 65 2e 0d 0a 3c 75 6c  s possible...<ul
16f0: 3e 0d 0a 3c 6c 69 3e 61 6e 20 49 6e 74 65 67 65  >..<li>an Intege
1700: 72 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74  r input argument
1710: 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 61 20 4e   will return a N
1720: 55 4c 4c 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d  ULL value.</li>.
1730: 0a 3c 6c 69 3e 61 20 44 6f 75 62 6c 65 20 69 6e  .<li>a Double in
1740: 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 6c  put argument wil
1750: 6c 20 72 65 74 75 72 6e 20 61 20 4e 55 4c 4c 20  l return a NULL 
1760: 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  value.</li>..<li
1770: 3e 61 20 54 65 78 74 20 69 6e 70 75 74 20 61 72  >a Text input ar
1780: 67 75 6d 65 6e 74 20 20 77 69 6c 6c 20 72 65 74  gument  will ret
1790: 75 72 6e 20 74 68 65 20 63 6f 72 72 65 73 70 6f  urn the correspo
17a0: 6e 64 69 6e 67 20 42 4c 4f 42 20 76 61 6c 75 65  nding BLOB value
17b0: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20  .</li>..<li>any 
17c0: 42 4c 4f 42 20 69 6e 70 75 74 20 61 72 67 75 6d  BLOB input argum
17d0: 65 6e 74 20 77 69 6c 6c 20 72 65 74 75 72 6e 20  ent will return 
17e0: 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e  the correspondin
17f0: 67 20 42 4c 4f 42 20 76 61 6c 75 65 2e 3c 2f 6c  g BLOB value.</l
1800: 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 4e 55 4c 4c  i>..<li>any NULL
1810: 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20   input argument 
1820: 77 69 6c 6c 20 72 65 74 75 72 6e 20 61 20 4e 55  will return a NU
1830: 4c 4c 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a  LL value.</li>..
1840: 3c 2f 75 6c 3e 0d 0a 3c 76 65 72 62 61 74 69 6d  </ul>..<verbatim
1850: 3e 0d 0a 53 45 4c 45 43 54 20 48 65 78 28 20 43  >..SELECT Hex( C
1860: 61 73 74 54 6f 42 6c 6f 62 28 20 27 30 31 32 33  astToBlob( '0123
1870: 34 35 36 37 38 39 61 42 63 44 65 46 66 45 64 43  456789aBcDeFfEdC
1880: 62 41 39 38 37 36 35 34 33 32 31 30 27 2c 20 31  bA9876543210', 1
1890: 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 30 31   ) );..-----..01
18a0: 32 33 34 35 36 37 38 39 41 42 43 44 45 46 46 45  23456789ABCDEFFE
18b0: 44 43 42 41 39 38 37 36 35 34 33 32 31 30 0d 0a  DCBA9876543210..
18c0: 0d 0a 53 45 4c 45 43 54 20 43 61 73 74 54 6f 42  ..SELECT CastToB
18d0: 6c 6f 62 28 20 27 31 32 66 27 2c 20 31 20 29 3b  lob( '12f', 1 );
18e0: 0d 0a 2d 2d 2d 2d 2d 0d 0a 4e 55 4c 4c 0d 0a 0d  ..-----..NULL...
18f0: 0a 53 45 4c 45 43 54 20 43 61 73 74 54 6f 42 6c  .SELECT CastToBl
1900: 6f 62 28 20 27 31 32 48 46 27 2c 20 31 20 29 3b  ob( '12HF', 1 );
1910: 0d 0a 2d 2d 2d 2d 2d 0d 0a 4e 55 4c 4c 0d 0a 3c  ..-----..NULL..<
1920: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 41 20 73 65  /verbatim>..A se
1930: 63 6f 6e 64 20 6f 76 65 72 6c 6f 61 64 65 64 20  cond overloaded 
1940: 76 65 72 73 69 6f 6e 20 6f 66 20 3c 62 3e 43 61  version of <b>Ca
1950: 73 74 54 6f 42 6c 6f 62 28 29 3c 2f 62 3e 20 69  stToBlob()</b> i
1960: 73 20 73 75 70 70 6f 72 74 65 64 20 61 73 20 77  s supported as w
1970: 65 6c 6c 3b 20 62 79 20 73 70 65 63 69 66 79 69  ell; by specifyi
1980: 6e 67 20 61 20 66 75 72 74 68 65 72 20 3c 62 3e  ng a further <b>
1990: 68 65 78 5f 69 6e 70 75 74 3c 2f 62 3e 20 3c 75  hex_input</b> <u
19a0: 3e 62 6f 6f 6c 65 61 6e 3c 2f 75 3e 20 61 72 67  >boolean</u> arg
19b0: 75 6d 65 6e 74 20 73 65 74 20 61 73 20 3c 62 3e  ument set as <b>
19c0: 54 52 55 45 3c 2f 62 3e 20 74 68 65 20 69 6e 70  TRUE</b> the inp
19d0: 75 74 20 73 74 72 69 6e 67 20 77 69 6c 6c 20 62  ut string will b
19e0: 65 20 61 73 73 75 6d 65 64 20 74 6f 20 62 65 20  e assumed to be 
19f0: 3c 75 3e 48 65 78 61 64 65 63 69 6d 61 6c 6c 79  <u>Hexadecimally
1a00: 20 65 6e 63 6f 64 65 64 3c 2f 75 3e 2e 20 49 6e   encoded</u>. In
1a10: 20 74 68 69 73 20 63 61 73 65 20 4e 55 4c 4c 20   this case NULL 
1a20: 77 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64  will be returned
1a30: 20 69 66 20 74 68 65 20 69 6e 70 75 74 20 73 74   if the input st
1a40: 72 69 6e 67 20 64 6f 65 73 6e 27 74 20 63 6f 72  ring doesn't cor
1a50: 72 65 73 70 6f 6e 64 73 20 74 6f 20 61 20 76 61  responds to a va
1a60: 6c 69 64 20 48 65 78 61 64 65 63 69 6d 61 6c 20  lid Hexadecimal 
1a70: 6e 6f 74 61 74 69 6f 6e 2e 0d 0a 3c 68 72 3e 0d  notation...<hr>.
1a80: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c  .<verbatim>..SEL
1a90: 45 43 54 20 46 6f 72 63 65 41 73 4e 75 6c 6c 28  ECT ForceAsNull(
1aa0: 20 27 61 27 2c 20 27 62 27 20 29 2c 20 46 6f 72   'a', 'b' ), For
1ab0: 63 65 41 73 4e 75 6c 6c 28 20 27 61 62 63 64 27  ceAsNull( 'abcd'
1ac0: 2c 20 27 61 62 63 64 27 20 29 2c 20 46 6f 72 63  , 'abcd' ), Forc
1ad0: 65 41 73 4e 75 6c 6c 28 20 31 2c 20 31 29 2c 20  eAsNull( 1, 1), 
1ae0: 46 6f 72 63 65 41 73 4e 75 6c 6c 28 20 31 2e 31  ForceAsNull( 1.1
1af0: 2c 20 31 20 29 3b 0d 0a 3c 2f 76 65 72 62 61 74  , 1 );..</verbat
1b00: 69 6d 3e 0d 0a 3c 74 61 62 6c 65 20 62 6f 72 64  im>..<table bord
1b10: 65 72 3d 22 31 22 20 63 65 6c 6c 73 70 61 63 69  er="1" cellspaci
1b20: 6e 67 3d 22 34 22 20 63 65 6c 6c 70 61 64 64 69  ng="4" cellpaddi
1b30: 6e 67 3d 22 34 22 3e 0d 0a 3c 74 72 3e 3c 74 68  ng="4">..<tr><th
1b40: 3e 46 6f 72 63 65 41 73 4e 75 6c 6c 28 20 27 61  >ForceAsNull( 'a
1b50: 27 2c 20 27 62 27 20 29 3c 2f 74 68 3e 3c 74 68  ', 'b' )</th><th
1b60: 3e 46 6f 72 63 65 41 73 4e 75 6c 6c 28 20 27 61  >ForceAsNull( 'a
1b70: 62 63 64 27 2c 20 27 61 62 63 64 27 20 29 3c 2f  bcd', 'abcd' )</
1b80: 74 68 3e 3c 74 68 3e 46 6f 72 63 65 41 73 4e 75  th><th>ForceAsNu
1b90: 6c 6c 28 20 31 2c 20 31 29 3c 2f 74 68 3e 3c 74  ll( 1, 1)</th><t
1ba0: 68 3e 46 6f 72 63 65 41 73 4e 75 6c 6c 28 20 31  h>ForceAsNull( 1
1bb0: 2e 31 2c 20 2d 39 39 39 39 20 29 3c 2f 74 68 3e  .1, -9999 )</th>
1bc0: 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 61  </tr>..<tr><td>a
1bd0: 3c 2f 74 64 3e 3c 74 64 3e 4e 55 4c 4c 3c 2f 74  </td><td>NULL</t
1be0: 64 3e 3c 74 64 3e 4e 55 4c 4c 3c 2f 74 64 3e 3c  d><td>NULL</td><
1bf0: 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22  td align="right"
1c00: 3e 31 2e 31 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f  >1.1</td></tr></
1c10: 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 54 68 65 20  table><br>..The 
1c20: 3c 62 3e 46 6f 72 63 65 41 73 4e 75 6c 6c 28 29  <b>ForceAsNull()
1c30: 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f  </b> SQL functio
1c40: 6e 20 77 69 6c 6c 20 65 76 61 6c 75 61 74 65 20  n will evaluate 
1c50: 74 77 6f 20 61 72 62 69 74 72 61 72 79 20 61 72  two arbitrary ar
1c60: 67 75 6d 65 6e 74 73 2e 3c 62 72 3e 0d 0a 49 66  guments.<br>..If
1c70: 20 74 68 65 79 20 61 72 65 20 65 71 75 61 6c 20   they are equal 
1c80: 61 6e 64 20 65 78 61 63 74 6c 79 20 6f 66 20 74  and exactly of t
1c90: 68 65 20 73 61 6d 65 20 64 61 74 61 2d 74 79 70  he same data-typ
1ca0: 65 20 4e 55 4c 4c 20 77 69 6c 6c 20 62 65 20 72  e NULL will be r
1cb0: 65 74 75 72 6e 65 64 3b 20 6f 74 68 65 72 77 69  eturned; otherwi
1cc0: 73 65 20 74 68 65 20 66 69 72 73 74 20 61 72 67  se the first arg
1cd0: 75 6d 65 6e 74 20 76 61 6c 75 65 20 77 69 6c 6c  ument value will
1ce0: 20 62 65 20 72 65 74 75 72 6e 65 64 2e 3c 62 72   be returned.<br
1cf0: 3e 0d 0a 55 73 65 66 75 6c 20 65 2e 67 2e 20 77  >..Useful e.g. w
1d00: 68 69 6c 65 20 70 72 6f 63 65 73 73 69 6e 67 20  hile processing 
1d10: 64 61 74 61 20 69 6d 70 6f 72 74 65 64 20 66 72  data imported fr
1d20: 6f 6d 20 61 6e 79 20 3c 62 3e 53 68 61 70 65 66  om any <b>Shapef
1d30: 69 6c 65 3c 2f 62 3e 20 6f 72 20 3c 62 3e 44 42  ile</b> or <b>DB
1d40: 46 20 66 69 6c 65 3c 2f 62 3e 20 28 73 75 63 68  F file</b> (such
1d50: 20 66 6f 72 6d 61 74 73 20 64 6f 65 73 6e 27 74   formats doesn't
1d60: 20 73 75 70 70 6f 72 74 20 61 6e 79 20 72 65 61   support any rea
1d70: 6c 20 4e 55 4c 4c 20 76 61 6c 75 65 2c 20 6f 66  l NULL value, of
1d80: 74 65 6e 20 62 65 69 6e 67 20 72 65 70 6c 61 63  ten being replac
1d90: 65 64 20 62 79 20 73 6f 6d 65 20 63 6f 6e 76 65  ed by some conve
1da0: 6e 74 69 6f 6e 61 6c 20 76 61 6c 75 65 20 65 2e  ntional value e.
1db0: 67 2e 20 3c 62 3e 30 3c 2f 62 3e 20 6f 72 20 3c  g. <b>0</b> or <
1dc0: 62 3e 2d 39 39 39 39 3c 2f 62 3e 20 61 6e 64 20  b>-9999</b> and 
1dd0: 61 6c 69 6b 65 29 2e 0d 0a 3c 68 72 3e 0d 0a 3c  alike)...<hr>..<
1de0: 68 33 3e 47 65 6e 65 72 69 63 20 53 51 4c 20 66  h3>Generic SQL f
1df0: 75 6e 63 74 69 6f 6e 20 2d 20 55 55 49 44 20 67  unction - UUID g
1e00: 65 6e 65 72 61 74 6f 72 3c 2f 68 33 3e 0d 0a 41  enerator</h3>..A
1e10: 6e 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 3a  n <a href="http:
1e20: 2f 2f 65 6e 2e 77 69 6b 69 70 65 64 69 61 2e 6f  //en.wikipedia.o
1e30: 72 67 2f 77 69 6b 69 2f 55 6e 69 76 65 72 73 61  rg/wiki/Universa
1e40: 6c 6c 79 5f 75 6e 69 71 75 65 5f 69 64 65 6e 74  lly_unique_ident
1e50: 69 66 69 65 72 22 3e 55 6e 69 76 65 72 73 61 6c  ifier">Universal
1e60: 6c 79 20 75 6e 69 71 75 65 20 69 64 65 6e 74 69  ly unique identi
1e70: 66 69 65 72 3c 2f 61 3e 20 28 61 6b 61 20 3c 62  fier</a> (aka <b
1e80: 3e 55 55 49 44 3c 2f 62 3e 29 20 73 69 6d 70 6c  >UUID</b>) simpl
1e90: 79 20 69 73 20 61 20 3c 75 3e 31 32 38 20 62 69  y is a <u>128 bi
1ea0: 74 3c 2f 75 3e 20 49 6e 74 65 67 65 72 3b 20 61  t</u> Integer; a
1eb0: 63 63 6f 72 64 69 6e 67 6c 79 20 74 6f 20 3c 61  ccordingly to <a
1ec0: 20 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f 65 6e   href="http://en
1ed0: 2e 77 69 6b 69 70 65 64 69 61 2e 6f 72 67 2f 77  .wikipedia.org/w
1ee0: 69 6b 69 2f 55 55 49 44 23 52 61 6e 64 6f 6d 5f  iki/UUID#Random_
1ef0: 55 55 49 44 5f 70 72 6f 62 61 62 69 6c 69 74 79  UUID_probability
1f00: 5f 6f 66 5f 64 75 70 6c 69 63 61 74 65 73 22 3e  _of_duplicates">
1f10: 74 68 65 6f 72 79 3c 2f 61 3e 2c 20 74 68 65 20  theory</a>, the 
1f20: 70 72 6f 62 61 62 69 6c 69 74 79 20 74 68 61 74  probability that
1f30: 20 74 77 6f 20 72 61 6e 64 6f 6d 6c 79 20 67 65   two randomly ge
1f40: 6e 65 72 61 74 65 64 20 55 55 49 44 73 20 63 6f  nerated UUIDs co
1f50: 75 6c 64 20 61 73 73 75 6d 65 20 74 68 65 20 73  uld assume the s
1f60: 61 6d 65 20 76 61 6c 75 65 20 69 73 20 6e 65 61  ame value is nea
1f70: 72 20 74 6f 20 7a 65 72 6f 20 66 6f 72 20 6d 61  r to zero for ma
1f80: 6e 79 20 70 72 61 63 74 69 63 61 6c 20 70 75 72  ny practical pur
1f90: 70 6f 73 65 73 2e 20 41 6e 64 20 63 6f 6e 73 65  poses. And conse
1fa0: 71 75 65 6e 74 6c 79 20 55 55 49 44 73 20 61 72  quently UUIDs ar
1fb0: 65 20 77 69 64 65 6c 79 20 75 73 65 64 20 61 73  e widely used as
1fc0: 20 3c 75 3e 75 6e 69 76 65 72 73 61 6c 6c 79 20   <u>universally 
1fd0: 75 6e 69 71 75 65 20 49 44 73 3c 2f 75 3e 2e 3c  unique IDs</u>.<
1fe0: 62 72 3e 0d 0a 55 73 75 61 6c 6c 79 20 55 55 49  br>..Usually UUI
1ff0: 44 73 20 61 72 65 20 72 65 70 72 65 73 65 6e 74  Ds are represent
2000: 65 64 20 69 6e 20 74 68 65 69 72 20 3c 75 3e 63  ed in their <u>c
2010: 61 6e 6f 6e 69 63 61 6c 20 66 6f 72 6d 3c 2f 75  anonical form</u
2020: 3e 2c 20 69 2e 65 2e 20 61 73 20 61 20 73 65 71  >, i.e. as a seq
2030: 75 65 6e 63 65 20 6f 66 20 33 32 20 68 65 78 61  uence of 32 hexa
2040: 64 65 63 69 6d 61 6c 20 64 69 67 69 74 73 20 73  decimal digits s
2050: 65 70 61 72 61 74 65 64 20 69 6e 74 6f 20 66 69  eparated into fi
2060: 76 65 20 64 69 73 74 69 6e 63 74 20 62 6c 6f 63  ve distinct bloc
2070: 6b 2c 20 61 63 63 6f 72 64 69 6e 67 6c 79 20 74  k, accordingly t
2080: 6f 20 61 20 3c 62 3e 38 2d 34 2d 34 2d 34 2d 31  o a <b>8-4-4-4-1
2090: 32 3c 2f 62 3e 20 73 63 68 65 6d 61 2e 0d 0a 3c  2</b> schema...<
20a0: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43  verbatim>..SELEC
20b0: 54 20 43 72 65 61 74 65 55 55 49 44 28 29 3b 0d  T CreateUUID();.
20c0: 0a 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 66 66 66 35 66  .--------..fff5f
20d0: 61 66 31 2d 64 63 63 30 2d 34 33 39 31 2d 38 30  af1-dcc0-4391-80
20e0: 35 34 2d 36 65 37 64 65 37 35 64 38 35 62 31 0d  54-6e7de75d85b1.
20f0: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68  .</verbatim>..Th
2100: 65 20 3c 62 3e 43 72 65 61 74 65 55 55 49 44 28  e <b>CreateUUID(
2110: 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69  )</b> SQL functi
2120: 6f 6e 20 69 73 20 62 75 69 6c 74 20 6f 6e 20 74  on is built on t
2130: 68 65 20 74 6f 70 20 74 68 65 20 3c 69 3e 48 69  he top the <i>Hi
2140: 67 68 20 51 75 61 6c 69 74 79 20 50 73 65 75 64  gh Quality Pseud
2150: 6f 2d 52 61 6e 64 6f 6d 20 4e 75 6d 62 65 72 20  o-Random Number 
2160: 47 65 6e 65 72 61 74 6f 72 3c 2f 69 3e 20 3c 61  Generator</i> <a
2170: 20 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f 77 77   href="http://ww
2180: 77 2e 73 71 6c 69 74 65 2e 6f 72 67 2f 63 33 72  w.sqlite.org/c3r
2190: 65 66 2f 72 61 6e 64 6f 6d 6e 65 73 73 2e 68 74  ef/randomness.ht
21a0: 6d 6c 22 3e 69 6e 74 65 72 6e 61 6c 6c 79 20 69  ml">internally i
21b0: 6d 70 6c 65 6d 65 6e 74 65 64 3c 2f 61 3e 20 62  mplemented</a> b
21c0: 79 20 53 51 4c 69 74 65 2e 3c 62 72 3e 0d 0a 54  y SQLite.<br>..T
21d0: 68 65 20 72 65 74 75 72 6e 65 64 20 55 55 49 44  he returned UUID
21e0: 20 69 73 20 63 6f 6e 66 6f 72 6d 61 6e 74 20 74   is conformant t
21f0: 6f 20 3c 75 3e 56 65 72 73 69 6f 6e 20 34 20 28  o <u>Version 4 (
2200: 72 61 6e 64 6f 6d 29 3c 2f 75 3e 20 28 69 2e 65  random)</u> (i.e
2210: 2e 20 74 68 65 20 66 69 72 73 74 20 64 69 67 69  . the first digi
2220: 74 20 69 6e 74 6f 20 74 68 65 20 74 68 69 72 64  t into the third
2230: 20 62 6c 6f 63 6b 20 77 69 6c 6c 20 61 6c 77 61   block will alwa
2240: 79 73 20 62 65 20 3c 62 3e 34 3c 2f 62 3e 20 61  ys be <b>4</b> a
2250: 6e 64 20 74 68 65 20 66 69 72 73 74 20 64 69 67  nd the first dig
2260: 69 74 20 69 6e 74 6f 20 74 68 65 20 66 6f 75 72  it into the four
2270: 74 68 20 62 6c 6f 63 6b 20 77 69 6c 6c 20 61 6c  th block will al
2280: 77 61 79 73 20 62 65 20 3c 62 3e 38 3c 2f 62 3e  ways be <b>8</b>
2290: 29 2e 0d 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 53 70  )...<hr>..<h3>Sp
22a0: 61 74 69 61 6c 20 53 51 4c 20 66 75 6e 63 74 69  atial SQL functi
22b0: 6f 6e 73 3c 2f 68 33 3e 0d 0a 46 65 77 20 6d 6f  ons</h3>..Few mo
22c0: 72 65 20 53 70 61 74 69 61 6c 20 53 51 4c 20 66  re Spatial SQL f
22d0: 75 6e 63 74 69 6f 6e 73 20 61 72 65 20 6e 6f 77  unctions are now
22e0: 20 73 75 70 70 6f 72 74 65 64 2e 0d 0a 3c 76 65   supported...<ve
22f0: 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20  rbatim>..SELECT 
2300: 53 54 5f 41 73 54 65 78 74 28 20 53 54 5f 41 64  ST_AsText( ST_Ad
2310: 64 50 6f 69 6e 74 28 20 0d 0a 20 20 53 54 5f 47  dPoint( ..  ST_G
2320: 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27 4c 49  eomFromText( 'LI
2330: 4e 45 53 54 52 49 4e 47 28 20 30 20 30 2c 20 31  NESTRING( 0 0, 1
2340: 20 30 20 29 27 20 29 2c 20 0d 0a 20 20 53 54 5f   0 )' ), ..  ST_
2350: 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27 50  GeomFromText( 'P
2360: 4f 49 4e 54 28 20 31 20 31 20 29 27 20 29 20 29  OINT( 1 1 )' ) )
2370: 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c   );..--------..L
2380: 49 4e 45 53 54 52 49 4e 47 28 30 20 30 2c 20 31  INESTRING(0 0, 1
2390: 20 30 2c 20 31 20 31 29 0d 0a 3c 2f 76 65 72 62   0, 1 1)..</verb
23a0: 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 53 54  atim>..The <b>ST
23b0: 5f 41 64 64 50 6f 69 6e 74 28 29 3c 2f 62 3e 20  _AddPoint()</b> 
23c0: 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 61 64 64  SQL function add
23d0: 73 20 61 20 66 75 72 74 68 65 72 20 50 6f 69 6e  s a further Poin
23e0: 74 2f 56 65 72 74 65 78 20 61 74 20 74 68 65 20  t/Vertex at the 
23f0: 65 6e 64 20 6f 66 20 61 20 4c 69 6e 65 73 74 72  end of a Linestr
2400: 69 6e 67 3b 20 74 68 65 20 66 69 72 73 74 20 61  ing; the first a
2410: 72 67 75 6d 65 6e 74 20 69 73 20 61 6c 77 61 79  rgument is alway
2420: 73 20 65 78 70 65 63 74 65 64 20 74 6f 20 62 65  s expected to be
2430: 20 6f 66 20 74 68 65 20 4c 69 6e 65 73 74 72 69   of the Linestri
2440: 6e 67 20 74 79 70 65 2c 20 74 68 65 20 73 65 63  ng type, the sec
2450: 6f 6e 64 20 6f 6e 65 20 6d 75 73 74 20 62 65 20  ond one must be 
2460: 61 20 50 6f 69 6e 74 2e 0d 0a 3c 76 65 72 62 61  a Point...<verba
2470: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 54 5f  tim>..SELECT ST_
2480: 41 73 54 65 78 74 28 20 53 54 5f 41 64 64 50 6f  AsText( ST_AddPo
2490: 69 6e 74 28 20 0d 0a 20 20 53 54 5f 47 65 6f 6d  int( ..  ST_Geom
24a0: 46 72 6f 6d 54 65 78 74 28 20 27 4c 49 4e 45 53  FromText( 'LINES
24b0: 54 52 49 4e 47 28 20 31 20 30 2c 20 31 20 31 20  TRING( 1 0, 1 1 
24c0: 29 27 20 29 2c 20 0d 0a 20 20 53 54 5f 47 65 6f  )' ), ..  ST_Geo
24d0: 6d 46 72 6f 6d 54 65 78 74 28 20 27 50 4f 49 4e  mFromText( 'POIN
24e0: 54 28 20 30 20 30 20 29 27 20 29 2c 20 30 20 29  T( 0 0 )' ), 0 )
24f0: 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a   );..---------..
2500: 4c 49 4e 45 53 54 52 49 4e 47 28 30 20 30 2c 20  LINESTRING(0 0, 
2510: 31 20 30 2c 20 31 20 31 29 0d 0a 3c 2f 76 65 72  1 0, 1 1)..</ver
2520: 62 61 74 69 6d 3e 0d 0a 49 66 20 61 6e 20 6f 70  batim>..If an op
2530: 74 69 6f 6e 61 6c 20 74 68 69 72 64 20 61 72 67  tional third arg
2540: 75 6d 65 6e 74 20 28 6f 66 20 74 68 65 20 49 6e  ument (of the In
2550: 74 65 67 65 72 20 74 79 70 65 29 20 69 73 20 70  teger type) is p
2560: 61 73 73 65 64 20 74 6f 20 3c 62 3e 53 54 5f 41  assed to <b>ST_A
2570: 64 64 50 6f 69 6e 74 28 29 3c 2f 62 3e 20 69 74  ddPoint()</b> it
2580: 27 73 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 73  's intended to s
2590: 70 65 63 69 66 79 20 74 68 65 20 3c 75 3e 69 6e  pecify the <u>in
25a0: 64 65 78 3c 2f 75 3e 20 6f 66 20 74 68 65 20 6e  dex</u> of the n
25b0: 65 77 20 56 65 72 74 65 78 20 28 66 69 72 73 74  ew Vertex (first
25c0: 20 56 65 72 74 65 78 20 68 61 73 20 69 6e 64 65   Vertex has inde
25d0: 78 20 30 2c 20 73 65 63 6f 6e 64 20 56 65 72 74  x 0, second Vert
25e0: 65 78 20 68 61 73 20 69 6e 64 65 78 20 31 20 61  ex has index 1 a
25f0: 6e 64 20 73 6f 20 6f 6e 29 2e 3c 62 72 3e 0d 0a  nd so on).<br>..
2600: 52 65 66 65 72 65 6e 63 69 6e 67 20 61 20 6e 6f  Referencing a no
2610: 74 20 65 78 69 73 74 69 6e 67 20 69 6e 64 65 78  t existing index
2620: 20 69 73 20 61 6e 20 65 72 72 6f 72 2c 20 61 6e   is an error, an
2630: 64 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 4e 55  d will return NU
2640: 4c 4c 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d  LL...<verbatim>.
2650: 0a 53 45 4c 45 43 54 20 53 54 5f 41 73 54 65 78  .SELECT ST_AsTex
2660: 74 28 20 53 54 5f 41 64 64 50 6f 69 6e 74 28 20  t( ST_AddPoint( 
2670: 0d 0a 20 20 53 54 5f 47 65 6f 6d 46 72 6f 6d 54  ..  ST_GeomFromT
2680: 65 78 74 28 20 27 4c 49 4e 45 53 54 52 49 4e 47  ext( 'LINESTRING
2690: 28 20 30 20 30 2c 20 31 20 30 20 29 27 20 29 2c  ( 0 0, 1 0 )' ),
26a0: 20 0d 0a 20 20 53 54 5f 47 65 6f 6d 46 72 6f 6d   ..  ST_GeomFrom
26b0: 54 65 78 74 28 20 27 50 4f 49 4e 54 28 20 31 20  Text( 'POINT( 1 
26c0: 31 20 29 27 20 29 2c 20 2d 31 20 29 20 29 3b 0d  1 )' ), -1 ) );.
26d0: 0a 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45 53  .--------..LINES
26e0: 54 52 49 4e 47 28 30 20 30 2c 20 31 20 30 2c 20  TRING(0 0, 1 0, 
26f0: 31 20 31 29 0d 0a 3c 2f 76 65 72 62 61 74 69 6d  1 1)..</verbatim
2700: 3e 0d 0a 50 61 73 73 69 6e 67 20 61 20 6e 65 67  >..Passing a neg
2710: 61 74 69 76 65 20 69 6e 64 65 78 20 69 73 20 61  ative index is a
2720: 20 73 75 70 70 6f 72 74 65 64 20 6f 70 74 69 6f   supported optio
2730: 6e 2c 20 61 6e 64 20 73 69 6d 70 6c 79 20 63 6f  n, and simply co
2740: 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 74 68 65  rresponds to the
2750: 20 64 65 66 61 75 6c 74 20 62 65 68 61 76 69 6f   default behavio
2760: 75 72 20 28 69 2e 65 2e 20 3c 69 3e 61 70 70 65  ur (i.e. <i>appe
2770: 6e 64 69 6e 67 20 74 68 65 20 50 6f 69 6e 74 20  nding the Point 
2780: 74 6f 20 74 68 65 20 65 6e 64 20 6f 66 20 74 68  to the end of th
2790: 65 20 4c 69 6e 65 73 74 72 69 6e 67 3c 2f 69 3e  e Linestring</i>
27a0: 29 2e 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61  )...<hr>..<verba
27b0: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 54 5f  tim>..SELECT ST_
27c0: 41 73 54 65 78 74 28 20 53 54 5f 53 65 74 50 6f  AsText( ST_SetPo
27d0: 69 6e 74 28 20 0d 0a 20 20 53 54 5f 47 65 6f 6d  int( ..  ST_Geom
27e0: 46 72 6f 6d 54 65 78 74 28 20 27 4c 49 4e 45 53  FromText( 'LINES
27f0: 54 52 49 4e 47 28 20 30 20 30 2c 20 31 20 30 2c  TRING( 0 0, 1 0,
2800: 20 31 20 31 20 29 27 20 29 2c 20 0d 0a 20 20 31   1 1 )' ), ..  1
2810: 2c 20 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78  , ST_GeomFromTex
2820: 74 28 20 27 50 4f 49 4e 54 28 20 32 20 31 20 29  t( 'POINT( 2 1 )
2830: 27 20 29 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d  ' ) ) );..------
2840: 2d 2d 2d 0d 0a 4c 49 4e 45 53 54 52 49 4e 47 28  ---..LINESTRING(
2850: 30 20 30 2c 20 32 20 31 2c 20 31 20 31 29 0d 0a  0 0, 2 1, 1 1)..
2860: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65  </verbatim>..The
2870: 20 3c 62 3e 53 54 5f 53 65 74 50 6f 69 6e 74 28   <b>ST_SetPoint(
2880: 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69  )</b> SQL functi
2890: 6f 6e 20 63 61 6e 20 72 65 70 6c 61 63 65 20 61  on can replace a
28a0: 20 50 6f 69 6e 74 2f 56 65 72 74 65 78 20 66 72   Point/Vertex fr
28b0: 6f 6d 20 77 69 74 68 69 6e 20 61 20 4c 69 6e 65  om within a Line
28c0: 73 74 72 69 6e 67 3b 20 74 68 65 20 66 69 72 73  string; the firs
28d0: 74 20 61 72 67 75 6d 65 6e 74 20 69 73 20 61 6c  t argument is al
28e0: 77 61 79 73 20 65 78 70 65 63 74 65 64 20 74 6f  ways expected to
28f0: 20 62 65 20 6f 66 20 74 68 65 20 4c 69 6e 65 73   be of the Lines
2900: 74 72 69 6e 67 20 74 79 70 65 2c 20 74 68 65 20  tring type, the 
2910: 73 65 63 6f 6e 64 20 69 73 20 61 6e 20 49 6e 74  second is an Int
2920: 65 67 65 72 20 73 70 65 63 69 66 79 69 6e 67 20  eger specifying 
2930: 74 68 65 20 3c 75 3e 69 6e 64 65 78 3c 2f 75 3e  the <u>index</u>
2940: 20 6f 66 20 74 68 65 20 61 66 66 65 63 74 65 64   of the affected
2950: 20 56 65 72 74 65 78 20 61 6e 64 20 74 68 65 20   Vertex and the 
2960: 74 68 69 72 64 20 6f 6e 65 20 6d 75 73 74 20 62  third one must b
2970: 65 20 61 20 50 6f 69 6e 74 2e 3c 62 72 3e 0d 0a  e a Point.<br>..
2980: 52 65 66 65 72 65 6e 63 69 6e 67 20 61 20 6e 6f  Referencing a no
2990: 74 20 65 78 69 73 74 69 6e 67 20 69 6e 64 65 78  t existing index
29a0: 20 69 73 20 61 6e 20 65 72 72 6f 72 2c 20 61 6e   is an error, an
29b0: 64 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 4e 55  d will return NU
29c0: 4c 4c 2e 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62  LL...<hr>..<verb
29d0: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 54  atim>..SELECT ST
29e0: 5f 41 73 54 65 78 74 28 20 53 54 5f 52 65 6d 6f  _AsText( ST_Remo
29f0: 76 65 50 6f 69 6e 74 28 20 0d 0a 20 20 53 54 5f  vePoint( ..  ST_
2a00: 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27 4c  GeomFromText( 'L
2a10: 49 4e 45 53 54 52 49 4e 47 28 20 30 20 30 2c 20  INESTRING( 0 0, 
2a20: 31 20 30 2c 20 31 20 31 20 29 27 20 29 2c 20 31  1 0, 1 1 )' ), 1
2a30: 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d   ) );..---------
2a40: 0d 0a 4c 49 4e 45 53 54 52 49 4e 47 28 30 20 30  ..LINESTRING(0 0
2a50: 2c 20 31 20 31 29 0d 0a 3c 2f 76 65 72 62 61 74  , 1 1)..</verbat
2a60: 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 53 54 5f 52  im>..The <b>ST_R
2a70: 65 6d 6f 76 65 50 6f 69 6e 74 28 29 3c 2f 62 3e  emovePoint()</b>
2a80: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 63 61   SQL function ca
2a90: 6e 20 72 65 6d 6f 76 65 20 61 20 50 6f 69 6e 74  n remove a Point
2aa0: 2f 56 65 72 74 65 78 20 66 72 6f 6d 20 77 69 74  /Vertex from wit
2ab0: 68 69 6e 20 61 20 4c 69 6e 65 73 74 72 69 6e 67  hin a Linestring
2ac0: 3b 20 74 68 65 20 66 69 72 73 74 20 61 72 67 75  ; the first argu
2ad0: 6d 65 6e 74 20 69 73 20 61 6c 77 61 79 73 20 65  ment is always e
2ae0: 78 70 65 63 74 65 64 20 74 6f 20 62 65 20 6f 66  xpected to be of
2af0: 20 74 68 65 20 4c 69 6e 65 73 74 72 69 6e 67 20   the Linestring 
2b00: 74 79 70 65 2c 20 74 68 65 20 73 65 63 6f 6e 64  type, the second
2b10: 20 69 73 20 61 6e 20 49 6e 74 65 67 65 72 20 73   is an Integer s
2b20: 70 65 63 69 66 79 69 6e 67 20 74 68 65 20 3c 75  pecifying the <u
2b30: 3e 69 6e 64 65 78 3c 2f 75 3e 20 6f 66 20 74 68  >index</u> of th
2b40: 65 20 61 66 66 65 63 74 65 64 20 56 65 72 74 65  e affected Verte
2b50: 78 2e 3c 62 72 3e 0d 0a 52 65 66 65 72 65 6e 63  x.<br>..Referenc
2b60: 69 6e 67 20 61 20 6e 6f 74 20 65 78 69 73 74 69  ing a not existi
2b70: 6e 67 20 69 6e 64 65 78 20 69 73 20 61 6e 20 65  ng index is an e
2b80: 72 72 6f 72 2c 20 61 6e 64 20 77 69 6c 6c 20 72  rror, and will r
2b90: 65 74 75 72 6e 20 4e 55 4c 4c 2e 0d 0a 3c 68 72  eturn NULL...<hr
2ba0: 3e 0d 0a 3c 68 33 3e 55 6e 73 61 66 65 20 28 62  >..<h3>Unsafe (b
2bb0: 75 74 20 75 73 65 66 75 6c 29 20 49 6d 70 6f 72  ut useful) Impor
2bc0: 74 2f 45 78 70 6f 72 74 20 53 51 4c 20 66 75 6e  t/Export SQL fun
2bd0: 63 74 69 6f 6e 73 3c 2f 68 33 3e 0d 0a 41 6c 6c  ctions</h3>..All
2be0: 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 53   the following S
2bf0: 51 4c 20 66 75 6e 63 74 69 6f 6e 73 20 63 6f 75  QL functions cou
2c00: 6c 64 20 62 65 20 72 65 61 6c 6c 79 20 75 73 65  ld be really use
2c10: 66 75 6c 20 69 6e 20 6f 72 64 65 72 20 74 6f 20  ful in order to 
2c20: 73 75 70 70 6f 72 74 20 49 6d 70 6f 72 74 2f 45  support Import/E
2c30: 78 70 6f 72 74 20 6f 70 65 72 61 74 69 6f 6e 73  xport operations
2c40: 2e 3c 62 72 3e 0d 0a 41 6e 79 77 61 79 20 79 6f  .<br>..Anyway yo
2c50: 75 20 73 68 6f 75 6c 64 20 62 65 20 3c 75 3e 77  u should be <u>w
2c60: 65 6c 6c 20 61 77 61 72 65 3c 2f 75 3e 20 74 68  ell aware</u> th
2c70: 61 74 20 61 6c 6c 20 74 68 65 6d 20 63 6f 75 6c  at all them coul
2c80: 64 20 62 65 20 70 6f 74 65 6e 74 69 61 6c 6c 79  d be potentially
2c90: 20 3c 75 3e 75 6e 73 61 66 65 3c 2f 75 3e 20 61   <u>unsafe</u> a
2ca0: 6e 64 20 63 6f 75 6c 64 20 62 65 20 70 6f 74 65  nd could be pote
2cb0: 6e 74 69 61 6c 6c 79 20 75 73 65 64 20 62 79 20  ntially used by 
2cc0: 73 6f 6d 65 20 3c 75 3e 6d 61 6c 69 63 69 6f 75  some <u>maliciou
2cd0: 73 20 68 61 63 6b 65 72 3c 2f 75 3e 20 69 6e 20  s hacker</u> in 
2ce0: 6f 72 64 65 72 20 74 6f 20 63 72 65 61 74 65 20  order to create 
2cf0: 61 6e 64 20 65 78 70 6c 6f 69 74 20 73 6f 6d 65  and exploit some
2d00: 20 3c 75 3e 73 65 63 75 72 69 74 79 20 62 72 65   <u>security bre
2d10: 61 63 68 3c 2f 75 3e 2e 3c 62 72 3e 0d 0a 54 68  ach</u>.<br>..Th
2d20: 65 20 63 61 75 73 65 20 69 73 20 76 65 72 79 20  e cause is very 
2d30: 65 61 73 79 20 74 6f 20 62 65 20 75 6e 64 65 72  easy to be under
2d40: 73 74 6f 6f 64 3a 20 74 68 65 73 65 20 66 75 6e  stood: these fun
2d50: 63 74 69 6f 6e 73 20 61 6c 6c 6f 77 20 74 6f 20  ctions allow to 
2d60: 74 72 61 6e 73 66 65 72 20 61 72 62 69 74 72 61  transfer arbitra
2d70: 72 79 20 70 61 79 6c 6f 61 64 73 20 66 72 6f 6d  ry payloads from
2d80: 20 2f 20 74 6f 20 74 68 65 20 44 61 74 61 62 61   / to the Databa
2d90: 73 65 20 61 6e 64 20 74 68 65 20 6c 6f 63 61 6c  se and the local
2da0: 20 46 69 6c 65 2d 53 79 73 74 65 6d 2e 0d 0a 41   File-System...A
2db0: 20 6d 61 6c 69 63 69 6f 75 73 20 61 74 74 61 63   malicious attac
2dc0: 6b 20 63 6f 75 6c 64 20 62 65 20 74 68 75 73 20  k could be thus 
2dd0: 69 6d 70 6c 65 6d 65 6e 74 65 64 20 65 2e 67 2e  implemented e.g.
2de0: 20 62 79 20 65 78 65 63 75 74 69 6e 67 20 73 6f   by executing so
2df0: 6d 65 20 53 51 4c 20 73 63 72 69 70 74 20 6f 72  me SQL script or
2e00: 20 62 79 20 64 65 66 69 6e 69 6e 67 20 61 20 70   by defining a p
2e10: 75 72 70 6f 73 65 6c 79 20 66 6f 72 67 65 64 20  urposely forged 
2e20: 54 72 69 67 67 65 72 2c 20 61 6e 64 20 74 68 65  Trigger, and the
2e30: 20 65 6e 64 20 75 73 65 72 73 20 77 6f 75 6c 64   end users would
2e40: 20 62 65 20 61 62 73 6f 6c 75 74 65 6c 79 20 75   be absolutely u
2e50: 6e 61 77 61 72 65 20 6f 66 20 77 68 61 74 20 69  naware of what i
2e60: 73 20 72 65 61 6c 6c 79 20 68 61 70 70 65 6e 69  s really happeni
2e70: 6e 67 2e 0d 0a 53 6f 20 69 6e 20 6f 72 64 65 72  ng...So in order
2e80: 20 74 6f 20 65 66 66 65 63 74 69 76 65 6c 79 20   to effectively 
2e90: 73 68 69 65 6c 64 20 75 73 65 72 73 20 61 67 61  shield users aga
2ea0: 69 6e 73 74 20 74 68 65 73 65 20 70 6f 74 65 6e  inst these poten
2eb0: 74 69 61 6c 6c 79 20 64 61 6e 67 65 72 6f 75 73  tially dangerous
2ec0: 20 73 65 63 75 72 69 74 79 20 70 69 74 66 61 6c   security pitfal
2ed0: 6c 73 20 61 6c 6c 20 74 68 65 73 65 20 53 51 4c  ls all these SQL
2ee0: 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 65 20 61   functions are a
2ef0: 6c 77 61 79 73 20 3c 75 3e 64 69 73 61 62 6c 65  lways <u>disable
2f00: 64 20 62 79 20 64 65 66 61 75 6c 74 3c 2f 75 3e  d by default</u>
2f10: 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 65  ...<verbatim>..e
2f20: 78 70 6f 72 74 20 22 53 50 41 54 49 41 4c 49 54  xport "SPATIALIT
2f30: 45 5f 53 45 43 55 52 49 54 59 3d 72 65 6c 61 78  E_SECURITY=relax
2f40: 65 64 22 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e  ed"..</verbatim>
2f50: 0d 0a 49 6e 20 6f 72 64 65 72 20 74 6f 20 72 65  ..In order to re
2f60: 61 6c 6c 79 20 65 6e 61 62 6c 65 20 74 68 65 73  ally enable thes
2f70: 65 20 66 75 6e 63 74 69 6f 6e 73 20 74 68 65 20  e functions the 
2f80: 75 73 65 72 20 69 73 20 72 65 71 75 69 72 65 64  user is required
2f90: 20 74 6f 20 74 61 6b 65 20 61 6e 20 65 78 70 6c   to take an expl
2fa0: 69 63 69 74 20 61 63 74 69 6f 6e 3b 20 69 2e 65  icit action; i.e
2fb0: 2e 20 74 68 65 20 3c 75 3e 65 6e 76 69 72 6f 6e  . the <u>environ
2fc0: 6d 65 6e 74 20 76 61 72 69 61 62 6c 65 3c 2f 75  ment variable</u
2fd0: 3e 20 3c 62 3e 53 50 41 54 49 41 4c 49 54 45 5f  > <b>SPATIALITE_
2fe0: 53 45 43 55 52 49 54 59 3d 72 65 6c 61 78 65 64  SECURITY=relaxed
2ff0: 3c 2f 62 3e 20 68 61 73 20 74 6f 20 62 65 20 64  </b> has to be d
3000: 65 66 69 6e 65 64 2e 0d 0a 3c 76 65 72 62 61 74  efined...<verbat
3010: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 43 6f 75 6e  im>..SELECT Coun
3020: 74 55 6e 73 61 66 65 54 72 69 67 67 65 72 73 28  tUnsafeTriggers(
3030: 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 30  );..---------..0
3040: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54  ..</verbatim>..T
3050: 68 65 20 3c 62 3e 43 6f 75 6e 74 55 6e 73 61 66  he <b>CountUnsaf
3060: 65 54 72 69 67 67 65 72 73 28 29 3c 2f 62 3e 20  eTriggers()</b> 
3070: 61 63 74 75 61 6c 6c 79 20 63 68 65 63 6b 73 20  actually checks 
3080: 69 66 20 74 68 65 20 63 6f 6e 6e 65 63 74 65 64  if the connected
3090: 20 44 61 74 61 62 61 73 65 20 64 6f 65 73 20 63   Database does c
30a0: 6f 6e 74 61 69 6e 73 20 61 6e 79 20 73 75 73 70  ontains any susp
30b0: 65 63 74 20 54 72 69 67 67 65 72 3b 20 63 68 65  ect Trigger; che
30c0: 63 6b 69 6e 67 20 74 68 69 73 20 76 65 72 73 69  cking this versi
30d0: 6f 6e 20 62 65 66 6f 72 65 20 65 6e 61 62 6c 69  on before enabli
30e0: 6e 67 20 74 68 65 20 75 6e 73 61 66 65 20 53 51  ng the unsafe SQ
30f0: 4c 20 46 75 6e 63 74 69 6f 6e 73 20 69 73 20 61  L Functions is a
3100: 6c 77 61 79 73 20 68 69 67 68 6c 79 20 72 65 63  lways highly rec
3110: 6f 6d 6d 65 6e 64 65 64 2e 3c 62 72 3e 0d 0a 41  ommended.<br>..A
3120: 20 72 65 73 75 6c 74 20 64 69 66 66 65 72 65 6e   result differen
3130: 74 20 66 72 6f 6d 20 5a 45 52 4f 20 69 6d 70 6c  t from ZERO impl
3140: 69 65 73 20 74 68 61 74 20 73 6f 6d 65 20 6d 61  ies that some ma
3150: 6c 69 63 69 6f 75 73 20 54 72 69 67 67 65 72 20  licious Trigger 
3160: 68 61 73 20 62 65 65 6e 20 69 64 65 6e 74 69 66  has been identif
3170: 69 65 64 3b 20 69 6e 20 74 68 69 73 20 63 61 73  ied; in this cas
3180: 65 20 79 6f 75 20 63 61 6e 20 70 65 72 66 6f 72  e you can perfor
3190: 6d 20 61 20 64 65 65 70 65 73 74 20 69 6e 73 70  m a deepest insp
31a0: 65 63 74 69 6f 6e 20 62 79 20 65 78 65 63 75 74  ection by execut
31b0: 69 6e 67 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e  ing the followin
31c0: 67 20 53 51 4c 20 71 75 65 72 79 3a 0d 0a 3c 76  g SQL query:..<v
31d0: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54  erbatim>..SELECT
31e0: 20 74 79 70 65 2c 20 6e 61 6d 65 2c 20 74 62 6c   type, name, tbl
31f0: 5f 6e 61 6d 65 2c 20 73 71 6c 20 0d 0a 46 52 4f  _name, sql ..FRO
3200: 4d 20 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 20  M sqlite_master 
3210: 0d 0a 57 48 45 52 45 20 74 79 70 65 20 49 4e 20  ..WHERE type IN 
3220: 28 27 74 72 69 67 67 65 72 27 2c 20 27 76 69 65  ('trigger', 'vie
3230: 77 27 29 20 41 4e 44 20 28 73 71 6c 20 4c 49 4b  w') AND (sql LIK
3240: 45 20 27 25 42 6c 6f 62 46 72 6f 6d 46 69 6c 65  E '%BlobFromFile
3250: 25 27 20 0d 0a 20 20 20 4f 52 20 73 71 6c 20 4c  %' ..   OR sql L
3260: 49 4b 45 20 27 25 42 6c 6f 62 54 6f 46 69 6c 65  IKE '%BlobToFile
3270: 25 27 20 4f 52 20 73 71 6c 20 4c 49 4b 45 20 27  %' OR sql LIKE '
3280: 25 58 42 5f 4c 6f 61 64 58 4d 4c 25 27 20 0d 0a  %XB_LoadXML%' ..
3290: 20 20 20 4f 52 20 73 71 6c 20 4c 49 4b 45 20 27     OR sql LIKE '
32a0: 25 58 42 5f 53 74 6f 72 65 58 4d 4c 25 27 29 3b  %XB_StoreXML%');
32b0: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 74  ..</verbatim>..t
32c0: 68 69 73 20 77 69 6c 6c 20 67 69 76 65 20 61 20  his will give a 
32d0: 66 75 6c 6c 20 72 65 70 6f 72 74 20 66 6f 72 20  full report for 
32e0: 61 6e 79 20 6d 61 6c 69 63 69 6f 75 73 20 54 72  any malicious Tr
32f0: 69 67 67 65 72 20 65 76 65 6e 74 75 61 6c 6c 79  igger eventually
3300: 20 66 6f 75 6e 64 2e 0d 0a 3c 68 72 3e 0d 0a 3c   found...<hr>..<
3310: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43  verbatim>..SELEC
3320: 54 20 42 6c 6f 62 46 72 6f 6d 46 69 6c 65 28 20  T BlobFromFile( 
3330: 27 43 3a 2f 6d 79 70 69 63 74 75 72 65 73 2f 73  'C:/mypictures/s
3340: 75 6e 73 65 74 2e 6a 70 67 27 20 29 3b 0d 0a 2d  unset.jpg' );..-
3350: 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 42 4c 4f 42 2d 76  --------..BLOB-v
3360: 61 6c 75 65 0d 0a 3c 2f 76 65 72 62 61 74 69 6d  alue..</verbatim
3370: 3e 0d 0a 54 68 65 20 3c 62 3e 42 6c 6f 62 46 72  >..The <b>BlobFr
3380: 6f 6d 46 69 6c 65 28 29 3c 2f 62 3e 20 53 51 4c  omFile()</b> SQL
3390: 20 66 75 6e 63 74 69 6f 6e 20 61 6c 6c 6f 77 73   function allows
33a0: 20 74 6f 20 69 6d 70 6f 72 74 20 61 20 77 68 6f   to import a who
33b0: 6c 65 20 66 69 6c 65 20 69 6e 20 61 20 73 69 6e  le file in a sin
33c0: 67 6c 65 20 73 74 65 70 3b 20 74 68 65 20 66 75  gle step; the fu
33d0: 6c 6c 20 66 69 6c 65 20 70 61 79 6c 6f 61 64 20  ll file payload 
33e0: 77 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64  will be returned
33f0: 20 61 73 20 61 20 42 4c 4f 42 20 76 61 6c 75 65   as a BLOB value
3400: 2e 3c 62 72 3e 0d 0a 49 66 20 74 68 65 20 61 72  .<br>..If the ar
3410: 67 75 6d 65 6e 74 20 28 3c 62 3e 66 69 6c 65 2d  gument (<b>file-
3420: 70 61 74 68 3c 2f 62 3e 29 20 64 6f 65 73 6e 27  path</b>) doesn'
3430: 74 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f  t corresponds to
3440: 20 61 20 76 61 6c 69 64 20 66 69 6c 65 20 6f 72   a valid file or
3450: 20 69 66 20 74 68 65 20 65 78 74 65 72 6e 61 6c   if the external
3460: 20 66 69 6c 65 20 63 61 6e 6e 6f 74 20 62 65 20   file cannot be 
3470: 61 63 63 65 73 73 65 64 20 66 6f 72 20 61 6e 79  accessed for any
3480: 20 72 65 61 73 6f 6e 20 4e 55 4c 4c 20 77 69 6c   reason NULL wil
3490: 6c 20 62 65 20 72 65 74 75 72 6e 65 64 2e 20 0d  l be returned. .
34a0: 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d  .<hr>..<verbatim
34b0: 3e 0d 0a 53 45 4c 45 43 54 20 42 6c 6f 62 54 6f  >..SELECT BlobTo
34c0: 46 69 6c 65 28 20 73 6f 6d 65 42 6c 6f 62 20 2c  File( someBlob ,
34d0: 20 27 43 3a 2f 6d 79 70 69 63 74 75 72 65 73 2f   'C:/mypictures/
34e0: 73 75 6e 73 65 74 2e 6a 70 67 27 20 29 3b 0d 0a  sunset.jpg' );..
34f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f  ---------..1..</
3500: 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c  verbatim>..The <
3510: 62 3e 42 6c 6f 62 54 6f 46 69 6c 65 28 29 3c 2f  b>BlobToFile()</
3520: 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20  b> SQL function 
3530: 70 65 72 66 6f 72 6d 73 20 74 68 65 20 6f 70 70  performs the opp
3540: 6f 73 69 74 65 20 74 61 73 6b 2c 20 69 2e 65 2e  osite task, i.e.
3550: 20 69 74 20 65 78 70 6f 72 74 73 20 61 20 77 68   it exports a wh
3560: 6f 6c 65 20 42 4c 4f 42 20 69 6e 74 6f 20 61 6e  ole BLOB into an
3570: 20 65 78 74 65 72 6e 61 6c 20 66 69 6c 65 3b 20   external file; 
3580: 74 68 65 20 66 69 72 73 74 20 61 72 67 75 6d 65  the first argume
3590: 6e 74 20 6d 75 73 74 20 63 6f 72 72 65 73 70 6f  nt must correspo
35a0: 6e 64 20 74 6f 20 73 6f 6d 65 20 42 4c 4f 42 2c  nd to some BLOB,
35b0: 20 74 68 65 20 73 65 63 6f 6e 64 20 6f 6e 65 20   the second one 
35c0: 69 73 20 74 68 65 20 3c 62 3e 66 69 6c 65 2d 70  is the <b>file-p
35d0: 61 74 68 3c 2f 62 3e 20 69 64 65 6e 74 69 66 79  ath</b> identify
35e0: 69 6e 67 20 74 68 65 20 66 69 6c 65 20 74 6f 20  ing the file to 
35f0: 62 65 20 63 72 65 61 74 65 64 20 6f 72 20 6f 76  be created or ov
3600: 65 72 77 72 69 74 74 65 6e 2e 3c 62 72 3e 3c 62  erwritten.<br><b
3610: 72 3e 0d 0a 3c 75 3e 50 6c 65 61 73 65 20 6e 6f  r>..<u>Please no
3620: 74 65 3c 2f 75 3e 3a 20 62 6f 74 68 20 3c 62 3e  te</u>: both <b>
3630: 42 6c 6f 62 46 72 6f 6d 46 69 6c 65 28 29 3c 2f  BlobFromFile()</
3640: 62 3e 20 61 6e 64 20 3c 62 3e 42 6c 6f 62 54 6f  b> and <b>BlobTo
3650: 46 69 6c 65 28 29 3c 2f 62 3e 20 77 65 72 65 20  File()</b> were 
3660: 61 6c 72 65 61 64 79 20 73 75 70 70 6f 72 74 65  already supporte
3670: 64 20 62 79 20 34 2e 30 2e 30 2c 20 62 75 74 20  d by 4.0.0, but 
3680: 61 20 71 75 69 63 6b 20 72 65 63 61 6c 6c 20 69  a quick recall i
3690: 73 20 61 6e 79 77 61 79 20 75 73 65 66 75 6c 20  s anyway useful 
36a0: 73 6f 20 74 6f 20 72 65 63 61 6c 6c 20 61 20 63  so to recall a c
36b0: 6c 65 61 72 65 72 20 63 6f 6e 74 65 78 74 2e 0d  learer context..
36c0: 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d  .<hr>..<verbatim
36d0: 3e 0d 0a 53 45 4c 45 43 54 20 58 42 5f 4c 6f 61  >..SELECT XB_Loa
36e0: 64 58 4d 4c 28 20 27 43 3a 2f 6d 79 64 6f 63 73  dXML( 'C:/mydocs
36f0: 2f 69 73 6f 6d 65 74 61 64 61 74 61 2d 73 61 6d  /isometadata-sam
3700: 70 6c 65 2e 78 6d 6c 27 20 29 3b 0d 0a 2d 2d 2d  ple.xml' );..---
3710: 2d 2d 2d 2d 2d 0d 0a 42 4c 4f 42 2d 76 61 6c 75  -----..BLOB-valu
3720: 65 0d 0a 0d 0a 53 45 4c 45 43 54 20 58 42 5f 4c  e....SELECT XB_L
3730: 6f 61 64 58 4d 4c 28 20 27 68 74 74 70 3a 2f 2f  oadXML( 'http://
3740: 77 77 77 2e 61 63 6d 65 2e 63 6f 6d 2f 70 75 62  www.acme.com/pub
3750: 6c 69 63 2f 69 73 6f 6d 65 74 61 64 61 74 61 2d  lic/isometadata-
3760: 73 61 6d 70 6c 65 2e 78 6d 6c 27 20 29 3b 0d 0a  sample.xml' );..
3770: 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 42 4c 4f 42 2d 76  --------..BLOB-v
3780: 61 6c 75 65 0d 0a 3c 2f 76 65 72 62 61 74 69 6d  alue..</verbatim
3790: 3e 0d 0a 54 68 65 20 3c 62 3e 58 42 5f 4c 6f 61  >..The <b>XB_Loa
37a0: 64 58 4d 4c 28 29 3c 2f 62 3e 20 53 51 4c 20 66  dXML()</b> SQL f
37b0: 75 6e 63 74 69 6f 6e 20 61 6c 6c 6f 77 73 20 74  unction allows t
37c0: 6f 20 69 6d 70 6f 72 74 20 61 6e 20 58 4d 4c 20  o import an XML 
37d0: 44 6f 63 75 6d 65 6e 74 20 69 6e 20 61 20 73 69  Document in a si
37e0: 6e 67 6c 65 20 73 74 65 70 3a 20 74 68 65 20 66  ngle step: the f
37f0: 75 6c 6c 20 58 4d 4c 20 44 6f 63 75 6d 65 6e 74  ull XML Document
3800: 20 70 61 79 6c 6f 61 64 20 77 69 6c 6c 20 62 65   payload will be
3810: 20 72 65 74 75 72 6e 65 64 20 61 73 20 61 20 42   returned as a B
3820: 4c 4f 42 20 76 61 6c 75 65 2e 3c 62 72 3e 0d 0a  LOB value.<br>..
3830: 54 68 65 20 70 61 73 73 65 64 20 61 72 67 75 6d  The passed argum
3840: 65 6e 74 20 63 61 6e 20 69 6e 64 69 66 66 65 72  ent can indiffer
3850: 65 6e 74 6c 79 20 62 65 20 61 20 3c 62 3e 66 69  ently be a <b>fi
3860: 6c 65 2d 70 61 74 68 3c 2f 62 3e 20 6f 72 20 61  le-path</b> or a
3870: 20 3c 62 3e 55 52 4c 3c 2f 62 3e 3b 20 69 66 20   <b>URL</b>; if 
3880: 74 68 65 20 64 61 74 61 73 6f 75 72 63 65 20 63  the datasource c
3890: 61 6e 6e 6f 74 20 62 65 20 61 63 63 65 73 73 65  annot be accesse
38a0: 64 2c 20 6f 72 20 69 66 20 69 74 20 64 6f 65 73  d, or if it does
38b0: 6e 27 74 20 63 6f 6e 74 61 69 6e 73 20 61 20 3c  n't contains a <
38c0: 75 3e 77 65 6c 6c 2d 66 6f 72 6d 65 64 3c 2f 75  u>well-formed</u
38d0: 3e 20 58 4d 4c 20 44 6f 63 75 6d 65 6e 74 20 4e  > XML Document N
38e0: 55 4c 4c 20 77 69 6c 6c 20 62 65 20 72 65 74 75  ULL will be retu
38f0: 72 6e 65 64 2e 0d 0a 3c 68 72 3e 0d 0a 3c 76 65  rned...<hr>..<ve
3900: 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20  rbatim>..SELECT 
3910: 58 42 5f 53 74 6f 72 65 58 4d 4c 28 20 73 6f 6d  XB_StoreXML( som
3920: 65 58 6d 6c 42 6c 6f 62 2c 20 27 43 3a 2f 6d 79  eXmlBlob, 'C:/my
3930: 64 6f 63 73 2f 69 73 6f 6d 65 74 61 64 61 74 61  docs/isometadata
3940: 2d 73 61 6d 70 6c 65 2e 78 6d 6c 27 20 29 3b 0d  -sample.xml' );.
3950: 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c  .---------..1..<
3960: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20  /verbatim>..The 
3970: 3c 62 3e 58 42 5f 53 74 6f 72 65 58 4d 4c 28 29  <b>XB_StoreXML()
3980: 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f  </b> SQL functio
3990: 6e 20 70 65 72 66 6f 72 6d 73 20 74 68 65 20 6f  n performs the o
39a0: 70 70 6f 73 69 74 65 20 74 61 73 6b 2c 20 69 2e  pposite task, i.
39b0: 65 2e 20 69 74 20 65 78 70 6f 72 74 73 20 61 20  e. it exports a 
39c0: 77 68 6f 6c 65 20 58 6d 6c 42 4c 4f 42 20 69 6e  whole XmlBLOB in
39d0: 74 6f 20 61 6e 20 65 78 74 65 72 6e 61 6c 20 66  to an external f
39e0: 69 6c 65 20 61 73 20 61 6e 20 58 4d 4c 20 44 6f  ile as an XML Do
39f0: 63 75 6d 65 6e 74 3b 20 74 68 65 20 66 69 72 73  cument; the firs
3a00: 74 20 61 72 67 75 6d 65 6e 74 20 6d 75 73 74 20  t argument must 
3a10: 63 6f 72 72 65 73 70 6f 6e 64 20 74 6f 20 73 6f  correspond to so
3a20: 6d 65 20 76 61 6c 69 64 20 58 6d 6c 42 4c 4f 42  me valid XmlBLOB
3a30: 2c 20 74 68 65 20 73 65 63 6f 6e 64 20 6f 6e 65  , the second one
3a40: 20 69 73 20 74 68 65 20 3c 62 3e 66 69 6c 65 2d   is the <b>file-
3a50: 70 61 74 68 3c 2f 62 3e 20 69 64 65 6e 74 69 66  path</b> identif
3a60: 79 69 6e 67 20 74 68 65 20 66 69 6c 65 20 74 6f  ying the file to
3a70: 20 62 65 20 63 72 65 61 74 65 64 20 6f 72 20 6f   be created or o
3a80: 76 65 72 77 72 69 74 74 65 6e 2e 20 0d 0a 3c 76  verwritten. ..<v
3a90: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54  erbatim>..SELECT
3aa0: 20 58 42 5f 53 74 6f 72 65 58 4d 4c 28 20 73 6f   XB_StoreXML( so
3ab0: 6d 65 58 6d 6c 42 6c 6f 62 2c 20 27 43 3a 2f 6d  meXmlBlob, 'C:/m
3ac0: 79 64 6f 63 73 2f 69 73 6f 6d 65 74 61 64 61 74  ydocs/isometadat
3ad0: 61 2d 73 61 6d 70 6c 65 2e 78 6d 6c 27 2c 20 34  a-sample.xml', 4
3ae0: 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a   );..---------..
3af0: 31 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a  1..</verbatim>..
3b00: 41 20 66 75 72 74 68 65 72 20 6f 70 74 69 6f 6e  A further option
3b10: 61 6c 20 3c 62 3e 69 6e 64 65 6e 74 61 74 69 6f  al <b>indentatio
3b20: 6e 3c 2f 62 3e 20 61 72 67 75 6d 65 6e 74 20 63  n</b> argument c
3b30: 61 6e 20 62 65 20 65 76 65 6e 74 75 61 6c 6c 79  an be eventually
3b40: 20 73 70 65 63 69 66 69 65 64 3b 20 74 68 69 73   specified; this
3b50: 20 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 62   argument will b
3b60: 65 20 68 61 6e 64 6c 65 64 20 65 78 61 63 74 6c  e handled exactl
3b70: 79 20 69 6e 20 74 68 65 20 73 61 6d 65 20 77 61  y in the same wa
3b80: 79 20 61 6c 72 65 61 64 79 20 73 70 65 63 69 66  y already specif
3b90: 69 65 64 20 66 6f 72 20 62 6f 74 68 20 3c 62 3e  ied for both <b>
3ba0: 58 42 5f 47 65 74 50 61 79 6c 6f 61 64 28 29 3c  XB_GetPayload()<
3bb0: 2f 62 3e 20 61 6e 64 20 3c 62 3e 58 42 5f 47 65  /b> and <b>XB_Ge
3bc0: 74 44 6f 63 75 6d 65 6e 74 28 29 3c 2f 62 3e 20  tDocument()</b> 
3bd0: 66 75 6e 63 74 69 6f 6e 73 2e 20 0d 0a 3c 68 72  functions. ..<hr
3be0: 3e 3c 62 72 3e 0d 0a 62 61 63 6b 20 74 6f 20 58  ><br>..back to X
3bf0: 6d 6c 42 6c 6f 62 20 3c 61 20 68 72 65 66 3d 22  mlBlob <a href="
3c00: 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67 61 69 61  https://www.gaia
3c10: 2d 67 69 73 2e 69 74 2f 66 6f 73 73 69 6c 2f 6c  -gis.it/fossil/l
3c20: 69 62 73 70 61 74 69 61 6c 69 74 65 2f 77 69 6b  ibspatialite/wik
3c30: 69 3f 6e 61 6d 65 3d 58 6d 6c 42 6c 6f 62 2b 61  i?name=XmlBlob+a
3c40: 6e 64 2b 56 69 72 74 75 61 6c 58 50 61 74 68 22  nd+VirtualXPath"
3c50: 3e 6d 61 69 6e 20 70 61 67 65 3c 2f 61 3e 0a 5a  >main page</a>.Z
3c60: 20 36 61 63 33 35 63 63 64 36 63 62 39 63 39 35   6ac35ccd6cb9c95
3c70: 63 30 30 30 30 31 38 66 31 30 33 34 34 62 34 34  c000018f10344b44
3c80: 62 0a                                            b.