Hex Artifact Content
Not logged in

Artifact 6dd4ef50cb2e811039bdcb004ca15fea71612e8b:

Wiki page [4.1.0 Changes] by sandro 2013-03-06 10:40:09.
0000: 44 20 32 30 31 33 2d 30 33 2d 30 36 54 31 30 3a  D 2013-03-06T10:
0010: 34 30 3a 30 39 2e 33 38 39 0a 4c 20 34 2e 31 2e  40:09.389.L 4.1.
0020: 30 5c 73 43 68 61 6e 67 65 73 0a 50 20 36 63 30  0\sChanges.P 6c0
0030: 37 62 65 63 35 62 34 65 65 37 34 37 38 35 63 62  7bec5b4ee74785cb
0040: 38 30 31 61 33 66 39 32 64 62 39 30 64 39 64 62  801a3f92db90d9db
0050: 33 65 35 62 33 0a 55 20 73 61 6e 64 72 6f 0a 57  3e5b3.U sandro.W
0060: 20 31 34 37 37 30 0a 62 61 63 6b 20 74 6f 20 58   14770.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 68 72 3e 0d 0a 3c 76 65  </ul>..<hr>..<ve
1850: 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20  rbatim>..SELECT 
1860: 46 6f 72 63 65 41 73 4e 75 6c 6c 28 20 27 61 27  ForceAsNull( 'a'
1870: 2c 20 27 62 27 20 29 2c 20 46 6f 72 63 65 41 73  , 'b' ), ForceAs
1880: 4e 75 6c 6c 28 20 27 61 62 63 64 27 2c 20 27 61  Null( 'abcd', 'a
1890: 62 63 64 27 20 29 2c 20 46 6f 72 63 65 41 73 4e  bcd' ), ForceAsN
18a0: 75 6c 6c 28 20 31 2c 20 31 29 2c 20 46 6f 72 63  ull( 1, 1), Forc
18b0: 65 41 73 4e 75 6c 6c 28 20 31 2e 31 2c 20 31 20  eAsNull( 1.1, 1 
18c0: 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d  );..</verbatim>.
18d0: 0a 3c 74 61 62 6c 65 20 62 6f 72 64 65 72 3d 22  .<table border="
18e0: 31 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22  1" cellspacing="
18f0: 34 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22  4" cellpadding="
1900: 34 22 3e 0d 0a 3c 74 72 3e 3c 74 68 3e 46 6f 72  4">..<tr><th>For
1910: 63 65 41 73 4e 75 6c 6c 28 20 27 61 27 2c 20 27  ceAsNull( 'a', '
1920: 62 27 20 29 3c 2f 74 68 3e 3c 74 68 3e 46 6f 72  b' )</th><th>For
1930: 63 65 41 73 4e 75 6c 6c 28 20 27 61 62 63 64 27  ceAsNull( 'abcd'
1940: 2c 20 27 61 62 63 64 27 20 29 3c 2f 74 68 3e 3c  , 'abcd' )</th><
1950: 74 68 3e 46 6f 72 63 65 41 73 4e 75 6c 6c 28 20  th>ForceAsNull( 
1960: 31 2c 20 31 29 3c 2f 74 68 3e 3c 74 68 3e 46 6f  1, 1)</th><th>Fo
1970: 72 63 65 41 73 4e 75 6c 6c 28 20 31 2e 31 2c 20  rceAsNull( 1.1, 
1980: 2d 39 39 39 39 20 29 3c 2f 74 68 3e 3c 2f 74 72  -9999 )</th></tr
1990: 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 61 3c 2f 74 64  >..<tr><td>a</td
19a0: 3e 3c 74 64 3e 4e 55 4c 4c 3c 2f 74 64 3e 3c 74  ><td>NULL</td><t
19b0: 64 3e 4e 55 4c 4c 3c 2f 74 64 3e 3c 74 64 20 61  d>NULL</td><td a
19c0: 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 31 2e 31  lign="right">1.1
19d0: 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c  </td></tr></tabl
19e0: 65 3e 3c 62 72 3e 0d 0a 54 68 65 20 3c 62 3e 46  e><br>..The <b>F
19f0: 6f 72 63 65 41 73 4e 75 6c 6c 28 29 3c 2f 62 3e  orceAsNull()</b>
1a00: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 77 69   SQL function wi
1a10: 6c 6c 20 65 76 61 6c 75 61 74 65 20 74 77 6f 20  ll evaluate two 
1a20: 61 72 62 69 74 72 61 72 79 20 61 72 67 75 6d 65  arbitrary argume
1a30: 6e 74 73 2e 3c 62 72 3e 0d 0a 49 66 20 74 68 65  nts.<br>..If the
1a40: 79 20 61 72 65 20 65 71 75 61 6c 20 61 6e 64 20  y are equal and 
1a50: 65 78 61 63 74 6c 79 20 6f 66 20 74 68 65 20 73  exactly of the s
1a60: 61 6d 65 20 64 61 74 61 2d 74 79 70 65 20 4e 55  ame data-type NU
1a70: 4c 4c 20 77 69 6c 6c 20 62 65 20 72 65 74 75 72  LL will be retur
1a80: 6e 65 64 3b 20 6f 74 68 65 72 77 69 73 65 20 74  ned; otherwise t
1a90: 68 65 20 66 69 72 73 74 20 61 72 67 75 6d 65 6e  he first argumen
1aa0: 74 20 76 61 6c 75 65 20 77 69 6c 6c 20 62 65 20  t value will be 
1ab0: 72 65 74 75 72 6e 65 64 2e 3c 62 72 3e 0d 0a 55  returned.<br>..U
1ac0: 73 65 66 75 6c 20 65 2e 67 2e 20 77 68 69 6c 65  seful e.g. while
1ad0: 20 70 72 6f 63 65 73 73 69 6e 67 20 64 61 74 61   processing data
1ae0: 20 69 6d 70 6f 72 74 65 64 20 66 72 6f 6d 20 61   imported from a
1af0: 6e 79 20 3c 62 3e 53 68 61 70 65 66 69 6c 65 3c  ny <b>Shapefile<
1b00: 2f 62 3e 20 6f 72 20 3c 62 3e 44 42 46 20 66 69  /b> or <b>DBF fi
1b10: 6c 65 3c 2f 62 3e 20 28 73 75 63 68 20 66 6f 72  le</b> (such for
1b20: 6d 61 74 73 20 64 6f 65 73 6e 27 74 20 73 75 70  mats doesn't sup
1b30: 70 6f 72 74 20 61 6e 79 20 72 65 61 6c 20 4e 55  port any real NU
1b40: 4c 4c 20 76 61 6c 75 65 2c 20 6f 66 74 65 6e 20  LL value, often 
1b50: 62 65 69 6e 67 20 72 65 70 6c 61 63 65 64 20 62  being replaced b
1b60: 79 20 73 6f 6d 65 20 63 6f 6e 76 65 6e 74 69 6f  y some conventio
1b70: 6e 61 6c 20 76 61 6c 75 65 20 65 2e 67 2e 20 3c  nal value e.g. <
1b80: 62 3e 30 3c 2f 62 3e 20 6f 72 20 3c 62 3e 2d 39  b>0</b> or <b>-9
1b90: 39 39 39 3c 2f 62 3e 20 61 6e 64 20 61 6c 69 6b  999</b> and alik
1ba0: 65 29 2e 0d 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 47  e)...<hr>..<h3>G
1bb0: 65 6e 65 72 69 63 20 53 51 4c 20 66 75 6e 63 74  eneric SQL funct
1bc0: 69 6f 6e 20 2d 20 55 55 49 44 20 67 65 6e 65 72  ion - UUID gener
1bd0: 61 74 6f 72 3c 2f 68 33 3e 0d 0a 41 6e 20 3c 61  ator</h3>..An <a
1be0: 20 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f 65 6e   href="http://en
1bf0: 2e 77 69 6b 69 70 65 64 69 61 2e 6f 72 67 2f 77  .wikipedia.org/w
1c00: 69 6b 69 2f 55 6e 69 76 65 72 73 61 6c 6c 79 5f  iki/Universally_
1c10: 75 6e 69 71 75 65 5f 69 64 65 6e 74 69 66 69 65  unique_identifie
1c20: 72 22 3e 55 6e 69 76 65 72 73 61 6c 6c 79 20 75  r">Universally u
1c30: 6e 69 71 75 65 20 69 64 65 6e 74 69 66 69 65 72  nique identifier
1c40: 3c 2f 61 3e 20 28 61 6b 61 20 3c 62 3e 55 55 49  </a> (aka <b>UUI
1c50: 44 3c 2f 62 3e 29 20 73 69 6d 70 6c 79 20 69 73  D</b>) simply is
1c60: 20 61 20 3c 75 3e 31 32 38 20 62 69 74 3c 2f 75   a <u>128 bit</u
1c70: 3e 20 49 6e 74 65 67 65 72 3b 20 61 63 63 6f 72  > Integer; accor
1c80: 64 69 6e 67 6c 79 20 74 6f 20 3c 61 20 68 72 65  dingly to <a hre
1c90: 66 3d 22 68 74 74 70 3a 2f 2f 65 6e 2e 77 69 6b  f="http://en.wik
1ca0: 69 70 65 64 69 61 2e 6f 72 67 2f 77 69 6b 69 2f  ipedia.org/wiki/
1cb0: 55 55 49 44 23 52 61 6e 64 6f 6d 5f 55 55 49 44  UUID#Random_UUID
1cc0: 5f 70 72 6f 62 61 62 69 6c 69 74 79 5f 6f 66 5f  _probability_of_
1cd0: 64 75 70 6c 69 63 61 74 65 73 22 3e 74 68 65 6f  duplicates">theo
1ce0: 72 79 3c 2f 61 3e 2c 20 74 68 65 20 70 72 6f 62  ry</a>, the prob
1cf0: 61 62 69 6c 69 74 79 20 74 68 61 74 20 74 77 6f  ability that two
1d00: 20 72 61 6e 64 6f 6d 6c 79 20 67 65 6e 65 72 61   randomly genera
1d10: 74 65 64 20 55 55 49 44 73 20 63 6f 75 6c 64 20  ted UUIDs could 
1d20: 61 73 73 75 6d 65 20 74 68 65 20 73 61 6d 65 20  assume the same 
1d30: 76 61 6c 75 65 20 69 73 20 6e 65 61 72 20 74 6f  value is near to
1d40: 20 7a 65 72 6f 20 66 6f 72 20 6d 61 6e 79 20 70   zero for many p
1d50: 72 61 63 74 69 63 61 6c 20 70 75 72 70 6f 73 65  ractical purpose
1d60: 73 2e 20 41 6e 64 20 63 6f 6e 73 65 71 75 65 6e  s. And consequen
1d70: 74 6c 79 20 55 55 49 44 73 20 61 72 65 20 77 69  tly UUIDs are wi
1d80: 64 65 6c 79 20 75 73 65 64 20 61 73 20 3c 75 3e  dely used as <u>
1d90: 75 6e 69 76 65 72 73 61 6c 6c 79 20 75 6e 69 71  universally uniq
1da0: 75 65 20 49 44 73 3c 2f 75 3e 2e 3c 62 72 3e 0d  ue IDs</u>.<br>.
1db0: 0a 55 73 75 61 6c 6c 79 20 55 55 49 44 73 20 61  .Usually UUIDs a
1dc0: 72 65 20 72 65 70 72 65 73 65 6e 74 65 64 20 69  re represented i
1dd0: 6e 20 74 68 65 69 72 20 3c 75 3e 63 61 6e 6f 6e  n their <u>canon
1de0: 69 63 61 6c 20 66 6f 72 6d 3c 2f 75 3e 2c 20 69  ical form</u>, i
1df0: 2e 65 2e 20 61 73 20 61 20 73 65 71 75 65 6e 63  .e. as a sequenc
1e00: 65 20 6f 66 20 33 32 20 68 65 78 61 64 65 63 69  e of 32 hexadeci
1e10: 6d 61 6c 20 64 69 67 69 74 73 20 73 65 70 61 72  mal digits separ
1e20: 61 74 65 64 20 69 6e 74 6f 20 66 69 76 65 20 64  ated into five d
1e30: 69 73 74 69 6e 63 74 20 62 6c 6f 63 6b 2c 20 61  istinct block, a
1e40: 63 63 6f 72 64 69 6e 67 6c 79 20 74 6f 20 61 20  ccordingly to a 
1e50: 3c 62 3e 38 2d 34 2d 34 2d 34 2d 31 32 3c 2f 62  <b>8-4-4-4-12</b
1e60: 3e 20 73 63 68 65 6d 61 2e 0d 0a 3c 76 65 72 62  > schema...<verb
1e70: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 43 72  atim>..SELECT Cr
1e80: 65 61 74 65 55 55 49 44 28 29 3b 0d 0a 2d 2d 2d  eateUUID();..---
1e90: 2d 2d 2d 2d 2d 0d 0a 66 66 66 35 66 61 66 31 2d  -----..fff5faf1-
1ea0: 64 63 63 30 2d 34 33 39 31 2d 38 30 35 34 2d 36  dcc0-4391-8054-6
1eb0: 65 37 64 65 37 35 64 38 35 62 31 0d 0a 3c 2f 76  e7de75d85b1..</v
1ec0: 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62  erbatim>..The <b
1ed0: 3e 43 72 65 61 74 65 55 55 49 44 28 29 3c 2f 62  >CreateUUID()</b
1ee0: 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 69  > SQL function i
1ef0: 73 20 62 75 69 6c 74 20 6f 6e 20 74 68 65 20 74  s built on the t
1f00: 6f 70 20 74 68 65 20 3c 69 3e 48 69 67 68 20 51  op the <i>High Q
1f10: 75 61 6c 69 74 79 20 50 73 65 75 64 6f 2d 52 61  uality Pseudo-Ra
1f20: 6e 64 6f 6d 20 4e 75 6d 62 65 72 20 47 65 6e 65  ndom Number Gene
1f30: 72 61 74 6f 72 3c 2f 69 3e 20 3c 61 20 68 72 65  rator</i> <a hre
1f40: 66 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 73 71  f="http://www.sq
1f50: 6c 69 74 65 2e 6f 72 67 2f 63 33 72 65 66 2f 72  lite.org/c3ref/r
1f60: 61 6e 64 6f 6d 6e 65 73 73 2e 68 74 6d 6c 22 3e  andomness.html">
1f70: 69 6e 74 65 72 6e 61 6c 6c 79 20 69 6d 70 6c 65  internally imple
1f80: 6d 65 6e 74 65 64 3c 2f 61 3e 20 62 79 20 53 51  mented</a> by SQ
1f90: 4c 69 74 65 2e 3c 62 72 3e 0d 0a 54 68 65 20 72  Lite.<br>..The r
1fa0: 65 74 75 72 6e 65 64 20 55 55 49 44 20 69 73 20  eturned UUID is 
1fb0: 63 6f 6e 66 6f 72 6d 61 6e 74 20 74 6f 20 3c 75  conformant to <u
1fc0: 3e 56 65 72 73 69 6f 6e 20 34 20 28 72 61 6e 64  >Version 4 (rand
1fd0: 6f 6d 29 3c 2f 75 3e 20 28 69 2e 65 2e 20 74 68  om)</u> (i.e. th
1fe0: 65 20 66 69 72 73 74 20 64 69 67 69 74 20 69 6e  e first digit in
1ff0: 74 6f 20 74 68 65 20 74 68 69 72 64 20 62 6c 6f  to the third blo
2000: 63 6b 20 77 69 6c 6c 20 61 6c 77 61 79 73 20 62  ck will always b
2010: 65 20 3c 62 3e 34 3c 2f 62 3e 20 61 6e 64 20 74  e <b>4</b> and t
2020: 68 65 20 66 69 72 73 74 20 64 69 67 69 74 20 69  he first digit i
2030: 6e 74 6f 20 74 68 65 20 66 6f 75 72 74 68 20 62  nto the fourth b
2040: 6c 6f 63 6b 20 77 69 6c 6c 20 61 6c 77 61 79 73  lock will always
2050: 20 62 65 20 3c 62 3e 38 3c 2f 62 3e 29 2e 0d 0a   be <b>8</b>)...
2060: 3c 68 72 3e 0d 0a 3c 68 33 3e 53 70 61 74 69 61  <hr>..<h3>Spatia
2070: 6c 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 73 3c  l SQL functions<
2080: 2f 68 33 3e 0d 0a 46 65 77 20 6d 6f 72 65 20 53  /h3>..Few more S
2090: 70 61 74 69 61 6c 20 53 51 4c 20 66 75 6e 63 74  patial SQL funct
20a0: 69 6f 6e 73 20 61 72 65 20 6e 6f 77 20 73 75 70  ions are now sup
20b0: 70 6f 72 74 65 64 2e 0d 0a 3c 76 65 72 62 61 74  ported...<verbat
20c0: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 54 5f 41  im>..SELECT ST_A
20d0: 73 54 65 78 74 28 20 53 54 5f 41 64 64 50 6f 69  sText( ST_AddPoi
20e0: 6e 74 28 20 0d 0a 20 20 53 54 5f 47 65 6f 6d 46  nt( ..  ST_GeomF
20f0: 72 6f 6d 54 65 78 74 28 20 27 4c 49 4e 45 53 54  romText( 'LINEST
2100: 52 49 4e 47 28 20 30 20 30 2c 20 31 20 30 20 29  RING( 0 0, 1 0 )
2110: 27 20 29 2c 20 0d 0a 20 20 53 54 5f 47 65 6f 6d  ' ), ..  ST_Geom
2120: 46 72 6f 6d 54 65 78 74 28 20 27 50 4f 49 4e 54  FromText( 'POINT
2130: 28 20 31 20 31 20 29 27 20 29 20 29 20 29 3b 0d  ( 1 1 )' ) ) );.
2140: 0a 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45 53  .--------..LINES
2150: 54 52 49 4e 47 28 30 20 30 2c 20 31 20 30 2c 20  TRING(0 0, 1 0, 
2160: 31 20 31 29 0d 0a 3c 2f 76 65 72 62 61 74 69 6d  1 1)..</verbatim
2170: 3e 0d 0a 54 68 65 20 3c 62 3e 53 54 5f 41 64 64  >..The <b>ST_Add
2180: 50 6f 69 6e 74 28 29 3c 2f 62 3e 20 53 51 4c 20  Point()</b> SQL 
2190: 66 75 6e 63 74 69 6f 6e 20 61 64 64 73 20 61 20  function adds a 
21a0: 66 75 72 74 68 65 72 20 50 6f 69 6e 74 2f 56 65  further Point/Ve
21b0: 72 74 65 78 20 61 74 20 74 68 65 20 65 6e 64 20  rtex at the end 
21c0: 6f 66 20 61 20 4c 69 6e 65 73 74 72 69 6e 67 3b  of a Linestring;
21d0: 20 74 68 65 20 66 69 72 73 74 20 61 72 67 75 6d   the first argum
21e0: 65 6e 74 20 69 73 20 61 6c 77 61 79 73 20 65 78  ent is always ex
21f0: 70 65 63 74 65 64 20 74 6f 20 62 65 20 6f 66 20  pected to be of 
2200: 74 68 65 20 4c 69 6e 65 73 74 72 69 6e 67 20 74  the Linestring t
2210: 79 70 65 2c 20 74 68 65 20 73 65 63 6f 6e 64 20  ype, the second 
2220: 6f 6e 65 20 6d 75 73 74 20 62 65 20 61 20 50 6f  one must be a Po
2230: 69 6e 74 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e  int...<verbatim>
2240: 0d 0a 53 45 4c 45 43 54 20 53 54 5f 41 73 54 65  ..SELECT ST_AsTe
2250: 78 74 28 20 53 54 5f 41 64 64 50 6f 69 6e 74 28  xt( ST_AddPoint(
2260: 20 0d 0a 20 20 53 54 5f 47 65 6f 6d 46 72 6f 6d   ..  ST_GeomFrom
2270: 54 65 78 74 28 20 27 4c 49 4e 45 53 54 52 49 4e  Text( 'LINESTRIN
2280: 47 28 20 31 20 30 2c 20 31 20 31 20 29 27 20 29  G( 1 0, 1 1 )' )
2290: 2c 20 0d 0a 20 20 53 54 5f 47 65 6f 6d 46 72 6f  , ..  ST_GeomFro
22a0: 6d 54 65 78 74 28 20 27 50 4f 49 4e 54 28 20 30  mText( 'POINT( 0
22b0: 20 30 20 29 27 20 29 2c 20 30 20 29 20 29 3b 0d   0 )' ), 0 ) );.
22c0: 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45  .---------..LINE
22d0: 53 54 52 49 4e 47 28 30 20 30 2c 20 31 20 30 2c  STRING(0 0, 1 0,
22e0: 20 31 20 31 29 0d 0a 3c 2f 76 65 72 62 61 74 69   1 1)..</verbati
22f0: 6d 3e 0d 0a 49 66 20 61 6e 20 6f 70 74 69 6f 6e  m>..If an option
2300: 61 6c 20 74 68 69 72 64 20 61 72 67 75 6d 65 6e  al third argumen
2310: 74 20 28 6f 66 20 74 68 65 20 49 6e 74 65 67 65  t (of the Intege
2320: 72 20 74 79 70 65 29 20 69 73 20 70 61 73 73 65  r type) is passe
2330: 64 20 74 6f 20 3c 62 3e 53 54 5f 41 64 64 50 6f  d to <b>ST_AddPo
2340: 69 6e 74 28 29 3c 2f 62 3e 20 69 74 27 73 20 69  int()</b> it's i
2350: 6e 74 65 6e 64 65 64 20 74 6f 20 73 70 65 63 69  ntended to speci
2360: 66 79 20 74 68 65 20 3c 75 3e 69 6e 64 65 78 3c  fy the <u>index<
2370: 2f 75 3e 20 6f 66 20 74 68 65 20 6e 65 77 20 56  /u> of the new V
2380: 65 72 74 65 78 20 28 66 69 72 73 74 20 56 65 72  ertex (first Ver
2390: 74 65 78 20 68 61 73 20 69 6e 64 65 78 20 30 2c  tex has index 0,
23a0: 20 73 65 63 6f 6e 64 20 56 65 72 74 65 78 20 68   second Vertex h
23b0: 61 73 20 69 6e 64 65 78 20 31 20 61 6e 64 20 73  as index 1 and s
23c0: 6f 20 6f 6e 29 2e 3c 62 72 3e 0d 0a 52 65 66 65  o on).<br>..Refe
23d0: 72 65 6e 63 69 6e 67 20 61 20 6e 6f 74 20 65 78  rencing a not ex
23e0: 69 73 74 69 6e 67 20 69 6e 64 65 78 20 69 73 20  isting index is 
23f0: 61 6e 20 65 72 72 6f 72 2c 20 61 6e 64 20 77 69  an error, and wi
2400: 6c 6c 20 72 65 74 75 72 6e 20 4e 55 4c 4c 2e 0d  ll return NULL..
2410: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c  .<verbatim>..SEL
2420: 45 43 54 20 53 54 5f 41 73 54 65 78 74 28 20 53  ECT ST_AsText( S
2430: 54 5f 41 64 64 50 6f 69 6e 74 28 20 0d 0a 20 20  T_AddPoint( ..  
2440: 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28  ST_GeomFromText(
2450: 20 27 4c 49 4e 45 53 54 52 49 4e 47 28 20 30 20   'LINESTRING( 0 
2460: 30 2c 20 31 20 30 20 29 27 20 29 2c 20 0d 0a 20  0, 1 0 )' ), .. 
2470: 20 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74   ST_GeomFromText
2480: 28 20 27 50 4f 49 4e 54 28 20 31 20 31 20 29 27  ( 'POINT( 1 1 )'
2490: 20 29 2c 20 2d 31 20 29 20 29 3b 0d 0a 2d 2d 2d   ), -1 ) );..---
24a0: 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45 53 54 52 49 4e  -----..LINESTRIN
24b0: 47 28 30 20 30 2c 20 31 20 30 2c 20 31 20 31 29  G(0 0, 1 0, 1 1)
24c0: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 50  ..</verbatim>..P
24d0: 61 73 73 69 6e 67 20 61 20 6e 65 67 61 74 69 76  assing a negativ
24e0: 65 20 69 6e 64 65 78 20 69 73 20 61 20 73 75 70  e index is a sup
24f0: 70 6f 72 74 65 64 20 6f 70 74 69 6f 6e 2c 20 61  ported option, a
2500: 6e 64 20 73 69 6d 70 6c 79 20 63 6f 72 72 65 73  nd simply corres
2510: 70 6f 6e 64 73 20 74 6f 20 74 68 65 20 64 65 66  ponds to the def
2520: 61 75 6c 74 20 62 65 68 61 76 69 6f 75 72 20 28  ault behaviour (
2530: 69 2e 65 2e 20 3c 69 3e 61 70 70 65 6e 64 69 6e  i.e. <i>appendin
2540: 67 20 74 68 65 20 50 6f 69 6e 74 20 74 6f 20 74  g the Point to t
2550: 68 65 20 65 6e 64 20 6f 66 20 74 68 65 20 4c 69  he end of the Li
2560: 6e 65 73 74 72 69 6e 67 3c 2f 69 3e 29 2e 0d 0a  nestring</i>)...
2570: 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e  <hr>..<verbatim>
2580: 0d 0a 53 45 4c 45 43 54 20 53 54 5f 41 73 54 65  ..SELECT ST_AsTe
2590: 78 74 28 20 53 54 5f 53 65 74 50 6f 69 6e 74 28  xt( ST_SetPoint(
25a0: 20 0d 0a 20 20 53 54 5f 47 65 6f 6d 46 72 6f 6d   ..  ST_GeomFrom
25b0: 54 65 78 74 28 20 27 4c 49 4e 45 53 54 52 49 4e  Text( 'LINESTRIN
25c0: 47 28 20 30 20 30 2c 20 31 20 30 2c 20 31 20 31  G( 0 0, 1 0, 1 1
25d0: 20 29 27 20 29 2c 20 0d 0a 20 20 31 2c 20 53 54   )' ), ..  1, ST
25e0: 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27  _GeomFromText( '
25f0: 50 4f 49 4e 54 28 20 32 20 31 20 29 27 20 29 20  POINT( 2 1 )' ) 
2600: 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d  ) );..---------.
2610: 0a 4c 49 4e 45 53 54 52 49 4e 47 28 30 20 30 2c  .LINESTRING(0 0,
2620: 20 32 20 31 2c 20 31 20 31 29 0d 0a 3c 2f 76 65   2 1, 1 1)..</ve
2630: 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e  rbatim>..The <b>
2640: 53 54 5f 53 65 74 50 6f 69 6e 74 28 29 3c 2f 62  ST_SetPoint()</b
2650: 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 63  > SQL function c
2660: 61 6e 20 72 65 70 6c 61 63 65 20 61 20 50 6f 69  an replace a Poi
2670: 6e 74 2f 56 65 72 74 65 78 20 66 72 6f 6d 20 77  nt/Vertex from w
2680: 69 74 68 69 6e 20 61 20 4c 69 6e 65 73 74 72 69  ithin a Linestri
2690: 6e 67 3b 20 74 68 65 20 66 69 72 73 74 20 61 72  ng; the first ar
26a0: 67 75 6d 65 6e 74 20 69 73 20 61 6c 77 61 79 73  gument is always
26b0: 20 65 78 70 65 63 74 65 64 20 74 6f 20 62 65 20   expected to be 
26c0: 6f 66 20 74 68 65 20 4c 69 6e 65 73 74 72 69 6e  of the Linestrin
26d0: 67 20 74 79 70 65 2c 20 74 68 65 20 73 65 63 6f  g type, the seco
26e0: 6e 64 20 69 73 20 61 6e 20 49 6e 74 65 67 65 72  nd is an Integer
26f0: 20 73 70 65 63 69 66 79 69 6e 67 20 74 68 65 20   specifying the 
2700: 3c 75 3e 69 6e 64 65 78 3c 2f 75 3e 20 6f 66 20  <u>index</u> of 
2710: 74 68 65 20 61 66 66 65 63 74 65 64 20 56 65 72  the affected Ver
2720: 74 65 78 20 61 6e 64 20 74 68 65 20 74 68 69 72  tex and the thir
2730: 64 20 6f 6e 65 20 6d 75 73 74 20 62 65 20 61 20  d one must be a 
2740: 50 6f 69 6e 74 2e 3c 62 72 3e 0d 0a 52 65 66 65  Point.<br>..Refe
2750: 72 65 6e 63 69 6e 67 20 61 20 6e 6f 74 20 65 78  rencing a not ex
2760: 69 73 74 69 6e 67 20 69 6e 64 65 78 20 69 73 20  isting index is 
2770: 61 6e 20 65 72 72 6f 72 2c 20 61 6e 64 20 77 69  an error, and wi
2780: 6c 6c 20 72 65 74 75 72 6e 20 4e 55 4c 4c 2e 0d  ll return NULL..
2790: 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d  .<hr>..<verbatim
27a0: 3e 0d 0a 53 45 4c 45 43 54 20 53 54 5f 41 73 54  >..SELECT ST_AsT
27b0: 65 78 74 28 20 53 54 5f 52 65 6d 6f 76 65 50 6f  ext( ST_RemovePo
27c0: 69 6e 74 28 20 0d 0a 20 20 53 54 5f 47 65 6f 6d  int( ..  ST_Geom
27d0: 46 72 6f 6d 54 65 78 74 28 20 27 4c 49 4e 45 53  FromText( 'LINES
27e0: 54 52 49 4e 47 28 20 30 20 30 2c 20 31 20 30 2c  TRING( 0 0, 1 0,
27f0: 20 31 20 31 20 29 27 20 29 2c 20 31 20 29 20 29   1 1 )' ), 1 ) )
2800: 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c 49  ;..---------..LI
2810: 4e 45 53 54 52 49 4e 47 28 30 20 30 2c 20 31 20  NESTRING(0 0, 1 
2820: 31 29 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d  1)..</verbatim>.
2830: 0a 54 68 65 20 3c 62 3e 53 54 5f 52 65 6d 6f 76  .The <b>ST_Remov
2840: 65 50 6f 69 6e 74 28 29 3c 2f 62 3e 20 53 51 4c  ePoint()</b> SQL
2850: 20 66 75 6e 63 74 69 6f 6e 20 63 61 6e 20 72 65   function can re
2860: 6d 6f 76 65 20 61 20 50 6f 69 6e 74 2f 56 65 72  move a Point/Ver
2870: 74 65 78 20 66 72 6f 6d 20 77 69 74 68 69 6e 20  tex from within 
2880: 61 20 4c 69 6e 65 73 74 72 69 6e 67 3b 20 74 68  a Linestring; th
2890: 65 20 66 69 72 73 74 20 61 72 67 75 6d 65 6e 74  e first argument
28a0: 20 69 73 20 61 6c 77 61 79 73 20 65 78 70 65 63   is always expec
28b0: 74 65 64 20 74 6f 20 62 65 20 6f 66 20 74 68 65  ted to be of the
28c0: 20 4c 69 6e 65 73 74 72 69 6e 67 20 74 79 70 65   Linestring type
28d0: 2c 20 74 68 65 20 73 65 63 6f 6e 64 20 69 73 20  , the second is 
28e0: 61 6e 20 49 6e 74 65 67 65 72 20 73 70 65 63 69  an Integer speci
28f0: 66 79 69 6e 67 20 74 68 65 20 3c 75 3e 69 6e 64  fying the <u>ind
2900: 65 78 3c 2f 75 3e 20 6f 66 20 74 68 65 20 61 66  ex</u> of the af
2910: 66 65 63 74 65 64 20 56 65 72 74 65 78 2e 3c 62  fected Vertex.<b
2920: 72 3e 0d 0a 52 65 66 65 72 65 6e 63 69 6e 67 20  r>..Referencing 
2930: 61 20 6e 6f 74 20 65 78 69 73 74 69 6e 67 20 69  a not existing i
2940: 6e 64 65 78 20 69 73 20 61 6e 20 65 72 72 6f 72  ndex is an error
2950: 2c 20 61 6e 64 20 77 69 6c 6c 20 72 65 74 75 72  , and will retur
2960: 6e 20 4e 55 4c 4c 2e 0d 0a 3c 68 72 3e 0d 0a 3c  n NULL...<hr>..<
2970: 68 33 3e 55 6e 73 61 66 65 20 28 62 75 74 20 75  h3>Unsafe (but u
2980: 73 65 66 75 6c 29 20 49 6d 70 6f 72 74 2f 45 78  seful) Import/Ex
2990: 70 6f 72 74 20 53 51 4c 20 66 75 6e 63 74 69 6f  port SQL functio
29a0: 6e 73 3c 2f 68 33 3e 0d 0a 41 6c 6c 20 74 68 65  ns</h3>..All the
29b0: 20 66 6f 6c 6c 6f 77 69 6e 67 20 53 51 4c 20 66   following SQL f
29c0: 75 6e 63 74 69 6f 6e 73 20 63 6f 75 6c 64 20 62  unctions could b
29d0: 65 20 72 65 61 6c 6c 79 20 75 73 65 66 75 6c 20  e really useful 
29e0: 69 6e 20 6f 72 64 65 72 20 74 6f 20 73 75 70 70  in order to supp
29f0: 6f 72 74 20 49 6d 70 6f 72 74 2f 45 78 70 6f 72  ort Import/Expor
2a00: 74 20 6f 70 65 72 61 74 69 6f 6e 73 2e 3c 62 72  t operations.<br
2a10: 3e 0d 0a 41 6e 79 77 61 79 20 79 6f 75 20 73 68  >..Anyway you sh
2a20: 6f 75 6c 64 20 62 65 20 3c 75 3e 77 65 6c 6c 20  ould be <u>well 
2a30: 61 77 61 72 65 3c 2f 75 3e 20 74 68 61 74 20 61  aware</u> that a
2a40: 6c 6c 20 74 68 65 6d 20 63 6f 75 6c 64 20 62 65  ll them could be
2a50: 20 70 6f 74 65 6e 74 69 61 6c 6c 79 20 3c 75 3e   potentially <u>
2a60: 75 6e 73 61 66 65 3c 2f 75 3e 20 61 6e 64 20 63  unsafe</u> and c
2a70: 6f 75 6c 64 20 62 65 20 70 6f 74 65 6e 74 69 61  ould be potentia
2a80: 6c 6c 79 20 75 73 65 64 20 62 79 20 73 6f 6d 65  lly used by some
2a90: 20 3c 75 3e 6d 61 6c 69 63 69 6f 75 73 20 68 61   <u>malicious ha
2aa0: 63 6b 65 72 3c 2f 75 3e 20 69 6e 20 6f 72 64 65  cker</u> in orde
2ab0: 72 20 74 6f 20 63 72 65 61 74 65 20 61 6e 64 20  r to create and 
2ac0: 65 78 70 6c 6f 69 74 20 73 6f 6d 65 20 3c 75 3e  exploit some <u>
2ad0: 73 65 63 75 72 69 74 79 20 62 72 65 61 63 68 3c  security breach<
2ae0: 2f 75 3e 2e 3c 62 72 3e 0d 0a 54 68 65 20 63 61  /u>.<br>..The ca
2af0: 75 73 65 20 69 73 20 76 65 72 79 20 65 61 73 79  use is very easy
2b00: 20 74 6f 20 62 65 20 75 6e 64 65 72 73 74 6f 6f   to be understoo
2b10: 64 3a 20 74 68 65 73 65 20 66 75 6e 63 74 69 6f  d: these functio
2b20: 6e 73 20 61 6c 6c 6f 77 20 74 6f 20 74 72 61 6e  ns allow to tran
2b30: 73 66 65 72 20 61 72 62 69 74 72 61 72 79 20 70  sfer arbitrary p
2b40: 61 79 6c 6f 61 64 73 20 66 72 6f 6d 20 2f 20 74  ayloads from / t
2b50: 6f 20 74 68 65 20 44 61 74 61 62 61 73 65 20 61  o the Database a
2b60: 6e 64 20 74 68 65 20 6c 6f 63 61 6c 20 46 69 6c  nd the local Fil
2b70: 65 2d 53 79 73 74 65 6d 2e 0d 0a 41 20 6d 61 6c  e-System...A mal
2b80: 69 63 69 6f 75 73 20 61 74 74 61 63 6b 20 63 6f  icious attack co
2b90: 75 6c 64 20 62 65 20 74 68 75 73 20 69 6d 70 6c  uld be thus impl
2ba0: 65 6d 65 6e 74 65 64 20 65 2e 67 2e 20 62 79 20  emented e.g. by 
2bb0: 65 78 65 63 75 74 69 6e 67 20 73 6f 6d 65 20 53  executing some S
2bc0: 51 4c 20 73 63 72 69 70 74 20 6f 72 20 62 79 20  QL script or by 
2bd0: 64 65 66 69 6e 69 6e 67 20 61 20 70 75 72 70 6f  defining a purpo
2be0: 73 65 6c 79 20 66 6f 72 67 65 64 20 54 72 69 67  sely forged Trig
2bf0: 67 65 72 2c 20 61 6e 64 20 74 68 65 20 65 6e 64  ger, and the end
2c00: 20 75 73 65 72 73 20 77 6f 75 6c 64 20 62 65 20   users would be 
2c10: 61 62 73 6f 6c 75 74 65 6c 79 20 75 6e 61 77 61  absolutely unawa
2c20: 72 65 20 6f 66 20 77 68 61 74 20 69 73 20 72 65  re of what is re
2c30: 61 6c 6c 79 20 68 61 70 70 65 6e 69 6e 67 2e 0d  ally happening..
2c40: 0a 53 6f 20 69 6e 20 6f 72 64 65 72 20 74 6f 20  .So in order to 
2c50: 65 66 66 65 63 74 69 76 65 6c 79 20 73 68 69 65  effectively shie
2c60: 6c 64 20 75 73 65 72 73 20 61 67 61 69 6e 73 74  ld users against
2c70: 20 74 68 65 73 65 20 70 6f 74 65 6e 74 69 61 6c   these potential
2c80: 6c 79 20 64 61 6e 67 65 72 6f 75 73 20 73 65 63  ly dangerous sec
2c90: 75 72 69 74 79 20 70 69 74 66 61 6c 6c 73 20 61  urity pitfalls a
2ca0: 6c 6c 20 74 68 65 73 65 20 53 51 4c 20 66 75 6e  ll these SQL fun
2cb0: 63 74 69 6f 6e 73 20 61 72 65 20 61 6c 77 61 79  ctions are alway
2cc0: 73 20 3c 75 3e 64 69 73 61 62 6c 65 64 20 62 79  s <u>disabled by
2cd0: 20 64 65 66 61 75 6c 74 3c 2f 75 3e 2e 0d 0a 3c   default</u>...<
2ce0: 76 65 72 62 61 74 69 6d 3e 0d 0a 65 78 70 6f 72  verbatim>..expor
2cf0: 74 20 22 53 50 41 54 49 41 4c 49 54 45 5f 53 45  t "SPATIALITE_SE
2d00: 43 55 52 49 54 59 3d 72 65 6c 61 78 65 64 22 0d  CURITY=relaxed".
2d10: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 49 6e  .</verbatim>..In
2d20: 20 6f 72 64 65 72 20 74 6f 20 72 65 61 6c 6c 79   order to really
2d30: 20 65 6e 61 62 6c 65 20 74 68 65 73 65 20 66 75   enable these fu
2d40: 6e 63 74 69 6f 6e 73 20 74 68 65 20 75 73 65 72  nctions the user
2d50: 20 69 73 20 72 65 71 75 69 72 65 64 20 74 6f 20   is required to 
2d60: 74 61 6b 65 20 61 6e 20 65 78 70 6c 69 63 69 74  take an explicit
2d70: 20 61 63 74 69 6f 6e 3b 20 69 2e 65 2e 20 74 68   action; i.e. th
2d80: 65 20 3c 75 3e 65 6e 76 69 72 6f 6e 6d 65 6e 74  e <u>environment
2d90: 20 76 61 72 69 61 62 6c 65 3c 2f 75 3e 20 3c 62   variable</u> <b
2da0: 3e 53 50 41 54 49 41 4c 49 54 45 5f 53 45 43 55  >SPATIALITE_SECU
2db0: 52 49 54 59 3d 72 65 6c 61 78 65 64 3c 2f 62 3e  RITY=relaxed</b>
2dc0: 20 68 61 73 20 74 6f 20 62 65 20 64 65 66 69 6e   has to be defin
2dd0: 65 64 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d  ed...<verbatim>.
2de0: 0a 53 45 4c 45 43 54 20 43 6f 75 6e 74 55 6e 73  .SELECT CountUns
2df0: 61 66 65 54 72 69 67 67 65 72 73 28 29 3b 0d 0a  afeTriggers();..
2e00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 30 0d 0a 3c 2f  ---------..0..</
2e10: 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c  verbatim>..The <
2e20: 62 3e 43 6f 75 6e 74 55 6e 73 61 66 65 54 72 69  b>CountUnsafeTri
2e30: 67 67 65 72 73 28 29 3c 2f 62 3e 20 61 63 74 75  ggers()</b> actu
2e40: 61 6c 6c 79 20 63 68 65 63 6b 73 20 69 66 20 74  ally checks if t
2e50: 68 65 20 63 6f 6e 6e 65 63 74 65 64 20 44 61 74  he connected Dat
2e60: 61 62 61 73 65 20 64 6f 65 73 20 63 6f 6e 74 61  abase does conta
2e70: 69 6e 73 20 61 6e 79 20 73 75 73 70 65 63 74 20  ins any suspect 
2e80: 54 72 69 67 67 65 72 3b 20 63 68 65 63 6b 69 6e  Trigger; checkin
2e90: 67 20 74 68 69 73 20 76 65 72 73 69 6f 6e 20 62  g this version b
2ea0: 65 66 6f 72 65 20 65 6e 61 62 6c 69 6e 67 20 74  efore enabling t
2eb0: 68 65 20 75 6e 73 61 66 65 20 53 51 4c 20 46 75  he unsafe SQL Fu
2ec0: 6e 63 74 69 6f 6e 73 20 69 73 20 61 6c 77 61 79  nctions is alway
2ed0: 73 20 68 69 67 68 6c 79 20 72 65 63 6f 6d 6d 65  s highly recomme
2ee0: 6e 64 65 64 2e 3c 62 72 3e 0d 0a 41 20 72 65 73  nded.<br>..A res
2ef0: 75 6c 74 20 64 69 66 66 65 72 65 6e 74 20 66 72  ult different fr
2f00: 6f 6d 20 5a 45 52 4f 20 69 6d 70 6c 69 65 73 20  om ZERO implies 
2f10: 74 68 61 74 20 73 6f 6d 65 20 6d 61 6c 69 63 69  that some malici
2f20: 6f 75 73 20 54 72 69 67 67 65 72 20 68 61 73 20  ous Trigger has 
2f30: 62 65 65 6e 20 69 64 65 6e 74 69 66 69 65 64 3b  been identified;
2f40: 20 69 6e 20 74 68 69 73 20 63 61 73 65 20 79 6f   in this case yo
2f50: 75 20 63 61 6e 20 70 65 72 66 6f 72 6d 20 61 20  u can perform a 
2f60: 64 65 65 70 65 73 74 20 69 6e 73 70 65 63 74 69  deepest inspecti
2f70: 6f 6e 20 62 79 20 65 78 65 63 75 74 69 6e 67 20  on by executing 
2f80: 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 53 51  the following SQ
2f90: 4c 20 71 75 65 72 79 3a 0d 0a 3c 76 65 72 62 61  L query:..<verba
2fa0: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 6e 61 6d  tim>..SELECT nam
2fb0: 65 2c 20 74 62 6c 5f 6e 61 6d 65 2c 20 73 71 6c  e, tbl_name, sql
2fc0: 20 0d 0a 46 52 4f 4d 20 73 71 6c 69 74 65 5f 6d   ..FROM sqlite_m
2fd0: 61 73 74 65 72 20 0d 0a 57 48 45 52 45 20 74 79  aster ..WHERE ty
2fe0: 70 65 20 3d 20 27 74 72 69 67 67 65 72 27 20 41  pe = 'trigger' A
2ff0: 4e 44 20 28 73 71 6c 20 4c 49 4b 45 20 27 25 42  ND (sql LIKE '%B
3000: 6c 6f 62 46 72 6f 6d 46 69 6c 65 25 27 20 0d 0a  lobFromFile%' ..
3010: 20 20 20 4f 52 20 73 71 6c 20 4c 49 4b 45 20 27     OR sql LIKE '
3020: 25 42 6c 6f 62 54 6f 46 69 6c 65 25 27 20 4f 52  %BlobToFile%' OR
3030: 20 73 71 6c 20 4c 49 4b 45 20 27 25 58 42 5f 4c   sql LIKE '%XB_L
3040: 6f 61 64 58 4d 4c 25 27 20 0d 0a 20 20 20 4f 52  oadXML%' ..   OR
3050: 20 73 71 6c 20 4c 49 4b 45 20 27 25 58 42 5f 53   sql LIKE '%XB_S
3060: 74 6f 72 65 58 4d 4c 25 27 29 3b 0d 0a 3c 2f 76  toreXML%');..</v
3070: 65 72 62 61 74 69 6d 3e 0d 0a 74 68 69 73 20 77  erbatim>..this w
3080: 69 6c 6c 20 67 69 76 65 20 61 20 66 75 6c 6c 20  ill give a full 
3090: 72 65 70 6f 72 74 20 66 6f 72 20 61 6e 79 20 6d  report for any m
30a0: 61 6c 69 63 69 6f 75 73 20 54 72 69 67 67 65 72  alicious Trigger
30b0: 20 65 76 65 6e 74 75 61 6c 6c 79 20 66 6f 75 6e   eventually foun
30c0: 64 2e 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61  d...<hr>..<verba
30d0: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 42 6c 6f  tim>..SELECT Blo
30e0: 62 46 72 6f 6d 46 69 6c 65 28 20 27 43 3a 2f 6d  bFromFile( 'C:/m
30f0: 79 70 69 63 74 75 72 65 73 2f 73 75 6e 73 65 74  ypictures/sunset
3100: 2e 6a 70 67 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d  .jpg' );..------
3110: 2d 2d 2d 0d 0a 42 4c 4f 42 2d 76 61 6c 75 65 0d  ---..BLOB-value.
3120: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68  .</verbatim>..Th
3130: 65 20 3c 62 3e 42 6c 6f 62 46 72 6f 6d 46 69 6c  e <b>BlobFromFil
3140: 65 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63  e()</b> SQL func
3150: 74 69 6f 6e 20 61 6c 6c 6f 77 73 20 74 6f 20 69  tion allows to i
3160: 6d 70 6f 72 74 20 61 20 77 68 6f 6c 65 20 66 69  mport a whole fi
3170: 6c 65 20 69 6e 20 61 20 73 69 6e 67 6c 65 20 73  le in a single s
3180: 74 65 70 3b 20 74 68 65 20 66 75 6c 6c 20 66 69  tep; the full fi
3190: 6c 65 20 70 61 79 6c 6f 61 64 20 77 69 6c 6c 20  le payload will 
31a0: 62 65 20 72 65 74 75 72 6e 65 64 20 61 73 20 61  be returned as a
31b0: 20 42 4c 4f 42 20 76 61 6c 75 65 2e 3c 62 72 3e   BLOB value.<br>
31c0: 0d 0a 49 66 20 74 68 65 20 61 72 67 75 6d 65 6e  ..If the argumen
31d0: 74 20 28 3c 62 3e 66 69 6c 65 2d 70 61 74 68 3c  t (<b>file-path<
31e0: 2f 62 3e 29 20 64 6f 65 73 6e 27 74 20 63 6f 72  /b>) doesn't cor
31f0: 72 65 73 70 6f 6e 64 73 20 74 6f 20 61 20 76 61  responds to a va
3200: 6c 69 64 20 66 69 6c 65 20 6f 72 20 69 66 20 74  lid file or if t
3210: 68 65 20 65 78 74 65 72 6e 61 6c 20 66 69 6c 65  he external file
3220: 20 63 61 6e 6e 6f 74 20 62 65 20 61 63 63 65 73   cannot be acces
3230: 73 65 64 20 66 6f 72 20 61 6e 79 20 72 65 61 73  sed for any reas
3240: 6f 6e 20 4e 55 4c 4c 20 77 69 6c 6c 20 62 65 20  on NULL will be 
3250: 72 65 74 75 72 6e 65 64 2e 20 0d 0a 3c 68 72 3e  returned. ..<hr>
3260: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45  ..<verbatim>..SE
3270: 4c 45 43 54 20 42 6c 6f 62 54 6f 46 69 6c 65 28  LECT BlobToFile(
3280: 20 73 6f 6d 65 42 6c 6f 62 20 2c 20 27 43 3a 2f   someBlob , 'C:/
3290: 6d 79 70 69 63 74 75 72 65 73 2f 73 75 6e 73 65  mypictures/sunse
32a0: 74 2e 6a 70 67 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d  t.jpg' );..-----
32b0: 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61  ----..1..</verba
32c0: 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 42 6c 6f  tim>..The <b>Blo
32d0: 62 54 6f 46 69 6c 65 28 29 3c 2f 62 3e 20 53 51  bToFile()</b> SQ
32e0: 4c 20 66 75 6e 63 74 69 6f 6e 20 70 65 72 66 6f  L function perfo
32f0: 72 6d 73 20 74 68 65 20 6f 70 70 6f 73 69 74 65  rms the opposite
3300: 20 74 61 73 6b 2c 20 69 2e 65 2e 20 69 74 20 65   task, i.e. it e
3310: 78 70 6f 72 74 73 20 61 20 77 68 6f 6c 65 20 42  xports a whole B
3320: 4c 4f 42 20 69 6e 74 6f 20 61 6e 20 65 78 74 65  LOB into an exte
3330: 72 6e 61 6c 20 66 69 6c 65 3b 20 74 68 65 20 66  rnal file; the f
3340: 69 72 73 74 20 61 72 67 75 6d 65 6e 74 20 6d 75  irst argument mu
3350: 73 74 20 63 6f 72 72 65 73 70 6f 6e 64 20 74 6f  st correspond to
3360: 20 73 6f 6d 65 20 42 4c 4f 42 2c 20 74 68 65 20   some BLOB, the 
3370: 73 65 63 6f 6e 64 20 6f 6e 65 20 69 73 20 74 68  second one is th
3380: 65 20 3c 62 3e 66 69 6c 65 2d 70 61 74 68 3c 2f  e <b>file-path</
3390: 62 3e 20 69 64 65 6e 74 69 66 79 69 6e 67 20 74  b> identifying t
33a0: 68 65 20 66 69 6c 65 20 74 6f 20 62 65 20 63 72  he file to be cr
33b0: 65 61 74 65 64 20 6f 72 20 6f 76 65 72 77 72 69  eated or overwri
33c0: 74 74 65 6e 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c  tten.<br><br>..<
33d0: 75 3e 50 6c 65 61 73 65 20 6e 6f 74 65 3c 2f 75  u>Please note</u
33e0: 3e 3a 20 62 6f 74 68 20 3c 62 3e 42 6c 6f 62 46  >: both <b>BlobF
33f0: 72 6f 6d 46 69 6c 65 28 29 3c 2f 62 3e 20 61 6e  romFile()</b> an
3400: 64 20 3c 62 3e 42 6c 6f 62 54 6f 46 69 6c 65 28  d <b>BlobToFile(
3410: 29 3c 2f 62 3e 20 77 65 72 65 20 61 6c 72 65 61  )</b> were alrea
3420: 64 79 20 73 75 70 70 6f 72 74 65 64 20 62 79 20  dy supported by 
3430: 34 2e 30 2e 30 2c 20 62 75 74 20 61 20 71 75 69  4.0.0, but a qui
3440: 63 6b 20 72 65 63 61 6c 6c 20 69 73 20 61 6e 79  ck recall is any
3450: 77 61 79 20 75 73 65 66 75 6c 20 73 6f 20 74 6f  way useful so to
3460: 20 72 65 63 61 6c 6c 20 61 20 63 6c 65 61 72 65   recall a cleare
3470: 72 20 63 6f 6e 74 65 78 74 2e 0d 0a 3c 68 72 3e  r context...<hr>
3480: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45  ..<verbatim>..SE
3490: 4c 45 43 54 20 58 42 5f 4c 6f 61 64 58 4d 4c 28  LECT XB_LoadXML(
34a0: 20 27 43 3a 2f 6d 79 64 6f 63 73 2f 69 73 6f 6d   'C:/mydocs/isom
34b0: 65 74 61 64 61 74 61 2d 73 61 6d 70 6c 65 2e 78  etadata-sample.x
34c0: 6d 6c 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d  ml' );..--------
34d0: 0d 0a 42 4c 4f 42 2d 76 61 6c 75 65 0d 0a 0d 0a  ..BLOB-value....
34e0: 53 45 4c 45 43 54 20 58 42 5f 4c 6f 61 64 58 4d  SELECT XB_LoadXM
34f0: 4c 28 20 27 68 74 74 70 3a 2f 2f 77 77 77 2e 61  L( 'http://www.a
3500: 63 6d 65 2e 63 6f 6d 2f 70 75 62 6c 69 63 2f 69  cme.com/public/i
3510: 73 6f 6d 65 74 61 64 61 74 61 2d 73 61 6d 70 6c  sometadata-sampl
3520: 65 2e 78 6d 6c 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d  e.xml' );..-----
3530: 2d 2d 2d 0d 0a 42 4c 4f 42 2d 76 61 6c 75 65 0d  ---..BLOB-value.
3540: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68  .</verbatim>..Th
3550: 65 20 3c 62 3e 58 42 5f 4c 6f 61 64 58 4d 4c 28  e <b>XB_LoadXML(
3560: 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69  )</b> SQL functi
3570: 6f 6e 20 61 6c 6c 6f 77 73 20 74 6f 20 69 6d 70  on allows to imp
3580: 6f 72 74 20 61 6e 20 58 4d 4c 20 44 6f 63 75 6d  ort an XML Docum
3590: 65 6e 74 20 69 6e 20 61 20 73 69 6e 67 6c 65 20  ent in a single 
35a0: 73 74 65 70 3a 20 74 68 65 20 66 75 6c 6c 20 58  step: the full X
35b0: 4d 4c 20 44 6f 63 75 6d 65 6e 74 20 70 61 79 6c  ML Document payl
35c0: 6f 61 64 20 77 69 6c 6c 20 62 65 20 72 65 74 75  oad will be retu
35d0: 72 6e 65 64 20 61 73 20 61 20 42 4c 4f 42 20 76  rned as a BLOB v
35e0: 61 6c 75 65 2e 3c 62 72 3e 0d 0a 54 68 65 20 70  alue.<br>..The p
35f0: 61 73 73 65 64 20 61 72 67 75 6d 65 6e 74 20 63  assed argument c
3600: 61 6e 20 69 6e 64 69 66 66 65 72 65 6e 74 6c 79  an indifferently
3610: 20 62 65 20 61 20 3c 62 3e 66 69 6c 65 2d 70 61   be a <b>file-pa
3620: 74 68 3c 2f 62 3e 20 6f 72 20 61 20 3c 62 3e 55  th</b> or a <b>U
3630: 52 4c 3c 2f 62 3e 3b 20 69 66 20 74 68 65 20 64  RL</b>; if the d
3640: 61 74 61 73 6f 75 72 63 65 20 63 61 6e 6e 6f 74  atasource cannot
3650: 20 62 65 20 61 63 63 65 73 73 65 64 2c 20 6f 72   be accessed, or
3660: 20 69 66 20 69 74 20 64 6f 65 73 6e 27 74 20 63   if it doesn't c
3670: 6f 6e 74 61 69 6e 73 20 61 20 3c 75 3e 77 65 6c  ontains a <u>wel
3680: 6c 2d 66 6f 72 6d 65 64 3c 2f 75 3e 20 58 4d 4c  l-formed</u> XML
3690: 20 44 6f 63 75 6d 65 6e 74 20 4e 55 4c 4c 20 77   Document NULL w
36a0: 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 2e  ill be returned.
36b0: 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69  ..<hr>..<verbati
36c0: 6d 3e 0d 0a 53 45 4c 45 43 54 20 58 42 5f 53 74  m>..SELECT XB_St
36d0: 6f 72 65 58 4d 4c 28 20 73 6f 6d 65 58 6d 6c 42  oreXML( someXmlB
36e0: 6c 6f 62 2c 20 27 43 3a 2f 6d 79 64 6f 63 73 2f  lob, 'C:/mydocs/
36f0: 69 73 6f 6d 65 74 61 64 61 74 61 2d 73 61 6d 70  isometadata-samp
3700: 6c 65 2e 78 6d 6c 27 20 29 3b 0d 0a 2d 2d 2d 2d  le.xml' );..----
3710: 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62  -----..1..</verb
3720: 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 58 42  atim>..The <b>XB
3730: 5f 53 74 6f 72 65 58 4d 4c 28 29 3c 2f 62 3e 20  _StoreXML()</b> 
3740: 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 70 65 72  SQL function per
3750: 66 6f 72 6d 73 20 74 68 65 20 6f 70 70 6f 73 69  forms the opposi
3760: 74 65 20 74 61 73 6b 2c 20 69 2e 65 2e 20 69 74  te task, i.e. it
3770: 20 65 78 70 6f 72 74 73 20 61 20 77 68 6f 6c 65   exports a whole
3780: 20 58 6d 6c 42 4c 4f 42 20 69 6e 74 6f 20 61 6e   XmlBLOB into an
3790: 20 65 78 74 65 72 6e 61 6c 20 66 69 6c 65 20 61   external file a
37a0: 73 20 61 6e 20 58 4d 4c 20 44 6f 63 75 6d 65 6e  s an XML Documen
37b0: 74 3b 20 74 68 65 20 66 69 72 73 74 20 61 72 67  t; the first arg
37c0: 75 6d 65 6e 74 20 6d 75 73 74 20 63 6f 72 72 65  ument must corre
37d0: 73 70 6f 6e 64 20 74 6f 20 73 6f 6d 65 20 76 61  spond to some va
37e0: 6c 69 64 20 58 6d 6c 42 4c 4f 42 2c 20 74 68 65  lid XmlBLOB, the
37f0: 20 73 65 63 6f 6e 64 20 6f 6e 65 20 69 73 20 74   second one is t
3800: 68 65 20 3c 62 3e 66 69 6c 65 2d 70 61 74 68 3c  he <b>file-path<
3810: 2f 62 3e 20 69 64 65 6e 74 69 66 79 69 6e 67 20  /b> identifying 
3820: 74 68 65 20 66 69 6c 65 20 74 6f 20 62 65 20 63  the file to be c
3830: 72 65 61 74 65 64 20 6f 72 20 6f 76 65 72 77 72  reated or overwr
3840: 69 74 74 65 6e 2e 20 0d 0a 3c 76 65 72 62 61 74  itten. ..<verbat
3850: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 58 42 5f 53  im>..SELECT XB_S
3860: 74 6f 72 65 58 4d 4c 28 20 73 6f 6d 65 58 6d 6c  toreXML( someXml
3870: 42 6c 6f 62 2c 20 27 43 3a 2f 6d 79 64 6f 63 73  Blob, 'C:/mydocs
3880: 2f 69 73 6f 6d 65 74 61 64 61 74 61 2d 73 61 6d  /isometadata-sam
3890: 70 6c 65 2e 78 6d 6c 27 2c 20 34 20 29 3b 0d 0a  ple.xml', 4 );..
38a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f  ---------..1..</
38b0: 76 65 72 62 61 74 69 6d 3e 0d 0a 41 20 66 75 72  verbatim>..A fur
38c0: 74 68 65 72 20 6f 70 74 69 6f 6e 61 6c 20 3c 62  ther optional <b
38d0: 3e 69 6e 64 65 6e 74 61 74 69 6f 6e 3c 2f 62 3e  >indentation</b>
38e0: 20 61 72 67 75 6d 65 6e 74 20 63 61 6e 20 62 65   argument can be
38f0: 20 65 76 65 6e 74 75 61 6c 6c 79 20 73 70 65 63   eventually spec
3900: 69 66 69 65 64 3b 20 74 68 69 73 20 61 72 67 75  ified; this argu
3910: 6d 65 6e 74 20 77 69 6c 6c 20 62 65 20 68 61 6e  ment will be han
3920: 64 6c 65 64 20 65 78 61 63 74 6c 79 20 69 6e 20  dled exactly in 
3930: 74 68 65 20 73 61 6d 65 20 77 61 79 20 61 6c 72  the same way alr
3940: 65 61 64 79 20 73 70 65 63 69 66 69 65 64 20 66  eady specified f
3950: 6f 72 20 62 6f 74 68 20 3c 62 3e 58 42 5f 47 65  or both <b>XB_Ge
3960: 74 50 61 79 6c 6f 61 64 28 29 3c 2f 62 3e 20 61  tPayload()</b> a
3970: 6e 64 20 3c 62 3e 58 42 5f 47 65 74 44 6f 63 75  nd <b>XB_GetDocu
3980: 6d 65 6e 74 28 29 3c 2f 62 3e 20 66 75 6e 63 74  ment()</b> funct
3990: 69 6f 6e 73 2e 20 0d 0a 3c 68 72 3e 3c 62 72 3e  ions. ..<hr><br>
39a0: 0d 0a 62 61 63 6b 20 74 6f 20 58 6d 6c 42 6c 6f  ..back to XmlBlo
39b0: 62 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 73  b <a href="https
39c0: 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73 2e  ://www.gaia-gis.
39d0: 69 74 2f 66 6f 73 73 69 6c 2f 6c 69 62 73 70 61  it/fossil/libspa
39e0: 74 69 61 6c 69 74 65 2f 77 69 6b 69 3f 6e 61 6d  tialite/wiki?nam
39f0: 65 3d 58 6d 6c 42 6c 6f 62 2b 61 6e 64 2b 56 69  e=XmlBlob+and+Vi
3a00: 72 74 75 61 6c 58 50 61 74 68 22 3e 6d 61 69 6e  rtualXPath">main
3a10: 20 70 61 67 65 3c 2f 61 3e 0a 5a 20 30 63 63 36   page</a>.Z 0cc6
3a20: 62 35 31 63 32 36 66 36 32 31 39 64 32 33 34 35  b51c26f6219d2345
3a30: 37 39 36 36 33 66 37 34 65 32 35 30 0a           79663f74e250.