Hex Artifact Content
Not logged in

Artifact 9bbb5d516e45bf624ece82664c70ef86acaa9d0f:

Wiki page [Stored Procedures] by sandro 2017-12-03 09:07:58.
0000: 44 20 32 30 31 37 2d 31 32 2d 30 33 54 30 39 3a  D 2017-12-03T09:
0010: 30 37 3a 35 38 2e 37 36 37 0a 4c 20 53 74 6f 72  07:58.767.L Stor
0020: 65 64 5c 73 50 72 6f 63 65 64 75 72 65 73 0a 50  ed\sProcedures.P
0030: 20 30 32 31 35 62 35 39 33 37 31 62 66 35 31 39   0215b59371bf519
0040: 36 65 66 35 38 33 31 38 34 37 34 61 63 61 65 30  6ef58318474acae0
0050: 35 32 64 37 64 63 36 31 37 0a 55 20 73 61 6e 64  52d7dc617.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 62 65 63 61 75 73 65 20 74 68 65 20 74 61 62   because the tab
1080: 6c 65 2d 6e 61 6d 65 73 20 61 6e 64 20 63 6f 6c  le-names and col
1090: 75 6d 6e 2d 6e 61 6d 65 73 20 61 72 65 20 6e 6f  umn-names are no
10a0: 20 6c 6f 6e 67 65 72 20 3c 75 3e 3c 69 3e 68 61   longer <u><i>ha
10b0: 72 64 63 6f 64 65 64 3c 2f 69 3e 3c 2f 75 3e 2c  rdcoded</i></u>,
10c0: 20 62 75 74 20 3c 75 3e 3c 69 3e 64 79 6e 61 6d   but <u><i>dynam
10d0: 69 63 3c 2f 69 3e 3c 2f 75 3e 2e 3c 62 72 3e 0d  ic</i></u>.<br>.
10e0: 0a 53 6f 20 77 65 20 61 72 65 20 6e 6f 77 20 66  .So we are now f
10f0: 72 65 65 20 74 6f 20 72 65 75 73 65 20 74 68 69  ree to reuse thi
1100: 73 20 53 51 4c 20 42 6f 64 79 2c 20 69 6e 20 61  s SQL Body, in a
1110: 20 64 69 66 66 65 72 65 6e 74 20 63 6f 6e 74 65   different conte
1120: 78 74 20 61 66 74 65 72 20 73 65 74 74 69 6e 67  xt after setting
1130: 20 74 68 65 20 61 70 70 72 6f 70 72 69 61 74 65   the appropriate
1140: 20 56 61 72 69 61 62 6c 65 20 56 61 6c 75 65 73   Variable Values
1150: 20 62 65 66 6f 72 65 20 65 78 65 63 75 74 69 6f   before executio
1160: 6e 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 62 3e 3c  n.<br><br>..<b><
1170: 69 3e 53 51 4c 20 42 6f 64 69 65 73 3c 2f 69 3e  i>SQL Bodies</i>
1180: 3c 2f 62 3e 20 65 78 69 73 74 20 69 6e 20 74 77  </b> exist in tw
1190: 6f 20 64 69 66 66 65 72 65 6e 74 20 66 6f 72 6d  o different form
11a0: 73 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 3c 62  s:..<ul>..<li><b
11b0: 3e 72 61 77 3c 2f 62 3e 3a 20 63 6f 6e 74 61 69  >raw</b>: contai
11c0: 6e 69 6e 67 20 74 68 65 20 73 79 6d 62 6f 6c 69  ning the symboli
11d0: 63 20 56 61 72 69 61 62 6c 65 73 2e 3c 2f 6c 69  c Variables.</li
11e0: 3e 0d 0a 3c 6c 69 3e 3c 62 3e 63 6f 6f 6b 65 64  >..<li><b>cooked
11f0: 3c 2f 62 3e 3a 20 77 69 74 68 20 74 68 65 20 73  </b>: with the s
1200: 79 6d 62 6f 6c 69 63 20 56 61 72 69 61 62 6c 65  ymbolic Variable
1210: 73 20 70 72 6f 70 65 72 6c 79 20 72 65 70 6c 61  s properly repla
1220: 63 65 64 20 62 79 20 74 68 65 20 61 63 74 75 61  ced by the actua
1230: 6c 20 76 61 6c 75 65 73 2e 3c 62 72 3e 0d 0a 4f  l values.<br>..O
1240: 62 76 69 6f 75 73 6c 79 2c 20 6f 6e 6c 79 20 74  bviously, only t
1250: 68 65 20 3c 62 3e 3c 69 3e 63 6f 6f 6b 65 64 3c  he <b><i>cooked<
1260: 2f 69 3e 3c 2f 62 3e 20 66 6f 72 6d 20 63 61 6e  /i></b> form can
1270: 20 62 65 20 73 75 63 63 65 73 73 66 75 6c 6c 79   be successfully
1280: 20 65 78 65 63 75 74 65 64 2e 3c 2f 6c 69 3e 0d   executed.</li>.
1290: 0a 3c 2f 75 6c 3e 0d 0a 3c 62 72 3e 3c 68 72 3e  .</ul>..<br><hr>
12a0: 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c  ..</li>..<li>..<
12b0: 68 34 3e 53 51 4c 20 50 72 6f 63 65 64 75 72 65  h4>SQL Procedure
12c0: 20 42 4c 4f 42 20 6f 62 6a 65 63 74 3c 2f 68 34   BLOB object</h4
12d0: 3e 0d 0a 54 68 69 73 20 73 69 6d 70 6c 79 20 69  >..This simply i
12e0: 73 20 61 20 3c 62 3e 3c 69 3e 42 4c 4f 42 20 65  s a <b><i>BLOB e
12f0: 6e 63 6f 64 65 64 3c 2f 69 3e 3c 2f 62 3e 20 77  ncoded</i></b> w
1300: 69 74 68 20 74 68 65 20 70 72 65 2d 63 6f 6d 70  ith the pre-comp
1310: 69 6c 65 64 20 27 3c 75 3e 3c 69 3e 72 61 77 3c  iled '<u><i>raw<
1320: 2f 69 3e 3c 2f 75 3e 27 20 3c 62 3e 3c 69 3e 53  /i></u>' <b><i>S
1330: 51 4c 20 42 6f 64 79 3c 2f 69 3e 3c 2f 62 3e 2c  QL Body</i></b>,
1340: 20 77 68 69 63 68 20 77 69 6c 6c 20 62 65 20 75   which will be u
1350: 73 65 64 20 62 79 20 20 70 72 61 63 74 69 63 61  sed by  practica
1360: 6c 6c 79 20 61 6c 6c 20 53 51 4c 20 66 75 6e 63  lly all SQL func
1370: 74 69 6f 6e 73 20 73 75 70 70 6f 72 74 69 6e 67  tions supporting
1380: 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72   Stored Procedur
1390: 65 73 2e 20 0d 0a 3c 62 72 3e 3c 62 72 3e 3c 68  es. ..<br><br><h
13a0: 72 3e 20 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e  r> ..</li>..<li>
13b0: 0d 0a 3c 68 34 3e 53 74 6f 72 65 64 20 50 72 6f  ..<h4>Stored Pro
13c0: 63 65 64 75 72 65 3c 2f 68 34 3e 0d 0a 41 20 3c  cedure</h4>..A <
13d0: 62 3e 3c 69 3e 53 51 4c 20 50 72 6f 63 65 64 75  b><i>SQL Procedu
13e0: 72 65 20 42 4c 4f 42 20 6f 62 6a 65 63 74 3c 2f  re BLOB object</
13f0: 69 3e 3c 2f 62 3e 20 74 68 61 74 20 69 73 20 70  i></b> that is p
1400: 65 72 6d 61 6e 65 6e 74 6c 79 20 73 74 6f 72 65  ermanently store
1410: 64 20 69 6e 74 6f 20 61 20 64 61 74 61 62 61 73  d into a databas
1420: 65 2e 3c 62 72 3e 0d 0a 54 68 69 73 20 6d 61 6b  e.<br>..This mak
1430: 65 73 20 69 74 20 65 61 73 69 65 72 20 74 6f 20  es it easier to 
1440: 75 73 65 20 69 6e 20 61 20 61 75 74 6f 6d 61 74  use in a automat
1450: 65 64 20 20 77 6f 72 6b 66 6c 6f 77 2c 20 70 65  ed  workflow, pe
1460: 72 68 61 70 73 20 74 6f 20 62 65 20 69 6d 70 6c  rhaps to be impl
1470: 65 6d 65 6e 74 65 64 20 61 73 20 61 20 72 6f 75  emented as a rou
1480: 74 69 6e 65 6c 79 20 70 65 72 69 6f 64 69 63 20  tinely periodic 
1490: 74 61 73 6b 20 28 64 61 69 6c 79 20 2f 20 77 65  task (daily / we
14a0: 65 6b 6c 79 20 2f 20 6d 6f 6e 74 68 6c 79 20 61  ekly / monthly a
14b0: 6e 64 20 73 6f 20 6f 6e 29 2e 3c 62 72 3e 0d 0a  nd so on).<br>..
14c0: 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65  Stored Procedure
14d0: 73 20 61 6c 77 61 79 73 20 63 6f 6e 74 61 69 6e  s always contain
14e0: 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 65   the following e
14f0: 6c 65 6d 65 6e 74 73 3a 0d 0a 3c 75 6c 3e 0d 0a  lements:..<ul>..
1500: 3c 6c 69 3e 61 20 3c 62 3e 6e 61 6d 65 3c 2f 62  <li>a <b>name</b
1510: 3e 2c 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 62  >, intended to b
1520: 65 20 61 6e 20 75 6e 69 71 75 65 20 69 64 65 6e  e an unique iden
1530: 74 69 66 69 65 72 20 28 3c 62 3e 3c 69 3e 50 72  tifier (<b><i>Pr
1540: 69 6d 61 72 79 20 4b 65 79 3c 2f 69 3e 3c 2f 62  imary Key</i></b
1550: 3e 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 20  >).</li>..<li>a 
1560: 3c 62 3e 74 69 74 6c 65 3c 2f 62 3e 2c 20 69 2e  <b>title</b>, i.
1570: 65 2e 20 61 20 73 68 6f 72 74 20 64 65 73 63 72  e. a short descr
1580: 69 70 74 69 6f 6e 20 6f 66 20 74 68 65 20 69 6e  iption of the in
1590: 74 65 6e 64 65 64 20 73 63 6f 70 65 20 6f 66 20  tended scope of 
15a0: 74 68 65 20 53 74 6f 72 65 64 20 50 72 6f 63 65  the Stored Proce
15b0: 64 75 72 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e  dure.</li>..<li>
15c0: 61 20 3c 62 3e 53 51 4c 20 50 72 6f 63 65 64 75  a <b>SQL Procedu
15d0: 72 65 20 42 4c 4f 42 20 4f 62 6a 65 63 74 3c 2f  re BLOB Object</
15e0: 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d  b>.</li>..</ul>.
15f0: 0a 3c 62 72 3e 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e  .<br><hr>..</li>
1600: 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 56 61 72 69  ..<li>..<h4>Vari
1610: 61 62 6c 65 20 77 69 74 68 20 56 61 6c 75 65 20  able with Value 
1620: 73 74 72 69 6e 67 73 3c 2f 68 34 3e 0d 0a 42 65  strings</h4>..Be
1630: 66 6f 72 65 20 65 78 65 63 75 74 69 6e 67 20 61  fore executing a
1640: 20 27 3c 69 3e 72 61 77 3c 2f 69 3e 27 20 3c 62   '<i>raw</i>' <b
1650: 3e 3c 69 3e 53 51 4c 20 42 6f 64 79 3c 2f 69 3e  ><i>SQL Body</i>
1660: 3c 2f 62 3e 20 28 77 69 74 68 20 70 6c 61 63 65  </b> (with place
1670: 68 6f 6c 64 65 72 20 3c 62 3e 3c 69 3e 56 61 72  holder <b><i>Var
1680: 69 61 62 6c 65 73 3c 2f 69 3e 3c 2f 62 3e 29 2c  iables</i></b>),
1690: 20 74 68 65 73 65 20 56 61 72 69 61 62 6c 65 73   these Variables
16a0: 20 6e 65 65 64 20 74 6f 20 62 65 20 72 65 70 6c   need to be repl
16b0: 61 63 65 64 20 28 27 3c 69 3e 63 6f 6f 6b 65 64  aced ('<i>cooked
16c0: 3c 2f 69 3e 27 29 20 77 69 74 68 20 74 68 65 20  </i>') with the 
16d0: 61 70 70 72 6f 70 72 69 61 74 65 20 3c 62 3e 3c  appropriate <b><
16e0: 69 3e 56 61 6c 75 65 73 3c 2f 69 3e 3c 2f 62 3e  i>Values</i></b>
16f0: 2c 20 74 68 69 73 20 70 72 6f 70 65 72 6c 79 20  , this properly 
1700: 74 72 61 6e 73 66 6f 72 6d 69 6e 67 20 61 20 27  transforming a '
1710: 3c 62 3e 72 61 77 3c 2f 62 3e 27 20 53 51 4c 20  <b>raw</b>' SQL 
1720: 42 6f 64 79 20 69 6e 74 6f 20 61 20 27 3c 62 3e  Body into a '<b>
1730: 63 6f 6f 6b 65 64 3c 2f 62 3e 27 20 53 51 4c 20  cooked</b>' SQL 
1740: 42 6f 64 79 2e 3c 62 72 3e 0d 0a 41 20 3c 62 3e  Body.<br>..A <b>
1750: 3c 69 3e 56 61 72 69 61 62 6c 65 20 77 69 74 68  <i>Variable with
1760: 20 56 61 6c 75 65 3c 2f 69 3e 3c 2f 62 3e 20 73   Value</i></b> s
1770: 74 72 69 6e 67 20 73 69 6d 70 6c 79 20 69 73 20  tring simply is 
1780: 61 6e 20 61 70 70 72 6f 70 72 69 61 74 65 6c 79  an appropriately
1790: 20 77 65 6c 6c 2d 66 6f 72 6d 61 74 74 65 64 20   well-formatted 
17a0: 54 65 78 74 20 73 74 72 69 6e 67 20 64 65 63 6c  Text string decl
17b0: 61 72 69 6e 67 20 62 6f 74 68 20 74 68 65 20 53  aring both the S
17c0: 79 6d 62 6f 6c 20 61 6e 64 20 74 68 65 20 63 6f  ymbol and the co
17d0: 72 72 65 73 70 6f 6e 64 69 6e 67 20 72 65 70 6c  rresponding repl
17e0: 61 63 65 6d 65 6e 74 20 56 61 6c 75 65 20 28 65  acement Value (e
17f0: 78 70 72 65 73 73 65 64 20 69 6e 20 69 74 73 20  xpressed in its 
1800: 74 65 78 74 75 61 6c 20 72 65 70 72 65 73 65 6e  textual represen
1810: 74 61 74 69 6f 6e 29 2e 20 45 78 61 6d 70 6c 65  tation). Example
1820: 73 3a 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  s:..<verbatim>..
1830: 40 76 61 6c 75 65 5f 31 40 3d 31 32 33 34 20 20  @value_1@=1234  
1840: 20 20 20 20 20 20 20 20 20 20 2d 2d 20 69 6e 74            -- int
1850: 65 67 65 72 20 76 61 6c 75 65 0d 0a 40 76 61 6c  eger value..@val
1860: 75 65 5f 32 40 3d 31 32 2e 33 34 20 20 20 20 20  ue_2@=12.34     
1870: 20 20 20 20 20 20 2d 2d 20 64 6f 75 62 6c 65 20        -- double 
1880: 76 61 6c 75 65 0d 0a 40 76 61 6c 75 65 5f 33 40  value..@value_3@
1890: 3d 4e 65 77 20 59 6f 72 6b 20 43 69 74 79 20 20  =New York City  
18a0: 20 2d 2d 20 74 65 78 74 20 76 61 6c 75 65 0d 0a   -- text value..
18b0: 40 76 61 6c 75 65 5f 34 40 3d 78 27 30 31 32 33  @value_4@=x'0123
18c0: 61 62 63 64 27 20 20 20 20 20 2d 2d 20 62 6c 6f  abcd'     -- blo
18d0: 62 20 76 61 6c 75 65 0d 0a 40 76 61 6c 75 65 5f  b value..@value_
18e0: 35 40 3d 4e 55 4c 4c 20 20 20 20 20 20 20 20 20  5@=NULL         
18f0: 20 20 20 2d 2d 20 6e 75 6c 6c 20 76 61 6c 75 65     -- null value
1900: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c  ..</verbatim>..<
1910: 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23  table bgcolor="#
1920: 66 38 66 38 64 38 22 20 63 65 6c 6c 70 61 64 64  f8f8d8" cellpadd
1930: 69 6e 67 3d 22 36 22 20 63 65 6c 6c 73 70 61 63  ing="6" cellspac
1940: 69 6e 67 3d 22 38 22 3e 3c 74 72 3e 3c 74 64 3e  ing="8"><tr><td>
1950: 0d 0a 3c 75 3e 4e 6f 74 65 3c 2f 75 3e 3a 20 72  ..<u>Note</u>: r
1960: 65 70 6c 61 63 69 6e 67 20 56 61 72 69 61 62 6c  eplacing Variabl
1970: 65 73 20 77 69 74 68 20 74 68 65 20 61 63 74 75  es with the actu
1980: 61 6c 20 56 61 6c 75 65 73 20 69 73 20 61 20 62  al Values is a b
1990: 6c 69 6e 64 20 70 72 6f 63 65 73 73 20 63 6f 6d  lind process com
19a0: 70 6c 65 74 65 6c 79 20 69 6e 73 65 6e 73 69 62  pletely insensib
19b0: 6c 65 20 74 6f 20 74 68 65 20 73 70 65 63 69 66  le to the specif
19c0: 69 63 20 73 79 6e 74 61 63 74 69 63 20 63 6f 6e  ic syntactic con
19d0: 74 65 78 74 2e 3c 62 72 3e 0d 0a 59 6f 75 20 61  text.<br>..You a
19e0: 72 65 20 72 65 73 70 6f 6e 73 69 62 6c 65 20 66  re responsible f
19f0: 6f 72 20 74 68 65 20 63 6f 72 72 65 63 74 20 61  or the correct a
1a00: 70 70 6c 69 63 61 74 69 6f 6e 20 6f 66 20 73 69  pplication of si
1a10: 6e 67 6c 65 2d 20 6f 72 20 64 6f 75 62 6c 65 2d  ngle- or double-
1a20: 71 75 6f 74 69 6e 67 2c 20 72 65 71 75 69 72 65  quoting, require
1a30: 64 20 62 79 20 74 68 65 20 53 51 4c 20 73 79 6e  d by the SQL syn
1a40: 74 61 78 20 72 75 6c 65 73 2e 0d 0a 3c 2f 74 64  tax rules...</td
1a50: 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a  ></tr></table>..
1a60: 3c 62 72 3e 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d  <br><hr>..</li>.
1a70: 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 53 74 6f 72 65  .<li>..<h4>Store
1a80: 64 20 56 61 72 69 61 62 6c 65 3c 2f 68 34 3e 0d  d Variable</h4>.
1a90: 0a 41 20 3c 62 3e 3c 69 3e 56 61 72 69 61 62 6c  .A <b><i>Variabl
1aa0: 65 20 77 69 74 68 20 56 61 6c 75 65 3c 2f 69 3e  e with Value</i>
1ab0: 3c 2f 62 3e 20 70 65 72 6d 61 6e 65 6e 74 6c 79  </b> permanently
1ac0: 20 73 74 6f 72 65 64 20 69 6e 74 6f 20 61 20 64   stored into a d
1ad0: 61 74 61 62 61 73 65 2e 3c 62 72 3e 0d 0a 53 74  atabase.<br>..St
1ae0: 6f 72 65 64 20 56 61 72 69 61 62 6c 65 73 20 61  ored Variables a
1af0: 6c 77 61 79 73 20 63 6f 6e 74 61 69 6e 20 74 68  lways contain th
1b00: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 65 6c 65 6d  e following elem
1b10: 65 6e 74 73 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69  ents:..<ul>..<li
1b20: 3e 61 20 3c 62 3e 6e 61 6d 65 3c 2f 62 3e 2c 20  >a <b>name</b>, 
1b30: 69 6e 74 65 6e 64 65 64 20 74 6f 20 62 65 20 61  intended to be a
1b40: 6e 20 75 6e 69 71 75 65 20 69 64 65 6e 74 69 66  n unique identif
1b50: 69 65 72 20 28 3c 62 3e 3c 69 3e 50 72 69 6d 61  ier (<b><i>Prima
1b60: 72 79 20 4b 65 79 3c 2f 69 3e 3c 2f 62 3e 29 2e  ry Key</i></b>).
1b70: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 3c 62 3e  </li>..<li>a <b>
1b80: 74 69 74 6c 65 3c 2f 62 3e 2c 20 69 2e 65 2e 20  title</b>, i.e. 
1b90: 61 20 73 68 6f 72 74 20 64 65 73 63 72 69 70 74  a short descript
1ba0: 69 6f 6e 20 6f 66 20 74 68 65 20 69 6e 74 65 6e  ion of the inten
1bb0: 64 65 64 20 73 63 6f 70 65 20 6f 66 20 74 68 65  ded scope of the
1bc0: 20 53 74 6f 72 65 64 20 56 61 72 69 61 62 6c 65   Stored Variable
1bd0: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 3c 62  .</li>..<li>a <b
1be0: 3e 56 61 6c 75 65 20 73 74 72 69 6e 67 3c 2f 62  >Value string</b
1bf0: 3e 2e 3c 2f 6c 69 3e 3c 62 72 3e 0d 0a 3c 2f 75  >.</li><br>..</u
1c00: 6c 3e 3c 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72  l><table bgcolor
1c10: 3d 22 23 66 38 66 38 64 38 22 20 63 65 6c 6c 70  ="#f8f8d8" cellp
1c20: 61 64 64 69 6e 67 3d 22 36 22 20 63 65 6c 6c 73  adding="6" cells
1c30: 70 61 63 69 6e 67 3d 22 38 22 3e 3c 74 72 3e 3c  pacing="8"><tr><
1c40: 74 64 3e 0d 0a 3c 75 3e 4e 6f 74 65 3c 2f 75 3e  td>..<u>Note</u>
1c50: 3a 20 74 68 65 20 69 6e 74 65 6e 64 65 64 20 73  : the intended s
1c60: 63 6f 70 65 20 6f 66 20 3c 62 3e 53 74 6f 72 65  cope of <b>Store
1c70: 64 20 56 61 72 69 61 62 6c 65 73 3c 2f 62 3e 20  d Variables</b> 
1c80: 69 73 20 74 6f 20 64 65 66 69 6e 65 20 61 70 70  is to define app
1c90: 72 6f 70 72 69 61 74 65 20 64 65 66 61 75 6c 74  ropriate default
1ca0: 20 76 61 6c 75 65 73 2e 3c 62 72 3e 0d 0a 49 66   values.<br>..If
1cb0: 20 61 20 67 69 76 65 6e 20 3c 62 3e 56 61 72 69   a given <b>Vari
1cc0: 61 62 6c 65 3c 2f 62 3e 20 69 73 20 62 65 69 6e  able</b> is bein
1cd0: 67 20 75 73 65 64 20 77 69 74 68 69 6e 20 61 20  g used within a 
1ce0: 3c 69 3e 72 61 77 3c 2f 69 3e 20 53 51 4c 20 42  <i>raw</i> SQL B
1cf0: 6f 64 79 20 74 6f 20 62 65 20 65 78 65 63 75 74  ody to be execut
1d00: 65 64 2c 20 61 6e 64 20 61 20 63 6f 72 72 65 73  ed, and a corres
1d10: 70 6f 6e 64 69 6e 67 20 3c 62 3e 56 61 72 69 61  ponding <b>Varia
1d20: 62 6c 65 20 77 69 74 68 20 56 61 6c 75 65 3c 2f  ble with Value</
1d30: 62 3e 20 68 61 73 20 6e 6f 74 20 62 65 65 6e 20  b> has not been 
1d40: 72 65 73 6f 6c 76 65 64 2c 20 74 68 65 6e 20 61  resolved, then a
1d50: 6e 20 61 74 74 65 6d 70 74 20 77 69 6c 6c 20 62  n attempt will b
1d60: 65 20 61 6c 77 61 79 73 20 6d 61 64 65 20 74 6f  e always made to
1d70: 20 72 65 73 6f 6c 76 65 20 69 74 20 62 79 20 73   resolve it by s
1d80: 65 61 72 63 68 69 6e 67 20 66 6f 72 20 61 20 63  earching for a c
1d90: 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 3c 62 3e  orresponding <b>
1da0: 53 74 6f 72 65 64 20 56 61 72 69 61 62 6c 65 3c  Stored Variable<
1db0: 2f 62 3e 20 62 79 20 6e 61 6d 65 20 28 69 66 20  /b> by name (if 
1dc0: 69 74 20 65 78 69 73 74 73 29 2e 3c 62 72 3e 0d  it exists).<br>.
1dd0: 0a 41 6e 20 65 78 70 6c 69 63 69 74 6c 79 20 64  .An explicitly d
1de0: 65 66 69 6e 65 64 20 3c 62 3e 56 61 72 69 61 62  efined <b>Variab
1df0: 6c 65 20 77 69 74 68 20 56 61 6c 75 65 3c 2f 62  le with Value</b
1e00: 3e 20 61 72 67 75 6d 65 6e 74 20 77 69 6c 6c 20  > argument will 
1e10: 61 6c 77 61 79 73 20 74 61 6b 65 20 70 72 65 63  always take prec
1e20: 65 64 65 6e 63 65 20 6f 76 65 72 20 74 68 65 20  edence over the 
1e30: 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 3c 62  corresponding <b
1e40: 3e 53 74 6f 72 65 64 20 56 61 72 69 61 62 6c 65  >Stored Variable
1e50: 3c 2f 62 3e 3b 20 69 6e 20 6f 74 68 65 72 20 77  </b>; in other w
1e60: 6f 72 64 73 20 61 20 3c 62 3e 53 74 6f 72 65 64  ords a <b>Stored
1e70: 20 56 61 72 69 61 62 6c 65 3c 2f 62 3e 20 28 69   Variable</b> (i
1e80: 66 20 64 65 66 69 6e 65 64 29 20 77 69 6c 6c 20  f defined) will 
1e90: 6a 75 73 74 20 62 65 20 63 6f 6e 73 69 64 65 72  just be consider
1ea0: 65 64 20 74 68 65 20 64 65 66 61 75 6c 74 20 76  ed the default v
1eb0: 61 6c 75 65 2e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72  alue...</td></tr
1ec0: 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 62 72 3e 3c  ></table>..<br><
1ed0: 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e  hr>..</li>..<li>
1ee0: 0d 0a 3c 68 34 3e 53 51 4c 20 4c 6f 67 66 69 6c  ..<h4>SQL Logfil
1ef0: 65 3c 2f 68 34 3e 0d 0a 53 51 4c 20 71 75 65 72  e</h4>..SQL quer
1f00: 69 65 73 20 77 69 6c 6c 20 75 73 75 61 6c 6c 79  ies will usually
1f10: 20 72 65 74 75 72 6e 20 73 6f 6d 65 20 3c 62 3e   return some <b>
1f20: 72 65 73 75 6c 74 73 65 74 3c 2f 62 3e 20 70 6f  resultset</b> po
1f30: 74 65 6e 74 69 61 6c 6c 79 20 63 6f 6e 74 61 69  tentially contai
1f40: 6e 69 6e 67 20 75 73 65 66 75 6c 20 69 6e 66 6f  ning useful info
1f50: 72 6d 61 74 69 6f 6e 2e 3c 62 72 3e 0d 0a 42 75  rmation.<br>..Bu
1f60: 74 20 65 78 65 63 75 74 69 6e 67 20 61 20 3c 62  t executing a <b
1f70: 3e 53 51 4c 20 50 72 6f 63 65 64 75 72 65 3c 2f  >SQL Procedure</
1f80: 62 3e 20 6f 72 20 3c 62 3e 53 74 6f 72 65 64 20  b> or <b>Stored 
1f90: 50 72 6f 63 65 64 75 72 65 3c 2f 62 3e 20 77 69  Procedure</b> wi
1fa0: 6c 6c 20 62 65 20 73 65 65 6e 20 62 79 20 53 51  ll be seen by SQ
1fb0: 4c 69 74 65 20 6a 75 73 74 20 61 73 20 61 20 73  Lite just as a s
1fc0: 69 6d 70 6c 65 20 53 51 4c 20 66 75 6e 63 74 69  imple SQL functi
1fd0: 6f 6e 20 63 61 6c 6c 20 73 69 6d 70 6c 79 20 72  on call simply r
1fe0: 65 74 75 72 6e 69 6e 67 20 61 20 66 69 6e 61 6c  eturning a final
1ff0: 20 73 75 63 63 65 73 73 20 6f 72 20 66 61 69 6c   success or fail
2000: 75 72 65 20 72 65 74 75 72 6e 20 63 6f 64 65 2e  ure return code.
2010: 3c 62 72 3e 0d 0a 41 6e 79 20 69 6e 66 6f 72 6d  <br>..Any inform
2020: 61 74 69 6f 6e 20 61 62 6f 75 74 20 61 6c 6c 20  ation about all 
2030: 74 68 65 20 69 6e 74 65 72 6d 65 64 69 61 74 65  the intermediate
2040: 20 72 65 73 75 6c 74 73 65 74 73 2c 20 69 6e 74   resultsets, int
2050: 65 72 6e 61 6c 6c 79 20 70 72 6f 64 75 63 65 64  ernally produced
2060: 20 64 75 72 69 6e 67 20 74 68 65 20 65 78 65 63   during the exec
2070: 75 74 69 6f 6e 20 6f 66 20 74 68 65 20 50 72 6f  ution of the Pro
2080: 63 65 64 75 72 65 2c 20 77 69 6c 6c 20 62 65 20  cedure, will be 
2090: 6c 6f 73 74 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 54  lost.<br><br>..T
20a0: 6f 20 61 76 6f 69 64 20 74 68 69 73 2c 20 79 6f  o avoid this, yo
20b0: 75 20 63 61 6e 20 63 6f 6e 66 69 67 75 72 65 20  u can configure 
20c0: 61 6e 20 65 78 74 65 72 6e 61 6c 20 3c 62 3e 53  an external <b>S
20d0: 51 4c 20 4c 6f 67 66 69 6c 65 3c 2f 62 3e 20 74  QL Logfile</b> t
20e0: 6f 20 70 65 72 6d 61 6e 65 6e 74 6c 79 20 73 74  o permanently st
20f0: 6f 72 65 20 61 6c 6c 20 69 6e 74 65 72 6d 65 64  ore all intermed
2100: 69 61 74 65 20 72 65 73 75 6c 74 73 65 74 73 20  iate resultsets 
2110: 69 6e 74 6f 20 61 6e 20 6f 72 64 69 6e 61 72 79  into an ordinary
2120: 20 74 65 78 74 20 66 69 6c 65 2e 20 54 68 65 20   text file. The 
2130: 53 51 4c 20 4c 6f 67 66 69 6c 65 20 73 75 70 70  SQL Logfile supp
2140: 6f 72 74 73 20 74 77 6f 20 64 69 66 66 65 72 65  orts two differe
2150: 6e 74 20 6d 6f 64 65 73 3a 0d 0a 3c 75 6c 3e 0d  nt modes:..<ul>.
2160: 0a 3c 6c 69 3e 3c 62 3e 54 72 75 6e 63 61 74 65  .<li><b>Truncate
2170: 3c 2f 62 3e 3a 20 74 68 65 20 4c 6f 67 66 69 6c  </b>: the Logfil
2180: 65 20 77 69 6c 6c 20 62 65 20 61 75 74 6f 6d 61  e will be automa
2190: 74 69 63 61 6c 6c 79 20 63 72 65 61 74 65 64 20  tically created 
21a0: 77 68 65 6e 20 6e 6f 74 20 61 6c 72 65 61 64 79  when not already
21b0: 20 65 78 69 73 74 69 6e 67 2c 20 61 6e 64 20 69   existing, and i
21c0: 74 20 77 69 6c 6c 20 62 65 20 61 6c 77 61 79 73  t will be always
21d0: 20 74 72 75 6e 63 61 74 65 64 20 62 65 66 6f 72   truncated befor
21e0: 65 20 73 74 61 72 74 69 6e 67 20 61 6e 20 65 78  e starting an ex
21f0: 65 63 75 74 69 6f 6e 20 75 6e 69 74 3b 20 69 6e  ecution unit; in
2200: 20 6f 74 68 65 72 20 77 6f 72 64 73 20 69 74 20   other words it 
2210: 77 69 6c 6c 20 61 6c 77 61 79 73 20 70 72 65 73  will always pres
2220: 65 72 76 65 20 6a 75 73 74 20 74 68 65 20 72 65  erve just the re
2230: 73 75 6c 74 73 65 74 73 20 70 72 6f 64 75 63 65  sultsets produce
2240: 64 20 62 79 20 74 68 65 20 6d 6f 73 74 20 72 65  d by the most re
2250: 63 65 6e 74 20 65 78 65 63 75 74 69 6f 6e 20 75  cent execution u
2260: 6e 69 74 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c  nit.</li>..<li><
2270: 62 3e 41 70 70 65 6e 64 3c 2f 62 3e 3a 20 74 68  b>Append</b>: th
2280: 65 20 4c 6f 67 66 69 6c 65 20 77 69 6c 6c 20 62  e Logfile will b
2290: 65 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 20  e automatically 
22a0: 63 72 65 61 74 65 64 20 77 68 65 6e 20 6e 6f 74  created when not
22b0: 20 61 6c 72 65 61 64 79 20 65 78 69 73 74 69 6e   already existin
22c0: 67 2c 20 61 6e 64 20 69 74 20 77 69 6c 6c 20 62  g, and it will b
22d0: 65 20 6e 65 76 65 72 20 74 72 75 6e 63 61 74 65  e never truncate
22e0: 64 20 62 65 66 6f 72 65 20 73 74 61 72 74 69 6e  d before startin
22f0: 67 20 61 6e 20 65 78 65 63 75 74 69 6f 6e 20 75  g an execution u
2300: 6e 69 74 3b 20 69 6e 20 6f 74 68 65 72 20 77 6f  nit; in other wo
2310: 72 64 73 20 69 74 20 77 69 6c 6c 20 70 72 6f 67  rds it will prog
2320: 72 65 73 73 69 76 65 6c 79 20 67 72 6f 77 20 73  ressively grow s
2330: 6f 20 74 6f 20 73 74 6f 72 65 20 61 6c 6c 20 74  o to store all t
2340: 68 65 20 72 65 73 75 6c 74 73 65 74 73 20 70 72  he resultsets pr
2350: 6f 64 75 63 65 64 20 62 79 20 66 6f 6c 6c 6f 77  oduced by follow
2360: 69 6e 67 20 65 78 65 63 75 74 69 6f 6e 20 75 6e  ing execution un
2370: 69 74 73 2e 3c 62 72 3e 0d 0a 3c 75 3e 4e 6f 74  its.<br>..<u>Not
2380: 65 3c 2f 75 3e 3a 20 79 6f 75 27 6c 6c 20 62 65  e</u>: you'll be
2390: 20 6f 62 76 69 6f 75 73 6c 79 20 72 65 71 75 69   obviously requi
23a0: 72 65 64 20 74 6f 20 66 6c 75 73 68 20 74 68 65  red to flush the
23b0: 20 4c 6f 67 66 69 6c 65 20 66 72 6f 6d 20 74 69   Logfile from ti
23c0: 6d 65 20 74 6f 20 74 69 6d 65 20 73 6f 20 74 6f  me to time so to
23d0: 20 73 61 66 65 6c 79 20 61 76 6f 69 64 20 74 6f   safely avoid to
23e0: 20 63 6f 6e 73 75 6d 65 20 74 6f 6f 20 6d 75 63   consume too muc
23f0: 68 20 73 74 6f 72 61 67 65 20 73 70 61 63 65 2e  h storage space.
2400: 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 2f  </li>..</ul>..</
2410: 6c 69 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 2f 6f 6c  li>..</li>..</ol
2420: 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 32  ><br>..<hr>..<h2
2430: 3e 46 61 6d 69 6c 69 61 72 69 7a 69 6e 67 20 77  >Familiarizing w
2440: 69 74 68 20 53 51 4c 20 46 75 6e 63 74 69 6f 6e  ith SQL Function
2450: 73 3c 2f 68 32 3e 0d 0a 3c 6f 6c 3e 0d 0a 3c 6c  s</h2>..<ol>..<l
2460: 69 3e 0d 0a 3c 68 34 3e 48 61 6e 64 6c 69 6e 67  i>..<h4>Handling
2470: 20 53 51 4c 20 50 72 6f 63 65 64 75 72 65 20 42   SQL Procedure B
2480: 4c 4f 42 20 6f 62 6a 65 63 74 73 3c 2f 68 34 3e  LOB objects</h4>
2490: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45  ..<verbatim>..SE
24a0: 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 46 72 6f  LECT SqlProc_Fro
24b0: 6d 54 65 78 74 28 27 53 45 4c 45 43 54 20 40 63  mText('SELECT @c
24c0: 6f 6c 40 20 46 52 4f 4d 20 40 74 62 6c 40 27 29  ol@ FROM @tbl@')
24d0: 3b 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50  ;....SELECT SqlP
24e0: 72 6f 63 5f 46 72 6f 6d 46 69 6c 65 28 27 2f 68  roc_FromFile('/h
24f0: 6f 6d 65 2f 6a 6f 65 2f 74 65 6d 70 6c 61 74 65  ome/joe/template
2500: 2e 74 78 74 27 2c 20 43 50 31 32 35 32 27 29 3b  .txt', CP1252');
2510: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c  ..</verbatim>..<
2520: 75 6c 3e 0d 0a 3c 6c 69 3e 79 6f 75 20 63 61 6e  ul>..<li>you can
2530: 20 63 72 65 61 74 65 20 61 20 53 51 4c 20 50 72   create a SQL Pr
2540: 6f 63 65 64 75 72 65 20 42 4c 4f 42 20 6f 62 6a  ocedure BLOB obj
2550: 65 63 74 20 62 79 20 64 69 72 65 63 74 6c 79 20  ect by directly 
2560: 70 61 73 73 69 6e 67 20 61 20 54 65 78 74 20 53  passing a Text S
2570: 51 4c 20 42 6f 64 79 2e 3c 2f 6c 69 3e 0d 0a 3c  QL Body.</li>..<
2580: 6c 69 3e 6f 72 20 61 6c 74 65 72 6e 61 74 69 76  li>or alternativ
2590: 65 6c 79 20 79 6f 75 20 63 61 6e 20 6c 6f 61 64  ely you can load
25a0: 20 74 68 65 20 53 51 4c 20 42 6f 64 79 20 66 72   the SQL Body fr
25b0: 6f 6d 20 61 6e 20 65 78 74 65 72 6e 61 6c 20 66  om an external f
25c0: 69 6c 65 2e 3c 62 72 3e 0d 0a 3c 75 3e 4e 6f 74  ile.<br>..<u>Not
25d0: 65 3c 2f 75 3e 3a 20 74 68 69 73 20 69 73 20 61  e</u>: this is a
25e0: 20 73 65 63 75 72 69 74 79 20 73 65 6e 73 69 62   security sensib
25f0: 6c 65 20 6f 70 65 72 61 74 69 6f 6e 2c 20 73 6f  le operation, so
2600: 20 79 6f 75 20 61 6c 77 61 79 73 20 6e 65 65 64   you always need
2610: 20 74 6f 20 73 65 74 20 61 6e 20 65 78 70 6c 69   to set an expli
2620: 63 69 74 20 61 75 74 68 6f 72 69 7a 61 74 69 6f  cit authorizatio
2630: 6e 20 62 79 20 64 65 66 69 6e 69 6e 67 20 3c 62  n by defining <b
2640: 3e 53 50 41 54 49 41 4c 49 54 45 5f 53 45 43 55  >SPATIALITE_SECU
2650: 52 49 54 59 3d 72 65 6c 61 78 65 64 3c 2f 62 3e  RITY=relaxed</b>
2660: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 42 6f 74 68  .</li>..<li>Both
2670: 20 66 75 6e 63 74 69 6f 6e 73 20 61 63 63 65 70   functions accep
2680: 74 20 61 6e 20 6f 70 74 69 6f 6e 61 6c 20 3c 62  t an optional <b
2690: 3e 63 68 61 72 73 65 74 20 65 6e 63 6f 64 69 6e  >charset encodin
26a0: 67 3c 2f 62 3e 20 61 72 67 75 6d 65 6e 74 3b 20  g</b> argument; 
26b0: 69 6e 20 74 68 69 73 20 63 61 73 65 20 74 68 65  in this case the
26c0: 20 53 51 4c 20 42 6f 64 79 20 77 69 6c 6c 20 62   SQL Body will b
26d0: 65 20 61 70 70 72 6f 70 72 69 61 74 65 6c 79 20  e appropriately 
26e0: 63 6f 6e 76 65 72 74 65 64 20 66 72 6f 6d 20 74  converted from t
26f0: 68 65 20 67 69 76 65 6e 20 63 68 61 72 73 65 74  he given charset
2700: 20 69 6e 74 6f 20 3c 62 3e 55 54 46 2d 38 3c 2f   into <b>UTF-8</
2710: 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d  b>.</li>..</ul>.
2720: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c  .<verbatim>..SEL
2730: 45 43 54 20 53 71 6c 50 72 6f 63 5f 49 73 56 61  ECT SqlProc_IsVa
2740: 6c 69 64 20 28 20 53 71 6c 50 72 6f 63 5f 46 72  lid ( SqlProc_Fr
2750: 6f 6d 54 65 78 74 28 27 53 45 4c 45 43 54 20 40  omText('SELECT @
2760: 63 6f 6c 40 20 46 52 4f 4d 20 40 74 62 6c 40 27  col@ FROM @tbl@'
2770: 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a  ) );..-----..1..
2780: 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63  ..SELECT SqlProc
2790: 5f 49 73 56 61 6c 69 64 20 28 20 4d 61 6b 65 50  _IsValid ( MakeP
27a0: 6f 69 6e 74 28 31 31 2e 35 2c 20 34 32 2e 35 2c  oint(11.5, 42.5,
27b0: 20 34 33 32 36 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d   4326) );..-----
27c0: 0d 0a 30 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e  ..0..</verbatim>
27d0: 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 79 6f 75 20  ..<ul>..<li>you 
27e0: 63 61 6e 20 75 73 65 20 3c 62 3e 53 71 6c 50 72  can use <b>SqlPr
27f0: 6f 63 5f 49 73 56 61 6c 69 64 3c 2f 62 3e 20 69  oc_IsValid</b> i
2800: 6e 20 6f 72 64 65 72 20 74 6f 20 63 68 65 63 6b  n order to check
2810: 20 69 66 20 61 20 67 65 6e 65 72 69 63 20 42 4c   if a generic BL
2820: 4f 42 20 72 65 61 6c 6c 79 20 69 73 20 61 20 76  OB really is a v
2830: 61 6c 69 64 20 53 51 4c 20 50 72 6f 63 65 64 75  alid SQL Procedu
2840: 72 65 20 42 4c 4f 42 20 4f 62 6a 65 63 74 2e 0d  re BLOB Object..
2850: 0a 3c 2f 75 6c 3e 0d 0a 3c 76 65 72 62 61 74 69  .</ul>..<verbati
2860: 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72  m>..SELECT SqlPr
2870: 6f 63 5f 4e 75 6d 56 61 72 69 61 62 6c 65 73 20  oc_NumVariables 
2880: 28 20 53 71 6c 50 72 6f 63 5f 46 72 6f 6d 54 65  ( SqlProc_FromTe
2890: 78 74 28 27 53 45 4c 45 43 54 20 40 63 6f 6c 40  xt('SELECT @col@
28a0: 20 46 52 4f 4d 20 40 74 62 6c 40 27 29 20 29 3b   FROM @tbl@') );
28b0: 0d 0a 2d 2d 2d 2d 2d 0d 0a 32 0d 0a 0d 0a 53 45  ..-----..2....SE
28c0: 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 56 61 72  LECT SqlProc_Var
28d0: 69 61 62 6c 65 4e 20 28 53 71 6c 50 72 6f 63 5f  iableN (SqlProc_
28e0: 46 72 6f 6d 54 65 78 74 28 27 53 45 4c 45 43 54  FromText('SELECT
28f0: 20 40 63 6f 6c 40 20 46 52 4f 4d 20 40 74 62 6c   @col@ FROM @tbl
2900: 40 27 29 2c 20 30 29 3b 0d 0a 2d 2d 2d 2d 2d 0d  @'), 0);..-----.
2910: 0a 40 63 6f 6c 40 0d 0a 0d 0a 53 45 4c 45 43 54  .@col@....SELECT
2920: 20 53 71 6c 50 72 6f 63 5f 56 61 72 69 61 62 6c   SqlProc_Variabl
2930: 65 4e 20 28 53 71 6c 50 72 6f 63 5f 46 72 6f 6d  eN (SqlProc_From
2940: 54 65 78 74 28 27 53 45 4c 45 43 54 20 40 63 6f  Text('SELECT @co
2950: 6c 40 20 46 52 4f 4d 20 40 74 62 6c 40 27 29 2c  l@ FROM @tbl@'),
2960: 20 31 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 40 74 62   1);..-----..@tb
2970: 6c 40 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 71 6c  l@....SELECT Sql
2980: 50 72 6f 63 5f 41 6c 6c 56 61 72 69 61 62 6c 65  Proc_AllVariable
2990: 73 20 28 53 71 6c 50 72 6f 63 5f 46 72 6f 6d 54  s (SqlProc_FromT
29a0: 65 78 74 28 27 53 45 4c 45 43 54 20 40 63 6f 6c  ext('SELECT @col
29b0: 40 20 46 52 4f 4d 20 40 74 62 6c 40 27 29 20 29  @ FROM @tbl@') )
29c0: 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 40 63 6f 6c 40 20  ;..-----..@col@ 
29d0: 40 74 62 6c 40 0d 0a 3c 2f 76 65 72 62 61 74 69  @tbl@..</verbati
29e0: 6d 3e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 79 6f  m>..<ul>..<li>yo
29f0: 75 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 71 6c  u can use <b>Sql
2a00: 50 72 6f 63 5f 4e 75 6d 56 61 72 69 61 62 6c 65  Proc_NumVariable
2a10: 73 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74  s</b> in order t
2a20: 6f 20 63 68 65 63 6b 20 68 6f 77 20 6d 61 6e 79  o check how many
2a30: 20 56 61 72 69 61 62 6c 65 73 20 61 72 65 20 64   Variables are d
2a40: 65 66 69 6e 65 64 20 62 79 20 61 20 53 51 4c 20  efined by a SQL 
2a50: 50 72 6f 63 65 64 75 72 65 20 42 4c 4f 42 20 4f  Procedure BLOB O
2a60: 62 6a 65 63 74 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  bject.</li>..<li
2a70: 3e 61 6e 64 20 79 6f 75 20 63 61 6e 20 75 73 65  >and you can use
2a80: 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 56 61 72 69   <b>SqlProc_Vari
2a90: 61 62 6c 65 4e 3c 2f 62 3e 20 69 6e 20 6f 72 64  ableN</b> in ord
2aa0: 65 72 20 74 6f 20 72 65 74 72 69 65 76 65 20 61  er to retrieve a
2ab0: 20 56 61 72 69 61 62 6c 65 20 4e 61 6d 65 20 62   Variable Name b
2ac0: 79 20 73 70 65 63 69 66 79 69 6e 67 20 69 74 73  y specifying its
2ad0: 20 72 65 6c 61 74 69 76 65 20 3c 62 3e 49 6e 64   relative <b>Ind
2ae0: 65 78 3c 2f 62 3e 20 28 46 69 72 73 74 20 56 61  ex</b> (First Va
2af0: 72 69 61 62 6c 65 20 61 6c 77 61 79 73 20 63 6f  riable always co
2b00: 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 3c 62 3e  rresponds to <b>
2b10: 49 6e 64 65 78 3d 30 3c 2f 62 3e 29 2e 3c 2f 6c  Index=0</b>).</l
2b20: 69 3e 0d 0a 3c 6c 69 3e 61 6e 64 20 66 69 6e 61  i>..<li>and fina
2b30: 6c 6c 79 20 79 6f 75 20 63 61 6e 20 75 73 65 20  lly you can use 
2b40: 3c 62 3e 53 71 6c 50 72 6f 63 5f 41 6c 6c 56 61  <b>SqlProc_AllVa
2b50: 72 69 61 62 6c 65 73 3c 2f 62 3e 20 69 6e 20 6f  riables</b> in o
2b60: 72 64 65 72 20 74 6f 20 64 69 72 65 63 74 6c 79  rder to directly
2b70: 20 67 65 74 20 61 6c 6c 20 56 61 72 69 61 62 6c   get all Variabl
2b80: 65 20 4e 61 6d 65 73 20 66 6f 72 6d 61 74 74 65  e Names formatte
2b90: 64 20 61 73 20 61 20 73 70 61 63 65 2d 73 65 70  d as a space-sep
2ba0: 61 72 61 74 65 64 20 6c 69 73 74 2e 3c 2f 6c 69  arated list.</li
2bb0: 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 62 72 3e 3c 68  >..</ul>..<br><h
2bc0: 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d  r>..</li>..<li>.
2bd0: 0a 3c 68 34 3e 45 72 72 6f 72 20 68 61 6e 64 6c  .<h4>Error handl
2be0: 69 6e 67 3c 2f 68 34 3e 0d 0a 3c 76 65 72 62 61  ing</h4>..<verba
2bf0: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 71 6c  tim>..SELECT Sql
2c00: 50 72 6f 63 5f 47 65 74 4c 61 73 74 45 72 72 6f  Proc_GetLastErro
2c10: 72 28 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d  r();..</verbatim
2c20: 3e 0d 0a 41 6c 6c 20 74 68 65 73 65 20 66 75 6e  >..All these fun
2c30: 63 74 69 6f 6e 73 20 77 69 6c 6c 20 72 61 69 73  ctions will rais
2c40: 65 20 61 6e 20 45 78 63 65 70 74 69 6f 6e 20 6f  e an Exception o
2c50: 6e 20 69 6e 76 61 6c 69 64 20 61 72 67 75 6d 65  n invalid argume
2c60: 6e 74 73 20 6f 72 20 65 72 72 6f 72 73 2e 3c 62  nts or errors.<b
2c70: 72 3e 0d 0a 42 79 20 63 61 6c 6c 69 6e 67 20 3c  r>..By calling <
2c80: 62 3e 53 71 6c 50 72 6f 63 5f 47 65 74 4c 61 73  b>SqlProc_GetLas
2c90: 74 45 72 72 6f 72 3c 2f 62 3e 20 79 6f 75 27 6c  tError</b> you'l
2ca0: 6c 20 75 73 75 61 6c 6c 79 20 67 65 74 20 61 20  l usually get a 
2cb0: 6d 6f 72 65 20 64 65 74 61 69 6c 65 64 20 65 78  more detailed ex
2cc0: 70 6c 61 6e 61 74 69 6f 6e 20 61 62 6f 75 74 20  planation about 
2cd0: 74 68 65 20 73 70 65 63 69 66 69 63 20 63 61 75  the specific cau
2ce0: 73 65 20 61 63 63 6f 75 6e 74 69 6e 67 20 66 6f  se accounting fo
2cf0: 72 20 74 68 65 20 66 61 69 6c 75 72 65 2e 0d 0a  r the failure...
2d00: 3c 62 72 3e 3c 62 72 3e 3c 68 72 3e 0d 0a 3c 2f  <br><br><hr>..</
2d10: 6c 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 43  li>..<li>..<h4>C
2d20: 72 65 61 74 69 6e 67 20 56 61 72 69 61 62 6c 65  reating Variable
2d30: 73 20 77 69 74 68 20 56 61 6c 75 65 73 3c 2f 68  s with Values</h
2d40: 34 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  4>..<verbatim>..
2d50: 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 56  SELECT SqlProc_V
2d60: 61 72 56 61 6c 75 65 20 28 27 76 61 72 27 2c 20  arValue ('var', 
2d70: 4e 55 4c 4c 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 40  NULL);..-----..@
2d80: 76 61 72 40 3d 4e 55 4c 4c 0d 0a 0d 0a 53 45 4c  var@=NULL....SEL
2d90: 45 43 54 20 53 71 6c 50 72 6f 63 5f 56 61 72 56  ECT SqlProc_VarV
2da0: 61 6c 75 65 20 28 27 76 61 72 27 2c 20 31 29 3b  alue ('var', 1);
2db0: 0d 0a 2d 2d 2d 2d 2d 0d 0a 40 76 61 72 40 3d 31  ..-----..@var@=1
2dc0: 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72  ....SELECT SqlPr
2dd0: 6f 63 5f 56 61 72 56 61 6c 75 65 20 28 27 76 61  oc_VarValue ('va
2de0: 72 27 2c 20 31 30 2e 35 29 3b 0d 0a 2d 2d 2d 2d  r', 10.5);..----
2df0: 2d 0d 0a 40 76 61 72 40 3d 31 30 2e 35 30 30 30  -..@var@=10.5000
2e00: 30 30 30 30 30 30 0d 0a 0d 0a 53 45 4c 45 43 54  000000....SELECT
2e10: 20 53 71 6c 50 72 6f 63 5f 56 61 72 56 61 6c 75   SqlProc_VarValu
2e20: 65 20 28 27 76 61 72 27 2c 20 27 61 6c 70 68 61  e ('var', 'alpha
2e30: 20 62 65 74 61 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d   beta');..-----.
2e40: 0a 40 76 61 72 40 3d 61 6c 70 68 61 20 62 65 74  .@var@=alpha bet
2e50: 61 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50  a....SELECT SqlP
2e60: 72 6f 63 5f 56 61 72 56 61 6c 75 65 20 28 27 76  roc_VarValue ('v
2e70: 61 72 27 2c 20 4d 61 6b 65 50 6f 69 6e 74 28 31  ar', MakePoint(1
2e80: 31 2e 35 2c 20 34 32 2e 35 2c 20 34 33 32 36 29  1.5, 42.5, 4326)
2e90: 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 40 76 61 72   );..-----..@var
2ea0: 40 3d 78 27 30 30 30 31 45 36 31 30 30 30 30 30  @=x'0001E6100000
2eb0: 30 30 30 30 30 30 30 30 30 30 30 30 32 37 34 30  0000000000002740
2ec0: 30 30 30 30 30 30 30 30 30 30 34 30 34 35 34 30  0000000000404540
2ed0: 30 30 30 30 30 30 30 30 30 30 30 30 32 37 34 30  0000000000002740
2ee0: 30 30 30 30 30 30 30 30 30 30 34 30 34 35 34 30  0000000000404540
2ef0: 37 43 30 31 30 30 30 30 30 30 30 30 30 30 30 30  7C01000000000000
2f00: 30 30 30 30 30 30 32 37 34 30 30 30 30 30 30 30  0000002740000000
2f10: 30 30 30 30 34 30 34 35 34 30 46 45 27 0d 0a 3c  0000404540FE'..<
2f20: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 75 3e 4e  /verbatim>..<u>N
2f30: 6f 74 65 3c 2f 75 3e 3a 20 68 61 6e 64 20 77 72  ote</u>: hand wr
2f40: 69 74 69 6e 67 20 56 61 72 69 61 62 6c 65 20 77  iting Variable w
2f50: 69 74 68 20 56 61 6c 75 65 20 73 74 72 69 6e 67  ith Value string
2f60: 73 20 69 73 20 61 20 72 61 74 68 65 72 20 74 72  s is a rather tr
2f70: 69 76 69 61 6c 20 6f 70 65 72 61 74 69 6f 6e 2c  ivial operation,
2f80: 20 73 6f 20 63 61 6c 6c 69 6e 67 20 74 68 69 73   so calling this
2f90: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 69 73   SQL function is
2fa0: 20 6f 66 74 65 6e 20 6b 69 6e 64 20 6f 66 20 61   often kind of a
2fb0: 6e 20 6f 76 65 72 6b 69 6c 6c 2e 20 45 78 63 65  n overkill. Exce
2fc0: 70 74 2c 20 6d 61 79 20 62 65 2c 20 69 6e 20 74  pt, may be, in t
2fd0: 68 65 20 63 61 73 65 20 6f 66 20 42 4c 4f 42 20  he case of BLOB 
2fe0: 76 61 6c 75 65 73 2e 0d 0a 3c 62 72 3e 3c 62 72  values...<br><br
2ff0: 3e 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c  ><hr>..</li>..<l
3000: 69 3e 0d 0a 3c 68 34 3e 52 61 77 20 61 6e 64 20  i>..<h4>Raw and 
3010: 43 6f 6f 6b 65 64 20 53 51 4c 20 2d 20 72 65 70  Cooked SQL - rep
3020: 6c 61 63 69 6e 67 20 53 79 6d 62 6f 6c 73 20 77  lacing Symbols w
3030: 69 74 68 20 74 68 65 69 72 20 61 63 74 75 61 6c  ith their actual
3040: 20 56 61 6c 75 65 73 3c 2f 68 34 3e 0d 0a 3c 76   Values</h4>..<v
3050: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54  erbatim>..SELECT
3060: 20 53 71 6c 50 72 6f 63 5f 52 61 77 53 51 4c 20   SqlProc_RawSQL 
3070: 28 20 53 71 6c 50 72 6f 63 5f 46 72 6f 6d 54 65  ( SqlProc_FromTe
3080: 78 74 28 27 53 45 4c 45 43 54 20 40 63 6f 6c 40  xt('SELECT @col@
3090: 20 46 52 4f 4d 20 40 74 62 6c 40 3b 27 29 20 29   FROM @tbl@;') )
30a0: 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 53 45 4c 45 43 54  ;..-----..SELECT
30b0: 20 40 63 6f 6c 40 20 46 52 4f 4d 20 40 74 62 6c   @col@ FROM @tbl
30c0: 40 3b 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 71 6c  @;....SELECT Sql
30d0: 50 72 6f 63 5f 43 6f 6f 6b 65 64 53 51 4c 20 28  Proc_CookedSQL (
30e0: 20 53 71 6c 50 72 6f 63 5f 46 72 6f 6d 54 65 78   SqlProc_FromTex
30f0: 74 28 27 53 45 4c 45 43 54 20 40 63 6f 6c 40 20  t('SELECT @col@ 
3100: 46 52 4f 4d 20 40 74 62 6c 40 3b 27 29 2c 0d 0a  FROM @tbl@;'),..
3110: 20 20 20 20 27 40 63 6f 6c 40 3d 66 69 72 73 74      '@col@=first
3120: 5f 6e 61 6d 65 27 2c 0d 0a 20 20 20 20 27 40 74  _name',..    '@t
3130: 62 6c 40 3d 70 68 6f 6e 65 5f 62 6f 6f 6b 27 20  bl@=phone_book' 
3140: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 53 45 4c 45 43  );..-----..SELEC
3150: 54 20 66 69 72 73 74 5f 6e 61 6d 65 20 46 52 4f  T first_name FRO
3160: 4d 20 70 68 6f 6e 65 5f 62 6f 6f 6b 3b 0d 0a 3c  M phone_book;..<
3170: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 75 6c 3e  /verbatim>..<ul>
3180: 0d 0a 3c 6c 69 3e 79 6f 75 20 63 61 6e 20 75 73  ..<li>you can us
3190: 65 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 52 61 77  e <b>SqlProc_Raw
31a0: 53 51 4c 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72  SQL</b> in order
31b0: 20 74 6f 20 64 69 72 65 63 74 6c 79 20 63 68 65   to directly che
31c0: 63 6b 20 74 68 65 20 53 51 4c 20 42 6f 64 79 20  ck the SQL Body 
31d0: 65 6e 63 61 70 73 75 6c 61 74 65 64 20 69 6e 74  encapsulated int
31e0: 6f 20 61 20 53 51 4c 20 50 72 6f 63 65 64 75 72  o a SQL Procedur
31f0: 65 20 42 4c 4f 42 20 4f 62 6a 65 63 74 3b 20 61  e BLOB Object; a
3200: 6c 6c 20 69 6e 69 74 69 61 6c 20 56 61 72 69 61  ll initial Varia
3210: 62 6c 65 20 64 65 66 69 6e 69 74 69 6f 6e 73 20  ble definitions 
3220: 77 69 6c 6c 20 62 65 20 63 61 72 65 66 75 6c 6c  will be carefull
3230: 79 20 70 72 65 73 65 72 76 65 64 2e 3c 2f 6c 69  y preserved.</li
3240: 3e 0d 0a 3c 6c 69 3e 61 6e 64 20 79 6f 75 20 63  >..<li>and you c
3250: 61 6e 20 75 73 65 20 3c 62 3e 53 71 6c 50 72 6f  an use <b>SqlPro
3260: 63 5f 43 6f 6f 6b 65 64 53 51 4c 3c 2f 62 3e 20  c_CookedSQL</b> 
3270: 69 6e 20 6f 72 64 65 72 20 74 6f 20 64 69 72 65  in order to dire
3280: 63 74 6c 79 20 63 68 65 63 6b 20 74 68 65 20 53  ctly check the S
3290: 51 4c 20 42 6f 64 79 20 61 73 20 69 74 20 61 63  QL Body as it ac
32a0: 74 75 61 6c 6c 79 20 61 70 70 65 61 72 73 20 61  tually appears a
32b0: 66 74 65 72 20 72 65 70 6c 61 63 69 6e 67 20 61  fter replacing a
32c0: 6c 6c 20 72 65 71 75 69 72 65 64 20 56 61 72 69  ll required Vari
32d0: 61 62 6c 65 20 56 61 6c 75 65 73 2e 3c 2f 6c 69  able Values.</li
32e0: 3e 0d 0a 3c 6c 69 3e 42 6f 74 68 20 66 75 6e 63  >..<li>Both func
32f0: 74 69 6f 6e 73 20 61 72 65 20 6d 61 69 6e 6c 79  tions are mainly
3300: 20 69 6e 74 65 6e 64 65 64 20 66 6f 72 20 73 75   intended for su
3310: 70 70 6f 72 74 69 6e 67 20 64 65 62 75 67 67 69  pporting debuggi
3320: 6e 67 20 61 63 74 69 76 69 74 69 65 73 2c 20 73  ng activities, s
3330: 6f 20 74 6f 20 6d 61 6b 65 20 61 73 20 65 61 73  o to make as eas
3340: 79 20 61 73 20 70 6f 73 73 69 62 6c 65 20 69 64  y as possible id
3350: 65 6e 74 69 66 79 69 6e 67 20 65 76 65 6e 74 75  entifying eventu
3360: 61 6c 20 65 72 72 6f 72 73 2e 3c 2f 6c 69 3e 0d  al errors.</li>.
3370: 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d 0a 3c 74 61 62  .</ul><br>..<tab
3380: 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 66 38 66  le bgcolor="#f8f
3390: 38 64 38 22 20 63 65 6c 6c 70 61 64 64 69 6e 67  8d8" cellpadding
33a0: 3d 22 36 22 20 63 65 6c 6c 73 70 61 63 69 6e 67  ="6" cellspacing
33b0: 3d 22 38 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 3c  ="8"><tr><td>..<
33c0: 75 3e 4e 6f 74 65 3c 2f 75 3e 3a 20 3c 62 3e 53  u>Note</u>: <b>S
33d0: 71 6c 50 72 6f 63 5f 43 6f 6f 6b 65 64 53 51 4c  qlProc_CookedSQL
33e0: 3c 2f 62 3e 20 77 69 6c 6c 20 61 63 63 65 70 74  </b> will accept
33f0: 20 61 6e 20 61 72 62 69 74 72 61 72 79 20 6c 69   an arbitrary li
3400: 73 74 20 6f 66 20 3c 62 3e 56 61 72 69 61 62 6c  st of <b>Variabl
3410: 65 20 77 69 74 68 20 56 61 6c 75 65 3c 2f 62 3e  e with Value</b>
3420: 20 61 72 67 75 6d 65 6e 74 73 2e 0d 0a 3c 75 6c   arguments...<ul
3430: 3e 0d 0a 3c 6c 69 3e 61 6e 20 65 6d 70 74 79 20  >..<li>an empty 
3440: 6c 69 73 74 20 28 6e 6f 20 56 61 72 69 61 62 6c  list (no Variabl
3450: 65 73 20 77 69 74 68 20 56 61 6c 75 65 73 20 61  es with Values a
3460: 74 20 61 6c 6c 29 20 69 73 20 61 20 70 65 72 66  t all) is a perf
3470: 65 63 74 6c 79 20 6c 65 67 61 6c 20 63 6f 6e 64  ectly legal cond
3480: 69 74 69 6f 6e 20 28 63 6f 75 6c 64 20 65 76 65  ition (could eve
3490: 6e 74 75 61 6c 6c 79 20 6c 65 61 64 20 74 6f 20  ntually lead to 
34a0: 61 6e 20 69 6e 76 61 6c 69 64 20 43 6f 6f 6b 65  an invalid Cooke
34b0: 64 20 53 51 4c 20 42 6f 64 79 2c 20 73 65 65 20  d SQL Body, see 
34c0: 62 65 6c 6f 77 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c  below).</li>..<l
34d0: 69 3e 61 6c 6c 20 61 72 67 75 6d 65 6e 74 73 20  i>all arguments 
34e0: 66 72 6f 6d 20 74 68 65 20 73 65 63 6f 6e 64 20  from the second 
34f0: 74 69 6c 6c 20 74 68 65 20 6c 61 73 74 20 61 72  till the last ar
3500: 65 20 65 78 70 65 63 74 65 64 20 74 6f 20 62 65  e expected to be
3510: 20 77 65 6c 6c 2d 66 6f 72 6d 65 64 20 56 61 72   well-formed Var
3520: 69 61 62 6c 65 73 20 77 69 74 68 20 56 61 6c 75  iables with Valu
3530: 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 79 6f  es.</li>..<li>yo
3540: 75 20 63 61 6e 20 64 65 66 69 6e 65 20 75 70 20  u can define up 
3550: 74 6f 20 3c 62 3e 31 36 3c 2f 62 3e 20 64 69 66  to <b>16</b> dif
3560: 66 65 72 65 6e 74 20 56 61 72 69 61 62 6c 65 73  ferent Variables
3570: 20 77 69 74 68 20 56 61 6c 75 65 73 2e 3c 2f 6c   with Values.</l
3580: 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 61 74 74 65  i>..<li>any atte
3590: 6d 70 74 20 74 6f 20 72 65 2d 64 65 66 69 6e 65  mpt to re-define
35a0: 20 74 68 65 20 73 61 6d 65 20 56 61 72 69 61 62   the same Variab
35b0: 6c 65 20 77 69 74 68 20 61 6e 6f 74 68 65 72 20  le with another 
35c0: 56 61 6c 75 65 20 77 69 6c 6c 20 62 65 20 61 6c  Value will be al
35d0: 77 61 79 73 20 63 6f 6e 73 69 64 65 72 65 64 20  ways considered 
35e0: 61 73 20 61 20 66 61 74 61 6c 20 65 72 72 6f 72  as a fatal error
35f0: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20  .</li>..<li>any 
3600: 6f 66 20 74 68 65 20 56 61 72 69 61 62 6c 65 20  of the Variable 
3610: 61 72 67 75 6d 65 6e 74 73 20 6e 6f 74 20 63 6f  arguments not co
3620: 6e 74 61 69 6e 65 64 20 69 6e 20 74 68 65 20 3c  ntained in the <
3630: 69 3e 72 61 77 3c 2f 69 3e 20 53 51 4c 20 42 6f  i>raw</i> SQL Bo
3640: 64 79 20 77 69 6c 6c 20 62 65 20 69 67 6e 6f 72  dy will be ignor
3650: 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 69 66  ed.</li>..<li>if
3660: 20 61 20 56 61 72 69 61 62 6c 65 20 64 65 66 69   a Variable defi
3670: 6e 65 64 20 69 6e 20 74 68 65 20 72 61 77 20 53  ned in the raw S
3680: 51 4c 20 42 6f 64 79 20 64 6f 65 73 20 6e 6f 74  QL Body does not
3690: 20 6d 61 74 63 68 65 73 20 61 20 63 6f 72 72 65   matches a corre
36a0: 73 70 6f 6e 64 69 6e 67 20 56 61 72 69 61 62 6c  sponding Variabl
36b0: 65 20 61 72 67 75 6d 65 6e 74 20 74 68 65 6e 20  e argument then 
36c0: 69 74 20 77 69 6c 6c 20 62 65 20 73 65 74 20 77  it will be set w
36d0: 69 74 68 20 61 20 27 3c 62 3e 4e 55 4c 4c 3c 2f  ith a '<b>NULL</
36e0: 62 3e 27 20 73 74 72 69 6e 67 2e 3c 2f 6c 69 3e  b>' string.</li>
36f0: 0d 0a 3c 6c 69 3e 74 68 65 20 73 61 6d 65 20 69  ..<li>the same i
3700: 64 65 6e 74 69 63 61 6c 20 72 75 6c 65 73 20 66  dentical rules f
3710: 6f 72 20 70 61 73 73 69 6e 67 20 56 61 72 69 61  or passing Varia
3720: 62 6c 65 2d 56 61 6c 75 65 20 61 72 67 75 6d 65  ble-Value argume
3730: 6e 74 73 20 61 70 70 6c 79 20 74 6f 20 3c 62 3e  nts apply to <b>
3740: 53 71 6c 50 72 6f 63 5f 43 6f 6f 6b 65 64 53 51  SqlProc_CookedSQ
3750: 4c 3c 2f 62 3e 2c 20 3c 62 3e 53 71 6c 50 72 6f  L</b>, <b>SqlPro
3760: 63 5f 45 78 65 63 75 74 65 3c 2f 62 3e 20 61 6e  c_Execute</b> an
3770: 64 20 3c 62 3e 53 74 6f 72 65 64 50 72 6f 63 5f  d <b>StoredProc_
3780: 45 78 65 63 75 74 65 3c 2f 62 3e 2e 3c 2f 6c 69  Execute</b>.</li
3790: 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 2f 74 64 3e 3c  >..</ul>..</td><
37a0: 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 62  /tr></table>..<b
37b0: 72 3e 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c  r><hr>..</li>..<
37c0: 6c 69 3e 0d 0a 3c 68 34 3e 45 78 65 63 75 74 69  li>..<h4>Executi
37d0: 6e 67 20 61 20 53 51 4c 20 50 72 6f 63 65 64 75  ng a SQL Procedu
37e0: 72 65 3c 2f 68 34 3e 0d 0a 3c 76 65 72 62 61 74  re</h4>..<verbat
37f0: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50  im>..SELECT SqlP
3800: 72 6f 63 5f 45 78 65 63 75 74 65 20 28 53 71 6c  roc_Execute (Sql
3810: 50 72 6f 63 5f 46 72 6f 6d 54 65 78 74 28 27 53  Proc_FromText('S
3820: 45 4c 45 43 54 20 40 63 6f 6c 40 20 46 52 4f 4d  ELECT @col@ FROM
3830: 20 40 74 62 6c 40 3b 27 29 2c 0d 0a 20 20 20 20   @tbl@;'),..    
3840: 27 40 63 6f 6c 40 3d 66 69 72 73 74 5f 6e 61 6d  '@col@=first_nam
3850: 65 27 2c 0d 0a 20 20 20 20 27 40 74 62 6c 40 3d  e',..    '@tbl@=
3860: 70 68 6f 6e 65 5f 62 6f 6f 6b 27 20 29 3b 0d 0a  phone_book' );..
3870: 2d 2d 2d 2d 2d 0d 0a 53 71 6c 50 72 6f 63 20 65  -----..SqlProc e
3880: 78 63 65 70 74 69 6f 6e 20 2d 20 61 20 66 61 74  xception - a fat
3890: 61 6c 20 53 51 4c 20 65 72 72 6f 72 20 77 61 73  al SQL error was
38a0: 20 65 6e 63 6f 75 6e 74 65 72 65 64 2e 0d 0a 0d   encountered....
38b0: 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f  .SELECT SqlProc_
38c0: 47 65 74 4c 61 73 74 45 72 72 6f 72 28 29 3b 0d  GetLastError();.
38d0: 0a 2d 2d 2d 2d 2d 0d 0a 67 61 69 61 5f 73 71 6c  .-----..gaia_sql
38e0: 5f 70 72 6f 63 5f 65 78 65 63 75 74 65 3a 20 6e  _proc_execute: n
38f0: 6f 20 73 75 63 68 20 74 61 62 6c 65 3a 20 70 68  o such table: ph
3900: 6f 6e 65 5f 62 6f 6f 6b 0d 0a 3c 2f 76 65 72 62  one_book..</verb
3910: 61 74 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 75  atim>..you can u
3920: 73 65 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 45 78  se <b>SqlProc_Ex
3930: 65 63 75 74 65 3c 2f 62 3e 20 69 6e 20 6f 72 64  ecute</b> in ord
3940: 65 72 20 74 6f 20 64 69 72 65 63 74 6c 79 20 65  er to directly e
3950: 78 65 63 75 74 65 20 74 68 65 20 77 68 6f 6c 65  xecute the whole
3960: 20 53 51 4c 20 42 6f 64 79 20 61 73 20 61 20 73   SQL Body as a s
3970: 69 6e 67 6c 65 20 6d 6f 6e 6f 6c 69 74 68 69 63  ingle monolithic
3980: 20 75 6e 69 74 2e 3c 62 72 3e 0d 0a 41 74 20 74   unit.<br>..At t
3990: 68 65 20 65 6e 64 20 6f 66 20 74 68 65 20 70 72  he end of the pr
39a0: 6f 63 65 73 73 20 3c 62 3e 31 3c 2f 62 3e 20 28  ocess <b>1</b> (
39b0: 61 6b 61 20 3c 62 3e 54 72 75 65 3c 2f 62 3e 29  aka <b>True</b>)
39c0: 20 77 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65   will be returne
39d0: 64 20 6f 6e 20 66 75 6c 6c 20 73 75 63 63 65 73  d on full succes
39e0: 73 3b 20 61 6e 20 45 78 63 65 70 74 69 6f 6e 20  s; an Exception 
39f0: 77 69 6c 6c 20 62 65 20 72 61 69 73 65 64 20 6f  will be raised o
3a00: 6e 20 66 61 69 6c 75 72 65 2c 20 61 73 20 77 69  n failure, as wi
3a10: 6c 6c 20 68 61 70 70 65 6e 73 20 69 6e 20 74 68  ll happens in th
3a20: 69 73 20 73 61 6d 70 6c 65 2c 20 79 6f 75 20 63  is sample, you c
3a30: 61 6e 20 74 68 65 6e 20 75 73 65 20 3c 62 3e 53  an then use <b>S
3a40: 71 6c 50 72 6f 63 5f 47 65 74 4c 61 73 74 45 72  qlProc_GetLastEr
3a50: 72 6f 72 3c 2f 62 3e 20 74 6f 20 72 65 74 72 69  ror</b> to retri
3a60: 65 76 65 20 74 68 65 20 63 6f 72 72 65 73 70 6f  eve the correspo
3a70: 6e 64 69 6e 67 20 53 51 4c 20 65 72 72 6f 72 20  nding SQL error 
3a80: 6d 65 73 73 61 67 65 2e 0d 0a 3c 62 72 3e 3c 62  message...<br><b
3a90: 72 3e 0d 0a 3c 74 61 62 6c 65 20 62 67 63 6f 6c  r>..<table bgcol
3aa0: 6f 72 3d 22 23 66 38 66 38 64 38 22 20 63 65 6c  or="#f8f8d8" cel
3ab0: 6c 70 61 64 64 69 6e 67 3d 22 36 22 20 63 65 6c  lpadding="6" cel
3ac0: 6c 73 70 61 63 69 6e 67 3d 22 38 22 3e 3c 74 72  lspacing="8"><tr
3ad0: 3e 3c 74 64 3e 0d 0a 3c 75 3e 4e 6f 74 65 3c 2f  ><td>..<u>Note</
3ae0: 75 3e 3a 20 61 6c 6c 20 3c 62 3e 44 6f 74 20 4d  u>: all <b>Dot M
3af0: 61 63 72 6f 73 3c 2f 62 3e 20 66 6f 75 6e 64 20  acros</b> found 
3b00: 77 69 74 68 69 6e 20 74 68 65 20 53 51 4c 20 42  within the SQL B
3b10: 6f 64 79 20 62 65 69 6e 67 20 65 78 65 63 75 74  ody being execut
3b20: 65 64 20 77 69 6c 6c 20 61 6c 77 61 79 73 20 62  ed will always b
3b30: 65 20 69 67 6e 6f 72 65 64 2e 3c 62 72 3e 0d 0a  e ignored.<br>..
3b40: 54 68 65 20 73 61 6d 65 20 72 75 6c 65 20 61 70  The same rule ap
3b50: 70 6c 69 65 73 20 74 6f 20 3c 62 3e 53 74 6f 72  plies to <b>Stor
3b60: 65 64 50 72 6f 63 5f 45 78 65 63 75 74 65 3c 2f  edProc_Execute</
3b70: 62 3e 20 61 73 20 77 65 6c 6c 2e 3c 2f 62 3e 0d  b> as well.</b>.
3b80: 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62  .</td></tr></tab
3b90: 6c 65 3e 0d 0a 3c 62 72 3e 3c 68 72 3e 0d 0a 3c  le>..<br><hr>..<
3ba0: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e  /li>..<li>..<h4>
3bb0: 48 61 6e 64 6c 69 6e 67 20 53 51 4c 20 53 74 6f  Handling SQL Sto
3bc0: 72 65 64 20 50 72 6f 63 65 64 75 72 65 73 3c 2f  red Procedures</
3bd0: 68 34 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d  h4>..<verbatim>.
3be0: 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50 72  .SELECT StoredPr
3bf0: 6f 63 5f 43 72 65 61 74 65 54 61 62 6c 65 73 28  oc_CreateTables(
3c00: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f  );..-----..1..</
3c10: 76 65 72 62 61 74 69 6d 3e 0d 0a 79 6f 75 20 63  verbatim>..you c
3c20: 61 6e 20 75 73 65 20 3c 62 3e 53 74 6f 72 65 64  an use <b>Stored
3c30: 50 72 6f 63 5f 43 72 65 61 74 65 54 61 62 6c 65  Proc_CreateTable
3c40: 73 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74  s</b> in order t
3c50: 6f 20 63 72 65 61 74 65 2c 20 77 69 74 68 69 6e  o create, within
3c60: 20 79 6f 75 72 20 63 75 72 72 65 6e 74 6c 79 20   your currently 
3c70: 63 6f 6e 6e 65 63 74 65 64 20 64 61 74 61 62 61  connected databa
3c80: 73 65 2c 20 61 6c 6c 20 3c 62 3e 6d 65 74 61 74  se, all <b>metat
3c90: 61 62 6c 65 73 3c 2f 62 3e 20 72 65 71 75 69 72  ables</b> requir
3ca0: 65 64 20 74 6f 20 70 65 72 6d 61 6e 65 6e 74 6c  ed to permanentl
3cb0: 79 20 72 65 67 69 73 74 65 72 20 53 74 6f 72 65  y register Store
3cc0: 64 20 50 72 6f 63 65 64 75 72 65 73 20 61 6e 64  d Procedures and
3cd0: 20 53 74 6f 72 65 64 20 56 61 72 69 61 62 6c 65   Stored Variable
3ce0: 73 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 74 61 62  s.<br><br>..<tab
3cf0: 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 66 38 66  le bgcolor="#f8f
3d00: 38 64 38 22 20 63 65 6c 6c 70 61 64 64 69 6e 67  8d8" cellpadding
3d10: 3d 22 36 22 20 63 65 6c 6c 73 70 61 63 69 6e 67  ="6" cellspacing
3d20: 3d 22 38 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 3c  ="8"><tr><td>..<
3d30: 75 3e 4e 6f 74 65 3c 2f 75 3e 3a 20 61 6e 79 20  u>Note</u>: any 
3d40: 6e 65 77 20 64 61 74 61 62 61 73 65 20 63 72 65  new database cre
3d50: 61 74 65 64 20 62 79 20 53 70 61 74 69 61 4c 69  ated by SpatiaLi
3d60: 74 65 20 34 2e 35 2e 30 20 28 61 6e 64 20 73 75  te 4.5.0 (and su
3d70: 62 73 65 71 75 65 6e 74 20 76 65 72 73 69 6f 6e  bsequent version
3d80: 73 29 20 77 69 6c 6c 20 61 75 74 6f 6d 61 74 69  s) will automati
3d90: 63 61 6c 6c 79 20 73 75 70 70 6f 72 74 20 74 68  cally support th
3da0: 65 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75  e Stored Procedu
3db0: 72 65 73 20 6d 65 74 61 74 61 62 6c 65 73 2e 20  res metatables. 
3dc0: 45 78 70 6c 69 63 69 74 6c 79 20 63 61 6c 6c 69  Explicitly calli
3dd0: 6e 67 20 74 68 69 73 20 66 75 6e 63 74 69 6f 6e  ng this function
3de0: 20 69 73 20 6d 61 69 6e 6c 79 20 75 73 65 64 20   is mainly used 
3df0: 69 6e 20 6f 72 64 65 72 20 74 6f 20 61 64 64 20  in order to add 
3e00: 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65  Stored Procedure
3e10: 73 20 73 75 70 70 6f 72 74 20 6f 6e 20 61 6c 72  s support on alr
3e20: 65 61 64 79 20 65 78 69 73 74 69 6e 67 20 64 61  eady existing da
3e30: 74 61 62 61 73 65 73 20 63 72 65 61 74 65 64 20  tabases created 
3e40: 62 79 20 70 72 65 76 69 6f 75 73 20 76 65 72 73  by previous vers
3e50: 69 6f 6e 73 2e 20 43 61 6c 6c 69 6e 67 20 3c 62  ions. Calling <b
3e60: 3e 53 74 6f 72 65 64 50 72 6f 63 5f 43 72 65 61  >StoredProc_Crea
3e70: 74 65 54 61 62 6c 65 73 3c 2f 62 3e 20 6f 6e 20  teTables</b> on 
3e80: 62 65 68 61 6c 66 20 6f 66 20 61 20 64 61 74 61  behalf of a data
3e90: 62 61 73 65 20 61 6c 72 65 61 64 79 20 73 75 70  base already sup
3ea0: 70 6f 72 74 69 6e 67 20 74 68 65 20 53 74 6f 72  porting the Stor
3eb0: 65 64 20 50 72 6f 63 65 64 75 72 65 73 20 6d 65  ed Procedures me
3ec0: 74 61 74 61 62 6c 65 20 69 73 20 61 6e 20 68 61  tatable is an ha
3ed0: 72 6d 6c 65 73 73 20 6f 70 65 72 61 74 69 6f 6e  rmless operation
3ee0: 20 73 69 6d 70 6c 79 20 72 65 74 75 72 6e 69 6e   simply returnin
3ef0: 67 20 3c 62 3e 31 3c 2f 62 3e 20 28 66 75 6c 6c  g <b>1</b> (full
3f00: 20 73 75 63 63 65 73 73 29 2e 0d 0a 3c 2f 74 64   success)...</td
3f10: 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a  ></tr></table>..
3f20: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45  <verbatim>..SELE
3f30: 43 54 20 53 74 6f 72 65 64 50 72 6f 63 5f 52 65  CT StoredProc_Re
3f40: 67 69 73 74 65 72 20 28 20 27 73 70 5f 31 27 2c  gister ( 'sp_1',
3f50: 20 27 61 20 73 61 6d 70 6c 65 20 53 74 6f 72 65   'a sample Store
3f60: 64 20 50 72 6f 63 65 64 75 72 65 20 66 6f 72 20  d Procedure for 
3f70: 74 65 73 74 69 6e 67 27 2c 20 53 71 6c 50 72 6f  testing', SqlPro
3f80: 63 5f 46 72 6f 6d 54 65 78 74 28 27 53 45 4c 45  c_FromText('SELE
3f90: 43 54 20 40 63 6f 6c 40 20 46 52 4f 4d 20 40 74  CT @col@ FROM @t
3fa0: 62 6c 40 3b 27 20 29 29 3b 0d 0a 2d 2d 2d 2d 2d  bl@;' ));..-----
3fb0: 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e  ..1..</verbatim>
3fc0: 0d 0a 79 6f 75 20 63 61 6e 20 75 73 65 20 3c 62  ..you can use <b
3fd0: 3e 53 74 6f 72 65 64 50 72 6f 63 5f 52 65 67 69  >StoredProc_Regi
3fe0: 73 74 65 72 3c 2f 62 3e 20 69 6e 20 6f 72 64 65  ster</b> in orde
3ff0: 72 20 74 6f 20 70 65 72 6d 61 6e 65 6e 74 6c 79  r to permanently
4000: 20 72 65 67 69 73 74 65 72 20 61 20 53 74 6f 72   register a Stor
4010: 65 64 20 50 72 6f 63 65 64 75 72 65 2e 0d 0a 3c  ed Procedure...<
4020: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43  verbatim>..SELEC
4030: 54 20 53 74 6f 72 65 64 50 72 6f 63 5f 44 65 6c  T StoredProc_Del
4040: 65 74 65 20 28 20 27 73 70 5f 31 27 20 29 3b 0d  ete ( 'sp_1' );.
4050: 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72  .-----..1..</ver
4060: 62 61 74 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20  batim>..you can 
4070: 75 73 65 20 3c 62 3e 53 74 6f 72 65 64 50 72 6f  use <b>StoredPro
4080: 63 5f 44 65 6c 65 74 65 3c 2f 62 3e 20 69 6e 20  c_Delete</b> in 
4090: 6f 72 64 65 72 20 74 6f 20 70 65 72 6d 61 6e 65  order to permane
40a0: 6e 74 6c 79 20 72 65 6d 6f 76 65 20 61 20 70 72  ntly remove a pr
40b0: 65 76 69 6f 75 73 6c 79 20 72 65 67 69 73 74 65  eviously registe
40c0: 72 65 64 20 53 74 6f 72 65 64 20 50 72 6f 63 65  red Stored Proce
40d0: 64 75 72 65 2e 0d 0a 3c 76 65 72 62 61 74 69 6d  dure...<verbatim
40e0: 3e 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f  >..SELECT SqlPro
40f0: 63 5f 52 61 77 53 51 4c 20 28 20 53 74 6f 72 65  c_RawSQL ( Store
4100: 64 50 72 6f 63 5f 47 65 74 20 28 20 27 73 70 5f  dProc_Get ( 'sp_
4110: 31 27 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a  1' ) );..-----..
4120: 53 45 4c 45 43 54 20 40 63 6f 6c 40 20 46 52 4f  SELECT @col@ FRO
4130: 4d 20 40 74 62 6c 40 3b 0d 0a 3c 2f 76 65 72 62  M @tbl@;..</verb
4140: 61 74 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 75  atim>..you can u
4150: 73 65 20 3c 62 3e 53 74 6f 72 65 64 50 72 6f 63  se <b>StoredProc
4160: 5f 47 65 74 3c 2f 62 3e 20 69 6e 20 6f 72 64 65  _Get</b> in orde
4170: 72 20 74 6f 20 72 65 74 72 69 65 76 65 20 74 68  r to retrieve th
4180: 65 20 53 51 4c 20 50 72 6f 63 65 64 75 72 65 20  e SQL Procedure 
4190: 42 4c 4f 42 20 4f 62 6a 65 63 74 20 66 72 6f 6d  BLOB Object from
41a0: 20 61 20 72 65 67 69 73 74 65 72 65 64 20 53 74   a registered St
41b0: 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65 2e 0d  ored Procedure..
41c0: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c  .<verbatim>..SEL
41d0: 45 43 54 20 53 74 6f 72 65 64 50 72 6f 63 5f 55  ECT StoredProc_U
41e0: 70 64 61 74 65 54 69 74 6c 65 20 28 20 27 73 70  pdateTitle ( 'sp
41f0: 5f 31 27 2c 20 27 74 68 69 73 20 54 69 74 6c 65  _1', 'this Title
4200: 20 77 61 73 20 63 68 61 6e 67 65 64 27 20 29 3b   was changed' );
4210: 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65  ..-----..1..</ve
4220: 72 62 61 74 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e  rbatim>..you can
4230: 20 75 73 65 20 3c 62 3e 53 74 6f 72 65 64 50 72   use <b>StoredPr
4240: 6f 63 5f 55 70 64 61 74 65 54 69 74 6c 65 3c 2f  oc_UpdateTitle</
4250: 62 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 6d  b> in order to m
4260: 6f 64 69 66 79 20 74 68 65 20 54 69 74 6c 65 20  odify the Title 
4270: 6f 66 20 61 6e 20 61 6c 72 65 61 64 79 20 72 65  of an already re
4280: 67 69 73 74 65 72 65 64 20 53 74 6f 72 65 64 20  gistered Stored 
4290: 50 72 6f 63 65 64 75 72 65 2e 0d 0a 3c 76 65 72  Procedure...<ver
42a0: 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53  batim>..SELECT S
42b0: 74 6f 72 65 64 50 72 6f 63 5f 55 70 64 61 74 65  toredProc_Update
42c0: 53 71 6c 42 6f 64 79 20 28 20 27 73 70 5f 31 27  SqlBody ( 'sp_1'
42d0: 2c 20 53 71 6c 50 72 6f 63 5f 46 72 6f 6d 46 69  , SqlProc_FromFi
42e0: 6c 65 28 27 2f 68 6f 6d 65 2f 6a 6f 65 2f 73 71  le('/home/joe/sq
42f0: 6c 5f 73 63 72 69 70 74 73 2f 73 74 6f 72 65 64  l_scripts/stored
4300: 5f 70 72 6f 63 5f 74 65 73 74 5f 76 32 2e 74 78  _proc_test_v2.tx
4310: 74 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d  t' );..-----..1.
4320: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 79 6f  .</verbatim>..yo
4330: 75 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 74 6f  u can use <b>Sto
4340: 72 65 64 50 72 6f 63 5f 55 70 64 61 74 65 53 71  redProc_UpdateSq
4350: 6c 42 6f 64 79 3c 2f 62 3e 20 69 6e 20 6f 72 64  lBody</b> in ord
4360: 65 72 20 74 6f 20 6d 6f 64 69 66 79 20 74 68 65  er to modify the
4370: 20 53 71 6c 20 42 6f 64 79 20 6f 66 20 61 6e 20   Sql Body of an 
4380: 61 6c 72 65 61 64 79 20 72 65 67 69 73 74 65 72  already register
4390: 65 64 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64  ed Stored Proced
43a0: 75 72 65 20 28 65 2e 67 2e 20 62 65 63 61 75 73  ure (e.g. becaus
43b0: 65 20 79 6f 75 27 76 65 20 64 69 73 63 6f 76 65  e you've discove
43c0: 72 65 64 20 61 6e 64 20 66 69 78 65 64 20 73 6f  red and fixed so
43d0: 6d 65 20 62 75 67 20 61 66 66 65 63 74 69 6e 67  me bug affecting
43e0: 20 74 68 65 20 70 72 65 76 69 6f 75 73 20 53 51   the previous SQ
43f0: 4c 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e  L implementation
4400: 29 2e 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45  ).<verbatim>..SE
4410: 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f 63 5f  LECT StoredProc_
4420: 45 78 65 63 75 74 65 20 28 20 27 73 70 5f 31 27  Execute ( 'sp_1'
4430: 2c 0d 0a 20 20 20 20 27 40 63 6f 6c 40 3d 73 72  ,..    '@col@=sr
4440: 69 64 27 2c 0d 0a 20 20 20 20 27 40 74 62 6c 40  id',..    '@tbl@
4450: 3d 73 70 61 74 69 61 6c 5f 72 65 66 5f 73 79 73  =spatial_ref_sys
4460: 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a  ' );..-----..1..
4470: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 61 6e 64  </verbatim>..and
4480: 20 66 69 6e 61 6c 6c 79 20 79 6f 75 20 63 61 6e   finally you can
4490: 20 75 73 65 20 3c 62 3e 53 74 6f 72 65 64 50 72   use <b>StoredPr
44a0: 6f 63 5f 45 78 65 63 75 74 65 3c 2f 62 3e 20 69  oc_Execute</b> i
44b0: 6e 20 6f 72 64 65 72 20 74 6f 20 64 69 72 65 63  n order to direc
44c0: 74 6c 79 20 65 78 65 63 75 74 65 20 61 20 53 74  tly execute a St
44d0: 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65 20 61  ored Procedure a
44e0: 73 20 61 20 73 69 6e 67 6c 65 20 6d 6f 6e 6f 6c  s a single monol
44f0: 69 74 68 69 63 20 75 6e 69 74 2e 3c 62 72 3e 0d  ithic unit.<br>.
4500: 0a 3c 62 72 3e 3c 62 72 3e 3c 68 72 3e 0d 0a 3c  .<br><br><hr>..<
4510: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e  /li>..<li>..<h4>
4520: 48 61 6e 64 6c 69 6e 67 20 53 51 4c 20 53 74 6f  Handling SQL Sto
4530: 72 65 64 20 56 61 72 69 61 62 6c 65 73 3c 2f 68  red Variables</h
4540: 34 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  4>..<verbatim>..
4550: 53 45 4c 45 43 54 20 53 74 6f 72 65 64 56 61 72  SELECT StoredVar
4560: 5f 52 65 67 69 73 74 65 72 20 28 20 27 70 69 27  _Register ( 'pi'
4570: 2c 20 27 61 6e 20 75 6e 69 76 65 72 73 61 6c 6c  , 'an universall
4580: 79 20 75 73 65 66 75 6c 20 63 6f 6e 73 74 61 6e  y useful constan
4590: 74 27 2c 20 27 33 2e 31 34 27 20 29 3b 0d 0a 2d  t', '3.14' );..-
45a0: 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61  ----..1..</verba
45b0: 74 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 75 73  tim>..you can us
45c0: 65 20 3c 62 3e 53 74 6f 72 65 64 56 61 72 5f 52  e <b>StoredVar_R
45d0: 65 67 69 73 74 65 72 3c 2f 62 3e 20 69 6e 20 6f  egister</b> in o
45e0: 72 64 65 72 20 74 6f 20 70 65 72 6d 61 6e 65 6e  rder to permanen
45f0: 74 6c 79 20 72 65 67 69 73 74 65 72 20 61 20 53  tly register a S
4600: 74 6f 72 65 64 20 56 61 72 69 61 62 6c 65 2e 0d  tored Variable..
4610: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c  .<verbatim>..SEL
4620: 45 43 54 20 53 74 6f 72 65 64 56 61 72 5f 44 65  ECT StoredVar_De
4630: 6c 65 74 65 20 28 20 27 70 69 27 20 29 3b 0d 0a  lete ( 'pi' );..
4640: 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62  -----..1..</verb
4650: 61 74 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 75  atim>..you can u
4660: 73 65 20 3c 62 3e 53 74 6f 72 65 64 56 61 72 5f  se <b>StoredVar_
4670: 44 65 6c 65 74 65 3c 2f 62 3e 20 69 6e 20 6f 72  Delete</b> in or
4680: 64 65 72 20 74 6f 20 70 65 72 6d 61 6e 65 6e 74  der to permanent
4690: 6c 79 20 72 65 6d 6f 76 65 20 61 20 70 72 65 76  ly remove a prev
46a0: 69 6f 75 73 6c 79 20 72 65 67 69 73 74 65 72 65  iously registere
46b0: 64 20 53 74 6f 72 65 64 20 56 61 72 69 61 62 6c  d Stored Variabl
46c0: 65 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  e...<verbatim>..
46d0: 53 45 4c 45 43 54 20 53 74 6f 72 65 64 56 61 72  SELECT StoredVar
46e0: 5f 47 65 74 20 28 20 27 70 69 27 20 29 3b 0d 0a  _Get ( 'pi' );..
46f0: 2d 2d 2d 2d 2d 0d 0a 40 50 49 40 3d 33 2e 31 34  -----..@PI@=3.14
4700: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 79  ..</verbatim>..y
4710: 6f 75 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 74  ou can use <b>St
4720: 6f 72 65 64 56 61 72 5f 47 65 74 3c 2f 62 3e 20  oredVar_Get</b> 
4730: 69 6e 20 6f 72 64 65 72 20 74 6f 20 72 65 74 72  in order to retr
4740: 69 65 76 65 20 74 68 65 20 56 61 72 69 61 62 6c  ieve the Variabl
4750: 65 20 77 69 74 68 20 56 61 6c 75 65 20 73 74 72  e with Value str
4760: 69 6e 67 20 66 72 6f 6d 20 61 20 72 65 67 69 73  ing from a regis
4770: 74 65 72 65 64 20 53 74 6f 72 65 64 20 56 61 72  tered Stored Var
4780: 69 61 62 6c 65 2e 0d 0a 3c 76 65 72 62 61 74 69  iable...<verbati
4790: 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65  m>..SELECT Store
47a0: 64 56 61 72 5f 55 70 64 61 74 65 54 69 74 6c 65  dVar_UpdateTitle
47b0: 20 28 20 27 70 69 27 2c 20 27 50 49 20 2d 20 74   ( 'pi', 'PI - t
47c0: 68 65 20 6d 61 67 69 63 20 6e 75 6d 62 65 72 27  he magic number'
47d0: 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c   );..-----..1..<
47e0: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 79 6f 75 20  /verbatim>..you 
47f0: 63 61 6e 20 75 73 65 20 3c 62 3e 53 74 6f 72 65  can use <b>Store
4800: 64 56 61 72 5f 55 70 64 61 74 65 54 69 74 6c 65  dVar_UpdateTitle
4810: 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f  </b> in order to
4820: 20 6d 6f 64 69 66 79 20 74 68 65 20 54 69 74 6c   modify the Titl
4830: 65 20 6f 66 20 61 6e 20 61 6c 72 65 61 64 79 20  e of an already 
4840: 72 65 67 69 73 74 65 72 65 64 20 53 74 6f 72 65  registered Store
4850: 64 20 50 72 6f 63 65 64 75 72 65 2e 0d 0a 3c 76  d Procedure...<v
4860: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54  erbatim>..SELECT
4870: 20 53 74 6f 72 65 64 56 61 72 5f 55 70 64 61 74   StoredVar_Updat
4880: 65 56 61 6c 75 65 20 28 20 27 70 69 27 2c 20 27  eValue ( 'pi', '
4890: 33 2e 31 34 31 35 39 32 36 35 33 35 27 20 29 3b  3.1415926535' );
48a0: 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65  ..-----..1..</ve
48b0: 72 62 61 74 69 6d 3e 0d 0a 61 6e 64 20 66 69 6e  rbatim>..and fin
48c0: 61 6c 6c 79 20 79 6f 75 20 63 61 6e 20 75 73 65  ally you can use
48d0: 20 3c 62 3e 53 74 6f 72 65 64 56 61 72 5f 55 70   <b>StoredVar_Up
48e0: 64 61 74 65 56 61 6c 75 65 3c 2f 62 3e 20 69 6e  dateValue</b> in
48f0: 20 6f 72 64 65 72 20 74 6f 20 6d 6f 64 69 66 79   order to modify
4900: 20 74 68 65 20 56 61 72 69 61 62 6c 65 20 77 69   the Variable wi
4910: 74 68 20 56 61 6c 75 65 20 6f 66 20 61 6e 20 61  th Value of an a
4920: 6c 72 65 61 64 79 20 72 65 67 69 73 74 65 72 65  lready registere
4930: 64 20 53 74 6f 72 65 64 20 56 61 72 69 61 62 6c  d Stored Variabl
4940: 65 2e 0d 0a 3c 2f 6c 69 3e 3c 62 72 3e 3c 68 72  e...</li><br><hr
4950: 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 48 61 6e  >..<li>..<h4>Han
4960: 64 6c 69 6e 67 20 74 68 65 20 53 51 4c 20 4c 6f  dling the SQL Lo
4970: 67 66 69 6c 65 3c 2f 68 34 3e 0d 0a 3c 76 65 72  gfile</h4>..<ver
4980: 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53  batim>..SELECT S
4990: 71 6c 50 72 6f 63 5f 53 65 74 4c 6f 67 66 69 6c  qlProc_SetLogfil
49a0: 65 20 28 20 27 2f 68 6f 6d 65 2f 73 61 6e 64 72  e ( '/home/sandr
49b0: 6f 2f 73 71 6c 5f 6c 6f 67 2e 74 78 74 27 20 29  o/sql_log.txt' )
49c0: 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a 53  ;..-----..1....S
49d0: 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 53 65  ELECT SqlProc_Se
49e0: 74 4c 6f 67 66 69 6c 65 20 28 20 27 2f 68 6f 6d  tLogfile ( '/hom
49f0: 65 2f 73 61 6e 64 72 6f 2f 73 71 6c 5f 6c 6f 67  e/sandro/sql_log
4a00: 2e 74 78 74 27 2c 20 31 29 3b 0d 0a 2d 2d 2d 2d  .txt', 1);..----
4a10: 2d 0d 0a 31 0d 0a 0d 0a 53 45 4c 45 43 54 20 53  -..1....SELECT S
4a20: 71 6c 50 72 6f 63 5f 53 65 74 4c 6f 67 66 69 6c  qlProc_SetLogfil
4a30: 65 20 28 20 4e 55 4c 4c 20 29 3b 0d 0a 2d 2d 2d  e ( NULL );..---
4a40: 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69  --..1..</verbati
4a50: 6d 3e 0d 0a 59 6f 75 20 63 61 6e 20 75 73 65 20  m>..You can use 
4a60: 3c 62 3e 53 71 6c 50 72 6f 63 5f 53 65 74 4c 6f  <b>SqlProc_SetLo
4a70: 67 66 69 6c 65 28 29 3c 2f 62 3e 20 69 6e 20 6f  gfile()</b> in o
4a80: 72 64 65 72 20 74 6f 20 65 6e 61 62 6c 65 20 6f  rder to enable o
4a90: 72 20 64 69 73 61 62 6c 65 20 74 68 65 20 53 51  r disable the SQ
4aa0: 4c 20 4c 6f 67 66 69 6c 65 3a 0d 0a 3c 75 6c 3e  L Logfile:..<ul>
4ab0: 0d 0a 3c 6c 69 3e 74 68 65 20 66 69 72 73 74 20  ..<li>the first 
4ac0: 66 6f 72 6d 20 28 73 69 6e 67 6c 65 20 61 72 67  form (single arg
4ad0: 75 6d 65 6e 74 29 20 6a 75 73 74 20 72 65 71 75  ument) just requ
4ae0: 69 72 65 73 20 74 6f 20 64 65 66 69 6e 65 20 74  ires to define t
4af0: 68 65 20 3c 62 3e 61 62 73 6f 6c 75 74 65 3c 2f  he <b>absolute</
4b00: 62 3e 20 6f 72 20 3c 62 3e 72 65 6c 61 74 69 76  b> or <b>relativ
4b10: 65 20 70 61 74 68 6e 61 6d 65 3c 2f 62 3e 20 6f  e pathname</b> o
4b20: 66 20 74 68 65 20 69 6e 74 65 6e 64 65 64 20 4c  f the intended L
4b30: 6f 67 66 69 6c 65 2e 3c 62 72 3e 0d 0a 41 20 4c  ogfile.<br>..A L
4b40: 6f 67 66 69 6c 65 20 64 65 66 69 6e 65 64 20 69  ogfile defined i
4b50: 6e 20 73 75 63 68 20 61 20 77 61 79 20 77 69 6c  n such a way wil
4b60: 6c 20 61 6c 77 61 79 73 20 6f 70 65 72 61 74 65  l always operate
4b70: 20 69 6e 20 3c 62 3e 54 72 75 6e 63 61 74 65 3c   in <b>Truncate<
4b80: 2f 62 3e 20 6d 6f 64 65 2e 3c 2f 6c 69 3e 0d 0a  /b> mode.</li>..
4b90: 3c 6c 69 3e 74 68 65 20 73 65 63 6f 6e 64 20 66  <li>the second f
4ba0: 6f 72 6d 20 28 74 77 6f 20 61 72 67 75 6d 65 6e  orm (two argumen
4bb0: 74 73 29 20 73 75 70 70 6f 72 74 73 20 61 20 66  ts) supports a f
4bc0: 75 72 74 68 65 72 20 3c 62 3e 6d 6f 64 65 3c 2f  urther <b>mode</
4bd0: 62 3e 20 61 72 67 75 6d 65 6e 74 3a 0d 0a 3c 75  b> argument:..<u
4be0: 6c 3e 0d 0a 3c 6c 69 3e 69 66 20 73 65 74 20 74  l>..<li>if set t
4bf0: 6f 20 3c 62 3e 46 41 4c 53 45 3c 2f 62 3e 20 28  o <b>FALSE</b> (
4c00: 3c 62 3e 30 3c 2f 62 3e 2c 20 64 65 66 61 75 6c  <b>0</b>, defaul
4c10: 74 20 76 61 6c 75 65 29 20 74 68 65 20 4c 6f 67  t value) the Log
4c20: 66 69 6c 65 20 77 69 6c 6c 20 6f 70 65 72 61 74  file will operat
4c30: 65 20 69 6e 20 3c 62 3e 54 72 75 6e 63 61 74 65  e in <b>Truncate
4c40: 3c 2f 62 3e 20 6d 6f 64 65 2e 3c 2f 6c 69 3e 0d  </b> mode.</li>.
4c50: 0a 3c 6c 69 3e 69 66 20 73 65 74 20 74 6f 20 3c  .<li>if set to <
4c60: 62 3e 54 52 55 45 3c 2f 62 3e 20 28 61 6e 79 20  b>TRUE</b> (any 
4c70: 6f 74 68 65 72 20 76 61 6c 75 65 20 64 69 66 66  other value diff
4c80: 65 72 65 6e 74 20 66 72 6f 6d 20 3c 62 3e 30 3c  erent from <b>0<
4c90: 2f 62 3e 29 20 74 68 65 20 4c 6f 67 66 69 6c 65  /b>) the Logfile
4ca0: 20 77 69 6c 6c 20 6f 70 65 72 61 74 65 20 69 6e   will operate in
4cb0: 20 3c 62 3e 41 70 70 65 6e 64 3c 2f 62 3e 20 6d   <b>Append</b> m
4cc0: 6f 64 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e  ode.</li>..</ul>
4cd0: 0d 0a 3c 6c 69 3e 66 69 6e 61 6c 6c 79 2c 20 79  ..<li>finally, y
4ce0: 6f 75 20 63 61 6e 20 70 61 73 73 20 61 20 3c 62  ou can pass a <b
4cf0: 3e 4e 55 4c 4c 3c 2f 62 3e 20 70 61 74 68 20 61  >NULL</b> path a
4d00: 72 67 75 6d 65 6e 74 20 69 6e 20 6f 72 64 65 72  rgument in order
4d10: 20 74 6f 20 69 6d 6d 65 64 69 61 74 65 6c 79 20   to immediately 
4d20: 64 69 73 61 62 6c 65 20 74 68 65 20 4c 6f 67 66  disable the Logf
4d30: 69 6c 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 6c 69 3e  ile.</li>..</li>
4d40: 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 76 65 72 62 61 74  ..</ul>..<verbat
4d50: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50  im>..SELECT SqlP
4d60: 72 6f 63 5f 47 65 74 4c 6f 67 66 69 6c 65 28 29  roc_GetLogfile()
4d70: 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 2f 68 6f 6d 65 2f  ;..-----../home/
4d80: 73 61 6e 64 72 6f 2f 73 71 6c 5f 6c 6f 67 2e 74  sandro/sql_log.t
4d90: 78 74 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 71 6c  xt....SELECT Sql
4da0: 50 72 6f 63 5f 47 65 74 4c 6f 67 66 69 6c 65 28  Proc_GetLogfile(
4db0: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 4e 55 4c 4c 0d  );..-----..NULL.
4dc0: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 59 6f  .</verbatim>..Yo
4dd0: 75 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 71 6c  u can use <b>Sql
4de0: 50 72 6f 63 5f 47 65 74 4c 6f 67 66 69 6c 65 28  Proc_GetLogfile(
4df0: 29 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74  )</b> in order t
4e00: 6f 20 63 68 65 63 6b 20 69 66 20 74 68 65 20 63  o check if the c
4e10: 75 72 72 65 6e 74 20 44 42 2d 63 6f 6e 6e 65 63  urrent DB-connec
4e20: 74 69 6f 6e 20 69 73 20 75 73 69 6e 67 20 61 20  tion is using a 
4e30: 4c 6f 67 66 69 6c 65 20 6f 72 20 6e 6f 74 2e 3c  Logfile or not.<
4e40: 62 72 3e 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65 20  br><br>..<table 
4e50: 62 67 63 6f 6c 6f 72 3d 22 23 66 38 66 38 64 38  bgcolor="#f8f8d8
4e60: 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 36  " cellpadding="6
4e70: 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 38  " cellspacing="8
4e80: 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 3c 75 3e 4e  "><tr><td>..<u>N
4e90: 6f 74 65 3c 2f 75 3e 3a 20 74 68 65 20 4c 6f 67  ote</u>: the Log
4ea0: 66 69 6c 65 20 73 65 74 74 69 6e 67 20 69 73 20  file setting is 
4eb0: 70 65 72 6d 61 6e 65 6e 74 20 6f 6e 20 61 20 70  permanent on a p
4ec0: 65 72 2d 63 6f 6e 6e 65 63 74 69 6f 6e 20 62 61  er-connection ba
4ed0: 73 69 73 2e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e  sis...<ul>..<li>
4ee0: 61 6e 79 20 6e 65 77 20 44 42 2d 63 6f 6e 6e 65  any new DB-conne
4ef0: 63 74 69 6f 6e 20 77 69 6c 6c 20 61 6c 77 61 79  ction will alway
4f00: 73 20 73 74 61 72 74 20 62 79 20 6b 65 65 70 69  s start by keepi
4f10: 6e 67 20 74 68 65 20 4c 6f 67 66 69 6c 65 20 64  ng the Logfile d
4f20: 69 73 61 62 6c 65 64 2e 3c 62 72 3e 0d 0a 59 6f  isabled.<br>..Yo
4f30: 75 20 61 72 65 20 61 6c 77 61 79 73 20 72 65 71  u are always req
4f40: 75 69 72 65 64 20 74 6f 20 70 65 72 66 6f 72 6d  uired to perform
4f50: 20 61 6e 20 65 78 70 6c 69 63 69 74 20 63 61 6c   an explicit cal
4f60: 6c 20 74 6f 20 3c 62 3e 53 71 6c 50 72 6f 63 5f  l to <b>SqlProc_
4f70: 53 65 74 4c 6f 67 66 69 6c 65 28 29 3c 2f 62 3e  SetLogfile()</b>
4f80: 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 65 66 66   in order to eff
4f90: 65 63 74 69 76 65 6c 79 20 65 6e 61 62 6c 65 20  ectively enable 
4fa0: 61 20 4c 6f 67 66 69 6c 65 2e 3c 2f 6c 69 3e 0d  a Logfile.</li>.
4fb0: 0a 3c 6c 69 3e 6f 6e 63 65 20 61 20 4c 6f 67 66  .<li>once a Logf
4fc0: 69 6c 65 20 68 61 73 20 62 65 65 6e 20 65 6e 61  ile has been ena
4fd0: 62 6c 65 64 20 69 74 20 77 69 6c 6c 20 63 6f 6e  bled it will con
4fe0: 74 69 6e 75 65 20 74 6f 20 73 75 70 70 6f 72 74  tinue to support
4ff0: 20 74 68 65 20 63 75 72 72 65 6e 74 20 44 42 2d   the current DB-
5000: 63 6f 6e 6e 65 63 74 69 6f 6e 20 64 75 72 69 6e  connection durin
5010: 67 20 69 74 73 20 6c 69 66 65 73 70 61 6e 2c 20  g its lifespan, 
5020: 69 66 20 6e 6f 74 20 62 65 65 6e 20 65 78 70 6c  if not been expl
5030: 69 63 69 74 6c 79 20 64 69 73 61 62 6c 65 64 2e  icitly disabled.
5040: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 4c 6f 67 66 69  </li>..<li>Logfi
5050: 6c 65 20 73 65 74 74 69 6e 67 73 20 61 72 65 20  le settings are 
5060: 73 74 72 69 63 74 6c 79 20 63 6f 6e 66 69 6e 65  strictly confine
5070: 64 20 77 69 74 68 69 6e 67 20 74 68 65 20 63 75  d withing the cu
5080: 72 72 65 6e 74 20 44 42 2d 63 6f 6e 6e 65 63 74  rrent DB-connect
5090: 69 6f 6e 2c 20 61 6e 64 20 77 69 6c 6c 20 6e 65  ion, and will ne
50a0: 76 65 72 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c  ver automaticall
50b0: 79 20 62 65 20 63 6f 6e 74 69 6e 75 65 64 20 69  y be continued i
50c0: 6e 20 61 6e 79 20 66 6f 6c 6c 6f 77 69 6e 67 20  n any following 
50d0: 63 6f 6e 6e 65 63 74 69 6f 6e 73 2e 3c 2f 6c 69  connections.</li
50e0: 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 2f 74 64 3e 3c  >..</ul>..</td><
50f0: 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 2f  /tr></table>..</
5100: 6c 69 3e 0d 0a 3c 2f 6f 6c 3e 0d 0a 3c 62 72 3e  li>..</ol>..<br>
5110: 3c 68 72 3e 0d 0a 3c 68 32 3e 54 75 74 6f 72 69  <hr>..<h2>Tutori
5120: 61 6c 20 23 31 3c 2f 68 32 3e 0d 0a 3c 74 61 62  al #1</h2>..<tab
5130: 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 66 38 66  le bgcolor="#f8f
5140: 38 64 38 22 20 63 65 6c 6c 70 61 64 64 69 6e 67  8d8" cellpadding
5150: 3d 22 36 22 20 63 65 6c 6c 73 70 61 63 69 6e 67  ="6" cellspacing
5160: 3d 22 38 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 41  ="8"><tr><td>..A
5170: 6c 6c 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67  ll the following
5180: 20 74 75 74 6f 72 69 61 6c 73 20 61 72 65 20 62   tutorials are b
5190: 61 73 65 64 20 6f 6e 20 74 68 65 20 73 61 6d 65  ased on the same
51a0: 20 73 61 6d 70 6c 65 20 64 61 74 61 62 61 73 65   sample database
51b0: 2c 20 77 68 69 63 68 20 73 68 6f 75 6c 64 20 62  , which should b
51c0: 65 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 3a  e <a href="http:
51d0: 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73 2e 69  //www.gaia-gis.i
51e0: 74 2f 67 61 69 61 2d 73 69 6e 73 2f 73 70 5f 73  t/gaia-sins/sp_s
51f0: 61 6d 70 6c 65 5f 64 62 2e 37 7a 22 3e 64 6f 77  ample_db.7z">dow
5200: 6e 6c 6f 61 64 65 64 3c 2f 61 3e 20 62 65 66 6f  nloaded</a> befo
5210: 72 65 20 63 6f 6e 74 69 6e 75 69 6e 67 2e 0d 0a  re continuing...
5220: 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c  </td></tr></tabl
5230: 65 3e 3c 62 72 3e 0d 0a 41 73 20 79 6f 75 20 63  e><br>..As you c
5240: 61 6e 20 73 65 65 2c 20 74 68 69 73 20 64 61 74  an see, this dat
5250: 61 62 61 73 65 20 63 6f 6e 74 61 69 6e 73 20 74  abase contains t
5260: 68 72 65 65 20 53 70 61 74 69 61 6c 20 54 61 62  hree Spatial Tab
5270: 6c 65 73 20 72 65 70 72 65 73 65 6e 74 69 6e 67  les representing
5280: 20 74 68 65 20 3c 62 3e 3c 69 3e 41 64 6d 69 6e   the <b><i>Admin
5290: 69 73 74 72 61 74 69 76 65 20 42 6f 75 6e 64 61  istrative Bounda
52a0: 72 69 65 73 3c 2f 69 3e 3c 2f 62 3e 20 6f 66 20  ries</i></b> of 
52b0: 61 6c 6c 20 49 74 61 6c 69 61 6e 20 4d 75 6e 69  all Italian Muni
52c0: 63 69 70 61 6c 69 74 69 65 73 20 61 73 20 6f 66  cipalities as of
52d0: 66 69 63 69 61 6c 6c 79 20 64 65 74 65 72 6d 69  ficially determi
52e0: 6e 65 64 20 62 79 20 3c 61 20 68 72 65 66 3d 22  ned by <a href="
52f0: 68 74 74 70 73 3a 2f 2f 65 6e 2e 77 69 6b 69 70  https://en.wikip
5300: 65 64 69 61 2e 6f 72 67 2f 77 69 6b 69 2f 4e 61  edia.org/wiki/Na
5310: 74 69 6f 6e 61 6c 5f 49 6e 73 74 69 74 75 74 65  tional_Institute
5320: 5f 6f 66 5f 53 74 61 74 69 73 74 69 63 73 5f 28  _of_Statistics_(
5330: 49 74 61 6c 79 29 22 3e 49 53 54 41 54 3c 2f 61  Italy)">ISTAT</a
5340: 3e 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 74 68  >:..<ul>..<li>th
5350: 65 72 65 20 61 72 65 20 74 68 72 65 65 20 64 69  ere are three di
5360: 66 66 65 72 65 6e 74 20 74 61 62 6c 65 73 2c 20  fferent tables, 
5370: 65 61 63 68 20 6f 6e 65 20 63 6f 72 72 65 73 70  each one corresp
5380: 6f 6e 64 69 6e 67 20 74 6f 20 61 20 73 70 65 63  onding to a spec
5390: 69 66 69 63 20 4e 61 74 69 6f 6e 61 6c 20 43 65  ific National Ce
53a0: 6e 73 75 73 20 28 79 65 61 72 73 20 31 39 39 31  nsus (years 1991
53b0: 2c 20 32 30 30 31 20 61 6e 64 20 32 30 31 31 20  , 2001 and 2011 
53c0: 61 72 65 20 61 76 61 69 6c 61 62 6c 65 29 2e 3c  are available).<
53d0: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6c 6c 20 74 68  /li>..<li>all th
53e0: 72 65 65 20 74 61 62 6c 65 73 20 68 61 76 65 20  ree tables have 
53f0: 65 78 61 63 74 6c 79 20 74 68 65 20 73 61 6d 65  exactly the same
5400: 20 6c 61 79 6f 75 74 2e 3c 2f 6c 69 3e 0d 0a 3c   layout.</li>..<
5410: 6c 69 3e 41 64 6d 69 6e 69 73 74 72 61 74 69 76  li>Administrativ
5420: 65 20 42 6f 75 6e 64 61 72 69 65 73 20 61 72 65  e Boundaries are
5430: 20 61 6c 77 61 79 73 20 72 65 70 72 65 73 65 6e   always represen
5440: 74 65 64 20 61 73 20 4d 75 6c 74 69 50 6f 6c 79  ted as MultiPoly
5450: 67 6f 6e 73 20 28 53 72 69 64 3d 33 32 36 33 32  gons (Srid=32632
5460: 29 2e 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d 0a 3c  )...</ul><br>..<
5470: 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23  table bgcolor="#
5480: 66 38 66 38 64 38 22 20 63 65 6c 6c 70 61 64 64  f8f8d8" cellpadd
5490: 69 6e 67 3d 22 36 22 20 63 65 6c 6c 73 70 61 63  ing="6" cellspac
54a0: 69 6e 67 3d 22 38 22 3e 3c 74 72 3e 3c 74 64 3e  ing="8"><tr><td>
54b0: 0d 0a 3c 68 34 3e 54 68 65 20 50 72 6f 62 6c 65  ..<h4>The Proble
54c0: 6d 3c 2f 68 34 3e 0d 0a 57 65 27 6c 6c 20 69 6d  m</h4>..We'll im
54d0: 70 6c 65 6d 65 6e 74 20 61 20 3c 62 3e 50 72 6f  plement a <b>Pro
54e0: 63 65 64 75 72 65 3c 2f 62 3e 20 69 6e 74 65 6e  cedure</b> inten
54f0: 64 65 64 20 74 6f 20 65 78 70 6f 72 74 20 73 65  ded to export se
5500: 6c 65 63 74 65 64 20 53 68 61 70 65 66 69 6c 65  lected Shapefile
5510: 73 2e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 54 68  s...<ul>..<li>Th
5520: 65 20 43 65 6e 73 75 73 20 59 65 61 72 20 6d 75  e Census Year mu
5530: 73 74 20 62 65 20 66 72 65 65 6c 79 20 73 65 6c  st be freely sel
5540: 65 63 74 61 62 6c 65 2e 3c 2f 6c 69 3e 0d 0a 3c  ectable.</li>..<
5550: 6c 69 3e 41 20 72 65 71 75 69 72 65 64 20 66 65  li>A required fe
5560: 61 74 75 72 65 20 69 73 20 61 6c 6c 6f 77 69 6e  ature is allowin
5570: 67 20 65 69 74 68 65 72 20 66 69 6c 74 65 72 69  g either filteri
5580: 6e 67 20 61 20 73 69 6e 67 6c 65 20 4d 75 6e 69  ng a single Muni
5590: 63 69 70 61 6c 69 74 79 20 6f 72 20 6c 69 73 74  cipality or list
55a0: 69 6e 67 20 61 6c 6c 20 4d 75 6e 69 63 69 70 61  ing all Municipa
55b0: 6c 69 74 69 65 73 20 62 65 6c 6f 6e 67 69 6e 67  lities belonging
55c0: 20 74 6f 20 74 68 65 20 61 20 50 72 6f 76 69 6e   to the a Provin
55d0: 63 65 20 6f 72 20 52 65 67 69 6f 6e 2e 3c 2f 6c  ce or Region.</l
55e0: 69 3e 0d 0a 3c 6c 69 3e 52 65 70 72 6f 6a 65 63  i>..<li>Reprojec
55f0: 74 69 6e 67 20 74 6f 20 73 6f 6d 65 20 61 6c 74  ting to some alt
5600: 65 72 6e 61 74 69 76 65 20 53 52 49 44 20 77 69  ernative SRID wi
5610: 6c 6c 20 62 65 20 61 20 73 75 70 70 6f 72 74 65  ll be a supporte
5620: 64 20 66 65 61 74 75 72 65 2e 3c 2f 6c 69 3e 0d  d feature.</li>.
5630: 0a 3c 6c 69 3e 57 68 69 6c 65 20 64 6f 69 6e 67  .<li>While doing
5640: 20 61 6c 6c 20 74 68 69 73 20 77 65 27 6c 6c 20   all this we'll 
5650: 6f 62 76 69 6f 75 73 6c 79 20 74 72 79 20 74 6f  obviously try to
5660: 20 74 61 6b 65 20 66 75 6c 6c 20 61 64 76 61 6e   take full advan
5670: 74 61 67 65 20 6f 66 20 75 73 69 6e 67 20 3c 62  tage of using <b
5680: 3e 56 61 72 69 61 62 6c 65 73 3c 2f 62 3e 20 74  >Variables</b> t
5690: 6f 20 6d 61 6b 65 20 74 68 65 20 50 72 6f 63 65  o make the Proce
56a0: 64 75 72 65 20 61 73 20 67 65 6e 65 72 69 63 20  dure as generic 
56b0: 61 6e 64 20 66 6c 65 78 69 62 6c 65 20 61 73 20  and flexible as 
56c0: 70 6f 73 73 69 62 6c 65 2e 3c 2f 6c 69 3e 0d 0a  possible.</li>..
56d0: 3c 2f 75 6c 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72  </ul>..</td></tr
56e0: 3e 3c 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 3c  ></table><br>..<
56f0: 76 65 72 62 61 74 69 6d 3e 0d 0a 2d 2d 0d 0a 2d  verbatim>..--..-
5700: 2d 20 72 65 6d 6f 76 69 6e 67 20 74 68 65 20 77  - removing the w
5710: 6f 72 6b 20 74 61 62 6c 65 20 28 6a 75 73 74 20  ork table (just 
5720: 69 6e 20 63 61 73 65 20 69 74 20 61 6c 72 65 61  in case it alrea
5730: 64 79 20 65 78 69 73 74 73 29 0d 0a 2d 2d 0d 0a  dy exists)..--..
5740: 53 45 4c 45 43 54 20 44 72 6f 70 47 65 6f 54 61  SELECT DropGeoTa
5750: 62 6c 65 28 27 74 72 61 6e 73 69 65 6e 74 5f 74  ble('transient_t
5760: 61 62 6c 65 27 29 3b 0d 0a 0d 0a 2d 2d 0d 0a 2d  able');....--..-
5770: 2d 20 69 6e 73 65 72 74 69 6e 67 20 73 65 6c 65  - inserting sele
5780: 63 74 65 64 20 64 61 74 61 20 69 6e 74 6f 20 74  cted data into t
5790: 68 65 20 77 6f 72 6b 20 74 61 62 6c 65 0d 0a 2d  he work table..-
57a0: 2d 0d 0a 43 52 45 41 54 45 20 54 41 42 4c 45 20  -..CREATE TABLE 
57b0: 74 72 61 6e 73 69 65 6e 74 5f 74 61 62 6c 65 20  transient_table 
57c0: 41 53 0d 0a 53 45 4c 45 43 54 20 69 64 2c 20 69  AS..SELECT id, i
57d0: 73 74 61 74 2c 20 6e 61 6d 65 2c 20 70 72 6f 76  stat, name, prov
57e0: 69 6e 63 65 2c 20 72 65 67 69 6f 6e 2c 20 53 54  ince, region, ST
57f0: 5f 54 72 61 6e 73 66 6f 72 6d 28 67 65 6f 6d 2c  _Transform(geom,
5800: 20 40 73 72 69 64 40 29 20 41 53 20 67 65 6f 6d   @srid@) AS geom
5810: 0d 0a 46 52 4f 4d 20 6d 75 6e 69 63 69 70 61 6c  ..FROM municipal
5820: 69 74 69 65 73 5f 40 79 65 61 72 40 0d 0a 57 48  ities_@year@..WH
5830: 45 52 45 20 28 55 70 70 65 72 28 6e 61 6d 65 29  ERE (Upper(name)
5840: 20 3d 20 55 70 70 65 72 28 27 40 6d 75 6e 69 63   = Upper('@munic
5850: 69 70 61 6c 69 74 79 40 27 29 20 4f 52 20 55 70  ipality@') OR Up
5860: 70 65 72 28 70 72 6f 76 69 6e 63 65 29 20 3d 20  per(province) = 
5870: 55 70 70 65 72 28 27 40 70 72 6f 76 69 6e 63 65  Upper('@province
5880: 40 27 29 20 4f 52 20 55 70 70 65 72 28 72 65 67  @') OR Upper(reg
5890: 69 6f 6e 29 20 3d 20 55 70 70 65 72 28 27 40 72  ion) = Upper('@r
58a0: 65 67 69 6f 6e 40 27 29 29 3b 0d 0a 0d 0a 2d 2d  egion@'));....--
58b0: 0d 0a 2d 2d 20 70 72 6f 70 65 72 6c 79 20 72 65  ..-- properly re
58c0: 63 6f 76 65 72 69 6e 67 20 74 68 65 20 77 6f 72  covering the wor
58d0: 6b 20 74 61 62 6c 65 0d 0a 2d 2d 0d 0a 53 45 4c  k table..--..SEL
58e0: 45 43 54 20 52 65 63 6f 76 65 72 47 65 6f 6d 65  ECT RecoverGeome
58f0: 74 72 79 43 6f 6c 75 6d 6e 28 27 74 72 61 6e 73  tryColumn('trans
5900: 69 65 6e 74 5f 74 61 62 6c 65 27 2c 20 27 67 65  ient_table', 'ge
5910: 6f 6d 27 2c 20 40 73 72 69 64 40 2c 20 27 4d 55  om', @srid@, 'MU
5920: 4c 54 49 50 4f 4c 59 47 4f 4e 27 2c 20 27 58 59  LTIPOLYGON', 'XY
5930: 27 29 3b 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20 65 78  ');....--..-- ex
5940: 70 6f 72 74 69 6e 67 20 66 72 6f 6d 20 74 68 65  porting from the
5950: 20 77 6f 72 6b 20 74 61 62 6c 65 20 69 6e 74 6f   work table into
5960: 20 74 68 65 20 53 68 61 70 65 66 69 6c 65 0d 0a   the Shapefile..
5970: 2d 2d 0d 0a 53 45 4c 45 43 54 20 45 78 70 6f 72  --..SELECT Expor
5980: 74 53 68 70 28 27 74 72 61 6e 73 69 65 6e 74 5f  tShp('transient_
5990: 74 61 62 6c 65 27 2c 20 27 67 65 6f 6d 27 2c 20  table', 'geom', 
59a0: 27 40 73 68 70 5f 70 61 74 68 40 27 2c 20 27 43  '@shp_path@', 'C
59b0: 50 31 32 35 32 27 29 3b 0d 0a 0d 0a 2d 2d 0d 0a  P1252');....--..
59c0: 2d 2d 20 72 65 6d 6f 76 69 6e 67 20 74 68 65 20  -- removing the 
59d0: 77 6f 72 6b 20 74 61 62 6c 65 0d 0a 2d 2d 0d 0a  work table..--..
59e0: 53 45 4c 45 43 54 20 44 72 6f 70 47 65 6f 54 61  SELECT DropGeoTa
59f0: 62 6c 65 28 27 74 72 61 6e 73 69 65 6e 74 5f 74  ble('transient_t
5a00: 61 62 6c 65 27 29 3b 0d 0a 3c 2f 76 65 72 62 61  able');..</verba
5a10: 74 69 6d 3e 0d 0a 41 73 20 79 6f 75 20 63 61 6e  tim>..As you can
5a20: 20 73 65 65 20 74 68 65 20 70 72 6f 70 6f 73 65   see the propose
5a30: 64 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e  d implementation
5a40: 20 69 73 20 62 61 73 69 63 61 6c 6c 79 20 73 69   is basically si
5a50: 6d 70 6c 65 2e 20 4e 6f 77 20 79 6f 75 20 73 69  mple. Now you si
5a60: 6d 70 6c 79 20 68 61 76 65 20 74 6f 20 3c 62 3e  mply have to <b>
5a70: 63 75 74 26 70 61 73 74 65 3c 2f 62 3e 20 74 68  cut&paste</b> th
5a80: 65 20 61 62 6f 76 65 20 53 51 4c 20 62 6f 64 79  e above SQL body
5a90: 20 73 61 76 69 6e 67 20 69 74 20 69 6e 74 6f 20   saving it into 
5aa0: 61 20 66 69 6c 65 20 6e 61 6d 65 64 20 3c 62 3e  a file named <b>
5ab0: 74 65 73 74 5f 73 70 2e 74 78 74 3c 2f 62 3e 20  test_sp.txt</b> 
5ac0: 66 6f 72 20 66 75 72 74 68 65 72 20 75 73 61 67  for further usag
5ad0: 65 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 46 65 77 20  e.<br><br>..Few 
5ae0: 69 6e 74 65 72 65 73 74 69 6e 67 20 64 65 74 61  interesting deta
5af0: 69 6c 73 20 77 6f 72 74 68 20 62 65 69 6e 67 20  ils worth being 
5b00: 65 78 70 6c 61 69 6e 65 64 3a 0d 0a 3c 75 6c 3e  explained:..<ul>
5b10: 0d 0a 3c 6c 69 3e 56 61 72 69 61 62 6c 65 20 3c  ..<li>Variable <
5b20: 62 3e 40 79 65 61 72 40 3c 2f 62 3e 20 69 73 20  b>@year@</b> is 
5b30: 69 6e 74 65 6e 64 65 64 20 74 6f 20 73 65 6c 65  intended to sele
5b40: 63 74 20 77 68 69 63 68 20 73 70 65 63 69 66 69  ct which specifi
5b50: 63 20 53 70 61 74 69 61 6c 20 54 61 62 6c 65 20  c Spatial Table 
5b60: 77 69 6c 6c 20 62 65 20 71 75 65 72 69 65 64 2e  will be queried.
5b70: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 56 61 72 69 61  </li>..<li>Varia
5b80: 62 6c 65 20 3c 62 3e 40 73 72 69 64 40 3c 2f 62  ble <b>@srid@</b
5b90: 3e 20 69 73 20 69 6e 74 65 6e 64 65 64 20 74 6f  > is intended to
5ba0: 20 73 70 65 63 69 66 79 20 74 68 65 20 6f 75 74   specify the out
5bb0: 70 75 74 20 53 52 49 44 2e 3c 2f 6c 69 3e 0d 0a  put SRID.</li>..
5bc0: 3c 6c 69 3e 56 61 72 69 61 62 6c 65 20 3c 62 3e  <li>Variable <b>
5bd0: 40 73 68 70 5f 70 61 74 68 40 3c 2f 62 3e 20 69  @shp_path@</b> i
5be0: 73 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 73 70  s intended to sp
5bf0: 65 63 69 66 79 20 74 68 65 20 70 61 74 68 6e 61  ecify the pathna
5c00: 6d 65 20 6f 66 20 74 68 65 20 6f 75 74 70 75 74  me of the output
5c10: 20 53 68 61 70 65 66 69 6c 65 2e 3c 2f 6c 69 3e   Shapefile.</li>
5c20: 0d 0a 3c 6c 69 3e 56 61 72 69 61 62 6c 65 73 20  ..<li>Variables 
5c30: 3c 62 3e 40 6d 75 6e 69 63 69 70 61 6c 69 74 79  <b>@municipality
5c40: 40 3c 2f 62 3e 2c 20 3c 62 3e 40 70 72 6f 76 69  @</b>, <b>@provi
5c50: 6e 63 65 40 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e  nce@</b> and <b>
5c60: 40 72 65 67 69 6f 6e 40 3c 2f 62 3e 20 61 72 65  @region@</b> are
5c70: 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 73 70 65   intended to spe
5c80: 63 69 66 79 20 74 68 65 20 69 6e 74 65 6e 64 65  cify the intende
5c90: 64 20 66 69 6c 74 65 72 69 6e 67 20 63 72 69 74  d filtering crit
5ca0: 65 72 69 61 2e 3c 62 72 3e 0d 0a 54 68 69 73 20  eria.<br>..This 
5cb0: 69 73 20 61 20 6c 69 74 74 6c 65 20 62 69 74 20  is a little bit 
5cc0: 74 72 69 63 6b 79 2c 20 73 6f 20 77 65 27 6c 6c  tricky, so we'll
5cd0: 20 67 6f 20 69 6e 20 66 75 72 74 68 65 72 20 64   go in further d
5ce0: 65 70 74 68 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69  epth:..<ul>..<li
5cf0: 3e 54 68 65 73 65 20 56 61 72 69 61 62 6c 65 73  >These Variables
5d00: 20 61 72 65 20 65 78 70 65 63 74 65 64 20 74 6f   are expected to
5d10: 20 62 65 20 61 63 74 75 61 6c 6c 79 20 72 65 70   be actually rep
5d20: 6c 61 63 65 64 20 62 79 20 3c 62 3e 74 65 78 74  laced by <b>text
5d30: 20 73 74 72 69 6e 67 20 76 61 6c 75 65 73 3c 2f   string values</
5d40: 62 3e 3b 20 73 6f 20 77 65 27 76 65 20 63 6f 6e  b>; so we've con
5d50: 73 69 73 74 65 6e 74 6c 79 20 3c 62 3e 73 69 6e  sistently <b>sin
5d60: 67 6c 65 2d 71 75 6f 74 65 64 3c 2f 62 3e 20 74  gle-quoted</b> t
5d70: 68 65 20 76 61 72 69 61 62 6c 65 20 73 79 6d 62  he variable symb
5d80: 6f 6c 2c 20 73 6f 20 74 6f 20 61 6c 6c 6f 77 20  ol, so to allow 
5d90: 66 6f 72 20 61 6e 20 65 61 73 69 65 72 20 76 61  for an easier va
5da0: 6c 75 65 20 72 65 70 6c 61 63 65 6d 65 6e 74 2e  lue replacement.
5db0: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 57 65 20 61 72  </li>..<li>We ar
5dc0: 65 20 73 79 73 74 65 6d 61 74 69 63 61 6c 6c 79  e systematically
5dd0: 20 75 73 69 6e 67 20 74 68 65 20 3c 62 3e 55 70   using the <b>Up
5de0: 70 65 72 28 29 3c 2f 62 3e 20 66 75 6e 63 74 69  per()</b> functi
5df0: 6f 6e 20 73 69 6d 70 6c 79 20 62 65 63 61 75 73  on simply becaus
5e00: 65 20 50 72 6f 76 69 6e 63 65 20 61 6e 64 20 52  e Province and R
5e10: 65 67 69 6f 6e 20 6e 61 6d 65 73 20 61 72 65 20  egion names are 
5e20: 61 6c 6c 2d 75 70 70 65 72 63 61 73 65 20 69 6e  all-uppercase in
5e30: 20 79 65 61 72 73 20 31 39 39 31 20 61 6e 64 20   years 1991 and 
5e40: 32 30 30 31 20 62 75 74 20 6e 6f 74 20 66 6f 72  2001 but not for
5e50: 20 74 68 65 20 79 65 61 72 20 32 30 31 31 2e 3c   the year 2011.<
5e60: 62 72 3e 0d 0a 53 79 73 74 65 6d 61 74 69 63 61  br>..Systematica
5e70: 6c 6c 79 20 75 73 69 6e 67 20 55 70 70 65 72 28  lly using Upper(
5e80: 29 20 77 69 6c 6c 20 69 6e 73 75 72 65 20 63 6f  ) will insure co
5e90: 6e 73 69 73 74 65 6e 74 65 6e 63 79 20 6f 66 20  nsistentency of 
5ea0: 61 6c 6c 20 6e 61 6d 65 73 2e 3c 2f 6c 69 3e 0d  all names.</li>.
5eb0: 0a 3c 6c 69 3e 57 65 20 61 72 65 20 75 73 69 6e  .<li>We are usin
5ec0: 67 20 74 68 72 65 65 20 73 65 70 61 72 61 74 65  g three separate
5ed0: 20 63 6f 6d 70 61 72 69 73 6f 6e 73 20 28 6f 6e   comparisons (on
5ee0: 65 20 66 6f 72 20 4d 75 6e 69 63 69 70 61 6c 69  e for Municipali
5ef0: 74 79 2c 20 6f 6e 65 20 66 6f 72 20 50 72 6f 76  ty, one for Prov
5f00: 69 6e 63 65 20 61 6e 64 20 6f 6e 65 20 66 6f 72  ince and one for
5f10: 20 52 65 67 69 6f 6e 29 20 63 6f 6e 6e 65 63 74   Region) connect
5f20: 65 64 20 62 79 20 3c 62 3e 4f 52 3c 2f 62 3e 20  ed by <b>OR</b> 
5f30: 6c 6f 67 69 63 61 6c 20 6f 70 65 72 61 74 6f 72  logical operator
5f40: 73 20 73 6f 20 74 6f 20 6d 61 6b 65 20 69 74 20  s so to make it 
5f50: 70 6f 73 73 69 62 6c 65 20 62 79 20 73 70 65 63  possible by spec
5f60: 69 66 79 69 6e 67 20 6a 75 73 74 20 61 20 73 69  ifying just a si
5f70: 6e 67 6c 65 20 6f 72 20 6d 6f 72 65 20 66 69 6c  ngle or more fil
5f80: 74 65 72 20 63 6c 61 75 73 65 73 2e 3c 62 72 3e  ter clauses.<br>
5f90: 0d 0a 3c 75 3e 52 65 63 61 6c 6c 3c 2f 75 3e 3a  ..<u>Recall</u>:
5fa0: 20 75 6e 61 73 73 69 67 6e 65 64 20 56 61 72 69   unassigned Vari
5fb0: 61 62 6c 65 73 20 77 69 6c 6c 20 64 65 66 61 75  ables will defau
5fc0: 6c 74 20 74 6f 20 4e 55 4c 4c 3b 20 73 6f 20 62  lt to NULL; so b
5fd0: 79 20 6a 75 73 74 20 64 65 63 6c 61 72 69 6e 67  y just declaring
5fe0: 20 0d 0a 3c 62 3e 40 70 72 6f 76 69 6e 63 65 40   ..<b>@province@
5ff0: 3d 41 72 65 7a 7a 6f 3c 2f 62 3e 20 77 65 27 6c  =Arezzo</b> we'l
6000: 6c 20 74 68 65 6e 20 67 65 74 20 61 20 3c 62 3e  l then get a <b>
6010: 3c 69 3e 63 6f 6f 6b 65 64 3c 2f 69 3e 3c 2f 62  <i>cooked</i></b
6020: 3e 20 57 48 45 52 45 20 63 6c 61 75 73 65 20 6c  > WHERE clause l
6030: 69 6b 65 20 74 68 69 73 3a 0d 0a 3c 76 65 72 62  ike this:..<verb
6040: 61 74 69 6d 3e 0d 0a 57 48 45 52 45 20 28 55 70  atim>..WHERE (Up
6050: 70 65 72 28 6e 61 6d 65 29 20 3d 20 55 70 70 65  per(name) = Uppe
6060: 72 28 27 4e 55 4c 4c 27 29 20 4f 52 20 55 70 70  r('NULL') OR Upp
6070: 65 72 28 70 72 6f 76 69 6e 63 65 29 20 3d 20 55  er(province) = U
6080: 70 70 65 72 28 27 41 72 65 7a 7a 6f 27 29 20 4f  pper('Arezzo') O
6090: 52 20 55 70 70 65 72 28 72 65 67 69 6f 6e 29 20  R Upper(region) 
60a0: 3d 20 55 70 70 65 72 28 27 4e 55 4c 4c 27 29 29  = Upper('NULL'))
60b0: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c  ..</verbatim>..<
60c0: 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 2f 6c  /li>..</ul>..</l
60d0: 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 62 72 3e 0d  i>..</ul>..<br>.
60e0: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c  .<verbatim>..SEL
60f0: 45 43 54 20 53 71 6c 50 72 6f 63 5f 45 78 65 63  ECT SqlProc_Exec
6100: 75 74 65 28 20 53 71 6c 50 72 6f 63 5f 46 72 6f  ute( SqlProc_Fro
6110: 6d 46 69 6c 65 20 28 27 43 3a 2f 75 73 65 72 73  mFile ('C:/users
6120: 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70 72 6f 63  /joe/stored_proc
6130: 5f 74 65 73 74 2f 74 65 73 74 5f 73 70 2e 74 78  _test/test_sp.tx
6140: 74 27 29 2c 0d 0a 20 20 27 40 73 72 69 64 40 3d  t'),..  '@srid@=
6150: 33 30 30 34 27 2c 20 27 40 79 65 61 72 40 3d 32  3004', '@year@=2
6160: 30 30 31 27 2c 20 27 40 72 65 67 69 6f 6e 40 3d  001', '@region@=
6170: 4c 61 7a 69 6f 27 2c 20 27 40 73 68 70 5f 70 61  Lazio', '@shp_pa
6180: 74 68 40 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65  th@=C:/users/joe
6190: 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73  /stored_proc_tes
61a0: 74 2f 6c 61 7a 69 6f 5f 32 30 30 31 5f 33 30 30  t/lazio_2001_300
61b0: 34 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a  4');..-----..1..
61c0: 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63  ..SELECT SqlProc
61d0: 5f 45 78 65 63 75 74 65 28 20 53 71 6c 50 72 6f  _Execute( SqlPro
61e0: 63 5f 46 72 6f 6d 46 69 6c 65 20 28 27 43 3a 2f  c_FromFile ('C:/
61f0: 75 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64  users/joe/stored
6200: 5f 70 72 6f 63 5f 74 65 73 74 2f 74 65 73 74 5f  _proc_test/test_
6210: 73 70 2e 74 78 74 27 29 2c 0d 0a 20 20 27 40 73  sp.txt'),..  '@s
6220: 72 69 64 40 3d 34 33 32 36 27 2c 20 27 40 79 65  rid@=4326', '@ye
6230: 61 72 40 3d 31 39 39 31 27 2c 20 27 40 72 65 67  ar@=1991', '@reg
6240: 69 6f 6e 40 3d 70 75 67 6c 69 61 27 2c 20 27 40  ion@=puglia', '@
6250: 73 68 70 5f 70 61 74 68 40 3d 43 3a 2f 75 73 65  shp_path@=C:/use
6260: 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70 72  rs/joe/stored_pr
6270: 6f 63 5f 74 65 73 74 2f 70 75 67 6c 69 61 5f 31  oc_test/puglia_1
6280: 39 39 31 5f 34 33 32 36 27 29 3b 0d 0a 2d 2d 2d  991_4326');..---
6290: 2d 2d 0d 0a 31 0d 0a 0d 0a 53 45 4c 45 43 54 20  --..1....SELECT 
62a0: 53 71 6c 50 72 6f 63 5f 45 78 65 63 75 74 65 28  SqlProc_Execute(
62b0: 20 53 71 6c 50 72 6f 63 5f 46 72 6f 6d 46 69 6c   SqlProc_FromFil
62c0: 65 20 28 27 43 3a 2f 75 73 65 72 73 2f 6a 6f 65  e ('C:/users/joe
62d0: 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73  /stored_proc_tes
62e0: 74 2f 74 65 73 74 5f 73 70 2e 74 78 74 27 29 2c  t/test_sp.txt'),
62f0: 0d 0a 20 20 27 40 73 72 69 64 40 3d 33 30 30 33  ..  '@srid@=3003
6300: 27 2c 20 27 40 79 65 61 72 40 3d 32 30 31 31 27  ', '@year@=2011'
6310: 2c 20 27 40 70 72 6f 76 69 6e 63 65 40 3d 41 52  , '@province@=AR
6320: 45 5a 5a 4f 27 2c 20 27 40 73 68 70 5f 70 61 74  EZZO', '@shp_pat
6330: 68 40 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f  h@=C:/users/joe/
6340: 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74  stored_proc_test
6350: 2f 61 72 65 7a 7a 6f 5f 32 30 31 31 5f 33 30 30  /arezzo_2011_300
6360: 33 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a  3');..-----..1..
6370: 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63  ..SELECT SqlProc
6380: 5f 45 78 65 63 75 74 65 28 20 53 71 6c 50 72 6f  _Execute( SqlPro
6390: 63 5f 46 72 6f 6d 46 69 6c 65 20 28 27 43 3a 2f  c_FromFile ('C:/
63a0: 75 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64  users/joe/stored
63b0: 5f 70 72 6f 63 5f 74 65 73 74 2f 74 65 73 74 5f  _proc_test/test_
63c0: 73 70 2e 74 78 74 27 29 2c 0d 0a 20 20 27 40 73  sp.txt'),..  '@s
63d0: 72 69 64 40 3d 33 30 30 33 27 2c 20 27 40 79 65  rid@=3003', '@ye
63e0: 61 72 40 3d 32 30 30 31 27 2c 20 27 40 6d 75 6e  ar@=2001', '@mun
63f0: 69 63 69 70 61 6c 69 74 79 40 3d 41 52 45 5a 5a  icipality@=AREZZ
6400: 4f 27 2c 20 27 40 73 68 70 5f 70 61 74 68 40 3d  O', '@shp_path@=
6410: 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74 6f  C:/users/joe/sto
6420: 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f 63 6f  red_proc_test/co
6430: 6d 5f 61 72 65 7a 7a 6f 5f 32 30 30 31 5f 33 30  m_arezzo_2001_30
6440: 30 33 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d  03');..-----..1.
6450: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 49 6e  .</verbatim>..In
6460: 20 74 68 69 73 20 66 69 72 73 74 20 74 75 74 6f   this first tuto
6470: 72 69 61 6c 20 77 65 20 68 61 76 65 20 61 6c 77  rial we have alw
6480: 61 79 73 20 3c 62 3e 65 78 65 63 75 74 65 64 3c  ays <b>executed<
6490: 2f 62 3e 20 61 20 50 72 6f 63 65 64 75 72 65 20  /b> a Procedure 
64a0: 6c 6f 61 64 65 64 20 66 72 6f 6d 20 61 6e 20 65  loaded from an e
64b0: 78 74 65 72 6e 61 6c 20 66 69 6c 65 2e 3c 62 72  xternal file.<br
64c0: 3e 0d 0a 41 73 20 79 6f 75 20 63 61 6e 20 73 65  >..As you can se
64d0: 65 20 65 78 65 63 75 74 69 6e 67 20 61 20 50 72  e executing a Pr
64e0: 6f 63 65 64 75 72 65 20 69 73 20 61 20 73 74 72  ocedure is a str
64f0: 61 69 67 68 74 66 6f 72 77 61 72 64 20 74 61 73  aightforward tas
6500: 6b 3b 20 79 6f 75 20 73 69 6d 70 6c 79 20 68 61  k; you simply ha
6510: 76 65 20 74 6f 20 73 70 65 63 69 66 79 20 61 6e  ve to specify an
6520: 20 61 70 70 72 6f 70 72 69 61 74 65 20 6c 69 73   appropriate lis
6530: 74 20 6f 66 20 3c 62 3e 56 61 72 69 61 62 6c 65  t of <b>Variable
6540: 20 56 61 6c 75 65 73 3c 2f 62 3e 20 61 6e 64 20   Values</b> and 
6550: 74 68 61 74 27 73 20 61 6c 6c 2e 0d 0a 3c 68 72  that's all...<hr
6560: 3e 0d 0a 3c 68 32 3e 54 75 74 6f 72 69 61 6c 20  >..<h2>Tutorial 
6570: 23 32 3c 2f 68 32 3e 0d 0a 3c 76 65 72 62 61 74  #2</h2>..<verbat
6580: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72  im>..SELECT Stor
6590: 65 64 50 72 6f 63 5f 52 65 67 69 73 74 65 72 28  edProc_Register(
65a0: 20 27 6d 79 5f 70 72 6f 63 27 2c 20 27 61 20 53   'my_proc', 'a S
65b0: 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65 20  tored Procedure 
65c0: 66 6f 72 20 65 78 70 6f 72 74 69 6e 67 20 73 65  for exporting se
65d0: 6c 65 63 74 65 64 20 53 68 61 70 65 66 69 6c 65  lected Shapefile
65e0: 73 27 2c 20 53 71 6c 50 72 6f 63 5f 46 72 6f 6d  s', SqlProc_From
65f0: 46 69 6c 65 20 28 27 43 3a 2f 75 73 65 72 73 2f  File ('C:/users/
6600: 6a 6f 65 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f  joe/stored_proc_
6610: 74 65 73 74 2f 74 65 73 74 5f 73 70 2e 74 78 74  test/test_sp.txt
6620: 27 29 20 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69  ') );..</verbati
6630: 6d 3e 0d 0a 54 68 69 73 20 73 65 63 6f 6e 64 20  m>..This second 
6640: 74 75 74 6f 72 69 61 6c 20 69 73 20 20 62 61 73  tutorial is  bas
6650: 69 63 61 6c 6c 79 20 74 68 65 20 73 61 6d 65 20  ically the same 
6660: 6f 66 20 74 68 65 20 66 69 72 73 74 20 6f 6e 65  of the first one
6670: 2e 3c 62 72 3e 0d 0a 54 68 65 20 6f 6e 6c 79 20  .<br>..The only 
6680: 64 69 66 66 65 72 65 6e 63 65 20 69 73 20 74 68  difference is th
6690: 61 74 20 77 65 27 6c 6c 20 6e 6f 77 20 75 73 65  at we'll now use
66a0: 20 61 20 70 65 72 6d 61 6e 65 6e 74 6c 79 20 72   a permanently r
66b0: 65 67 69 73 74 65 72 65 64 20 3c 62 3e 53 74 6f  egistered <b>Sto
66c0: 72 65 64 20 50 72 6f 63 65 64 75 72 65 3c 2f 62  red Procedure</b
66d0: 3e 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  >...<verbatim>..
66e0: 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f  SELECT StoredPro
66f0: 63 5f 45 78 65 63 75 74 65 28 20 27 6d 79 5f 70  c_Execute( 'my_p
6700: 72 6f 63 27 2c 20 27 40 73 72 69 64 40 3d 33 30  roc', '@srid@=30
6710: 30 34 27 2c 20 27 40 79 65 61 72 40 3d 32 30 30  04', '@year@=200
6720: 31 27 2c 20 27 40 72 65 67 69 6f 6e 40 3d 4c 61  1', '@region@=La
6730: 7a 69 6f 27 2c 20 27 40 73 68 70 5f 70 61 74 68  zio', '@shp_path
6740: 40 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73  @=C:/users/joe/s
6750: 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f  tored_proc_test/
6760: 6c 61 7a 69 6f 5f 32 30 30 31 5f 33 30 30 34 27  lazio_2001_3004'
6770: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a  );..-----..1....
6780: 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f  SELECT StoredPro
6790: 63 5f 45 78 65 63 75 74 65 28 20 27 6d 79 5f 70  c_Execute( 'my_p
67a0: 72 6f 63 27 2c 20 27 40 73 72 69 64 40 3d 34 33  roc', '@srid@=43
67b0: 32 36 27 2c 20 27 40 79 65 61 72 40 3d 31 39 39  26', '@year@=199
67c0: 31 27 2c 20 27 40 72 65 67 69 6f 6e 40 3d 70 75  1', '@region@=pu
67d0: 67 6c 69 61 27 2c 20 27 40 73 68 70 5f 70 61 74  glia', '@shp_pat
67e0: 68 40 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f  h@=C:/users/joe/
67f0: 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74  stored_proc_test
6800: 2f 70 75 67 6c 69 61 5f 31 39 39 31 5f 34 33 32  /puglia_1991_432
6810: 36 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a  6');..-----..1..
6820: 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50  ..SELECT StoredP
6830: 72 6f 63 5f 45 78 65 63 75 74 65 28 20 27 6d 79  roc_Execute( 'my
6840: 5f 70 72 6f 63 27 2c 20 27 40 73 72 69 64 40 3d  _proc', '@srid@=
6850: 33 30 30 33 27 2c 20 27 40 79 65 61 72 40 3d 32  3003', '@year@=2
6860: 30 31 31 27 2c 20 27 40 70 72 6f 76 69 6e 63 65  011', '@province
6870: 40 3d 41 52 45 5a 5a 4f 27 2c 20 27 40 73 68 70  @=AREZZO', '@shp
6880: 5f 70 61 74 68 40 3d 43 3a 2f 75 73 65 72 73 2f  _path@=C:/users/
6890: 6a 6f 65 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f  joe/stored_proc_
68a0: 74 65 73 74 2f 61 72 65 7a 7a 6f 5f 32 30 31 31  test/arezzo_2011
68b0: 5f 33 30 30 33 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d  _3003');..-----.
68c0: 0a 31 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 74 6f  .1....SELECT Sto
68d0: 72 65 64 50 72 6f 63 5f 45 78 65 63 75 74 65 28  redProc_Execute(
68e0: 20 27 6d 79 5f 70 72 6f 63 27 2c 20 27 40 73 72   'my_proc', '@sr
68f0: 69 64 40 3d 33 30 30 33 27 2c 20 27 40 79 65 61  id@=3003', '@yea
6900: 72 40 3d 32 30 30 31 27 2c 20 27 40 6d 75 6e 69  r@=2001', '@muni
6910: 63 69 70 61 6c 69 74 79 40 3d 41 52 45 5a 5a 4f  cipality@=AREZZO
6920: 27 2c 20 27 40 73 68 70 5f 70 61 74 68 40 3d 43  ', '@shp_path@=C
6930: 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72  :/users/joe/stor
6940: 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f 63 6f 6d  ed_proc_test/com
6950: 5f 61 72 65 7a 7a 6f 5f 32 30 30 31 5f 33 30 30  _arezzo_2001_300
6960: 33 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a  3');..-----..1..
6970: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 45 78 65  </verbatim>..Exe
6980: 63 75 74 69 6e 67 20 61 20 53 74 6f 72 65 64 20  cuting a Stored 
6990: 50 72 6f 63 65 64 75 72 65 20 69 73 6e 27 74 20  Procedure isn't 
69a0: 76 65 72 79 20 64 69 66 66 65 72 65 6e 74 20 66  very different f
69b0: 72 6f 6d 20 65 78 65 63 75 74 69 6e 67 20 61 20  rom executing a 
69c0: 50 72 6f 63 65 64 75 72 65 20 73 74 6f 72 65 64  Procedure stored
69d0: 20 69 6e 74 6f 20 61 6e 20 65 78 74 65 72 6e 61   into an externa
69e0: 6c 20 66 69 6c 65 2e 3c 62 72 3e 0d 0a 3c 74 61  l file.<br>..<ta
69f0: 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 66 38  ble bgcolor="#f8
6a00: 66 38 64 38 22 20 63 65 6c 6c 70 61 64 64 69 6e  f8d8" cellpaddin
6a10: 67 3d 22 36 22 20 63 65 6c 6c 73 70 61 63 69 6e  g="6" cellspacin
6a20: 67 3d 22 38 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a  g="8"><tr><td>..
6a30: 45 78 65 63 75 74 69 6e 67 20 79 6f 75 72 20 50  Executing your P
6a40: 72 6f 63 65 64 75 72 65 73 20 66 72 6f 6d 20 65  rocedures from e
6a50: 78 74 65 72 6e 61 6c 20 66 69 6c 65 73 20 6f 72  xternal files or
6a60: 20 70 65 72 6d 61 6e 65 6e 74 6c 79 20 72 65 67   permanently reg
6a70: 69 73 74 65 72 69 6e 67 20 53 74 6f 72 65 64 20  istering Stored 
6a80: 50 72 6f 63 65 64 75 72 65 73 20 64 69 72 65 63  Procedures direc
6a90: 74 6c 79 20 77 69 74 68 69 6e 20 61 20 64 61 74  tly within a dat
6aa0: 61 62 61 73 65 20 69 73 20 61 20 6d 61 74 74 65  abase is a matte
6ab0: 72 20 6f 66 20 66 72 65 65 20 63 68 6f 69 63 65  r of free choice
6ac0: 2e 3c 62 72 3e 0d 0a 49 66 20 79 6f 75 20 61 72  .<br>..If you ar
6ad0: 65 20 70 6c 61 6e 6e 69 6e 67 20 74 6f 20 64 65  e planning to de
6ae0: 70 6c 6f 79 20 61 20 50 72 6f 63 65 64 75 72 65  ploy a Procedure
6af0: 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 73 75 70   intended to sup
6b00: 70 6f 72 74 20 6d 61 6e 79 20 64 69 66 66 65 72  port many differ
6b10: 65 6e 74 20 64 61 74 61 62 61 73 65 73 2c 20 74  ent databases, t
6b20: 68 65 6e 20 75 73 69 6e 67 20 61 6e 20 65 78 74  hen using an ext
6b30: 65 72 6e 61 6c 20 66 69 6c 65 20 63 6f 75 6c 64  ernal file could
6b40: 20 70 72 6f 62 61 62 6c 79 20 73 69 6d 70 6c 69   probably simpli
6b50: 66 79 20 79 6f 75 72 20 77 6f 72 6b 2e 3c 62 72  fy your work.<br
6b60: 3e 0d 0a 42 75 74 20 69 66 20 79 6f 75 20 61 72  >..But if you ar
6b70: 65 20 70 6c 61 6e 6e 69 6e 67 20 74 6f 20 64 65  e planning to de
6b80: 70 6c 6f 79 20 61 20 50 72 6f 63 65 64 75 72 65  ploy a Procedure
6b90: 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 61 75 74   intended to aut
6ba0: 6f 6d 61 74 65 20 6d 61 6e 79 20 72 6f 75 74 69  omate many routi
6bb0: 6e 65 6c 79 20 74 61 73 6b 20 74 6f 20 62 65 20  nely task to be 
6bc0: 65 78 65 63 75 74 65 64 20 6f 66 74 65 6e 20 6f  executed often o
6bd0: 6e 20 74 68 65 20 73 61 6d 65 20 64 61 74 61 62  n the same datab
6be0: 61 73 65 2c 20 74 68 65 6e 20 70 65 72 6d 61 6e  ase, then perman
6bf0: 65 6e 74 6c 79 20 72 65 67 69 73 74 65 72 69 6e  ently registerin
6c00: 67 20 61 20 53 74 6f 72 65 64 20 50 72 6f 63 65  g a Stored Proce
6c10: 64 75 72 65 20 77 6f 75 6c 64 20 70 72 6f 62 61  dure would proba
6c20: 62 6c 79 20 62 65 20 62 65 74 74 65 72 20 61 6e  bly be better an
6c30: 64 20 66 61 73 74 65 72 2e 0d 0a 3c 2f 74 64 3e  d faster...</td>
6c40: 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c  </tr></table>..<
6c50: 62 72 3e 3c 68 72 3e 0d 0a 3c 68 32 3e 54 75 74  br><hr>..<h2>Tut
6c60: 6f 72 69 61 6c 20 23 33 3c 2f 68 32 3e 0d 0a 54  orial #3</h2>..T
6c70: 68 69 73 20 6c 61 73 74 20 74 75 74 6f 72 69 61  his last tutoria
6c80: 6c 20 69 73 20 6a 75 73 74 20 61 20 73 6d 61 6c  l is just a smal
6c90: 6c 20 76 61 72 69 61 74 69 6f 6e 20 6f 6e 20 74  l variation on t
6ca0: 68 65 20 74 68 65 6d 65 20 69 6e 74 65 6e 64 65  he theme intende
6cb0: 64 20 74 6f 20 68 69 67 68 6c 69 67 68 74 20 73  d to highlight s
6cc0: 6f 6d 65 20 70 6f 74 65 6e 74 69 61 6c 6c 79 20  ome potentially 
6cd0: 64 61 6e 67 65 72 6f 75 73 20 70 69 74 66 61 6c  dangerous pitfal
6ce0: 6c 73 20 72 65 6c 61 74 65 64 20 74 6f 20 3c 62  ls related to <b
6cf0: 3e 73 69 6e 67 6c 65 2d 71 75 6f 74 69 6e 67 3c  >single-quoting<
6d00: 2f 62 3e 2e 20 0d 0a 3c 76 65 72 62 61 74 69 6d  /b>. ..<verbatim
6d10: 3e 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64  >..SELECT Stored
6d20: 50 72 6f 63 5f 45 78 65 63 75 74 65 28 20 27 6d  Proc_Execute( 'm
6d30: 79 5f 70 72 6f 63 27 29 2c 20 27 40 73 72 69 64  y_proc'), '@srid
6d40: 40 3d 33 30 30 33 27 2c 20 27 40 79 65 61 72 40  @=3003', '@year@
6d50: 3d 32 30 31 31 27 2c 20 27 40 6d 75 6e 69 63 69  =2011', '@munici
6d60: 70 61 6c 69 74 79 40 3d 72 69 6f 20 6e 65 6c 6c  pality@=rio nell
6d70: 27 27 65 6c 62 61 27 2c 20 27 40 73 68 70 5f 70  ''elba', '@shp_p
6d80: 61 74 68 40 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f  ath@=C:/users/jo
6d90: 65 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65  e/stored_proc_te
6da0: 73 74 2f 72 69 6f 5f 65 6c 62 61 5f 32 30 31 31  st/rio_elba_2011
6db0: 5f 33 30 30 33 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d  _3003');..-----.
6dc0: 0a 53 74 6f 72 65 64 50 72 6f 63 20 65 78 63 65  .StoredProc exce
6dd0: 70 74 69 6f 6e 20 2d 20 61 20 66 61 74 61 6c 20  ption - a fatal 
6de0: 53 51 4c 20 65 72 72 6f 72 20 77 61 73 20 65 6e  SQL error was en
6df0: 63 6f 75 6e 74 65 72 65 64 2e 0d 0a 0d 0a 53 45  countered.....SE
6e00: 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 47 65 74  LECT SqlProc_Get
6e10: 4c 61 73 74 45 72 72 6f 72 28 29 3b 0d 0a 2d 2d  LastError();..--
6e20: 2d 2d 2d 0d 0a 67 61 69 61 5f 73 71 6c 5f 70 72  ---..gaia_sql_pr
6e30: 6f 63 5f 65 78 65 63 75 74 65 3a 20 6e 65 61 72  oc_execute: near
6e40: 20 22 65 6c 62 61 22 3a 20 73 79 6e 74 61 78 20   "elba": syntax 
6e50: 65 72 72 6f 72 0d 0a 3c 2f 76 65 72 62 61 74 69  error..</verbati
6e60: 6d 3e 0d 0a 54 68 69 73 20 66 69 72 73 74 20 61  m>..This first a
6e70: 74 74 65 6d 70 74 20 77 69 6c 6c 20 66 61 69 6c  ttempt will fail
6e80: 2c 20 61 6e 64 20 75 73 69 6e 67 20 3c 62 3e 53  , and using <b>S
6e90: 71 6c 50 72 6f 63 5f 47 65 74 4c 61 73 74 45 72  qlProc_GetLastEr
6ea0: 72 6f 72 3c 2f 62 3e 20 77 69 6c 6c 20 65 78 70  ror</b> will exp
6eb0: 6c 61 69 6e 20 77 68 79 20 69 74 20 66 61 69 6c  lain why it fail
6ec0: 65 64 3c 62 72 3e 0d 0a 57 65 27 76 65 20 70 61  ed<br>..We've pa
6ed0: 73 73 65 64 20 61 20 3c 62 3e 27 40 6d 75 6e 69  ssed a <b>'@muni
6ee0: 63 69 70 61 6c 69 74 79 40 3d 72 69 6f 20 6e 65  cipality@=rio ne
6ef0: 6c 6c 27 27 65 6c 62 61 27 3c 2f 62 3e 20 56 61  ll''elba'</b> Va
6f00: 72 69 61 62 6c 65 20 77 69 74 68 20 56 61 6c 75  riable with Valu
6f10: 65 2c 20 74 68 61 74 20 77 69 6c 6c 20 6c 65 61  e, that will lea
6f20: 64 20 74 6f 20 61 20 3c 62 3e 63 6f 6f 6b 65 64  d to a <b>cooked
6f30: 3c 2f 62 3e 20 57 48 45 52 45 20 63 6c 61 75 73  </b> WHERE claus
6f40: 65 20 6c 69 6b 65 20 74 68 69 73 3a 0d 0a 3c 76  e like this:..<v
6f50: 65 72 62 61 74 69 6d 3e 0d 0a 57 48 45 52 45 20  erbatim>..WHERE 
6f60: 28 55 70 70 65 72 28 6e 61 6d 65 29 20 3d 20 55  (Upper(name) = U
6f70: 70 70 65 72 28 27 72 69 6f 20 6e 65 6c 6c 27 65  pper('rio nell'e
6f80: 6c 62 61 27 29 20 4f 52 20 55 70 70 65 72 28 70  lba') OR Upper(p
6f90: 72 6f 76 69 6e 63 65 29 20 3d 20 55 70 70 65 72  rovince) = Upper
6fa0: 28 27 4e 55 4c 4c 27 29 20 4f 52 20 55 70 70 65  ('NULL') OR Uppe
6fb0: 72 28 72 65 67 69 6f 6e 29 20 3d 20 55 70 70 65  r(region) = Uppe
6fc0: 72 28 27 4e 55 4c 4c 27 29 29 0d 0a 3c 2f 76 65  r('NULL'))..</ve
6fd0: 72 62 61 74 69 6d 3e 0d 0a 54 68 65 2c 20 6e 6f  rbatim>..The, no
6fe0: 74 20 61 6c 77 61 79 73 20 6f 62 76 69 6f 75 73  t always obvious
6ff0: 20 63 61 75 73 65 2c 20 69 73 20 74 68 61 74 20   cause, is that 
7000: 3c 62 3e 27 72 69 6f 20 6e 65 6c 6c 27 65 6c 62  <b>'rio nell'elb
7010: 61 27 3c 2f 62 3e 20 69 73 20 61 6e 20 69 6c 6c  a'</b> is an ill
7020: 65 67 61 6c 20 53 51 4c 20 74 65 78 74 20 73 74  egal SQL text st
7030: 72 69 6e 67 3b 20 74 68 65 20 63 6f 72 72 65 63  ring; the correc
7040: 74 20 73 79 6e 74 61 78 20 73 68 6f 75 6c 64 20  t syntax should 
7050: 62 65 20 69 6e 73 74 65 61 64 20 3c 62 3e 27 72  be instead <b>'r
7060: 69 6f 20 6e 65 6c 6c 27 27 65 6c 62 61 27 3c 2f  io nell''elba'</
7070: 62 3e 2e 0d 0a 3c 62 72 3e 3c 62 72 3e 0d 0a 3c  b>...<br><br>..<
7080: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43  verbatim>..SELEC
7090: 54 20 53 74 6f 72 65 64 50 72 6f 63 5f 45 78 65  T StoredProc_Exe
70a0: 63 75 74 65 28 20 27 6d 79 5f 70 72 6f 63 27 29  cute( 'my_proc')
70b0: 2c 20 27 40 73 72 69 64 40 3d 33 30 30 33 27 2c  , '@srid@=3003',
70c0: 20 27 40 79 65 61 72 40 3d 32 30 31 31 27 2c 20   '@year@=2011', 
70d0: 27 40 6d 75 6e 69 63 69 70 61 6c 69 74 79 40 3d  '@municipality@=
70e0: 72 69 6f 20 6e 65 6c 6c 27 27 27 27 65 6c 62 61  rio nell''''elba
70f0: 27 2c 20 27 40 73 68 70 5f 70 61 74 68 40 3d 43  ', '@shp_path@=C
7100: 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72  :/users/joe/stor
7110: 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f 72 69 6f  ed_proc_test/rio
7120: 5f 65 6c 62 61 5f 32 30 31 31 5f 33 30 30 33 27  _elba_2011_3003'
7130: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f  );..-----..1..</
7140: 76 65 72 62 61 74 69 6d 3e 0d 0a 52 65 73 6f 6c  verbatim>..Resol
7150: 76 69 6e 67 20 73 75 63 68 20 61 6e 20 69 73 73  ving such an iss
7160: 75 65 20 69 73 20 72 61 74 68 65 72 20 74 72 69  ue is rather tri
7170: 76 69 61 6c 3b 20 77 65 20 6a 75 73 74 20 68 61  vial; we just ha
7180: 76 65 20 74 6f 20 75 73 65 20 3c 62 3e 66 6f 75  ve to use <b>fou
7190: 72 3c 2f 62 3e 20 63 6f 6e 73 65 63 75 74 69 76  r</b> consecutiv
71a0: 65 20 73 69 6e 67 6c 65 2d 71 75 6f 74 65 73 20  e single-quotes 
71b0: 73 6f 20 74 6f 20 63 6f 72 72 65 63 74 6c 79 20  so to correctly 
71c0: 65 73 63 61 70 65 20 74 68 65 20 73 74 72 69 6e  escape the strin
71d0: 67 20 76 61 6c 75 65 20 6f 72 3c 62 72 3e 20 75  g value or<br> u
71e0: 73 65 20 64 6f 75 62 6c 65 20 71 75 6f 74 65 73  se double quotes
71f0: 20 66 6f 72 20 66 69 65 6c 64 73 20 77 68 65 72   for fields wher
7200: 65 20 73 69 6e 67 6c 65 20 71 75 6f 74 65 73 20  e single quotes 
7210: 6f 66 74 65 6e 20 6f 63 63 75 72 20 69 6e 20 6e  often occur in n
7220: 61 6d 65 73 20 28 3c 62 3e 22 40 6d 75 6e 69 63  ames (<b>"@munic
7230: 69 70 61 6c 69 74 79 40 3d 72 69 6f 20 6e 65 6c  ipality@=rio nel
7240: 6c 27 65 6c 62 61 22 3c 2f 62 3e 29 2e 0d 0a 3c  l'elba"</b>)...<
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 31 62 34 66 31 37 31 61 61 61 33 39 34 66  Z 1b4f171aaa394f
7350: 61 39 33 65 64 33 39 61 61 32 37 34 61 61 31 34  a93ed39aa274aa14
7360: 63 34 0a                                         c4.