Hex Artifact Content
Not logged in

Artifact 39be82c165be7a6771dbd093cbeec62dd8a48c75:

Wiki page [Stored Procedures] by sandro 2017-11-30 09:03:44.
0000: 44 20 32 30 31 37 2d 31 31 2d 33 30 54 30 39 3a  D 2017-11-30T09:
0010: 30 33 3a 34 34 2e 39 38 39 0a 4c 20 53 74 6f 72  03:44.989.L Stor
0020: 65 64 5c 73 50 72 6f 63 65 64 75 72 65 73 0a 50  ed\sProcedures.P
0030: 20 62 63 62 61 63 39 36 35 35 61 32 35 34 34 37   bcbac9655a25447
0040: 31 61 36 31 61 62 37 36 32 63 36 63 65 31 32 30  1a61ab762c6ce120
0050: 63 31 61 61 35 39 63 38 34 0a 55 20 73 61 6e 64  c1aa59c84.U sand
0060: 72 6f 0a 57 20 32 39 33 39 36 0a 3c 74 61 62 6c  ro.W 29396.<tabl
0070: 65 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 31  e cellspacing="1
0080: 32 22 20 77 69 64 74 68 3d 22 31 30 30 25 22 3e  2" width="100%">
0090: 0d 0a 3c 74 72 3e 3c 74 64 20 63 6f 6c 73 70 61  ..<tr><td colspa
00a0: 6e 3d 22 32 22 3e 0d 0a 3c 74 61 62 6c 65 20 77  n="2">..<table w
00b0: 69 64 74 68 3d 22 31 30 30 25 22 20 62 67 63 6f  idth="100%" bgco
00c0: 6c 6f 72 3d 22 23 66 30 66 30 66 38 22 3e 0d 0a  lor="#f0f0f8">..
00d0: 3c 74 72 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 63  <tr><td align="c
00e0: 65 6e 74 65 72 22 3e 0d 0a 3c 2f 74 64 3e 3c 2f  enter">..</td></
00f0: 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 74 61  tr></table>..<ta
0100: 62 6c 65 20 77 69 64 74 68 3d 22 31 30 30 25 22  ble width="100%"
0110: 3e 3c 74 72 3e 0d 0a 3c 74 64 20 77 69 64 74 68  ><tr>..<td width
0120: 3d 22 33 33 25 22 20 61 6c 69 67 6e 3d 22 6c 65  ="33%" align="le
0130: 66 74 22 3e 3c 2f 74 64 3e 0d 0a 3c 74 64 20 61  ft"></td>..<td a
0140: 6c 69 67 6e 3d 22 63 65 6e 74 65 72 22 3e 3c 61  lign="center"><a
0150: 20 68 72 65 66 3d 22 68 74 74 70 73 3a 2f 2f 77   href="https://w
0160: 77 77 2e 67 61 69 61 2d 67 69 73 2e 69 74 2f 66  ww.gaia-gis.it/f
0170: 6f 73 73 69 6c 2f 6c 69 62 73 70 61 74 69 61 6c  ossil/libspatial
0180: 69 74 65 2f 77 69 6b 69 3f 6e 61 6d 65 3d 34 2e  ite/wiki?name=4.
0190: 33 2e 30 2b 64 6f 63 22 3e 62 61 63 6b 20 74 6f  3.0+doc">back to
01a0: 20 69 6e 64 65 78 3c 2f 61 3e 3c 2f 74 64 3e 0d   index</a></td>.
01b0: 0a 3c 74 64 20 77 69 64 74 68 3d 22 33 33 25 22  .<td width="33%"
01c0: 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 3c   align="right"><
01d0: 2f 74 64 3e 0d 0a 3c 2f 74 72 3e 3c 2f 74 61 62  /td>..</tr></tab
01e0: 6c 65 3e 0d 0a 3c 68 31 3e 53 51 4c 20 50 72 6f  le>..<h1>SQL Pro
01f0: 63 65 64 75 72 65 73 2c 20 53 74 6f 72 65 64 20  cedures, Stored 
0200: 50 72 6f 63 65 64 75 72 65 73 20 61 6e 64 20 53  Procedures and S
0210: 74 6f 72 65 64 20 56 61 72 69 61 62 6c 65 73 3a  tored Variables:
0220: 20 61 20 71 75 69 63 6b 20 69 6e 74 72 6f 3c 2f   a quick intro</
0230: 68 31 3e 0d 0a 53 74 61 72 74 69 6e 67 20 77 69  h1>..Starting wi
0240: 74 68 20 76 65 72 73 69 6f 6e 20 3c 62 3e 34 2e  th version <b>4.
0250: 35 2e 30 3c 2f 62 3e 2c 20 53 70 61 74 69 61 4c  5.0</b>, SpatiaL
0260: 69 74 65 20 73 75 70 70 6f 72 74 73 20 61 6e 20  ite supports an 
0270: 61 64 76 61 6e 63 65 64 20 6d 65 63 68 61 6e 69  advanced mechani
0280: 73 6d 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 73  sm intended to s
0290: 69 67 6e 69 66 69 63 61 6e 74 6c 79 20 65 78 74  ignificantly ext
02a0: 65 6e 64 20 74 68 65 20 73 63 72 69 70 74 69 6e  end the scriptin
02b0: 67 20 74 65 63 68 6e 69 71 75 65 73 20 61 6c 6c  g techniques all
02c0: 6f 77 69 6e 67 20 66 6f 72 20 61 20 70 6f 77 65  owing for a powe
02d0: 72 66 75 6c 20 61 6e 64 20 66 6c 65 78 69 62 6c  rful and flexibl
02e0: 65 20 61 75 74 6f 6d 61 74 69 6f 6e 20 6f 66 20  e automation of 
02f0: 63 6f 6d 70 6c 65 78 20 77 6f 72 6b 66 6c 6f 77  complex workflow
0300: 73 2e 3c 62 72 3e 0d 0a 54 68 69 6e 6b 20 6f 66  s.<br>..Think of
0310: 20 74 68 65 20 6e 69 63 65 20 66 6c 65 78 69 62   the nice flexib
0320: 69 6c 69 74 79 20 70 6f 73 73 69 62 6c 65 2c 20  ility possible, 
0330: 62 79 20 6d 69 78 69 6e 67 20 73 74 61 6e 64 61  by mixing standa
0340: 72 64 20 3c 62 3e 3c 69 3e 53 51 4c 20 73 63 72  rd <b><i>SQL scr
0350: 69 70 74 73 3c 2f 69 3e 3c 2f 62 3e 20 61 6e 64  ipts</i></b> and
0360: 20 3c 62 3e 3c 69 3e 56 61 72 69 61 62 6c 65 73   <b><i>Variables
0370: 3c 2f 69 3e 3c 2f 62 3e 20 77 68 69 63 68 20 61  </i></b> which a
0380: 72 65 20 72 65 70 6c 61 63 65 64 20 62 65 66 6f  re replaced befo
0390: 72 65 20 62 65 69 6e 67 20 65 78 65 63 75 74 65  re being execute
03a0: 64 2e 0d 0a 4e 6f 74 20 6f 6e 6c 79 20 74 68 61  d...Not only tha
03b0: 74 2c 20 62 75 74 20 74 68 69 6e 6b 20 6f 66 20  t, but think of 
03c0: 74 68 65 20 6d 61 6e 79 20 77 6f 6e 64 65 72 66  the many wonderf
03d0: 75 6c 20 6f 70 70 6f 72 74 75 6e 69 74 69 65 73  ul opportunities
03e0: 20 6f 66 66 65 72 65 64 20 62 79 20 70 65 72 6d   offered by perm
03f0: 61 6e 65 6e 74 6c 79 20 73 74 6f 72 69 6e 67 2c  anently storing,
0400: 20 77 69 74 68 69 6e 20 61 20 64 61 74 61 62 61   within a databa
0410: 73 65 2c 20 3c 62 3e 3c 69 3e 53 51 4c 20 53 63  se, <b><i>SQL Sc
0420: 72 69 70 74 73 20 77 69 74 68 20 56 61 72 69 61  ripts with Varia
0430: 62 6c 65 73 3c 2f 69 3e 3c 2f 62 3e 2c 20 73 69  bles</i></b>, si
0440: 6d 70 6c 69 66 79 69 6e 67 20 63 6f 6d 6d 6f 6e  mplifying common
0450: 20 61 75 74 6f 6d 61 74 65 64 20 77 6f 72 6b 66   automated workf
0460: 6c 6f 77 73 20 74 68 61 74 20 61 72 65 20 72 65  lows that are re
0470: 70 65 61 74 65 64 6c 79 20 65 78 65 63 75 74 65  peatedly execute
0480: 64 2e 20 54 68 69 73 20 69 73 20 65 78 61 63 74  d. This is exact
0490: 6c 79 20 74 68 65 20 69 6e 74 65 6e 64 65 64 20  ly the intended 
04a0: 73 63 6f 70 65 20 6f 66 20 74 68 69 73 20 6e 65  scope of this ne
04b0: 77 20 6d 6f 64 75 6c 65 2e 3c 62 72 3e 3c 62 72  w module.<br><br
04c0: 3e 0d 0a 57 65 27 6c 6c 20 73 74 61 72 74 20 66  >..We'll start f
04d0: 69 72 73 74 20 62 79 20 64 65 66 69 6e 69 6e 67  irst by defining
04e0: 20 61 20 66 65 77 20 62 61 73 69 63 20 63 6f 6e   a few basic con
04f0: 63 65 70 74 73 20 61 6e 64 20 6f 62 6a 65 63 74  cepts and object
0500: 69 76 65 73 2c 20 73 6f 20 61 73 20 74 6f 20 61  ives, so as to a
0510: 76 6f 69 64 20 61 6e 79 20 70 6f 73 73 69 62 6c  void any possibl
0520: 65 20 63 6f 6e 66 75 73 69 6f 6e 2e 3c 62 72 3e  e confusion.<br>
0530: 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 32 3e  <br>..<hr>..<h2>
0540: 42 61 73 69 63 20 44 65 66 69 6e 69 74 69 6f 6e  Basic Definition
0550: 73 20 61 6e 64 20 43 6f 6e 63 65 70 74 73 3c 2f  s and Concepts</
0560: 68 32 3e 0d 0a 3c 6f 6c 3e 0d 0a 3c 6c 69 3e 0d  h2>..<ol>..<li>.
0570: 0a 3c 68 34 3e 53 51 4c 20 53 74 61 74 65 6d 65  .<h4>SQL Stateme
0580: 6e 74 3c 2f 68 34 3e 0d 0a 54 68 65 20 6d 69 6e  nt</h4>..The min
0590: 69 6d 61 6c 20 65 78 65 63 75 74 69 6f 6e 20 75  imal execution u
05a0: 6e 69 74 20 61 6c 6c 6f 77 65 64 20 62 79 20 53  nit allowed by S
05b0: 51 4c 20 73 79 6e 74 61 78 3b 20 61 20 73 74 61  QL syntax; a sta
05c0: 6e 64 2d 61 6c 6f 6e 65 20 53 51 4c 20 64 69 72  nd-alone SQL dir
05d0: 65 63 74 69 76 65 20 74 6f 20 62 65 20 61 74 6f  ective to be ato
05e0: 6d 69 63 61 6c 6c 79 20 65 78 65 63 75 74 65 64  mically executed
05f0: 20 69 6e 20 61 20 73 69 6e 67 6c 65 20 73 74 65   in a single ste
0600: 70 2e 20 3c 62 72 3e 0d 0a 53 61 6d 70 6c 65 73  p. <br>..Samples
0610: 3a 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53  :..<verbatim>..S
0620: 45 4c 45 43 54 20 69 64 2c 20 6e 61 6d 65 2c 20  ELECT id, name, 
0630: 6d 65 61 73 75 72 65 20 46 52 4f 4d 20 73 6f 6d  measure FROM som
0640: 65 5f 74 61 62 6c 65 3b 0d 0a 2d 2d 2d 2d 2d 2d  e_table;..------
0650: 2d 2d 2d 2d 2d 2d 0d 0a 44 45 4c 45 54 45 20 46  ------..DELETE F
0660: 52 4f 4d 20 73 6f 6d 65 5f 74 61 62 6c 65 20 57  ROM some_table W
0670: 48 45 52 45 20 6d 65 61 73 75 72 65 20 3e 20 31  HERE measure > 1
0680: 30 30 30 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  000;..----------
0690: 2d 2d 0d 0a 55 50 44 41 54 45 20 73 6f 6d 65 5f  --..UPDATE some_
06a0: 74 61 62 6c 65 20 53 45 54 20 6d 65 61 73 75 72  table SET measur
06b0: 65 20 3d 20 6d 65 61 73 75 72 65 20 2f 20 31 30  e = measure / 10
06c0: 2e 30 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d  .0..</verbatim>.
06d0: 0a 3c 75 3e 4e 6f 74 65 3c 2f 75 3e 3a 20 53 51  .<u>Note</u>: SQ
06e0: 4c 20 53 74 61 74 65 6d 65 6e 74 73 20 61 72 65  L Statements are
06f0: 20 75 73 75 61 6c 6c 79 20 65 78 70 65 63 74 65   usually expecte
0700: 64 20 74 6f 20 62 65 20 65 78 70 6c 69 63 69 74  d to be explicit
0710: 6c 79 20 74 65 72 6d 69 6e 61 74 65 64 20 62 79  ly terminated by
0720: 20 61 20 3c 62 3e 3c 69 3e 73 65 6d 69 63 6f 6c   a <b><i>semicol
0730: 6f 6e 3c 2f 69 3e 3c 2f 62 3e 20 28 3c 62 3e 3c  on</i></b> (<b><
0740: 69 3e 3b 3c 2f 69 3e 3c 2f 62 3e 29 2e 3c 62 72  i>;</i></b>).<br
0750: 3e 0d 0a 54 68 65 20 73 65 6d 69 63 6f 6c 6f 6e  >..The semicolon
0760: 20 74 65 72 6d 69 6e 61 74 6f 72 20 63 61 6e 20   terminator can 
0770: 62 65 20 73 61 66 65 6c 79 20 73 75 70 70 72 65  be safely suppre
0780: 73 73 65 64 20 6f 6e 6c 79 20 77 68 65 6e 20 74  ssed only when t
0790: 68 65 20 53 51 4c 20 53 74 61 74 65 6d 65 6e 74  he SQL Statement
07a0: 20 69 73 20 69 6d 6d 65 64 69 61 74 65 6c 79 20   is immediately 
07b0: 66 6f 6c 6c 6f 77 65 64 20 62 79 20 61 20 73 74  followed by a st
07c0: 72 69 6e 67 20 74 65 72 6d 69 6e 61 74 6f 72 20  ring terminator 
07d0: 28 6c 65 61 64 69 6e 67 20 61 6e 64 20 74 72 61  (leading and tra
07e0: 69 6c 69 6e 67 20 73 65 71 75 65 6e 63 65 73 20  iling sequences 
07f0: 6f 66 20 61 6c 6c 20 3c 62 3e 3c 69 3e 62 6c 61  of all <b><i>bla
0800: 6e 6b 73 3c 2f 69 3e 3c 2f 62 3e 20 77 69 6c 6c  nks</i></b> will
0810: 20 62 65 20 61 6c 77 61 79 73 20 69 67 6e 6f 72   be always ignor
0820: 65 64 29 2e 0d 0a 3c 62 72 3e 3c 62 72 3e 3c 68  ed)...<br><br><h
0830: 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d  r>..</li>..<li>.
0840: 0a 3c 68 34 3e 53 51 4c 20 53 63 72 69 70 74 3c  .<h4>SQL Script<
0850: 2f 68 34 3e 0d 0a 41 20 6d 6f 72 65 20 6f 72 20  /h4>..A more or 
0860: 6c 65 73 73 20 63 6f 6d 70 6c 65 78 20 63 6f 6c  less complex col
0870: 6c 65 63 74 69 6f 6e 20 6f 66 20 3c 62 3e 3c 69  lection of <b><i
0880: 3e 53 51 4c 20 53 74 61 74 65 6d 65 6e 74 73 3c  >SQL Statements<
0890: 2f 69 3e 3c 2f 62 3e 2c 20 70 6f 73 73 69 62 6c  /i></b>, possibl
08a0: 79 20 69 6e 63 6c 75 64 69 6e 67 20 69 6e 74 65  y including inte
08b0: 72 6c 65 61 76 65 64 20 3c 62 3e 3c 69 3e 43 6f  rleaved <b><i>Co
08c0: 6d 6d 65 6e 74 73 3c 2f 69 3e 3c 2f 62 3e 20 61  mments</i></b> a
08d0: 6e 64 2f 6f 72 20 3c 62 3e 3c 69 3e 44 6f 74 20  nd/or <b><i>Dot 
08e0: 4d 61 63 72 6f 73 3c 2f 69 3e 3c 2f 62 3e 2e 3c  Macros</i></b>.<
08f0: 62 72 3e 0d 0a 53 51 4c 20 53 63 72 69 70 74 73  br>..SQL Scripts
0900: 20 61 72 65 20 69 6e 74 65 6e 64 65 64 20 74 6f   are intended to
0910: 20 62 65 20 65 78 65 63 75 74 65 64 20 69 6e 20   be executed in 
0920: 61 20 73 69 6e 67 6c 65 20 6d 6f 6e 6f 6c 69 74  a single monolit
0930: 68 69 63 20 70 61 73 73 20 28 61 74 6f 6d 69 63  hic pass (atomic
0940: 61 6c 6c 79 20 6f 72 20 6e 6f 74 2c 20 64 65 70  ally or not, dep
0950: 65 6e 64 69 6e 67 20 6f 6e 20 69 6e 74 65 72 6e  ending on intern
0960: 61 6c 20 3c 62 3e 3c 69 3e 54 72 61 6e 73 61 63  al <b><i>Transac
0970: 74 69 6f 6e 3c 2f 69 3e 3c 2f 62 3e 20 68 61 6e  tion</i></b> han
0980: 64 6c 69 6e 67 29 2e 20 45 78 61 6d 70 6c 65 3a  dling). Example:
0990: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 2e 65  ..<verbatim>...e
09a0: 63 68 6f 20 6f 6e 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d  cho on....--..--
09b0: 20 73 74 61 72 74 69 6e 67 20 61 20 54 72 61 6e   starting a Tran
09c0: 73 61 63 74 69 6f 6e 0d 0a 2d 2d 0d 0a 42 45 47  saction..--..BEG
09d0: 49 4e 3b 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20 63 72  IN;....--..-- cr
09e0: 65 61 74 69 6e 67 20 61 20 74 61 62 6c 65 0d 0a  eating a table..
09f0: 2d 2d 0d 0a 43 52 45 41 54 45 20 54 41 42 4c 45  --..CREATE TABLE
0a00: 20 65 78 61 6d 70 6c 65 20 28 0d 0a 20 20 69 64   example (..  id
0a10: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59   INTEGER PRIMARY
0a20: 20 4b 45 59 20 41 55 54 4f 49 4e 43 52 45 4d 45   KEY AUTOINCREME
0a30: 4e 54 2c 0d 0a 20 20 6e 61 6d 65 20 54 45 58 54  NT,..  name TEXT
0a40: 20 4e 4f 54 20 4e 55 4c 4c 2c 0d 0a 20 20 76 61   NOT NULL,..  va
0a50: 6c 75 65 20 44 4f 55 42 4c 45 29 3b 0d 0a 0d 0a  lue DOUBLE);....
0a60: 2d 2d 0d 0a 2d 2d 20 70 6f 70 75 6c 61 74 69 6e  --..-- populatin
0a70: 67 20 74 68 65 20 74 61 62 6c 65 0d 0a 2d 2d 0d  g the table..--.
0a80: 0a 49 4e 53 45 52 54 20 49 4e 54 4f 20 65 78 61  .INSERT INTO exa
0a90: 6d 70 6c 65 20 28 69 64 2c 20 6e 61 6d 65 2c 20  mple (id, name, 
0aa0: 76 61 6c 75 65 29 20 56 41 4c 55 45 53 20 28 4e  value) VALUES (N
0ab0: 55 4c 4c 2c 20 27 66 69 72 73 74 27 2c 20 31 32  ULL, 'first', 12
0ac0: 2e 33 34 29 3b 0d 0a 49 4e 53 45 52 54 20 49 4e  .34);..INSERT IN
0ad0: 54 4f 20 65 78 61 6d 70 6c 65 20 28 69 64 2c 20  TO example (id, 
0ae0: 6e 61 6d 65 2c 20 76 61 6c 75 65 29 20 56 41 4c  name, value) VAL
0af0: 55 45 53 20 28 4e 55 4c 4c 2c 20 27 73 65 63 6f  UES (NULL, 'seco
0b00: 6e 64 27 2c 20 35 36 2e 37 38 29 3b 0d 0a 49 4e  nd', 56.78);..IN
0b10: 53 45 52 54 20 49 4e 54 4f 20 65 78 61 6d 70 6c  SERT INTO exampl
0b20: 65 20 28 69 64 2c 20 6e 61 6d 65 2c 20 76 61 6c  e (id, name, val
0b30: 75 65 29 20 56 41 4c 55 45 53 20 28 4e 55 4c 4c  ue) VALUES (NULL
0b40: 2c 20 27 74 68 69 72 64 27 2c 20 4e 55 4c 4c 29  , 'third', NULL)
0b50: 3b 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20 63 6f 6d 6d  ;....--..-- comm
0b60: 69 74 74 69 6e 67 20 74 68 65 20 70 65 6e 64 69  itting the pendi
0b70: 6e 67 20 54 72 61 6e 73 61 63 74 69 6f 6e 0d 0a  ng Transaction..
0b80: 2d 2d 0d 0a 43 4f 4d 4d 49 54 3b 0d 0a 0d 0a 2e  --..COMMIT;.....
0b90: 71 75 69 74 0d 0a 3c 2f 76 65 72 62 61 74 69 6d  quit..</verbatim
0ba0: 3e 0d 0a 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a  >..<hr>..</li>..
0bb0: 3c 6c 69 3e 0d 0a 3c 68 34 3e 53 51 4c 20 56 61  <li>..<h4>SQL Va
0bc0: 72 69 61 62 6c 65 3c 2f 68 34 3e 0d 0a 41 20 3c  riable</h4>..A <
0bd0: 62 3e 3c 69 3e 53 51 4c 20 56 61 72 69 61 62 6c  b><i>SQL Variabl
0be0: 65 3c 2f 69 3e 3c 2f 62 3e 20 69 73 20 6a 75 73  e</i></b> is jus
0bf0: 74 20 61 20 70 6c 61 63 65 68 6f 6c 64 65 72 20  t a placeholder 
0c00: 73 79 6d 62 6f 6c 2c 20 74 68 61 74 20 6c 61 74  symbol, that lat
0c10: 65 72 20 6d 75 73 74 20 62 65 20 72 65 73 6f 6c  er must be resol
0c20: 76 65 64 2c 20 65 6e 63 6c 6f 73 65 64 20 62 65  ved, enclosed be
0c30: 74 77 65 65 6e 20 74 77 6f 20 3c 69 3e 3c 75 3e  tween two <i><u>
0c40: 73 70 65 63 69 61 6c 20 6d 61 72 6b 65 72 73 3c  special markers<
0c50: 2f 75 3e 3c 2f 69 3e 20 28 3c 62 3e 3c 69 3e 40  /u></i> (<b><i>@
0c60: 3c 2f 69 3e 3c 2f 62 3e 20 6f 72 20 3c 62 3e 3c  </i></b> or <b><
0c70: 69 3e 24 3c 2f 69 3e 3c 2f 62 3e 29 2e 20 45 78  i>$</i></b>). Ex
0c80: 61 6d 70 6c 65 73 3a 0d 0a 3c 76 65 72 62 61 74  amples:..<verbat
0c90: 69 6d 3e 0d 0a 40 74 61 62 6c 65 5f 6e 61 6d 65  im>..@table_name
0ca0: 40 0d 0a 40 63 6f 6c 5f 6e 61 6d 65 40 0d 0a 24  @..@col_name@..$
0cb0: 76 61 6c 75 65 24 0d 0a 24 72 61 64 69 75 73 24  value$..$radius$
0cc0: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c  ..</verbatim>..<
0cd0: 75 3e 4e 6f 74 65 3c 2f 75 3e 3a 20 75 73 69 6e  u>Note</u>: usin
0ce0: 67 20 74 68 65 20 3c 62 3e 3c 69 3e 40 3c 2f 69  g the <b><i>@</i
0cf0: 3e 3c 2f 62 3e 20 6f 72 20 74 68 65 20 3c 62 3e  ></b> or the <b>
0d00: 3c 69 3e 24 3c 2f 69 3e 3c 2f 62 3e 20 6d 61 72  <i>$</i></b> mar
0d10: 6b 65 72 73 20 69 73 20 6a 75 73 74 20 61 20 3c  kers is just a <
0d20: 69 3e 3c 75 3e 6d 61 74 74 65 72 20 6f 66 20 63  i><u>matter of c
0d30: 68 6f 69 63 65 3c 2f 75 3e 3c 2f 69 3e 3b 20 62  hoice</u></i>; b
0d40: 6f 74 68 20 68 61 76 65 20 69 64 65 6e 74 69 63  oth have identic
0d50: 61 6c 20 6d 65 61 6e 69 6e 67 20 61 6e 64 20 70  al meaning and p
0d60: 72 61 63 74 69 63 61 6c 20 65 66 66 65 63 74 2e  ractical effect.
0d70: 0d 0a 3c 62 72 3e 3c 62 72 3e 3c 68 72 3e 0d 0a  ..<br><br><hr>..
0d80: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34  </li>..<li>..<h4
0d90: 3e 53 51 4c 20 42 6f 64 79 3c 2f 68 34 3e 0d 0a  >SQL Body</h4>..
0da0: 41 20 3c 62 3e 3c 69 3e 53 51 4c 20 53 63 72 69  A <b><i>SQL Scri
0db0: 70 74 3c 2f 69 3e 3c 2f 62 3e 20 74 68 61 74 20  pt</i></b> that 
0dc0: 69 6e 74 65 72 6e 61 6c 6c 79 20 75 73 65 73 20  internally uses 
0dd0: 3c 62 3e 3c 69 3e 56 61 72 69 61 62 6c 65 73 3c  <b><i>Variables<
0de0: 2f 69 3e 3c 2f 62 3e 2e 20 45 78 61 6d 70 6c 65  /i></b>. Example
0df0: 3a 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 2e  :..<verbatim>...
0e00: 65 63 68 6f 20 6f 6e 0d 0a 0d 0a 2d 2d 0d 0a 2d  echo on....--..-
0e10: 2d 20 73 74 61 72 74 69 6e 67 20 61 20 54 72 61  - starting a Tra
0e20: 6e 73 61 63 74 69 6f 6e 0d 0a 2d 2d 0d 0a 42 45  nsaction..--..BE
0e30: 47 49 4e 3b 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20 63  GIN;....--..-- c
0e40: 72 65 61 74 69 6e 67 20 61 20 74 61 62 6c 65 0d  reating a table.
0e50: 0a 2d 2d 0d 0a 43 52 45 41 54 45 20 54 41 42 4c  .--..CREATE TABL
0e60: 45 20 40 74 61 62 6c 65 40 20 28 0d 0a 20 20 40  E @table@ (..  @
0e70: 70 6b 40 20 49 4e 54 45 47 45 52 20 50 52 49 4d  pk@ INTEGER PRIM
0e80: 41 52 59 20 4b 45 59 20 41 55 54 4f 49 4e 43 52  ARY KEY AUTOINCR
0e90: 45 4d 45 4e 54 2c 0d 0a 20 20 40 63 6f 6c 31 40  EMENT,..  @col1@
0ea0: 20 54 45 58 54 20 4e 4f 54 20 4e 55 4c 4c 2c 0d   TEXT NOT NULL,.
0eb0: 0a 20 20 40 63 6f 6c 32 40 20 44 4f 55 42 4c 45  .  @col2@ DOUBLE
0ec0: 29 3b 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20 70 6f 70  );....--..-- pop
0ed0: 75 6c 61 74 69 6e 67 20 74 68 65 20 74 61 62 6c  ulating the tabl
0ee0: 65 0d 0a 2d 2d 0d 0a 49 4e 53 45 52 54 20 49 4e  e..--..INSERT IN
0ef0: 54 4f 20 40 74 61 62 6c 65 40 20 28 40 70 6b 40  TO @table@ (@pk@
0f00: 2c 20 40 63 6f 6c 31 40 2c 20 40 63 6f 6c 32 40  , @col1@, @col2@
0f10: 29 20 56 41 4c 55 45 53 20 28 4e 55 4c 4c 2c 20  ) VALUES (NULL, 
0f20: 27 66 69 72 73 74 27 2c 20 31 32 2e 33 34 29 3b  'first', 12.34);
0f30: 0d 0a 49 4e 53 45 52 54 20 49 4e 54 4f 20 40 74  ..INSERT INTO @t
0f40: 61 62 6c 65 40 20 28 40 70 6b 40 2c 20 40 63 6f  able@ (@pk@, @co
0f50: 6c 31 40 2c 20 40 63 6f 6c 32 40 29 20 56 41 4c  l1@, @col2@) VAL
0f60: 55 45 53 20 28 4e 55 4c 4c 2c 20 27 73 65 63 6f  UES (NULL, 'seco
0f70: 6e 64 27 2c 20 35 36 2e 37 38 29 3b 0d 0a 49 4e  nd', 56.78);..IN
0f80: 53 45 52 54 20 49 4e 54 4f 20 40 74 61 62 6c 65  SERT INTO @table
0f90: 40 20 28 40 70 6b 40 2c 20 40 63 6f 6c 32 40 2c  @ (@pk@, @col2@,
0fa0: 20 40 63 6f 6c 32 40 29 20 56 41 4c 55 45 53 20   @col2@) VALUES 
0fb0: 28 4e 55 4c 4c 2c 20 27 74 68 69 72 64 27 2c 20  (NULL, 'third', 
0fc0: 4e 55 4c 4c 29 3b 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d  NULL);....--..--
0fd0: 20 63 6f 6d 6d 69 74 74 69 6e 67 20 74 68 65 20   committing the 
0fe0: 70 65 6e 64 69 6e 67 20 54 72 61 6e 73 61 63 74  pending Transact
0ff0: 69 6f 6e 0d 0a 2d 2d 0d 0a 43 4f 4d 4d 49 54 3b  ion..--..COMMIT;
1000: 0d 0a 0d 0a 2e 71 75 69 74 0d 0a 3c 2f 76 65 72  .....quit..</ver
1010: 62 61 74 69 6d 3e 0d 0a 3c 75 3e 4e 6f 74 65 3c  batim>..<u>Note<
1020: 2f 75 3e 3a 20 74 68 69 73 20 73 65 63 6f 6e 64  /u>: this second
1030: 20 76 65 72 73 69 6f 6e 20 69 73 20 6f 62 76 69   version is obvi
1040: 6f 75 73 6c 79 20 6d 6f 72 65 20 66 6c 65 78 69  ously more flexi
1050: 62 6c 65 20 74 68 61 6e 20 74 68 65 20 69 6e 69  ble than the ini
1060: 74 69 61 6c 20 53 51 4c 20 73 63 72 69 70 74 2c  tial SQL script,
1070: 20 6a 75 73 74 20 62 65 63 61 75 73 65 20 74 68   just because th
1080: 65 20 74 61 62 6c 65 2d 6e 61 6d 65 73 20 61 6e  e table-names an
1090: 64 20 63 6f 6c 75 6d 6e 2d 6e 61 6d 65 73 20 61  d column-names a
10a0: 72 65 20 6e 6f 20 6c 6f 6e 67 65 72 20 3c 75 3e  re no longer <u>
10b0: 3c 69 3e 68 61 72 64 63 6f 64 65 64 3c 2f 69 3e  <i>hardcoded</i>
10c0: 3c 2f 75 3e 2c 20 62 75 74 20 3c 75 3e 3c 69 3e  </u>, but <u><i>
10d0: 64 79 6e 61 6d 69 63 3c 2f 69 3e 3c 2f 75 3e 2e  dynamic</i></u>.
10e0: 3c 62 72 3e 0d 0a 53 6f 20 77 65 20 61 72 65 20  <br>..So we are 
10f0: 6e 6f 77 20 66 72 65 65 20 74 6f 20 72 65 75 73  now free to reus
1100: 65 20 74 68 69 73 20 53 51 4c 20 42 6f 64 79 2c  e this SQL Body,
1110: 20 69 6e 20 64 69 66 66 65 72 65 6e 74 20 63 6f   in different co
1120: 6e 74 65 78 74 73 20 61 66 74 65 72 20 73 65 74  ntexts after set
1130: 74 69 6e 67 20 74 68 65 20 61 70 70 72 6f 70 72  ting the appropr
1140: 69 61 74 65 20 56 61 72 69 61 62 6c 65 20 56 61  iate Variable Va
1150: 6c 75 65 73 20 62 65 66 6f 72 65 20 65 78 65 63  lues before exec
1160: 75 74 69 6f 6e 2e 3c 62 72 3e 3c 62 72 3e 0d 0a  ution.<br><br>..
1170: 3c 62 3e 3c 69 3e 53 51 4c 20 42 6f 64 69 65 73  <b><i>SQL Bodies
1180: 3c 2f 69 3e 3c 2f 62 3e 20 65 78 69 73 74 20 69  </i></b> exist i
1190: 6e 20 74 77 6f 20 64 69 66 66 65 72 65 6e 74 20  n two different 
11a0: 66 6f 72 6d 73 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c  forms:..<ul>..<l
11b0: 69 3e 3c 62 3e 72 61 77 3c 2f 62 3e 3a 20 63 6f  i><b>raw</b>: co
11c0: 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 73 79 6d  ntaining the sym
11d0: 62 6f 6c 69 63 20 56 61 72 69 61 62 6c 65 73 2e  bolic Variables.
11e0: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 63 6f  </li>..<li><b>co
11f0: 6f 6b 65 64 3c 2f 62 3e 3a 20 77 69 74 68 20 74  oked</b>: with t
1200: 68 65 20 73 79 6d 62 6f 6c 69 63 20 56 61 72 69  he symbolic Vari
1210: 61 62 6c 65 73 20 70 72 6f 70 65 72 6c 79 20 72  ables properly r
1220: 65 70 6c 61 63 65 64 20 62 79 20 74 68 65 20 61  eplaced by the a
1230: 63 74 75 61 6c 20 76 61 6c 75 65 73 2e 3c 62 72  ctual values.<br
1240: 3e 0d 0a 4f 62 76 69 6f 75 73 6c 79 2c 20 6f 6e  >..Obviously, on
1250: 6c 79 20 74 68 65 20 3c 62 3e 3c 69 3e 63 6f 6f  ly the <b><i>coo
1260: 6b 65 64 3c 2f 69 3e 3c 2f 62 3e 20 66 6f 72 6d  ked</i></b> form
1270: 20 63 61 6e 20 62 65 20 73 75 63 63 65 73 73 66   can be successf
1280: 75 6c 6c 79 20 65 78 65 63 75 74 65 64 2e 3c 2f  ully executed.</
1290: 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 62 72 3e  li>..</ul>..<br>
12a0: 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69  <hr>..</li>..<li
12b0: 3e 0d 0a 3c 68 34 3e 53 51 4c 20 50 72 6f 63 65  >..<h4>SQL Proce
12c0: 64 75 72 65 20 42 4c 4f 42 20 6f 62 6a 65 63 74  dure BLOB object
12d0: 3c 2f 68 34 3e 0d 0a 54 68 69 73 20 73 69 6d 70  </h4>..This simp
12e0: 6c 79 20 69 73 20 61 20 3c 62 3e 3c 69 3e 42 4c  ly is a <b><i>BL
12f0: 4f 42 20 65 6e 63 6f 64 65 64 3c 2f 69 3e 3c 2f  OB encoded</i></
1300: 62 3e 20 77 69 74 68 20 74 68 65 20 65 6e 63 6f  b> with the enco
1310: 64 65 64 20 70 72 65 2d 63 6f 6d 70 69 6c 65 64  ded pre-compiled
1320: 20 27 3c 75 3e 3c 69 3e 72 61 77 3c 2f 69 3e 3c   '<u><i>raw</i><
1330: 2f 75 3e 27 20 3c 62 3e 3c 69 3e 53 51 4c 20 42  /u>' <b><i>SQL B
1340: 6f 64 79 3c 2f 69 3e 3c 2f 62 3e 2c 20 77 68 69  ody</i></b>, whi
1350: 63 68 20 77 69 6c 6c 20 62 65 20 75 73 65 64 20  ch will be used 
1360: 62 79 20 20 70 72 61 63 74 69 63 61 6c 6c 79 20  by  practically 
1370: 61 6c 6c 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e  all SQL function
1380: 73 20 73 75 70 70 6f 72 74 69 6e 67 20 53 74 6f  s supporting Sto
1390: 72 65 64 20 50 72 6f 63 65 64 75 72 65 73 2e 20  red Procedures. 
13a0: 0d 0a 3c 62 72 3e 3c 62 72 3e 3c 68 72 3e 20 0d  ..<br><br><hr> .
13b0: 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68  .</li>..<li>..<h
13c0: 34 3e 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75  4>Stored Procedu
13d0: 72 65 3c 2f 68 34 3e 0d 0a 41 20 3c 62 3e 3c 69  re</h4>..A <b><i
13e0: 3e 53 51 4c 20 50 72 6f 63 65 64 75 72 65 20 42  >SQL Procedure B
13f0: 4c 4f 42 20 6f 62 6a 65 63 74 3c 2f 69 3e 3c 2f  LOB object</i></
1400: 62 3e 20 74 68 61 74 20 69 73 20 70 65 72 6d 61  b> that is perma
1410: 6e 65 6e 74 6c 79 20 73 74 6f 72 65 64 20 69 6e  nently stored in
1420: 74 6f 20 61 20 64 61 74 61 62 61 73 65 2e 3c 62  to a database.<b
1430: 72 3e 0d 0a 54 68 69 73 20 6d 61 6b 65 73 20 69  r>..This makes i
1440: 74 20 65 61 73 69 65 72 20 74 6f 20 75 73 65 20  t easier to use 
1450: 69 6e 20 61 20 61 75 74 6f 6d 61 74 65 64 20 20  in a automated  
1460: 77 6f 72 6b 66 6c 6f 77 2c 20 70 65 72 68 61 70  workflow, perhap
1470: 73 20 74 6f 20 62 65 20 69 6d 70 6c 65 6d 65 6e  s to be implemen
1480: 74 65 64 20 61 73 20 61 20 72 6f 75 74 69 6e 65  ted as a routine
1490: 6c 79 20 70 65 72 69 6f 64 69 63 20 74 61 73 6b  ly periodic task
14a0: 20 28 64 61 69 6c 79 20 2f 20 77 65 65 6b 6c 79   (daily / weekly
14b0: 20 2f 20 6d 6f 6e 74 68 6c 79 20 61 6e 64 20 73   / monthly and s
14c0: 6f 20 6f 6e 29 2e 3c 62 72 3e 0d 0a 53 74 6f 72  o on).<br>..Stor
14d0: 65 64 20 50 72 6f 63 65 64 75 72 65 73 20 61 6c  ed Procedures al
14e0: 77 61 79 73 20 68 61 76 65 20 74 68 65 20 66 6f  ways have the fo
14f0: 6c 6c 6f 77 69 6e 67 20 65 6c 65 6d 65 6e 74 73  llowing elements
1500: 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 20 3c  :..<ul>..<li>a <
1510: 62 3e 6e 61 6d 65 3c 2f 62 3e 2c 20 69 6e 74 65  b>name</b>, inte
1520: 6e 64 65 64 20 74 6f 20 62 65 20 61 6e 20 75 6e  nded to be an un
1530: 69 71 75 65 20 69 64 65 6e 74 69 66 69 65 72 20  ique identifier 
1540: 28 3c 62 3e 3c 69 3e 50 72 69 6d 61 72 79 20 4b  (<b><i>Primary K
1550: 65 79 3c 2f 69 3e 3c 2f 62 3e 29 2e 3c 2f 6c 69  ey</i></b>).</li
1560: 3e 0d 0a 3c 6c 69 3e 61 20 3c 62 3e 74 69 74 6c  >..<li>a <b>titl
1570: 65 3c 2f 62 3e 2c 20 69 2e 65 2e 20 61 20 73 68  e</b>, i.e. a sh
1580: 6f 72 74 20 64 65 73 63 72 69 70 74 69 6f 6e 20  ort description 
1590: 6f 66 20 74 68 65 20 69 6e 74 65 6e 64 65 64 20  of the intended 
15a0: 73 63 6f 70 65 20 6f 66 20 74 68 65 20 53 74 6f  scope of the Sto
15b0: 72 65 64 20 50 72 6f 63 65 64 75 72 65 2e 3c 2f  red Procedure.</
15c0: 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 3c 62 3e 53 51  li>..<li>a <b>SQ
15d0: 4c 20 50 72 6f 63 65 64 75 72 65 20 42 4c 4f 42  L Procedure BLOB
15e0: 20 4f 62 6a 65 63 74 3c 2f 62 3e 2e 3c 2f 6c 69   Object</b>.</li
15f0: 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 62 72 3e 3c 68  >..</ul>..<br><h
1600: 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d  r>..</li>..<li>.
1610: 0a 3c 68 34 3e 56 61 72 69 61 62 6c 65 20 77 69  .<h4>Variable wi
1620: 74 68 20 56 61 6c 75 65 20 73 74 72 69 6e 67 73  th Value strings
1630: 3c 2f 68 34 3e 0d 0a 42 65 66 6f 72 65 20 65 78  </h4>..Before ex
1640: 65 63 75 74 69 6e 67 20 61 20 27 3c 69 3e 72 61  ecuting a '<i>ra
1650: 77 3c 2f 69 3e 27 20 3c 62 3e 3c 69 3e 53 51 4c  w</i>' <b><i>SQL
1660: 20 42 6f 64 79 3c 2f 69 3e 3c 2f 62 3e 20 28 77   Body</i></b> (w
1670: 69 74 68 20 70 6c 61 63 65 68 6f 6c 64 65 72 20  ith placeholder 
1680: 3c 62 3e 3c 69 3e 56 61 72 69 61 62 6c 65 73 3c  <b><i>Variables<
1690: 2f 69 3e 3c 2f 62 3e 29 2c 20 74 68 65 73 65 20  /i></b>), these 
16a0: 56 61 72 69 61 62 6c 65 73 20 6e 65 65 64 20 74  Variables need t
16b0: 6f 20 62 65 20 72 65 70 6c 61 63 65 64 20 28 27  o be replaced ('
16c0: 3c 69 3e 63 6f 6f 6b 65 64 3c 2f 69 3e 27 29 20  <i>cooked</i>') 
16d0: 77 69 74 68 20 74 68 65 20 61 70 70 72 6f 70 72  with the appropr
16e0: 69 61 74 65 20 3c 62 3e 3c 69 3e 56 61 6c 75 65  iate <b><i>Value
16f0: 73 3c 2f 69 3e 3c 2f 62 3e 2c 20 74 68 69 73 20  s</i></b>, this 
1700: 70 72 6f 70 65 72 6c 79 20 74 72 61 6e 73 66 6f  properly transfo
1710: 72 6d 69 6e 67 20 61 20 27 3c 62 3e 72 61 77 3c  rming a '<b>raw<
1720: 2f 62 3e 27 20 53 51 4c 20 42 6f 64 79 20 69 6e  /b>' SQL Body in
1730: 74 6f 20 61 20 27 3c 62 3e 63 6f 6f 6b 65 64 3c  to a '<b>cooked<
1740: 2f 62 3e 27 20 53 51 4c 20 42 6f 64 79 2e 3c 62  /b>' SQL Body.<b
1750: 72 3e 0d 0a 41 20 3c 62 3e 3c 69 3e 56 61 72 69  r>..A <b><i>Vari
1760: 61 62 6c 65 20 77 69 74 68 20 56 61 6c 75 65 3c  able with Value<
1770: 2f 69 3e 3c 2f 62 3e 20 73 74 72 69 6e 67 20 73  /i></b> string s
1780: 69 6d 70 6c 79 20 69 73 20 61 6e 20 61 70 70 72  imply is an appr
1790: 6f 70 72 69 61 74 65 6c 79 20 77 65 6c 6c 2d 66  opriately well-f
17a0: 6f 72 6d 61 74 74 65 64 20 54 65 78 74 20 73 74  ormatted Text st
17b0: 72 69 6e 67 20 64 65 63 6c 61 72 69 6e 67 20 62  ring declaring b
17c0: 6f 74 68 20 74 68 65 20 53 79 6d 62 6f 6c 20 61  oth the Symbol a
17d0: 6e 64 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e  nd the correspon
17e0: 64 69 6e 67 20 72 65 70 6c 61 63 65 6d 65 6e 74  ding replacement
17f0: 20 56 61 6c 75 65 20 28 65 78 70 72 65 73 73 65   Value (expresse
1800: 64 20 69 6e 20 69 74 73 20 74 65 78 74 75 61 6c  d in its textual
1810: 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 29   representation)
1820: 2e 20 45 78 61 6d 70 6c 65 73 3a 0d 0a 3c 76 65  . Examples:..<ve
1830: 72 62 61 74 69 6d 3e 0d 0a 40 76 61 6c 75 65 5f  rbatim>..@value_
1840: 31 40 3d 31 32 33 34 20 20 20 20 20 20 20 20 20  1@=1234         
1850: 20 20 20 2d 2d 20 69 6e 74 65 67 65 72 20 76 61     -- integer va
1860: 6c 75 65 0d 0a 40 76 61 6c 75 65 5f 32 40 3d 31  lue..@value_2@=1
1870: 32 2e 33 34 20 20 20 20 20 20 20 20 20 20 20 2d  2.34           -
1880: 2d 20 64 6f 75 62 6c 65 20 76 61 6c 75 65 0d 0a  - double value..
1890: 40 76 61 6c 75 65 5f 33 40 3d 4e 65 77 20 59 6f  @value_3@=New Yo
18a0: 72 6b 20 43 69 74 79 20 20 20 2d 2d 20 74 65 78  rk City   -- tex
18b0: 74 20 76 61 6c 75 65 0d 0a 40 76 61 6c 75 65 5f  t value..@value_
18c0: 34 40 3d 78 27 30 31 32 33 61 62 63 64 27 20 20  4@=x'0123abcd'  
18d0: 20 20 20 2d 2d 20 62 6c 6f 62 20 76 61 6c 75 65     -- blob value
18e0: 0d 0a 40 76 61 6c 75 65 5f 35 40 3d 4e 55 4c 4c  ..@value_5@=NULL
18f0: 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 6e              -- n
1900: 75 6c 6c 20 76 61 6c 75 65 0d 0a 3c 2f 76 65 72  ull value..</ver
1910: 62 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c 65 20 62  batim>..<table b
1920: 67 63 6f 6c 6f 72 3d 22 23 66 38 66 38 64 38 22  gcolor="#f8f8d8"
1930: 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 36 22   cellpadding="6"
1940: 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 38 22   cellspacing="8"
1950: 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 3c 75 3e 4e 6f  ><tr><td>..<u>No
1960: 74 65 3c 2f 75 3e 3a 20 72 65 70 6c 61 63 69 6e  te</u>: replacin
1970: 67 20 56 61 72 69 61 62 6c 65 73 20 77 69 74 68  g Variables with
1980: 20 74 68 65 20 61 63 74 75 61 6c 20 56 61 6c 75   the actual Valu
1990: 65 73 20 69 73 20 61 20 62 6c 69 6e 64 20 70 72  es is a blind pr
19a0: 6f 63 65 73 73 20 63 6f 6d 70 6c 65 74 65 6c 79  ocess completely
19b0: 20 69 6e 73 65 6e 73 69 62 6c 65 20 74 6f 20 74   insensible to t
19c0: 68 65 20 73 70 65 63 69 66 69 63 20 73 79 6e 74  he specific synt
19d0: 61 63 74 69 63 20 63 6f 6e 74 65 78 74 2e 3c 62  actic context.<b
19e0: 72 3e 0d 0a 59 6f 75 20 61 72 65 20 72 65 73 70  r>..You are resp
19f0: 6f 6e 73 69 62 6c 65 20 66 6f 72 20 74 68 65 20  onsible for the 
1a00: 63 6f 72 72 65 63 74 20 61 70 70 6c 69 63 61 74  correct applicat
1a10: 69 6f 6e 20 6f 66 20 73 69 6e 67 6c 65 2d 20 6f  ion of single- o
1a20: 72 20 64 6f 75 62 6c 65 2d 71 75 6f 74 69 6e 67  r double-quoting
1a30: 2c 20 72 65 71 75 69 72 65 64 20 62 79 20 74 68  , required by th
1a40: 65 20 53 51 4c 20 73 79 6e 74 61 78 20 72 75 6c  e SQL syntax rul
1a50: 65 73 2e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 3c  es...</td></tr><
1a60: 2f 74 61 62 6c 65 3e 0d 0a 3c 62 72 3e 3c 68 72  /table>..<br><hr
1a70: 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d 0a  >..</li>..<li>..
1a80: 3c 68 34 3e 53 74 6f 72 65 64 20 56 61 72 69 61  <h4>Stored Varia
1a90: 62 6c 65 3c 2f 68 34 3e 0d 0a 41 20 3c 62 3e 3c  ble</h4>..A <b><
1aa0: 69 3e 56 61 72 69 61 62 6c 65 20 77 69 74 68 20  i>Variable with 
1ab0: 56 61 6c 75 65 3c 2f 69 3e 3c 2f 62 3e 20 70 65  Value</i></b> pe
1ac0: 72 6d 61 6e 65 6e 74 6c 79 20 73 74 6f 72 65 64  rmanently stored
1ad0: 20 69 6e 74 6f 20 61 20 64 61 74 61 62 61 73 65   into a database
1ae0: 2e 3c 62 72 3e 0d 0a 53 74 6f 72 65 64 20 56 61  .<br>..Stored Va
1af0: 72 69 61 62 6c 65 73 20 61 6c 77 61 79 73 20 68  riables always h
1b00: 61 76 65 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e  ave the followin
1b10: 67 20 65 6c 65 6d 65 6e 74 73 3a 0d 0a 3c 75 6c  g elements:..<ul
1b20: 3e 0d 0a 3c 6c 69 3e 61 20 3c 62 3e 6e 61 6d 65  >..<li>a <b>name
1b30: 3c 2f 62 3e 2c 20 69 6e 74 65 6e 64 65 64 20 74  </b>, intended t
1b40: 6f 20 62 65 20 61 6e 20 75 6e 69 71 75 65 20 69  o be an unique i
1b50: 64 65 6e 74 69 66 69 65 72 20 28 3c 62 3e 3c 69  dentifier (<b><i
1b60: 3e 50 72 69 6d 61 72 79 20 4b 65 79 3c 2f 69 3e  >Primary Key</i>
1b70: 3c 2f 62 3e 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  </b>).</li>..<li
1b80: 3e 61 20 3c 62 3e 74 69 74 6c 65 3c 2f 62 3e 2c  >a <b>title</b>,
1b90: 20 69 2e 65 2e 20 61 20 73 68 6f 72 74 20 64 65   i.e. a short de
1ba0: 73 63 72 69 70 74 69 6f 6e 20 6f 66 20 74 68 65  scription of the
1bb0: 20 69 6e 74 65 6e 64 65 64 20 73 63 6f 70 65 20   intended scope 
1bc0: 6f 66 20 74 68 65 20 53 74 6f 72 65 64 20 56 61  of the Stored Va
1bd0: 72 69 61 62 6c 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c  riable.</li>..<l
1be0: 69 3e 61 20 3c 62 3e 56 61 6c 75 65 20 73 74 72  i>a <b>Value str
1bf0: 69 6e 67 3c 2f 62 3e 2e 3c 2f 6c 69 3e 3c 62 72  ing</b>.</li><br
1c00: 3e 0d 0a 3c 2f 75 6c 3e 3c 74 61 62 6c 65 20 62  >..</ul><table b
1c10: 67 63 6f 6c 6f 72 3d 22 23 66 38 66 38 64 38 22  gcolor="#f8f8d8"
1c20: 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 36 22   cellpadding="6"
1c30: 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 38 22   cellspacing="8"
1c40: 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 3c 75 3e 4e 6f  ><tr><td>..<u>No
1c50: 74 65 3c 2f 75 3e 3a 20 74 68 65 20 69 6e 74 65  te</u>: the inte
1c60: 6e 64 65 64 20 73 63 6f 70 65 20 6f 66 20 3c 62  nded scope of <b
1c70: 3e 53 74 6f 72 65 64 20 56 61 72 69 61 62 6c 65  >Stored Variable
1c80: 73 3c 2f 62 3e 20 69 73 20 74 6f 20 64 65 66 69  s</b> is to defi
1c90: 6e 65 20 61 70 70 72 6f 70 72 69 61 74 65 20 64  ne appropriate d
1ca0: 65 66 61 75 6c 74 20 76 61 6c 75 65 73 2e 3c 62  efault values.<b
1cb0: 72 3e 0d 0a 49 66 20 61 20 67 69 76 65 6e 20 3c  r>..If a given <
1cc0: 62 3e 56 61 72 69 61 62 6c 65 3c 2f 62 3e 20 69  b>Variable</b> i
1cd0: 73 20 62 65 69 6e 67 20 75 73 65 64 20 77 69 74  s being used wit
1ce0: 68 69 6e 20 61 20 3c 69 3e 72 61 77 3c 2f 69 3e  hin a <i>raw</i>
1cf0: 20 53 51 4c 20 42 6f 64 79 20 74 6f 20 62 65 20   SQL Body to be 
1d00: 65 78 65 63 75 74 65 64 2c 20 61 6e 64 20 61 20  executed, and a 
1d10: 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 3c 62  corresponding <b
1d20: 3e 56 61 72 69 61 62 6c 65 20 77 69 74 68 20 56  >Variable with V
1d30: 61 6c 75 65 3c 2f 62 3e 20 68 61 73 20 6e 6f 74  alue</b> has not
1d40: 20 62 65 65 6e 20 72 65 73 6f 6c 76 65 64 2c 20   been resolved, 
1d50: 74 68 65 6e 20 61 6e 20 61 74 74 65 6d 70 74 20  then an attempt 
1d60: 77 69 6c 6c 20 62 65 20 61 6c 77 61 79 73 20 6d  will be always m
1d70: 61 64 65 20 74 6f 20 72 65 73 6f 6c 76 65 20 69  ade to resolve i
1d80: 74 20 62 79 20 73 65 61 72 63 68 69 6e 67 20 66  t by searching f
1d90: 6f 72 20 61 20 63 6f 72 72 65 73 70 6f 6e 64 69  or a correspondi
1da0: 6e 67 20 3c 62 3e 53 74 6f 72 65 64 20 56 61 72  ng <b>Stored Var
1db0: 69 61 62 6c 65 3c 2f 62 3e 20 62 79 20 6e 61 6d  iable</b> by nam
1dc0: 65 20 28 69 66 20 69 74 20 65 78 69 73 74 73 29  e (if it exists)
1dd0: 2e 3c 62 72 3e 0d 0a 41 6e 20 65 78 70 6c 69 63  .<br>..An explic
1de0: 69 74 6c 79 20 64 65 66 69 6e 65 64 20 3c 62 3e  itly defined <b>
1df0: 56 61 72 69 61 62 6c 65 20 77 69 74 68 20 56 61  Variable with Va
1e00: 6c 75 65 3c 2f 62 3e 20 61 72 67 75 6d 65 6e 74  lue</b> argument
1e10: 20 77 69 6c 6c 20 61 6c 77 61 79 73 20 74 61 6b   will always tak
1e20: 65 20 70 72 65 63 65 64 65 6e 63 65 20 6f 76 65  e precedence ove
1e30: 72 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64  r the correspond
1e40: 69 6e 67 20 3c 62 3e 53 74 6f 72 65 64 20 56 61  ing <b>Stored Va
1e50: 72 69 61 62 6c 65 3c 2f 62 3e 3b 20 69 6e 20 6f  riable</b>; in o
1e60: 74 68 65 72 20 77 6f 72 64 73 20 61 20 3c 62 3e  ther words a <b>
1e70: 53 74 6f 72 65 64 20 56 61 72 69 61 62 6c 65 3c  Stored Variable<
1e80: 2f 62 3e 20 28 69 66 20 64 65 66 69 6e 65 64 29  /b> (if defined)
1e90: 20 77 69 6c 6c 20 6a 75 73 74 20 62 65 20 63 6f   will just be co
1ea0: 6e 73 69 64 65 72 65 64 20 74 68 65 20 64 65 66  nsidered the def
1eb0: 61 75 6c 74 20 76 61 6c 75 65 2e 0d 0a 3c 2f 74  ault value...</t
1ec0: 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d  d></tr></table>.
1ed0: 0a 3c 62 72 3e 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e  .<br><hr>..</li>
1ee0: 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 53 51 4c 20  ..<li>..<h4>SQL 
1ef0: 4c 6f 67 66 69 6c 65 3c 2f 68 34 3e 0d 0a 53 51  Logfile</h4>..SQ
1f00: 4c 20 71 75 65 72 69 65 73 20 77 69 6c 6c 20 75  L queries will u
1f10: 73 75 61 6c 6c 79 20 72 65 74 75 72 6e 20 73 6f  sually return so
1f20: 6d 65 20 3c 62 3e 72 65 73 75 6c 74 73 65 74 3c  me <b>resultset<
1f30: 2f 62 3e 20 70 6f 74 65 6e 74 69 61 6c 6c 79 20  /b> potentially 
1f40: 63 6f 6e 74 61 69 6e 69 6e 67 20 75 73 65 66 75  containing usefu
1f50: 6c 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e 3c 62  l information.<b
1f60: 72 3e 0d 0a 42 75 74 20 65 78 65 63 75 74 69 6e  r>..But executin
1f70: 67 20 61 20 3c 62 3e 53 51 4c 20 50 72 6f 63 65  g a <b>SQL Proce
1f80: 64 75 72 65 3c 2f 62 3e 20 6f 72 20 3c 62 3e 53  dure</b> or <b>S
1f90: 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65 3c  tored Procedure<
1fa0: 2f 62 3e 20 77 69 6c 6c 20 62 65 20 73 65 65 6e  /b> will be seen
1fb0: 20 62 79 20 53 51 4c 69 74 65 20 6a 75 73 74 20   by SQLite just 
1fc0: 61 73 20 61 20 73 69 6d 70 6c 65 20 53 51 4c 20  as a simple SQL 
1fd0: 66 75 6e 63 74 69 6f 6e 20 63 61 6c 6c 20 73 69  function call si
1fe0: 6d 70 6c 79 20 72 65 74 75 72 6e 69 6e 67 20 61  mply returning a
1ff0: 20 66 69 6e 61 6c 20 73 75 63 63 65 73 73 20 6f   final success o
2000: 72 20 66 61 69 6c 75 72 65 20 72 65 74 75 72 6e  r failure return
2010: 20 63 6f 64 65 2e 3c 62 72 3e 0d 0a 41 6e 79 20   code.<br>..Any 
2020: 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75  information abou
2030: 74 20 61 6c 6c 20 74 68 65 20 69 6e 74 65 72 6d  t all the interm
2040: 65 64 69 61 74 65 20 72 65 73 75 6c 74 73 65 74  ediate resultset
2050: 73 2c 20 69 6e 74 65 72 6e 61 6c 6c 79 20 70 72  s, internally pr
2060: 6f 64 75 63 65 64 20 64 75 72 69 6e 67 20 74 68  oduced during th
2070: 65 20 65 78 65 63 75 74 69 6f 6e 20 6f 66 20 74  e execution of t
2080: 68 65 20 50 72 6f 63 65 64 75 72 65 2c 20 77 69  he Procedure, wi
2090: 6c 6c 20 62 65 20 6c 6f 73 74 2e 3c 62 72 3e 3c  ll be lost.<br><
20a0: 62 72 3e 0d 0a 54 6f 20 61 76 6f 69 64 20 74 68  br>..To avoid th
20b0: 69 73 2c 20 79 6f 75 20 63 61 6e 20 63 6f 6e 66  is, you can conf
20c0: 69 67 75 72 65 20 61 6e 20 65 78 74 65 72 6e 61  igure an externa
20d0: 6c 20 3c 62 3e 53 51 4c 20 4c 6f 67 66 69 6c 65  l <b>SQL Logfile
20e0: 3c 2f 62 3e 20 74 6f 20 70 65 72 6d 61 6e 65 6e  </b> to permanen
20f0: 74 6c 79 20 73 74 6f 72 65 20 61 6c 6c 20 69 6e  tly store all in
2100: 74 65 72 6d 65 64 69 61 74 65 20 72 65 73 75 6c  termediate resul
2110: 74 73 65 74 73 20 69 6e 74 6f 20 61 6e 20 6f 72  tsets into an or
2120: 64 69 6e 61 72 79 20 74 65 78 74 20 66 69 6c 65  dinary text file
2130: 2e 20 54 68 65 20 53 51 4c 20 4c 6f 67 66 69 6c  . The SQL Logfil
2140: 65 20 73 75 70 70 6f 72 74 73 20 74 77 6f 20 64  e supports two d
2150: 69 66 66 65 72 65 6e 74 20 6d 6f 64 65 73 3a 0d  ifferent modes:.
2160: 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 3c 62 3e 54 72  .<ul>..<li><b>Tr
2170: 75 6e 63 61 74 65 3c 2f 62 3e 3a 20 74 68 65 20  uncate</b>: the 
2180: 4c 6f 67 66 69 6c 65 20 77 69 6c 6c 20 62 65 20  Logfile will be 
2190: 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 20 63 72  automatically cr
21a0: 65 61 74 65 64 20 77 68 65 6e 20 6e 6f 74 20 61  eated when not a
21b0: 6c 72 65 61 64 79 20 65 78 69 73 74 69 6e 67 2c  lready existing,
21c0: 20 61 6e 64 20 69 74 20 77 69 6c 6c 20 62 65 20   and it will be 
21d0: 61 6c 77 61 79 73 20 74 72 75 6e 63 61 74 65 64  always truncated
21e0: 20 62 65 66 6f 72 65 20 73 74 61 72 74 69 6e 67   before starting
21f0: 20 61 6e 20 65 78 65 63 75 74 69 6f 6e 20 75 6e   an execution un
2200: 69 74 3b 20 69 6e 20 6f 74 68 65 72 20 77 6f 72  it; in other wor
2210: 64 73 20 69 74 20 77 69 6c 6c 20 61 6c 77 61 79  ds it will alway
2220: 73 20 70 72 65 73 65 72 76 65 20 6a 75 73 74 20  s preserve just 
2230: 74 68 65 20 72 65 73 75 6c 74 73 65 74 73 20 70  the resultsets p
2240: 72 6f 64 75 63 65 64 20 62 79 20 74 68 65 20 6d  roduced by the m
2250: 6f 73 74 20 72 65 63 65 6e 74 20 65 78 65 63 75  ost recent execu
2260: 74 69 6f 6e 20 75 6e 69 74 2e 3c 2f 6c 69 3e 0d  tion unit.</li>.
2270: 0a 3c 6c 69 3e 3c 62 3e 41 70 70 65 6e 64 3c 2f  .<li><b>Append</
2280: 62 3e 3a 20 74 68 65 20 4c 6f 67 66 69 6c 65 20  b>: the Logfile 
2290: 77 69 6c 6c 20 62 65 20 61 75 74 6f 6d 61 74 69  will be automati
22a0: 63 61 6c 6c 79 20 63 72 65 61 74 65 64 20 77 68  cally created wh
22b0: 65 6e 20 6e 6f 74 20 61 6c 72 65 61 64 79 20 65  en not already e
22c0: 78 69 73 74 69 6e 67 2c 20 61 6e 64 20 69 74 20  xisting, and it 
22d0: 77 69 6c 6c 20 62 65 20 6e 65 76 65 72 20 74 72  will be never tr
22e0: 75 6e 63 61 74 65 64 20 62 65 66 6f 72 65 20 73  uncated before s
22f0: 74 61 72 74 69 6e 67 20 61 6e 20 65 78 65 63 75  tarting an execu
2300: 74 69 6f 6e 20 75 6e 69 74 3b 20 69 6e 20 6f 74  tion unit; in ot
2310: 68 65 72 20 77 6f 72 64 73 20 69 74 20 77 69 6c  her words it wil
2320: 6c 20 70 72 6f 67 72 65 73 73 69 76 65 6c 79 20  l progressively 
2330: 67 72 6f 77 20 73 6f 20 74 6f 20 73 74 6f 72 65  grow so to store
2340: 20 61 6c 6c 20 74 68 65 20 72 65 73 75 6c 74 73   all the results
2350: 65 74 73 20 70 72 6f 64 75 63 65 64 20 62 79 20  ets produced by 
2360: 66 6f 6c 6c 6f 77 69 6e 67 20 65 78 65 63 75 74  following execut
2370: 69 6f 6e 20 75 6e 69 74 73 2e 3c 62 72 3e 0d 0a  ion units.<br>..
2380: 3c 75 3e 4e 6f 74 65 3c 2f 75 3e 3a 20 79 6f 75  <u>Note</u>: you
2390: 27 6c 6c 20 62 65 20 6f 62 76 69 6f 75 73 6c 79  'll be obviously
23a0: 20 72 65 71 75 69 72 65 64 20 74 6f 20 66 6c 75   required to flu
23b0: 73 68 20 74 68 65 20 4c 6f 67 66 69 6c 65 20 66  sh the Logfile f
23c0: 72 6f 6d 20 74 69 6d 65 20 74 6f 20 74 69 6d 65  rom time to time
23d0: 20 73 6f 20 74 6f 20 73 61 66 65 6c 79 20 61 76   so to safely av
23e0: 6f 69 64 20 74 6f 20 63 6f 6e 73 75 6d 65 20 74  oid to consume t
23f0: 6f 6f 20 6d 75 63 68 20 73 74 6f 72 61 67 65 20  oo much storage 
2400: 73 70 61 63 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75  space.</li>..</u
2410: 6c 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 2f 6c 69 3e  l>..</li>..</li>
2420: 0d 0a 3c 2f 6f 6c 3e 3c 62 72 3e 0d 0a 3c 68 72  ..</ol><br>..<hr
2430: 3e 0d 0a 3c 68 32 3e 46 61 6d 69 6c 69 61 72 69  >..<h2>Familiari
2440: 7a 69 6e 67 20 77 69 74 68 20 53 51 4c 20 46 75  zing with SQL Fu
2450: 6e 63 74 69 6f 6e 73 3c 2f 68 32 3e 0d 0a 3c 6f  nctions</h2>..<o
2460: 6c 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 48 61  l>..<li>..<h4>Ha
2470: 6e 64 6c 69 6e 67 20 53 51 4c 20 50 72 6f 63 65  ndling SQL Proce
2480: 64 75 72 65 20 42 4c 4f 42 20 6f 62 6a 65 63 74  dure BLOB object
2490: 73 3c 2f 68 34 3e 0d 0a 3c 76 65 72 62 61 74 69  s</h4>..<verbati
24a0: 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72  m>..SELECT SqlPr
24b0: 6f 63 5f 46 72 6f 6d 54 65 78 74 28 27 53 45 4c  oc_FromText('SEL
24c0: 45 43 54 20 40 63 6f 6c 40 20 46 52 4f 4d 20 40  ECT @col@ FROM @
24d0: 74 62 6c 40 27 29 3b 0d 0a 0d 0a 53 45 4c 45 43  tbl@');....SELEC
24e0: 54 20 53 71 6c 50 72 6f 63 5f 46 72 6f 6d 46 69  T SqlProc_FromFi
24f0: 6c 65 28 27 2f 68 6f 6d 65 2f 6a 6f 65 2f 74 65  le('/home/joe/te
2500: 6d 70 6c 61 74 65 2e 74 78 74 27 2c 20 43 50 31  mplate.txt', CP1
2510: 32 35 32 27 29 3b 0d 0a 3c 2f 76 65 72 62 61 74  252');..</verbat
2520: 69 6d 3e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 79  im>..<ul>..<li>y
2530: 6f 75 20 63 61 6e 20 63 72 65 61 74 65 20 61 20  ou can create a 
2540: 53 51 4c 20 50 72 6f 63 65 64 75 72 65 20 42 4c  SQL Procedure BL
2550: 4f 42 20 6f 62 6a 65 63 74 20 62 79 20 64 69 72  OB object by dir
2560: 65 63 74 6c 79 20 70 61 73 73 69 6e 67 20 61 20  ectly passing a 
2570: 54 65 78 74 20 53 51 4c 20 42 6f 64 79 2e 3c 2f  Text SQL Body.</
2580: 6c 69 3e 0d 0a 3c 6c 69 3e 6f 72 20 61 6c 74 65  li>..<li>or alte
2590: 72 6e 61 74 69 76 65 6c 79 20 79 6f 75 20 63 61  rnatively you ca
25a0: 6e 20 6c 6f 61 64 20 74 68 65 20 53 51 4c 20 42  n load the SQL B
25b0: 6f 64 79 20 66 72 6f 6d 20 61 6e 20 65 78 74 65  ody from an exte
25c0: 72 6e 61 6c 20 66 69 6c 65 2e 3c 62 72 3e 0d 0a  rnal file.<br>..
25d0: 3c 75 3e 4e 6f 74 65 3c 2f 75 3e 3a 20 74 68 69  <u>Note</u>: thi
25e0: 73 20 69 73 20 61 20 73 65 63 75 72 69 74 79 20  s is a security 
25f0: 73 65 6e 73 69 62 6c 65 20 6f 70 65 72 61 74 69  sensible operati
2600: 6f 6e 2c 20 73 6f 20 79 6f 75 20 61 6c 77 61 79  on, so you alway
2610: 73 20 6e 65 65 64 20 74 6f 20 73 65 74 20 61 6e  s need to set an
2620: 20 65 78 70 6c 69 63 69 74 20 61 75 74 68 6f 72   explicit author
2630: 69 7a 61 74 69 6f 6e 20 62 79 20 64 65 66 69 6e  ization by defin
2640: 69 6e 67 20 3c 62 3e 53 50 41 54 49 41 4c 49 54  ing <b>SPATIALIT
2650: 45 5f 53 45 43 55 52 49 54 59 3d 72 65 6c 61 78  E_SECURITY=relax
2660: 65 64 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c 6c  ed</b>.</li>..<l
2670: 69 3e 42 6f 74 68 20 66 75 6e 63 74 69 6f 6e 73  i>Both functions
2680: 20 61 63 63 65 70 74 20 61 6e 20 6f 70 74 69 6f   accept an optio
2690: 6e 61 6c 20 3c 62 3e 63 68 61 72 73 65 74 20 65  nal <b>charset e
26a0: 6e 63 6f 64 69 6e 67 3c 2f 62 3e 20 61 72 67 75  ncoding</b> argu
26b0: 6d 65 6e 74 3b 20 69 6e 20 74 68 69 73 20 63 61  ment; in this ca
26c0: 73 65 20 74 68 65 20 53 51 4c 20 42 6f 64 79 20  se the SQL Body 
26d0: 77 69 6c 6c 20 62 65 20 61 70 70 72 6f 70 72 69  will be appropri
26e0: 61 74 65 6c 79 20 63 6f 6e 76 65 72 74 65 64 20  ately converted 
26f0: 66 72 6f 6d 20 74 68 65 20 67 69 76 65 6e 20 63  from the given c
2700: 68 61 72 73 65 74 20 69 6e 74 6f 20 3c 62 3e 55  harset into <b>U
2710: 54 46 2d 38 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a  TF-8</b>.</li>..
2720: 3c 2f 75 6c 3e 0d 0a 3c 76 65 72 62 61 74 69 6d  </ul>..<verbatim
2730: 3e 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f  >..SELECT SqlPro
2740: 63 5f 49 73 56 61 6c 69 64 20 28 20 53 71 6c 50  c_IsValid ( SqlP
2750: 72 6f 63 5f 46 72 6f 6d 54 65 78 74 28 27 53 45  roc_FromText('SE
2760: 4c 45 43 54 20 40 63 6f 6c 40 20 46 52 4f 4d 20  LECT @col@ FROM 
2770: 40 74 62 6c 40 27 29 20 29 3b 0d 0a 2d 2d 2d 2d  @tbl@') );..----
2780: 2d 0d 0a 31 0d 0a 0d 0a 53 45 4c 45 43 54 20 53  -..1....SELECT S
2790: 71 6c 50 72 6f 63 5f 49 73 56 61 6c 69 64 20 28  qlProc_IsValid (
27a0: 20 4d 61 6b 65 50 6f 69 6e 74 28 31 31 2e 35 2c   MakePoint(11.5,
27b0: 20 34 32 2e 35 2c 20 34 33 32 36 29 20 29 3b 0d   42.5, 4326) );.
27c0: 0a 2d 2d 2d 2d 2d 0d 0a 30 0d 0a 3c 2f 76 65 72  .-----..0..</ver
27d0: 62 61 74 69 6d 3e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c  batim>..<ul>..<l
27e0: 69 3e 79 6f 75 20 63 61 6e 20 75 73 65 20 3c 62  i>you can use <b
27f0: 3e 53 71 6c 50 72 6f 63 5f 49 73 56 61 6c 69 64  >SqlProc_IsValid
2800: 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f  </b> in order to
2810: 20 63 68 65 63 6b 20 69 66 20 61 20 67 65 6e 65   check if a gene
2820: 72 69 63 20 42 4c 4f 42 20 72 65 61 6c 6c 79 20  ric BLOB really 
2830: 69 73 20 61 20 76 61 6c 69 64 20 53 51 4c 20 50  is a valid SQL P
2840: 72 6f 63 65 64 75 72 65 20 42 4c 4f 42 20 4f 62  rocedure BLOB Ob
2850: 6a 65 63 74 2e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 76  ject...</ul>..<v
2860: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54  erbatim>..SELECT
2870: 20 53 71 6c 50 72 6f 63 5f 4e 75 6d 56 61 72 69   SqlProc_NumVari
2880: 61 62 6c 65 73 20 28 20 53 71 6c 50 72 6f 63 5f  ables ( SqlProc_
2890: 46 72 6f 6d 54 65 78 74 28 27 53 45 4c 45 43 54  FromText('SELECT
28a0: 20 40 63 6f 6c 40 20 46 52 4f 4d 20 40 74 62 6c   @col@ FROM @tbl
28b0: 40 27 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 32  @') );..-----..2
28c0: 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72  ....SELECT SqlPr
28d0: 6f 63 5f 56 61 72 69 61 62 6c 65 4e 20 28 53 71  oc_VariableN (Sq
28e0: 6c 50 72 6f 63 5f 46 72 6f 6d 54 65 78 74 28 27  lProc_FromText('
28f0: 53 45 4c 45 43 54 20 40 63 6f 6c 40 20 46 52 4f  SELECT @col@ FRO
2900: 4d 20 40 74 62 6c 40 27 29 2c 20 30 29 3b 0d 0a  M @tbl@'), 0);..
2910: 2d 2d 2d 2d 2d 0d 0a 40 63 6f 6c 40 0d 0a 0d 0a  -----..@col@....
2920: 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 56  SELECT SqlProc_V
2930: 61 72 69 61 62 6c 65 4e 20 28 53 71 6c 50 72 6f  ariableN (SqlPro
2940: 63 5f 46 72 6f 6d 54 65 78 74 28 27 53 45 4c 45  c_FromText('SELE
2950: 43 54 20 40 63 6f 6c 40 20 46 52 4f 4d 20 40 74  CT @col@ FROM @t
2960: 62 6c 40 27 29 2c 20 31 29 3b 0d 0a 2d 2d 2d 2d  bl@'), 1);..----
2970: 2d 0d 0a 40 74 62 6c 40 0d 0a 0d 0a 53 45 4c 45  -..@tbl@....SELE
2980: 43 54 20 53 71 6c 50 72 6f 63 5f 41 6c 6c 56 61  CT SqlProc_AllVa
2990: 72 69 61 62 6c 65 73 20 28 53 71 6c 50 72 6f 63  riables (SqlProc
29a0: 5f 46 72 6f 6d 54 65 78 74 28 27 53 45 4c 45 43  _FromText('SELEC
29b0: 54 20 40 63 6f 6c 40 20 46 52 4f 4d 20 40 74 62  T @col@ FROM @tb
29c0: 6c 40 27 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a  l@') );..-----..
29d0: 40 63 6f 6c 40 20 40 74 62 6c 40 0d 0a 3c 2f 76  @col@ @tbl@..</v
29e0: 65 72 62 61 74 69 6d 3e 0d 0a 3c 75 6c 3e 0d 0a  erbatim>..<ul>..
29f0: 3c 6c 69 3e 79 6f 75 20 63 61 6e 20 75 73 65 20  <li>you can use 
2a00: 3c 62 3e 53 71 6c 50 72 6f 63 5f 4e 75 6d 56 61  <b>SqlProc_NumVa
2a10: 72 69 61 62 6c 65 73 3c 2f 62 3e 20 69 6e 20 6f  riables</b> in o
2a20: 72 64 65 72 20 74 6f 20 63 68 65 63 6b 20 68 6f  rder to check ho
2a30: 77 20 6d 61 6e 79 20 56 61 72 69 61 62 6c 65 73  w many Variables
2a40: 20 61 72 65 20 64 65 66 69 6e 65 64 20 62 79 20   are defined by 
2a50: 61 20 53 51 4c 20 50 72 6f 63 65 64 75 72 65 20  a SQL Procedure 
2a60: 42 4c 4f 42 20 4f 62 6a 65 63 74 2e 3c 2f 6c 69  BLOB Object.</li
2a70: 3e 0d 0a 3c 6c 69 3e 61 6e 64 20 79 6f 75 20 63  >..<li>and you c
2a80: 61 6e 20 75 73 65 20 3c 62 3e 53 71 6c 50 72 6f  an use <b>SqlPro
2a90: 63 5f 56 61 72 69 61 62 6c 65 4e 3c 2f 62 3e 20  c_VariableN</b> 
2aa0: 69 6e 20 6f 72 64 65 72 20 74 6f 20 72 65 74 72  in order to retr
2ab0: 69 65 76 65 20 61 20 56 61 72 69 61 62 6c 65 20  ieve a Variable 
2ac0: 4e 61 6d 65 20 62 79 20 73 70 65 63 69 66 79 69  Name by specifyi
2ad0: 6e 67 20 69 74 73 20 72 65 6c 61 74 69 76 65 20  ng its relative 
2ae0: 3c 62 3e 49 6e 64 65 78 3c 2f 62 3e 20 28 46 69  <b>Index</b> (Fi
2af0: 72 73 74 20 56 61 72 69 61 62 6c 65 20 61 6c 77  rst Variable alw
2b00: 61 79 73 20 63 6f 72 72 65 73 70 6f 6e 64 73 20  ays corresponds 
2b10: 74 6f 20 3c 62 3e 49 6e 64 65 78 3d 30 3c 2f 62  to <b>Index=0</b
2b20: 3e 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e  >).</li>..<li>an
2b30: 64 20 66 69 6e 61 6c 6c 79 20 79 6f 75 20 63 61  d finally you ca
2b40: 6e 20 75 73 65 20 3c 62 3e 53 71 6c 50 72 6f 63  n use <b>SqlProc
2b50: 5f 41 6c 6c 56 61 72 69 61 62 6c 65 73 3c 2f 62  _AllVariables</b
2b60: 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 64 69  > in order to di
2b70: 72 65 63 74 6c 79 20 67 65 74 20 61 6c 6c 20 56  rectly get all V
2b80: 61 72 69 61 62 6c 65 20 4e 61 6d 65 73 20 66 6f  ariable Names fo
2b90: 72 6d 61 74 74 65 64 20 61 73 20 61 20 73 70 61  rmatted as a spa
2ba0: 63 65 2d 73 65 70 61 72 61 74 65 64 20 6c 69 73  ce-separated lis
2bb0: 74 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a  t.</li>..</ul>..
2bc0: 3c 62 72 3e 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d  <br><hr>..</li>.
2bd0: 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 45 72 72 6f 72  .<li>..<h4>Error
2be0: 20 68 61 6e 64 6c 69 6e 67 3c 2f 68 34 3e 0d 0a   handling</h4>..
2bf0: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45  <verbatim>..SELE
2c00: 43 54 20 53 71 6c 50 72 6f 63 5f 47 65 74 4c 61  CT SqlProc_GetLa
2c10: 73 74 45 72 72 6f 72 28 29 3b 0d 0a 3c 2f 76 65  stError();..</ve
2c20: 72 62 61 74 69 6d 3e 0d 0a 41 6c 6c 20 74 68 65  rbatim>..All the
2c30: 73 65 20 66 75 6e 63 74 69 6f 6e 73 20 77 69 6c  se functions wil
2c40: 6c 20 72 61 69 73 65 20 61 6e 20 45 78 63 65 70  l raise an Excep
2c50: 74 69 6f 6e 20 6f 6e 20 69 6e 76 61 6c 69 64 20  tion on invalid 
2c60: 61 72 67 75 6d 65 6e 74 73 20 6f 72 20 65 72 72  arguments or err
2c70: 6f 72 73 2e 3c 62 72 3e 0d 0a 42 79 20 63 61 6c  ors.<br>..By cal
2c80: 6c 69 6e 67 20 3c 62 3e 53 71 6c 50 72 6f 63 5f  ling <b>SqlProc_
2c90: 47 65 74 4c 61 73 74 45 72 72 6f 72 3c 2f 62 3e  GetLastError</b>
2ca0: 20 79 6f 75 27 6c 6c 20 75 73 75 61 6c 6c 79 20   you'll usually 
2cb0: 67 65 74 20 61 20 6d 6f 72 65 20 64 65 74 61 69  get a more detai
2cc0: 6c 65 64 20 65 78 70 6c 61 6e 61 74 69 6f 6e 20  led explanation 
2cd0: 61 62 6f 75 74 20 74 68 65 20 73 70 65 63 69 66  about the specif
2ce0: 69 63 20 63 61 75 73 65 20 61 63 63 6f 75 6e 74  ic cause account
2cf0: 69 6e 67 20 66 6f 72 20 74 68 65 20 66 61 69 6c  ing for the fail
2d00: 75 72 65 2e 0d 0a 3c 62 72 3e 3c 62 72 3e 3c 68  ure...<br><br><h
2d10: 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d  r>..</li>..<li>.
2d20: 0a 3c 68 34 3e 43 72 65 61 74 69 6e 67 20 56 61  .<h4>Creating Va
2d30: 72 69 61 62 6c 65 73 20 77 69 74 68 20 56 61 6c  riables with Val
2d40: 75 65 73 3c 2f 68 34 3e 0d 0a 3c 76 65 72 62 61  ues</h4>..<verba
2d50: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 71 6c  tim>..SELECT Sql
2d60: 50 72 6f 63 5f 56 61 72 56 61 6c 75 65 20 28 27  Proc_VarValue ('
2d70: 76 61 72 27 2c 20 4e 55 4c 4c 29 3b 0d 0a 2d 2d  var', NULL);..--
2d80: 2d 2d 2d 0d 0a 40 76 61 72 40 3d 4e 55 4c 4c 0d  ---..@var@=NULL.
2d90: 0a 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f  ...SELECT SqlPro
2da0: 63 5f 56 61 72 56 61 6c 75 65 20 28 27 76 61 72  c_VarValue ('var
2db0: 27 2c 20 31 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 40  ', 1);..-----..@
2dc0: 76 61 72 40 3d 31 0d 0a 0d 0a 53 45 4c 45 43 54  var@=1....SELECT
2dd0: 20 53 71 6c 50 72 6f 63 5f 56 61 72 56 61 6c 75   SqlProc_VarValu
2de0: 65 20 28 27 76 61 72 27 2c 20 31 30 2e 35 29 3b  e ('var', 10.5);
2df0: 0d 0a 2d 2d 2d 2d 2d 0d 0a 40 76 61 72 40 3d 31  ..-----..@var@=1
2e00: 30 2e 35 30 30 30 30 30 30 30 30 30 0d 0a 0d 0a  0.5000000000....
2e10: 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 56  SELECT SqlProc_V
2e20: 61 72 56 61 6c 75 65 20 28 27 76 61 72 27 2c 20  arValue ('var', 
2e30: 27 61 6c 70 68 61 20 62 65 74 61 27 29 3b 0d 0a  'alpha beta');..
2e40: 2d 2d 2d 2d 2d 0d 0a 40 76 61 72 40 3d 61 6c 70  -----..@var@=alp
2e50: 68 61 20 62 65 74 61 0d 0a 0d 0a 53 45 4c 45 43  ha beta....SELEC
2e60: 54 20 53 71 6c 50 72 6f 63 5f 56 61 72 56 61 6c  T SqlProc_VarVal
2e70: 75 65 20 28 27 76 61 72 27 2c 20 4d 61 6b 65 50  ue ('var', MakeP
2e80: 6f 69 6e 74 28 31 31 2e 35 2c 20 34 32 2e 35 2c  oint(11.5, 42.5,
2e90: 20 34 33 32 36 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d   4326) );..-----
2ea0: 0d 0a 40 76 61 72 40 3d 78 27 30 30 30 31 45 36  ..@var@=x'0001E6
2eb0: 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30  1000000000000000
2ec0: 30 30 32 37 34 30 30 30 30 30 30 30 30 30 30 30  0027400000000000
2ed0: 34 30 34 35 34 30 30 30 30 30 30 30 30 30 30 30  4045400000000000
2ee0: 30 30 32 37 34 30 30 30 30 30 30 30 30 30 30 30  0027400000000000
2ef0: 34 30 34 35 34 30 37 43 30 31 30 30 30 30 30 30  4045407C01000000
2f00: 30 30 30 30 30 30 30 30 30 30 30 30 32 37 34 30  0000000000002740
2f10: 30 30 30 30 30 30 30 30 30 30 34 30 34 35 34 30  0000000000404540
2f20: 46 45 27 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e  FE'..</verbatim>
2f30: 0d 0a 3c 75 3e 4e 6f 74 65 3c 2f 75 3e 3a 20 68  ..<u>Note</u>: h
2f40: 61 6e 64 20 77 72 69 74 69 6e 67 20 56 61 72 69  and writing Vari
2f50: 61 62 6c 65 20 77 69 74 68 20 56 61 6c 75 65 20  able with Value 
2f60: 73 74 72 69 6e 67 73 20 69 73 20 61 20 72 61 74  strings is a rat
2f70: 68 65 72 20 74 72 69 76 69 61 6c 20 6f 70 65 72  her trivial oper
2f80: 61 74 69 6f 6e 2c 20 73 6f 20 63 61 6c 6c 69 6e  ation, so callin
2f90: 67 20 74 68 69 73 20 53 51 4c 20 66 75 6e 63 74  g this SQL funct
2fa0: 69 6f 6e 20 69 73 20 6f 66 74 65 6e 20 6b 69 6e  ion is often kin
2fb0: 64 20 6f 66 20 61 6e 20 6f 76 65 72 6b 69 6c 6c  d of an overkill
2fc0: 2e 20 45 78 63 65 70 74 2c 20 6d 61 79 20 62 65  . Except, may be
2fd0: 2c 20 69 6e 20 74 68 65 20 63 61 73 65 20 6f 66  , in the case of
2fe0: 20 42 4c 4f 42 20 76 61 6c 75 65 73 2e 0d 0a 3c   BLOB values...<
2ff0: 62 72 3e 3c 62 72 3e 3c 68 72 3e 0d 0a 3c 2f 6c  br><br><hr>..</l
3000: 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 52 61  i>..<li>..<h4>Ra
3010: 77 20 61 6e 64 20 43 6f 6f 6b 65 64 20 53 51 4c  w and Cooked SQL
3020: 20 2d 20 72 65 70 6c 61 63 69 6e 67 20 53 79 6d   - replacing Sym
3030: 62 6f 6c 73 20 77 69 74 68 20 74 68 65 69 72 20  bols with their 
3040: 61 63 74 75 61 6c 20 56 61 6c 75 65 73 3c 2f 68  actual Values</h
3050: 34 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  4>..<verbatim>..
3060: 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 52  SELECT SqlProc_R
3070: 61 77 53 51 4c 20 28 20 53 71 6c 50 72 6f 63 5f  awSQL ( SqlProc_
3080: 46 72 6f 6d 54 65 78 74 28 27 53 45 4c 45 43 54  FromText('SELECT
3090: 20 40 63 6f 6c 40 20 46 52 4f 4d 20 40 74 62 6c   @col@ FROM @tbl
30a0: 40 3b 27 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a  @;') );..-----..
30b0: 53 45 4c 45 43 54 20 40 63 6f 6c 40 20 46 52 4f  SELECT @col@ FRO
30c0: 4d 20 40 74 62 6c 40 3b 0d 0a 0d 0a 53 45 4c 45  M @tbl@;....SELE
30d0: 43 54 20 53 71 6c 50 72 6f 63 5f 43 6f 6f 6b 65  CT SqlProc_Cooke
30e0: 64 53 51 4c 20 28 20 53 71 6c 50 72 6f 63 5f 46  dSQL ( SqlProc_F
30f0: 72 6f 6d 54 65 78 74 28 27 53 45 4c 45 43 54 20  romText('SELECT 
3100: 40 63 6f 6c 40 20 46 52 4f 4d 20 40 74 62 6c 40  @col@ FROM @tbl@
3110: 3b 27 29 2c 0d 0a 20 20 20 20 27 40 63 6f 6c 40  ;'),..    '@col@
3120: 3d 66 69 72 73 74 5f 6e 61 6d 65 27 2c 0d 0a 20  =first_name',.. 
3130: 20 20 20 27 40 74 62 6c 40 3d 70 68 6f 6e 65 5f     '@tbl@=phone_
3140: 62 6f 6f 6b 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d  book' );..-----.
3150: 0a 53 45 4c 45 43 54 20 66 69 72 73 74 5f 6e 61  .SELECT first_na
3160: 6d 65 20 46 52 4f 4d 20 70 68 6f 6e 65 5f 62 6f  me FROM phone_bo
3170: 6f 6b 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e  ok;..</verbatim>
3180: 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 79 6f 75 20  ..<ul>..<li>you 
3190: 63 61 6e 20 75 73 65 20 3c 62 3e 53 71 6c 50 72  can use <b>SqlPr
31a0: 6f 63 5f 52 61 77 53 51 4c 3c 2f 62 3e 20 69 6e  oc_RawSQL</b> in
31b0: 20 6f 72 64 65 72 20 74 6f 20 64 69 72 65 63 74   order to direct
31c0: 6c 79 20 63 68 65 63 6b 20 74 68 65 20 53 51 4c  ly check the SQL
31d0: 20 42 6f 64 79 20 65 6e 63 61 70 73 75 6c 61 74   Body encapsulat
31e0: 65 64 20 69 6e 74 6f 20 73 20 53 51 4c 20 50 72  ed into s SQL Pr
31f0: 6f 63 65 64 75 72 65 20 42 4c 4f 42 20 4f 62 6a  ocedure BLOB Obj
3200: 65 63 74 3b 20 61 6c 6c 20 69 6e 69 74 69 61 6c  ect; all initial
3210: 20 56 61 72 69 61 62 6c 65 20 64 65 66 69 6e 69   Variable defini
3220: 74 69 6f 6e 73 20 77 69 6c 6c 20 62 65 20 63 61  tions will be ca
3230: 72 65 66 75 6c 6c 79 20 70 72 65 73 65 72 76 65  refully preserve
3240: 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 64  d.</li>..<li>and
3250: 20 79 6f 75 20 63 61 6e 20 75 73 65 20 3c 62 3e   you can use <b>
3260: 53 71 6c 50 72 6f 63 5f 43 6f 6f 6b 65 64 53 51  SqlProc_CookedSQ
3270: 4c 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74  L</b> in order t
3280: 6f 20 64 69 72 65 63 74 6c 79 20 63 68 65 63 6b  o directly check
3290: 20 74 68 65 20 53 51 4c 20 42 6f 64 79 20 61 73   the SQL Body as
32a0: 20 69 74 20 61 63 74 75 61 6c 6c 79 20 61 70 70   it actually app
32b0: 65 61 72 73 20 61 66 74 65 72 20 72 65 70 6c 61  ears after repla
32c0: 63 69 6e 67 20 61 6c 6c 20 72 65 71 75 69 72 65  cing all require
32d0: 64 20 56 61 72 69 61 62 6c 65 20 56 61 6c 75 65  d Variable Value
32e0: 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 42 6f 74  s.</li>..<li>Bot
32f0: 68 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 65 20  h functions are 
3300: 6d 61 69 6e 6c 79 20 69 6e 74 65 6e 64 65 64 20  mainly intended 
3310: 66 6f 72 20 73 75 70 70 6f 72 74 69 6e 67 20 64  for supporting d
3320: 65 62 75 67 67 69 6e 67 20 61 63 74 69 76 69 74  ebugging activit
3330: 69 65 73 2c 20 73 6f 20 74 6f 20 6d 61 6b 65 20  ies, so to make 
3340: 61 73 20 65 61 73 79 20 61 73 20 70 6f 73 73 69  as easy as possi
3350: 62 6c 65 20 69 64 65 6e 74 69 66 79 69 6e 67 20  ble identifying 
3360: 65 76 65 6e 74 75 61 6c 20 65 72 72 6f 72 73 2e  eventual errors.
3370: 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e  </li>..</ul><br>
3380: 0d 0a 3c 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72  ..<table bgcolor
3390: 3d 22 23 66 38 66 38 64 38 22 20 63 65 6c 6c 70  ="#f8f8d8" cellp
33a0: 61 64 64 69 6e 67 3d 22 36 22 20 63 65 6c 6c 73  adding="6" cells
33b0: 70 61 63 69 6e 67 3d 22 38 22 3e 3c 74 72 3e 3c  pacing="8"><tr><
33c0: 74 64 3e 0d 0a 3c 75 3e 4e 6f 74 65 3c 2f 75 3e  td>..<u>Note</u>
33d0: 3a 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 43 6f 6f  : <b>SqlProc_Coo
33e0: 6b 65 64 53 51 4c 3c 2f 62 3e 20 77 69 6c 6c 20  kedSQL</b> will 
33f0: 61 63 63 65 70 74 20 61 6e 20 61 72 62 69 74 72  accept an arbitr
3400: 61 72 79 20 6c 69 73 74 20 6f 66 20 3c 62 3e 56  ary list of <b>V
3410: 61 72 69 61 62 6c 65 20 77 69 74 68 20 56 61 6c  ariable with Val
3420: 75 65 3c 2f 62 3e 20 61 72 67 75 6d 65 6e 74 73  ue</b> arguments
3430: 2e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 6e 20  ...<ul>..<li>an 
3440: 65 6d 70 74 79 20 6c 69 73 74 20 28 6e 6f 20 56  empty list (no V
3450: 61 72 69 61 62 6c 65 73 20 77 69 74 68 20 56 61  ariables with Va
3460: 6c 75 65 73 20 61 74 20 61 6c 6c 29 20 69 73 20  lues at all) is 
3470: 61 20 70 65 72 66 65 63 74 6c 79 20 6c 65 67 61  a perfectly lega
3480: 6c 20 63 6f 6e 64 69 74 69 6f 6e 20 28 63 6f 75  l condition (cou
3490: 6c 64 20 65 76 65 6e 74 75 61 6c 6c 79 20 6c 65  ld eventually le
34a0: 61 64 20 74 6f 20 61 6e 20 69 6e 76 61 6c 69 64  ad to an invalid
34b0: 20 43 6f 6f 6b 65 64 20 53 51 4c 20 42 6f 64 79   Cooked SQL Body
34c0: 2c 20 73 65 65 20 62 65 6c 6f 77 29 2e 3c 2f 6c  , see below).</l
34d0: 69 3e 0d 0a 3c 6c 69 3e 61 6c 6c 20 61 72 67 75  i>..<li>all argu
34e0: 6d 65 6e 74 73 20 66 72 6f 6d 20 74 68 65 20 73  ments from the s
34f0: 65 63 6f 6e 64 20 75 6e 74 69 6c 20 74 68 65 20  econd until the 
3500: 65 6e 64 20 61 72 65 20 65 78 70 65 63 74 65 64  end are expected
3510: 20 74 6f 20 62 65 20 77 65 6c 6c 2d 66 6f 72 6d   to be well-form
3520: 65 64 20 56 61 72 69 61 62 6c 65 73 20 77 69 74  ed Variables wit
3530: 68 20 56 61 6c 75 65 73 2e 3c 2f 6c 69 3e 0d 0a  h Values.</li>..
3540: 3c 6c 69 3e 79 6f 75 20 63 61 6e 20 64 65 66 69  <li>you can defi
3550: 6e 65 20 61 73 20 6d 75 63 68 20 61 73 20 3c 62  ne as much as <b
3560: 3e 31 36 3c 2f 62 3e 20 64 69 66 66 65 72 65 6e  >16</b> differen
3570: 74 20 56 61 72 69 61 62 6c 65 73 20 77 69 74 68  t Variables with
3580: 20 56 61 6c 75 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c   Values.</li>..<
3590: 6c 69 3e 61 6e 79 20 61 74 74 65 6d 70 74 20 74  li>any attempt t
35a0: 6f 20 64 65 66 69 6e 65 20 74 77 69 63 65 20 61  o define twice a
35b0: 20 56 61 6c 75 65 20 66 6f 72 20 74 68 65 20 73   Value for the s
35c0: 61 6d 65 20 56 61 72 69 61 62 6c 65 20 77 69 6c  ame Variable wil
35d0: 6c 20 62 65 20 61 6c 77 61 79 73 20 63 6f 6e 73  l be always cons
35e0: 69 64 65 72 65 64 20 61 73 20 61 20 66 61 74 61  idered as a fata
35f0: 6c 20 65 72 72 6f 72 2e 3c 2f 6c 69 3e 0d 0a 3c  l error.</li>..<
3600: 6c 69 3e 69 66 20 6f 6e 65 20 6f 66 20 74 68 65  li>if one of the
3610: 20 56 61 72 69 61 62 6c 65 20 61 72 67 75 6d 65   Variable argume
3620: 6e 74 73 20 64 6f 65 73 20 6e 6f 74 20 6d 61 74  nts does not mat
3630: 63 68 20 6f 6e 65 20 74 68 65 20 56 61 72 69 61  ch one the Varia
3640: 62 6c 65 73 20 69 6e 74 65 72 6e 61 6c 6c 79 20  bles internally 
3650: 64 65 66 69 6e 65 64 20 62 79 20 74 68 65 20 52  defined by the R
3660: 61 77 20 53 51 4c 20 42 6f 64 79 20 69 74 20 77  aw SQL Body it w
3670: 69 6c 6c 20 62 65 20 73 69 6d 70 6c 79 20 69 67  ill be simply ig
3680: 6e 6f 72 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  nored.</li>..<li
3690: 3e 69 66 20 61 20 56 61 72 69 61 62 6c 65 20 64  >if a Variable d
36a0: 65 66 69 6e 65 64 20 69 6e 74 6f 20 74 68 65 20  efined into the 
36b0: 52 61 77 20 53 51 4c 20 42 6f 64 79 20 64 6f 65  Raw SQL Body doe
36c0: 73 20 6e 6f 74 20 6d 61 74 63 68 65 73 20 61 20  s not matches a 
36d0: 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 56 61  corresponding Va
36e0: 72 69 61 62 6c 65 20 61 72 67 75 6d 65 6e 74 20  riable argument 
36f0: 74 68 65 6e 20 69 74 20 77 69 6c 6c 20 72 65 70  then it will rep
3700: 6c 61 63 65 64 20 62 79 20 61 20 64 65 66 61 75  laced by a defau
3710: 6c 74 20 27 3c 62 3e 4e 55 4c 4c 3c 2f 62 3e 27  lt '<b>NULL</b>'
3720: 20 73 74 72 69 6e 67 2e 3c 2f 6c 69 3e 0d 0a 3c   string.</li>..<
3730: 6c 69 3e 74 68 65 20 73 61 6d 65 20 69 64 65 6e  li>the same iden
3740: 74 69 63 61 6c 20 72 75 6c 65 73 20 66 6f 72 20  tical rules for 
3750: 70 61 73 73 69 6e 67 20 56 61 72 69 61 62 6c 65  passing Variable
3760: 2d 56 61 6c 75 65 20 61 72 67 75 6d 65 6e 74 73  -Value arguments
3770: 20 61 70 70 6c 79 20 74 6f 20 3c 62 3e 53 71 6c   apply to <b>Sql
3780: 50 72 6f 63 5f 43 6f 6f 6b 65 64 53 51 4c 3c 2f  Proc_CookedSQL</
3790: 62 3e 2c 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 45  b>, <b>SqlProc_E
37a0: 78 65 63 75 74 65 3c 2f 62 3e 20 61 6e 64 20 3c  xecute</b> and <
37b0: 62 3e 53 74 6f 72 65 64 50 72 6f 63 5f 45 78 65  b>StoredProc_Exe
37c0: 63 75 74 65 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a  cute</b>.</li>..
37d0: 3c 2f 75 6c 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72  </ul>..</td></tr
37e0: 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 62 72 3e 3c  ></table>..<br><
37f0: 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e  hr>..</li>..<li>
3800: 0d 0a 3c 68 34 3e 45 78 65 63 75 74 69 6e 67 20  ..<h4>Executing 
3810: 61 20 53 51 4c 20 50 72 6f 63 65 64 75 72 65 3c  a SQL Procedure<
3820: 2f 68 34 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e  /h4>..<verbatim>
3830: 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63  ..SELECT SqlProc
3840: 5f 45 78 65 63 75 74 65 20 28 53 71 6c 50 72 6f  _Execute (SqlPro
3850: 63 5f 46 72 6f 6d 54 65 78 74 28 27 53 45 4c 45  c_FromText('SELE
3860: 43 54 20 40 63 6f 6c 40 20 46 52 4f 4d 20 40 74  CT @col@ FROM @t
3870: 62 6c 40 3b 27 29 2c 0d 0a 20 20 20 20 27 40 63  bl@;'),..    '@c
3880: 6f 6c 40 3d 66 69 72 73 74 5f 6e 61 6d 65 27 2c  ol@=first_name',
3890: 0d 0a 20 20 20 20 27 40 74 62 6c 40 3d 70 68 6f  ..    '@tbl@=pho
38a0: 6e 65 5f 62 6f 6f 6b 27 20 29 3b 0d 0a 2d 2d 2d  ne_book' );..---
38b0: 2d 2d 0d 0a 53 71 6c 50 72 6f 63 20 65 78 63 65  --..SqlProc exce
38c0: 70 74 69 6f 6e 20 2d 20 61 20 66 61 74 61 6c 20  ption - a fatal 
38d0: 53 51 4c 20 65 72 72 6f 72 20 77 61 73 20 65 6e  SQL error was en
38e0: 63 6f 75 6e 74 65 72 65 64 2e 0d 0a 0d 0a 53 45  countered.....SE
38f0: 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 47 65 74  LECT SqlProc_Get
3900: 4c 61 73 74 45 72 72 6f 72 28 29 3b 0d 0a 2d 2d  LastError();..--
3910: 2d 2d 2d 0d 0a 67 61 69 61 5f 73 71 6c 5f 70 72  ---..gaia_sql_pr
3920: 6f 63 5f 65 78 65 63 75 74 65 3a 20 6e 6f 20 73  oc_execute: no s
3930: 75 63 68 20 74 61 62 6c 65 3a 20 70 68 6f 6e 65  uch table: phone
3940: 5f 62 6f 6f 6b 0d 0a 3c 2f 76 65 72 62 61 74 69  _book..</verbati
3950: 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 75 73 65 20  m>..you can use 
3960: 3c 62 3e 53 71 6c 50 72 6f 63 5f 45 78 65 63 75  <b>SqlProc_Execu
3970: 74 65 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20  te</b> in order 
3980: 74 6f 20 64 69 72 65 63 74 6c 79 20 65 78 65 63  to directly exec
3990: 75 74 65 20 74 68 65 20 77 68 6f 6c 65 20 53 51  ute the whole SQ
39a0: 4c 20 42 6f 64 79 20 61 73 20 61 20 73 69 6e 67  L Body as a sing
39b0: 6c 65 20 6d 6f 6e 6f 6c 69 74 68 69 63 20 75 6e  le monolithic un
39c0: 69 74 2e 3c 62 72 3e 0d 0a 41 74 20 74 68 65 20  it.<br>..At the 
39d0: 65 6e 64 20 6f 66 20 74 68 65 20 70 72 6f 63 65  end of the proce
39e0: 73 73 20 3c 62 3e 31 3c 2f 62 3e 20 28 61 6b 61  ss <b>1</b> (aka
39f0: 20 3c 62 3e 54 72 75 65 3c 2f 62 3e 29 20 77 69   <b>True</b>) wi
3a00: 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 20 6f  ll be returned o
3a10: 6e 20 66 75 6c 6c 20 73 75 63 63 65 73 73 3b 20  n full success; 
3a20: 61 6e 20 45 78 63 65 70 74 69 6f 6e 20 77 69 6c  an Exception wil
3a30: 6c 20 62 65 20 72 61 69 73 65 64 20 6f 6e 20 66  l be raised on f
3a40: 61 69 6c 75 72 65 2c 20 61 73 20 69 74 20 68 61  ailure, as it ha
3a50: 70 70 65 6e 73 20 69 6e 20 74 68 69 73 20 65 78  ppens in this ex
3a60: 61 6d 70 6c 65 2c 20 61 6e 64 20 69 6e 20 74 68  ample, and in th
3a70: 69 73 20 63 61 73 65 20 79 6f 75 20 63 61 6e 20  is case you can 
3a80: 74 68 65 6e 20 75 73 65 20 3c 62 3e 53 71 6c 50  then use <b>SqlP
3a90: 72 6f 63 5f 47 65 74 4c 61 73 74 45 72 72 6f 72  roc_GetLastError
3aa0: 3c 2f 62 3e 20 73 6f 20 74 6f 20 72 65 74 72 69  </b> so to retri
3ab0: 65 76 65 20 74 68 65 20 63 6f 72 72 65 73 70 6f  eve the correspo
3ac0: 6e 64 69 6e 67 20 53 51 4c 20 65 72 72 6f 72 20  nding SQL error 
3ad0: 6d 65 73 73 61 67 65 2e 0d 0a 3c 62 72 3e 3c 62  message...<br><b
3ae0: 72 3e 0d 0a 3c 74 61 62 6c 65 20 62 67 63 6f 6c  r>..<table bgcol
3af0: 6f 72 3d 22 23 66 38 66 38 64 38 22 20 63 65 6c  or="#f8f8d8" cel
3b00: 6c 70 61 64 64 69 6e 67 3d 22 36 22 20 63 65 6c  lpadding="6" cel
3b10: 6c 73 70 61 63 69 6e 67 3d 22 38 22 3e 3c 74 72  lspacing="8"><tr
3b20: 3e 3c 74 64 3e 0d 0a 3c 75 3e 4e 6f 74 65 3c 2f  ><td>..<u>Note</
3b30: 75 3e 3a 20 61 6c 6c 20 3c 62 3e 44 6f 74 20 4d  u>: all <b>Dot M
3b40: 61 63 72 6f 73 3c 2f 62 3e 20 65 76 65 6e 74 75  acros</b> eventu
3b50: 61 6c 6c 79 20 66 6f 75 6e 64 20 77 69 74 68 69  ally found withi
3b60: 6e 20 74 68 65 20 53 51 4c 20 42 6f 64 79 20 62  n the SQL Body b
3b70: 65 69 6e 67 20 65 78 65 63 75 74 65 64 20 77 69  eing executed wi
3b80: 6c 6c 20 62 65 20 61 6c 77 61 79 73 20 73 69 6c  ll be always sil
3b90: 65 6e 74 6c 79 20 69 67 6e 6f 72 65 64 2e 3c 62  ently ignored.<b
3ba0: 72 3e 0d 0a 54 68 65 20 73 61 6d 65 20 72 75 6c  r>..The same rul
3bb0: 65 20 61 70 70 6c 69 65 73 20 74 6f 20 3c 62 3e  e applies to <b>
3bc0: 53 74 6f 72 65 64 50 72 6f 63 5f 45 78 65 63 75  StoredProc_Execu
3bd0: 74 65 3c 2f 62 3e 20 61 73 20 77 65 6c 6c 2e 3c  te</b> as well.<
3be0: 2f 62 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 3c  /b>..</td></tr><
3bf0: 2f 74 61 62 6c 65 3e 0d 0a 3c 62 72 3e 3c 68 72  /table>..<br><hr
3c00: 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d 0a  >..</li>..<li>..
3c10: 3c 68 34 3e 48 61 6e 64 6c 69 6e 67 20 53 51 4c  <h4>Handling SQL
3c20: 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72   Stored Procedur
3c30: 65 73 3c 2f 68 34 3e 0d 0a 3c 76 65 72 62 61 74  es</h4>..<verbat
3c40: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72  im>..SELECT Stor
3c50: 65 64 50 72 6f 63 5f 43 72 65 61 74 65 54 61 62  edProc_CreateTab
3c60: 6c 65 73 28 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31  les();..-----..1
3c70: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 79  ..</verbatim>..y
3c80: 6f 75 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 74  ou can use <b>St
3c90: 6f 72 65 64 50 72 6f 63 5f 43 72 65 61 74 65 54  oredProc_CreateT
3ca0: 61 62 6c 65 73 3c 2f 62 3e 20 69 6e 20 6f 72 64  ables</b> in ord
3cb0: 65 72 20 74 6f 20 63 72 65 61 74 65 20 6f 6e 20  er to create on 
3cc0: 79 6f 75 72 20 63 75 72 72 65 6e 74 6c 79 20 63  your currently c
3cd0: 6f 6e 6e 65 63 74 65 64 20 64 61 74 61 62 61 73  onnected databas
3ce0: 65 20 61 6c 6c 20 3c 62 3e 6d 65 74 61 74 61 62  e all <b>metatab
3cf0: 6c 65 73 3c 2f 62 3e 20 72 65 71 75 69 72 65 64  les</b> required
3d00: 20 74 6f 20 70 65 72 6d 61 6e 65 6e 74 6c 79 20   to permanently 
3d10: 72 65 67 69 73 74 65 72 20 53 74 6f 72 65 64 20  register Stored 
3d20: 50 72 6f 63 65 64 75 72 65 73 20 61 6e 64 20 53  Procedures and S
3d30: 74 6f 72 65 64 20 56 61 72 69 61 62 6c 65 73 2e  tored Variables.
3d40: 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65  <br><br>..<table
3d50: 20 62 67 63 6f 6c 6f 72 3d 22 23 66 38 66 38 64   bgcolor="#f8f8d
3d60: 38 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22  8" cellpadding="
3d70: 36 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22  6" cellspacing="
3d80: 38 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 3c 75 3e  8"><tr><td>..<u>
3d90: 4e 6f 74 65 3c 2f 75 3e 3a 20 61 6e 79 20 6e 65  Note</u>: any ne
3da0: 77 20 64 61 74 61 62 61 73 65 20 63 72 65 61 74  w database creat
3db0: 65 64 20 62 79 20 53 70 61 74 69 61 4c 69 74 65  ed by SpatiaLite
3dc0: 20 34 2e 35 2e 30 20 28 61 6e 64 20 73 75 62 73   4.5.0 (and subs
3dd0: 65 71 75 65 6e 74 20 76 65 72 73 69 6f 6e 73 29  equent versions)
3de0: 20 77 69 6c 6c 20 61 75 74 6f 6d 61 74 69 63 61   will automatica
3df0: 6c 6c 79 20 73 75 70 70 6f 72 74 20 74 68 65 20  lly support the 
3e00: 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65  Stored Procedure
3e10: 73 20 6d 65 74 61 74 61 62 6c 65 73 2e 0d 0a 45  s metatables...E
3e20: 78 70 6c 69 63 69 74 6c 79 20 63 61 6c 6c 69 6e  xplicitly callin
3e30: 67 20 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 20  g this function 
3e40: 69 73 20 6d 61 69 6e 6c 79 20 75 73 65 66 75 6c  is mainly useful
3e50: 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 72 65 74   in order to ret
3e60: 72 6f 66 69 74 20 53 74 6f 72 65 64 20 50 72 6f  rofit Stored Pro
3e70: 63 65 64 75 72 65 73 20 73 75 70 70 6f 72 74 20  cedures support 
3e80: 6f 6e 20 61 6c 72 65 61 64 79 20 65 78 69 73 74  on already exist
3e90: 69 6e 67 20 64 61 74 61 62 61 73 65 73 20 63 72  ing databases cr
3ea0: 65 61 74 65 20 62 79 20 70 72 65 76 69 6f 75 73  eate by previous
3eb0: 20 76 65 72 73 69 6f 6e 73 2e 0d 0a 43 61 6c 6c   versions...Call
3ec0: 69 6e 67 20 3c 62 3e 53 74 6f 72 65 64 50 72 6f  ing <b>StoredPro
3ed0: 63 5f 43 72 65 61 74 65 54 61 62 6c 65 73 3c 2f  c_CreateTables</
3ee0: 62 3e 20 6f 6e 20 62 65 68 61 6c 66 20 6f 66 20  b> on behalf of 
3ef0: 61 20 64 61 74 61 62 61 73 65 20 61 6c 72 65 61  a database alrea
3f00: 64 79 20 73 75 70 70 6f 72 74 69 6e 67 20 74 68  dy supporting th
3f10: 65 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75  e Stored Procedu
3f20: 72 65 73 20 6d 65 74 61 74 61 62 6c 65 20 69 73  res metatable is
3f30: 20 61 6e 20 68 61 72 6d 6c 65 73 73 20 6f 70 65   an harmless ope
3f40: 72 61 74 69 6f 6e 20 73 69 6d 70 6c 79 20 72 65  ration simply re
3f50: 74 75 72 6e 69 6e 67 20 3c 62 3e 31 3c 2f 62 3e  turning <b>1</b>
3f60: 20 28 66 75 6c 6c 20 73 75 63 63 65 73 73 29 2e   (full success).
3f70: 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61  ..</td></tr></ta
3f80: 62 6c 65 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e  ble>..<verbatim>
3f90: 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50  ..SELECT StoredP
3fa0: 72 6f 63 5f 52 65 67 69 73 74 65 72 20 28 20 27  roc_Register ( '
3fb0: 73 70 5f 31 27 2c 20 27 61 20 73 61 6d 70 6c 65  sp_1', 'a sample
3fc0: 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72   Stored Procedur
3fd0: 65 20 66 6f 72 20 74 65 73 74 69 6e 67 27 2c 20  e for testing', 
3fe0: 53 71 6c 50 72 6f 63 5f 46 72 6f 6d 54 65 78 74  SqlProc_FromText
3ff0: 28 27 53 45 4c 45 43 54 20 40 63 6f 6c 40 20 46  ('SELECT @col@ F
4000: 52 4f 4d 20 40 74 62 6c 40 3b 27 20 29 29 3b 0d  ROM @tbl@;' ));.
4010: 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72  .-----..1..</ver
4020: 62 61 74 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20  batim>..you can 
4030: 75 73 65 20 3c 62 3e 53 74 6f 72 65 64 50 72 6f  use <b>StoredPro
4040: 63 5f 52 65 67 69 73 74 65 72 3c 2f 62 3e 20 69  c_Register</b> i
4050: 6e 20 6f 72 64 65 72 20 74 6f 20 70 65 72 6d 61  n order to perma
4060: 6e 65 6e 74 6c 79 20 72 65 67 69 73 74 65 72 20  nently register 
4070: 61 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75  a Stored Procedu
4080: 72 65 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d  re...<verbatim>.
4090: 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50 72  .SELECT StoredPr
40a0: 6f 63 5f 44 65 6c 65 74 65 20 28 20 27 73 70 5f  oc_Delete ( 'sp_
40b0: 31 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d  1' );..-----..1.
40c0: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 79 6f  .</verbatim>..yo
40d0: 75 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 74 6f  u can use <b>Sto
40e0: 72 65 64 50 72 6f 63 5f 44 65 6c 65 74 65 3c 2f  redProc_Delete</
40f0: 62 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 70  b> in order to p
4100: 65 72 6d 61 6e 65 6e 74 6c 79 20 72 65 6d 6f 76  ermanently remov
4110: 65 20 61 20 70 72 65 76 69 6f 75 73 6c 79 20 72  e a previously r
4120: 65 67 69 73 74 65 72 65 64 20 53 74 6f 72 65 64  egistered Stored
4130: 20 50 72 6f 63 65 64 75 72 65 2e 0d 0a 3c 76 65   Procedure...<ve
4140: 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20  rbatim>..SELECT 
4150: 53 71 6c 50 72 6f 63 5f 52 61 77 53 51 4c 20 28  SqlProc_RawSQL (
4160: 20 53 74 6f 72 65 64 50 72 6f 63 5f 47 65 74 20   StoredProc_Get 
4170: 28 20 27 73 70 5f 31 27 20 29 20 29 3b 0d 0a 2d  ( 'sp_1' ) );..-
4180: 2d 2d 2d 2d 0d 0a 53 45 4c 45 43 54 20 40 63 6f  ----..SELECT @co
4190: 6c 40 20 46 52 4f 4d 20 40 74 62 6c 40 3b 0d 0a  l@ FROM @tbl@;..
41a0: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 79 6f 75  </verbatim>..you
41b0: 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 74 6f 72   can use <b>Stor
41c0: 65 64 50 72 6f 63 5f 47 65 74 3c 2f 62 3e 20 69  edProc_Get</b> i
41d0: 6e 20 6f 72 64 65 72 20 74 6f 20 72 65 74 72 69  n order to retri
41e0: 65 76 65 20 74 68 65 20 53 51 4c 20 50 72 6f 63  eve the SQL Proc
41f0: 65 64 75 72 65 20 42 4c 4f 42 20 4f 62 6a 65 63  edure BLOB Objec
4200: 74 20 66 72 6f 6d 20 61 20 72 65 67 69 73 74 65  t from a registe
4210: 72 65 64 20 53 74 6f 72 65 64 20 50 72 6f 63 65  red Stored Proce
4220: 64 75 72 65 2e 0d 0a 3c 76 65 72 62 61 74 69 6d  dure...<verbatim
4230: 3e 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64  >..SELECT Stored
4240: 50 72 6f 63 5f 55 70 64 61 74 65 54 69 74 6c 65  Proc_UpdateTitle
4250: 20 28 20 27 73 70 5f 31 27 2c 20 27 74 68 69 73   ( 'sp_1', 'this
4260: 20 54 69 74 6c 65 20 77 61 73 20 63 68 61 6e 67   Title was chang
4270: 65 64 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31  ed' );..-----..1
4280: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 79  ..</verbatim>..y
4290: 6f 75 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 74  ou can use <b>St
42a0: 6f 72 65 64 50 72 6f 63 5f 55 70 64 61 74 65 54  oredProc_UpdateT
42b0: 69 74 6c 65 3c 2f 62 3e 20 69 6e 20 6f 72 64 65  itle</b> in orde
42c0: 72 20 74 6f 20 6d 6f 64 69 66 79 20 74 68 65 20  r to modify the 
42d0: 54 69 74 6c 65 20 6f 66 20 61 6e 20 61 6c 72 65  Title of an alre
42e0: 61 64 79 20 72 65 67 69 73 74 65 72 65 64 20 53  ady registered S
42f0: 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65 2e  tored Procedure.
4300: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45  ..<verbatim>..SE
4310: 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f 63 5f  LECT StoredProc_
4320: 55 70 64 61 74 65 53 71 6c 42 6f 64 79 20 28 20  UpdateSqlBody ( 
4330: 27 73 70 5f 31 27 2c 20 53 71 6c 50 72 6f 63 5f  'sp_1', SqlProc_
4340: 46 72 6f 6d 46 69 6c 65 28 27 2f 68 6f 6d 65 2f  FromFile('/home/
4350: 6a 6f 65 2f 73 71 6c 5f 73 63 72 69 70 74 73 2f  joe/sql_scripts/
4360: 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74  stored_proc_test
4370: 5f 76 32 2e 74 78 74 27 20 29 3b 0d 0a 2d 2d 2d  _v2.txt' );..---
4380: 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69  --..1..</verbati
4390: 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 75 73 65 20  m>..you can use 
43a0: 3c 62 3e 53 74 6f 72 65 64 50 72 6f 63 5f 55 70  <b>StoredProc_Up
43b0: 64 61 74 65 53 71 6c 42 6f 64 79 3c 2f 62 3e 20  dateSqlBody</b> 
43c0: 69 6e 20 6f 72 64 65 72 20 74 6f 20 6d 6f 64 69  in order to modi
43d0: 66 79 20 74 68 65 20 53 71 6c 20 42 6f 64 79 20  fy the Sql Body 
43e0: 6f 66 20 61 6e 20 61 6c 72 65 61 64 79 20 72 65  of an already re
43f0: 67 69 73 74 65 72 65 64 20 53 74 6f 72 65 64 20  gistered Stored 
4400: 50 72 6f 63 65 64 75 72 65 20 28 65 2e 67 2e 20  Procedure (e.g. 
4410: 62 65 63 61 75 73 65 20 79 6f 75 27 76 65 20 64  because you've d
4420: 69 73 63 6f 76 65 72 65 64 20 61 6e 64 20 66 69  iscovered and fi
4430: 78 65 64 20 73 6f 6d 65 20 62 75 67 20 61 66 66  xed some bug aff
4440: 65 63 74 69 6e 67 20 74 68 65 20 70 72 65 76 69  ecting the previ
4450: 6f 75 73 20 53 51 4c 20 69 6d 70 6c 65 6d 65 6e  ous SQL implemen
4460: 74 61 74 69 6f 6e 29 2e 3c 76 65 72 62 61 74 69  tation).<verbati
4470: 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65  m>..SELECT Store
4480: 64 50 72 6f 63 5f 45 78 65 63 75 74 65 20 28 20  dProc_Execute ( 
4490: 27 73 70 5f 31 27 2c 0d 0a 20 20 20 20 27 40 63  'sp_1',..    '@c
44a0: 6f 6c 40 3d 73 72 69 64 27 2c 0d 0a 20 20 20 20  ol@=srid',..    
44b0: 27 40 74 62 6c 40 3d 73 70 61 74 69 61 6c 5f 72  '@tbl@=spatial_r
44c0: 65 66 5f 73 79 73 27 20 29 3b 0d 0a 2d 2d 2d 2d  ef_sys' );..----
44d0: 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69 6d  -..1..</verbatim
44e0: 3e 0d 0a 61 6e 64 20 66 69 6e 61 6c 6c 79 20 79  >..and finally y
44f0: 6f 75 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 74  ou can use <b>St
4500: 6f 72 65 64 50 72 6f 63 5f 45 78 65 63 75 74 65  oredProc_Execute
4510: 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f  </b> in order to
4520: 20 64 69 72 65 63 74 6c 79 20 65 78 65 63 75 74   directly execut
4530: 65 20 61 20 53 74 6f 72 65 64 20 50 72 6f 63 65  e a Stored Proce
4540: 64 75 72 65 20 61 73 20 61 20 73 69 6e 67 6c 65  dure as a single
4550: 20 6d 6f 6e 6f 6c 69 74 68 69 63 20 75 6e 69 74   monolithic unit
4560: 2e 3c 62 72 3e 0d 0a 3c 62 72 3e 3c 62 72 3e 3c  .<br>..<br><br><
4570: 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e  hr>..</li>..<li>
4580: 0d 0a 3c 68 34 3e 48 61 6e 64 6c 69 6e 67 20 53  ..<h4>Handling S
4590: 51 4c 20 53 74 6f 72 65 64 20 56 61 72 69 61 62  QL Stored Variab
45a0: 6c 65 73 3c 2f 68 34 3e 0d 0a 3c 76 65 72 62 61  les</h4>..<verba
45b0: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 74 6f  tim>..SELECT Sto
45c0: 72 65 64 56 61 72 5f 52 65 67 69 73 74 65 72 20  redVar_Register 
45d0: 28 20 27 70 69 27 2c 20 27 61 6e 20 75 6e 69 76  ( 'pi', 'an univ
45e0: 65 72 73 61 6c 6c 79 20 75 73 65 66 75 6c 20 63  ersally useful c
45f0: 6f 6e 73 74 61 6e 74 27 2c 20 27 33 2e 31 34 27  onstant', '3.14'
4600: 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c   );..-----..1..<
4610: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 79 6f 75 20  /verbatim>..you 
4620: 63 61 6e 20 75 73 65 20 3c 62 3e 53 74 6f 72 65  can use <b>Store
4630: 64 56 61 72 5f 52 65 67 69 73 74 65 72 3c 2f 62  dVar_Register</b
4640: 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 70 65  > in order to pe
4650: 72 6d 61 6e 65 6e 74 6c 79 20 72 65 67 69 73 74  rmanently regist
4660: 65 72 20 61 20 53 74 6f 72 65 64 20 56 61 72 69  er a Stored Vari
4670: 61 62 6c 65 2e 0d 0a 3c 76 65 72 62 61 74 69 6d  able...<verbatim
4680: 3e 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64  >..SELECT Stored
4690: 56 61 72 5f 44 65 6c 65 74 65 20 28 20 27 70 69  Var_Delete ( 'pi
46a0: 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a  ' );..-----..1..
46b0: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 79 6f 75  </verbatim>..you
46c0: 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 74 6f 72   can use <b>Stor
46d0: 65 64 56 61 72 5f 44 65 6c 65 74 65 3c 2f 62 3e  edVar_Delete</b>
46e0: 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 70 65 72   in order to per
46f0: 6d 61 6e 65 6e 74 6c 79 20 72 65 6d 6f 76 65 20  manently remove 
4700: 61 20 70 72 65 76 69 6f 75 73 6c 79 20 72 65 67  a previously reg
4710: 69 73 74 65 72 65 64 20 53 74 6f 72 65 64 20 56  istered Stored V
4720: 61 72 69 61 62 6c 65 2e 0d 0a 3c 76 65 72 62 61  ariable...<verba
4730: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 74 6f  tim>..SELECT Sto
4740: 72 65 64 56 61 72 5f 47 65 74 20 28 20 27 70 69  redVar_Get ( 'pi
4750: 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 40 50 49  ' );..-----..@PI
4760: 40 3d 33 2e 31 34 0d 0a 3c 2f 76 65 72 62 61 74  @=3.14..</verbat
4770: 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 75 73 65  im>..you can use
4780: 20 3c 62 3e 53 74 6f 72 65 64 56 61 72 5f 47 65   <b>StoredVar_Ge
4790: 74 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74  t</b> in order t
47a0: 6f 20 72 65 74 72 69 65 76 65 20 74 68 65 20 56  o retrieve the V
47b0: 61 72 69 61 62 6c 65 20 77 69 74 68 20 56 61 6c  ariable with Val
47c0: 75 65 20 73 74 72 69 6e 67 20 66 72 6f 6d 20 61  ue string from a
47d0: 20 72 65 67 69 73 74 65 72 65 64 20 53 74 6f 72   registered Stor
47e0: 65 64 20 56 61 72 69 61 62 6c 65 2e 0d 0a 3c 76  ed Variable...<v
47f0: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54  erbatim>..SELECT
4800: 20 53 74 6f 72 65 64 56 61 72 5f 55 70 64 61 74   StoredVar_Updat
4810: 65 54 69 74 6c 65 20 28 20 27 70 69 27 2c 20 27  eTitle ( 'pi', '
4820: 50 49 20 2d 20 74 68 65 20 6d 61 67 69 63 20 6e  PI - the magic n
4830: 75 6d 62 65 72 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d  umber' );..-----
4840: 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e  ..1..</verbatim>
4850: 0d 0a 79 6f 75 20 63 61 6e 20 75 73 65 20 3c 62  ..you can use <b
4860: 3e 53 74 6f 72 65 64 56 61 72 5f 55 70 64 61 74  >StoredVar_Updat
4870: 65 54 69 74 6c 65 3c 2f 62 3e 20 69 6e 20 6f 72  eTitle</b> in or
4880: 64 65 72 20 74 6f 20 6d 6f 64 69 66 79 20 74 68  der to modify th
4890: 65 20 54 69 74 6c 65 20 6f 66 20 61 6e 20 61 6c  e Title of an al
48a0: 72 65 61 64 79 20 72 65 67 69 73 74 65 72 65 64  ready registered
48b0: 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72   Stored Procedur
48c0: 65 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  e...<verbatim>..
48d0: 53 45 4c 45 43 54 20 53 74 6f 72 65 64 56 61 72  SELECT StoredVar
48e0: 5f 55 70 64 61 74 65 56 61 6c 75 65 20 28 20 27  _UpdateValue ( '
48f0: 70 69 27 2c 20 27 33 2e 31 34 31 35 39 32 36 35  pi', '3.14159265
4900: 33 35 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31  35' );..-----..1
4910: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 61  ..</verbatim>..a
4920: 6e 64 20 66 69 6e 61 6c 6c 79 20 79 6f 75 20 63  nd finally you c
4930: 61 6e 20 75 73 65 20 3c 62 3e 53 74 6f 72 65 64  an use <b>Stored
4940: 56 61 72 5f 55 70 64 61 74 65 56 61 6c 75 65 3c  Var_UpdateValue<
4950: 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20  /b> in order to 
4960: 6d 6f 64 69 66 79 20 74 68 65 20 56 61 72 69 61  modify the Varia
4970: 62 6c 65 20 77 69 74 68 20 56 61 6c 75 65 20 6f  ble with Value o
4980: 66 20 61 6e 20 61 6c 72 65 61 64 79 20 72 65 67  f an already reg
4990: 69 73 74 65 72 65 64 20 53 74 6f 72 65 64 20 56  istered Stored V
49a0: 61 72 69 61 62 6c 65 2e 0d 0a 3c 2f 6c 69 3e 3c  ariable...</li><
49b0: 62 72 3e 3c 68 72 3e 0d 0a 3c 6c 69 3e 0d 0a 3c  br><hr>..<li>..<
49c0: 68 34 3e 48 61 6e 64 6c 69 6e 67 20 74 68 65 20  h4>Handling the 
49d0: 53 51 4c 20 4c 6f 67 66 69 6c 65 3c 2f 68 34 3e  SQL Logfile</h4>
49e0: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45  ..<verbatim>..SE
49f0: 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 53 65 74  LECT SqlProc_Set
4a00: 4c 6f 67 66 69 6c 65 20 28 20 27 2f 68 6f 6d 65  Logfile ( '/home
4a10: 2f 73 61 6e 64 72 6f 2f 73 71 6c 5f 6c 6f 67 2e  /sandro/sql_log.
4a20: 74 78 74 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a  txt' );..-----..
4a30: 31 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50  1....SELECT SqlP
4a40: 72 6f 63 5f 53 65 74 4c 6f 67 66 69 6c 65 20 28  roc_SetLogfile (
4a50: 20 27 2f 68 6f 6d 65 2f 73 61 6e 64 72 6f 2f 73   '/home/sandro/s
4a60: 71 6c 5f 6c 6f 67 2e 74 78 74 27 2c 20 31 29 3b  ql_log.txt', 1);
4a70: 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a 53 45  ..-----..1....SE
4a80: 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 53 65 74  LECT SqlProc_Set
4a90: 4c 6f 67 66 69 6c 65 20 28 20 4e 55 4c 4c 20 29  Logfile ( NULL )
4aa0: 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76  ;..-----..1..</v
4ab0: 65 72 62 61 74 69 6d 3e 0d 0a 59 6f 75 20 63 61  erbatim>..You ca
4ac0: 6e 20 75 73 65 20 3c 62 3e 53 71 6c 50 72 6f 63  n use <b>SqlProc
4ad0: 5f 53 65 74 4c 6f 67 66 69 6c 65 28 29 3c 2f 62  _SetLogfile()</b
4ae0: 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 65 6e  > in order to en
4af0: 61 62 6c 65 20 6f 72 20 64 69 73 61 62 6c 65 20  able or disable 
4b00: 74 68 65 20 53 51 4c 20 4c 6f 67 66 69 6c 65 3a  the SQL Logfile:
4b10: 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 74 68 65 20  ..<ul>..<li>the 
4b20: 66 69 72 73 74 20 66 6f 72 6d 20 28 73 69 6e 67  first form (sing
4b30: 6c 65 20 61 72 67 75 6d 65 6e 74 29 20 6a 75 73  le argument) jus
4b40: 74 20 72 65 71 75 69 72 65 73 20 74 6f 20 64 65  t requires to de
4b50: 66 69 6e 65 20 74 68 65 20 3c 62 3e 61 62 73 6f  fine the <b>abso
4b60: 6c 75 74 65 3c 2f 62 3e 20 6f 72 20 3c 62 3e 72  lute</b> or <b>r
4b70: 65 6c 61 74 69 76 65 20 70 61 74 68 6e 61 6d 65  elative pathname
4b80: 3c 2f 62 3e 20 6f 66 20 74 68 65 20 69 6e 74 65  </b> of the inte
4b90: 6e 64 65 64 20 4c 6f 67 66 69 6c 65 2e 3c 62 72  nded Logfile.<br
4ba0: 3e 0d 0a 41 20 4c 6f 67 66 69 6c 65 20 64 65 66  >..A Logfile def
4bb0: 69 6e 65 64 20 69 6e 20 73 75 63 68 20 61 20 77  ined in such a w
4bc0: 61 79 20 77 69 6c 6c 20 62 65 20 61 6c 77 61 79  ay will be alway
4bd0: 73 20 6f 70 65 72 61 74 65 20 69 6e 20 3c 62 3e  s operate in <b>
4be0: 54 72 75 6e 63 61 74 65 3c 2f 62 3e 20 6d 6f 64  Truncate</b> mod
4bf0: 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 74 68 65  e.</li>..<li>the
4c00: 20 73 65 63 6f 6e 64 20 66 6f 72 6d 20 28 74 77   second form (tw
4c10: 6f 20 61 72 67 75 6d 65 6e 74 73 29 20 73 75 70  o arguments) sup
4c20: 70 6f 72 74 73 20 61 20 66 75 72 74 68 65 72 20  ports a further 
4c30: 3c 62 3e 6d 6f 64 65 3c 2f 62 3e 20 61 72 67 75  <b>mode</b> argu
4c40: 6d 65 6e 74 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69  ment:..<ul>..<li
4c50: 3e 69 66 20 73 65 74 20 74 6f 20 3c 62 3e 46 41  >if set to <b>FA
4c60: 4c 53 45 3c 2f 62 3e 20 28 3c 62 3e 30 3c 2f 62  LSE</b> (<b>0</b
4c70: 3e 2c 20 64 65 66 61 75 6c 74 20 76 61 6c 75 65  >, default value
4c80: 29 20 74 68 65 20 4c 6f 67 66 69 6c 65 20 77 69  ) the Logfile wi
4c90: 6c 6c 20 6f 70 65 72 61 74 65 20 69 6e 20 3c 62  ll operate in <b
4ca0: 3e 54 72 75 6e 63 61 74 65 3c 2f 62 3e 20 6d 6f  >Truncate</b> mo
4cb0: 64 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 69 66  de.</li>..<li>if
4cc0: 20 73 65 74 20 74 6f 20 3c 62 3e 54 52 55 45 3c   set to <b>TRUE<
4cd0: 2f 62 3e 20 28 61 6e 79 20 6f 74 68 65 72 20 76  /b> (any other v
4ce0: 61 6c 75 65 20 64 69 66 66 65 72 65 6e 74 20 66  alue different f
4cf0: 72 6f 6d 20 3c 62 3e 30 3c 2f 62 3e 29 20 74 68  rom <b>0</b>) th
4d00: 65 20 4c 6f 67 66 69 6c 65 20 77 69 6c 6c 20 6f  e Logfile will o
4d10: 70 65 72 61 74 65 20 69 6e 20 3c 62 3e 41 70 70  perate in <b>App
4d20: 65 6e 64 3c 2f 62 3e 20 6d 6f 64 65 2e 3c 2f 6c  end</b> mode.</l
4d30: 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 6c 69 3e 66  i>..</ul>..<li>f
4d40: 69 6e 61 6c 6c 79 2c 20 79 6f 75 20 63 61 6e 20  inally, you can 
4d50: 70 61 73 73 20 61 20 3c 62 3e 4e 55 4c 4c 3c 2f  pass a <b>NULL</
4d60: 62 3e 20 70 61 74 68 20 61 72 67 75 6d 65 6e 74  b> path argument
4d70: 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 69 6d 6d   in order to imm
4d80: 65 64 69 61 74 65 6c 79 20 64 69 73 61 62 6c 65  ediately disable
4d90: 20 74 68 65 20 4c 6f 67 66 69 6c 65 2e 3c 2f 6c   the Logfile.</l
4da0: 69 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e  i>..</li>..</ul>
4db0: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45  ..<verbatim>..SE
4dc0: 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 47 65 74  LECT SqlProc_Get
4dd0: 4c 6f 67 66 69 6c 65 28 29 3b 0d 0a 2d 2d 2d 2d  Logfile();..----
4de0: 2d 0d 0a 2f 68 6f 6d 65 2f 73 61 6e 64 72 6f 2f  -../home/sandro/
4df0: 73 71 6c 5f 6c 6f 67 2e 74 78 74 0d 0a 0d 0a 53  sql_log.txt....S
4e00: 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 47 65  ELECT SqlProc_Ge
4e10: 74 4c 6f 67 66 69 6c 65 28 29 3b 0d 0a 2d 2d 2d  tLogfile();..---
4e20: 2d 2d 0d 0a 4e 55 4c 4c 0d 0a 3c 2f 76 65 72 62  --..NULL..</verb
4e30: 61 74 69 6d 3e 0d 0a 59 6f 75 20 63 61 6e 20 75  atim>..You can u
4e40: 73 65 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 47 65  se <b>SqlProc_Ge
4e50: 74 4c 6f 67 66 69 6c 65 28 29 3c 2f 62 3e 20 69  tLogfile()</b> i
4e60: 6e 20 6f 72 64 65 72 20 74 6f 20 63 68 65 63 6b  n order to check
4e70: 20 69 66 20 74 68 65 20 63 75 72 72 65 6e 74 20   if the current 
4e80: 44 42 2d 63 6f 6e 6e 65 63 74 69 6f 6e 20 69 73  DB-connection is
4e90: 20 73 75 70 70 6f 72 74 65 64 20 62 79 20 73 6f   supported by so
4ea0: 6d 65 20 4c 6f 67 66 69 6c 65 20 6f 72 20 6e 6f  me Logfile or no
4eb0: 74 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 74 61 62  t.<br><br>..<tab
4ec0: 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 66 38 66  le bgcolor="#f8f
4ed0: 38 64 38 22 20 63 65 6c 6c 70 61 64 64 69 6e 67  8d8" cellpadding
4ee0: 3d 22 36 22 20 63 65 6c 6c 73 70 61 63 69 6e 67  ="6" cellspacing
4ef0: 3d 22 38 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 3c  ="8"><tr><td>..<
4f00: 75 3e 4e 6f 74 65 3c 2f 75 3e 3a 20 74 68 65 20  u>Note</u>: the 
4f10: 4c 6f 67 66 69 6c 65 20 73 65 74 74 69 6e 67 20  Logfile setting 
4f20: 69 73 20 70 65 72 6d 61 6e 65 6e 74 20 6f 6e 20  is permanent on 
4f30: 61 20 70 65 72 2d 63 6f 6e 6e 65 63 74 69 6f 6e  a per-connection
4f40: 20 62 61 73 69 73 2e 0d 0a 3c 75 6c 3e 0d 0a 3c   basis...<ul>..<
4f50: 6c 69 3e 61 6e 79 20 6e 65 77 20 44 42 2d 63 6f  li>any new DB-co
4f60: 6e 6e 65 63 74 69 6f 6e 20 77 69 6c 6c 20 61 6c  nnection will al
4f70: 77 61 79 73 20 73 74 61 72 74 20 62 79 20 6b 65  ways start by ke
4f80: 65 70 69 6e 67 20 74 68 65 20 4c 6f 67 66 69 6c  eping the Logfil
4f90: 65 20 64 69 73 61 62 6c 65 64 2e 3c 62 72 3e 0d  e disabled.<br>.
4fa0: 0a 59 6f 75 20 61 72 65 20 61 6c 77 61 79 73 20  .You are always 
4fb0: 72 65 71 75 69 72 65 64 20 74 6f 20 70 65 72 66  required to perf
4fc0: 6f 72 6d 20 61 6e 20 65 78 70 6c 69 63 69 74 20  orm an explicit 
4fd0: 63 61 6c 6c 20 74 6f 20 3c 62 3e 53 71 6c 50 72  call to <b>SqlPr
4fe0: 6f 63 5f 53 65 74 4c 6f 67 66 69 6c 65 28 29 3c  oc_SetLogfile()<
4ff0: 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20  /b> in order to 
5000: 65 66 66 65 63 74 69 76 65 6c 79 20 65 6e 61 62  effectively enab
5010: 6c 65 20 61 20 4c 6f 67 66 69 6c 65 2e 3c 2f 6c  le a Logfile.</l
5020: 69 3e 0d 0a 3c 6c 69 3e 6f 6e 63 65 20 61 20 4c  i>..<li>once a L
5030: 6f 67 66 69 6c 65 20 68 61 73 20 62 65 65 6e 20  ogfile has been 
5040: 65 6e 61 62 6c 65 64 20 69 74 20 77 69 6c 6c 20  enabled it will 
5050: 63 6f 6e 74 69 6e 75 65 20 74 6f 20 73 75 70 70  continue to supp
5060: 6f 72 74 20 74 68 65 20 63 75 72 72 65 6e 74 20  ort the current 
5070: 44 42 2d 63 6f 6e 6e 65 63 74 69 6f 6e 20 64 75  DB-connection du
5080: 72 69 6e 67 20 61 6c 6c 20 69 74 73 20 6c 69 66  ring all its lif
5090: 65 73 70 61 6e 2c 20 69 66 20 6e 6f 74 20 65 78  espan, if not ex
50a0: 70 6c 69 63 69 74 6c 79 20 64 69 73 61 62 6c 65  plicitly disable
50b0: 64 20 69 6e 20 74 68 65 20 61 66 74 65 72 20 77  d in the after w
50c0: 68 69 6c 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e  hile.</li>..<li>
50d0: 4c 6f 67 66 69 6c 65 20 73 65 74 74 69 6e 67 73  Logfile settings
50e0: 20 61 72 65 20 73 74 72 69 63 74 6c 79 20 63 6f   are strictly co
50f0: 6e 66 69 6e 65 64 20 77 69 74 68 69 6e 67 20 74  nfined withing t
5100: 68 65 20 63 75 72 72 65 6e 74 20 44 42 2d 63 6f  he current DB-co
5110: 6e 6e 65 63 74 69 6f 6e 2c 20 61 6e 64 20 77 69  nnection, and wi
5120: 6c 6c 20 6e 65 76 65 72 20 70 72 6f 70 61 67 61  ll never propaga
5130: 74 65 20 62 65 74 77 65 65 6e 20 66 6f 6c 6c 6f  te between follo
5140: 77 69 6e 67 20 73 65 73 73 69 6f 6e 73 2e 3c 2f  wing sessions.</
5150: 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 2f 74 64  li>..</ul>..</td
5160: 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a  ></tr></table>..
5170: 3c 2f 6c 69 3e 0d 0a 3c 2f 6f 6c 3e 0d 0a 3c 62  </li>..</ol>..<b
5180: 72 3e 3c 68 72 3e 0d 0a 3c 68 32 3e 54 75 74 6f  r><hr>..<h2>Tuto
5190: 72 69 61 6c 20 23 31 3c 2f 68 32 3e 0d 0a 3c 74  rial #1</h2>..<t
51a0: 61 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 66  able bgcolor="#f
51b0: 38 66 38 64 38 22 20 63 65 6c 6c 70 61 64 64 69  8f8d8" cellpaddi
51c0: 6e 67 3d 22 36 22 20 63 65 6c 6c 73 70 61 63 69  ng="6" cellspaci
51d0: 6e 67 3d 22 38 22 3e 3c 74 72 3e 3c 74 64 3e 0d  ng="8"><tr><td>.
51e0: 0a 41 6c 6c 20 74 68 65 20 66 6f 6c 6c 6f 77 69  .All the followi
51f0: 6e 67 20 74 75 74 6f 72 69 61 6c 73 20 61 72 65  ng tutorials are
5200: 20 62 61 73 65 64 20 6f 6e 20 74 68 65 20 73 61   based on the sa
5210: 6d 65 20 73 61 6d 70 6c 65 20 64 61 74 61 62 61  me sample databa
5220: 73 65 3a 20 70 6c 65 61 73 65 20 3c 61 20 68 72  se: please <a hr
5230: 65 66 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 67  ef="http://www.g
5240: 61 69 61 2d 67 69 73 2e 69 74 2f 67 61 69 61 2d  aia-gis.it/gaia-
5250: 73 69 6e 73 2f 73 70 5f 73 61 6d 70 6c 65 5f 64  sins/sp_sample_d
5260: 62 2e 37 7a 22 3e 64 6f 77 6e 6c 6f 61 64 20 69  b.7z">download i
5270: 74 3c 2f 61 3e 20 62 65 66 6f 72 65 20 67 6f 69  t</a> before goi
5280: 6e 67 20 66 75 72 74 68 65 72 20 61 77 61 79 2e  ng further away.
5290: 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61  ..</td></tr></ta
52a0: 62 6c 65 3e 3c 62 72 3e 0d 0a 41 73 20 79 6f 75  ble><br>..As you
52b0: 20 63 61 6e 20 65 61 73 69 6c 79 20 63 68 65 63   can easily chec
52c0: 6b 20 74 68 69 73 20 64 61 74 61 62 61 73 65 20  k this database 
52d0: 63 6f 6e 74 61 69 6e 73 20 74 68 72 65 65 20 53  contains three S
52e0: 70 61 74 69 61 6c 20 54 61 62 6c 65 73 20 72 65  patial Tables re
52f0: 70 72 65 73 65 6e 74 69 6e 67 20 74 68 65 20 3c  presenting the <
5300: 62 3e 3c 69 3e 41 64 6d 69 6e 69 73 74 72 61 74  b><i>Administrat
5310: 69 76 65 20 42 6f 75 6e 64 61 72 69 65 73 3c 2f  ive Boundaries</
5320: 69 3e 3c 2f 62 3e 20 6f 66 20 61 6c 6c 20 49 74  i></b> of all It
5330: 61 6c 69 61 6e 20 4d 75 6e 69 63 69 70 61 6c 69  alian Municipali
5340: 74 69 65 73 20 61 73 20 6f 66 66 69 63 69 61 6c  ties as official
5350: 6c 79 20 64 65 74 65 72 6d 69 6e 65 64 20 62 79  ly determined by
5360: 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 73 3a   <a href="https:
5370: 2f 2f 65 6e 2e 77 69 6b 69 70 65 64 69 61 2e 6f  //en.wikipedia.o
5380: 72 67 2f 77 69 6b 69 2f 4e 61 74 69 6f 6e 61 6c  rg/wiki/National
5390: 5f 49 6e 73 74 69 74 75 74 65 5f 6f 66 5f 53 74  _Institute_of_St
53a0: 61 74 69 73 74 69 63 73 5f 28 49 74 61 6c 79 29  atistics_(Italy)
53b0: 22 3e 49 53 54 41 54 3c 2f 61 3e 3a 0d 0a 3c 75  ">ISTAT</a>:..<u
53c0: 6c 3e 0d 0a 3c 6c 69 3e 74 68 65 72 65 20 61 72  l>..<li>there ar
53d0: 65 20 74 68 72 65 65 20 64 69 66 66 65 72 65 6e  e three differen
53e0: 74 20 74 61 62 6c 65 73 2c 20 65 61 63 68 20 6f  t tables, each o
53f0: 6e 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67  ne corresponding
5400: 20 74 6f 20 61 20 73 70 65 63 69 66 69 63 20 4e   to a specific N
5410: 61 74 69 6f 6e 61 6c 20 43 65 6e 73 75 73 20 28  ational Census (
5420: 79 65 61 72 73 20 31 39 39 31 2c 20 32 30 30 31  years 1991, 2001
5430: 20 61 6e 64 20 32 30 31 31 20 61 72 65 20 61 76   and 2011 are av
5440: 61 69 6c 61 62 6c 65 29 2e 3c 2f 6c 69 3e 0d 0a  ailable).</li>..
5450: 3c 6c 69 3e 61 6c 6c 20 74 68 72 65 65 20 74 61  <li>all three ta
5460: 62 6c 65 73 20 68 61 76 65 20 65 78 61 63 74 6c  bles have exactl
5470: 79 20 74 68 65 20 73 61 6d 65 20 6c 61 79 6f 75  y the same layou
5480: 74 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 41 64 6d  t.</li>..<li>Adm
5490: 69 6e 69 73 74 72 61 74 69 76 65 20 42 6f 75 6e  inistrative Boun
54a0: 64 61 72 69 65 73 20 61 72 65 20 61 6c 77 61 79  daries are alway
54b0: 73 20 72 65 70 72 65 73 65 6e 74 65 64 20 61 73  s represented as
54c0: 20 4d 75 6c 74 69 50 6f 6c 79 67 6f 6e 73 20 28   MultiPolygons (
54d0: 53 72 69 64 3d 33 32 36 33 32 29 2e 0d 0a 3c 2f  Srid=32632)...</
54e0: 75 6c 3e 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65 20  ul><br>..<table 
54f0: 62 67 63 6f 6c 6f 72 3d 22 23 66 38 66 38 64 38  bgcolor="#f8f8d8
5500: 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 36  " cellpadding="6
5510: 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 38  " cellspacing="8
5520: 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 3c 68 34 3e  "><tr><td>..<h4>
5530: 54 68 65 20 50 72 6f 62 6c 65 6d 3c 2f 68 34 3e  The Problem</h4>
5540: 0d 0a 57 65 27 6c 6c 20 67 6f 20 74 6f 20 69 6d  ..We'll go to im
5550: 70 6c 65 6d 65 6e 74 20 61 20 3c 62 3e 50 72 6f  plement a <b>Pro
5560: 63 65 64 75 72 65 3c 2f 62 3e 20 69 6e 74 65 6e  cedure</b> inten
5570: 64 65 64 20 74 6f 20 65 78 70 6f 72 74 20 73 65  ded to export se
5580: 6c 65 63 74 65 64 20 53 68 61 70 65 66 69 6c 65  lected Shapefile
5590: 73 2e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 54 68  s...<ul>..<li>Th
55a0: 65 20 43 65 6e 73 75 73 20 59 65 61 72 20 6d 75  e Census Year mu
55b0: 73 74 20 62 65 20 66 72 65 65 6c 79 20 73 65 6c  st be freely sel
55c0: 65 63 74 61 62 6c 65 2e 3c 2f 6c 69 3e 0d 0a 3c  ectable.</li>..<
55d0: 6c 69 3e 41 20 72 65 71 75 69 72 65 64 20 66 65  li>A required fe
55e0: 61 74 75 72 65 20 69 73 20 61 6c 6c 6f 77 69 6e  ature is allowin
55f0: 67 20 66 6f 72 20 66 72 65 65 6c 79 20 66 69 6c  g for freely fil
5600: 74 65 72 69 6e 67 20 61 20 73 69 6e 67 6c 65 20  tering a single 
5610: 4d 75 6e 69 63 69 70 61 6c 69 74 79 20 6f 72 20  Municipality or 
5620: 61 6c 6c 20 4d 75 6e 69 63 69 70 61 6c 69 74 69  all Municipaliti
5630: 65 73 20 62 65 6c 6f 6e 67 69 6e 67 20 74 6f 20  es belonging to 
5640: 74 68 65 20 73 61 6d 65 20 50 72 6f 76 69 6e 63  the same Provinc
5650: 65 20 6f 72 20 52 65 67 69 6f 6e 2e 3c 2f 6c 69  e or Region.</li
5660: 3e 0d 0a 3c 6c 69 3e 52 65 70 72 6f 6a 65 63 74  >..<li>Reproject
5670: 69 6e 67 20 74 6f 20 73 6f 6d 65 20 61 6c 74 65  ing to some alte
5680: 72 6e 61 74 69 76 65 20 53 52 49 44 20 73 68 6f  rnative SRID sho
5690: 75 6c 64 20 62 65 20 61 20 73 75 70 70 6f 72 74  uld be a support
56a0: 65 64 20 66 65 61 74 75 72 65 2e 3c 2f 6c 69 3e  ed feature.</li>
56b0: 0d 0a 3c 6c 69 3e 57 68 69 6c 65 20 64 6f 69 6e  ..<li>While doin
56c0: 67 20 61 6c 6c 20 74 68 69 73 20 77 65 27 6c 6c  g all this we'll
56d0: 20 6f 62 76 69 6f 75 73 6c 79 20 74 72 79 20 74   obviously try t
56e0: 6f 20 74 61 6b 65 20 66 75 6c 6c 20 61 64 76 61  o take full adva
56f0: 6e 74 61 67 65 20 66 72 6f 6d 20 75 73 69 6e 67  ntage from using
5700: 20 3c 62 3e 56 61 72 69 61 62 6c 65 73 3c 2f 62   <b>Variables</b
5710: 3e 20 73 6f 20 74 6f 20 6d 61 6b 65 20 74 68 65  > so to make the
5720: 20 50 72 6f 63 65 64 75 72 65 20 61 73 20 67 65   Procedure as ge
5730: 6e 65 72 69 63 20 61 6e 64 20 66 6c 65 78 69 62  neric and flexib
5740: 6c 65 20 61 73 20 70 6f 73 73 69 62 6c 65 2e 3c  le as possible.<
5750: 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 2f 74  /li>..</ul>..</t
5760: 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 3c  d></tr></table><
5770: 62 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d  br>..<verbatim>.
5780: 0a 2d 2d 0d 0a 2d 2d 20 72 65 6d 6f 76 69 6e 67  .--..-- removing
5790: 20 74 68 65 20 77 6f 72 6b 20 74 61 62 6c 65 20   the work table 
57a0: 28 6a 75 73 74 20 69 6e 20 63 61 73 65 20 69 74  (just in case it
57b0: 20 61 6c 72 65 61 64 79 20 65 78 69 73 74 73 29   already exists)
57c0: 0d 0a 2d 2d 0d 0a 53 45 4c 45 43 54 20 44 72 6f  ..--..SELECT Dro
57d0: 70 47 65 6f 54 61 62 6c 65 28 27 74 72 61 6e 73  pGeoTable('trans
57e0: 69 65 6e 74 5f 74 61 62 6c 65 27 29 3b 0d 0a 0d  ient_table');...
57f0: 0a 2d 2d 0d 0a 2d 2d 20 69 6e 73 65 72 74 69 6e  .--..-- insertin
5800: 67 20 73 65 6c 65 63 74 65 64 20 64 61 74 61 20  g selected data 
5810: 69 6e 74 6f 20 74 68 65 20 77 6f 72 6b 20 74 61  into the work ta
5820: 62 6c 65 0d 0a 2d 2d 0d 0a 43 52 45 41 54 45 20  ble..--..CREATE 
5830: 54 41 42 4c 45 20 74 72 61 6e 73 69 65 6e 74 5f  TABLE transient_
5840: 74 61 62 6c 65 20 41 53 0d 0a 53 45 4c 45 43 54  table AS..SELECT
5850: 20 69 64 2c 20 69 73 74 61 74 2c 20 6e 61 6d 65   id, istat, name
5860: 2c 20 70 72 6f 76 69 6e 63 65 2c 20 72 65 67 69  , province, regi
5870: 6f 6e 2c 20 53 54 5f 54 72 61 6e 73 66 6f 72 6d  on, ST_Transform
5880: 28 67 65 6f 6d 2c 20 40 73 72 69 64 40 29 20 41  (geom, @srid@) A
5890: 53 20 67 65 6f 6d 0d 0a 46 52 4f 4d 20 6d 75 6e  S geom..FROM mun
58a0: 69 63 69 70 61 6c 69 74 69 65 73 5f 40 79 65 61  icipalities_@yea
58b0: 72 40 0d 0a 57 48 45 52 45 20 28 55 70 70 65 72  r@..WHERE (Upper
58c0: 28 6e 61 6d 65 29 20 3d 20 55 70 70 65 72 28 27  (name) = Upper('
58d0: 40 6d 75 6e 69 63 69 70 61 6c 69 74 79 40 27 29  @municipality@')
58e0: 20 4f 52 20 55 70 70 65 72 28 70 72 6f 76 69 6e   OR Upper(provin
58f0: 63 65 29 20 3d 20 55 70 70 65 72 28 27 40 70 72  ce) = Upper('@pr
5900: 6f 76 69 6e 63 65 40 27 29 20 4f 52 20 55 70 70  ovince@') OR Upp
5910: 65 72 28 72 65 67 69 6f 6e 29 20 3d 20 55 70 70  er(region) = Upp
5920: 65 72 28 27 40 72 65 67 69 6f 6e 40 27 29 29 3b  er('@region@'));
5930: 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20 70 72 6f 70 65  ....--..-- prope
5940: 72 6c 79 20 72 65 63 6f 76 65 72 69 6e 67 20 74  rly recovering t
5950: 68 65 20 77 6f 72 6b 20 74 61 62 6c 65 0d 0a 2d  he work table..-
5960: 2d 0d 0a 53 45 4c 45 43 54 20 52 65 63 6f 76 65  -..SELECT Recove
5970: 72 47 65 6f 6d 65 74 72 79 43 6f 6c 75 6d 6e 28  rGeometryColumn(
5980: 27 74 72 61 6e 73 69 65 6e 74 5f 74 61 62 6c 65  'transient_table
5990: 27 2c 20 27 67 65 6f 6d 27 2c 20 40 73 72 69 64  ', 'geom', @srid
59a0: 40 2c 20 27 4d 55 4c 54 49 50 4f 4c 59 47 4f 4e  @, 'MULTIPOLYGON
59b0: 27 2c 20 27 58 59 27 29 3b 0d 0a 0d 0a 2d 2d 0d  ', 'XY');....--.
59c0: 0a 2d 2d 20 65 78 70 6f 72 74 69 6e 67 20 66 72  .-- exporting fr
59d0: 6f 6d 20 74 68 65 20 77 6f 72 6b 20 74 61 62 6c  om the work tabl
59e0: 65 20 69 6e 74 6f 20 74 68 65 20 53 68 61 70 65  e into the Shape
59f0: 66 69 6c 65 0d 0a 2d 2d 0d 0a 53 45 4c 45 43 54  file..--..SELECT
5a00: 20 45 78 70 6f 72 74 53 68 70 28 27 74 72 61 6e   ExportShp('tran
5a10: 73 69 65 6e 74 5f 74 61 62 6c 65 27 2c 20 27 67  sient_table', 'g
5a20: 65 6f 6d 27 2c 20 27 40 73 68 70 5f 70 61 74 68  eom', '@shp_path
5a30: 40 27 2c 20 27 43 50 31 32 35 32 27 29 3b 0d 0a  @', 'CP1252');..
5a40: 0d 0a 2d 2d 0d 0a 2d 2d 20 72 65 6d 6f 76 69 6e  ..--..-- removin
5a50: 67 20 74 68 65 20 77 6f 72 6b 20 74 61 62 6c 65  g the work table
5a60: 0d 0a 2d 2d 0d 0a 53 45 4c 45 43 54 20 44 72 6f  ..--..SELECT Dro
5a70: 70 47 65 6f 54 61 62 6c 65 28 27 74 72 61 6e 73  pGeoTable('trans
5a80: 69 65 6e 74 5f 74 61 62 6c 65 27 29 3b 0d 0a 3c  ient_table');..<
5a90: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 41 73 20 79  /verbatim>..As y
5aa0: 6f 75 20 63 61 6e 20 73 65 65 20 74 68 65 20 70  ou can see the p
5ab0: 72 6f 70 6f 73 65 64 20 69 6d 70 6c 65 6d 65 6e  roposed implemen
5ac0: 74 61 74 69 6f 6e 20 69 73 20 62 61 73 69 63 61  tation is basica
5ad0: 6c 6c 79 20 73 69 6d 70 6c 65 2e 20 4e 6f 77 20  lly simple. Now 
5ae0: 79 6f 75 20 73 69 6d 70 6c 79 20 68 61 76 65 20  you simply have 
5af0: 74 6f 20 3c 62 3e 63 75 74 26 70 61 73 74 65 3c  to <b>cut&paste<
5b00: 2f 62 3e 20 74 68 65 20 61 62 6f 76 65 20 53 51  /b> the above SQ
5b10: 4c 20 62 6f 64 79 20 73 61 76 69 6e 67 20 69 74  L body saving it
5b20: 20 69 6e 74 6f 20 61 20 66 69 6c 65 20 6e 61 6d   into a file nam
5b30: 65 64 20 3c 62 3e 74 65 73 74 5f 73 70 2e 74 78  ed <b>test_sp.tx
5b40: 74 3c 2f 62 3e 20 66 6f 72 20 66 75 72 74 68 65  t</b> for furthe
5b50: 72 20 75 73 61 67 65 2e 3c 62 72 3e 3c 62 72 3e  r usage.<br><br>
5b60: 0d 0a 46 65 77 20 69 6e 74 65 72 65 73 74 69 6e  ..Few interestin
5b70: 67 20 64 65 74 61 69 6c 73 20 77 6f 72 74 68 20  g details worth 
5b80: 74 6f 20 62 65 20 65 78 70 6c 61 69 6e 65 64 3a  to be explained:
5b90: 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 56 61 72 69  ..<ul>..<li>Vari
5ba0: 61 62 6c 65 20 3c 62 3e 40 79 65 61 72 40 3c 2f  able <b>@year@</
5bb0: 62 3e 20 69 73 20 69 6e 74 65 6e 64 65 64 20 74  b> is intended t
5bc0: 6f 20 73 65 6c 65 63 74 20 77 68 69 63 68 20 73  o select which s
5bd0: 70 65 63 69 66 69 63 20 53 70 61 74 69 61 6c 20  pecific Spatial 
5be0: 54 61 62 6c 65 20 77 69 6c 6c 20 62 65 20 71 75  Table will be qu
5bf0: 65 72 69 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  eried.</li>..<li
5c00: 3e 56 61 72 69 61 62 6c 65 20 3c 62 3e 40 73 72  >Variable <b>@sr
5c10: 69 64 40 3c 2f 62 3e 20 69 73 20 69 6e 74 65 6e  id@</b> is inten
5c20: 64 65 64 20 74 6f 20 73 70 65 63 69 66 79 20 74  ded to specify t
5c30: 68 65 20 6f 75 74 70 75 74 20 53 52 49 44 2e 3c  he output SRID.<
5c40: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 56 61 72 69 61 62  /li>..<li>Variab
5c50: 6c 65 20 3c 62 3e 40 73 68 70 5f 70 61 74 68 40  le <b>@shp_path@
5c60: 3c 2f 62 3e 20 69 73 20 69 6e 74 65 6e 64 65 64  </b> is intended
5c70: 20 74 6f 20 73 70 65 63 69 66 79 20 74 68 65 20   to specify the 
5c80: 70 61 74 68 6e 61 6d 65 20 6f 66 20 74 68 65 20  pathname of the 
5c90: 6f 75 74 70 75 74 20 53 68 61 70 65 66 69 6c 65  output Shapefile
5ca0: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 56 61 72 69  .</li>..<li>Vari
5cb0: 61 62 6c 65 73 20 3c 62 3e 40 6d 75 6e 69 63 69  ables <b>@munici
5cc0: 70 61 6c 69 74 79 40 3c 2f 62 3e 2c 20 3c 62 3e  pality@</b>, <b>
5cd0: 40 70 72 6f 76 69 6e 63 65 40 3c 2f 62 3e 20 61  @province@</b> a
5ce0: 6e 64 20 3c 62 3e 40 72 65 67 69 6f 6e 40 3c 2f  nd <b>@region@</
5cf0: 62 3e 20 61 72 65 20 69 6e 74 65 6e 64 65 64 20  b> are intended 
5d00: 74 6f 20 73 70 65 63 69 66 79 20 74 68 65 20 69  to specify the i
5d10: 6e 74 65 6e 64 65 64 20 66 69 6c 74 65 72 69 6e  ntended filterin
5d20: 67 20 63 72 69 74 65 72 69 61 2e 3c 62 72 3e 0d  g criteria.<br>.
5d30: 0a 54 68 69 73 20 69 73 20 61 20 6c 69 74 74 6c  .This is a littl
5d40: 65 20 62 69 74 20 74 72 69 63 6b 79 2c 20 73 6f  e bit tricky, so
5d50: 20 77 65 27 6c 6c 20 67 6f 20 69 6e 20 66 75 72   we'll go in fur
5d60: 74 68 65 72 20 64 65 70 74 68 3a 0d 0a 3c 75 6c  ther depth:..<ul
5d70: 3e 0d 0a 3c 6c 69 3e 54 68 65 73 65 20 56 61 72  >..<li>These Var
5d80: 69 61 62 6c 65 73 20 61 72 65 20 65 78 70 65 63  iables are expec
5d90: 74 65 64 20 74 6f 20 62 65 20 61 63 74 75 61 6c  ted to be actual
5da0: 6c 79 20 72 65 70 6c 61 63 65 64 20 62 79 20 3c  ly replaced by <
5db0: 62 3e 74 65 78 74 20 73 74 72 69 6e 67 20 76 61  b>text string va
5dc0: 6c 75 65 73 3c 2f 62 3e 3b 20 73 6f 20 77 65 27  lues</b>; so we'
5dd0: 76 65 20 63 6f 6e 73 69 73 74 65 6e 74 6c 79 20  ve consistently 
5de0: 3c 62 3e 73 69 6e 67 6c 65 2d 71 75 6f 74 65 64  <b>single-quoted
5df0: 3c 2f 62 3e 20 74 68 65 20 76 61 72 69 61 62 6c  </b> the variabl
5e00: 65 20 73 79 6d 62 6f 6c 2c 20 73 6f 20 74 6f 20  e symbol, so to 
5e10: 61 6c 6c 6f 77 20 66 6f 72 20 61 6e 20 65 61 73  allow for an eas
5e20: 69 65 72 20 76 61 6c 75 65 20 72 65 70 6c 61 63  ier value replac
5e30: 65 6d 65 6e 74 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  ement.</li>..<li
5e40: 3e 57 65 20 61 72 65 20 73 79 73 74 65 6d 61 74  >We are systemat
5e50: 69 63 61 6c 6c 79 20 75 73 69 6e 67 20 74 68 65  ically using the
5e60: 20 3c 62 3e 55 70 70 65 72 28 29 3c 2f 62 3e 20   <b>Upper()</b> 
5e70: 66 75 6e 63 74 69 6f 6e 20 73 69 6d 70 6c 79 20  function simply 
5e80: 62 65 63 61 75 73 65 20 50 72 6f 76 69 6e 63 65  because Province
5e90: 20 61 6e 64 20 52 65 67 69 6f 6e 20 6e 61 6d 65   and Region name
5ea0: 20 61 72 65 20 61 6c 6c 2d 75 70 70 65 72 63 61   are all-upperca
5eb0: 73 65 20 69 6e 20 79 65 61 72 73 20 31 39 39 31  se in years 1991
5ec0: 20 61 6e 64 20 32 30 30 31 20 62 75 74 20 6e 6f   and 2001 but no
5ed0: 74 20 6f 6e 20 79 65 61 72 20 32 30 31 31 2e 3c  t on year 2011.<
5ee0: 62 72 3e 0d 0a 53 79 73 74 65 6d 61 74 69 63 61  br>..Systematica
5ef0: 6c 6c 79 20 75 73 69 6e 67 20 55 70 70 65 72 28  lly using Upper(
5f00: 29 20 77 69 6c 6c 20 68 6f 6d 6f 67 65 6e 69 7a  ) will homogeniz
5f10: 65 20 61 6c 6c 20 6e 61 6d 65 73 20 69 6e 20 61  e all names in a
5f20: 20 63 6f 6e 73 69 73 74 65 6e 74 20 77 61 79 2e   consistent way.
5f30: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 57 65 20 61 72  </li>..<li>We ar
5f40: 65 20 75 73 69 6e 67 20 74 68 72 65 65 20 73 65  e using three se
5f50: 70 61 72 61 74 65 20 63 6f 6d 70 61 72 69 73 6f  parate compariso
5f60: 6e 73 20 28 6f 6e 65 20 66 6f 72 20 4d 75 6e 69  ns (one for Muni
5f70: 63 69 70 61 6c 69 74 79 2c 20 6f 6e 65 20 66 6f  cipality, one fo
5f80: 72 20 50 72 6f 76 69 6e 63 65 20 61 6e 64 20 6f  r Province and o
5f90: 6e 65 20 66 6f 72 20 52 65 67 69 6f 6e 29 20 63  ne for Region) c
5fa0: 6f 6e 6e 65 63 74 65 64 20 62 79 20 3c 62 3e 4f  onnected by <b>O
5fb0: 52 3c 2f 62 3e 20 6c 6f 67 69 63 61 6c 20 6f 70  R</b> logical op
5fc0: 65 72 61 74 6f 72 73 20 73 6f 20 74 6f 20 6d 61  erators so to ma
5fd0: 6b 65 20 70 6f 73 73 69 62 6c 65 20 73 70 65 63  ke possible spec
5fe0: 69 66 79 69 6e 67 20 6a 75 73 74 20 61 20 73 69  ifying just a si
5ff0: 6e 67 6c 65 20 66 69 6c 74 65 72 20 63 6c 61 75  ngle filter clau
6000: 73 65 2e 3c 62 72 3e 0d 0a 3c 75 3e 52 65 63 61  se.<br>..<u>Reca
6010: 6c 6c 3c 2f 75 3e 3a 20 75 6e 61 73 73 69 67 6e  ll</u>: unassign
6020: 65 64 20 56 61 72 69 61 62 6c 65 73 20 77 69 6c  ed Variables wil
6030: 6c 20 64 65 66 61 75 6c 74 20 74 6f 20 4e 55 4c  l default to NUL
6040: 4c 3b 20 73 6f 20 62 79 20 6a 75 73 74 20 64 65  L; so by just de
6050: 63 6c 61 72 69 6e 67 20 0d 0a 3c 62 3e 40 70 72  claring ..<b>@pr
6060: 6f 76 69 6e 63 65 40 3d 41 72 65 7a 7a 6f 3c 2f  ovince@=Arezzo</
6070: 62 3e 20 77 65 27 6c 6c 20 74 68 65 6e 20 67 65  b> we'll then ge
6080: 74 20 61 20 3c 62 3e 3c 69 3e 63 6f 6f 6b 65 64  t a <b><i>cooked
6090: 3c 2f 69 3e 3c 2f 62 3e 20 57 48 45 52 45 20 63  </i></b> WHERE c
60a0: 6c 61 75 73 65 20 6c 69 6b 65 20 74 68 69 73 3a  lause like this:
60b0: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 57 48  ..<verbatim>..WH
60c0: 45 52 45 20 28 55 70 70 65 72 28 6e 61 6d 65 29  ERE (Upper(name)
60d0: 20 3d 20 55 70 70 65 72 28 27 4e 55 4c 4c 27 29   = Upper('NULL')
60e0: 20 4f 52 20 55 70 70 65 72 28 70 72 6f 76 69 6e   OR Upper(provin
60f0: 63 65 29 20 3d 20 55 70 70 65 72 28 27 41 72 65  ce) = Upper('Are
6100: 7a 7a 6f 27 29 20 4f 52 20 55 70 70 65 72 28 72  zzo') OR Upper(r
6110: 65 67 69 6f 6e 29 20 3d 20 55 70 70 65 72 28 27  egion) = Upper('
6120: 4e 55 4c 4c 27 29 29 0d 0a 3c 2f 76 65 72 62 61  NULL'))..</verba
6130: 74 69 6d 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 2f 75  tim>..</li>..</u
6140: 6c 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e  l>..</li>..</ul>
6150: 0d 0a 3c 62 72 3e 0d 0a 3c 76 65 72 62 61 74 69  ..<br>..<verbati
6160: 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72  m>..SELECT SqlPr
6170: 6f 63 5f 45 78 65 63 75 74 65 28 20 53 71 6c 50  oc_Execute( SqlP
6180: 72 6f 63 5f 46 72 6f 6d 46 69 6c 65 20 28 27 43  roc_FromFile ('C
6190: 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72  :/users/joe/stor
61a0: 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f 74 65 73  ed_proc_test/tes
61b0: 74 5f 73 70 2e 74 78 74 27 29 2c 0d 0a 20 20 27  t_sp.txt'),..  '
61c0: 40 73 72 69 64 40 3d 33 30 30 34 27 2c 20 27 40  @srid@=3004', '@
61d0: 79 65 61 72 40 3d 32 30 30 31 27 2c 20 27 40 72  year@=2001', '@r
61e0: 65 67 69 6f 6e 40 3d 4c 61 7a 69 6f 27 2c 20 27  egion@=Lazio', '
61f0: 40 73 68 70 5f 70 61 74 68 40 3d 43 3a 2f 75 73  @shp_path@=C:/us
6200: 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70  ers/joe/stored_p
6210: 72 6f 63 5f 74 65 73 74 2f 6c 61 7a 69 6f 5f 32  roc_test/lazio_2
6220: 30 30 31 5f 33 30 30 34 27 29 3b 0d 0a 2d 2d 2d  001_3004');..---
6230: 2d 2d 0d 0a 31 0d 0a 0d 0a 53 45 4c 45 43 54 20  --..1....SELECT 
6240: 53 71 6c 50 72 6f 63 5f 45 78 65 63 75 74 65 28  SqlProc_Execute(
6250: 20 53 71 6c 50 72 6f 63 5f 46 72 6f 6d 46 69 6c   SqlProc_FromFil
6260: 65 20 28 27 43 3a 2f 75 73 65 72 73 2f 6a 6f 65  e ('C:/users/joe
6270: 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73  /stored_proc_tes
6280: 74 2f 74 65 73 74 5f 73 70 2e 74 78 74 27 29 2c  t/test_sp.txt'),
6290: 0d 0a 20 20 27 40 73 72 69 64 40 3d 34 33 32 36  ..  '@srid@=4326
62a0: 27 2c 20 27 40 79 65 61 72 40 3d 31 39 39 31 27  ', '@year@=1991'
62b0: 2c 20 27 40 72 65 67 69 6f 6e 40 3d 70 75 67 6c  , '@region@=pugl
62c0: 69 61 27 2c 20 27 40 73 68 70 5f 70 61 74 68 40  ia', '@shp_path@
62d0: 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74  =C:/users/joe/st
62e0: 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f 70  ored_proc_test/p
62f0: 75 67 6c 69 61 5f 31 39 39 31 5f 34 33 32 36 27  uglia_1991_4326'
6300: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a  );..-----..1....
6310: 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 45  SELECT SqlProc_E
6320: 78 65 63 75 74 65 28 20 53 71 6c 50 72 6f 63 5f  xecute( SqlProc_
6330: 46 72 6f 6d 46 69 6c 65 20 28 27 43 3a 2f 75 73  FromFile ('C:/us
6340: 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70  ers/joe/stored_p
6350: 72 6f 63 5f 74 65 73 74 2f 74 65 73 74 5f 73 70  roc_test/test_sp
6360: 2e 74 78 74 27 29 2c 0d 0a 20 20 27 40 73 72 69  .txt'),..  '@sri
6370: 64 40 3d 33 30 30 33 27 2c 20 27 40 79 65 61 72  d@=3003', '@year
6380: 40 3d 32 30 31 31 27 2c 20 27 40 70 72 6f 76 69  @=2011', '@provi
6390: 6e 63 65 40 3d 41 52 45 5a 5a 4f 27 2c 20 27 40  nce@=AREZZO', '@
63a0: 73 68 70 5f 70 61 74 68 40 3d 43 3a 2f 75 73 65  shp_path@=C:/use
63b0: 72 73 2f 6a 6f 65 2f 75 63 73 35 67 62 2f 73 74  rs/joe/ucs5gb/st
63c0: 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f 61  ored_proc_test/a
63d0: 72 65 7a 7a 6f 5f 32 30 31 31 5f 33 30 30 33 27  rezzo_2011_3003'
63e0: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a  );..-----..1....
63f0: 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 45  SELECT SqlProc_E
6400: 78 65 63 75 74 65 28 20 53 71 6c 50 72 6f 63 5f  xecute( SqlProc_
6410: 46 72 6f 6d 46 69 6c 65 20 28 27 43 3a 2f 75 73  FromFile ('C:/us
6420: 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70  ers/joe/stored_p
6430: 72 6f 63 5f 74 65 73 74 2f 74 65 73 74 5f 73 70  roc_test/test_sp
6440: 2e 74 78 74 27 29 2c 0d 0a 20 20 27 40 73 72 69  .txt'),..  '@sri
6450: 64 40 3d 33 30 30 33 27 2c 20 27 40 79 65 61 72  d@=3003', '@year
6460: 40 3d 32 30 30 31 27 2c 20 27 40 6d 75 6e 69 63  @=2001', '@munic
6470: 69 70 61 6c 69 74 79 40 3d 41 52 45 5a 5a 4f 27  ipality@=AREZZO'
6480: 2c 20 27 40 73 68 70 5f 70 61 74 68 40 3d 43 3a  , '@shp_path@=C:
6490: 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65  /users/joe/store
64a0: 64 5f 70 72 6f 63 5f 74 65 73 74 2f 63 6f 6d 5f  d_proc_test/com_
64b0: 61 72 65 7a 7a 6f 5f 32 30 30 31 5f 33 30 30 33  arezzo_2001_3003
64c0: 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c  ');..-----..1..<
64d0: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 49 6e 20 74  /verbatim>..In t
64e0: 68 69 73 20 66 69 72 73 74 20 74 75 74 6f 72 69  his first tutori
64f0: 61 6c 20 77 65 27 6c 6c 20 61 6c 77 61 79 73 20  al we'll always 
6500: 3c 62 3e 65 78 65 63 75 74 65 3c 2f 62 3e 20 61  <b>execute</b> a
6510: 20 50 72 6f 63 65 64 75 72 65 20 6c 6f 61 64 65   Procedure loade
6520: 64 20 66 72 6f 6d 20 61 6e 20 65 78 74 65 72 6e  d from an extern
6530: 61 6c 20 66 69 6c 65 2e 3c 62 72 3e 0d 0a 41 73  al file.<br>..As
6540: 20 79 6f 75 20 63 61 6e 20 73 65 65 20 65 78 65   you can see exe
6550: 63 75 74 69 6e 67 20 61 20 50 72 6f 63 65 64 75  cuting a Procedu
6560: 72 65 20 69 73 20 61 20 73 74 72 61 69 67 68 74  re is a straight
6570: 66 6f 72 77 61 72 64 20 74 61 73 6b 3b 20 79 6f  forward task; yo
6580: 75 20 73 69 6d 70 6c 79 20 68 61 76 65 20 74 6f  u simply have to
6590: 20 73 70 65 63 69 66 79 20 61 6e 20 61 70 70 72   specify an appr
65a0: 6f 70 72 69 61 74 65 20 6c 69 73 74 20 6f 66 20  opriate list of 
65b0: 3c 62 3e 56 61 72 69 61 62 6c 65 20 56 61 6c 75  <b>Variable Valu
65c0: 65 73 3c 2f 62 3e 20 61 6e 64 20 74 68 61 74 27  es</b> and that'
65d0: 73 20 61 6c 6c 2e 0d 0a 3c 68 72 3e 0d 0a 3c 68  s all...<hr>..<h
65e0: 32 3e 54 75 74 6f 72 69 61 6c 20 23 32 3c 2f 68  2>Tutorial #2</h
65f0: 32 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  2>..<verbatim>..
6600: 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f  SELECT StoredPro
6610: 63 5f 52 65 67 69 73 74 65 72 28 20 27 6d 79 5f  c_Register( 'my_
6620: 70 72 6f 63 27 2c 20 27 61 20 53 74 6f 72 65 64  proc', 'a Stored
6630: 20 50 72 6f 63 65 64 75 72 65 20 66 6f 72 20 65   Procedure for e
6640: 78 70 6f 72 74 69 6e 67 20 73 65 6c 65 63 74 65  xporting selecte
6650: 64 20 53 68 61 70 65 66 69 6c 65 73 27 2c 20 53  d Shapefiles', S
6660: 71 6c 50 72 6f 63 5f 46 72 6f 6d 46 69 6c 65 20  qlProc_FromFile 
6670: 28 27 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73  ('C:/users/joe/s
6680: 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f  tored_proc_test/
6690: 74 65 73 74 5f 73 70 2e 74 78 74 27 29 20 29 3b  test_sp.txt') );
66a0: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54  ..</verbatim>..T
66b0: 68 69 73 20 73 65 63 6f 6e 64 20 74 75 74 6f 72  his second tutor
66c0: 69 61 6c 20 69 73 20 73 75 62 73 74 61 6e 74 69  ial is substanti
66d0: 61 6c 6c 79 20 74 68 65 20 73 61 6d 65 20 6f 66  ally the same of
66e0: 20 74 68 65 20 66 69 72 73 74 20 6f 6e 65 2e 3c   the first one.<
66f0: 62 72 3e 0d 0a 54 68 65 20 75 6e 69 71 75 65 20  br>..The unique 
6700: 64 69 66 66 65 72 65 6e 63 65 20 69 73 20 74 68  difference is th
6710: 61 74 20 6e 6f 77 20 77 65 27 6c 6c 20 67 6f 20  at now we'll go 
6720: 74 6f 20 70 65 72 6d 61 6e 65 6e 74 6c 79 20 72  to permanently r
6730: 65 67 69 73 74 65 72 65 64 20 61 20 3c 62 3e 53  egistered a <b>S
6740: 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65 3c  tored Procedure<
6750: 2f 62 3e 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e  /b>...<verbatim>
6760: 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50  ..SELECT StoredP
6770: 72 6f 63 5f 45 78 65 63 75 74 65 28 20 27 6d 79  roc_Execute( 'my
6780: 5f 70 72 6f 63 27 2c 20 27 40 73 72 69 64 40 3d  _proc', '@srid@=
6790: 33 30 30 34 27 2c 20 27 40 79 65 61 72 40 3d 32  3004', '@year@=2
67a0: 30 30 31 27 2c 20 27 40 72 65 67 69 6f 6e 40 3d  001', '@region@=
67b0: 4c 61 7a 69 6f 27 2c 20 27 40 73 68 70 5f 70 61  Lazio', '@shp_pa
67c0: 74 68 40 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65  th@=C:/users/joe
67d0: 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73  /stored_proc_tes
67e0: 74 2f 6c 61 7a 69 6f 5f 32 30 30 31 5f 33 30 30  t/lazio_2001_300
67f0: 34 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a  4');..-----..1..
6800: 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50  ..SELECT StoredP
6810: 72 6f 63 5f 45 78 65 63 75 74 65 28 20 27 6d 79  roc_Execute( 'my
6820: 5f 70 72 6f 63 27 2c 20 27 40 73 72 69 64 40 3d  _proc', '@srid@=
6830: 34 33 32 36 27 2c 20 27 40 79 65 61 72 40 3d 31  4326', '@year@=1
6840: 39 39 31 27 2c 20 27 40 72 65 67 69 6f 6e 40 3d  991', '@region@=
6850: 70 75 67 6c 69 61 27 2c 20 27 40 73 68 70 5f 70  puglia', '@shp_p
6860: 61 74 68 40 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f  ath@=C:/users/jo
6870: 65 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65  e/stored_proc_te
6880: 73 74 2f 70 75 67 6c 69 61 5f 31 39 39 31 5f 34  st/puglia_1991_4
6890: 33 32 36 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31  326');..-----..1
68a0: 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65  ....SELECT Store
68b0: 64 50 72 6f 63 5f 45 78 65 63 75 74 65 28 20 27  dProc_Execute( '
68c0: 6d 79 5f 70 72 6f 63 27 2c 20 27 40 73 72 69 64  my_proc', '@srid
68d0: 40 3d 33 30 30 33 27 2c 20 27 40 79 65 61 72 40  @=3003', '@year@
68e0: 3d 32 30 31 31 27 2c 20 27 40 70 72 6f 76 69 6e  =2011', '@provin
68f0: 63 65 40 3d 41 52 45 5a 5a 4f 27 2c 20 27 40 73  ce@=AREZZO', '@s
6900: 68 70 5f 70 61 74 68 40 3d 43 3a 2f 75 73 65 72  hp_path@=C:/user
6910: 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70 72 6f  s/joe/stored_pro
6920: 63 5f 74 65 73 74 2f 61 72 65 7a 7a 6f 5f 32 30  c_test/arezzo_20
6930: 31 31 5f 33 30 30 33 27 29 3b 0d 0a 2d 2d 2d 2d  11_3003');..----
6940: 2d 0d 0a 31 0d 0a 0d 0a 53 45 4c 45 43 54 20 53  -..1....SELECT S
6950: 74 6f 72 65 64 50 72 6f 63 5f 45 78 65 63 75 74  toredProc_Execut
6960: 65 28 20 27 6d 79 5f 70 72 6f 63 27 2c 20 27 40  e( 'my_proc', '@
6970: 73 72 69 64 40 3d 33 30 30 33 27 2c 20 27 40 79  srid@=3003', '@y
6980: 65 61 72 40 3d 32 30 30 31 27 2c 20 27 40 6d 75  ear@=2001', '@mu
6990: 6e 69 63 69 70 61 6c 69 74 79 40 3d 41 52 45 5a  nicipality@=AREZ
69a0: 5a 4f 27 2c 20 27 40 73 68 70 5f 70 61 74 68 40  ZO', '@shp_path@
69b0: 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74  =C:/users/joe/st
69c0: 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f 63  ored_proc_test/c
69d0: 6f 6d 5f 61 72 65 7a 7a 6f 5f 32 30 30 31 5f 33  om_arezzo_2001_3
69e0: 30 30 33 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31  003');..-----..1
69f0: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 45  ..</verbatim>..E
6a00: 78 65 63 75 74 69 6e 67 20 61 20 53 74 6f 72 65  xecuting a Store
6a10: 64 20 50 72 6f 63 65 64 75 72 65 20 69 73 6e 27  d Procedure isn'
6a20: 74 20 76 65 72 79 20 64 69 66 66 65 72 65 6e 74  t very different
6a30: 20 66 72 6f 6d 20 65 78 65 63 75 74 69 6e 67 20   from executing 
6a40: 61 20 50 72 6f 63 65 64 75 72 65 20 73 74 6f 72  a Procedure stor
6a50: 65 64 20 69 6e 74 6f 20 61 6e 20 65 78 74 65 72  ed into an exter
6a60: 6e 61 6c 20 66 69 6c 65 2e 3c 62 72 3e 0d 0a 3c  nal file.<br>..<
6a70: 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23  table bgcolor="#
6a80: 66 38 66 38 64 38 22 20 63 65 6c 6c 70 61 64 64  f8f8d8" cellpadd
6a90: 69 6e 67 3d 22 36 22 20 63 65 6c 6c 73 70 61 63  ing="6" cellspac
6aa0: 69 6e 67 3d 22 38 22 3e 3c 74 72 3e 3c 74 64 3e  ing="8"><tr><td>
6ab0: 0d 0a 45 78 65 63 75 74 69 6e 67 20 79 6f 75 72  ..Executing your
6ac0: 20 50 72 6f 63 65 64 75 72 65 73 20 66 72 6f 6d   Procedures from
6ad0: 20 65 78 74 65 72 6e 61 6c 20 66 69 6c 65 73 20   external files 
6ae0: 6f 72 20 70 65 72 6d 61 6e 65 6e 74 6c 79 20 72  or permanently r
6af0: 65 67 69 73 74 65 72 69 6e 67 20 53 74 6f 72 65  egistering Store
6b00: 64 20 50 72 6f 63 65 64 75 72 65 73 20 64 69 72  d Procedures dir
6b10: 65 63 74 6c 79 20 77 69 74 68 69 6e 20 61 20 64  ectly within a d
6b20: 61 74 61 62 61 73 65 20 69 73 20 61 20 6d 61 74  atabase is a mat
6b30: 74 65 72 20 6f 66 20 66 72 65 65 20 63 68 6f 69  ter of free choi
6b40: 63 65 2e 3c 62 72 3e 0d 0a 49 66 20 79 6f 75 20  ce.<br>..If you 
6b50: 61 72 65 20 70 6c 61 6e 6e 69 6e 67 20 74 6f 20  are planning to 
6b60: 64 65 70 6c 6f 79 20 61 20 50 72 6f 63 65 64 75  deploy a Procedu
6b70: 72 65 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 73  re intended to s
6b80: 75 70 70 6f 72 74 20 6d 61 6e 79 20 64 69 66 66  upport many diff
6b90: 65 72 65 6e 74 20 64 61 74 61 62 61 73 65 73 2c  erent databases,
6ba0: 20 74 68 65 6e 20 75 73 69 6e 67 20 61 6e 20 65   then using an e
6bb0: 78 74 65 72 6e 61 6c 20 66 69 6c 65 20 63 6f 75  xternal file cou
6bc0: 6c 64 20 70 72 6f 62 61 62 6c 79 20 73 69 6d 70  ld probably simp
6bd0: 6c 69 66 79 20 79 6f 75 72 20 77 6f 72 6b 2e 3c  lify your work.<
6be0: 62 72 3e 0d 0a 42 75 74 20 69 66 20 79 6f 75 20  br>..But if you 
6bf0: 61 72 65 20 70 6c 61 6e 6e 69 6e 67 20 74 6f 20  are planning to 
6c00: 64 65 70 6c 6f 79 20 61 20 50 72 6f 63 65 64 75  deploy a Procedu
6c10: 72 65 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 61  re intended to a
6c20: 75 74 6f 6d 61 74 65 20 6d 61 6e 79 20 72 6f 75  utomate many rou
6c30: 74 69 6e 65 6c 79 20 74 61 73 6b 20 74 6f 20 62  tinely task to b
6c40: 65 20 65 78 65 63 75 74 65 64 20 6d 6f 72 65 20  e executed more 
6c50: 61 6e 64 20 6d 6f 72 65 20 74 69 6d 65 73 20 6f  and more times o
6c60: 6e 20 74 68 65 20 73 61 6d 65 20 64 61 74 61 62  n the same datab
6c70: 61 73 65 2c 20 74 68 65 6e 20 70 65 72 6d 61 6e  ase, then perman
6c80: 65 6e 74 6c 79 20 72 65 67 69 73 74 65 72 69 6e  ently registerin
6c90: 67 20 61 20 53 74 6f 72 65 64 20 50 72 6f 63 65  g a Stored Proce
6ca0: 64 75 72 65 20 77 6f 75 6c 64 20 70 72 6f 62 61  dure would proba
6cb0: 62 6c 79 20 62 65 20 62 65 74 74 65 72 2e 0d 0a  bly be better...
6cc0: 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c  </td></tr></tabl
6cd0: 65 3e 0d 0a 3c 62 72 3e 3c 68 72 3e 0d 0a 3c 68  e>..<br><hr>..<h
6ce0: 32 3e 54 75 74 6f 72 69 61 6c 20 23 33 3c 2f 68  2>Tutorial #3</h
6cf0: 32 3e 0d 0a 54 68 69 73 20 6c 61 74 65 73 74 20  2>..This latest 
6d00: 74 75 74 6f 72 69 61 6c 20 69 73 20 6a 75 73 74  tutorial is just
6d10: 20 61 20 73 6d 61 6c 6c 20 76 61 72 69 61 74 69   a small variati
6d20: 6f 6e 20 6f 6e 20 74 68 65 20 74 68 65 6d 65 20  on on the theme 
6d30: 69 6e 74 65 6e 64 65 64 20 74 6f 20 68 69 67 68  intended to high
6d40: 6c 69 67 68 74 20 73 6f 6d 65 20 70 6f 74 65 6e  light some poten
6d50: 74 69 61 6c 6c 79 20 64 61 6e 67 65 72 6f 75 73  tially dangerous
6d60: 20 70 69 74 66 61 6c 6c 73 20 72 65 6c 61 74 65   pitfalls relate
6d70: 64 20 74 6f 20 3c 62 3e 73 69 6e 67 6c 65 2d 71  d to <b>single-q
6d80: 75 6f 74 69 6e 67 3c 2f 62 3e 2e 20 0d 0a 3c 76  uoting</b>. ..<v
6d90: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54  erbatim>..SELECT
6da0: 20 53 74 6f 72 65 64 50 72 6f 63 5f 45 78 65 63   StoredProc_Exec
6db0: 75 74 65 28 20 27 6d 79 5f 70 72 6f 63 27 29 2c  ute( 'my_proc'),
6dc0: 20 27 40 73 72 69 64 40 3d 33 30 30 33 27 2c 20   '@srid@=3003', 
6dd0: 27 40 79 65 61 72 40 3d 32 30 31 31 27 2c 20 27  '@year@=2011', '
6de0: 40 6d 75 6e 69 63 69 70 61 6c 69 74 79 40 3d 72  @municipality@=r
6df0: 69 6f 20 6e 65 6c 6c 27 27 65 6c 62 61 27 2c 20  io nell''elba', 
6e00: 27 40 73 68 70 5f 70 61 74 68 40 3d 43 3a 2f 75  '@shp_path@=C:/u
6e10: 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f  sers/joe/stored_
6e20: 70 72 6f 63 5f 74 65 73 74 2f 72 69 6f 5f 65 6c  proc_test/rio_el
6e30: 62 61 5f 32 30 31 31 5f 33 30 30 33 27 29 3b 0d  ba_2011_3003');.
6e40: 0a 2d 2d 2d 2d 2d 0d 0a 53 74 6f 72 65 64 50 72  .-----..StoredPr
6e50: 6f 63 20 65 78 63 65 70 74 69 6f 6e 20 2d 20 61  oc exception - a
6e60: 20 66 61 74 61 6c 20 53 51 4c 20 65 72 72 6f 72   fatal SQL error
6e70: 20 77 61 73 20 65 6e 63 6f 75 6e 74 65 72 65 64   was encountered
6e80: 2e 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50  .....SELECT SqlP
6e90: 72 6f 63 5f 47 65 74 4c 61 73 74 45 72 72 6f 72  roc_GetLastError
6ea0: 28 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 67 61 69 61  ();..-----..gaia
6eb0: 5f 73 71 6c 5f 70 72 6f 63 5f 65 78 65 63 75 74  _sql_proc_execut
6ec0: 65 3a 20 6e 65 61 72 20 22 65 6c 62 61 22 3a 20  e: near "elba": 
6ed0: 73 79 6e 74 61 78 20 65 72 72 6f 72 0d 0a 3c 2f  syntax error..</
6ee0: 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 69 73 20  verbatim>..This 
6ef0: 66 69 72 73 74 20 6e 61 69 76 65 20 61 74 74 65  first naive atte
6f00: 6d 70 74 20 77 69 6c 6c 20 66 61 69 6c 2c 20 61  mpt will fail, a
6f10: 6e 64 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 47 65  nd <b>SqlProc_Ge
6f20: 74 4c 61 73 74 45 72 72 6f 72 3c 2f 62 3e 20 77  tLastError</b> w
6f30: 69 6c 6c 20 65 78 70 6c 61 69 6e 20 77 68 79 20  ill explain why 
6f40: 69 74 20 66 61 69 6c 65 64 2e 20 57 65 27 76 65  it failed. We've
6f50: 20 70 61 73 73 65 64 20 61 20 3c 62 3e 27 40 6d   passed a <b>'@m
6f60: 75 6e 69 63 69 70 61 6c 69 74 79 40 3d 72 69 6f  unicipality@=rio
6f70: 20 6e 65 6c 6c 27 27 65 6c 62 61 27 3c 2f 62 3e   nell''elba'</b>
6f80: 20 56 61 72 69 61 62 6c 65 20 77 69 74 68 20 56   Variable with V
6f90: 61 6c 75 65 2c 20 74 68 61 74 20 77 69 6c 6c 20  alue, that will 
6fa0: 6c 65 61 64 20 74 6f 20 61 20 3c 62 3e 63 6f 6f  lead to a <b>coo
6fb0: 6b 65 64 3c 2f 62 3e 20 57 48 45 52 45 20 63 6c  ked</b> WHERE cl
6fc0: 61 75 73 65 20 6c 69 6b 65 20 74 68 69 73 3a 0d  ause like this:.
6fd0: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 57 48 45  .<verbatim>..WHE
6fe0: 52 45 20 28 55 70 70 65 72 28 6e 61 6d 65 29 20  RE (Upper(name) 
6ff0: 3d 20 55 70 70 65 72 28 27 72 69 6f 20 6e 65 6c  = Upper('rio nel
7000: 6c 27 65 6c 62 61 27 29 20 4f 52 20 55 70 70 65  l'elba') OR Uppe
7010: 72 28 70 72 6f 76 69 6e 63 65 29 20 3d 20 55 70  r(province) = Up
7020: 70 65 72 28 27 4e 55 4c 4c 27 29 20 4f 52 20 55  per('NULL') OR U
7030: 70 70 65 72 28 72 65 67 69 6f 6e 29 20 3d 20 55  pper(region) = U
7040: 70 70 65 72 28 27 4e 55 4c 4c 27 29 29 0d 0a 3c  pper('NULL'))..<
7050: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 49 74 27 73  /verbatim>..It's
7060: 20 72 61 74 68 65 72 20 6f 62 76 69 6f 75 73 20   rather obvious 
7070: 74 68 61 74 20 3c 62 3e 27 72 69 6f 20 6e 65 6c  that <b>'rio nel
7080: 6c 27 65 6c 62 61 27 3c 2f 62 3e 20 69 73 20 61  l'elba'</b> is a
7090: 6e 20 69 6c 6c 65 67 61 6c 20 53 51 4c 20 74 65  n illegal SQL te
70a0: 78 74 20 73 74 72 69 6e 67 3b 20 74 68 65 20 63  xt string; the c
70b0: 6f 72 72 65 63 74 20 73 79 6e 74 61 78 20 73 68  orrect syntax sh
70c0: 6f 75 6c 64 20 62 65 20 69 6e 73 74 65 61 64 20  ould be instead 
70d0: 3c 62 3e 27 72 69 6f 20 6e 65 6c 6c 27 27 65 6c  <b>'rio nell''el
70e0: 62 61 27 3c 2f 62 3e 2e 0d 0a 3c 62 72 3e 3c 62  ba'</b>...<br><b
70f0: 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  r>..<verbatim>..
7100: 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f  SELECT StoredPro
7110: 63 5f 45 78 65 63 75 74 65 28 20 27 6d 79 5f 70  c_Execute( 'my_p
7120: 72 6f 63 27 29 2c 20 27 40 73 72 69 64 40 3d 33  roc'), '@srid@=3
7130: 30 30 33 27 2c 20 27 40 79 65 61 72 40 3d 32 30  003', '@year@=20
7140: 31 31 27 2c 20 27 40 6d 75 6e 69 63 69 70 61 6c  11', '@municipal
7150: 69 74 79 40 3d 72 69 6f 20 6e 65 6c 6c 27 27 27  ity@=rio nell'''
7160: 27 65 6c 62 61 27 2c 20 27 40 73 68 70 5f 70 61  'elba', '@shp_pa
7170: 74 68 40 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65  th@=C:/users/joe
7180: 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73  /stored_proc_tes
7190: 74 2f 72 69 6f 5f 65 6c 62 61 5f 32 30 31 31 5f  t/rio_elba_2011_
71a0: 33 30 30 33 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a  3003');..-----..
71b0: 31 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a  1..</verbatim>..
71c0: 52 65 73 6f 6c 76 69 6e 67 20 73 75 63 68 20 61  Resolving such a
71d0: 6e 20 69 73 73 75 65 20 69 73 20 72 61 74 68 65  n issue is rathe
71e0: 72 20 74 72 69 76 69 61 6c 3b 20 77 65 20 6a 75  r trivial; we ju
71f0: 73 74 20 68 61 76 65 20 74 6f 20 75 73 65 20 3c  st have to use <
7200: 62 3e 66 6f 75 72 3c 2f 62 3e 20 63 6f 6e 73 65  b>four</b> conse
7210: 63 75 74 69 76 65 20 73 69 6e 67 6c 65 2d 71 75  cutive single-qu
7220: 6f 74 65 73 20 73 6f 20 74 6f 20 63 6f 72 72 65  otes so to corre
7230: 63 74 6c 79 20 65 73 63 61 70 65 20 74 68 65 20  ctly escape the 
7240: 73 74 72 69 6e 67 20 76 61 6c 75 65 2e 0d 0a 3c  string value...<
7250: 62 72 3e 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65 20  br><br>..<table 
7260: 77 69 64 74 68 3d 22 31 30 30 25 22 3e 3c 74 72  width="100%"><tr
7270: 3e 0d 0a 3c 74 64 20 77 69 64 74 68 3d 22 33 33  >..<td width="33
7280: 25 22 20 61 6c 69 67 6e 3d 22 6c 65 66 74 22 3e  %" align="left">
7290: 3c 2f 74 64 3e 0d 0a 3c 74 64 20 61 6c 69 67 6e  </td>..<td align
72a0: 3d 22 63 65 6e 74 65 72 22 3e 3c 61 20 68 72 65  ="center"><a hre
72b0: 66 3d 22 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67  f="https://www.g
72c0: 61 69 61 2d 67 69 73 2e 69 74 2f 66 6f 73 73 69  aia-gis.it/fossi
72d0: 6c 2f 6c 69 62 73 70 61 74 69 61 6c 69 74 65 2f  l/libspatialite/
72e0: 77 69 6b 69 3f 6e 61 6d 65 3d 34 2e 33 2e 30 2b  wiki?name=4.3.0+
72f0: 64 6f 63 22 3e 62 61 63 6b 20 74 6f 20 69 6e 64  doc">back to ind
7300: 65 78 3c 2f 61 3e 3c 2f 74 64 3e 0d 0a 3c 74 64  ex</a></td>..<td
7310: 20 77 69 64 74 68 3d 22 33 33 25 22 20 61 6c 69   width="33%" ali
7320: 67 6e 3d 22 72 69 67 68 74 22 3e 3c 2f 74 64 3e  gn="right"></td>
7330: 0d 0a 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0a  ..</tr></table>.
7340: 5a 20 34 36 36 39 63 38 35 39 35 35 38 30 35 65  Z 4669c85955805e
7350: 63 64 65 62 66 30 37 62 34 34 33 62 63 31 37 66  cdebf07b443bc17f
7360: 35 38 0a                                         58.