Hex Artifact Content
Not logged in

Artifact c05bd3af6673d5429653d8edca509456532e69a0:

Wiki page [4.1.0 Changes] by sandro 2013-03-14 12:00:41.
0000: 44 20 32 30 31 33 2d 30 33 2d 31 34 54 31 32 3a  D 2013-03-14T12:
0010: 30 30 3a 34 31 2e 33 34 33 0a 4c 20 34 2e 31 2e  00:41.343.L 4.1.
0020: 30 5c 73 43 68 61 6e 67 65 73 0a 50 20 36 62 61  0\sChanges.P 6ba
0030: 62 66 36 33 65 33 36 63 30 62 64 34 63 38 31 38  bf63e36c0bd4c818
0040: 35 62 35 30 33 34 33 39 31 62 66 38 38 36 30 63  5b5034391bf8860c
0050: 61 33 66 35 36 0a 55 20 73 61 6e 64 72 6f 0a 57  a3f56.U sandro.W
0060: 20 31 35 37 36 35 0a 62 61 63 6b 20 74 6f 20 58   15765.back to X
0070: 6d 6c 42 6c 6f 62 20 3c 61 20 68 72 65 66 3d 22  mlBlob <a href="
0080: 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67 61 69 61  https://www.gaia
0090: 2d 67 69 73 2e 69 74 2f 66 6f 73 73 69 6c 2f 6c  -gis.it/fossil/l
00a0: 69 62 73 70 61 74 69 61 6c 69 74 65 2f 77 69 6b  ibspatialite/wik
00b0: 69 3f 6e 61 6d 65 3d 58 6d 6c 42 6c 6f 62 2b 61  i?name=XmlBlob+a
00c0: 6e 64 2b 56 69 72 74 75 61 6c 58 50 61 74 68 22  nd+VirtualXPath"
00d0: 3e 6d 61 69 6e 20 70 61 67 65 3c 2f 61 3e 0d 0a  >main page</a>..
00e0: 3c 68 32 3e 4e 65 77 20 53 51 4c 20 66 75 6e 63  <h2>New SQL func
00f0: 74 69 6f 6e 73 20 69 6e 74 72 6f 64 75 63 65 64  tions introduced
0100: 20 69 6e 20 34 2e 31 2e 30 3c 2f 68 32 3e 0d 0a   in 4.1.0</h2>..
0110: 54 61 62 6c 65 20 6f 66 20 63 6f 6e 74 65 6e 74  Table of content
0120: 73 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 53 51  s:..<ul>..<li>SQ
0130: 4c 20 66 75 6e 63 74 69 6f 6e 73 20 73 75 70 70  L functions supp
0140: 6f 72 74 69 6e 67 20 3c 61 20 68 72 65 66 3d 22  orting <a href="
0150: 23 63 61 73 74 22 3e 64 61 74 61 2d 74 79 70 65  #cast">data-type
0160: 20 63 61 73 74 69 6e 67 3c 2f 61 3e 3c 2f 6c 69   casting</a></li
0170: 3e 0d 0a 3c 6c 69 3e 53 51 4c 20 66 75 6e 63 74  >..<li>SQL funct
0180: 69 6f 6e 73 20 73 75 70 70 6f 72 74 69 6e 67 20  ions supporting 
0190: 3c 61 20 68 72 65 66 3d 22 23 75 75 69 64 22 3e  <a href="#uuid">
01a0: 55 55 49 44 20 67 65 6e 65 72 61 74 69 6f 6e 3c  UUID generation<
01b0: 2f 61 3e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 53 70  /a></li>..<li>Sp
01c0: 61 74 69 61 6c 20 53 51 4c 20 66 75 6e 63 74 69  atial SQL functi
01d0: 6f 6e 73 20 73 75 70 70 6f 72 74 69 6e 67 20 3c  ons supporting <
01e0: 61 20 68 72 65 66 3d 22 23 67 65 6f 6d 22 3e 47  a href="#geom">G
01f0: 65 6f 6d 65 74 72 69 65 73 3c 2f 61 3e 3c 2f 6c  eometries</a></l
0200: 69 3e 0d 0a 3c 6c 69 3e 53 51 4c 20 66 75 6e 63  i>..<li>SQL func
0210: 74 69 6f 6e 73 20 73 75 70 70 6f 72 74 69 6e 67  tions supporting
0220: 20 3c 61 20 68 72 65 66 3d 22 23 75 6e 73 61 66   <a href="#unsaf
0230: 65 22 3e 75 6e 73 61 66 65 3c 2f 61 3e 20 64 69  e">unsafe</a> di
0240: 72 65 63 74 20 49 6d 70 6f 72 74 2f 45 78 70 6f  rect Import/Expo
0250: 72 74 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a  rt</li>..</ul>..
0260: 3c 68 33 3e 3c 61 20 6e 61 6d 65 3d 22 67 65 6e  <h3><a name="gen
0270: 65 72 69 63 22 3e 63 61 73 74 3c 2f 61 3e 20 53  eric">cast</a> S
0280: 51 4c 20 66 75 6e 63 74 69 6f 6e 73 20 2d 20 74  QL functions - t
0290: 79 70 65 20 63 61 73 74 69 6e 67 3c 2f 68 33 3e  ype casting</h3>
02a0: 0d 0a 53 51 4c 69 74 65 20 6f 66 66 65 72 73 20  ..SQLite offers 
02b0: 6a 75 73 74 20 61 20 76 65 72 79 20 62 61 73 69  just a very basi
02c0: 63 20 74 79 70 65 20 63 68 65 63 6b 69 6e 67 3b  c type checking;
02d0: 20 74 68 69 73 20 69 73 20 73 6f 6d 65 74 69 6d   this is sometim
02e0: 65 73 20 75 73 65 66 75 6c 2c 20 62 75 74 20 63  es useful, but c
02f0: 6f 75 6c 64 20 62 65 20 72 65 61 6c 6c 79 20 61  ould be really a
0300: 6e 6e 6f 79 69 6e 67 20 76 65 72 79 20 6f 66 74  nnoying very oft
0310: 65 6e 2e 3c 62 72 3e 0d 0a 3c 76 65 72 62 61 74  en.<br>..<verbat
0320: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 27 31 27 2c  im>..SELECT '1',
0330: 20 54 79 70 65 4f 66 28 20 27 31 27 20 29 2c 20   TypeOf( '1' ), 
0340: 43 41 53 54 20 28 20 27 31 27 20 41 53 20 49 4e  CAST ( '1' AS IN
0350: 54 45 47 45 52 20 29 2c 20 54 79 70 65 4f 66 28  TEGER ), TypeOf(
0360: 20 43 41 53 54 20 28 20 27 31 27 20 41 53 20 49   CAST ( '1' AS I
0370: 4e 54 45 47 45 52 20 29 20 29 3b 0d 0a 3c 2f 76  NTEGER ) );..</v
0380: 65 72 62 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c 65  erbatim>..<table
0390: 20 62 6f 72 64 65 72 3d 22 31 22 20 63 65 6c 6c   border="1" cell
03a0: 73 70 61 63 69 6e 67 3d 22 34 22 20 63 65 6c 6c  spacing="4" cell
03b0: 70 61 64 64 69 6e 67 3d 22 34 22 3e 0d 0a 3c 74  padding="4">..<t
03c0: 72 3e 3c 74 68 3e 27 31 27 3c 2f 74 68 3e 3c 74  r><th>'1'</th><t
03d0: 68 3e 54 79 70 65 4f 66 28 20 27 31 27 20 29 3c  h>TypeOf( '1' )<
03e0: 2f 74 68 3e 3c 74 68 3e 43 41 53 54 20 28 20 27  /th><th>CAST ( '
03f0: 31 27 20 41 53 20 49 4e 54 45 47 45 52 20 29 3c  1' AS INTEGER )<
0400: 2f 74 68 3e 3c 74 68 3e 54 79 70 65 4f 66 28 20  /th><th>TypeOf( 
0410: 43 41 53 54 20 28 20 27 31 27 20 41 53 20 49 4e  CAST ( '1' AS IN
0420: 54 45 47 45 52 20 29 20 29 3c 2f 74 68 3e 3c 2f  TEGER ) )</th></
0430: 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 31 3c 2f  tr>..<tr><td>1</
0440: 74 64 3e 3c 74 64 3e 74 65 78 74 3c 2f 74 64 3e  td><td>text</td>
0450: 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74  <td align="right
0460: 22 3e 31 3c 2f 74 64 3e 3c 74 64 3e 69 6e 74 65  ">1</td><td>inte
0470: 67 65 72 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74  ger</td></tr></t
0480: 61 62 6c 65 3e 3c 62 72 3e 0d 0a 54 68 65 20 53  able><br>..The S
0490: 51 4c 20 3c 62 3e 43 41 53 54 3c 2f 62 3e 20 6f  QL <b>CAST</b> o
04a0: 70 65 72 61 74 6f 72 20 61 6c 72 65 61 64 79 20  perator already 
04b0: 73 75 70 70 6f 72 74 73 20 74 68 65 20 70 6f 73  supports the pos
04c0: 73 69 62 69 6c 69 74 79 20 74 6f 20 65 78 70 6c  sibility to expl
04d0: 69 63 69 74 6c 79 20 73 65 74 20 61 20 64 61 74  icitly set a dat
04e0: 61 2d 74 79 70 65 3b 20 6e 6f 77 20 73 74 61 72  a-type; now star
04f0: 74 69 6e 67 20 73 69 6e 63 65 20 34 2e 31 2e 30  ting since 4.1.0
0500: 20 53 70 61 74 69 61 4c 69 74 65 20 73 75 70 70   SpatiaLite supp
0510: 6f 72 74 73 20 66 65 77 20 53 51 4c 20 66 75 6e  orts few SQL fun
0520: 63 74 69 6f 6e 73 20 70 65 72 66 6f 72 6d 69 6e  ctions performin
0530: 67 20 74 68 65 20 73 61 6d 65 20 74 61 73 6b 2e  g the same task.
0540: 3c 62 72 3e 0d 0a 3c 75 3e 50 6c 65 61 73 65 20  <br>..<u>Please 
0550: 6e 6f 74 65 3c 2f 75 3e 3a 20 73 6f 6d 65 20 73  note</u>: some s
0560: 75 62 74 6c 65 20 64 69 66 66 65 72 65 6e 63 65  ubtle difference
0570: 73 20 65 78 69 73 74 73 20 68 65 72 65 20 61 6e  s exists here an
0580: 64 20 74 68 65 72 65 3b 20 70 6c 65 61 73 65 20  d there; please 
0590: 63 61 72 65 66 75 6c 6c 79 20 72 65 61 64 20 74  carefully read t
05a0: 68 69 73 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f  his documentatio
05b0: 6e 20 70 61 67 65 2e 0d 0a 3c 76 65 72 62 61 74  n page...<verbat
05c0: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 43 61 73 74  im>..SELECT Cast
05d0: 54 6f 49 6e 74 65 67 65 72 28 20 31 20 29 2c 20  ToInteger( 1 ), 
05e0: 43 61 73 74 54 6f 49 6e 74 65 67 65 72 28 20 31  CastToInteger( 1
05f0: 2e 34 20 29 2c 20 43 61 73 74 54 6f 49 6e 74 65  .4 ), CastToInte
0600: 67 65 72 28 20 31 2e 36 20 29 2c 20 0d 0a 20 20  ger( 1.6 ), ..  
0610: 20 20 43 61 73 74 54 6f 49 6e 74 65 67 65 72 28    CastToInteger(
0620: 20 27 31 32 33 27 20 29 2c 20 43 61 73 74 54 6f   '123' ), CastTo
0630: 49 6e 74 65 67 65 72 28 20 27 61 6c 70 68 61 27  Integer( 'alpha'
0640: 20 29 2c 20 43 61 73 74 54 6f 49 6e 74 65 67 65   ), CastToIntege
0650: 72 20 28 20 7a 65 72 6f 62 6c 6f 62 28 34 29 20  r ( zeroblob(4) 
0660: 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d  );..</verbatim>.
0670: 0a 3c 74 61 62 6c 65 20 62 6f 72 64 65 72 3d 22  .<table border="
0680: 31 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22  1" cellspacing="
0690: 34 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22  4" cellpadding="
06a0: 34 22 3e 0d 0a 3c 74 72 3e 3c 74 68 3e 43 61 73  4">..<tr><th>Cas
06b0: 74 54 6f 49 6e 74 65 67 65 72 28 20 31 20 29 3c  tToInteger( 1 )<
06c0: 2f 74 68 3e 3c 74 68 3e 43 61 73 74 54 6f 49 6e  /th><th>CastToIn
06d0: 74 65 67 65 72 28 20 31 2e 34 20 29 3c 2f 74 68  teger( 1.4 )</th
06e0: 3e 3c 74 68 3e 43 61 73 74 54 6f 49 6e 74 65 67  ><th>CastToInteg
06f0: 65 72 28 20 31 2e 36 20 29 3c 2f 74 68 3e 3c 74  er( 1.6 )</th><t
0700: 68 3e 43 61 73 74 54 6f 49 6e 74 65 67 65 72 28  h>CastToInteger(
0710: 20 27 31 32 33 27 20 29 3c 2f 74 68 3e 3c 74 68   '123' )</th><th
0720: 3e 43 61 73 74 54 6f 49 6e 74 65 67 65 72 28 20  >CastToInteger( 
0730: 27 61 6c 70 68 61 27 20 29 3c 2f 74 68 3e 3c 74  'alpha' )</th><t
0740: 68 3e 43 61 73 74 54 6f 49 6e 74 65 67 65 72 20  h>CastToInteger 
0750: 28 20 7a 65 72 6f 62 6c 6f 62 28 34 29 20 29 3c  ( zeroblob(4) )<
0760: 2f 74 68 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c  /th></tr>..<tr><
0770: 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22  td align="right"
0780: 3e 31 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e  >1</td><td align
0790: 3d 22 72 69 67 68 74 22 3e 31 3c 2f 74 64 3e 3c  ="right">1</td><
07a0: 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22  td align="right"
07b0: 3e 32 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e  >2</td><td align
07c0: 3d 22 72 69 67 68 74 22 3e 31 32 33 3c 2f 74 64  ="right">123</td
07d0: 3e 3c 74 64 3e 4e 55 4c 4c 3c 2f 74 64 3e 3c 74  ><td>NULL</td><t
07e0: 64 3e 4e 55 4c 4c 3c 2f 74 64 3e 3c 2f 74 72 3e  d>NULL</td></tr>
07f0: 3c 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 54 68  </table><br>..Th
0800: 65 20 3c 62 3e 43 61 73 74 54 6f 49 6e 74 65 67  e <b>CastToInteg
0810: 65 72 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e  er()</b> SQL fun
0820: 63 74 69 6f 6e 20 77 69 6c 6c 20 61 74 74 65 6d  ction will attem
0830: 70 74 20 74 6f 20 72 65 74 75 72 6e 20 61 20 76  pt to return a v
0840: 61 6c 75 65 20 6f 66 20 74 68 65 20 3c 62 3e 49  alue of the <b>I
0850: 6e 74 65 67 65 72 3c 2f 62 3e 20 64 61 74 61 2d  nteger</b> data-
0860: 74 79 70 65 2c 20 6f 72 20 3c 62 3e 4e 55 4c 4c  type, or <b>NULL
0870: 3c 2f 62 3e 20 69 66 20 6e 6f 20 63 6f 6e 76 65  </b> if no conve
0880: 72 73 69 6f 6e 20 69 73 20 70 6f 73 73 69 62 6c  rsion is possibl
0890: 65 2e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 6e  e...<ul>..<li>an
08a0: 20 49 6e 74 65 67 65 72 20 69 6e 70 75 74 20 61   Integer input a
08b0: 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 62 65 20  rgument will be 
08c0: 72 65 74 75 72 6e 65 64 20 61 62 73 6f 6c 75 74  returned absolut
08d0: 65 6c 79 20 75 6e 61 66 66 65 63 74 65 64 2e 3c  ely unaffected.<
08e0: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 44 6f 75 62  /li>..<li>a Doub
08f0: 6c 65 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e  le input argumen
0900: 74 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 74 68  t will return th
0910: 65 20 3c 75 3e 6e 65 61 72 65 73 74 3c 2f 75 3e  e <u>nearest</u>
0920: 20 49 6e 74 65 67 65 72 20 76 61 6c 75 65 20 28   Integer value (
0930: 61 66 74 65 72 20 61 70 70 6c 79 69 6e 67 20 3c  after applying <
0940: 62 3e 34 2f 35 3c 2f 62 3e 20 72 6f 75 6e 64 69  b>4/5</b> roundi
0950: 6e 67 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61  ng).</li>..<li>a
0960: 20 54 65 78 74 20 69 6e 70 75 74 20 61 72 67 75   Text input argu
0970: 6d 65 6e 74 20 77 69 6c 6c 20 72 65 74 75 72 6e  ment will return
0980: 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69   the correspondi
0990: 6e 67 20 49 6e 74 65 67 65 72 20 76 61 6c 75 65  ng Integer value
09a0: 20 6f 6e 6c 79 20 69 66 20 74 68 65 20 74 65 78   only if the tex
09b0: 74 20 73 74 72 69 6e 67 20 72 65 70 72 65 73 65  t string represe
09c0: 6e 74 73 20 61 20 76 61 6c 69 64 20 6e 75 6d 62  nts a valid numb
09d0: 65 72 20 28 65 76 65 6e 20 61 20 64 65 63 69 6d  er (even a decim
09e0: 61 6c 20 6f 6e 65 29 3a 20 69 66 20 74 68 65 20  al one): if the 
09f0: 74 65 78 74 20 73 74 72 69 6e 67 20 63 61 6e 6e  text string cann
0a00: 6f 74 20 62 65 20 63 6f 6e 76 65 72 74 65 64 20  ot be converted 
0a10: 74 6f 20 61 20 6e 75 6d 62 65 72 20 4e 55 4c 4c  to a number NULL
0a20: 20 77 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65   will be returne
0a30: 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79  d.</li>..<li>any
0a40: 20 42 4c 4f 42 20 69 6e 70 75 74 20 61 72 67 75   BLOB input argu
0a50: 6d 65 6e 74 20 77 69 6c 6c 20 72 65 74 75 72 6e  ment will return
0a60: 20 61 20 4e 55 4c 4c 20 76 61 6c 75 65 2e 3c 2f   a NULL value.</
0a70: 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 4e 55 4c  li>..<li>any NUL
0a80: 4c 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74  L input argument
0a90: 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 61 20 4e   will return a N
0aa0: 55 4c 4c 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d  ULL value.</li>.
0ab0: 0a 3c 2f 75 6c 3e 0d 0a 3c 68 72 3e 0d 0a 3c 76  .</ul>..<hr>..<v
0ac0: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54  erbatim>..SELECT
0ad0: 20 43 61 73 74 54 6f 44 6f 75 62 6c 65 28 20 31   CastToDouble( 1
0ae0: 20 29 2c 20 43 61 73 74 54 6f 44 6f 75 62 6c 65   ), CastToDouble
0af0: 28 20 31 2e 32 33 20 29 2c 20 43 61 73 74 54 6f  ( 1.23 ), CastTo
0b00: 44 6f 75 62 6c 65 28 20 27 31 32 33 2e 34 35 27  Double( '123.45'
0b10: 20 29 2c 0d 0a 20 20 20 20 43 61 73 74 54 6f 44   ),..    CastToD
0b20: 6f 75 62 6c 65 28 20 27 61 6c 70 68 61 27 20 29  ouble( 'alpha' )
0b30: 2c 20 43 61 73 74 54 6f 44 6f 75 62 6c 65 20 28  , CastToDouble (
0b40: 20 7a 65 72 6f 62 6c 6f 62 28 34 29 20 29 3b 0d   zeroblob(4) );.
0b50: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 74  .</verbatim>..<t
0b60: 61 62 6c 65 20 62 6f 72 64 65 72 3d 22 31 22 20  able border="1" 
0b70: 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 34 22 20  cellspacing="4" 
0b80: 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 34 22 3e  cellpadding="4">
0b90: 0d 0a 3c 74 72 3e 3c 74 68 3e 43 61 73 74 54 6f  ..<tr><th>CastTo
0ba0: 44 6f 75 62 6c 65 28 20 31 20 29 3c 2f 74 68 3e  Double( 1 )</th>
0bb0: 3c 74 68 3e 43 61 73 74 54 6f 44 6f 75 62 6c 65  <th>CastToDouble
0bc0: 28 20 31 2e 32 33 20 29 3c 2f 74 68 3e 3c 74 68  ( 1.23 )</th><th
0bd0: 3e 43 61 73 74 54 6f 44 6f 75 62 6c 65 28 20 27  >CastToDouble( '
0be0: 31 32 33 2e 34 35 27 20 29 3c 2f 74 68 3e 3c 74  123.45' )</th><t
0bf0: 68 3e 43 61 73 74 54 6f 44 6f 75 62 6c 65 28 20  h>CastToDouble( 
0c00: 27 61 6c 70 68 61 27 20 29 3c 2f 74 68 3e 3c 74  'alpha' )</th><t
0c10: 68 3e 43 61 73 74 54 6f 44 6f 75 62 6c 65 20 28  h>CastToDouble (
0c20: 20 7a 65 72 6f 62 6c 6f 62 28 34 29 20 29 3c 2f   zeroblob(4) )</
0c30: 74 68 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74  th></tr>..<tr><t
0c40: 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e  d align="right">
0c50: 31 2e 30 30 30 30 30 30 3c 2f 74 64 3e 3c 74 64  1.000000</td><td
0c60: 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 31   align="right">1
0c70: 2e 32 33 30 30 30 30 3c 2f 74 64 3e 3c 74 64 20  .230000</td><td 
0c80: 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 31 32  align="right">12
0c90: 33 2e 34 35 30 30 30 3c 2f 74 64 3e 3c 74 64 3e  3.45000</td><td>
0ca0: 4e 55 4c 4c 3c 2f 74 64 3e 3c 74 64 3e 4e 55 4c  NULL</td><td>NUL
0cb0: 4c 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62  L</td></tr></tab
0cc0: 6c 65 3e 3c 62 72 3e 0d 0a 54 68 65 20 3c 62 3e  le><br>..The <b>
0cd0: 43 61 73 74 54 6f 44 6f 75 62 6c 65 28 29 3c 2f  CastToDouble()</
0ce0: 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20  b> SQL function 
0cf0: 77 69 6c 6c 20 61 74 74 65 6d 70 74 20 74 6f 20  will attempt to 
0d00: 72 65 74 75 72 6e 20 61 20 76 61 6c 75 65 20 6f  return a value o
0d10: 66 20 74 68 65 20 3c 62 3e 44 6f 75 62 6c 65 3c  f the <b>Double<
0d20: 2f 62 3e 20 64 61 74 61 2d 74 79 70 65 2c 20 6f  /b> data-type, o
0d30: 72 20 3c 62 3e 4e 55 4c 4c 3c 2f 62 3e 20 69 66  r <b>NULL</b> if
0d40: 20 6e 6f 20 63 6f 6e 76 65 72 73 69 6f 6e 20 69   no conversion i
0d50: 73 20 70 6f 73 73 69 62 6c 65 2e 0d 0a 3c 75 6c  s possible...<ul
0d60: 3e 0d 0a 3c 6c 69 3e 61 6e 20 49 6e 74 65 67 65  >..<li>an Intege
0d70: 72 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74  r input argument
0d80: 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 74 68 65   will return the
0d90: 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 44   corresponding D
0da0: 6f 75 62 6c 65 20 76 61 6c 75 65 2e 3c 2f 6c 69  ouble value.</li
0db0: 3e 0d 0a 3c 6c 69 3e 61 20 44 6f 75 62 6c 65 20  >..<li>a Double 
0dc0: 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77  input argument w
0dd0: 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 20  ill be returned 
0de0: 61 62 73 6f 6c 75 74 65 6c 79 20 75 6e 61 66 66  absolutely unaff
0df0: 65 63 74 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  ected.</li>..<li
0e00: 3e 61 20 54 65 78 74 20 69 6e 70 75 74 20 61 72  >a Text input ar
0e10: 67 75 6d 65 6e 74 20 77 69 6c 6c 20 72 65 74 75  gument will retu
0e20: 72 6e 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e  rn the correspon
0e30: 64 69 6e 67 20 44 6f 75 62 6c 65 20 76 61 6c 75  ding Double valu
0e40: 65 20 6f 6e 6c 79 20 69 66 20 74 68 65 20 74 65  e only if the te
0e50: 78 74 20 73 74 72 69 6e 67 20 72 65 70 72 65 73  xt string repres
0e60: 65 6e 74 73 20 61 20 76 61 6c 69 64 20 6e 75 6d  ents a valid num
0e70: 62 65 72 3a 20 69 66 20 74 68 65 20 74 65 78 74  ber: if the text
0e80: 20 73 74 72 69 6e 67 20 63 61 6e 6e 6f 74 20 62   string cannot b
0e90: 65 20 63 6f 6e 76 65 72 74 65 64 20 74 6f 20 61  e converted to a
0ea0: 20 6e 75 6d 62 65 72 20 4e 55 4c 4c 20 77 69 6c   number NULL wil
0eb0: 6c 20 62 65 20 72 65 74 75 72 6e 65 64 2e 3c 2f  l be returned.</
0ec0: 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 42 4c 4f  li>..<li>any BLO
0ed0: 42 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74  B input argument
0ee0: 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 61 20 4e   will return a N
0ef0: 55 4c 4c 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d  ULL value.</li>.
0f00: 0a 3c 6c 69 3e 61 6e 79 20 4e 55 4c 4c 20 69 6e  .<li>any NULL in
0f10: 70 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 6c  put argument wil
0f20: 6c 20 72 65 74 75 72 6e 20 61 20 4e 55 4c 4c 20  l return a NULL 
0f30: 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75  value.</li>..</u
0f40: 6c 3e 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61  l>..<hr>..<verba
0f50: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 43 61 73  tim>..SELECT Cas
0f60: 74 54 6f 54 65 78 74 28 20 31 20 29 2c 20 43 61  tToText( 1 ), Ca
0f70: 73 74 54 6f 54 65 78 74 28 20 31 2e 35 20 29 2c  stToText( 1.5 ),
0f80: 20 43 61 73 74 54 6f 54 65 78 74 28 20 27 61 6c   CastToText( 'al
0f90: 70 68 61 27 20 29 2c 20 43 61 73 74 54 6f 54 65  pha' ), CastToTe
0fa0: 78 74 20 28 20 7a 65 72 6f 62 6c 6f 62 28 34 29  xt ( zeroblob(4)
0fb0: 20 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e   );..</verbatim>
0fc0: 0d 0a 3c 74 61 62 6c 65 20 62 6f 72 64 65 72 3d  ..<table border=
0fd0: 22 31 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d  "1" cellspacing=
0fe0: 22 34 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d  "4" cellpadding=
0ff0: 22 34 22 3e 0d 0a 3c 74 72 3e 3c 74 68 3e 43 61  "4">..<tr><th>Ca
1000: 73 74 54 6f 54 65 78 74 28 20 31 20 29 3c 2f 74  stToText( 1 )</t
1010: 68 3e 3c 74 68 3e 43 61 73 74 54 6f 54 65 78 74  h><th>CastToText
1020: 28 20 31 2e 35 20 29 3c 2f 74 68 3e 3c 74 68 3e  ( 1.5 )</th><th>
1030: 43 61 73 74 54 6f 54 65 78 74 28 20 27 61 6c 70  CastToText( 'alp
1040: 68 61 27 20 29 3c 2f 74 68 3e 3c 74 68 3e 43 61  ha' )</th><th>Ca
1050: 73 74 54 6f 54 65 78 74 20 28 20 7a 65 72 6f 62  stToText ( zerob
1060: 6c 6f 62 28 34 29 20 29 3c 2f 74 68 3e 3c 2f 74  lob(4) )</th></t
1070: 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 31 3c 2f 74  r>..<tr><td>1</t
1080: 64 3e 3c 74 64 3e 31 2e 35 3c 2f 74 64 3e 3c 74  d><td>1.5</td><t
1090: 64 3e 61 6c 70 68 61 3c 2f 74 64 3e 3c 74 64 3e  d>alpha</td><td>
10a0: 4e 55 4c 4c 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f  NULL</td></tr></
10b0: 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 54 68 65 20  table><br>..The 
10c0: 3c 62 3e 43 61 73 74 54 6f 54 65 78 74 28 29 3c  <b>CastToText()<
10d0: 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e  /b> SQL function
10e0: 20 77 69 6c 6c 20 61 74 74 65 6d 70 74 20 74 6f   will attempt to
10f0: 20 72 65 74 75 72 6e 20 61 20 76 61 6c 75 65 20   return a value 
1100: 6f 66 20 74 68 65 20 3c 62 3e 54 65 78 74 3c 2f  of the <b>Text</
1110: 62 3e 20 64 61 74 61 2d 74 79 70 65 2c 20 6f 72  b> data-type, or
1120: 20 3c 62 3e 4e 55 4c 4c 3c 2f 62 3e 20 69 66 20   <b>NULL</b> if 
1130: 6e 6f 20 63 6f 6e 76 65 72 73 69 6f 6e 20 69 73  no conversion is
1140: 20 70 6f 73 73 69 62 6c 65 2e 0d 0a 3c 75 6c 3e   possible...<ul>
1150: 0d 0a 3c 6c 69 3e 61 6e 20 49 6e 74 65 67 65 72  ..<li>an Integer
1160: 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20   input argument 
1170: 77 69 6c 6c 20 72 65 74 75 72 6e 20 74 68 65 20  will return the 
1180: 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 54 65  corresponding Te
1190: 78 74 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a  xt value.</li>..
11a0: 3c 6c 69 3e 61 20 44 6f 75 62 6c 65 20 69 6e 70  <li>a Double inp
11b0: 75 74 20 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c  ut argument will
11c0: 20 62 65 20 72 65 74 75 72 6e 20 74 68 65 20 63   be return the c
11d0: 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 54 65 78  orresponding Tex
11e0: 74 20 76 61 6c 75 65 3b 20 6e 6f 20 73 69 67 6e  t value; no sign
11f0: 69 66 69 63 61 6e 74 20 64 65 63 69 6d 61 6c 20  ificant decimal 
1200: 64 69 67 69 74 20 77 69 6c 6c 20 62 65 20 73 75  digit will be su
1210: 70 70 72 65 73 73 65 64 2e 3c 2f 6c 69 3e 0d 0a  ppressed.</li>..
1220: 3c 6c 69 3e 61 20 54 65 78 74 20 69 6e 70 75 74  <li>a Text input
1230: 20 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 72   argument will r
1240: 65 74 75 72 6e 20 74 68 65 20 63 6f 72 72 65 73  eturn the corres
1250: 70 6f 6e 64 69 6e 67 20 44 6f 75 62 6c 65 20 76  ponding Double v
1260: 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e  alue.</li>..<li>
1270: 61 6e 79 20 42 4c 4f 42 20 69 6e 70 75 74 20 61  any BLOB input a
1280: 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 72 65 74  rgument will ret
1290: 75 72 6e 20 61 20 4e 55 4c 4c 20 76 61 6c 75 65  urn a NULL value
12a0: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20  .</li>..<li>any 
12b0: 4e 55 4c 4c 20 69 6e 70 75 74 20 61 72 67 75 6d  NULL input argum
12c0: 65 6e 74 20 77 69 6c 6c 20 72 65 74 75 72 6e 20  ent will return 
12d0: 61 20 4e 55 4c 4c 20 76 61 6c 75 65 2e 3c 2f 6c  a NULL value.</l
12e0: 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 76 65 72 62  i>..</ul>..<verb
12f0: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 43 61  atim>..SELECT Ca
1300: 73 74 54 6f 54 65 78 74 28 20 31 2c 20 34 20 29  stToText( 1, 4 )
1310: 2c 20 43 61 73 74 54 6f 54 65 78 74 28 20 31 32  , CastToText( 12
1320: 33 34 2c 20 32 20 29 2c 20 43 61 73 74 54 6f 54  34, 2 ), CastToT
1330: 65 78 74 28 20 31 2c 20 38 20 29 2c 20 43 61 73  ext( 1, 8 ), Cas
1340: 74 54 6f 54 65 78 74 28 20 31 2e 35 2c 20 34 20  tToText( 1.5, 4 
1350: 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d  );..</verbatim>.
1360: 0a 3c 74 61 62 6c 65 20 62 6f 72 64 65 72 3d 22  .<table border="
1370: 31 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22  1" cellspacing="
1380: 34 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22  4" cellpadding="
1390: 34 22 3e 0d 0a 3c 74 72 3e 3c 74 68 3e 43 61 73  4">..<tr><th>Cas
13a0: 74 54 6f 54 65 78 74 28 20 31 2c 20 34 20 29 3c  tToText( 1, 4 )<
13b0: 2f 74 68 3e 3c 74 68 3e 43 61 73 74 54 6f 54 65  /th><th>CastToTe
13c0: 78 74 28 20 31 32 33 34 2c 20 32 20 29 3c 2f 74  xt( 1234, 2 )</t
13d0: 68 3e 3c 74 68 3e 43 61 73 74 54 6f 54 65 78 74  h><th>CastToText
13e0: 28 20 31 2c 20 38 20 29 3c 2f 74 68 3e 3c 74 68  ( 1, 8 )</th><th
13f0: 3e 43 61 73 74 54 6f 54 65 78 74 28 20 31 2e 35  >CastToText( 1.5
1400: 2c 20 34 20 29 3c 2f 74 68 3e 3c 2f 74 72 3e 0d  , 4 )</th></tr>.
1410: 0a 3c 74 72 3e 3c 74 64 3e 30 30 30 31 3c 2f 74  .<tr><td>0001</t
1420: 64 3e 3c 74 64 3e 31 32 33 34 3c 2f 74 64 3e 3c  d><td>1234</td><
1430: 74 64 3e 30 30 30 30 30 30 30 31 3c 2f 74 64 3e  td>00000001</td>
1440: 3c 74 64 3e 30 30 30 31 2e 35 3c 2f 74 64 3e 3c  <td>0001.5</td><
1450: 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 3c 62 72 3e  /tr></table><br>
1460: 0d 0a 41 6e 20 6f 76 65 72 6c 6f 61 64 65 64 20  ..An overloaded 
1470: 76 65 72 73 69 6f 6e 20 6f 66 20 3c 62 3e 43 61  version of <b>Ca
1480: 73 74 54 6f 54 65 78 74 28 29 3c 2f 62 3e 20 69  stToText()</b> i
1490: 73 20 73 75 70 70 6f 72 74 65 64 20 61 73 20 77  s supported as w
14a0: 65 6c 6c 2c 20 62 75 74 20 6f 6e 6c 79 20 77 68  ell, but only wh
14b0: 65 6e 20 74 68 65 20 69 6e 70 75 74 20 61 72 67  en the input arg
14c0: 75 6d 65 6e 74 20 69 73 20 6f 66 20 74 68 65 20  ument is of the 
14d0: 49 6e 74 65 67 65 72 20 6f 72 20 44 6f 75 62 6c  Integer or Doubl
14e0: 65 20 64 61 74 61 2d 74 79 70 65 3a 20 69 6e 20  e data-type: in 
14f0: 74 68 69 73 20 63 61 73 65 20 61 20 73 65 63 6f  this case a seco
1500: 6e 64 20 49 6e 74 65 67 65 72 20 61 72 67 75 6d  nd Integer argum
1510: 65 6e 74 20 63 6f 75 6c 64 20 62 65 20 6f 70 74  ent could be opt
1520: 69 6f 6e 61 6c 6c 79 20 73 70 65 63 69 66 69 65  ionally specifie
1530: 64 2c 20 61 6e 64 20 77 69 6c 6c 20 62 65 20 69  d, and will be i
1540: 6e 74 65 72 70 72 65 74 65 64 20 61 64 20 3c 62  nterpreted ad <b
1550: 3e 7a 65 72 6f 2d 70 61 64 64 69 6e 67 2d 6c 65  >zero-padding-le
1560: 6e 67 74 68 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a 69  ngth</b>.<br>..i
1570: 2e 65 2e 20 74 68 65 20 72 65 74 75 72 6e 65 64  .e. the returned
1580: 20 54 65 78 74 20 73 74 72 69 6e 67 20 69 6e 20   Text string in 
1590: 74 68 69 73 20 63 61 73 65 20 77 69 6c 6c 20 68  this case will h
15a0: 61 76 65 20 61 6e 20 69 6e 74 65 67 65 72 20 70  ave an integer p
15b0: 61 72 74 20 61 74 20 6c 65 61 73 74 20 6f 66 20  art at least of 
15c0: 74 68 65 20 73 70 65 63 69 66 69 65 64 20 6c 65  the specified le
15d0: 6e 67 74 68 2c 20 61 6e 64 20 65 76 65 6e 74 75  ngth, and eventu
15e0: 61 6c 6c 79 20 70 61 64 64 65 64 20 62 79 20 69  ally padded by i
15f0: 6e 73 65 72 74 69 6e 67 20 6e 6f 74 20 73 69 67  nserting not sig
1600: 6e 69 66 69 63 61 6e 74 20 6c 65 61 64 69 6e 67  nificant leading
1610: 20 5a 45 52 4f 65 73 2e 3c 62 72 3e 0d 0a 3c 68   ZEROes.<br>..<h
1620: 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  r>..<verbatim>..
1630: 53 45 4c 45 43 54 20 43 61 73 74 54 6f 42 6c 6f  SELECT CastToBlo
1640: 62 28 20 31 20 29 2c 20 43 61 73 74 54 6f 42 6c  b( 1 ), CastToBl
1650: 6f 62 28 20 31 2e 35 20 29 2c 20 48 65 78 28 20  ob( 1.5 ), Hex( 
1660: 43 61 73 74 54 6f 42 6c 6f 62 28 20 27 61 6c 70  CastToBlob( 'alp
1670: 68 61 27 20 29 20 29 2c 20 48 65 78 20 28 20 43  ha' ) ), Hex ( C
1680: 61 73 74 54 6f 42 6c 6f 62 20 28 20 7a 65 72 6f  astToBlob ( zero
1690: 62 6c 6f 62 28 34 29 20 29 20 29 3b 0d 0a 3c 2f  blob(4) ) );..</
16a0: 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c  verbatim>..<tabl
16b0: 65 20 62 6f 72 64 65 72 3d 22 31 22 20 63 65 6c  e border="1" cel
16c0: 6c 73 70 61 63 69 6e 67 3d 22 34 22 20 63 65 6c  lspacing="4" cel
16d0: 6c 70 61 64 64 69 6e 67 3d 22 34 22 3e 0d 0a 3c  lpadding="4">..<
16e0: 74 72 3e 3c 74 68 3e 43 61 73 74 54 6f 42 6c 6f  tr><th>CastToBlo
16f0: 62 28 20 31 20 29 3c 2f 74 68 3e 3c 74 68 3e 43  b( 1 )</th><th>C
1700: 61 73 74 54 6f 42 6c 6f 62 28 20 31 2e 35 20 29  astToBlob( 1.5 )
1710: 3c 2f 74 68 3e 3c 74 68 3e 48 65 78 28 20 43 61  </th><th>Hex( Ca
1720: 73 74 54 6f 42 6c 6f 62 28 20 27 61 6c 70 68 61  stToBlob( 'alpha
1730: 27 20 29 20 29 3c 2f 74 68 3e 3c 74 68 3e 48 65  ' ) )</th><th>He
1740: 78 28 20 43 61 73 74 54 6f 54 65 78 74 20 28 20  x( CastToText ( 
1750: 7a 65 72 6f 62 6c 6f 62 28 34 29 20 29 20 29 3c  zeroblob(4) ) )<
1760: 2f 74 68 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c  /th></tr>..<tr><
1770: 74 64 3e 4e 55 4c 4c 3c 2f 74 64 3e 3c 74 64 3e  td>NULL</td><td>
1780: 4e 55 4c 4c 3c 2f 74 64 3e 3c 74 64 3e 36 31 36  NULL</td><td>616
1790: 43 37 30 36 38 36 31 3c 2f 74 64 3e 3c 74 64 3e  C706861</td><td>
17a0: 30 30 30 30 30 30 30 30 3c 2f 74 64 3e 3c 2f 74  00000000</td></t
17b0: 72 3e 3c 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a  r></table><br>..
17c0: 54 68 65 20 3c 62 3e 43 61 73 74 54 6f 42 6c 6f  The <b>CastToBlo
17d0: 62 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63  b()</b> SQL func
17e0: 74 69 6f 6e 20 77 69 6c 6c 20 61 74 74 65 6d 70  tion will attemp
17f0: 74 20 74 6f 20 72 65 74 75 72 6e 20 61 20 76 61  t to return a va
1800: 6c 75 65 20 6f 66 20 74 68 65 20 3c 62 3e 42 4c  lue of the <b>BL
1810: 4f 42 3c 2f 62 3e 20 64 61 74 61 2d 74 79 70 65  OB</b> data-type
1820: 2c 20 6f 72 20 3c 62 3e 4e 55 4c 4c 3c 2f 62 3e  , or <b>NULL</b>
1830: 20 69 66 20 6e 6f 20 63 6f 6e 76 65 72 73 69 6f   if no conversio
1840: 6e 20 69 73 20 70 6f 73 73 69 62 6c 65 2e 0d 0a  n is possible...
1850: 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 6e 20 49 6e 74  <ul>..<li>an Int
1860: 65 67 65 72 20 69 6e 70 75 74 20 61 72 67 75 6d  eger input argum
1870: 65 6e 74 20 77 69 6c 6c 20 72 65 74 75 72 6e 20  ent will return 
1880: 61 20 4e 55 4c 4c 20 76 61 6c 75 65 2e 3c 2f 6c  a NULL value.</l
1890: 69 3e 0d 0a 3c 6c 69 3e 61 20 44 6f 75 62 6c 65  i>..<li>a Double
18a0: 20 69 6e 70 75 74 20 61 72 67 75 6d 65 6e 74 20   input argument 
18b0: 77 69 6c 6c 20 72 65 74 75 72 6e 20 61 20 4e 55  will return a NU
18c0: 4c 4c 20 76 61 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a  LL value.</li>..
18d0: 3c 6c 69 3e 61 20 54 65 78 74 20 69 6e 70 75 74  <li>a Text input
18e0: 20 61 72 67 75 6d 65 6e 74 20 20 77 69 6c 6c 20   argument  will 
18f0: 72 65 74 75 72 6e 20 74 68 65 20 63 6f 72 72 65  return the corre
1900: 73 70 6f 6e 64 69 6e 67 20 42 4c 4f 42 20 76 61  sponding BLOB va
1910: 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61  lue.</li>..<li>a
1920: 6e 79 20 42 4c 4f 42 20 69 6e 70 75 74 20 61 72  ny BLOB input ar
1930: 67 75 6d 65 6e 74 20 77 69 6c 6c 20 72 65 74 75  gument will retu
1940: 72 6e 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e  rn the correspon
1950: 64 69 6e 67 20 42 4c 4f 42 20 76 61 6c 75 65 2e  ding BLOB value.
1960: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 4e  </li>..<li>any N
1970: 55 4c 4c 20 69 6e 70 75 74 20 61 72 67 75 6d 65  ULL input argume
1980: 6e 74 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 61  nt will return a
1990: 20 4e 55 4c 4c 20 76 61 6c 75 65 2e 3c 2f 6c 69   NULL value.</li
19a0: 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 76 65 72 62 61  >..</ul>..<verba
19b0: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 48 65 78  tim>..SELECT Hex
19c0: 28 20 43 61 73 74 54 6f 42 6c 6f 62 28 20 27 30  ( CastToBlob( '0
19d0: 31 32 33 34 35 36 37 38 39 61 42 63 44 65 46 66  123456789aBcDeFf
19e0: 45 64 43 62 41 39 38 37 36 35 34 33 32 31 30 27  EdCbA9876543210'
19f0: 2c 20 31 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d  , 1 ) );..-----.
1a00: 0a 30 31 32 33 34 35 36 37 38 39 41 42 43 44 45  .0123456789ABCDE
1a10: 46 46 45 44 43 42 41 39 38 37 36 35 34 33 32 31  FFEDCBA987654321
1a20: 30 0d 0a 0d 0a 53 45 4c 45 43 54 20 43 61 73 74  0....SELECT Cast
1a30: 54 6f 42 6c 6f 62 28 20 27 31 32 66 27 2c 20 31  ToBlob( '12f', 1
1a40: 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 4e 55 4c 4c   );..-----..NULL
1a50: 0d 0a 0d 0a 53 45 4c 45 43 54 20 43 61 73 74 54  ....SELECT CastT
1a60: 6f 42 6c 6f 62 28 20 27 31 32 48 46 27 2c 20 31  oBlob( '12HF', 1
1a70: 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 4e 55 4c 4c   );..-----..NULL
1a80: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 41  ..</verbatim>..A
1a90: 20 73 65 63 6f 6e 64 20 6f 76 65 72 6c 6f 61 64   second overload
1aa0: 65 64 20 76 65 72 73 69 6f 6e 20 6f 66 20 3c 62  ed version of <b
1ab0: 3e 43 61 73 74 54 6f 42 6c 6f 62 28 29 3c 2f 62  >CastToBlob()</b
1ac0: 3e 20 69 73 20 73 75 70 70 6f 72 74 65 64 20 61  > is supported a
1ad0: 73 20 77 65 6c 6c 3b 20 62 79 20 73 70 65 63 69  s well; by speci
1ae0: 66 79 69 6e 67 20 61 20 66 75 72 74 68 65 72 20  fying a further 
1af0: 3c 62 3e 68 65 78 5f 69 6e 70 75 74 3c 2f 62 3e  <b>hex_input</b>
1b00: 20 3c 75 3e 62 6f 6f 6c 65 61 6e 3c 2f 75 3e 20   <u>boolean</u> 
1b10: 61 72 67 75 6d 65 6e 74 20 73 65 74 20 61 73 20  argument set as 
1b20: 3c 62 3e 54 52 55 45 3c 2f 62 3e 20 74 68 65 20  <b>TRUE</b> the 
1b30: 69 6e 70 75 74 20 73 74 72 69 6e 67 20 77 69 6c  input string wil
1b40: 6c 20 62 65 20 61 73 73 75 6d 65 64 20 74 6f 20  l be assumed to 
1b50: 62 65 20 3c 75 3e 48 65 78 61 64 65 63 69 6d 61  be <u>Hexadecima
1b60: 6c 6c 79 20 65 6e 63 6f 64 65 64 3c 2f 75 3e 2e  lly encoded</u>.
1b70: 20 49 6e 20 74 68 69 73 20 63 61 73 65 20 4e 55   In this case NU
1b80: 4c 4c 20 77 69 6c 6c 20 62 65 20 72 65 74 75 72  LL will be retur
1b90: 6e 65 64 20 69 66 20 74 68 65 20 69 6e 70 75 74  ned if the input
1ba0: 20 73 74 72 69 6e 67 20 64 6f 65 73 6e 27 74 20   string doesn't 
1bb0: 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 61  corresponds to a
1bc0: 20 76 61 6c 69 64 20 48 65 78 61 64 65 63 69 6d   valid Hexadecim
1bd0: 61 6c 20 6e 6f 74 61 74 69 6f 6e 2e 0d 0a 3c 68  al notation...<h
1be0: 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  r>..<verbatim>..
1bf0: 53 45 4c 45 43 54 20 46 6f 72 63 65 41 73 4e 75  SELECT ForceAsNu
1c00: 6c 6c 28 20 27 61 27 2c 20 27 62 27 20 29 2c 20  ll( 'a', 'b' ), 
1c10: 46 6f 72 63 65 41 73 4e 75 6c 6c 28 20 27 61 62  ForceAsNull( 'ab
1c20: 63 64 27 2c 20 27 61 62 63 64 27 20 29 2c 20 46  cd', 'abcd' ), F
1c30: 6f 72 63 65 41 73 4e 75 6c 6c 28 20 31 2c 20 31  orceAsNull( 1, 1
1c40: 29 2c 20 46 6f 72 63 65 41 73 4e 75 6c 6c 28 20  ), ForceAsNull( 
1c50: 31 2e 31 2c 20 31 20 29 3b 0d 0a 3c 2f 76 65 72  1.1, 1 );..</ver
1c60: 62 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c 65 20 62  batim>..<table b
1c70: 6f 72 64 65 72 3d 22 31 22 20 63 65 6c 6c 73 70  order="1" cellsp
1c80: 61 63 69 6e 67 3d 22 34 22 20 63 65 6c 6c 70 61  acing="4" cellpa
1c90: 64 64 69 6e 67 3d 22 34 22 3e 0d 0a 3c 74 72 3e  dding="4">..<tr>
1ca0: 3c 74 68 3e 46 6f 72 63 65 41 73 4e 75 6c 6c 28  <th>ForceAsNull(
1cb0: 20 27 61 27 2c 20 27 62 27 20 29 3c 2f 74 68 3e   'a', 'b' )</th>
1cc0: 3c 74 68 3e 46 6f 72 63 65 41 73 4e 75 6c 6c 28  <th>ForceAsNull(
1cd0: 20 27 61 62 63 64 27 2c 20 27 61 62 63 64 27 20   'abcd', 'abcd' 
1ce0: 29 3c 2f 74 68 3e 3c 74 68 3e 46 6f 72 63 65 41  )</th><th>ForceA
1cf0: 73 4e 75 6c 6c 28 20 31 2c 20 31 29 3c 2f 74 68  sNull( 1, 1)</th
1d00: 3e 3c 74 68 3e 46 6f 72 63 65 41 73 4e 75 6c 6c  ><th>ForceAsNull
1d10: 28 20 31 2e 31 2c 20 2d 39 39 39 39 20 29 3c 2f  ( 1.1, -9999 )</
1d20: 74 68 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74  th></tr>..<tr><t
1d30: 64 3e 61 3c 2f 74 64 3e 3c 74 64 3e 4e 55 4c 4c  d>a</td><td>NULL
1d40: 3c 2f 74 64 3e 3c 74 64 3e 4e 55 4c 4c 3c 2f 74  </td><td>NULL</t
1d50: 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67  d><td align="rig
1d60: 68 74 22 3e 31 2e 31 3c 2f 74 64 3e 3c 2f 74 72  ht">1.1</td></tr
1d70: 3e 3c 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 54  ></table><br>..T
1d80: 68 65 20 3c 62 3e 46 6f 72 63 65 41 73 4e 75 6c  he <b>ForceAsNul
1d90: 6c 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63  l()</b> SQL func
1da0: 74 69 6f 6e 20 77 69 6c 6c 20 65 76 61 6c 75 61  tion will evalua
1db0: 74 65 20 74 77 6f 20 61 72 62 69 74 72 61 72 79  te two arbitrary
1dc0: 20 61 72 67 75 6d 65 6e 74 73 2e 3c 62 72 3e 0d   arguments.<br>.
1dd0: 0a 49 66 20 74 68 65 79 20 61 72 65 20 65 71 75  .If they are equ
1de0: 61 6c 20 61 6e 64 20 65 78 61 63 74 6c 79 20 6f  al and exactly o
1df0: 66 20 74 68 65 20 73 61 6d 65 20 64 61 74 61 2d  f the same data-
1e00: 74 79 70 65 20 4e 55 4c 4c 20 77 69 6c 6c 20 62  type NULL will b
1e10: 65 20 72 65 74 75 72 6e 65 64 3b 20 6f 74 68 65  e returned; othe
1e20: 72 77 69 73 65 20 74 68 65 20 66 69 72 73 74 20  rwise the first 
1e30: 61 72 67 75 6d 65 6e 74 20 76 61 6c 75 65 20 77  argument value w
1e40: 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 2e  ill be returned.
1e50: 3c 62 72 3e 0d 0a 55 73 65 66 75 6c 20 65 2e 67  <br>..Useful e.g
1e60: 2e 20 77 68 69 6c 65 20 70 72 6f 63 65 73 73 69  . while processi
1e70: 6e 67 20 64 61 74 61 20 69 6d 70 6f 72 74 65 64  ng data imported
1e80: 20 66 72 6f 6d 20 61 6e 79 20 3c 62 3e 53 68 61   from any <b>Sha
1e90: 70 65 66 69 6c 65 3c 2f 62 3e 20 6f 72 20 3c 62  pefile</b> or <b
1ea0: 3e 44 42 46 20 66 69 6c 65 3c 2f 62 3e 20 28 73  >DBF file</b> (s
1eb0: 75 63 68 20 66 6f 72 6d 61 74 73 20 64 6f 65 73  uch formats does
1ec0: 6e 27 74 20 73 75 70 70 6f 72 74 20 61 6e 79 20  n't support any 
1ed0: 72 65 61 6c 20 4e 55 4c 4c 20 76 61 6c 75 65 2c  real NULL value,
1ee0: 20 6f 66 74 65 6e 20 62 65 69 6e 67 20 72 65 70   often being rep
1ef0: 6c 61 63 65 64 20 62 79 20 73 6f 6d 65 20 63 6f  laced by some co
1f00: 6e 76 65 6e 74 69 6f 6e 61 6c 20 76 61 6c 75 65  nventional value
1f10: 20 65 2e 67 2e 20 3c 62 3e 30 3c 2f 62 3e 20 6f   e.g. <b>0</b> o
1f20: 72 20 3c 62 3e 2d 39 39 39 39 3c 2f 62 3e 20 61  r <b>-9999</b> a
1f30: 6e 64 20 61 6c 69 6b 65 29 2e 0d 0a 3c 68 72 3e  nd alike)...<hr>
1f40: 0d 0a 3c 68 33 3e 3c 61 20 6e 61 6d 65 3d 22 75  ..<h3><a name="u
1f50: 75 69 64 22 3e 47 65 6e 65 72 69 63 3c 2f 61 3e  uid">Generic</a>
1f60: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 2d 20   SQL function - 
1f70: 55 55 49 44 20 67 65 6e 65 72 61 74 6f 72 3c 2f  UUID generator</
1f80: 68 33 3e 0d 0a 41 6e 20 3c 61 20 68 72 65 66 3d  h3>..An <a href=
1f90: 22 68 74 74 70 3a 2f 2f 65 6e 2e 77 69 6b 69 70  "http://en.wikip
1fa0: 65 64 69 61 2e 6f 72 67 2f 77 69 6b 69 2f 55 6e  edia.org/wiki/Un
1fb0: 69 76 65 72 73 61 6c 6c 79 5f 75 6e 69 71 75 65  iversally_unique
1fc0: 5f 69 64 65 6e 74 69 66 69 65 72 22 3e 55 6e 69  _identifier">Uni
1fd0: 76 65 72 73 61 6c 6c 79 20 75 6e 69 71 75 65 20  versally unique 
1fe0: 69 64 65 6e 74 69 66 69 65 72 3c 2f 61 3e 20 28  identifier</a> (
1ff0: 61 6b 61 20 3c 62 3e 55 55 49 44 3c 2f 62 3e 29  aka <b>UUID</b>)
2000: 20 73 69 6d 70 6c 79 20 69 73 20 61 20 3c 75 3e   simply is a <u>
2010: 31 32 38 20 62 69 74 3c 2f 75 3e 20 49 6e 74 65  128 bit</u> Inte
2020: 67 65 72 3b 20 61 63 63 6f 72 64 69 6e 67 6c 79  ger; accordingly
2030: 20 74 6f 20 3c 61 20 68 72 65 66 3d 22 68 74 74   to <a href="htt
2040: 70 3a 2f 2f 65 6e 2e 77 69 6b 69 70 65 64 69 61  p://en.wikipedia
2050: 2e 6f 72 67 2f 77 69 6b 69 2f 55 55 49 44 23 52  .org/wiki/UUID#R
2060: 61 6e 64 6f 6d 5f 55 55 49 44 5f 70 72 6f 62 61  andom_UUID_proba
2070: 62 69 6c 69 74 79 5f 6f 66 5f 64 75 70 6c 69 63  bility_of_duplic
2080: 61 74 65 73 22 3e 74 68 65 6f 72 79 3c 2f 61 3e  ates">theory</a>
2090: 2c 20 74 68 65 20 70 72 6f 62 61 62 69 6c 69 74  , the probabilit
20a0: 79 20 74 68 61 74 20 74 77 6f 20 72 61 6e 64 6f  y that two rando
20b0: 6d 6c 79 20 67 65 6e 65 72 61 74 65 64 20 55 55  mly generated UU
20c0: 49 44 73 20 63 6f 75 6c 64 20 61 73 73 75 6d 65  IDs could assume
20d0: 20 74 68 65 20 73 61 6d 65 20 76 61 6c 75 65 20   the same value 
20e0: 69 73 20 6e 65 61 72 20 74 6f 20 7a 65 72 6f 20  is near to zero 
20f0: 66 6f 72 20 6d 61 6e 79 20 70 72 61 63 74 69 63  for many practic
2100: 61 6c 20 70 75 72 70 6f 73 65 73 2e 20 41 6e 64  al purposes. And
2110: 20 63 6f 6e 73 65 71 75 65 6e 74 6c 79 20 55 55   consequently UU
2120: 49 44 73 20 61 72 65 20 77 69 64 65 6c 79 20 75  IDs are widely u
2130: 73 65 64 20 61 73 20 3c 75 3e 75 6e 69 76 65 72  sed as <u>univer
2140: 73 61 6c 6c 79 20 75 6e 69 71 75 65 20 49 44 73  sally unique IDs
2150: 3c 2f 75 3e 2e 3c 62 72 3e 0d 0a 55 73 75 61 6c  </u>.<br>..Usual
2160: 6c 79 20 55 55 49 44 73 20 61 72 65 20 72 65 70  ly UUIDs are rep
2170: 72 65 73 65 6e 74 65 64 20 69 6e 20 74 68 65 69  resented in thei
2180: 72 20 3c 75 3e 63 61 6e 6f 6e 69 63 61 6c 20 66  r <u>canonical f
2190: 6f 72 6d 3c 2f 75 3e 2c 20 69 2e 65 2e 20 61 73  orm</u>, i.e. as
21a0: 20 61 20 73 65 71 75 65 6e 63 65 20 6f 66 20 33   a sequence of 3
21b0: 32 20 68 65 78 61 64 65 63 69 6d 61 6c 20 64 69  2 hexadecimal di
21c0: 67 69 74 73 20 73 65 70 61 72 61 74 65 64 20 69  gits separated i
21d0: 6e 74 6f 20 66 69 76 65 20 64 69 73 74 69 6e 63  nto five distinc
21e0: 74 20 62 6c 6f 63 6b 2c 20 61 63 63 6f 72 64 69  t block, accordi
21f0: 6e 67 6c 79 20 74 6f 20 61 20 3c 62 3e 38 2d 34  ngly to a <b>8-4
2200: 2d 34 2d 34 2d 31 32 3c 2f 62 3e 20 73 63 68 65  -4-4-12</b> sche
2210: 6d 61 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d  ma...<verbatim>.
2220: 0a 53 45 4c 45 43 54 20 43 72 65 61 74 65 55 55  .SELECT CreateUU
2230: 49 44 28 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 0d  ID();..--------.
2240: 0a 66 66 66 35 66 61 66 31 2d 64 63 63 30 2d 34  .fff5faf1-dcc0-4
2250: 33 39 31 2d 38 30 35 34 2d 36 65 37 64 65 37 35  391-8054-6e7de75
2260: 64 38 35 62 31 0d 0a 3c 2f 76 65 72 62 61 74 69  d85b1..</verbati
2270: 6d 3e 0d 0a 54 68 65 20 3c 62 3e 43 72 65 61 74  m>..The <b>Creat
2280: 65 55 55 49 44 28 29 3c 2f 62 3e 20 53 51 4c 20  eUUID()</b> SQL 
2290: 66 75 6e 63 74 69 6f 6e 20 69 73 20 62 75 69 6c  function is buil
22a0: 74 20 6f 6e 20 74 68 65 20 74 6f 70 20 74 68 65  t on the top the
22b0: 20 3c 69 3e 48 69 67 68 20 51 75 61 6c 69 74 79   <i>High Quality
22c0: 20 50 73 65 75 64 6f 2d 52 61 6e 64 6f 6d 20 4e   Pseudo-Random N
22d0: 75 6d 62 65 72 20 47 65 6e 65 72 61 74 6f 72 3c  umber Generator<
22e0: 2f 69 3e 20 3c 61 20 68 72 65 66 3d 22 68 74 74  /i> <a href="htt
22f0: 70 3a 2f 2f 77 77 77 2e 73 71 6c 69 74 65 2e 6f  p://www.sqlite.o
2300: 72 67 2f 63 33 72 65 66 2f 72 61 6e 64 6f 6d 6e  rg/c3ref/randomn
2310: 65 73 73 2e 68 74 6d 6c 22 3e 69 6e 74 65 72 6e  ess.html">intern
2320: 61 6c 6c 79 20 69 6d 70 6c 65 6d 65 6e 74 65 64  ally implemented
2330: 3c 2f 61 3e 20 62 79 20 53 51 4c 69 74 65 2e 3c  </a> by SQLite.<
2340: 62 72 3e 0d 0a 54 68 65 20 72 65 74 75 72 6e 65  br>..The returne
2350: 64 20 55 55 49 44 20 69 73 20 63 6f 6e 66 6f 72  d UUID is confor
2360: 6d 61 6e 74 20 74 6f 20 3c 75 3e 56 65 72 73 69  mant to <u>Versi
2370: 6f 6e 20 34 20 28 72 61 6e 64 6f 6d 29 3c 2f 75  on 4 (random)</u
2380: 3e 20 28 69 2e 65 2e 20 74 68 65 20 66 69 72 73  > (i.e. the firs
2390: 74 20 64 69 67 69 74 20 69 6e 74 6f 20 74 68 65  t digit into the
23a0: 20 74 68 69 72 64 20 62 6c 6f 63 6b 20 77 69 6c   third block wil
23b0: 6c 20 61 6c 77 61 79 73 20 62 65 20 3c 62 3e 34  l always be <b>4
23c0: 3c 2f 62 3e 20 61 6e 64 20 74 68 65 20 66 69 72  </b> and the fir
23d0: 73 74 20 64 69 67 69 74 20 69 6e 74 6f 20 74 68  st digit into th
23e0: 65 20 66 6f 75 72 74 68 20 62 6c 6f 63 6b 20 77  e fourth block w
23f0: 69 6c 6c 20 61 6c 77 61 79 73 20 62 65 20 3c 62  ill always be <b
2400: 3e 38 3c 2f 62 3e 29 2e 0d 0a 3c 68 72 3e 0d 0a  >8</b>)...<hr>..
2410: 3c 68 33 3e 3c 61 20 6e 61 6d 65 3d 22 67 65 6f  <h3><a name="geo
2420: 6d 22 3e 53 70 61 74 69 61 6c 3c 2f 61 3e 20 53  m">Spatial</a> S
2430: 51 4c 20 66 75 6e 63 74 69 6f 6e 73 3c 2f 68 33  QL functions</h3
2440: 3e 0d 0a 46 65 77 20 6d 6f 72 65 20 53 70 61 74  >..Few more Spat
2450: 69 61 6c 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e  ial SQL function
2460: 73 20 61 72 65 20 6e 6f 77 20 73 75 70 70 6f 72  s are now suppor
2470: 74 65 64 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e  ted...<verbatim>
2480: 0d 0a 53 45 4c 45 43 54 20 53 54 5f 41 73 54 65  ..SELECT ST_AsTe
2490: 78 74 28 20 53 54 5f 41 64 64 50 6f 69 6e 74 28  xt( ST_AddPoint(
24a0: 20 0d 0a 20 20 53 54 5f 47 65 6f 6d 46 72 6f 6d   ..  ST_GeomFrom
24b0: 54 65 78 74 28 20 27 4c 49 4e 45 53 54 52 49 4e  Text( 'LINESTRIN
24c0: 47 28 20 30 20 30 2c 20 31 20 30 20 29 27 20 29  G( 0 0, 1 0 )' )
24d0: 2c 20 0d 0a 20 20 53 54 5f 47 65 6f 6d 46 72 6f  , ..  ST_GeomFro
24e0: 6d 54 65 78 74 28 20 27 50 4f 49 4e 54 28 20 31  mText( 'POINT( 1
24f0: 20 31 20 29 27 20 29 20 29 20 29 3b 0d 0a 2d 2d   1 )' ) ) );..--
2500: 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45 53 54 52 49  ------..LINESTRI
2510: 4e 47 28 30 20 30 2c 20 31 20 30 2c 20 31 20 31  NG(0 0, 1 0, 1 1
2520: 29 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a  )..</verbatim>..
2530: 54 68 65 20 3c 62 3e 53 54 5f 41 64 64 50 6f 69  The <b>ST_AddPoi
2540: 6e 74 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e  nt()</b> SQL fun
2550: 63 74 69 6f 6e 20 61 64 64 73 20 61 20 66 75 72  ction adds a fur
2560: 74 68 65 72 20 50 6f 69 6e 74 2f 56 65 72 74 65  ther Point/Verte
2570: 78 20 61 74 20 74 68 65 20 65 6e 64 20 6f 66 20  x at the end of 
2580: 61 20 4c 69 6e 65 73 74 72 69 6e 67 3b 20 74 68  a Linestring; th
2590: 65 20 66 69 72 73 74 20 61 72 67 75 6d 65 6e 74  e first argument
25a0: 20 69 73 20 61 6c 77 61 79 73 20 65 78 70 65 63   is always expec
25b0: 74 65 64 20 74 6f 20 62 65 20 6f 66 20 74 68 65  ted to be of the
25c0: 20 4c 69 6e 65 73 74 72 69 6e 67 20 74 79 70 65   Linestring type
25d0: 2c 20 74 68 65 20 73 65 63 6f 6e 64 20 6f 6e 65  , the second one
25e0: 20 6d 75 73 74 20 62 65 20 61 20 50 6f 69 6e 74   must be a Point
25f0: 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53  ...<verbatim>..S
2600: 45 4c 45 43 54 20 53 54 5f 41 73 54 65 78 74 28  ELECT ST_AsText(
2610: 20 53 54 5f 41 64 64 50 6f 69 6e 74 28 20 0d 0a   ST_AddPoint( ..
2620: 20 20 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78    ST_GeomFromTex
2630: 74 28 20 27 4c 49 4e 45 53 54 52 49 4e 47 28 20  t( 'LINESTRING( 
2640: 31 20 30 2c 20 31 20 31 20 29 27 20 29 2c 20 0d  1 0, 1 1 )' ), .
2650: 0a 20 20 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65  .  ST_GeomFromTe
2660: 78 74 28 20 27 50 4f 49 4e 54 28 20 30 20 30 20  xt( 'POINT( 0 0 
2670: 29 27 20 29 2c 20 30 20 29 20 29 3b 0d 0a 2d 2d  )' ), 0 ) );..--
2680: 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45 53 54 52  -------..LINESTR
2690: 49 4e 47 28 30 20 30 2c 20 31 20 30 2c 20 31 20  ING(0 0, 1 0, 1 
26a0: 31 29 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d  1)..</verbatim>.
26b0: 0a 49 66 20 61 6e 20 6f 70 74 69 6f 6e 61 6c 20  .If an optional 
26c0: 74 68 69 72 64 20 61 72 67 75 6d 65 6e 74 20 28  third argument (
26d0: 6f 66 20 74 68 65 20 49 6e 74 65 67 65 72 20 74  of the Integer t
26e0: 79 70 65 29 20 69 73 20 70 61 73 73 65 64 20 74  ype) is passed t
26f0: 6f 20 3c 62 3e 53 54 5f 41 64 64 50 6f 69 6e 74  o <b>ST_AddPoint
2700: 28 29 3c 2f 62 3e 20 69 74 27 73 20 69 6e 74 65  ()</b> it's inte
2710: 6e 64 65 64 20 74 6f 20 73 70 65 63 69 66 79 20  nded to specify 
2720: 74 68 65 20 3c 75 3e 69 6e 64 65 78 3c 2f 75 3e  the <u>index</u>
2730: 20 6f 66 20 74 68 65 20 6e 65 77 20 56 65 72 74   of the new Vert
2740: 65 78 20 28 66 69 72 73 74 20 56 65 72 74 65 78  ex (first Vertex
2750: 20 68 61 73 20 69 6e 64 65 78 20 30 2c 20 73 65   has index 0, se
2760: 63 6f 6e 64 20 56 65 72 74 65 78 20 68 61 73 20  cond Vertex has 
2770: 69 6e 64 65 78 20 31 20 61 6e 64 20 73 6f 20 6f  index 1 and so o
2780: 6e 29 2e 3c 62 72 3e 0d 0a 52 65 66 65 72 65 6e  n).<br>..Referen
2790: 63 69 6e 67 20 61 20 6e 6f 74 20 65 78 69 73 74  cing a not exist
27a0: 69 6e 67 20 69 6e 64 65 78 20 69 73 20 61 6e 20  ing index is an 
27b0: 65 72 72 6f 72 2c 20 61 6e 64 20 77 69 6c 6c 20  error, and will 
27c0: 72 65 74 75 72 6e 20 4e 55 4c 4c 2e 0d 0a 3c 76  return NULL...<v
27d0: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54  erbatim>..SELECT
27e0: 20 53 54 5f 41 73 54 65 78 74 28 20 53 54 5f 41   ST_AsText( ST_A
27f0: 64 64 50 6f 69 6e 74 28 20 0d 0a 20 20 53 54 5f  ddPoint( ..  ST_
2800: 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27 4c  GeomFromText( 'L
2810: 49 4e 45 53 54 52 49 4e 47 28 20 30 20 30 2c 20  INESTRING( 0 0, 
2820: 31 20 30 20 29 27 20 29 2c 20 0d 0a 20 20 53 54  1 0 )' ), ..  ST
2830: 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27  _GeomFromText( '
2840: 50 4f 49 4e 54 28 20 31 20 31 20 29 27 20 29 2c  POINT( 1 1 )' ),
2850: 20 2d 31 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d   -1 ) );..------
2860: 2d 2d 0d 0a 4c 49 4e 45 53 54 52 49 4e 47 28 30  --..LINESTRING(0
2870: 20 30 2c 20 31 20 30 2c 20 31 20 31 29 0d 0a 3c   0, 1 0, 1 1)..<
2880: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 50 61 73 73  /verbatim>..Pass
2890: 69 6e 67 20 61 20 6e 65 67 61 74 69 76 65 20 69  ing a negative i
28a0: 6e 64 65 78 20 69 73 20 61 20 73 75 70 70 6f 72  ndex is a suppor
28b0: 74 65 64 20 6f 70 74 69 6f 6e 2c 20 61 6e 64 20  ted option, and 
28c0: 73 69 6d 70 6c 79 20 63 6f 72 72 65 73 70 6f 6e  simply correspon
28d0: 64 73 20 74 6f 20 74 68 65 20 64 65 66 61 75 6c  ds to the defaul
28e0: 74 20 62 65 68 61 76 69 6f 75 72 20 28 69 2e 65  t behaviour (i.e
28f0: 2e 20 3c 69 3e 61 70 70 65 6e 64 69 6e 67 20 74  . <i>appending t
2900: 68 65 20 50 6f 69 6e 74 20 74 6f 20 74 68 65 20  he Point to the 
2910: 65 6e 64 20 6f 66 20 74 68 65 20 4c 69 6e 65 73  end of the Lines
2920: 74 72 69 6e 67 3c 2f 69 3e 29 2e 0d 0a 3c 68 72  tring</i>)...<hr
2930: 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53  >..<verbatim>..S
2940: 45 4c 45 43 54 20 53 54 5f 41 73 54 65 78 74 28  ELECT ST_AsText(
2950: 20 53 54 5f 53 65 74 50 6f 69 6e 74 28 20 0d 0a   ST_SetPoint( ..
2960: 20 20 53 54 5f 47 65 6f 6d 46 72 6f 6d 54 65 78    ST_GeomFromTex
2970: 74 28 20 27 4c 49 4e 45 53 54 52 49 4e 47 28 20  t( 'LINESTRING( 
2980: 30 20 30 2c 20 31 20 30 2c 20 31 20 31 20 29 27  0 0, 1 0, 1 1 )'
2990: 20 29 2c 20 0d 0a 20 20 31 2c 20 53 54 5f 47 65   ), ..  1, ST_Ge
29a0: 6f 6d 46 72 6f 6d 54 65 78 74 28 20 27 50 4f 49  omFromText( 'POI
29b0: 4e 54 28 20 32 20 31 20 29 27 20 29 20 29 20 29  NT( 2 1 )' ) ) )
29c0: 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c 49  ;..---------..LI
29d0: 4e 45 53 54 52 49 4e 47 28 30 20 30 2c 20 32 20  NESTRING(0 0, 2 
29e0: 31 2c 20 31 20 31 29 0d 0a 3c 2f 76 65 72 62 61  1, 1 1)..</verba
29f0: 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 53 54 5f  tim>..The <b>ST_
2a00: 53 65 74 50 6f 69 6e 74 28 29 3c 2f 62 3e 20 53  SetPoint()</b> S
2a10: 51 4c 20 66 75 6e 63 74 69 6f 6e 20 63 61 6e 20  QL function can 
2a20: 72 65 70 6c 61 63 65 20 61 20 50 6f 69 6e 74 2f  replace a Point/
2a30: 56 65 72 74 65 78 20 66 72 6f 6d 20 77 69 74 68  Vertex from with
2a40: 69 6e 20 61 20 4c 69 6e 65 73 74 72 69 6e 67 3b  in a Linestring;
2a50: 20 74 68 65 20 66 69 72 73 74 20 61 72 67 75 6d   the first argum
2a60: 65 6e 74 20 69 73 20 61 6c 77 61 79 73 20 65 78  ent is always ex
2a70: 70 65 63 74 65 64 20 74 6f 20 62 65 20 6f 66 20  pected to be of 
2a80: 74 68 65 20 4c 69 6e 65 73 74 72 69 6e 67 20 74  the Linestring t
2a90: 79 70 65 2c 20 74 68 65 20 73 65 63 6f 6e 64 20  ype, the second 
2aa0: 69 73 20 61 6e 20 49 6e 74 65 67 65 72 20 73 70  is an Integer sp
2ab0: 65 63 69 66 79 69 6e 67 20 74 68 65 20 3c 75 3e  ecifying the <u>
2ac0: 69 6e 64 65 78 3c 2f 75 3e 20 6f 66 20 74 68 65  index</u> of the
2ad0: 20 61 66 66 65 63 74 65 64 20 56 65 72 74 65 78   affected Vertex
2ae0: 20 61 6e 64 20 74 68 65 20 74 68 69 72 64 20 6f   and the third o
2af0: 6e 65 20 6d 75 73 74 20 62 65 20 61 20 50 6f 69  ne must be a Poi
2b00: 6e 74 2e 3c 62 72 3e 0d 0a 52 65 66 65 72 65 6e  nt.<br>..Referen
2b10: 63 69 6e 67 20 61 20 6e 6f 74 20 65 78 69 73 74  cing a not exist
2b20: 69 6e 67 20 69 6e 64 65 78 20 69 73 20 61 6e 20  ing index is an 
2b30: 65 72 72 6f 72 2c 20 61 6e 64 20 77 69 6c 6c 20  error, and will 
2b40: 72 65 74 75 72 6e 20 4e 55 4c 4c 2e 0d 0a 3c 68  return NULL...<h
2b50: 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  r>..<verbatim>..
2b60: 53 45 4c 45 43 54 20 53 54 5f 41 73 54 65 78 74  SELECT ST_AsText
2b70: 28 20 53 54 5f 52 65 6d 6f 76 65 50 6f 69 6e 74  ( ST_RemovePoint
2b80: 28 20 0d 0a 20 20 53 54 5f 47 65 6f 6d 46 72 6f  ( ..  ST_GeomFro
2b90: 6d 54 65 78 74 28 20 27 4c 49 4e 45 53 54 52 49  mText( 'LINESTRI
2ba0: 4e 47 28 20 30 20 30 2c 20 31 20 30 2c 20 31 20  NG( 0 0, 1 0, 1 
2bb0: 31 20 29 27 20 29 2c 20 31 20 29 20 29 3b 0d 0a  1 )' ), 1 ) );..
2bc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45 53  ---------..LINES
2bd0: 54 52 49 4e 47 28 30 20 30 2c 20 31 20 31 29 0d  TRING(0 0, 1 1).
2be0: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68  .</verbatim>..Th
2bf0: 65 20 3c 62 3e 53 54 5f 52 65 6d 6f 76 65 50 6f  e <b>ST_RemovePo
2c00: 69 6e 74 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75  int()</b> SQL fu
2c10: 6e 63 74 69 6f 6e 20 63 61 6e 20 72 65 6d 6f 76  nction can remov
2c20: 65 20 61 20 50 6f 69 6e 74 2f 56 65 72 74 65 78  e a Point/Vertex
2c30: 20 66 72 6f 6d 20 77 69 74 68 69 6e 20 61 20 4c   from within a L
2c40: 69 6e 65 73 74 72 69 6e 67 3b 20 74 68 65 20 66  inestring; the f
2c50: 69 72 73 74 20 61 72 67 75 6d 65 6e 74 20 69 73  irst argument is
2c60: 20 61 6c 77 61 79 73 20 65 78 70 65 63 74 65 64   always expected
2c70: 20 74 6f 20 62 65 20 6f 66 20 74 68 65 20 4c 69   to be of the Li
2c80: 6e 65 73 74 72 69 6e 67 20 74 79 70 65 2c 20 74  nestring type, t
2c90: 68 65 20 73 65 63 6f 6e 64 20 69 73 20 61 6e 20  he second is an 
2ca0: 49 6e 74 65 67 65 72 20 73 70 65 63 69 66 79 69  Integer specifyi
2cb0: 6e 67 20 74 68 65 20 3c 75 3e 69 6e 64 65 78 3c  ng the <u>index<
2cc0: 2f 75 3e 20 6f 66 20 74 68 65 20 61 66 66 65 63  /u> of the affec
2cd0: 74 65 64 20 56 65 72 74 65 78 2e 3c 62 72 3e 0d  ted Vertex.<br>.
2ce0: 0a 52 65 66 65 72 65 6e 63 69 6e 67 20 61 20 6e  .Referencing a n
2cf0: 6f 74 20 65 78 69 73 74 69 6e 67 20 69 6e 64 65  ot existing inde
2d00: 78 20 69 73 20 61 6e 20 65 72 72 6f 72 2c 20 61  x is an error, a
2d10: 6e 64 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 4e  nd will return N
2d20: 55 4c 4c 2e 0d 0a 3c 68 72 3e 0d 0a 3c 68 33 3e  ULL...<hr>..<h3>
2d30: 3c 61 20 6e 61 6d 65 3d 22 75 6e 73 61 66 65 22  <a name="unsafe"
2d40: 3e 55 6e 73 61 66 65 3c 2f 61 3e 20 28 62 75 74  >Unsafe</a> (but
2d50: 20 75 73 65 66 75 6c 29 20 49 6d 70 6f 72 74 2f   useful) Import/
2d60: 45 78 70 6f 72 74 20 53 51 4c 20 66 75 6e 63 74  Export SQL funct
2d70: 69 6f 6e 73 3c 2f 68 33 3e 0d 0a 41 6c 6c 20 74  ions</h3>..All t
2d80: 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 53 51 4c  he following SQL
2d90: 20 66 75 6e 63 74 69 6f 6e 73 20 63 6f 75 6c 64   functions could
2da0: 20 62 65 20 72 65 61 6c 6c 79 20 75 73 65 66 75   be really usefu
2db0: 6c 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 73 75  l in order to su
2dc0: 70 70 6f 72 74 20 49 6d 70 6f 72 74 2f 45 78 70  pport Import/Exp
2dd0: 6f 72 74 20 6f 70 65 72 61 74 69 6f 6e 73 2e 3c  ort operations.<
2de0: 62 72 3e 0d 0a 41 6e 79 77 61 79 20 79 6f 75 20  br>..Anyway you 
2df0: 73 68 6f 75 6c 64 20 62 65 20 3c 75 3e 77 65 6c  should be <u>wel
2e00: 6c 20 61 77 61 72 65 3c 2f 75 3e 20 74 68 61 74  l aware</u> that
2e10: 20 61 6c 6c 20 74 68 65 6d 20 63 6f 75 6c 64 20   all them could 
2e20: 62 65 20 70 6f 74 65 6e 74 69 61 6c 6c 79 20 3c  be potentially <
2e30: 75 3e 75 6e 73 61 66 65 3c 2f 75 3e 20 61 6e 64  u>unsafe</u> and
2e40: 20 63 6f 75 6c 64 20 62 65 20 70 6f 74 65 6e 74   could be potent
2e50: 69 61 6c 6c 79 20 75 73 65 64 20 62 79 20 73 6f  ially used by so
2e60: 6d 65 20 3c 75 3e 6d 61 6c 69 63 69 6f 75 73 20  me <u>malicious 
2e70: 68 61 63 6b 65 72 3c 2f 75 3e 20 69 6e 20 6f 72  hacker</u> in or
2e80: 64 65 72 20 74 6f 20 63 72 65 61 74 65 20 61 6e  der to create an
2e90: 64 20 65 78 70 6c 6f 69 74 20 73 6f 6d 65 20 3c  d exploit some <
2ea0: 75 3e 73 65 63 75 72 69 74 79 20 62 72 65 61 63  u>security breac
2eb0: 68 3c 2f 75 3e 2e 3c 62 72 3e 0d 0a 54 68 65 20  h</u>.<br>..The 
2ec0: 63 61 75 73 65 20 69 73 20 76 65 72 79 20 65 61  cause is very ea
2ed0: 73 79 20 74 6f 20 62 65 20 75 6e 64 65 72 73 74  sy to be underst
2ee0: 6f 6f 64 3a 20 74 68 65 73 65 20 66 75 6e 63 74  ood: these funct
2ef0: 69 6f 6e 73 20 61 6c 6c 6f 77 20 74 6f 20 74 72  ions allow to tr
2f00: 61 6e 73 66 65 72 20 61 72 62 69 74 72 61 72 79  ansfer arbitrary
2f10: 20 70 61 79 6c 6f 61 64 73 20 66 72 6f 6d 20 2f   payloads from /
2f20: 20 74 6f 20 74 68 65 20 44 61 74 61 62 61 73 65   to the Database
2f30: 20 61 6e 64 20 74 68 65 20 6c 6f 63 61 6c 20 46   and the local F
2f40: 69 6c 65 2d 53 79 73 74 65 6d 2e 0d 0a 41 20 6d  ile-System...A m
2f50: 61 6c 69 63 69 6f 75 73 20 61 74 74 61 63 6b 20  alicious attack 
2f60: 63 6f 75 6c 64 20 62 65 20 74 68 75 73 20 69 6d  could be thus im
2f70: 70 6c 65 6d 65 6e 74 65 64 20 65 2e 67 2e 20 62  plemented e.g. b
2f80: 79 20 65 78 65 63 75 74 69 6e 67 20 73 6f 6d 65  y executing some
2f90: 20 53 51 4c 20 73 63 72 69 70 74 20 6f 72 20 62   SQL script or b
2fa0: 79 20 64 65 66 69 6e 69 6e 67 20 61 20 70 75 72  y defining a pur
2fb0: 70 6f 73 65 6c 79 20 66 6f 72 67 65 64 20 54 72  posely forged Tr
2fc0: 69 67 67 65 72 2c 20 61 6e 64 20 74 68 65 20 65  igger, and the e
2fd0: 6e 64 20 75 73 65 72 73 20 77 6f 75 6c 64 20 62  nd users would b
2fe0: 65 20 61 62 73 6f 6c 75 74 65 6c 79 20 75 6e 61  e absolutely una
2ff0: 77 61 72 65 20 6f 66 20 77 68 61 74 20 69 73 20  ware of what is 
3000: 72 65 61 6c 6c 79 20 68 61 70 70 65 6e 69 6e 67  really happening
3010: 2e 0d 0a 53 6f 20 69 6e 20 6f 72 64 65 72 20 74  ...So in order t
3020: 6f 20 65 66 66 65 63 74 69 76 65 6c 79 20 73 68  o effectively sh
3030: 69 65 6c 64 20 75 73 65 72 73 20 61 67 61 69 6e  ield users again
3040: 73 74 20 74 68 65 73 65 20 70 6f 74 65 6e 74 69  st these potenti
3050: 61 6c 6c 79 20 64 61 6e 67 65 72 6f 75 73 20 73  ally dangerous s
3060: 65 63 75 72 69 74 79 20 70 69 74 66 61 6c 6c 73  ecurity pitfalls
3070: 20 61 6c 6c 20 74 68 65 73 65 20 53 51 4c 20 66   all these SQL f
3080: 75 6e 63 74 69 6f 6e 73 20 61 72 65 20 61 6c 77  unctions are alw
3090: 61 79 73 20 3c 75 3e 64 69 73 61 62 6c 65 64 20  ays <u>disabled 
30a0: 62 79 20 64 65 66 61 75 6c 74 3c 2f 75 3e 2e 0d  by default</u>..
30b0: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 65 78 70  .<verbatim>..exp
30c0: 6f 72 74 20 22 53 50 41 54 49 41 4c 49 54 45 5f  ort "SPATIALITE_
30d0: 53 45 43 55 52 49 54 59 3d 72 65 6c 61 78 65 64  SECURITY=relaxed
30e0: 22 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a  "..</verbatim>..
30f0: 49 6e 20 6f 72 64 65 72 20 74 6f 20 72 65 61 6c  In order to real
3100: 6c 79 20 65 6e 61 62 6c 65 20 74 68 65 73 65 20  ly enable these 
3110: 66 75 6e 63 74 69 6f 6e 73 20 74 68 65 20 75 73  functions the us
3120: 65 72 20 69 73 20 72 65 71 75 69 72 65 64 20 74  er is required t
3130: 6f 20 74 61 6b 65 20 61 6e 20 65 78 70 6c 69 63  o take an explic
3140: 69 74 20 61 63 74 69 6f 6e 3b 20 69 2e 65 2e 20  it action; i.e. 
3150: 74 68 65 20 3c 75 3e 65 6e 76 69 72 6f 6e 6d 65  the <u>environme
3160: 6e 74 20 76 61 72 69 61 62 6c 65 3c 2f 75 3e 20  nt variable</u> 
3170: 3c 62 3e 53 50 41 54 49 41 4c 49 54 45 5f 53 45  <b>SPATIALITE_SE
3180: 43 55 52 49 54 59 3d 72 65 6c 61 78 65 64 3c 2f  CURITY=relaxed</
3190: 62 3e 20 68 61 73 20 74 6f 20 62 65 20 64 65 66  b> has to be def
31a0: 69 6e 65 64 2e 0d 0a 3c 76 65 72 62 61 74 69 6d  ined...<verbatim
31b0: 3e 0d 0a 53 45 4c 45 43 54 20 43 6f 75 6e 74 55  >..SELECT CountU
31c0: 6e 73 61 66 65 54 72 69 67 67 65 72 73 28 29 3b  nsafeTriggers();
31d0: 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 30 0d 0a  ..---------..0..
31e0: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65  </verbatim>..The
31f0: 20 3c 62 3e 43 6f 75 6e 74 55 6e 73 61 66 65 54   <b>CountUnsafeT
3200: 72 69 67 67 65 72 73 28 29 3c 2f 62 3e 20 61 63  riggers()</b> ac
3210: 74 75 61 6c 6c 79 20 63 68 65 63 6b 73 20 69 66  tually checks if
3220: 20 74 68 65 20 63 6f 6e 6e 65 63 74 65 64 20 44   the connected D
3230: 61 74 61 62 61 73 65 20 64 6f 65 73 20 63 6f 6e  atabase does con
3240: 74 61 69 6e 73 20 61 6e 79 20 73 75 73 70 65 63  tains any suspec
3250: 74 20 54 72 69 67 67 65 72 3b 20 63 68 65 63 6b  t Trigger; check
3260: 69 6e 67 20 74 68 69 73 20 76 65 72 73 69 6f 6e  ing this version
3270: 20 62 65 66 6f 72 65 20 65 6e 61 62 6c 69 6e 67   before enabling
3280: 20 74 68 65 20 75 6e 73 61 66 65 20 53 51 4c 20   the unsafe SQL 
3290: 46 75 6e 63 74 69 6f 6e 73 20 69 73 20 61 6c 77  Functions is alw
32a0: 61 79 73 20 68 69 67 68 6c 79 20 72 65 63 6f 6d  ays highly recom
32b0: 6d 65 6e 64 65 64 2e 3c 62 72 3e 0d 0a 41 20 72  mended.<br>..A r
32c0: 65 73 75 6c 74 20 64 69 66 66 65 72 65 6e 74 20  esult different 
32d0: 66 72 6f 6d 20 5a 45 52 4f 20 69 6d 70 6c 69 65  from ZERO implie
32e0: 73 20 74 68 61 74 20 73 6f 6d 65 20 6d 61 6c 69  s that some mali
32f0: 63 69 6f 75 73 20 54 72 69 67 67 65 72 20 68 61  cious Trigger ha
3300: 73 20 62 65 65 6e 20 69 64 65 6e 74 69 66 69 65  s been identifie
3310: 64 3b 20 69 6e 20 74 68 69 73 20 63 61 73 65 20  d; in this case 
3320: 79 6f 75 20 63 61 6e 20 70 65 72 66 6f 72 6d 20  you can perform 
3330: 61 20 64 65 65 70 65 73 74 20 69 6e 73 70 65 63  a deepest inspec
3340: 74 69 6f 6e 20 62 79 20 65 78 65 63 75 74 69 6e  tion by executin
3350: 67 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20  g the following 
3360: 53 51 4c 20 71 75 65 72 79 3a 0d 0a 3c 76 65 72  SQL query:..<ver
3370: 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 74  batim>..SELECT t
3380: 79 70 65 2c 20 6e 61 6d 65 2c 20 74 62 6c 5f 6e  ype, name, tbl_n
3390: 61 6d 65 2c 20 73 71 6c 20 0d 0a 46 52 4f 4d 20  ame, sql ..FROM 
33a0: 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 20 0d 0a  sqlite_master ..
33b0: 57 48 45 52 45 20 74 79 70 65 20 49 4e 20 28 27  WHERE type IN ('
33c0: 74 72 69 67 67 65 72 27 2c 20 27 76 69 65 77 27  trigger', 'view'
33d0: 29 20 41 4e 44 20 28 73 71 6c 20 4c 49 4b 45 20  ) AND (sql LIKE 
33e0: 27 25 42 6c 6f 62 46 72 6f 6d 46 69 6c 65 25 27  '%BlobFromFile%'
33f0: 20 0d 0a 20 20 20 4f 52 20 73 71 6c 20 4c 49 4b   ..   OR sql LIK
3400: 45 20 27 25 42 6c 6f 62 54 6f 46 69 6c 65 25 27  E '%BlobToFile%'
3410: 20 4f 52 20 73 71 6c 20 4c 49 4b 45 20 27 25 58   OR sql LIKE '%X
3420: 42 5f 4c 6f 61 64 58 4d 4c 25 27 20 0d 0a 20 20  B_LoadXML%' ..  
3430: 20 4f 52 20 73 71 6c 20 4c 49 4b 45 20 27 25 58   OR sql LIKE '%X
3440: 42 5f 53 74 6f 72 65 58 4d 4c 25 27 29 3b 0d 0a  B_StoreXML%');..
3450: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 74 68 69  </verbatim>..thi
3460: 73 20 77 69 6c 6c 20 67 69 76 65 20 61 20 66 75  s will give a fu
3470: 6c 6c 20 72 65 70 6f 72 74 20 66 6f 72 20 61 6e  ll report for an
3480: 79 20 6d 61 6c 69 63 69 6f 75 73 20 54 72 69 67  y malicious Trig
3490: 67 65 72 20 65 76 65 6e 74 75 61 6c 6c 79 20 66  ger eventually f
34a0: 6f 75 6e 64 2e 0d 0a 3c 68 72 3e 0d 0a 3c 76 65  ound...<hr>..<ve
34b0: 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20  rbatim>..SELECT 
34c0: 42 6c 6f 62 46 72 6f 6d 46 69 6c 65 28 20 27 43  BlobFromFile( 'C
34d0: 3a 2f 6d 79 70 69 63 74 75 72 65 73 2f 73 75 6e  :/mypictures/sun
34e0: 73 65 74 2e 6a 70 67 27 20 29 3b 0d 0a 2d 2d 2d  set.jpg' );..---
34f0: 2d 2d 2d 2d 2d 2d 0d 0a 42 4c 4f 42 2d 76 61 6c  ------..BLOB-val
3500: 75 65 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d  ue..</verbatim>.
3510: 0a 54 68 65 20 3c 62 3e 42 6c 6f 62 46 72 6f 6d  .The <b>BlobFrom
3520: 46 69 6c 65 28 29 3c 2f 62 3e 20 53 51 4c 20 66  File()</b> SQL f
3530: 75 6e 63 74 69 6f 6e 20 61 6c 6c 6f 77 73 20 74  unction allows t
3540: 6f 20 69 6d 70 6f 72 74 20 61 20 77 68 6f 6c 65  o import a whole
3550: 20 66 69 6c 65 20 69 6e 20 61 20 73 69 6e 67 6c   file in a singl
3560: 65 20 73 74 65 70 3b 20 74 68 65 20 66 75 6c 6c  e step; the full
3570: 20 66 69 6c 65 20 70 61 79 6c 6f 61 64 20 77 69   file payload wi
3580: 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 20 61  ll be returned a
3590: 73 20 61 20 42 4c 4f 42 20 76 61 6c 75 65 2e 3c  s a BLOB value.<
35a0: 62 72 3e 0d 0a 49 66 20 74 68 65 20 61 72 67 75  br>..If the argu
35b0: 6d 65 6e 74 20 28 3c 62 3e 66 69 6c 65 2d 70 61  ment (<b>file-pa
35c0: 74 68 3c 2f 62 3e 29 20 64 6f 65 73 6e 27 74 20  th</b>) doesn't 
35d0: 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 61  corresponds to a
35e0: 20 76 61 6c 69 64 20 66 69 6c 65 20 6f 72 20 69   valid file or i
35f0: 66 20 74 68 65 20 65 78 74 65 72 6e 61 6c 20 66  f the external f
3600: 69 6c 65 20 63 61 6e 6e 6f 74 20 62 65 20 61 63  ile cannot be ac
3610: 63 65 73 73 65 64 20 66 6f 72 20 61 6e 79 20 72  cessed for any r
3620: 65 61 73 6f 6e 20 4e 55 4c 4c 20 77 69 6c 6c 20  eason NULL will 
3630: 62 65 20 72 65 74 75 72 6e 65 64 2e 20 0d 0a 3c  be returned. ..<
3640: 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d  hr>..<verbatim>.
3650: 0a 53 45 4c 45 43 54 20 42 6c 6f 62 54 6f 46 69  .SELECT BlobToFi
3660: 6c 65 28 20 73 6f 6d 65 42 6c 6f 62 20 2c 20 27  le( someBlob , '
3670: 43 3a 2f 6d 79 70 69 63 74 75 72 65 73 2f 73 75  C:/mypictures/su
3680: 6e 73 65 74 2e 6a 70 67 27 20 29 3b 0d 0a 2d 2d  nset.jpg' );..--
3690: 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65  -------..1..</ve
36a0: 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e  rbatim>..The <b>
36b0: 42 6c 6f 62 54 6f 46 69 6c 65 28 29 3c 2f 62 3e  BlobToFile()</b>
36c0: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 70 65   SQL function pe
36d0: 72 66 6f 72 6d 73 20 74 68 65 20 6f 70 70 6f 73  rforms the oppos
36e0: 69 74 65 20 74 61 73 6b 2c 20 69 2e 65 2e 20 69  ite task, i.e. i
36f0: 74 20 65 78 70 6f 72 74 73 20 61 20 77 68 6f 6c  t exports a whol
3700: 65 20 42 4c 4f 42 20 69 6e 74 6f 20 61 6e 20 65  e BLOB into an e
3710: 78 74 65 72 6e 61 6c 20 66 69 6c 65 3b 20 74 68  xternal file; th
3720: 65 20 66 69 72 73 74 20 61 72 67 75 6d 65 6e 74  e first argument
3730: 20 6d 75 73 74 20 63 6f 72 72 65 73 70 6f 6e 64   must correspond
3740: 20 74 6f 20 73 6f 6d 65 20 42 4c 4f 42 2c 20 74   to some BLOB, t
3750: 68 65 20 73 65 63 6f 6e 64 20 6f 6e 65 20 69 73  he second one is
3760: 20 74 68 65 20 3c 62 3e 66 69 6c 65 2d 70 61 74   the <b>file-pat
3770: 68 3c 2f 62 3e 20 69 64 65 6e 74 69 66 79 69 6e  h</b> identifyin
3780: 67 20 74 68 65 20 66 69 6c 65 20 74 6f 20 62 65  g the file to be
3790: 20 63 72 65 61 74 65 64 20 6f 72 20 6f 76 65 72   created or over
37a0: 77 72 69 74 74 65 6e 2e 3c 62 72 3e 3c 62 72 3e  written.<br><br>
37b0: 0d 0a 3c 75 3e 50 6c 65 61 73 65 20 6e 6f 74 65  ..<u>Please note
37c0: 3c 2f 75 3e 3a 20 62 6f 74 68 20 3c 62 3e 42 6c  </u>: both <b>Bl
37d0: 6f 62 46 72 6f 6d 46 69 6c 65 28 29 3c 2f 62 3e  obFromFile()</b>
37e0: 20 61 6e 64 20 3c 62 3e 42 6c 6f 62 54 6f 46 69   and <b>BlobToFi
37f0: 6c 65 28 29 3c 2f 62 3e 20 77 65 72 65 20 61 6c  le()</b> were al
3800: 72 65 61 64 79 20 73 75 70 70 6f 72 74 65 64 20  ready supported 
3810: 62 79 20 34 2e 30 2e 30 2c 20 62 75 74 20 61 20  by 4.0.0, but a 
3820: 71 75 69 63 6b 20 72 65 63 61 6c 6c 20 69 73 20  quick recall is 
3830: 61 6e 79 77 61 79 20 75 73 65 66 75 6c 20 73 6f  anyway useful so
3840: 20 74 6f 20 72 65 63 61 6c 6c 20 61 20 63 6c 65   to recall a cle
3850: 61 72 65 72 20 63 6f 6e 74 65 78 74 2e 0d 0a 3c  arer context...<
3860: 68 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d  hr>..<verbatim>.
3870: 0a 53 45 4c 45 43 54 20 58 42 5f 4c 6f 61 64 58  .SELECT XB_LoadX
3880: 4d 4c 28 20 27 43 3a 2f 6d 79 64 6f 63 73 2f 69  ML( 'C:/mydocs/i
3890: 73 6f 6d 65 74 61 64 61 74 61 2d 73 61 6d 70 6c  sometadata-sampl
38a0: 65 2e 78 6d 6c 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d  e.xml' );..-----
38b0: 2d 2d 2d 0d 0a 42 4c 4f 42 2d 76 61 6c 75 65 0d  ---..BLOB-value.
38c0: 0a 0d 0a 53 45 4c 45 43 54 20 58 42 5f 4c 6f 61  ...SELECT XB_Loa
38d0: 64 58 4d 4c 28 20 27 68 74 74 70 3a 2f 2f 77 77  dXML( 'http://ww
38e0: 77 2e 61 63 6d 65 2e 63 6f 6d 2f 70 75 62 6c 69  w.acme.com/publi
38f0: 63 2f 69 73 6f 6d 65 74 61 64 61 74 61 2d 73 61  c/isometadata-sa
3900: 6d 70 6c 65 2e 78 6d 6c 27 20 29 3b 0d 0a 2d 2d  mple.xml' );..--
3910: 2d 2d 2d 2d 2d 2d 0d 0a 42 4c 4f 42 2d 76 61 6c  ------..BLOB-val
3920: 75 65 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d  ue..</verbatim>.
3930: 0a 54 68 65 20 3c 62 3e 58 42 5f 4c 6f 61 64 58  .The <b>XB_LoadX
3940: 4d 4c 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e  ML()</b> SQL fun
3950: 63 74 69 6f 6e 20 61 6c 6c 6f 77 73 20 74 6f 20  ction allows to 
3960: 69 6d 70 6f 72 74 20 61 6e 20 58 4d 4c 20 44 6f  import an XML Do
3970: 63 75 6d 65 6e 74 20 69 6e 20 61 20 73 69 6e 67  cument in a sing
3980: 6c 65 20 73 74 65 70 3a 20 74 68 65 20 66 75 6c  le step: the ful
3990: 6c 20 58 4d 4c 20 44 6f 63 75 6d 65 6e 74 20 70  l XML Document p
39a0: 61 79 6c 6f 61 64 20 77 69 6c 6c 20 62 65 20 72  ayload will be r
39b0: 65 74 75 72 6e 65 64 20 61 73 20 61 20 42 4c 4f  eturned as a BLO
39c0: 42 20 76 61 6c 75 65 2e 3c 62 72 3e 0d 0a 54 68  B value.<br>..Th
39d0: 65 20 70 61 73 73 65 64 20 61 72 67 75 6d 65 6e  e passed argumen
39e0: 74 20 63 61 6e 20 69 6e 64 69 66 66 65 72 65 6e  t can indifferen
39f0: 74 6c 79 20 62 65 20 61 20 3c 62 3e 66 69 6c 65  tly be a <b>file
3a00: 2d 70 61 74 68 3c 2f 62 3e 20 6f 72 20 61 20 3c  -path</b> or a <
3a10: 62 3e 55 52 4c 3c 2f 62 3e 3b 20 69 66 20 74 68  b>URL</b>; if th
3a20: 65 20 64 61 74 61 73 6f 75 72 63 65 20 63 61 6e  e datasource can
3a30: 6e 6f 74 20 62 65 20 61 63 63 65 73 73 65 64 2c  not be accessed,
3a40: 20 6f 72 20 69 66 20 69 74 20 64 6f 65 73 6e 27   or if it doesn'
3a50: 74 20 63 6f 6e 74 61 69 6e 73 20 61 20 3c 75 3e  t contains a <u>
3a60: 77 65 6c 6c 2d 66 6f 72 6d 65 64 3c 2f 75 3e 20  well-formed</u> 
3a70: 58 4d 4c 20 44 6f 63 75 6d 65 6e 74 20 4e 55 4c  XML Document NUL
3a80: 4c 20 77 69 6c 6c 20 62 65 20 72 65 74 75 72 6e  L will be return
3a90: 65 64 2e 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62  ed...<hr>..<verb
3aa0: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 58 42  atim>..SELECT XB
3ab0: 5f 53 74 6f 72 65 58 4d 4c 28 20 73 6f 6d 65 58  _StoreXML( someX
3ac0: 6d 6c 42 6c 6f 62 2c 20 27 43 3a 2f 6d 79 64 6f  mlBlob, 'C:/mydo
3ad0: 63 73 2f 69 73 6f 6d 65 74 61 64 61 74 61 2d 73  cs/isometadata-s
3ae0: 61 6d 70 6c 65 2e 78 6d 6c 27 20 29 3b 0d 0a 2d  ample.xml' );..-
3af0: 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76  --------..1..</v
3b00: 65 72 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62  erbatim>..The <b
3b10: 3e 58 42 5f 53 74 6f 72 65 58 4d 4c 28 29 3c 2f  >XB_StoreXML()</
3b20: 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20  b> SQL function 
3b30: 70 65 72 66 6f 72 6d 73 20 74 68 65 20 6f 70 70  performs the opp
3b40: 6f 73 69 74 65 20 74 61 73 6b 2c 20 69 2e 65 2e  osite task, i.e.
3b50: 20 69 74 20 65 78 70 6f 72 74 73 20 61 20 77 68   it exports a wh
3b60: 6f 6c 65 20 58 6d 6c 42 4c 4f 42 20 69 6e 74 6f  ole XmlBLOB into
3b70: 20 61 6e 20 65 78 74 65 72 6e 61 6c 20 66 69 6c   an external fil
3b80: 65 20 61 73 20 61 6e 20 58 4d 4c 20 44 6f 63 75  e as an XML Docu
3b90: 6d 65 6e 74 3b 20 74 68 65 20 66 69 72 73 74 20  ment; the first 
3ba0: 61 72 67 75 6d 65 6e 74 20 6d 75 73 74 20 63 6f  argument must co
3bb0: 72 72 65 73 70 6f 6e 64 20 74 6f 20 73 6f 6d 65  rrespond to some
3bc0: 20 76 61 6c 69 64 20 58 6d 6c 42 4c 4f 42 2c 20   valid XmlBLOB, 
3bd0: 74 68 65 20 73 65 63 6f 6e 64 20 6f 6e 65 20 69  the second one i
3be0: 73 20 74 68 65 20 3c 62 3e 66 69 6c 65 2d 70 61  s the <b>file-pa
3bf0: 74 68 3c 2f 62 3e 20 69 64 65 6e 74 69 66 79 69  th</b> identifyi
3c00: 6e 67 20 74 68 65 20 66 69 6c 65 20 74 6f 20 62  ng the file to b
3c10: 65 20 63 72 65 61 74 65 64 20 6f 72 20 6f 76 65  e created or ove
3c20: 72 77 72 69 74 74 65 6e 2e 20 0d 0a 3c 76 65 72  rwritten. ..<ver
3c30: 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 58  batim>..SELECT X
3c40: 42 5f 53 74 6f 72 65 58 4d 4c 28 20 73 6f 6d 65  B_StoreXML( some
3c50: 58 6d 6c 42 6c 6f 62 2c 20 27 43 3a 2f 6d 79 64  XmlBlob, 'C:/myd
3c60: 6f 63 73 2f 69 73 6f 6d 65 74 61 64 61 74 61 2d  ocs/isometadata-
3c70: 73 61 6d 70 6c 65 2e 78 6d 6c 27 2c 20 34 20 29  sample.xml', 4 )
3c80: 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 0d  ;..---------..1.
3c90: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 41 20  .</verbatim>..A 
3ca0: 66 75 72 74 68 65 72 20 6f 70 74 69 6f 6e 61 6c  further optional
3cb0: 20 3c 62 3e 69 6e 64 65 6e 74 61 74 69 6f 6e 3c   <b>indentation<
3cc0: 2f 62 3e 20 61 72 67 75 6d 65 6e 74 20 63 61 6e  /b> argument can
3cd0: 20 62 65 20 65 76 65 6e 74 75 61 6c 6c 79 20 73   be eventually s
3ce0: 70 65 63 69 66 69 65 64 3b 20 74 68 69 73 20 61  pecified; this a
3cf0: 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20 62 65 20  rgument will be 
3d00: 68 61 6e 64 6c 65 64 20 65 78 61 63 74 6c 79 20  handled exactly 
3d10: 69 6e 20 74 68 65 20 73 61 6d 65 20 77 61 79 20  in the same way 
3d20: 61 6c 72 65 61 64 79 20 73 70 65 63 69 66 69 65  already specifie
3d30: 64 20 66 6f 72 20 62 6f 74 68 20 3c 62 3e 58 42  d for both <b>XB
3d40: 5f 47 65 74 50 61 79 6c 6f 61 64 28 29 3c 2f 62  _GetPayload()</b
3d50: 3e 20 61 6e 64 20 3c 62 3e 58 42 5f 47 65 74 44  > and <b>XB_GetD
3d60: 6f 63 75 6d 65 6e 74 28 29 3c 2f 62 3e 20 66 75  ocument()</b> fu
3d70: 6e 63 74 69 6f 6e 73 2e 20 0d 0a 3c 68 72 3e 3c  nctions. ..<hr><
3d80: 62 72 3e 0d 0a 62 61 63 6b 20 74 6f 20 58 6d 6c  br>..back to Xml
3d90: 42 6c 6f 62 20 3c 61 20 68 72 65 66 3d 22 68 74  Blob <a href="ht
3da0: 74 70 73 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67  tps://www.gaia-g
3db0: 69 73 2e 69 74 2f 66 6f 73 73 69 6c 2f 6c 69 62  is.it/fossil/lib
3dc0: 73 70 61 74 69 61 6c 69 74 65 2f 77 69 6b 69 3f  spatialite/wiki?
3dd0: 6e 61 6d 65 3d 58 6d 6c 42 6c 6f 62 2b 61 6e 64  name=XmlBlob+and
3de0: 2b 56 69 72 74 75 61 6c 58 50 61 74 68 22 3e 6d  +VirtualXPath">m
3df0: 61 69 6e 20 70 61 67 65 3c 2f 61 3e 0a 5a 20 35  ain page</a>.Z 5
3e00: 35 62 31 38 62 35 35 65 36 30 31 61 37 34 37 37  5b18b55e601a7477
3e10: 65 30 30 37 34 37 66 34 66 30 34 66 63 63 65 0a  e00747f4f04fcce.