Wiki page
[4.1.0 Changes] by
sandro
2013-03-10 15:55:43.
0000: 44 20 32 30 31 33 2d 30 33 2d 31 30 54 31 35 3a D 2013-03-10T15:
0010: 35 35 3a 34 33 2e 31 35 31 0a 4c 20 34 2e 31 2e 55:43.151.L 4.1.
0020: 30 5c 73 43 68 61 6e 67 65 73 0a 50 20 36 64 64 0\sChanges.P 6dd
0030: 34 65 66 35 30 63 62 32 65 38 31 31 30 33 39 62 4ef50cb2e811039b
0040: 64 63 62 30 30 34 63 61 31 35 66 65 61 37 31 36 dcb004ca15fea716
0050: 31 32 65 38 62 0a 55 20 73 61 6e 64 72 6f 0a 57 12e8b.U sandro.W
0060: 20 31 34 37 38 37 0a 62 61 63 6b 20 74 6f 20 58 14787.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 74 79 70 tim>..SELECT typ
2fb0: 65 2c 20 6e 61 6d 65 2c 20 74 62 6c 5f 6e 61 6d e, name, tbl_nam
2fc0: 65 2c 20 73 71 6c 20 0d 0a 46 52 4f 4d 20 73 71 e, sql ..FROM sq
2fd0: 6c 69 74 65 5f 6d 61 73 74 65 72 20 0d 0a 57 48 lite_master ..WH
2fe0: 45 52 45 20 74 79 70 65 20 49 4e 20 28 27 74 72 ERE type IN ('tr
2ff0: 69 67 67 65 72 27 2c 20 27 76 69 65 77 27 29 20 igger', 'view')
3000: 41 4e 44 20 28 73 71 6c 20 4c 49 4b 45 20 27 25 AND (sql LIKE '%
3010: 42 6c 6f 62 46 72 6f 6d 46 69 6c 65 25 27 20 0d BlobFromFile%' .
3020: 0a 20 20 20 4f 52 20 73 71 6c 20 4c 49 4b 45 20 . OR sql LIKE
3030: 27 25 42 6c 6f 62 54 6f 46 69 6c 65 25 27 20 4f '%BlobToFile%' O
3040: 52 20 73 71 6c 20 4c 49 4b 45 20 27 25 58 42 5f R sql LIKE '%XB_
3050: 4c 6f 61 64 58 4d 4c 25 27 20 0d 0a 20 20 20 4f LoadXML%' .. O
3060: 52 20 73 71 6c 20 4c 49 4b 45 20 27 25 58 42 5f R sql LIKE '%XB_
3070: 53 74 6f 72 65 58 4d 4c 25 27 29 3b 0d 0a 3c 2f StoreXML%');..</
3080: 76 65 72 62 61 74 69 6d 3e 0d 0a 74 68 69 73 20 verbatim>..this
3090: 77 69 6c 6c 20 67 69 76 65 20 61 20 66 75 6c 6c will give a full
30a0: 20 72 65 70 6f 72 74 20 66 6f 72 20 61 6e 79 20 report for any
30b0: 6d 61 6c 69 63 69 6f 75 73 20 54 72 69 67 67 65 malicious Trigge
30c0: 72 20 65 76 65 6e 74 75 61 6c 6c 79 20 66 6f 75 r eventually fou
30d0: 6e 64 2e 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 nd...<hr>..<verb
30e0: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 42 6c atim>..SELECT Bl
30f0: 6f 62 46 72 6f 6d 46 69 6c 65 28 20 27 43 3a 2f obFromFile( 'C:/
3100: 6d 79 70 69 63 74 75 72 65 73 2f 73 75 6e 73 65 mypictures/sunse
3110: 74 2e 6a 70 67 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d t.jpg' );..-----
3120: 2d 2d 2d 2d 0d 0a 42 4c 4f 42 2d 76 61 6c 75 65 ----..BLOB-value
3130: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 ..</verbatim>..T
3140: 68 65 20 3c 62 3e 42 6c 6f 62 46 72 6f 6d 46 69 he <b>BlobFromFi
3150: 6c 65 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e le()</b> SQL fun
3160: 63 74 69 6f 6e 20 61 6c 6c 6f 77 73 20 74 6f 20 ction allows to
3170: 69 6d 70 6f 72 74 20 61 20 77 68 6f 6c 65 20 66 import a whole f
3180: 69 6c 65 20 69 6e 20 61 20 73 69 6e 67 6c 65 20 ile in a single
3190: 73 74 65 70 3b 20 74 68 65 20 66 75 6c 6c 20 66 step; the full f
31a0: 69 6c 65 20 70 61 79 6c 6f 61 64 20 77 69 6c 6c ile payload will
31b0: 20 62 65 20 72 65 74 75 72 6e 65 64 20 61 73 20 be returned as
31c0: 61 20 42 4c 4f 42 20 76 61 6c 75 65 2e 3c 62 72 a BLOB value.<br
31d0: 3e 0d 0a 49 66 20 74 68 65 20 61 72 67 75 6d 65 >..If the argume
31e0: 6e 74 20 28 3c 62 3e 66 69 6c 65 2d 70 61 74 68 nt (<b>file-path
31f0: 3c 2f 62 3e 29 20 64 6f 65 73 6e 27 74 20 63 6f </b>) doesn't co
3200: 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 61 20 76 rresponds to a v
3210: 61 6c 69 64 20 66 69 6c 65 20 6f 72 20 69 66 20 alid file or if
3220: 74 68 65 20 65 78 74 65 72 6e 61 6c 20 66 69 6c the external fil
3230: 65 20 63 61 6e 6e 6f 74 20 62 65 20 61 63 63 65 e cannot be acce
3240: 73 73 65 64 20 66 6f 72 20 61 6e 79 20 72 65 61 ssed for any rea
3250: 73 6f 6e 20 4e 55 4c 4c 20 77 69 6c 6c 20 62 65 son NULL will be
3260: 20 72 65 74 75 72 6e 65 64 2e 20 0d 0a 3c 68 72 returned. ..<hr
3270: 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 >..<verbatim>..S
3280: 45 4c 45 43 54 20 42 6c 6f 62 54 6f 46 69 6c 65 ELECT BlobToFile
3290: 28 20 73 6f 6d 65 42 6c 6f 62 20 2c 20 27 43 3a ( someBlob , 'C:
32a0: 2f 6d 79 70 69 63 74 75 72 65 73 2f 73 75 6e 73 /mypictures/suns
32b0: 65 74 2e 6a 70 67 27 20 29 3b 0d 0a 2d 2d 2d 2d et.jpg' );..----
32c0: 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 -----..1..</verb
32d0: 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 42 6c atim>..The <b>Bl
32e0: 6f 62 54 6f 46 69 6c 65 28 29 3c 2f 62 3e 20 53 obToFile()</b> S
32f0: 51 4c 20 66 75 6e 63 74 69 6f 6e 20 70 65 72 66 QL function perf
3300: 6f 72 6d 73 20 74 68 65 20 6f 70 70 6f 73 69 74 orms the opposit
3310: 65 20 74 61 73 6b 2c 20 69 2e 65 2e 20 69 74 20 e task, i.e. it
3320: 65 78 70 6f 72 74 73 20 61 20 77 68 6f 6c 65 20 exports a whole
3330: 42 4c 4f 42 20 69 6e 74 6f 20 61 6e 20 65 78 74 BLOB into an ext
3340: 65 72 6e 61 6c 20 66 69 6c 65 3b 20 74 68 65 20 ernal file; the
3350: 66 69 72 73 74 20 61 72 67 75 6d 65 6e 74 20 6d first argument m
3360: 75 73 74 20 63 6f 72 72 65 73 70 6f 6e 64 20 74 ust correspond t
3370: 6f 20 73 6f 6d 65 20 42 4c 4f 42 2c 20 74 68 65 o some BLOB, the
3380: 20 73 65 63 6f 6e 64 20 6f 6e 65 20 69 73 20 74 second one is t
3390: 68 65 20 3c 62 3e 66 69 6c 65 2d 70 61 74 68 3c he <b>file-path<
33a0: 2f 62 3e 20 69 64 65 6e 74 69 66 79 69 6e 67 20 /b> identifying
33b0: 74 68 65 20 66 69 6c 65 20 74 6f 20 62 65 20 63 the file to be c
33c0: 72 65 61 74 65 64 20 6f 72 20 6f 76 65 72 77 72 reated or overwr
33d0: 69 74 74 65 6e 2e 3c 62 72 3e 3c 62 72 3e 0d 0a itten.<br><br>..
33e0: 3c 75 3e 50 6c 65 61 73 65 20 6e 6f 74 65 3c 2f <u>Please note</
33f0: 75 3e 3a 20 62 6f 74 68 20 3c 62 3e 42 6c 6f 62 u>: both <b>Blob
3400: 46 72 6f 6d 46 69 6c 65 28 29 3c 2f 62 3e 20 61 FromFile()</b> a
3410: 6e 64 20 3c 62 3e 42 6c 6f 62 54 6f 46 69 6c 65 nd <b>BlobToFile
3420: 28 29 3c 2f 62 3e 20 77 65 72 65 20 61 6c 72 65 ()</b> were alre
3430: 61 64 79 20 73 75 70 70 6f 72 74 65 64 20 62 79 ady supported by
3440: 20 34 2e 30 2e 30 2c 20 62 75 74 20 61 20 71 75 4.0.0, but a qu
3450: 69 63 6b 20 72 65 63 61 6c 6c 20 69 73 20 61 6e ick recall is an
3460: 79 77 61 79 20 75 73 65 66 75 6c 20 73 6f 20 74 yway useful so t
3470: 6f 20 72 65 63 61 6c 6c 20 61 20 63 6c 65 61 72 o recall a clear
3480: 65 72 20 63 6f 6e 74 65 78 74 2e 0d 0a 3c 68 72 er context...<hr
3490: 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 >..<verbatim>..S
34a0: 45 4c 45 43 54 20 58 42 5f 4c 6f 61 64 58 4d 4c ELECT XB_LoadXML
34b0: 28 20 27 43 3a 2f 6d 79 64 6f 63 73 2f 69 73 6f ( 'C:/mydocs/iso
34c0: 6d 65 74 61 64 61 74 61 2d 73 61 6d 70 6c 65 2e metadata-sample.
34d0: 78 6d 6c 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d xml' );..-------
34e0: 2d 0d 0a 42 4c 4f 42 2d 76 61 6c 75 65 0d 0a 0d -..BLOB-value...
34f0: 0a 53 45 4c 45 43 54 20 58 42 5f 4c 6f 61 64 58 .SELECT XB_LoadX
3500: 4d 4c 28 20 27 68 74 74 70 3a 2f 2f 77 77 77 2e ML( 'http://www.
3510: 61 63 6d 65 2e 63 6f 6d 2f 70 75 62 6c 69 63 2f acme.com/public/
3520: 69 73 6f 6d 65 74 61 64 61 74 61 2d 73 61 6d 70 isometadata-samp
3530: 6c 65 2e 78 6d 6c 27 20 29 3b 0d 0a 2d 2d 2d 2d le.xml' );..----
3540: 2d 2d 2d 2d 0d 0a 42 4c 4f 42 2d 76 61 6c 75 65 ----..BLOB-value
3550: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 ..</verbatim>..T
3560: 68 65 20 3c 62 3e 58 42 5f 4c 6f 61 64 58 4d 4c he <b>XB_LoadXML
3570: 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 ()</b> SQL funct
3580: 69 6f 6e 20 61 6c 6c 6f 77 73 20 74 6f 20 69 6d ion allows to im
3590: 70 6f 72 74 20 61 6e 20 58 4d 4c 20 44 6f 63 75 port an XML Docu
35a0: 6d 65 6e 74 20 69 6e 20 61 20 73 69 6e 67 6c 65 ment in a single
35b0: 20 73 74 65 70 3a 20 74 68 65 20 66 75 6c 6c 20 step: the full
35c0: 58 4d 4c 20 44 6f 63 75 6d 65 6e 74 20 70 61 79 XML Document pay
35d0: 6c 6f 61 64 20 77 69 6c 6c 20 62 65 20 72 65 74 load will be ret
35e0: 75 72 6e 65 64 20 61 73 20 61 20 42 4c 4f 42 20 urned as a BLOB
35f0: 76 61 6c 75 65 2e 3c 62 72 3e 0d 0a 54 68 65 20 value.<br>..The
3600: 70 61 73 73 65 64 20 61 72 67 75 6d 65 6e 74 20 passed argument
3610: 63 61 6e 20 69 6e 64 69 66 66 65 72 65 6e 74 6c can indifferentl
3620: 79 20 62 65 20 61 20 3c 62 3e 66 69 6c 65 2d 70 y be a <b>file-p
3630: 61 74 68 3c 2f 62 3e 20 6f 72 20 61 20 3c 62 3e ath</b> or a <b>
3640: 55 52 4c 3c 2f 62 3e 3b 20 69 66 20 74 68 65 20 URL</b>; if the
3650: 64 61 74 61 73 6f 75 72 63 65 20 63 61 6e 6e 6f datasource canno
3660: 74 20 62 65 20 61 63 63 65 73 73 65 64 2c 20 6f t be accessed, o
3670: 72 20 69 66 20 69 74 20 64 6f 65 73 6e 27 74 20 r if it doesn't
3680: 63 6f 6e 74 61 69 6e 73 20 61 20 3c 75 3e 77 65 contains a <u>we
3690: 6c 6c 2d 66 6f 72 6d 65 64 3c 2f 75 3e 20 58 4d ll-formed</u> XM
36a0: 4c 20 44 6f 63 75 6d 65 6e 74 20 4e 55 4c 4c 20 L Document NULL
36b0: 77 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 will be returned
36c0: 2e 0d 0a 3c 68 72 3e 0d 0a 3c 76 65 72 62 61 74 ...<hr>..<verbat
36d0: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 58 42 5f 53 im>..SELECT XB_S
36e0: 74 6f 72 65 58 4d 4c 28 20 73 6f 6d 65 58 6d 6c toreXML( someXml
36f0: 42 6c 6f 62 2c 20 27 43 3a 2f 6d 79 64 6f 63 73 Blob, 'C:/mydocs
3700: 2f 69 73 6f 6d 65 74 61 64 61 74 61 2d 73 61 6d /isometadata-sam
3710: 70 6c 65 2e 78 6d 6c 27 20 29 3b 0d 0a 2d 2d 2d ple.xml' );..---
3720: 2d 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 ------..1..</ver
3730: 62 61 74 69 6d 3e 0d 0a 54 68 65 20 3c 62 3e 58 batim>..The <b>X
3740: 42 5f 53 74 6f 72 65 58 4d 4c 28 29 3c 2f 62 3e B_StoreXML()</b>
3750: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 70 65 SQL function pe
3760: 72 66 6f 72 6d 73 20 74 68 65 20 6f 70 70 6f 73 rforms the oppos
3770: 69 74 65 20 74 61 73 6b 2c 20 69 2e 65 2e 20 69 ite task, i.e. i
3780: 74 20 65 78 70 6f 72 74 73 20 61 20 77 68 6f 6c t exports a whol
3790: 65 20 58 6d 6c 42 4c 4f 42 20 69 6e 74 6f 20 61 e XmlBLOB into a
37a0: 6e 20 65 78 74 65 72 6e 61 6c 20 66 69 6c 65 20 n external file
37b0: 61 73 20 61 6e 20 58 4d 4c 20 44 6f 63 75 6d 65 as an XML Docume
37c0: 6e 74 3b 20 74 68 65 20 66 69 72 73 74 20 61 72 nt; the first ar
37d0: 67 75 6d 65 6e 74 20 6d 75 73 74 20 63 6f 72 72 gument must corr
37e0: 65 73 70 6f 6e 64 20 74 6f 20 73 6f 6d 65 20 76 espond to some v
37f0: 61 6c 69 64 20 58 6d 6c 42 4c 4f 42 2c 20 74 68 alid XmlBLOB, th
3800: 65 20 73 65 63 6f 6e 64 20 6f 6e 65 20 69 73 20 e second one is
3810: 74 68 65 20 3c 62 3e 66 69 6c 65 2d 70 61 74 68 the <b>file-path
3820: 3c 2f 62 3e 20 69 64 65 6e 74 69 66 79 69 6e 67 </b> identifying
3830: 20 74 68 65 20 66 69 6c 65 20 74 6f 20 62 65 20 the file to be
3840: 63 72 65 61 74 65 64 20 6f 72 20 6f 76 65 72 77 created or overw
3850: 72 69 74 74 65 6e 2e 20 0d 0a 3c 76 65 72 62 61 ritten. ..<verba
3860: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 58 42 5f tim>..SELECT XB_
3870: 53 74 6f 72 65 58 4d 4c 28 20 73 6f 6d 65 58 6d StoreXML( someXm
3880: 6c 42 6c 6f 62 2c 20 27 43 3a 2f 6d 79 64 6f 63 lBlob, 'C:/mydoc
3890: 73 2f 69 73 6f 6d 65 74 61 64 61 74 61 2d 73 61 s/isometadata-sa
38a0: 6d 70 6c 65 2e 78 6d 6c 27 2c 20 34 20 29 3b 0d mple.xml', 4 );.
38b0: 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c .---------..1..<
38c0: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 41 20 66 75 /verbatim>..A fu
38d0: 72 74 68 65 72 20 6f 70 74 69 6f 6e 61 6c 20 3c rther optional <
38e0: 62 3e 69 6e 64 65 6e 74 61 74 69 6f 6e 3c 2f 62 b>indentation</b
38f0: 3e 20 61 72 67 75 6d 65 6e 74 20 63 61 6e 20 62 > argument can b
3900: 65 20 65 76 65 6e 74 75 61 6c 6c 79 20 73 70 65 e eventually spe
3910: 63 69 66 69 65 64 3b 20 74 68 69 73 20 61 72 67 cified; this arg
3920: 75 6d 65 6e 74 20 77 69 6c 6c 20 62 65 20 68 61 ument will be ha
3930: 6e 64 6c 65 64 20 65 78 61 63 74 6c 79 20 69 6e ndled exactly in
3940: 20 74 68 65 20 73 61 6d 65 20 77 61 79 20 61 6c the same way al
3950: 72 65 61 64 79 20 73 70 65 63 69 66 69 65 64 20 ready specified
3960: 66 6f 72 20 62 6f 74 68 20 3c 62 3e 58 42 5f 47 for both <b>XB_G
3970: 65 74 50 61 79 6c 6f 61 64 28 29 3c 2f 62 3e 20 etPayload()</b>
3980: 61 6e 64 20 3c 62 3e 58 42 5f 47 65 74 44 6f 63 and <b>XB_GetDoc
3990: 75 6d 65 6e 74 28 29 3c 2f 62 3e 20 66 75 6e 63 ument()</b> func
39a0: 74 69 6f 6e 73 2e 20 0d 0a 3c 68 72 3e 3c 62 72 tions. ..<hr><br
39b0: 3e 0d 0a 62 61 63 6b 20 74 6f 20 58 6d 6c 42 6c >..back to XmlBl
39c0: 6f 62 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 ob <a href="http
39d0: 73 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73 s://www.gaia-gis
39e0: 2e 69 74 2f 66 6f 73 73 69 6c 2f 6c 69 62 73 70 .it/fossil/libsp
39f0: 61 74 69 61 6c 69 74 65 2f 77 69 6b 69 3f 6e 61 atialite/wiki?na
3a00: 6d 65 3d 58 6d 6c 42 6c 6f 62 2b 61 6e 64 2b 56 me=XmlBlob+and+V
3a10: 69 72 74 75 61 6c 58 50 61 74 68 22 3e 6d 61 69 irtualXPath">mai
3a20: 6e 20 70 61 67 65 3c 2f 61 3e 0a 5a 20 65 39 38 n page</a>.Z e98
3a30: 65 37 62 36 36 65 33 34 37 62 66 39 30 65 63 30 e7b66e347bf90ec0
3a40: 33 64 33 35 64 31 30 38 65 32 37 38 39 0a 3d35d108e2789.