Hex Artifact Content
Not logged in

Artifact 144ebd540de733c61000f31b35261b2a5885e2a4:

Wiki page [Stored Procedures] by sandro 2017-12-22 09:34:33.
0000: 44 20 32 30 31 37 2d 31 32 2d 32 32 54 30 39 3a  D 2017-12-22T09:
0010: 33 34 3a 33 33 2e 34 38 35 0a 4c 20 53 74 6f 72  34:33.485.L Stor
0020: 65 64 5c 73 50 72 6f 63 65 64 75 72 65 73 0a 50  ed\sProcedures.P
0030: 20 65 64 38 38 30 63 37 64 38 39 65 65 36 38 34   ed880c7d89ee684
0040: 62 34 61 35 33 36 66 37 31 39 38 39 63 34 63 37  b4a536f71989c4c7
0050: 31 33 36 65 38 61 38 39 37 0a 55 20 73 61 6e 64  136e8a897.U sand
0060: 72 6f 0a 57 20 34 33 33 33 38 0a 3c 74 61 62 6c  ro.W 43338.<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 3c 62 72 3e  /tr></table><br>
37b0: 0d 0a 3c 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72  ..<table bgcolor
37c0: 3d 22 23 66 38 63 38 63 38 22 20 63 65 6c 6c 70  ="#f8c8c8" cellp
37d0: 61 64 64 69 6e 67 3d 22 36 22 20 63 65 6c 6c 73  adding="6" cells
37e0: 70 61 63 69 6e 67 3d 22 38 22 3e 3c 74 72 3e 3c  pacing="8"><tr><
37f0: 74 64 3e 0d 0a 3c 75 3e 57 61 72 6e 69 6e 67 3c  td>..<u>Warning<
3800: 2f 75 3e 3a 20 72 65 66 65 72 65 6e 63 69 6e 67  /u>: referencing
3810: 20 61 20 56 61 72 69 61 62 6c 65 20 66 72 6f 6d   a Variable from
3820: 20 77 69 74 68 69 6e 20 61 6e 6f 74 68 65 72 20   within another 
3830: 56 61 72 69 61 62 6c 65 20 69 73 20 6e 6f 74 20  Variable is not 
3840: 70 65 72 6d 69 74 74 65 64 2e 0d 0a 3c 76 65 72  permitted...<ver
3850: 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53  batim>..SELECT S
3860: 71 6c 50 72 6f 63 5f 43 6f 6f 6b 65 64 53 51 4c  qlProc_CookedSQL
3870: 20 28 20 53 71 6c 50 72 6f 63 5f 46 72 6f 6d 54   ( SqlProc_FromT
3880: 65 78 74 28 27 53 45 4c 45 43 54 20 40 63 6f 6c  ext('SELECT @col
3890: 40 20 46 52 4f 4d 20 40 74 62 6c 40 3b 27 29 2c  @ FROM @tbl@;'),
38a0: 0d 0a 20 20 20 20 27 40 63 6f 6c 40 3d 66 69 72  ..    '@col@=fir
38b0: 73 74 5f 6e 61 6d 65 27 2c 0d 0a 20 20 20 20 27  st_name',..    '
38c0: 40 63 6f 75 6e 74 72 79 40 3d 69 74 61 6c 79 27  @country@=italy'
38d0: 2c 0d 0a 20 20 20 20 27 40 74 62 6c 40 3d 40 63  ,..    '@tbl@=@c
38e0: 6f 75 6e 74 72 79 40 5f 70 68 6f 6e 65 5f 62 6f  ountry@_phone_bo
38f0: 6f 6b 27 20 29 3b 0d 0a 3c 2f 76 65 72 62 61 74  ok' );..</verbat
3900: 69 6d 3e 0d 0a 49 6e 20 74 68 65 20 61 62 6f 76  im>..In the abov
3910: 65 20 65 78 61 6d 70 6c 65 20 74 68 65 20 3c 62  e example the <b
3920: 3e 40 63 6f 75 6e 74 72 79 40 3c 2f 62 3e 20 74  >@country@</b> t
3930: 65 72 6d 20 69 6e 74 6f 20 74 68 65 20 56 61 6c  erm into the Val
3940: 75 65 20 73 74 72 69 6e 67 20 3c 69 3e 27 40 63  ue string <i>'@c
3950: 6f 75 6e 74 72 79 40 5f 70 68 6f 6e 65 5f 62 6f  ountry@_phone_bo
3960: 6f 6b 27 3c 2f 69 3e 20 77 69 6c 6c 20 6e 6f 74  ok'</i> will not
3970: 20 62 65 20 63 6f 6e 73 69 64 65 72 65 64 20 61   be considered a
3980: 73 20 61 20 56 61 72 69 61 62 6c 65 20 61 6e 64  s a Variable and
3990: 20 77 69 6c 6c 20 6e 6f 74 20 62 65 20 72 65 70   will not be rep
39a0: 6c 61 63 65 64 2e 0d 0a 3c 2f 74 64 3e 3c 2f 74  laced...</td></t
39b0: 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 62 72 3e  r></table>..<br>
39c0: 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69  <hr>..</li>..<li
39d0: 3e 0d 0a 3c 68 34 3e 45 78 65 63 75 74 69 6e 67  >..<h4>Executing
39e0: 20 61 20 53 51 4c 20 50 72 6f 63 65 64 75 72 65   a SQL Procedure
39f0: 3c 2f 68 34 3e 0d 0a 3c 76 65 72 62 61 74 69 6d  </h4>..<verbatim
3a00: 3e 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f  >..SELECT SqlPro
3a10: 63 5f 45 78 65 63 75 74 65 20 28 53 71 6c 50 72  c_Execute (SqlPr
3a20: 6f 63 5f 46 72 6f 6d 54 65 78 74 28 27 53 45 4c  oc_FromText('SEL
3a30: 45 43 54 20 40 63 6f 6c 40 20 46 52 4f 4d 20 40  ECT @col@ FROM @
3a40: 74 62 6c 40 3b 27 29 2c 0d 0a 20 20 20 20 27 40  tbl@;'),..    '@
3a50: 63 6f 6c 40 3d 66 69 72 73 74 5f 6e 61 6d 65 27  col@=first_name'
3a60: 2c 0d 0a 20 20 20 20 27 40 74 62 6c 40 3d 70 68  ,..    '@tbl@=ph
3a70: 6f 6e 65 5f 62 6f 6f 6b 27 20 29 3b 0d 0a 2d 2d  one_book' );..--
3a80: 2d 2d 2d 0d 0a 53 71 6c 50 72 6f 63 20 65 78 63  ---..SqlProc exc
3a90: 65 70 74 69 6f 6e 20 2d 20 61 20 66 61 74 61 6c  eption - a fatal
3aa0: 20 53 51 4c 20 65 72 72 6f 72 20 77 61 73 20 65   SQL error was e
3ab0: 6e 63 6f 75 6e 74 65 72 65 64 2e 0d 0a 0d 0a 53  ncountered.....S
3ac0: 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 47 65  ELECT SqlProc_Ge
3ad0: 74 4c 61 73 74 45 72 72 6f 72 28 29 3b 0d 0a 2d  tLastError();..-
3ae0: 2d 2d 2d 2d 0d 0a 67 61 69 61 5f 73 71 6c 5f 70  ----..gaia_sql_p
3af0: 72 6f 63 5f 65 78 65 63 75 74 65 3a 20 6e 6f 20  roc_execute: no 
3b00: 73 75 63 68 20 74 61 62 6c 65 3a 20 70 68 6f 6e  such table: phon
3b10: 65 5f 62 6f 6f 6b 0d 0a 3c 2f 76 65 72 62 61 74  e_book..</verbat
3b20: 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 75 73 65  im>..you can use
3b30: 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 45 78 65 63   <b>SqlProc_Exec
3b40: 75 74 65 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72  ute</b> in order
3b50: 20 74 6f 20 64 69 72 65 63 74 6c 79 20 65 78 65   to directly exe
3b60: 63 75 74 65 20 74 68 65 20 77 68 6f 6c 65 20 53  cute the whole S
3b70: 51 4c 20 42 6f 64 79 20 61 73 20 61 20 73 69 6e  QL Body as a sin
3b80: 67 6c 65 20 6d 6f 6e 6f 6c 69 74 68 69 63 20 75  gle monolithic u
3b90: 6e 69 74 2e 3c 62 72 3e 0d 0a 41 74 20 74 68 65  nit.<br>..At the
3ba0: 20 65 6e 64 20 6f 66 20 74 68 65 20 70 72 6f 63   end of the proc
3bb0: 65 73 73 20 3c 62 3e 31 3c 2f 62 3e 20 28 61 6b  ess <b>1</b> (ak
3bc0: 61 20 3c 62 3e 54 72 75 65 3c 2f 62 3e 29 20 77  a <b>True</b>) w
3bd0: 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 20  ill be returned 
3be0: 6f 6e 20 66 75 6c 6c 20 73 75 63 63 65 73 73 3b  on full success;
3bf0: 20 61 6e 20 45 78 63 65 70 74 69 6f 6e 20 77 69   an Exception wi
3c00: 6c 6c 20 62 65 20 72 61 69 73 65 64 20 6f 6e 20  ll be raised on 
3c10: 66 61 69 6c 75 72 65 2c 20 61 73 20 77 69 6c 6c  failure, as will
3c20: 20 68 61 70 70 65 6e 73 20 69 6e 20 74 68 69 73   happens in this
3c30: 20 73 61 6d 70 6c 65 2c 20 79 6f 75 20 63 61 6e   sample, you can
3c40: 20 74 68 65 6e 20 75 73 65 20 3c 62 3e 53 71 6c   then use <b>Sql
3c50: 50 72 6f 63 5f 47 65 74 4c 61 73 74 45 72 72 6f  Proc_GetLastErro
3c60: 72 3c 2f 62 3e 20 74 6f 20 72 65 74 72 69 65 76  r</b> to retriev
3c70: 65 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64  e the correspond
3c80: 69 6e 67 20 53 51 4c 20 65 72 72 6f 72 20 6d 65  ing SQL error me
3c90: 73 73 61 67 65 2e 0d 0a 3c 62 72 3e 3c 62 72 3e  ssage...<br><br>
3ca0: 0d 0a 3c 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72  ..<table bgcolor
3cb0: 3d 22 23 66 38 66 38 64 38 22 20 63 65 6c 6c 70  ="#f8f8d8" cellp
3cc0: 61 64 64 69 6e 67 3d 22 36 22 20 63 65 6c 6c 73  adding="6" cells
3cd0: 70 61 63 69 6e 67 3d 22 38 22 3e 3c 74 72 3e 3c  pacing="8"><tr><
3ce0: 74 64 3e 0d 0a 3c 75 3e 4e 6f 74 65 3c 2f 75 3e  td>..<u>Note</u>
3cf0: 3a 20 61 6c 6c 20 3c 62 3e 44 6f 74 20 4d 61 63  : all <b>Dot Mac
3d00: 72 6f 73 3c 2f 62 3e 20 66 6f 75 6e 64 20 77 69  ros</b> found wi
3d10: 74 68 69 6e 20 74 68 65 20 53 51 4c 20 42 6f 64  thin the SQL Bod
3d20: 79 20 62 65 69 6e 67 20 65 78 65 63 75 74 65 64  y being executed
3d30: 20 77 69 6c 6c 20 61 6c 77 61 79 73 20 62 65 20   will always be 
3d40: 69 67 6e 6f 72 65 64 2e 3c 62 72 3e 0d 0a 54 68  ignored.<br>..Th
3d50: 65 20 73 61 6d 65 20 72 75 6c 65 20 61 70 70 6c  e same rule appl
3d60: 69 65 73 20 74 6f 20 3c 62 3e 53 74 6f 72 65 64  ies to <b>Stored
3d70: 50 72 6f 63 5f 45 78 65 63 75 74 65 3c 2f 62 3e  Proc_Execute</b>
3d80: 20 61 73 20 77 65 6c 6c 2e 3c 2f 62 3e 0d 0a 3c   as well.</b>..<
3d90: 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65  /td></tr></table
3da0: 3e 0d 0a 3c 62 72 3e 3c 68 72 3e 0d 0a 3c 2f 6c  >..<br><hr>..</l
3db0: 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 48 61  i>..<li>..<h4>Ha
3dc0: 6e 64 6c 69 6e 67 20 53 51 4c 20 53 74 6f 72 65  ndling SQL Store
3dd0: 64 20 50 72 6f 63 65 64 75 72 65 73 3c 2f 68 34  d Procedures</h4
3de0: 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53  >..<verbatim>..S
3df0: 45 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f 63  ELECT StoredProc
3e00: 5f 43 72 65 61 74 65 54 61 62 6c 65 73 28 29 3b  _CreateTables();
3e10: 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65  ..-----..1..</ve
3e20: 72 62 61 74 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e  rbatim>..you can
3e30: 20 75 73 65 20 3c 62 3e 53 74 6f 72 65 64 50 72   use <b>StoredPr
3e40: 6f 63 5f 43 72 65 61 74 65 54 61 62 6c 65 73 3c  oc_CreateTables<
3e50: 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20  /b> in order to 
3e60: 63 72 65 61 74 65 2c 20 77 69 74 68 69 6e 20 79  create, within y
3e70: 6f 75 72 20 63 75 72 72 65 6e 74 6c 79 20 63 6f  our currently co
3e80: 6e 6e 65 63 74 65 64 20 64 61 74 61 62 61 73 65  nnected database
3e90: 2c 20 61 6c 6c 20 3c 62 3e 6d 65 74 61 74 61 62  , all <b>metatab
3ea0: 6c 65 73 3c 2f 62 3e 20 72 65 71 75 69 72 65 64  les</b> required
3eb0: 20 74 6f 20 70 65 72 6d 61 6e 65 6e 74 6c 79 20   to permanently 
3ec0: 72 65 67 69 73 74 65 72 20 53 74 6f 72 65 64 20  register Stored 
3ed0: 50 72 6f 63 65 64 75 72 65 73 20 61 6e 64 20 53  Procedures and S
3ee0: 74 6f 72 65 64 20 56 61 72 69 61 62 6c 65 73 2e  tored Variables.
3ef0: 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65  <br><br>..<table
3f00: 20 62 67 63 6f 6c 6f 72 3d 22 23 66 38 66 38 64   bgcolor="#f8f8d
3f10: 38 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22  8" cellpadding="
3f20: 36 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22  6" cellspacing="
3f30: 38 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 3c 75 3e  8"><tr><td>..<u>
3f40: 4e 6f 74 65 3c 2f 75 3e 3a 20 61 6e 79 20 6e 65  Note</u>: any ne
3f50: 77 20 64 61 74 61 62 61 73 65 20 63 72 65 61 74  w database creat
3f60: 65 64 20 62 79 20 53 70 61 74 69 61 4c 69 74 65  ed by SpatiaLite
3f70: 20 34 2e 35 2e 30 20 28 61 6e 64 20 73 75 62 73   4.5.0 (and subs
3f80: 65 71 75 65 6e 74 20 76 65 72 73 69 6f 6e 73 29  equent versions)
3f90: 20 77 69 6c 6c 20 61 75 74 6f 6d 61 74 69 63 61   will automatica
3fa0: 6c 6c 79 20 73 75 70 70 6f 72 74 20 74 68 65 20  lly support the 
3fb0: 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65  Stored Procedure
3fc0: 73 20 6d 65 74 61 74 61 62 6c 65 73 2e 20 45 78  s metatables. Ex
3fd0: 70 6c 69 63 69 74 6c 79 20 63 61 6c 6c 69 6e 67  plicitly calling
3fe0: 20 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 69   this function i
3ff0: 73 20 6d 61 69 6e 6c 79 20 75 73 65 64 20 69 6e  s mainly used in
4000: 20 6f 72 64 65 72 20 74 6f 20 61 64 64 20 53 74   order to add St
4010: 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65 73 20  ored Procedures 
4020: 73 75 70 70 6f 72 74 20 6f 6e 20 61 6c 72 65 61  support on alrea
4030: 64 79 20 65 78 69 73 74 69 6e 67 20 64 61 74 61  dy existing data
4040: 62 61 73 65 73 20 63 72 65 61 74 65 64 20 62 79  bases created by
4050: 20 70 72 65 76 69 6f 75 73 20 76 65 72 73 69 6f   previous versio
4060: 6e 73 2e 20 43 61 6c 6c 69 6e 67 20 3c 62 3e 53  ns. Calling <b>S
4070: 74 6f 72 65 64 50 72 6f 63 5f 43 72 65 61 74 65  toredProc_Create
4080: 54 61 62 6c 65 73 3c 2f 62 3e 20 6f 6e 20 62 65  Tables</b> on be
4090: 68 61 6c 66 20 6f 66 20 61 20 64 61 74 61 62 61  half of a databa
40a0: 73 65 20 61 6c 72 65 61 64 79 20 73 75 70 70 6f  se already suppo
40b0: 72 74 69 6e 67 20 74 68 65 20 53 74 6f 72 65 64  rting the Stored
40c0: 20 50 72 6f 63 65 64 75 72 65 73 20 6d 65 74 61   Procedures meta
40d0: 74 61 62 6c 65 20 69 73 20 61 6e 20 68 61 72 6d  table is an harm
40e0: 6c 65 73 73 20 6f 70 65 72 61 74 69 6f 6e 20 73  less operation s
40f0: 69 6d 70 6c 79 20 72 65 74 75 72 6e 69 6e 67 20  imply returning 
4100: 3c 62 3e 31 3c 2f 62 3e 20 28 66 75 6c 6c 20 73  <b>1</b> (full s
4110: 75 63 63 65 73 73 29 2e 0d 0a 3c 2f 74 64 3e 3c  uccess)...</td><
4120: 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 76  /tr></table>..<v
4130: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54  erbatim>..SELECT
4140: 20 53 74 6f 72 65 64 50 72 6f 63 5f 52 65 67 69   StoredProc_Regi
4150: 73 74 65 72 20 28 20 27 73 70 5f 31 27 2c 20 27  ster ( 'sp_1', '
4160: 61 20 73 61 6d 70 6c 65 20 53 74 6f 72 65 64 20  a sample Stored 
4170: 50 72 6f 63 65 64 75 72 65 20 66 6f 72 20 74 65  Procedure for te
4180: 73 74 69 6e 67 27 2c 20 53 71 6c 50 72 6f 63 5f  sting', SqlProc_
4190: 46 72 6f 6d 54 65 78 74 28 27 53 45 4c 45 43 54  FromText('SELECT
41a0: 20 40 63 6f 6c 40 20 46 52 4f 4d 20 40 74 62 6c   @col@ FROM @tbl
41b0: 40 3b 27 20 29 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a  @;' ));..-----..
41c0: 31 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a  1..</verbatim>..
41d0: 79 6f 75 20 63 61 6e 20 75 73 65 20 3c 62 3e 53  you can use <b>S
41e0: 74 6f 72 65 64 50 72 6f 63 5f 52 65 67 69 73 74  toredProc_Regist
41f0: 65 72 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20  er</b> in order 
4200: 74 6f 20 70 65 72 6d 61 6e 65 6e 74 6c 79 20 72  to permanently r
4210: 65 67 69 73 74 65 72 20 61 20 53 74 6f 72 65 64  egister a Stored
4220: 20 50 72 6f 63 65 64 75 72 65 2e 0d 0a 3c 76 65   Procedure...<ve
4230: 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20  rbatim>..SELECT 
4240: 53 74 6f 72 65 64 50 72 6f 63 5f 44 65 6c 65 74  StoredProc_Delet
4250: 65 20 28 20 27 73 70 5f 31 27 20 29 3b 0d 0a 2d  e ( 'sp_1' );..-
4260: 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61  ----..1..</verba
4270: 74 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 75 73  tim>..you can us
4280: 65 20 3c 62 3e 53 74 6f 72 65 64 50 72 6f 63 5f  e <b>StoredProc_
4290: 44 65 6c 65 74 65 3c 2f 62 3e 20 69 6e 20 6f 72  Delete</b> in or
42a0: 64 65 72 20 74 6f 20 70 65 72 6d 61 6e 65 6e 74  der to permanent
42b0: 6c 79 20 72 65 6d 6f 76 65 20 61 20 70 72 65 76  ly remove a prev
42c0: 69 6f 75 73 6c 79 20 72 65 67 69 73 74 65 72 65  iously registere
42d0: 64 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75  d Stored Procedu
42e0: 72 65 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d  re...<verbatim>.
42f0: 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f  .SELECT SqlProc_
4300: 52 61 77 53 51 4c 20 28 20 53 74 6f 72 65 64 50  RawSQL ( StoredP
4310: 72 6f 63 5f 47 65 74 20 28 20 27 73 70 5f 31 27  roc_Get ( 'sp_1'
4320: 20 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 53 45   ) );..-----..SE
4330: 4c 45 43 54 20 40 63 6f 6c 40 20 46 52 4f 4d 20  LECT @col@ FROM 
4340: 40 74 62 6c 40 3b 0d 0a 3c 2f 76 65 72 62 61 74  @tbl@;..</verbat
4350: 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 75 73 65  im>..you can use
4360: 20 3c 62 3e 53 74 6f 72 65 64 50 72 6f 63 5f 47   <b>StoredProc_G
4370: 65 74 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20  et</b> in order 
4380: 74 6f 20 72 65 74 72 69 65 76 65 20 74 68 65 20  to retrieve the 
4390: 53 51 4c 20 50 72 6f 63 65 64 75 72 65 20 42 4c  SQL Procedure BL
43a0: 4f 42 20 4f 62 6a 65 63 74 20 66 72 6f 6d 20 61  OB Object from a
43b0: 20 72 65 67 69 73 74 65 72 65 64 20 53 74 6f 72   registered Stor
43c0: 65 64 20 50 72 6f 63 65 64 75 72 65 2e 0d 0a 3c  ed Procedure...<
43d0: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43  verbatim>..SELEC
43e0: 54 20 53 74 6f 72 65 64 50 72 6f 63 5f 55 70 64  T StoredProc_Upd
43f0: 61 74 65 54 69 74 6c 65 20 28 20 27 73 70 5f 31  ateTitle ( 'sp_1
4400: 27 2c 20 27 74 68 69 73 20 54 69 74 6c 65 20 77  ', 'this Title w
4410: 61 73 20 63 68 61 6e 67 65 64 27 20 29 3b 0d 0a  as changed' );..
4420: 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62  -----..1..</verb
4430: 61 74 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 75  atim>..you can u
4440: 73 65 20 3c 62 3e 53 74 6f 72 65 64 50 72 6f 63  se <b>StoredProc
4450: 5f 55 70 64 61 74 65 54 69 74 6c 65 3c 2f 62 3e  _UpdateTitle</b>
4460: 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 6d 6f 64   in order to mod
4470: 69 66 79 20 74 68 65 20 54 69 74 6c 65 20 6f 66  ify the Title of
4480: 20 61 6e 20 61 6c 72 65 61 64 79 20 72 65 67 69   an already regi
4490: 73 74 65 72 65 64 20 53 74 6f 72 65 64 20 50 72  stered Stored Pr
44a0: 6f 63 65 64 75 72 65 2e 0d 0a 3c 76 65 72 62 61  ocedure...<verba
44b0: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 74 6f  tim>..SELECT Sto
44c0: 72 65 64 50 72 6f 63 5f 55 70 64 61 74 65 53 71  redProc_UpdateSq
44d0: 6c 42 6f 64 79 20 28 20 27 73 70 5f 31 27 2c 20  lBody ( 'sp_1', 
44e0: 53 71 6c 50 72 6f 63 5f 46 72 6f 6d 46 69 6c 65  SqlProc_FromFile
44f0: 28 27 2f 68 6f 6d 65 2f 6a 6f 65 2f 73 71 6c 5f  ('/home/joe/sql_
4500: 73 63 72 69 70 74 73 2f 73 74 6f 72 65 64 5f 70  scripts/stored_p
4510: 72 6f 63 5f 74 65 73 74 5f 76 32 2e 74 78 74 27  roc_test_v2.txt'
4520: 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c   );..-----..1..<
4530: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 79 6f 75 20  /verbatim>..you 
4540: 63 61 6e 20 75 73 65 20 3c 62 3e 53 74 6f 72 65  can use <b>Store
4550: 64 50 72 6f 63 5f 55 70 64 61 74 65 53 71 6c 42  dProc_UpdateSqlB
4560: 6f 64 79 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72  ody</b> in order
4570: 20 74 6f 20 6d 6f 64 69 66 79 20 74 68 65 20 53   to modify the S
4580: 71 6c 20 42 6f 64 79 20 6f 66 20 61 6e 20 61 6c  ql Body of an al
4590: 72 65 61 64 79 20 72 65 67 69 73 74 65 72 65 64  ready registered
45a0: 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72   Stored Procedur
45b0: 65 20 28 65 2e 67 2e 20 62 65 63 61 75 73 65 20  e (e.g. because 
45c0: 79 6f 75 27 76 65 20 64 69 73 63 6f 76 65 72 65  you've discovere
45d0: 64 20 61 6e 64 20 66 69 78 65 64 20 73 6f 6d 65  d and fixed some
45e0: 20 62 75 67 20 61 66 66 65 63 74 69 6e 67 20 74   bug affecting t
45f0: 68 65 20 70 72 65 76 69 6f 75 73 20 53 51 4c 20  he previous SQL 
4600: 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 29 2e  implementation).
4610: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45  <verbatim>..SELE
4620: 43 54 20 53 74 6f 72 65 64 50 72 6f 63 5f 45 78  CT StoredProc_Ex
4630: 65 63 75 74 65 20 28 20 27 73 70 5f 31 27 2c 0d  ecute ( 'sp_1',.
4640: 0a 20 20 20 20 27 40 63 6f 6c 40 3d 73 72 69 64  .    '@col@=srid
4650: 27 2c 0d 0a 20 20 20 20 27 40 74 62 6c 40 3d 73  ',..    '@tbl@=s
4660: 70 61 74 69 61 6c 5f 72 65 66 5f 73 79 73 27 20  patial_ref_sys' 
4670: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f  );..-----..1..</
4680: 76 65 72 62 61 74 69 6d 3e 0d 0a 61 6e 64 20 66  verbatim>..and f
4690: 69 6e 61 6c 6c 79 20 79 6f 75 20 63 61 6e 20 75  inally you can u
46a0: 73 65 20 3c 62 3e 53 74 6f 72 65 64 50 72 6f 63  se <b>StoredProc
46b0: 5f 45 78 65 63 75 74 65 3c 2f 62 3e 20 69 6e 20  _Execute</b> in 
46c0: 6f 72 64 65 72 20 74 6f 20 64 69 72 65 63 74 6c  order to directl
46d0: 79 20 65 78 65 63 75 74 65 20 61 20 53 74 6f 72  y execute a Stor
46e0: 65 64 20 50 72 6f 63 65 64 75 72 65 20 61 73 20  ed Procedure as 
46f0: 61 20 73 69 6e 67 6c 65 20 6d 6f 6e 6f 6c 69 74  a single monolit
4700: 68 69 63 20 75 6e 69 74 2e 3c 62 72 3e 0d 0a 3c  hic unit.<br>..<
4710: 62 72 3e 3c 62 72 3e 3c 68 72 3e 0d 0a 3c 2f 6c  br><br><hr>..</l
4720: 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 48 61  i>..<li>..<h4>Ha
4730: 6e 64 6c 69 6e 67 20 53 51 4c 20 53 74 6f 72 65  ndling SQL Store
4740: 64 20 56 61 72 69 61 62 6c 65 73 3c 2f 68 34 3e  d Variables</h4>
4750: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45  ..<verbatim>..SE
4760: 4c 45 43 54 20 53 74 6f 72 65 64 56 61 72 5f 52  LECT StoredVar_R
4770: 65 67 69 73 74 65 72 20 28 20 27 70 69 27 2c 20  egister ( 'pi', 
4780: 27 61 6e 20 75 6e 69 76 65 72 73 61 6c 6c 79 20  'an universally 
4790: 75 73 65 66 75 6c 20 63 6f 6e 73 74 61 6e 74 27  useful constant'
47a0: 2c 20 27 33 2e 31 34 27 20 29 3b 0d 0a 2d 2d 2d  , '3.14' );..---
47b0: 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69  --..1..</verbati
47c0: 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 75 73 65 20  m>..you can use 
47d0: 3c 62 3e 53 74 6f 72 65 64 56 61 72 5f 52 65 67  <b>StoredVar_Reg
47e0: 69 73 74 65 72 3c 2f 62 3e 20 69 6e 20 6f 72 64  ister</b> in ord
47f0: 65 72 20 74 6f 20 70 65 72 6d 61 6e 65 6e 74 6c  er to permanentl
4800: 79 20 72 65 67 69 73 74 65 72 20 61 20 53 74 6f  y register a Sto
4810: 72 65 64 20 56 61 72 69 61 62 6c 65 2e 0d 0a 3c  red Variable...<
4820: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43  verbatim>..SELEC
4830: 54 20 53 74 6f 72 65 64 56 61 72 5f 44 65 6c 65  T StoredVar_Dele
4840: 74 65 20 28 20 27 70 69 27 20 29 3b 0d 0a 2d 2d  te ( 'pi' );..--
4850: 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74  ---..1..</verbat
4860: 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 75 73 65  im>..you can use
4870: 20 3c 62 3e 53 74 6f 72 65 64 56 61 72 5f 44 65   <b>StoredVar_De
4880: 6c 65 74 65 3c 2f 62 3e 20 69 6e 20 6f 72 64 65  lete</b> in orde
4890: 72 20 74 6f 20 70 65 72 6d 61 6e 65 6e 74 6c 79  r to permanently
48a0: 20 72 65 6d 6f 76 65 20 61 20 70 72 65 76 69 6f   remove a previo
48b0: 75 73 6c 79 20 72 65 67 69 73 74 65 72 65 64 20  usly registered 
48c0: 53 74 6f 72 65 64 20 56 61 72 69 61 62 6c 65 2e  Stored Variable.
48d0: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45  ..<verbatim>..SE
48e0: 4c 45 43 54 20 53 74 6f 72 65 64 56 61 72 5f 47  LECT StoredVar_G
48f0: 65 74 20 28 20 27 70 69 27 20 29 3b 0d 0a 2d 2d  et ( 'pi' );..--
4900: 2d 2d 2d 0d 0a 40 50 49 40 3d 33 2e 31 34 0d 0a  ---..@PI@=3.14..
4910: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 79 6f 75  </verbatim>..you
4920: 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 74 6f 72   can use <b>Stor
4930: 65 64 56 61 72 5f 47 65 74 3c 2f 62 3e 20 69 6e  edVar_Get</b> in
4940: 20 6f 72 64 65 72 20 74 6f 20 72 65 74 72 69 65   order to retrie
4950: 76 65 20 74 68 65 20 56 61 72 69 61 62 6c 65 20  ve the Variable 
4960: 77 69 74 68 20 56 61 6c 75 65 20 73 74 72 69 6e  with Value strin
4970: 67 20 66 72 6f 6d 20 61 20 72 65 67 69 73 74 65  g from a registe
4980: 72 65 64 20 53 74 6f 72 65 64 20 56 61 72 69 61  red Stored Varia
4990: 62 6c 65 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e  ble...<verbatim>
49a0: 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64 56  ..SELECT StoredV
49b0: 61 72 5f 55 70 64 61 74 65 54 69 74 6c 65 20 28  ar_UpdateTitle (
49c0: 20 27 70 69 27 2c 20 27 50 49 20 2d 20 74 68 65   'pi', 'PI - the
49d0: 20 6d 61 67 69 63 20 6e 75 6d 62 65 72 27 20 29   magic number' )
49e0: 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76  ;..-----..1..</v
49f0: 65 72 62 61 74 69 6d 3e 0d 0a 79 6f 75 20 63 61  erbatim>..you ca
4a00: 6e 20 75 73 65 20 3c 62 3e 53 74 6f 72 65 64 56  n use <b>StoredV
4a10: 61 72 5f 55 70 64 61 74 65 54 69 74 6c 65 3c 2f  ar_UpdateTitle</
4a20: 62 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 6d  b> in order to m
4a30: 6f 64 69 66 79 20 74 68 65 20 54 69 74 6c 65 20  odify the Title 
4a40: 6f 66 20 61 6e 20 61 6c 72 65 61 64 79 20 72 65  of an already re
4a50: 67 69 73 74 65 72 65 64 20 53 74 6f 72 65 64 20  gistered Stored 
4a60: 50 72 6f 63 65 64 75 72 65 2e 0d 0a 3c 76 65 72  Procedure...<ver
4a70: 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53  batim>..SELECT S
4a80: 74 6f 72 65 64 56 61 72 5f 55 70 64 61 74 65 56  toredVar_UpdateV
4a90: 61 6c 75 65 20 28 20 27 70 69 27 2c 20 27 33 2e  alue ( 'pi', '3.
4aa0: 31 34 31 35 39 32 36 35 33 35 27 20 29 3b 0d 0a  1415926535' );..
4ab0: 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62  -----..1..</verb
4ac0: 61 74 69 6d 3e 0d 0a 61 6e 64 20 66 69 6e 61 6c  atim>..and final
4ad0: 6c 79 20 79 6f 75 20 63 61 6e 20 75 73 65 20 3c  ly you can use <
4ae0: 62 3e 53 74 6f 72 65 64 56 61 72 5f 55 70 64 61  b>StoredVar_Upda
4af0: 74 65 56 61 6c 75 65 3c 2f 62 3e 20 69 6e 20 6f  teValue</b> in o
4b00: 72 64 65 72 20 74 6f 20 6d 6f 64 69 66 79 20 74  rder to modify t
4b10: 68 65 20 56 61 72 69 61 62 6c 65 20 77 69 74 68  he Variable with
4b20: 20 56 61 6c 75 65 20 6f 66 20 61 6e 20 61 6c 72   Value of an alr
4b30: 65 61 64 79 20 72 65 67 69 73 74 65 72 65 64 20  eady registered 
4b40: 53 74 6f 72 65 64 20 56 61 72 69 61 62 6c 65 2e  Stored Variable.
4b50: 0d 0a 3c 2f 6c 69 3e 3c 62 72 3e 3c 68 72 3e 0d  ..</li><br><hr>.
4b60: 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 48 61 6e 64 6c  .<li>..<h4>Handl
4b70: 69 6e 67 20 74 68 65 20 53 51 4c 20 4c 6f 67 66  ing the SQL Logf
4b80: 69 6c 65 3c 2f 68 34 3e 0d 0a 3c 76 65 72 62 61  ile</h4>..<verba
4b90: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 71 6c  tim>..SELECT Sql
4ba0: 50 72 6f 63 5f 53 65 74 4c 6f 67 66 69 6c 65 20  Proc_SetLogfile 
4bb0: 28 20 27 2f 68 6f 6d 65 2f 73 61 6e 64 72 6f 2f  ( '/home/sandro/
4bc0: 73 71 6c 5f 6c 6f 67 2e 74 78 74 27 20 29 3b 0d  sql_log.txt' );.
4bd0: 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a 53 45 4c  .-----..1....SEL
4be0: 45 43 54 20 53 71 6c 50 72 6f 63 5f 53 65 74 4c  ECT SqlProc_SetL
4bf0: 6f 67 66 69 6c 65 20 28 20 27 2f 68 6f 6d 65 2f  ogfile ( '/home/
4c00: 73 61 6e 64 72 6f 2f 73 71 6c 5f 6c 6f 67 2e 74  sandro/sql_log.t
4c10: 78 74 27 2c 20 31 29 3b 0d 0a 2d 2d 2d 2d 2d 0d  xt', 1);..-----.
4c20: 0a 31 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 71 6c  .1....SELECT Sql
4c30: 50 72 6f 63 5f 53 65 74 4c 6f 67 66 69 6c 65 20  Proc_SetLogfile 
4c40: 28 20 4e 55 4c 4c 20 29 3b 0d 0a 2d 2d 2d 2d 2d  ( NULL );..-----
4c50: 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e  ..1..</verbatim>
4c60: 0d 0a 59 6f 75 20 63 61 6e 20 75 73 65 20 3c 62  ..You can use <b
4c70: 3e 53 71 6c 50 72 6f 63 5f 53 65 74 4c 6f 67 66  >SqlProc_SetLogf
4c80: 69 6c 65 28 29 3c 2f 62 3e 20 69 6e 20 6f 72 64  ile()</b> in ord
4c90: 65 72 20 74 6f 20 65 6e 61 62 6c 65 20 6f 72 20  er to enable or 
4ca0: 64 69 73 61 62 6c 65 20 74 68 65 20 53 51 4c 20  disable the SQL 
4cb0: 4c 6f 67 66 69 6c 65 3a 0d 0a 3c 75 6c 3e 0d 0a  Logfile:..<ul>..
4cc0: 3c 6c 69 3e 74 68 65 20 66 69 72 73 74 20 66 6f  <li>the first fo
4cd0: 72 6d 20 28 73 69 6e 67 6c 65 20 61 72 67 75 6d  rm (single argum
4ce0: 65 6e 74 29 20 6a 75 73 74 20 72 65 71 75 69 72  ent) just requir
4cf0: 65 73 20 74 6f 20 64 65 66 69 6e 65 20 74 68 65  es to define the
4d00: 20 3c 62 3e 61 62 73 6f 6c 75 74 65 3c 2f 62 3e   <b>absolute</b>
4d10: 20 6f 72 20 3c 62 3e 72 65 6c 61 74 69 76 65 20   or <b>relative 
4d20: 70 61 74 68 6e 61 6d 65 3c 2f 62 3e 20 6f 66 20  pathname</b> of 
4d30: 74 68 65 20 69 6e 74 65 6e 64 65 64 20 4c 6f 67  the intended Log
4d40: 66 69 6c 65 2e 3c 62 72 3e 0d 0a 41 20 4c 6f 67  file.<br>..A Log
4d50: 66 69 6c 65 20 64 65 66 69 6e 65 64 20 69 6e 20  file defined in 
4d60: 73 75 63 68 20 61 20 77 61 79 20 77 69 6c 6c 20  such a way will 
4d70: 61 6c 77 61 79 73 20 6f 70 65 72 61 74 65 20 69  always operate i
4d80: 6e 20 3c 62 3e 54 72 75 6e 63 61 74 65 3c 2f 62  n <b>Truncate</b
4d90: 3e 20 6d 6f 64 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c  > mode.</li>..<l
4da0: 69 3e 74 68 65 20 73 65 63 6f 6e 64 20 66 6f 72  i>the second for
4db0: 6d 20 28 74 77 6f 20 61 72 67 75 6d 65 6e 74 73  m (two arguments
4dc0: 29 20 73 75 70 70 6f 72 74 73 20 61 20 66 75 72  ) supports a fur
4dd0: 74 68 65 72 20 3c 62 3e 6d 6f 64 65 3c 2f 62 3e  ther <b>mode</b>
4de0: 20 61 72 67 75 6d 65 6e 74 3a 0d 0a 3c 75 6c 3e   argument:..<ul>
4df0: 0d 0a 3c 6c 69 3e 69 66 20 73 65 74 20 74 6f 20  ..<li>if set to 
4e00: 3c 62 3e 46 41 4c 53 45 3c 2f 62 3e 20 28 3c 62  <b>FALSE</b> (<b
4e10: 3e 30 3c 2f 62 3e 2c 20 64 65 66 61 75 6c 74 20  >0</b>, default 
4e20: 76 61 6c 75 65 29 20 74 68 65 20 4c 6f 67 66 69  value) the Logfi
4e30: 6c 65 20 77 69 6c 6c 20 6f 70 65 72 61 74 65 20  le will operate 
4e40: 69 6e 20 3c 62 3e 54 72 75 6e 63 61 74 65 3c 2f  in <b>Truncate</
4e50: 62 3e 20 6d 6f 64 65 2e 3c 2f 6c 69 3e 0d 0a 3c  b> mode.</li>..<
4e60: 6c 69 3e 69 66 20 73 65 74 20 74 6f 20 3c 62 3e  li>if set to <b>
4e70: 54 52 55 45 3c 2f 62 3e 20 28 61 6e 79 20 6f 74  TRUE</b> (any ot
4e80: 68 65 72 20 76 61 6c 75 65 20 64 69 66 66 65 72  her value differ
4e90: 65 6e 74 20 66 72 6f 6d 20 3c 62 3e 30 3c 2f 62  ent from <b>0</b
4ea0: 3e 29 20 74 68 65 20 4c 6f 67 66 69 6c 65 20 77  >) the Logfile w
4eb0: 69 6c 6c 20 6f 70 65 72 61 74 65 20 69 6e 20 3c  ill operate in <
4ec0: 62 3e 41 70 70 65 6e 64 3c 2f 62 3e 20 6d 6f 64  b>Append</b> mod
4ed0: 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a  e.</li>..</ul>..
4ee0: 3c 6c 69 3e 66 69 6e 61 6c 6c 79 2c 20 79 6f 75  <li>finally, you
4ef0: 20 63 61 6e 20 70 61 73 73 20 61 20 3c 62 3e 4e   can pass a <b>N
4f00: 55 4c 4c 3c 2f 62 3e 20 70 61 74 68 20 61 72 67  ULL</b> path arg
4f10: 75 6d 65 6e 74 20 69 6e 20 6f 72 64 65 72 20 74  ument in order t
4f20: 6f 20 69 6d 6d 65 64 69 61 74 65 6c 79 20 64 69  o immediately di
4f30: 73 61 62 6c 65 20 74 68 65 20 4c 6f 67 66 69 6c  sable the Logfil
4f40: 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 6c 69 3e 0d 0a  e.</li>..</li>..
4f50: 3c 2f 75 6c 3e 0d 0a 3c 76 65 72 62 61 74 69 6d  </ul>..<verbatim
4f60: 3e 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f  >..SELECT SqlPro
4f70: 63 5f 47 65 74 4c 6f 67 66 69 6c 65 28 29 3b 0d  c_GetLogfile();.
4f80: 0a 2d 2d 2d 2d 2d 0d 0a 2f 68 6f 6d 65 2f 73 61  .-----../home/sa
4f90: 6e 64 72 6f 2f 73 71 6c 5f 6c 6f 67 2e 74 78 74  ndro/sql_log.txt
4fa0: 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72  ....SELECT SqlPr
4fb0: 6f 63 5f 47 65 74 4c 6f 67 66 69 6c 65 28 29 3b  oc_GetLogfile();
4fc0: 0d 0a 2d 2d 2d 2d 2d 0d 0a 4e 55 4c 4c 0d 0a 3c  ..-----..NULL..<
4fd0: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 59 6f 75 20  /verbatim>..You 
4fe0: 63 61 6e 20 75 73 65 20 3c 62 3e 53 71 6c 50 72  can use <b>SqlPr
4ff0: 6f 63 5f 47 65 74 4c 6f 67 66 69 6c 65 28 29 3c  oc_GetLogfile()<
5000: 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20  /b> in order to 
5010: 63 68 65 63 6b 20 69 66 20 74 68 65 20 63 75 72  check if the cur
5020: 72 65 6e 74 20 44 42 2d 63 6f 6e 6e 65 63 74 69  rent DB-connecti
5030: 6f 6e 20 69 73 20 75 73 69 6e 67 20 61 20 4c 6f  on is using a Lo
5040: 67 66 69 6c 65 20 6f 72 20 6e 6f 74 2e 3c 62 72  gfile or not.<br
5050: 3e 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65 20 62 67  ><br>..<table bg
5060: 63 6f 6c 6f 72 3d 22 23 66 38 66 38 64 38 22 20  color="#f8f8d8" 
5070: 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 36 22 20  cellpadding="6" 
5080: 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 38 22 3e  cellspacing="8">
5090: 3c 74 72 3e 3c 74 64 3e 0d 0a 3c 75 3e 4e 6f 74  <tr><td>..<u>Not
50a0: 65 3c 2f 75 3e 3a 20 74 68 65 20 4c 6f 67 66 69  e</u>: the Logfi
50b0: 6c 65 20 73 65 74 74 69 6e 67 20 69 73 20 70 65  le setting is pe
50c0: 72 6d 61 6e 65 6e 74 20 6f 6e 20 61 20 70 65 72  rmanent on a per
50d0: 2d 63 6f 6e 6e 65 63 74 69 6f 6e 20 62 61 73 69  -connection basi
50e0: 73 2e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 6e  s...<ul>..<li>an
50f0: 79 20 6e 65 77 20 44 42 2d 63 6f 6e 6e 65 63 74  y new DB-connect
5100: 69 6f 6e 20 77 69 6c 6c 20 61 6c 77 61 79 73 20  ion will always 
5110: 73 74 61 72 74 20 62 79 20 6b 65 65 70 69 6e 67  start by keeping
5120: 20 74 68 65 20 4c 6f 67 66 69 6c 65 20 64 69 73   the Logfile dis
5130: 61 62 6c 65 64 2e 3c 62 72 3e 0d 0a 59 6f 75 20  abled.<br>..You 
5140: 61 72 65 20 61 6c 77 61 79 73 20 72 65 71 75 69  are always requi
5150: 72 65 64 20 74 6f 20 70 65 72 66 6f 72 6d 20 61  red to perform a
5160: 6e 20 65 78 70 6c 69 63 69 74 20 63 61 6c 6c 20  n explicit call 
5170: 74 6f 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 53 65  to <b>SqlProc_Se
5180: 74 4c 6f 67 66 69 6c 65 28 29 3c 2f 62 3e 20 69  tLogfile()</b> i
5190: 6e 20 6f 72 64 65 72 20 74 6f 20 65 66 66 65 63  n order to effec
51a0: 74 69 76 65 6c 79 20 65 6e 61 62 6c 65 20 61 20  tively enable a 
51b0: 4c 6f 67 66 69 6c 65 2e 3c 2f 6c 69 3e 0d 0a 3c  Logfile.</li>..<
51c0: 6c 69 3e 6f 6e 63 65 20 61 20 4c 6f 67 66 69 6c  li>once a Logfil
51d0: 65 20 68 61 73 20 62 65 65 6e 20 65 6e 61 62 6c  e has been enabl
51e0: 65 64 20 69 74 20 77 69 6c 6c 20 63 6f 6e 74 69  ed it will conti
51f0: 6e 75 65 20 74 6f 20 73 75 70 70 6f 72 74 20 74  nue to support t
5200: 68 65 20 63 75 72 72 65 6e 74 20 44 42 2d 63 6f  he current DB-co
5210: 6e 6e 65 63 74 69 6f 6e 20 64 75 72 69 6e 67 20  nnection during 
5220: 69 74 73 20 6c 69 66 65 73 70 61 6e 2c 20 69 66  its lifespan, if
5230: 20 6e 6f 74 20 62 65 65 6e 20 65 78 70 6c 69 63   not been explic
5240: 69 74 6c 79 20 64 69 73 61 62 6c 65 64 2e 3c 2f  itly disabled.</
5250: 6c 69 3e 0d 0a 3c 6c 69 3e 4c 6f 67 66 69 6c 65  li>..<li>Logfile
5260: 20 73 65 74 74 69 6e 67 73 20 61 72 65 20 73 74   settings are st
5270: 72 69 63 74 6c 79 20 63 6f 6e 66 69 6e 65 64 20  rictly confined 
5280: 77 69 74 68 69 6e 67 20 74 68 65 20 63 75 72 72  withing the curr
5290: 65 6e 74 20 44 42 2d 63 6f 6e 6e 65 63 74 69 6f  ent DB-connectio
52a0: 6e 2c 20 61 6e 64 20 77 69 6c 6c 20 6e 65 76 65  n, and will neve
52b0: 72 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 20  r automatically 
52c0: 62 65 20 63 6f 6e 74 69 6e 75 65 64 20 69 6e 20  be continued in 
52d0: 61 6e 79 20 66 6f 6c 6c 6f 77 69 6e 67 20 63 6f  any following co
52e0: 6e 6e 65 63 74 69 6f 6e 73 2e 3c 2f 6c 69 3e 0d  nnections.</li>.
52f0: 0a 3c 2f 75 6c 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74  .</ul>..</td></t
5300: 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 2f 6c 69  r></table>..</li
5310: 3e 0d 0a 3c 2f 6f 6c 3e 0d 0a 3c 62 72 3e 3c 68  >..</ol>..<br><h
5320: 72 3e 0d 0a 3c 68 32 3e 54 75 74 6f 72 69 61 6c  r>..<h2>Tutorial
5330: 20 23 31 3c 2f 68 32 3e 0d 0a 3c 74 61 62 6c 65   #1</h2>..<table
5340: 20 62 67 63 6f 6c 6f 72 3d 22 23 66 38 66 38 64   bgcolor="#f8f8d
5350: 38 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22  8" cellpadding="
5360: 36 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22  6" cellspacing="
5370: 38 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 41 6c 6c  8"><tr><td>..All
5380: 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 74   the following t
5390: 75 74 6f 72 69 61 6c 73 20 61 72 65 20 62 61 73  utorials are bas
53a0: 65 64 20 6f 6e 20 74 68 65 20 73 61 6d 65 20 73  ed on the same s
53b0: 61 6d 70 6c 65 20 64 61 74 61 62 61 73 65 2c 20  ample database, 
53c0: 77 68 69 63 68 20 73 68 6f 75 6c 64 20 62 65 20  which should be 
53d0: 3c 61 20 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f  <a href="http://
53e0: 77 77 77 2e 67 61 69 61 2d 67 69 73 2e 69 74 2f  www.gaia-gis.it/
53f0: 67 61 69 61 2d 73 69 6e 73 2f 73 70 5f 73 61 6d  gaia-sins/sp_sam
5400: 70 6c 65 5f 64 62 2e 37 7a 22 3e 64 6f 77 6e 6c  ple_db.7z">downl
5410: 6f 61 64 65 64 3c 2f 61 3e 20 62 65 66 6f 72 65  oaded</a> before
5420: 20 63 6f 6e 74 69 6e 75 69 6e 67 2e 0d 0a 3c 2f   continuing...</
5430: 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e  td></tr></table>
5440: 3c 62 72 3e 0d 0a 41 73 20 79 6f 75 20 63 61 6e  <br>..As you can
5450: 20 73 65 65 2c 20 74 68 69 73 20 64 61 74 61 62   see, this datab
5460: 61 73 65 20 63 6f 6e 74 61 69 6e 73 20 74 68 72  ase contains thr
5470: 65 65 20 53 70 61 74 69 61 6c 20 54 61 62 6c 65  ee Spatial Table
5480: 73 20 72 65 70 72 65 73 65 6e 74 69 6e 67 20 74  s representing t
5490: 68 65 20 3c 62 3e 3c 69 3e 41 64 6d 69 6e 69 73  he <b><i>Adminis
54a0: 74 72 61 74 69 76 65 20 42 6f 75 6e 64 61 72 69  trative Boundari
54b0: 65 73 3c 2f 69 3e 3c 2f 62 3e 20 6f 66 20 61 6c  es</i></b> of al
54c0: 6c 20 49 74 61 6c 69 61 6e 20 4d 75 6e 69 63 69  l Italian Munici
54d0: 70 61 6c 69 74 69 65 73 20 61 73 20 6f 66 66 69  palities as offi
54e0: 63 69 61 6c 6c 79 20 64 65 74 65 72 6d 69 6e 65  cially determine
54f0: 64 20 62 79 20 3c 61 20 68 72 65 66 3d 22 68 74  d by <a href="ht
5500: 74 70 73 3a 2f 2f 65 6e 2e 77 69 6b 69 70 65 64  tps://en.wikiped
5510: 69 61 2e 6f 72 67 2f 77 69 6b 69 2f 4e 61 74 69  ia.org/wiki/Nati
5520: 6f 6e 61 6c 5f 49 6e 73 74 69 74 75 74 65 5f 6f  onal_Institute_o
5530: 66 5f 53 74 61 74 69 73 74 69 63 73 5f 28 49 74  f_Statistics_(It
5540: 61 6c 79 29 22 3e 49 53 54 41 54 3c 2f 61 3e 3a  aly)">ISTAT</a>:
5550: 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 74 68 65 72  ..<ul>..<li>ther
5560: 65 20 61 72 65 20 74 68 72 65 65 20 64 69 66 66  e are three diff
5570: 65 72 65 6e 74 20 74 61 62 6c 65 73 2c 20 65 61  erent tables, ea
5580: 63 68 20 6f 6e 65 20 63 6f 72 72 65 73 70 6f 6e  ch one correspon
5590: 64 69 6e 67 20 74 6f 20 61 20 73 70 65 63 69 66  ding to a specif
55a0: 69 63 20 4e 61 74 69 6f 6e 61 6c 20 43 65 6e 73  ic National Cens
55b0: 75 73 20 28 79 65 61 72 73 20 31 39 39 31 2c 20  us (years 1991, 
55c0: 32 30 30 31 20 61 6e 64 20 32 30 31 31 20 61 72  2001 and 2011 ar
55d0: 65 20 61 76 61 69 6c 61 62 6c 65 29 2e 3c 2f 6c  e available).</l
55e0: 69 3e 0d 0a 3c 6c 69 3e 61 6c 6c 20 74 68 72 65  i>..<li>all thre
55f0: 65 20 74 61 62 6c 65 73 20 68 61 76 65 20 65 78  e tables have ex
5600: 61 63 74 6c 79 20 74 68 65 20 73 61 6d 65 20 6c  actly the same l
5610: 61 79 6f 75 74 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  ayout.</li>..<li
5620: 3e 41 64 6d 69 6e 69 73 74 72 61 74 69 76 65 20  >Administrative 
5630: 42 6f 75 6e 64 61 72 69 65 73 20 61 72 65 20 61  Boundaries are a
5640: 6c 77 61 79 73 20 72 65 70 72 65 73 65 6e 74 65  lways represente
5650: 64 20 61 73 20 4d 75 6c 74 69 50 6f 6c 79 67 6f  d as MultiPolygo
5660: 6e 73 20 28 53 72 69 64 3d 33 32 36 33 32 29 2e  ns (Srid=32632).
5670: 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d 0a 3c 74 61  ..</ul><br>..<ta
5680: 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 66 38  ble bgcolor="#f8
5690: 66 38 64 38 22 20 63 65 6c 6c 70 61 64 64 69 6e  f8d8" cellpaddin
56a0: 67 3d 22 36 22 20 63 65 6c 6c 73 70 61 63 69 6e  g="6" cellspacin
56b0: 67 3d 22 38 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a  g="8"><tr><td>..
56c0: 3c 68 34 3e 54 68 65 20 50 72 6f 62 6c 65 6d 3c  <h4>The Problem<
56d0: 2f 68 34 3e 0d 0a 57 65 27 6c 6c 20 69 6d 70 6c  /h4>..We'll impl
56e0: 65 6d 65 6e 74 20 61 20 3c 62 3e 50 72 6f 63 65  ement a <b>Proce
56f0: 64 75 72 65 3c 2f 62 3e 20 69 6e 74 65 6e 64 65  dure</b> intende
5700: 64 20 74 6f 20 65 78 70 6f 72 74 20 73 65 6c 65  d to export sele
5710: 63 74 65 64 20 53 68 61 70 65 66 69 6c 65 73 2e  cted Shapefiles.
5720: 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 54 68 65 20  ..<ul>..<li>The 
5730: 43 65 6e 73 75 73 20 59 65 61 72 20 6d 75 73 74  Census Year must
5740: 20 62 65 20 66 72 65 65 6c 79 20 73 65 6c 65 63   be freely selec
5750: 74 61 62 6c 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  table.</li>..<li
5760: 3e 41 20 72 65 71 75 69 72 65 64 20 66 65 61 74  >A required feat
5770: 75 72 65 20 69 73 20 61 6c 6c 6f 77 69 6e 67 20  ure is allowing 
5780: 65 69 74 68 65 72 20 66 69 6c 74 65 72 69 6e 67  either filtering
5790: 20 61 20 73 69 6e 67 6c 65 20 4d 75 6e 69 63 69   a single Munici
57a0: 70 61 6c 69 74 79 20 6f 72 20 6c 69 73 74 69 6e  pality or listin
57b0: 67 20 61 6c 6c 20 4d 75 6e 69 63 69 70 61 6c 69  g all Municipali
57c0: 74 69 65 73 20 62 65 6c 6f 6e 67 69 6e 67 20 74  ties belonging t
57d0: 6f 20 74 68 65 20 61 20 50 72 6f 76 69 6e 63 65  o the a Province
57e0: 20 6f 72 20 52 65 67 69 6f 6e 2e 3c 2f 6c 69 3e   or Region.</li>
57f0: 0d 0a 3c 6c 69 3e 52 65 70 72 6f 6a 65 63 74 69  ..<li>Reprojecti
5800: 6e 67 20 74 6f 20 73 6f 6d 65 20 61 6c 74 65 72  ng to some alter
5810: 6e 61 74 69 76 65 20 53 52 49 44 20 77 69 6c 6c  native SRID will
5820: 20 62 65 20 61 20 73 75 70 70 6f 72 74 65 64 20   be a supported 
5830: 66 65 61 74 75 72 65 2e 3c 2f 6c 69 3e 0d 0a 3c  feature.</li>..<
5840: 6c 69 3e 57 68 69 6c 65 20 64 6f 69 6e 67 20 61  li>While doing a
5850: 6c 6c 20 74 68 69 73 20 77 65 27 6c 6c 20 6f 62  ll this we'll ob
5860: 76 69 6f 75 73 6c 79 20 74 72 79 20 74 6f 20 74  viously try to t
5870: 61 6b 65 20 66 75 6c 6c 20 61 64 76 61 6e 74 61  ake full advanta
5880: 67 65 20 6f 66 20 75 73 69 6e 67 20 3c 62 3e 56  ge of using <b>V
5890: 61 72 69 61 62 6c 65 73 3c 2f 62 3e 20 74 6f 20  ariables</b> to 
58a0: 6d 61 6b 65 20 74 68 65 20 50 72 6f 63 65 64 75  make the Procedu
58b0: 72 65 20 61 73 20 67 65 6e 65 72 69 63 20 61 6e  re as generic an
58c0: 64 20 66 6c 65 78 69 62 6c 65 20 61 73 20 70 6f  d flexible as po
58d0: 73 73 69 62 6c 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f  ssible.</li>..</
58e0: 75 6c 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 3c  ul>..</td></tr><
58f0: 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 3c 76 65  /table><br>..<ve
5900: 72 62 61 74 69 6d 3e 0d 0a 2d 2d 0d 0a 2d 2d 20  rbatim>..--..-- 
5910: 72 65 6d 6f 76 69 6e 67 20 74 68 65 20 77 6f 72  removing the wor
5920: 6b 20 74 61 62 6c 65 20 28 6a 75 73 74 20 69 6e  k table (just in
5930: 20 63 61 73 65 20 69 74 20 61 6c 72 65 61 64 79   case it already
5940: 20 65 78 69 73 74 73 29 0d 0a 2d 2d 0d 0a 53 45   exists)..--..SE
5950: 4c 45 43 54 20 44 72 6f 70 47 65 6f 54 61 62 6c  LECT DropGeoTabl
5960: 65 28 27 74 72 61 6e 73 69 65 6e 74 5f 74 61 62  e('transient_tab
5970: 6c 65 27 29 3b 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20  le');....--..-- 
5980: 69 6e 73 65 72 74 69 6e 67 20 73 65 6c 65 63 74  inserting select
5990: 65 64 20 64 61 74 61 20 69 6e 74 6f 20 74 68 65  ed data into the
59a0: 20 77 6f 72 6b 20 74 61 62 6c 65 0d 0a 2d 2d 0d   work table..--.
59b0: 0a 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 72  .CREATE TABLE tr
59c0: 61 6e 73 69 65 6e 74 5f 74 61 62 6c 65 20 41 53  ansient_table AS
59d0: 0d 0a 53 45 4c 45 43 54 20 69 64 2c 20 69 73 74  ..SELECT id, ist
59e0: 61 74 2c 20 6e 61 6d 65 2c 20 70 72 6f 76 69 6e  at, name, provin
59f0: 63 65 2c 20 72 65 67 69 6f 6e 2c 20 53 54 5f 54  ce, region, ST_T
5a00: 72 61 6e 73 66 6f 72 6d 28 67 65 6f 6d 2c 20 40  ransform(geom, @
5a10: 73 72 69 64 40 29 20 41 53 20 67 65 6f 6d 0d 0a  srid@) AS geom..
5a20: 46 52 4f 4d 20 6d 75 6e 69 63 69 70 61 6c 69 74  FROM municipalit
5a30: 69 65 73 5f 40 79 65 61 72 40 0d 0a 57 48 45 52  ies_@year@..WHER
5a40: 45 20 28 55 70 70 65 72 28 6e 61 6d 65 29 20 3d  E (Upper(name) =
5a50: 20 55 70 70 65 72 28 27 40 6d 75 6e 69 63 69 70   Upper('@municip
5a60: 61 6c 69 74 79 40 27 29 20 4f 52 20 55 70 70 65  ality@') OR Uppe
5a70: 72 28 70 72 6f 76 69 6e 63 65 29 20 3d 20 55 70  r(province) = Up
5a80: 70 65 72 28 27 40 70 72 6f 76 69 6e 63 65 40 27  per('@province@'
5a90: 29 20 4f 52 20 55 70 70 65 72 28 72 65 67 69 6f  ) OR Upper(regio
5aa0: 6e 29 20 3d 20 55 70 70 65 72 28 27 40 72 65 67  n) = Upper('@reg
5ab0: 69 6f 6e 40 27 29 29 3b 0d 0a 0d 0a 2d 2d 0d 0a  ion@'));....--..
5ac0: 2d 2d 20 70 72 6f 70 65 72 6c 79 20 72 65 63 6f  -- properly reco
5ad0: 76 65 72 69 6e 67 20 74 68 65 20 77 6f 72 6b 20  vering the work 
5ae0: 74 61 62 6c 65 0d 0a 2d 2d 0d 0a 53 45 4c 45 43  table..--..SELEC
5af0: 54 20 52 65 63 6f 76 65 72 47 65 6f 6d 65 74 72  T RecoverGeometr
5b00: 79 43 6f 6c 75 6d 6e 28 27 74 72 61 6e 73 69 65  yColumn('transie
5b10: 6e 74 5f 74 61 62 6c 65 27 2c 20 27 67 65 6f 6d  nt_table', 'geom
5b20: 27 2c 20 40 73 72 69 64 40 2c 20 27 4d 55 4c 54  ', @srid@, 'MULT
5b30: 49 50 4f 4c 59 47 4f 4e 27 2c 20 27 58 59 27 29  IPOLYGON', 'XY')
5b40: 3b 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20 65 78 70 6f  ;....--..-- expo
5b50: 72 74 69 6e 67 20 66 72 6f 6d 20 74 68 65 20 77  rting from the w
5b60: 6f 72 6b 20 74 61 62 6c 65 20 69 6e 74 6f 20 74  ork table into t
5b70: 68 65 20 53 68 61 70 65 66 69 6c 65 0d 0a 2d 2d  he Shapefile..--
5b80: 0d 0a 53 45 4c 45 43 54 20 45 78 70 6f 72 74 53  ..SELECT ExportS
5b90: 68 70 28 27 74 72 61 6e 73 69 65 6e 74 5f 74 61  hp('transient_ta
5ba0: 62 6c 65 27 2c 20 27 67 65 6f 6d 27 2c 20 27 40  ble', 'geom', '@
5bb0: 73 68 70 5f 70 61 74 68 40 27 2c 20 27 43 50 31  shp_path@', 'CP1
5bc0: 32 35 32 27 29 3b 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d  252');....--..--
5bd0: 20 72 65 6d 6f 76 69 6e 67 20 74 68 65 20 77 6f   removing the wo
5be0: 72 6b 20 74 61 62 6c 65 0d 0a 2d 2d 0d 0a 53 45  rk table..--..SE
5bf0: 4c 45 43 54 20 44 72 6f 70 47 65 6f 54 61 62 6c  LECT DropGeoTabl
5c00: 65 28 27 74 72 61 6e 73 69 65 6e 74 5f 74 61 62  e('transient_tab
5c10: 6c 65 27 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69  le');..</verbati
5c20: 6d 3e 0d 0a 41 73 20 79 6f 75 20 63 61 6e 20 73  m>..As you can s
5c30: 65 65 20 74 68 65 20 70 72 6f 70 6f 73 65 64 20  ee the proposed 
5c40: 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 69  implementation i
5c50: 73 20 62 61 73 69 63 61 6c 6c 79 20 73 69 6d 70  s basically simp
5c60: 6c 65 2e 20 4e 6f 77 20 79 6f 75 20 73 69 6d 70  le. Now you simp
5c70: 6c 79 20 68 61 76 65 20 74 6f 20 3c 62 3e 63 75  ly have to <b>cu
5c80: 74 26 70 61 73 74 65 3c 2f 62 3e 20 74 68 65 20  t&paste</b> the 
5c90: 61 62 6f 76 65 20 53 51 4c 20 62 6f 64 79 20 73  above SQL body s
5ca0: 61 76 69 6e 67 20 69 74 20 69 6e 74 6f 20 61 20  aving it into a 
5cb0: 66 69 6c 65 20 6e 61 6d 65 64 20 3c 62 3e 74 65  file named <b>te
5cc0: 73 74 5f 73 70 2e 74 78 74 3c 2f 62 3e 20 66 6f  st_sp.txt</b> fo
5cd0: 72 20 66 75 72 74 68 65 72 20 75 73 61 67 65 2e  r further usage.
5ce0: 3c 62 72 3e 3c 62 72 3e 0d 0a 46 65 77 20 69 6e  <br><br>..Few in
5cf0: 74 65 72 65 73 74 69 6e 67 20 64 65 74 61 69 6c  teresting detail
5d00: 73 20 77 6f 72 74 68 20 62 65 69 6e 67 20 65 78  s worth being ex
5d10: 70 6c 61 69 6e 65 64 3a 0d 0a 3c 75 6c 3e 0d 0a  plained:..<ul>..
5d20: 3c 6c 69 3e 56 61 72 69 61 62 6c 65 20 3c 62 3e  <li>Variable <b>
5d30: 40 79 65 61 72 40 3c 2f 62 3e 20 69 73 20 69 6e  @year@</b> is in
5d40: 74 65 6e 64 65 64 20 74 6f 20 73 65 6c 65 63 74  tended to select
5d50: 20 77 68 69 63 68 20 73 70 65 63 69 66 69 63 20   which specific 
5d60: 53 70 61 74 69 61 6c 20 54 61 62 6c 65 20 77 69  Spatial Table wi
5d70: 6c 6c 20 62 65 20 71 75 65 72 69 65 64 2e 3c 2f  ll be queried.</
5d80: 6c 69 3e 0d 0a 3c 6c 69 3e 56 61 72 69 61 62 6c  li>..<li>Variabl
5d90: 65 20 3c 62 3e 40 73 72 69 64 40 3c 2f 62 3e 20  e <b>@srid@</b> 
5da0: 69 73 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 73  is intended to s
5db0: 70 65 63 69 66 79 20 74 68 65 20 6f 75 74 70 75  pecify the outpu
5dc0: 74 20 53 52 49 44 2e 3c 2f 6c 69 3e 0d 0a 3c 6c  t SRID.</li>..<l
5dd0: 69 3e 56 61 72 69 61 62 6c 65 20 3c 62 3e 40 73  i>Variable <b>@s
5de0: 68 70 5f 70 61 74 68 40 3c 2f 62 3e 20 69 73 20  hp_path@</b> is 
5df0: 69 6e 74 65 6e 64 65 64 20 74 6f 20 73 70 65 63  intended to spec
5e00: 69 66 79 20 74 68 65 20 70 61 74 68 6e 61 6d 65  ify the pathname
5e10: 20 6f 66 20 74 68 65 20 6f 75 74 70 75 74 20 53   of the output S
5e20: 68 61 70 65 66 69 6c 65 2e 3c 2f 6c 69 3e 0d 0a  hapefile.</li>..
5e30: 3c 6c 69 3e 56 61 72 69 61 62 6c 65 73 20 3c 62  <li>Variables <b
5e40: 3e 40 6d 75 6e 69 63 69 70 61 6c 69 74 79 40 3c  >@municipality@<
5e50: 2f 62 3e 2c 20 3c 62 3e 40 70 72 6f 76 69 6e 63  /b>, <b>@provinc
5e60: 65 40 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e 40 72  e@</b> and <b>@r
5e70: 65 67 69 6f 6e 40 3c 2f 62 3e 20 61 72 65 20 69  egion@</b> are i
5e80: 6e 74 65 6e 64 65 64 20 74 6f 20 73 70 65 63 69  ntended to speci
5e90: 66 79 20 74 68 65 20 69 6e 74 65 6e 64 65 64 20  fy the intended 
5ea0: 66 69 6c 74 65 72 69 6e 67 20 63 72 69 74 65 72  filtering criter
5eb0: 69 61 2e 3c 62 72 3e 0d 0a 54 68 69 73 20 69 73  ia.<br>..This is
5ec0: 20 61 20 6c 69 74 74 6c 65 20 62 69 74 20 74 72   a little bit tr
5ed0: 69 63 6b 79 2c 20 73 6f 20 77 65 27 6c 6c 20 67  icky, so we'll g
5ee0: 6f 20 69 6e 20 66 75 72 74 68 65 72 20 64 65 70  o in further dep
5ef0: 74 68 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 54  th:..<ul>..<li>T
5f00: 68 65 73 65 20 56 61 72 69 61 62 6c 65 73 20 61  hese Variables a
5f10: 72 65 20 65 78 70 65 63 74 65 64 20 74 6f 20 62  re expected to b
5f20: 65 20 61 63 74 75 61 6c 6c 79 20 72 65 70 6c 61  e actually repla
5f30: 63 65 64 20 62 79 20 3c 62 3e 74 65 78 74 20 73  ced by <b>text s
5f40: 74 72 69 6e 67 20 76 61 6c 75 65 73 3c 2f 62 3e  tring values</b>
5f50: 3b 20 73 6f 20 77 65 27 76 65 20 63 6f 6e 73 69  ; so we've consi
5f60: 73 74 65 6e 74 6c 79 20 3c 62 3e 73 69 6e 67 6c  stently <b>singl
5f70: 65 2d 71 75 6f 74 65 64 3c 2f 62 3e 20 74 68 65  e-quoted</b> the
5f80: 20 76 61 72 69 61 62 6c 65 20 73 79 6d 62 6f 6c   variable symbol
5f90: 2c 20 73 6f 20 74 6f 20 61 6c 6c 6f 77 20 66 6f  , so to allow fo
5fa0: 72 20 61 6e 20 65 61 73 69 65 72 20 76 61 6c 75  r an easier valu
5fb0: 65 20 72 65 70 6c 61 63 65 6d 65 6e 74 2e 3c 2f  e replacement.</
5fc0: 6c 69 3e 0d 0a 3c 6c 69 3e 57 65 20 61 72 65 20  li>..<li>We are 
5fd0: 73 79 73 74 65 6d 61 74 69 63 61 6c 6c 79 20 75  systematically u
5fe0: 73 69 6e 67 20 74 68 65 20 3c 62 3e 55 70 70 65  sing the <b>Uppe
5ff0: 72 28 29 3c 2f 62 3e 20 66 75 6e 63 74 69 6f 6e  r()</b> function
6000: 20 73 69 6d 70 6c 79 20 62 65 63 61 75 73 65 20   simply because 
6010: 50 72 6f 76 69 6e 63 65 20 61 6e 64 20 52 65 67  Province and Reg
6020: 69 6f 6e 20 6e 61 6d 65 73 20 61 72 65 20 61 6c  ion names are al
6030: 6c 2d 75 70 70 65 72 63 61 73 65 20 69 6e 20 79  l-uppercase in y
6040: 65 61 72 73 20 31 39 39 31 20 61 6e 64 20 32 30  ears 1991 and 20
6050: 30 31 20 62 75 74 20 6e 6f 74 20 66 6f 72 20 74  01 but not for t
6060: 68 65 20 79 65 61 72 20 32 30 31 31 2e 3c 62 72  he year 2011.<br
6070: 3e 0d 0a 53 79 73 74 65 6d 61 74 69 63 61 6c 6c  >..Systematicall
6080: 79 20 75 73 69 6e 67 20 55 70 70 65 72 28 29 20  y using Upper() 
6090: 77 69 6c 6c 20 69 6e 73 75 72 65 20 63 6f 6e 73  will insure cons
60a0: 69 73 74 65 6e 74 65 6e 63 79 20 6f 66 20 61 6c  istentency of al
60b0: 6c 20 6e 61 6d 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c  l names.</li>..<
60c0: 6c 69 3e 57 65 20 61 72 65 20 75 73 69 6e 67 20  li>We are using 
60d0: 74 68 72 65 65 20 73 65 70 61 72 61 74 65 20 63  three separate c
60e0: 6f 6d 70 61 72 69 73 6f 6e 73 20 28 6f 6e 65 20  omparisons (one 
60f0: 66 6f 72 20 4d 75 6e 69 63 69 70 61 6c 69 74 79  for Municipality
6100: 2c 20 6f 6e 65 20 66 6f 72 20 50 72 6f 76 69 6e  , one for Provin
6110: 63 65 20 61 6e 64 20 6f 6e 65 20 66 6f 72 20 52  ce and one for R
6120: 65 67 69 6f 6e 29 20 63 6f 6e 6e 65 63 74 65 64  egion) connected
6130: 20 62 79 20 3c 62 3e 4f 52 3c 2f 62 3e 20 6c 6f   by <b>OR</b> lo
6140: 67 69 63 61 6c 20 6f 70 65 72 61 74 6f 72 73 20  gical operators 
6150: 73 6f 20 74 6f 20 6d 61 6b 65 20 69 74 20 70 6f  so to make it po
6160: 73 73 69 62 6c 65 20 62 79 20 73 70 65 63 69 66  ssible by specif
6170: 79 69 6e 67 20 6a 75 73 74 20 61 20 73 69 6e 67  ying just a sing
6180: 6c 65 20 6f 72 20 6d 6f 72 65 20 66 69 6c 74 65  le or more filte
6190: 72 20 63 6c 61 75 73 65 73 2e 3c 62 72 3e 0d 0a  r clauses.<br>..
61a0: 3c 75 3e 52 65 63 61 6c 6c 3c 2f 75 3e 3a 20 75  <u>Recall</u>: u
61b0: 6e 61 73 73 69 67 6e 65 64 20 56 61 72 69 61 62  nassigned Variab
61c0: 6c 65 73 20 77 69 6c 6c 20 64 65 66 61 75 6c 74  les will default
61d0: 20 74 6f 20 4e 55 4c 4c 3b 20 73 6f 20 62 79 20   to NULL; so by 
61e0: 6a 75 73 74 20 64 65 63 6c 61 72 69 6e 67 20 0d  just declaring .
61f0: 0a 3c 62 3e 40 70 72 6f 76 69 6e 63 65 40 3d 41  .<b>@province@=A
6200: 72 65 7a 7a 6f 3c 2f 62 3e 20 77 65 27 6c 6c 20  rezzo</b> we'll 
6210: 74 68 65 6e 20 67 65 74 20 61 20 3c 62 3e 3c 69  then get a <b><i
6220: 3e 63 6f 6f 6b 65 64 3c 2f 69 3e 3c 2f 62 3e 20  >cooked</i></b> 
6230: 57 48 45 52 45 20 63 6c 61 75 73 65 20 6c 69 6b  WHERE clause lik
6240: 65 20 74 68 69 73 3a 0d 0a 3c 76 65 72 62 61 74  e this:..<verbat
6250: 69 6d 3e 0d 0a 57 48 45 52 45 20 28 55 70 70 65  im>..WHERE (Uppe
6260: 72 28 6e 61 6d 65 29 20 3d 20 55 70 70 65 72 28  r(name) = Upper(
6270: 27 4e 55 4c 4c 27 29 20 4f 52 20 55 70 70 65 72  'NULL') OR Upper
6280: 28 70 72 6f 76 69 6e 63 65 29 20 3d 20 55 70 70  (province) = Upp
6290: 65 72 28 27 41 72 65 7a 7a 6f 27 29 20 4f 52 20  er('Arezzo') OR 
62a0: 55 70 70 65 72 28 72 65 67 69 6f 6e 29 20 3d 20  Upper(region) = 
62b0: 55 70 70 65 72 28 27 4e 55 4c 4c 27 29 29 0d 0a  Upper('NULL'))..
62c0: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 2f 6c  </verbatim>..</l
62d0: 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 2f 6c 69 3e  i>..</ul>..</li>
62e0: 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 62 72 3e 0d 0a 3c  ..</ul>..<br>..<
62f0: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43  verbatim>..SELEC
6300: 54 20 53 71 6c 50 72 6f 63 5f 45 78 65 63 75 74  T SqlProc_Execut
6310: 65 28 20 53 71 6c 50 72 6f 63 5f 46 72 6f 6d 46  e( SqlProc_FromF
6320: 69 6c 65 20 28 27 43 3a 2f 75 73 65 72 73 2f 6a  ile ('C:/users/j
6330: 6f 65 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74  oe/stored_proc_t
6340: 65 73 74 2f 74 65 73 74 5f 73 70 2e 74 78 74 27  est/test_sp.txt'
6350: 29 2c 0d 0a 20 20 27 40 73 72 69 64 40 3d 33 30  ),..  '@srid@=30
6360: 30 34 27 2c 20 27 40 79 65 61 72 40 3d 32 30 30  04', '@year@=200
6370: 31 27 2c 20 27 40 72 65 67 69 6f 6e 40 3d 4c 61  1', '@region@=La
6380: 7a 69 6f 27 2c 20 27 40 73 68 70 5f 70 61 74 68  zio', '@shp_path
6390: 40 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73  @=C:/users/joe/s
63a0: 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f  tored_proc_test/
63b0: 6c 61 7a 69 6f 5f 32 30 30 31 5f 33 30 30 34 27  lazio_2001_3004'
63c0: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a  );..-----..1....
63d0: 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 45  SELECT SqlProc_E
63e0: 78 65 63 75 74 65 28 20 53 71 6c 50 72 6f 63 5f  xecute( SqlProc_
63f0: 46 72 6f 6d 46 69 6c 65 20 28 27 43 3a 2f 75 73  FromFile ('C:/us
6400: 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70  ers/joe/stored_p
6410: 72 6f 63 5f 74 65 73 74 2f 74 65 73 74 5f 73 70  roc_test/test_sp
6420: 2e 74 78 74 27 29 2c 0d 0a 20 20 27 40 73 72 69  .txt'),..  '@sri
6430: 64 40 3d 34 33 32 36 27 2c 20 27 40 79 65 61 72  d@=4326', '@year
6440: 40 3d 31 39 39 31 27 2c 20 27 40 72 65 67 69 6f  @=1991', '@regio
6450: 6e 40 3d 70 75 67 6c 69 61 27 2c 20 27 40 73 68  n@=puglia', '@sh
6460: 70 5f 70 61 74 68 40 3d 43 3a 2f 75 73 65 72 73  p_path@=C:/users
6470: 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70 72 6f 63  /joe/stored_proc
6480: 5f 74 65 73 74 2f 70 75 67 6c 69 61 5f 31 39 39  _test/puglia_199
6490: 31 5f 34 33 32 36 27 29 3b 0d 0a 2d 2d 2d 2d 2d  1_4326');..-----
64a0: 0d 0a 31 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 71  ..1....SELECT Sq
64b0: 6c 50 72 6f 63 5f 45 78 65 63 75 74 65 28 20 53  lProc_Execute( S
64c0: 71 6c 50 72 6f 63 5f 46 72 6f 6d 46 69 6c 65 20  qlProc_FromFile 
64d0: 28 27 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73  ('C:/users/joe/s
64e0: 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f  tored_proc_test/
64f0: 74 65 73 74 5f 73 70 2e 74 78 74 27 29 2c 0d 0a  test_sp.txt'),..
6500: 20 20 27 40 73 72 69 64 40 3d 33 30 30 33 27 2c    '@srid@=3003',
6510: 20 27 40 79 65 61 72 40 3d 32 30 31 31 27 2c 20   '@year@=2011', 
6520: 27 40 70 72 6f 76 69 6e 63 65 40 3d 41 52 45 5a  '@province@=AREZ
6530: 5a 4f 27 2c 20 27 40 73 68 70 5f 70 61 74 68 40  ZO', '@shp_path@
6540: 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74  =C:/users/joe/st
6550: 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f 61  ored_proc_test/a
6560: 72 65 7a 7a 6f 5f 32 30 31 31 5f 33 30 30 33 27  rezzo_2011_3003'
6570: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a  );..-----..1....
6580: 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 45  SELECT SqlProc_E
6590: 78 65 63 75 74 65 28 20 53 71 6c 50 72 6f 63 5f  xecute( SqlProc_
65a0: 46 72 6f 6d 46 69 6c 65 20 28 27 43 3a 2f 75 73  FromFile ('C:/us
65b0: 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70  ers/joe/stored_p
65c0: 72 6f 63 5f 74 65 73 74 2f 74 65 73 74 5f 73 70  roc_test/test_sp
65d0: 2e 74 78 74 27 29 2c 0d 0a 20 20 27 40 73 72 69  .txt'),..  '@sri
65e0: 64 40 3d 33 30 30 33 27 2c 20 27 40 79 65 61 72  d@=3003', '@year
65f0: 40 3d 32 30 30 31 27 2c 20 27 40 6d 75 6e 69 63  @=2001', '@munic
6600: 69 70 61 6c 69 74 79 40 3d 41 52 45 5a 5a 4f 27  ipality@=AREZZO'
6610: 2c 20 27 40 73 68 70 5f 70 61 74 68 40 3d 43 3a  , '@shp_path@=C:
6620: 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65  /users/joe/store
6630: 64 5f 70 72 6f 63 5f 74 65 73 74 2f 63 6f 6d 5f  d_proc_test/com_
6640: 61 72 65 7a 7a 6f 5f 32 30 30 31 5f 33 30 30 33  arezzo_2001_3003
6650: 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c  ');..-----..1..<
6660: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 49 6e 20 74  /verbatim>..In t
6670: 68 69 73 20 66 69 72 73 74 20 74 75 74 6f 72 69  his first tutori
6680: 61 6c 20 77 65 20 68 61 76 65 20 61 6c 77 61 79  al we have alway
6690: 73 20 3c 62 3e 65 78 65 63 75 74 65 64 3c 2f 62  s <b>executed</b
66a0: 3e 20 61 20 50 72 6f 63 65 64 75 72 65 20 6c 6f  > a Procedure lo
66b0: 61 64 65 64 20 66 72 6f 6d 20 61 6e 20 65 78 74  aded from an ext
66c0: 65 72 6e 61 6c 20 66 69 6c 65 2e 3c 62 72 3e 0d  ernal file.<br>.
66d0: 0a 41 73 20 79 6f 75 20 63 61 6e 20 73 65 65 20  .As you can see 
66e0: 65 78 65 63 75 74 69 6e 67 20 61 20 50 72 6f 63  executing a Proc
66f0: 65 64 75 72 65 20 69 73 20 61 20 73 74 72 61 69  edure is a strai
6700: 67 68 74 66 6f 72 77 61 72 64 20 74 61 73 6b 3b  ghtforward task;
6710: 20 79 6f 75 20 73 69 6d 70 6c 79 20 68 61 76 65   you simply have
6720: 20 74 6f 20 73 70 65 63 69 66 79 20 61 6e 20 61   to specify an a
6730: 70 70 72 6f 70 72 69 61 74 65 20 6c 69 73 74 20  ppropriate list 
6740: 6f 66 20 3c 62 3e 56 61 72 69 61 62 6c 65 20 56  of <b>Variable V
6750: 61 6c 75 65 73 3c 2f 62 3e 20 61 6e 64 20 74 68  alues</b> and th
6760: 61 74 27 73 20 61 6c 6c 2e 0d 0a 3c 68 72 3e 0d  at's all...<hr>.
6770: 0a 3c 68 32 3e 54 75 74 6f 72 69 61 6c 20 23 32  .<h2>Tutorial #2
6780: 3c 2f 68 32 3e 0d 0a 3c 76 65 72 62 61 74 69 6d  </h2>..<verbatim
6790: 3e 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64  >..SELECT Stored
67a0: 50 72 6f 63 5f 52 65 67 69 73 74 65 72 28 20 27  Proc_Register( '
67b0: 6d 79 5f 70 72 6f 63 27 2c 20 27 61 20 53 74 6f  my_proc', 'a Sto
67c0: 72 65 64 20 50 72 6f 63 65 64 75 72 65 20 66 6f  red Procedure fo
67d0: 72 20 65 78 70 6f 72 74 69 6e 67 20 73 65 6c 65  r exporting sele
67e0: 63 74 65 64 20 53 68 61 70 65 66 69 6c 65 73 27  cted Shapefiles'
67f0: 2c 20 53 71 6c 50 72 6f 63 5f 46 72 6f 6d 46 69  , SqlProc_FromFi
6800: 6c 65 20 28 27 43 3a 2f 75 73 65 72 73 2f 6a 6f  le ('C:/users/jo
6810: 65 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65  e/stored_proc_te
6820: 73 74 2f 74 65 73 74 5f 73 70 2e 74 78 74 27 29  st/test_sp.txt')
6830: 20 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e   );..</verbatim>
6840: 0d 0a 54 68 69 73 20 73 65 63 6f 6e 64 20 74 75  ..This second tu
6850: 74 6f 72 69 61 6c 20 69 73 20 20 62 61 73 69 63  torial is  basic
6860: 61 6c 6c 79 20 74 68 65 20 73 61 6d 65 20 6f 66  ally the same of
6870: 20 74 68 65 20 66 69 72 73 74 20 6f 6e 65 2e 3c   the first one.<
6880: 62 72 3e 0d 0a 54 68 65 20 6f 6e 6c 79 20 64 69  br>..The only di
6890: 66 66 65 72 65 6e 63 65 20 69 73 20 74 68 61 74  fference is that
68a0: 20 77 65 27 6c 6c 20 6e 6f 77 20 75 73 65 20 61   we'll now use a
68b0: 20 70 65 72 6d 61 6e 65 6e 74 6c 79 20 72 65 67   permanently reg
68c0: 69 73 74 65 72 65 64 20 3c 62 3e 53 74 6f 72 65  istered <b>Store
68d0: 64 20 50 72 6f 63 65 64 75 72 65 3c 2f 62 3e 2e  d Procedure</b>.
68e0: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45  ..<verbatim>..SE
68f0: 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f 63 5f  LECT StoredProc_
6900: 45 78 65 63 75 74 65 28 20 27 6d 79 5f 70 72 6f  Execute( 'my_pro
6910: 63 27 2c 20 27 40 73 72 69 64 40 3d 33 30 30 34  c', '@srid@=3004
6920: 27 2c 20 27 40 79 65 61 72 40 3d 32 30 30 31 27  ', '@year@=2001'
6930: 2c 20 27 40 72 65 67 69 6f 6e 40 3d 4c 61 7a 69  , '@region@=Lazi
6940: 6f 27 2c 20 27 40 73 68 70 5f 70 61 74 68 40 3d  o', '@shp_path@=
6950: 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74 6f  C:/users/joe/sto
6960: 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f 6c 61  red_proc_test/la
6970: 7a 69 6f 5f 32 30 30 31 5f 33 30 30 34 27 29 3b  zio_2001_3004');
6980: 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a 53 45  ..-----..1....SE
6990: 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f 63 5f  LECT StoredProc_
69a0: 45 78 65 63 75 74 65 28 20 27 6d 79 5f 70 72 6f  Execute( 'my_pro
69b0: 63 27 2c 20 27 40 73 72 69 64 40 3d 34 33 32 36  c', '@srid@=4326
69c0: 27 2c 20 27 40 79 65 61 72 40 3d 31 39 39 31 27  ', '@year@=1991'
69d0: 2c 20 27 40 72 65 67 69 6f 6e 40 3d 70 75 67 6c  , '@region@=pugl
69e0: 69 61 27 2c 20 27 40 73 68 70 5f 70 61 74 68 40  ia', '@shp_path@
69f0: 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74  =C:/users/joe/st
6a00: 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f 70  ored_proc_test/p
6a10: 75 67 6c 69 61 5f 31 39 39 31 5f 34 33 32 36 27  uglia_1991_4326'
6a20: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a  );..-----..1....
6a30: 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f  SELECT StoredPro
6a40: 63 5f 45 78 65 63 75 74 65 28 20 27 6d 79 5f 70  c_Execute( 'my_p
6a50: 72 6f 63 27 2c 20 27 40 73 72 69 64 40 3d 33 30  roc', '@srid@=30
6a60: 30 33 27 2c 20 27 40 79 65 61 72 40 3d 32 30 31  03', '@year@=201
6a70: 31 27 2c 20 27 40 70 72 6f 76 69 6e 63 65 40 3d  1', '@province@=
6a80: 41 52 45 5a 5a 4f 27 2c 20 27 40 73 68 70 5f 70  AREZZO', '@shp_p
6a90: 61 74 68 40 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f  ath@=C:/users/jo
6aa0: 65 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65  e/stored_proc_te
6ab0: 73 74 2f 61 72 65 7a 7a 6f 5f 32 30 31 31 5f 33  st/arezzo_2011_3
6ac0: 30 30 33 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31  003');..-----..1
6ad0: 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65  ....SELECT Store
6ae0: 64 50 72 6f 63 5f 45 78 65 63 75 74 65 28 20 27  dProc_Execute( '
6af0: 6d 79 5f 70 72 6f 63 27 2c 20 27 40 73 72 69 64  my_proc', '@srid
6b00: 40 3d 33 30 30 33 27 2c 20 27 40 79 65 61 72 40  @=3003', '@year@
6b10: 3d 32 30 30 31 27 2c 20 27 40 6d 75 6e 69 63 69  =2001', '@munici
6b20: 70 61 6c 69 74 79 40 3d 41 52 45 5a 5a 4f 27 2c  pality@=AREZZO',
6b30: 20 27 40 73 68 70 5f 70 61 74 68 40 3d 43 3a 2f   '@shp_path@=C:/
6b40: 75 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64  users/joe/stored
6b50: 5f 70 72 6f 63 5f 74 65 73 74 2f 63 6f 6d 5f 61  _proc_test/com_a
6b60: 72 65 7a 7a 6f 5f 32 30 30 31 5f 33 30 30 33 27  rezzo_2001_3003'
6b70: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f  );..-----..1..</
6b80: 76 65 72 62 61 74 69 6d 3e 0d 0a 45 78 65 63 75  verbatim>..Execu
6b90: 74 69 6e 67 20 61 20 53 74 6f 72 65 64 20 50 72  ting a Stored Pr
6ba0: 6f 63 65 64 75 72 65 20 69 73 6e 27 74 20 76 65  ocedure isn't ve
6bb0: 72 79 20 64 69 66 66 65 72 65 6e 74 20 66 72 6f  ry different fro
6bc0: 6d 20 65 78 65 63 75 74 69 6e 67 20 61 20 50 72  m executing a Pr
6bd0: 6f 63 65 64 75 72 65 20 73 74 6f 72 65 64 20 69  ocedure stored i
6be0: 6e 74 6f 20 61 6e 20 65 78 74 65 72 6e 61 6c 20  nto an external 
6bf0: 66 69 6c 65 2e 3c 62 72 3e 0d 0a 3c 74 61 62 6c  file.<br>..<tabl
6c00: 65 20 62 67 63 6f 6c 6f 72 3d 22 23 66 38 66 38  e bgcolor="#f8f8
6c10: 64 38 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d  d8" cellpadding=
6c20: 22 36 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d  "6" cellspacing=
6c30: 22 38 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 45 78  "8"><tr><td>..Ex
6c40: 65 63 75 74 69 6e 67 20 79 6f 75 72 20 50 72 6f  ecuting your Pro
6c50: 63 65 64 75 72 65 73 20 66 72 6f 6d 20 65 78 74  cedures from ext
6c60: 65 72 6e 61 6c 20 66 69 6c 65 73 20 6f 72 20 70  ernal files or p
6c70: 65 72 6d 61 6e 65 6e 74 6c 79 20 72 65 67 69 73  ermanently regis
6c80: 74 65 72 69 6e 67 20 53 74 6f 72 65 64 20 50 72  tering Stored Pr
6c90: 6f 63 65 64 75 72 65 73 20 64 69 72 65 63 74 6c  ocedures directl
6ca0: 79 20 77 69 74 68 69 6e 20 61 20 64 61 74 61 62  y within a datab
6cb0: 61 73 65 20 69 73 20 61 20 6d 61 74 74 65 72 20  ase is a matter 
6cc0: 6f 66 20 66 72 65 65 20 63 68 6f 69 63 65 2e 3c  of free choice.<
6cd0: 62 72 3e 0d 0a 49 66 20 79 6f 75 20 61 72 65 20  br>..If you are 
6ce0: 70 6c 61 6e 6e 69 6e 67 20 74 6f 20 64 65 70 6c  planning to depl
6cf0: 6f 79 20 61 20 50 72 6f 63 65 64 75 72 65 20 69  oy a Procedure i
6d00: 6e 74 65 6e 64 65 64 20 74 6f 20 73 75 70 70 6f  ntended to suppo
6d10: 72 74 20 6d 61 6e 79 20 64 69 66 66 65 72 65 6e  rt many differen
6d20: 74 20 64 61 74 61 62 61 73 65 73 2c 20 74 68 65  t databases, the
6d30: 6e 20 75 73 69 6e 67 20 61 6e 20 65 78 74 65 72  n using an exter
6d40: 6e 61 6c 20 66 69 6c 65 20 63 6f 75 6c 64 20 70  nal file could p
6d50: 72 6f 62 61 62 6c 79 20 73 69 6d 70 6c 69 66 79  robably simplify
6d60: 20 79 6f 75 72 20 77 6f 72 6b 2e 3c 62 72 3e 0d   your work.<br>.
6d70: 0a 42 75 74 20 69 66 20 79 6f 75 20 61 72 65 20  .But if you are 
6d80: 70 6c 61 6e 6e 69 6e 67 20 74 6f 20 64 65 70 6c  planning to depl
6d90: 6f 79 20 61 20 50 72 6f 63 65 64 75 72 65 20 69  oy a Procedure i
6da0: 6e 74 65 6e 64 65 64 20 74 6f 20 61 75 74 6f 6d  ntended to autom
6db0: 61 74 65 20 6d 61 6e 79 20 72 6f 75 74 69 6e 65  ate many routine
6dc0: 6c 79 20 74 61 73 6b 20 74 6f 20 62 65 20 65 78  ly task to be ex
6dd0: 65 63 75 74 65 64 20 6f 66 74 65 6e 20 6f 6e 20  ecuted often on 
6de0: 74 68 65 20 73 61 6d 65 20 64 61 74 61 62 61 73  the same databas
6df0: 65 2c 20 74 68 65 6e 20 70 65 72 6d 61 6e 65 6e  e, then permanen
6e00: 74 6c 79 20 72 65 67 69 73 74 65 72 69 6e 67 20  tly registering 
6e10: 61 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75  a Stored Procedu
6e20: 72 65 20 77 6f 75 6c 64 20 70 72 6f 62 61 62 6c  re would probabl
6e30: 79 20 62 65 20 62 65 74 74 65 72 20 61 6e 64 20  y be better and 
6e40: 66 61 73 74 65 72 2e 0d 0a 3c 2f 74 64 3e 3c 2f  faster...</td></
6e50: 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 62 72  tr></table>..<br
6e60: 3e 3c 68 72 3e 0d 0a 3c 68 32 3e 54 75 74 6f 72  ><hr>..<h2>Tutor
6e70: 69 61 6c 20 23 33 3c 2f 68 32 3e 0d 0a 54 68 69  ial #3</h2>..Thi
6e80: 73 20 74 68 69 72 64 20 74 75 74 6f 72 69 61 6c  s third tutorial
6e90: 20 69 73 20 6a 75 73 74 20 61 20 73 6d 61 6c 6c   is just a small
6ea0: 20 76 61 72 69 61 74 69 6f 6e 20 6f 6e 20 74 68   variation on th
6eb0: 65 20 74 68 65 6d 65 20 69 6e 74 65 6e 64 65 64  e theme intended
6ec0: 20 74 6f 20 68 69 67 68 6c 69 67 68 74 20 73 6f   to highlight so
6ed0: 6d 65 20 70 6f 74 65 6e 74 69 61 6c 6c 79 20 64  me potentially d
6ee0: 61 6e 67 65 72 6f 75 73 20 70 69 74 66 61 6c 6c  angerous pitfall
6ef0: 73 20 72 65 6c 61 74 65 64 20 74 6f 20 3c 62 3e  s related to <b>
6f00: 73 69 6e 67 6c 65 2d 71 75 6f 74 69 6e 67 3c 2f  single-quoting</
6f10: 62 3e 2e 20 0d 0a 3c 76 65 72 62 61 74 69 6d 3e  b>. ..<verbatim>
6f20: 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50  ..SELECT StoredP
6f30: 72 6f 63 5f 45 78 65 63 75 74 65 28 20 27 6d 79  roc_Execute( 'my
6f40: 5f 70 72 6f 63 27 29 2c 20 27 40 73 72 69 64 40  _proc'), '@srid@
6f50: 3d 33 30 30 33 27 2c 20 27 40 79 65 61 72 40 3d  =3003', '@year@=
6f60: 32 30 31 31 27 2c 20 27 40 6d 75 6e 69 63 69 70  2011', '@municip
6f70: 61 6c 69 74 79 40 3d 72 69 6f 20 6e 65 6c 6c 27  ality@=rio nell'
6f80: 27 65 6c 62 61 27 2c 20 27 40 73 68 70 5f 70 61  'elba', '@shp_pa
6f90: 74 68 40 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65  th@=C:/users/joe
6fa0: 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73  /stored_proc_tes
6fb0: 74 2f 72 69 6f 5f 65 6c 62 61 5f 32 30 31 31 5f  t/rio_elba_2011_
6fc0: 33 30 30 33 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a  3003');..-----..
6fd0: 53 74 6f 72 65 64 50 72 6f 63 20 65 78 63 65 70  StoredProc excep
6fe0: 74 69 6f 6e 20 2d 20 61 20 66 61 74 61 6c 20 53  tion - a fatal S
6ff0: 51 4c 20 65 72 72 6f 72 20 77 61 73 20 65 6e 63  QL error was enc
7000: 6f 75 6e 74 65 72 65 64 2e 0d 0a 0d 0a 53 45 4c  ountered.....SEL
7010: 45 43 54 20 53 71 6c 50 72 6f 63 5f 47 65 74 4c  ECT SqlProc_GetL
7020: 61 73 74 45 72 72 6f 72 28 29 3b 0d 0a 2d 2d 2d  astError();..---
7030: 2d 2d 0d 0a 67 61 69 61 5f 73 71 6c 5f 70 72 6f  --..gaia_sql_pro
7040: 63 5f 65 78 65 63 75 74 65 3a 20 6e 65 61 72 20  c_execute: near 
7050: 22 65 6c 62 61 22 3a 20 73 79 6e 74 61 78 20 65  "elba": syntax e
7060: 72 72 6f 72 0d 0a 3c 2f 76 65 72 62 61 74 69 6d  rror..</verbatim
7070: 3e 0d 0a 54 68 69 73 20 66 69 72 73 74 20 61 74  >..This first at
7080: 74 65 6d 70 74 20 77 69 6c 6c 20 66 61 69 6c 2c  tempt will fail,
7090: 20 61 6e 64 20 75 73 69 6e 67 20 3c 62 3e 53 71   and using <b>Sq
70a0: 6c 50 72 6f 63 5f 47 65 74 4c 61 73 74 45 72 72  lProc_GetLastErr
70b0: 6f 72 3c 2f 62 3e 20 77 69 6c 6c 20 65 78 70 6c  or</b> will expl
70c0: 61 69 6e 20 77 68 79 20 69 74 20 66 61 69 6c 65  ain why it faile
70d0: 64 3c 62 72 3e 0d 0a 57 65 27 76 65 20 70 61 73  d<br>..We've pas
70e0: 73 65 64 20 61 20 3c 62 3e 27 40 6d 75 6e 69 63  sed a <b>'@munic
70f0: 69 70 61 6c 69 74 79 40 3d 72 69 6f 20 6e 65 6c  ipality@=rio nel
7100: 6c 27 27 65 6c 62 61 27 3c 2f 62 3e 20 56 61 72  l''elba'</b> Var
7110: 69 61 62 6c 65 20 77 69 74 68 20 56 61 6c 75 65  iable with Value
7120: 2c 20 74 68 61 74 20 77 69 6c 6c 20 6c 65 61 64  , that will lead
7130: 20 74 6f 20 61 20 3c 62 3e 63 6f 6f 6b 65 64 3c   to a <b>cooked<
7140: 2f 62 3e 20 57 48 45 52 45 20 63 6c 61 75 73 65  /b> WHERE clause
7150: 20 6c 69 6b 65 20 74 68 69 73 3a 0d 0a 3c 76 65   like this:..<ve
7160: 72 62 61 74 69 6d 3e 0d 0a 57 48 45 52 45 20 28  rbatim>..WHERE (
7170: 55 70 70 65 72 28 6e 61 6d 65 29 20 3d 20 55 70  Upper(name) = Up
7180: 70 65 72 28 27 72 69 6f 20 6e 65 6c 6c 27 65 6c  per('rio nell'el
7190: 62 61 27 29 20 4f 52 20 55 70 70 65 72 28 70 72  ba') OR Upper(pr
71a0: 6f 76 69 6e 63 65 29 20 3d 20 55 70 70 65 72 28  ovince) = Upper(
71b0: 27 4e 55 4c 4c 27 29 20 4f 52 20 55 70 70 65 72  'NULL') OR Upper
71c0: 28 72 65 67 69 6f 6e 29 20 3d 20 55 70 70 65 72  (region) = Upper
71d0: 28 27 4e 55 4c 4c 27 29 29 0d 0a 3c 2f 76 65 72  ('NULL'))..</ver
71e0: 62 61 74 69 6d 3e 0d 0a 54 68 65 2c 20 6e 6f 74  batim>..The, not
71f0: 20 61 6c 77 61 79 73 20 6f 62 76 69 6f 75 73 20   always obvious 
7200: 63 61 75 73 65 2c 20 69 73 20 74 68 61 74 20 3c  cause, is that <
7210: 62 3e 27 72 69 6f 20 6e 65 6c 6c 27 65 6c 62 61  b>'rio nell'elba
7220: 27 3c 2f 62 3e 20 69 73 20 61 6e 20 69 6c 6c 65  '</b> is an ille
7230: 67 61 6c 20 53 51 4c 20 74 65 78 74 20 73 74 72  gal SQL text str
7240: 69 6e 67 3b 20 74 68 65 20 63 6f 72 72 65 63 74  ing; the correct
7250: 20 73 79 6e 74 61 78 20 73 68 6f 75 6c 64 20 62   syntax should b
7260: 65 20 69 6e 73 74 65 61 64 20 3c 62 3e 27 72 69  e instead <b>'ri
7270: 6f 20 6e 65 6c 6c 27 27 65 6c 62 61 27 3c 2f 62  o nell''elba'</b
7280: 3e 2e 0d 0a 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 76  >...<br><br>..<v
7290: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54  erbatim>..SELECT
72a0: 20 53 74 6f 72 65 64 50 72 6f 63 5f 45 78 65 63   StoredProc_Exec
72b0: 75 74 65 28 20 27 6d 79 5f 70 72 6f 63 27 29 2c  ute( 'my_proc'),
72c0: 20 27 40 73 72 69 64 40 3d 33 30 30 33 27 2c 20   '@srid@=3003', 
72d0: 27 40 79 65 61 72 40 3d 32 30 31 31 27 2c 20 27  '@year@=2011', '
72e0: 40 6d 75 6e 69 63 69 70 61 6c 69 74 79 40 3d 72  @municipality@=r
72f0: 69 6f 20 6e 65 6c 6c 27 27 27 27 65 6c 62 61 27  io nell''''elba'
7300: 2c 20 27 40 73 68 70 5f 70 61 74 68 40 3d 43 3a  , '@shp_path@=C:
7310: 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65  /users/joe/store
7320: 64 5f 70 72 6f 63 5f 74 65 73 74 2f 72 69 6f 5f  d_proc_test/rio_
7330: 65 6c 62 61 5f 32 30 31 31 5f 33 30 30 33 27 29  elba_2011_3003')
7340: 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76  ;..-----..1..</v
7350: 65 72 62 61 74 69 6d 3e 0d 0a 52 65 73 6f 6c 76  erbatim>..Resolv
7360: 69 6e 67 20 73 75 63 68 20 61 6e 20 69 73 73 75  ing such an issu
7370: 65 20 69 73 20 72 61 74 68 65 72 20 74 72 69 76  e is rather triv
7380: 69 61 6c 3b 20 77 65 20 6a 75 73 74 20 68 61 76  ial; we just hav
7390: 65 20 74 6f 20 75 73 65 20 3c 62 3e 66 6f 75 72  e to use <b>four
73a0: 3c 2f 62 3e 20 63 6f 6e 73 65 63 75 74 69 76 65  </b> consecutive
73b0: 20 73 69 6e 67 6c 65 2d 71 75 6f 74 65 73 20 73   single-quotes s
73c0: 6f 20 74 6f 20 63 6f 72 72 65 63 74 6c 79 20 65  o to correctly e
73d0: 73 63 61 70 65 20 74 68 65 20 73 74 72 69 6e 67  scape the string
73e0: 20 76 61 6c 75 65 20 6f 72 3c 62 72 3e 20 75 73   value or<br> us
73f0: 65 20 64 6f 75 62 6c 65 20 71 75 6f 74 65 73 20  e double quotes 
7400: 66 6f 72 20 66 69 65 6c 64 73 20 77 68 65 72 65  for fields where
7410: 20 73 69 6e 67 6c 65 20 71 75 6f 74 65 73 20 6f   single quotes o
7420: 66 74 65 6e 20 6f 63 63 75 72 20 69 6e 20 6e 61  ften occur in na
7430: 6d 65 73 20 28 3c 62 3e 22 40 6d 75 6e 69 63 69  mes (<b>"@munici
7440: 70 61 6c 69 74 79 40 3d 72 69 6f 20 6e 65 6c 6c  pality@=rio nell
7450: 27 65 6c 62 61 22 3c 2f 62 3e 29 2e 0d 0a 3c 62  'elba"</b>)...<b
7460: 72 3e 3c 68 72 3e 0d 0a 3c 68 32 3e 54 75 74 6f  r><hr>..<h2>Tuto
7470: 72 69 61 6c 20 23 34 3c 2f 68 32 3e 0d 0a 54 68  rial #4</h2>..Th
7480: 69 73 20 6c 61 73 74 20 74 75 74 6f 72 69 61 6c  is last tutorial
7490: 20 69 73 20 65 78 61 63 74 6c 79 20 74 68 65 20   is exactly the 
74a0: 73 61 6d 65 20 6f 66 20 3c 62 3e 54 75 74 6f 72  same of <b>Tutor
74b0: 69 61 6c 20 23 32 3c 2f 62 3e 2c 20 62 75 74 20  ial #2</b>, but 
74c0: 74 68 69 73 20 74 69 6d 65 20 77 65 27 6c 6c 20  this time we'll 
74d0: 65 6e 61 62 6c 65 20 61 20 3c 62 3e 6c 6f 67 66  enable a <b>logf
74e0: 69 6c 65 3c 2f 62 3e 2e 20 0d 0a 3c 76 65 72 62  ile</b>. ..<verb
74f0: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 71  atim>..SELECT Sq
7500: 6c 50 72 6f 63 5f 53 65 74 4c 6f 67 66 69 6c 65  lProc_SetLogfile
7510: 28 20 27 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f  ( 'C:/users/joe/
7520: 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74  stored_proc_test
7530: 2f 6c 6f 67 66 69 6c 65 2e 74 78 74 27 2c 20 31  /logfile.txt', 1
7540: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a  );..-----..1....
7550: 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f  SELECT StoredPro
7560: 63 5f 45 78 65 63 75 74 65 28 20 27 6d 79 5f 70  c_Execute( 'my_p
7570: 72 6f 63 27 2c 20 27 40 73 72 69 64 40 3d 34 33  roc', '@srid@=43
7580: 32 36 27 2c 20 27 40 79 65 61 72 40 3d 31 39 39  26', '@year@=199
7590: 31 27 2c 20 27 40 72 65 67 69 6f 6e 40 3d 70 75  1', '@region@=pu
75a0: 67 6c 69 61 27 2c 20 27 40 73 68 70 5f 70 61 74  glia', '@shp_pat
75b0: 68 40 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f  h@=C:/users/joe/
75c0: 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74  stored_proc_test
75d0: 2f 70 75 67 6c 69 61 5f 31 39 39 31 5f 34 33 32  /puglia_1991_432
75e0: 36 27 29 3b 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31  6'););..-----..1
75f0: 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65  ....SELECT Store
7600: 64 50 72 6f 63 5f 45 78 65 63 75 74 65 28 20 27  dProc_Execute( '
7610: 6d 79 5f 70 72 6f 63 27 2c 20 27 40 73 72 69 64  my_proc', '@srid
7620: 40 3d 33 30 30 33 27 2c 20 27 40 79 65 61 72 40  @=3003', '@year@
7630: 3d 32 30 30 31 27 2c 20 27 40 6d 75 6e 69 63 69  =2001', '@munici
7640: 70 61 6c 69 74 79 40 3d 41 52 45 5a 5a 4f 27 2c  pality@=AREZZO',
7650: 20 27 40 73 68 70 5f 70 61 74 68 40 3d 43 3a 2f   '@shp_path@=C:/
7660: 75 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64  users/joe/stored
7670: 5f 70 72 6f 63 5f 74 65 73 74 2f 63 6f 6d 5f 61  _proc_test/com_a
7680: 72 65 7a 7a 6f 5f 32 30 30 31 5f 33 30 30 33 27  rezzo_2001_3003'
7690: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a  );..-----..1....
76a0: 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 53  SELECT SqlProc_S
76b0: 65 74 4c 6f 67 66 69 6c 65 28 20 4e 55 4c 4c 20  etLogfile( NULL 
76c0: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f  );..-----..1..</
76d0: 76 65 72 62 61 74 69 6d 3e 0d 0a 57 65 27 6c 6c  verbatim>..We'll
76e0: 20 73 74 61 72 74 20 62 79 20 63 61 6c 6c 69 6e   start by callin
76f0: 67 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 53 65 74  g <b>SqlProc_Set
7700: 4c 6f 67 66 69 6c 65 28 29 3c 2f 62 3e 20 73 6f  Logfile()</b> so
7710: 20 74 6f 20 65 6e 61 62 6c 65 20 74 68 65 20 6c   to enable the l
7720: 6f 67 67 69 6e 67 20 66 61 63 69 6c 69 74 79 3b  ogging facility;
7730: 20 74 68 65 20 6c 6f 67 66 69 6c 65 20 77 69 6c   the logfile wil
7740: 6c 20 62 65 20 3c 62 3e 43 3a 2f 75 73 65 72 73  l be <b>C:/users
7750: 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70 72 6f 63  /joe/stored_proc
7760: 5f 74 65 73 74 2f 6c 6f 67 66 69 6c 65 2e 74 78  _test/logfile.tx
7770: 74 3c 2f 62 3e 20 61 6e 64 20 69 74 20 77 69 6c  t</b> and it wil
7780: 6c 20 62 65 20 6f 70 65 6e 65 64 20 69 6e 20 3c  l be opened in <
7790: 62 3e 61 70 70 65 6e 64 20 6d 6f 64 65 3c 2f 62  b>append mode</b
77a0: 3e 2e 0d 0a 57 65 27 6c 6c 20 65 6e 64 20 66 69  >...We'll end fi
77b0: 6e 61 6c 6c 79 20 62 79 20 63 61 6c 6c 69 6e 67  nally by calling
77c0: 20 6f 6e 63 65 20 61 67 61 69 6e 20 3c 62 3e 53   once again <b>S
77d0: 71 6c 50 72 6f 63 5f 53 65 74 4c 6f 67 66 69 6c  qlProc_SetLogfil
77e0: 65 28 29 3c 2f 62 3e 20 62 79 20 70 61 73 73 69  e()</b> by passi
77f0: 6e 67 20 61 20 3c 62 3e 4e 55 4c 4c 3c 2f 62 3e  ng a <b>NULL</b>
7800: 20 70 61 74 68 6e 61 6d 65 20 73 6f 20 74 6f 20   pathname so to 
7810: 64 69 73 61 62 6c 65 20 74 68 65 20 6c 6f 67 67  disable the logg
7820: 69 6e 67 20 66 61 63 69 6c 69 74 79 2e 3c 62 72  ing facility.<br
7830: 3e 3c 62 72 3e 0d 0a 54 68 65 20 6c 6f 67 66 69  ><br>..The logfi
7840: 6c 65 20 69 73 20 6a 75 73 74 20 61 20 70 6c 61  le is just a pla
7850: 69 6e 20 74 65 78 74 20 66 69 6c 65 3b 20 79 6f  in text file; yo
7860: 75 20 63 61 6e 20 6f 70 65 6e 20 69 74 20 62 79  u can open it by
7870: 20 75 73 69 6e 67 20 61 6e 79 20 74 65 78 74 20   using any text 
7880: 65 64 69 74 6f 72 20 73 6f 20 74 6f 20 63 68 65  editor so to che
7890: 63 6b 20 74 68 61 74 20 69 74 20 77 69 6c 6c 20  ck that it will 
78a0: 6c 6f 6f 6b 20 6c 69 6b 65 20 74 68 69 73 3a 0d  look like this:.
78b0: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 3d 3d 3d  .<verbatim>..===
78c0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
78d0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
78e0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
78f0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
7900: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
7910: 3d 3d 3d 3d 3d 3d 0d 0a 3d 3d 20 20 20 20 20 53  ======..==     S
7920: 51 4c 20 73 65 73 73 69 6f 6e 20 73 74 61 72 74  QL session start
7930: 20 20 20 3d 20 20 20 32 30 31 37 2d 31 32 2d 32     =   2017-12-2
7940: 31 20 31 32 3a 35 30 3a 30 39 0d 0a 3d 3d 3d 3d  1 12:50:09..====
7950: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
7960: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
7970: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
7980: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
7990: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
79a0: 3d 3d 3d 3d 3d 0d 0a 53 45 4c 45 43 54 20 44 72  =====..SELECT Dr
79b0: 6f 70 47 65 6f 54 61 62 6c 65 28 27 74 72 61 6e  opGeoTable('tran
79c0: 73 69 65 6e 74 5f 74 61 62 6c 65 27 29 3b 0d 0a  sient_table');..
79d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
79e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d  ---------------.
79f0: 0a 44 72 6f 70 47 65 6f 54 61 62 6c 65 28 27 74  .DropGeoTable('t
7a00: 72 61 6e 73 69 65 6e 74 5f 74 61 62 6c 65 27 29  ransient_table')
7a10: 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ..--------------
7a20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7a30: 2d 0d 0a 30 0d 0a 3d 3d 3d 20 31 20 72 6f 77 20  -..0..=== 1 row 
7a40: 3d 3d 3d 20 45 78 65 63 75 74 69 6f 6e 20 74 69  === Execution ti
7a50: 6d 65 3a 20 30 2e 30 30 33 0d 0a 0d 0a 43 52 45  me: 0.003....CRE
7a60: 41 54 45 20 54 41 42 4c 45 20 74 72 61 6e 73 69  ATE TABLE transi
7a70: 65 6e 74 5f 74 61 62 6c 65 20 41 53 0d 0a 53 45  ent_table AS..SE
7a80: 4c 45 43 54 20 69 64 2c 20 69 73 74 61 74 2c 20  LECT id, istat, 
7a90: 6e 61 6d 65 2c 20 70 72 6f 76 69 6e 63 65 2c 20  name, province, 
7aa0: 72 65 67 69 6f 6e 2c 20 53 54 5f 54 72 61 6e 73  region, ST_Trans
7ab0: 66 6f 72 6d 28 67 65 6f 6d 2c 20 34 33 32 36 29  form(geom, 4326)
7ac0: 20 41 53 20 67 65 6f 6d 0d 0a 46 52 4f 4d 20 6d   AS geom..FROM m
7ad0: 75 6e 69 63 69 70 61 6c 69 74 69 65 73 5f 31 39  unicipalities_19
7ae0: 39 31 0d 0a 57 48 45 52 45 20 28 55 70 70 65 72  91..WHERE (Upper
7af0: 28 6e 61 6d 65 29 20 3d 20 55 70 70 65 72 28 27  (name) = Upper('
7b00: 4e 55 4c 4c 27 29 20 4f 52 20 55 70 70 65 72 28  NULL') OR Upper(
7b10: 70 72 6f 76 69 6e 63 65 29 20 3d 20 55 70 70 65  province) = Uppe
7b20: 72 28 27 4e 55 4c 4c 27 29 20 4f 52 20 55 70 70  r('NULL') OR Upp
7b30: 65 72 28 72 65 67 69 6f 6e 29 20 3d 20 55 70 70  er(region) = Upp
7b40: 65 72 28 27 70 75 67 6c 69 61 27 29 29 3b 0d 0a  er('puglia'));..
7b50: 3d 3d 3d 20 45 78 65 63 75 74 69 6f 6e 20 74 69  === Execution ti
7b60: 6d 65 3a 20 30 2e 31 31 31 0d 0a 0d 0a 53 45 4c  me: 0.111....SEL
7b70: 45 43 54 20 52 65 63 6f 76 65 72 47 65 6f 6d 65  ECT RecoverGeome
7b80: 74 72 79 43 6f 6c 75 6d 6e 28 27 74 72 61 6e 73  tryColumn('trans
7b90: 69 65 6e 74 5f 74 61 62 6c 65 27 2c 20 27 67 65  ient_table', 'ge
7ba0: 6f 6d 27 2c 20 34 33 32 36 2c 20 27 4d 55 4c 54  om', 4326, 'MULT
7bb0: 49 50 4f 4c 59 47 4f 4e 27 2c 20 27 58 59 27 29  IPOLYGON', 'XY')
7bc0: 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ;..-------------
7bd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7be0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7bf0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7c00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d  ---------------.
7c10: 0a 52 65 63 6f 76 65 72 47 65 6f 6d 65 74 72 79  .RecoverGeometry
7c20: 43 6f 6c 75 6d 6e 28 27 74 72 61 6e 73 69 65 6e  Column('transien
7c30: 74 5f 74 61 62 6c 65 27 2c 20 27 67 65 6f 6d 27  t_table', 'geom'
7c40: 2c 20 34 33 32 36 2c 20 27 4d 55 4c 54 49 50 4f  , 4326, 'MULTIPO
7c50: 4c 59 47 4f 4e 27 2c 20 27 58 59 27 29 0d 0a 2d  LYGON', 'XY')..-
7c60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7c70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7c80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7c90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7ca0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 0d 0a  -----------..1..
7cb0: 3d 3d 3d 20 31 20 72 6f 77 20 3d 3d 3d 20 45 78  === 1 row === Ex
7cc0: 65 63 75 74 69 6f 6e 20 74 69 6d 65 3a 20 30 2e  ecution time: 0.
7cd0: 30 33 31 0d 0a 0d 0a 53 45 4c 45 43 54 20 45 78  031....SELECT Ex
7ce0: 70 6f 72 74 53 68 70 28 27 74 72 61 6e 73 69 65  portShp('transie
7cf0: 6e 74 5f 74 61 62 6c 65 27 2c 20 27 67 65 6f 6d  nt_table', 'geom
7d00: 27 2c 20 27 43 3a 2f 75 73 65 72 73 2f 6a 6f 65  ', 'C:/users/joe
7d10: 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73  /stored_proc_tes
7d20: 74 2f 70 75 67 6c 69 61 5f 31 39 39 31 5f 34 33  t/puglia_1991_43
7d30: 32 36 27 2c 20 27 43 50 31 32 35 32 27 29 3b 0d  26', 'CP1252');.
7d40: 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .---------------
7d50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7d60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7d70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7d80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7d90: 0d 0a 45 78 70 6f 72 74 53 68 70 28 27 74 72 61  ..ExportShp('tra
7da0: 6e 73 69 65 6e 74 5f 74 61 62 6c 65 27 2c 20 27  nsient_table', '
7db0: 67 65 6f 6d 27 2c 20 27 43 3a 2f 75 73 65 72 73  geom', 'C:/users
7dc0: 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70 72 6f 63  /joe/stored_proc
7dd0: 5f 74 65 73 74 2f 70 75 67 6c 69 61 5f 31 39 39  _test/puglia_199
7de0: 31 5f 34 33 32 36 27 2c 20 27 43 50 31 32 35 32  1_4326', 'CP1252
7df0: 27 29 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ')..------------
7e00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7e10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7e20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7e30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7e40: 2d 2d 2d 0d 0a 32 35 37 0d 0a 3d 3d 3d 20 31 20  ---..257..=== 1 
7e50: 72 6f 77 20 3d 3d 3d 20 45 78 65 63 75 74 69 6f  row === Executio
7e60: 6e 20 74 69 6d 65 3a 20 30 2e 30 37 37 0d 0a 0d  n time: 0.077...
7e70: 0a 53 45 4c 45 43 54 20 44 72 6f 70 47 65 6f 54  .SELECT DropGeoT
7e80: 61 62 6c 65 28 27 74 72 61 6e 73 69 65 6e 74 5f  able('transient_
7e90: 74 61 62 6c 65 27 29 3b 0d 0a 2d 2d 2d 2d 2d 2d  table');..------
7ea0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7eb0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 44 72 6f 70 47  ---------..DropG
7ec0: 65 6f 54 61 62 6c 65 28 27 74 72 61 6e 73 69 65  eoTable('transie
7ed0: 6e 74 5f 74 61 62 6c 65 27 29 0d 0a 2d 2d 2d 2d  nt_table')..----
7ee0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7ef0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 0d 0a  -----------..1..
7f00: 3d 3d 3d 20 31 20 72 6f 77 20 3d 3d 3d 20 45 78  === 1 row === Ex
7f10: 65 63 75 74 69 6f 6e 20 74 69 6d 65 3a 20 30 2e  ecution time: 0.
7f20: 30 30 32 0d 0a 0d 0a 3d 3d 3d 3d 3d 3d 3d 3d 3d  002....=========
7f30: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
7f40: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
7f50: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
7f60: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
7f70: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
7f80: 0d 0a 3d 3d 20 20 20 20 20 53 51 4c 20 73 65 73  ..==     SQL ses
7f90: 73 69 6f 6e 20 65 6e 64 20 20 20 3d 20 20 20 32  sion end   =   2
7fa0: 30 31 37 2d 31 32 2d 32 31 20 31 32 3a 35 30 3a  017-12-21 12:50:
7fb0: 30 39 20 20 20 3d 20 20 20 35 20 73 74 61 74 65  09   =   5 state
7fc0: 6d 65 6e 74 73 20 77 65 72 65 20 65 78 65 63 75  ments were execu
7fd0: 74 65 64 0d 0a 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ted..===========
7fe0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
7ff0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
8000: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
8010: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
8020: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 0d 0a  ==============..
8030: 0d 0a 0d 0a 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ....============
8040: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
8050: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
8060: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
8070: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
8080: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 0d 0a 3d  =============..=
8090: 3d 20 20 20 20 20 53 51 4c 20 73 65 73 73 69 6f  =     SQL sessio
80a0: 6e 20 73 74 61 72 74 20 20 20 3d 20 20 20 32 30  n start   =   20
80b0: 31 37 2d 31 32 2d 32 31 20 31 32 3a 35 33 3a 30  17-12-21 12:53:0
80c0: 31 0d 0a 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  1..=============
80d0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
80e0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
80f0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
8100: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
8110: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 0d 0a 53 45  ============..SE
8120: 4c 45 43 54 20 44 72 6f 70 47 65 6f 54 61 62 6c  LECT DropGeoTabl
8130: 65 28 27 74 72 61 6e 73 69 65 6e 74 5f 74 61 62  e('transient_tab
8140: 6c 65 27 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d  le');..---------
8150: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8160: 2d 2d 2d 2d 2d 2d 0d 0a 44 72 6f 70 47 65 6f 54  ------..DropGeoT
8170: 61 62 6c 65 28 27 74 72 61 6e 73 69 65 6e 74 5f  able('transient_
8180: 74 61 62 6c 65 27 29 0d 0a 2d 2d 2d 2d 2d 2d 2d  table')..-------
8190: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
81a0: 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 30 0d 0a 3d 3d 3d  --------..0..===
81b0: 20 31 20 72 6f 77 20 3d 3d 3d 20 45 78 65 63 75   1 row === Execu
81c0: 74 69 6f 6e 20 74 69 6d 65 3a 20 30 2e 30 30 32  tion time: 0.002
81d0: 0d 0a 0d 0a 43 52 45 41 54 45 20 54 41 42 4c 45  ....CREATE TABLE
81e0: 20 74 72 61 6e 73 69 65 6e 74 5f 74 61 62 6c 65   transient_table
81f0: 20 41 53 0d 0a 53 45 4c 45 43 54 20 69 64 2c 20   AS..SELECT id, 
8200: 69 73 74 61 74 2c 20 6e 61 6d 65 2c 20 70 72 6f  istat, name, pro
8210: 76 69 6e 63 65 2c 20 72 65 67 69 6f 6e 2c 20 53  vince, region, S
8220: 54 5f 54 72 61 6e 73 66 6f 72 6d 28 67 65 6f 6d  T_Transform(geom
8230: 2c 20 33 30 30 33 29 20 41 53 20 67 65 6f 6d 0d  , 3003) AS geom.
8240: 0a 46 52 4f 4d 20 6d 75 6e 69 63 69 70 61 6c 69  .FROM municipali
8250: 74 69 65 73 5f 32 30 30 31 0d 0a 57 48 45 52 45  ties_2001..WHERE
8260: 20 28 55 70 70 65 72 28 6e 61 6d 65 29 20 3d 20   (Upper(name) = 
8270: 55 70 70 65 72 28 27 41 52 45 5a 5a 4f 27 29 20  Upper('AREZZO') 
8280: 4f 52 20 55 70 70 65 72 28 70 72 6f 76 69 6e 63  OR Upper(provinc
8290: 65 29 20 3d 20 55 70 70 65 72 28 27 4e 55 4c 4c  e) = Upper('NULL
82a0: 27 29 20 4f 52 20 55 70 70 65 72 28 72 65 67 69  ') OR Upper(regi
82b0: 6f 6e 29 20 3d 20 55 70 70 65 72 28 27 4e 55 4c  on) = Upper('NUL
82c0: 4c 27 29 29 3b 0d 0a 3d 3d 3d 20 45 78 65 63 75  L'));..=== Execu
82d0: 74 69 6f 6e 20 74 69 6d 65 3a 20 30 2e 30 33 32  tion time: 0.032
82e0: 0d 0a 0d 0a 53 45 4c 45 43 54 20 52 65 63 6f 76  ....SELECT Recov
82f0: 65 72 47 65 6f 6d 65 74 72 79 43 6f 6c 75 6d 6e  erGeometryColumn
8300: 28 27 74 72 61 6e 73 69 65 6e 74 5f 74 61 62 6c  ('transient_tabl
8310: 65 27 2c 20 27 67 65 6f 6d 27 2c 20 33 30 30 33  e', 'geom', 3003
8320: 2c 20 27 4d 55 4c 54 49 50 4f 4c 59 47 4f 4e 27  , 'MULTIPOLYGON'
8330: 2c 20 27 58 59 27 29 3b 0d 0a 2d 2d 2d 2d 2d 2d  , 'XY');..------
8340: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8350: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8360: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8370: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8380: 2d 2d 2d 2d 2d 2d 0d 0a 52 65 63 6f 76 65 72 47  ------..RecoverG
8390: 65 6f 6d 65 74 72 79 43 6f 6c 75 6d 6e 28 27 74  eometryColumn('t
83a0: 72 61 6e 73 69 65 6e 74 5f 74 61 62 6c 65 27 2c  ransient_table',
83b0: 20 27 67 65 6f 6d 27 2c 20 33 30 30 33 2c 20 27   'geom', 3003, '
83c0: 4d 55 4c 54 49 50 4f 4c 59 47 4f 4e 27 2c 20 27  MULTIPOLYGON', '
83d0: 58 59 27 29 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  XY')..----------
83e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
83f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8400: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8410: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8420: 2d 2d 0d 0a 31 0d 0a 3d 3d 3d 20 31 20 72 6f 77  --..1..=== 1 row
8430: 20 3d 3d 3d 20 45 78 65 63 75 74 69 6f 6e 20 74   === Execution t
8440: 69 6d 65 3a 20 30 2e 30 31 33 0d 0a 0d 0a 53 45  ime: 0.013....SE
8450: 4c 45 43 54 20 45 78 70 6f 72 74 53 68 70 28 27  LECT ExportShp('
8460: 74 72 61 6e 73 69 65 6e 74 5f 74 61 62 6c 65 27  transient_table'
8470: 2c 20 27 67 65 6f 6d 27 2c 20 27 43 3a 2f 75 73  , 'geom', 'C:/us
8480: 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70  ers/joe/stored_p
8490: 72 6f 63 5f 74 65 73 74 2f 63 6f 6d 5f 61 72 65  roc_test/com_are
84a0: 7a 7a 6f 5f 32 30 30 31 5f 33 30 30 33 27 2c 20  zzo_2001_3003', 
84b0: 27 43 50 31 32 35 32 27 29 3b 0d 0a 2d 2d 2d 2d  'CP1252');..----
84c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
84d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
84e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
84f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8500: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d  ---------------.
8510: 0a 45 78 70 6f 72 74 53 68 70 28 27 74 72 61 6e  .ExportShp('tran
8520: 73 69 65 6e 74 5f 74 61 62 6c 65 27 2c 20 27 67  sient_table', 'g
8530: 65 6f 6d 27 2c 20 27 43 3a 2f 75 73 65 72 73 2f  eom', 'C:/users/
8540: 6a 6f 65 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f  joe/stored_proc_
8550: 74 65 73 74 2f 63 6f 6d 5f 61 72 65 7a 7a 6f 5f  test/com_arezzo_
8560: 32 30 30 31 5f 33 30 30 33 27 2c 20 27 43 50 31  2001_3003', 'CP1
8570: 32 35 32 27 29 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d  252')..---------
8580: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8590: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
85a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
85b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
85c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3d  ----------..1..=
85d0: 3d 3d 20 31 20 72 6f 77 20 3d 3d 3d 20 45 78 65  == 1 row === Exe
85e0: 63 75 74 69 6f 6e 20 74 69 6d 65 3a 20 30 2e 30  cution time: 0.0
85f0: 30 38 0d 0a 0d 0a 53 45 4c 45 43 54 20 44 72 6f  08....SELECT Dro
8600: 70 47 65 6f 54 61 62 6c 65 28 27 74 72 61 6e 73  pGeoTable('trans
8610: 69 65 6e 74 5f 74 61 62 6c 65 27 29 3b 0d 0a 2d  ient_table');..-
8620: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8630: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a  --------------..
8640: 44 72 6f 70 47 65 6f 54 61 62 6c 65 28 27 74 72  DropGeoTable('tr
8650: 61 6e 73 69 65 6e 74 5f 74 61 62 6c 65 27 29 0d  ansient_table').
8660: 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .---------------
8670: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8680: 0d 0a 31 0d 0a 3d 3d 3d 20 31 20 72 6f 77 20 3d  ..1..=== 1 row =
8690: 3d 3d 20 45 78 65 63 75 74 69 6f 6e 20 74 69 6d  == Execution tim
86a0: 65 3a 20 30 2e 30 30 37 0d 0a 0d 0a 3d 3d 3d 3d  e: 0.007....====
86b0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
86c0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
86d0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
86e0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
86f0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
8700: 3d 3d 3d 3d 3d 0d 0a 3d 3d 20 20 20 20 20 53 51  =====..==     SQ
8710: 4c 20 73 65 73 73 69 6f 6e 20 65 6e 64 20 20 20  L session end   
8720: 3d 20 20 20 32 30 31 37 2d 31 32 2d 32 31 20 31  =   2017-12-21 1
8730: 32 3a 35 33 3a 30 31 20 20 20 3d 20 20 20 35 20  2:53:01   =   5 
8740: 73 74 61 74 65 6d 65 6e 74 73 20 77 65 72 65 20  statements were 
8750: 65 78 65 63 75 74 65 64 0d 0a 3d 3d 3d 3d 3d 3d  executed..======
8760: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
8770: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
8780: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
8790: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
87a0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
87b0: 3d 3d 3d 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e  ===..</verbatim>
87c0: 0d 0a 3c 62 72 3e 3c 68 72 3e 0d 0a 3c 68 32 3e  ..<br><hr>..<h2>
87d0: 54 75 74 6f 72 69 61 6c 20 23 35 20 28 61 64 76  Tutorial #5 (adv
87e0: 61 6e 63 65 64 29 3c 2f 68 32 3e 0d 0a 3c 68 33  anced)</h2>..<h3
87f0: 3e 35 2e 31 20 41 64 61 70 74 65 64 20 53 74 6f  >5.1 Adapted Sto
8800: 72 65 64 20 50 72 6f 63 65 64 75 72 65 20 66 6f  red Procedure fo
8810: 72 20 69 73 74 61 74 5f 69 74 3c 2f 68 33 3e 0d  r istat_it</h3>.
8820: 0a 42 61 73 65 64 20 6f 6e 20 3c 62 3e 54 75 74  .Based on <b>Tut
8830: 6f 72 69 61 6c 20 23 32 3c 2f 62 3e 2c 20 62 75  orial #2</b>, bu
8840: 74 20 61 64 61 70 74 65 64 20 73 6f 20 74 68 61  t adapted so tha
8850: 74 20 74 68 65 20 53 74 6f 72 65 64 20 50 72 6f  t the Stored Pro
8860: 63 65 64 75 72 65 73 20 61 72 65 20 63 6f 6e 74  cedures are cont
8870: 61 69 6e 65 64 20 69 6e 20 61 6e 20 65 78 74 65  ained in an exte
8880: 72 6e 61 6c 20 3c 62 3e 3c 69 3e 61 74 74 61 63  rnal <b><i>attac
8890: 68 3c 2f 69 3e 3c 2f 62 3e 65 64 20 44 61 74 61  h</i></b>ed Data
88a0: 62 61 73 65 20 77 68 65 72 65 20 74 68 65 20 73  base where the s
88b0: 6f 75 72 63 65 20 44 61 74 61 62 61 73 65 20 73  ource Database s
88c0: 68 6f 75 6c 64 20 6f 6e 6c 79 20 62 65 20 72 65  hould only be re
88d0: 61 64 20 62 75 74 20 6e 6f 74 20 63 68 61 6e 67  ad but not chang
88e0: 65 64 2e 0d 0a 3c 62 72 3e 3c 62 72 3e 0d 0a 54  ed...<br><br>..T
88f0: 68 65 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64  he Stored Proced
8900: 75 72 65 20 68 61 73 20 62 65 65 6e 20 61 64 61  ure has been ada
8910: 70 74 65 64 20 74 6f 20 73 75 70 70 6f 72 74 20  pted to support 
8920: 61 6e 20 3c 62 3e 3c 69 3e 61 74 74 61 63 68 3c  an <b><i>attach<
8930: 2f 69 3e 3c 2f 62 3e 65 64 20 44 61 74 61 62 61  /i></b>ed Databa
8940: 73 65 2e 3c 62 72 3e 0d 0a 49 74 20 69 73 20 73  se.<br>..It is s
8950: 70 65 63 69 66 69 63 20 66 6f 72 20 74 68 65 20  pecific for the 
8960: 53 6f 75 72 63 65 20 3c 62 3e 69 73 74 61 74 5f  Source <b>istat_
8970: 69 74 3c 2f 62 3e 20 44 61 74 61 62 61 73 65 2e  it</b> Database.
8980: 3c 62 72 3e 0d 0a 3c 62 3e 40 61 74 74 61 63 68  <br>..<b>@attach
8990: 5f 73 63 68 65 6d 61 5f 6e 61 6d 65 40 3c 2f 62  _schema_name@</b
89a0: 3e 20 77 69 6c 6c 20 63 6f 6e 74 61 69 6e 20 74  > will contain t
89b0: 68 65 20 73 63 68 65 6d 61 2d 6e 61 6d 65 20 75  he schema-name u
89c0: 73 65 64 20 69 6e 20 74 68 65 20 63 61 6c 6c 69  sed in the calli
89d0: 6e 67 20 73 63 72 69 70 74 3a 20 0d 0a 3c 76 65  ng script: ..<ve
89e0: 72 62 61 74 69 6d 3e 0d 0a 2d 2d 20 2d 2d 20 2d  rbatim>..-- -- -
89f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8a00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8a10: 2d 20 2d 2d 0d 0a 2d 2d 20 41 54 54 41 43 48 20  - --..-- ATTACH 
8a20: 73 6f 75 72 63 65 20 44 61 74 61 62 61 73 65 20  source Database 
8a30: 41 53 20 27 64 62 5f 73 6f 75 72 63 65 27 0d 0a  AS 'db_source'..
8a40: 2d 2d 20 2d 2d 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  -- -- ----------
8a50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8a60: 2d 2d 2d 2d 2d 2d 2d 2d 20 2d 2d 0d 0a 2d 2d 20  -------- --..-- 
8a70: 4e 6f 74 65 3a 20 53 6f 75 72 63 65 20 44 61 74  Note: Source Dat
8a80: 61 62 61 73 65 20 6d 75 73 74 20 62 65 20 61 74  abase must be at
8a90: 74 61 63 68 65 64 20 62 65 66 6f 72 65 20 74 68  tached before th
8aa0: 69 73 20 69 73 20 63 61 6c 6c 65 64 0d 0a 2d 2d  is is called..--
8ab0: 20 20 49 66 20 63 61 6c 6c 65 64 20 66 72 6f 6d    If called from
8ac0: 20 69 6e 73 69 64 65 20 61 20 53 74 6f 72 65 64   inside a Stored
8ad0: 20 50 72 6f 63 65 64 75 72 65 73 20 77 69 6c 6c   Procedures will
8ae0: 20 77 6f 72 6b 20 74 68 65 20 66 69 72 73 74 20   work the first 
8af0: 74 69 6d 65 2c 0d 0a 2d 2d 20 20 20 74 68 65 6e  time,..--   then
8b00: 20 66 61 69 6c 20 77 69 74 68 20 27 67 61 69 61   fail with 'gaia
8b10: 5f 73 71 6c 5f 70 72 6f 63 5f 65 78 65 63 75 74  _sql_proc_execut
8b20: 65 3a 20 64 61 74 61 62 61 73 65 20 64 62 5f 73  e: database db_s
8b30: 6f 75 72 63 65 20 69 73 20 61 6c 72 65 61 64 79  ource is already
8b40: 20 69 6e 20 75 73 65 27 0d 0a 2d 2d 20 2d 2d 20   in use'..-- -- 
8b50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8b60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8b70: 2d 2d 20 2d 2d 0d 0a 2d 2d 20 72 65 6d 6f 76 69  -- --..-- removi
8b80: 6e 67 20 74 68 65 20 77 6f 72 6b 20 74 61 62 6c  ng the work tabl
8b90: 65 20 28 6a 75 73 74 20 69 6e 20 63 61 73 65 20  e (just in case 
8ba0: 69 74 20 61 6c 72 65 61 64 79 20 65 78 69 73 74  it already exist
8bb0: 73 29 0d 0a 2d 2d 20 2d 2d 20 2d 2d 2d 2d 2d 2d  s)..-- -- ------
8bc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8bd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 20 2d 2d 0d  ------------ --.
8be0: 0a 53 45 4c 45 43 54 20 44 72 6f 70 47 65 6f 54  .SELECT DropGeoT
8bf0: 61 62 6c 65 28 27 74 72 61 6e 73 69 65 6e 74 5f  able('transient_
8c00: 74 61 62 6c 65 27 29 3b 0d 0a 2d 2d 20 2d 2d 20  table');..-- -- 
8c10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8c20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8c30: 2d 2d 20 2d 2d 0d 0a 2d 2d 20 69 6e 73 65 72 74  -- --..-- insert
8c40: 69 6e 67 20 73 65 6c 65 63 74 65 64 20 69 73 74  ing selected ist
8c50: 61 74 5f 69 74 20 64 61 74 61 20 69 6e 74 6f 20  at_it data into 
8c60: 74 68 65 20 77 6f 72 6b 20 74 61 62 6c 65 0d 0a  the work table..
8c70: 2d 2d 20 2d 2d 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  -- -- ----------
8c80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8c90: 2d 2d 2d 2d 2d 2d 2d 2d 20 2d 2d 0d 0a 2d 2d 20  -------- --..-- 
8ca0: 53 45 4c 45 43 54 20 44 61 74 65 54 69 6d 65 28  SELECT DateTime(
8cb0: 27 6e 6f 77 27 2c 27 6c 6f 63 61 6c 74 69 6d 65  'now','localtime
8cc0: 27 29 2c 27 63 61 6c 6c 69 6e 67 3a 20 43 52 45  '),'calling: CRE
8cd0: 41 54 45 20 54 41 42 4c 45 27 3b 0d 0a 43 52 45  ATE TABLE';..CRE
8ce0: 41 54 45 20 54 41 42 4c 45 20 74 72 61 6e 73 69  ATE TABLE transi
8cf0: 65 6e 74 5f 74 61 62 6c 65 20 41 53 0d 0a 53 45  ent_table AS..SE
8d00: 4c 45 43 54 20 69 64 2c 0d 0a 20 69 73 74 61 74  LECT id,.. istat
8d10: 2c 0d 0a 20 6e 61 6d 65 2c 0d 0a 20 70 72 6f 76  ,.. name,.. prov
8d20: 69 6e 63 65 2c 0d 0a 20 72 65 67 69 6f 6e 2c 0d  ince,.. region,.
8d30: 0a 20 53 54 5f 54 72 61 6e 73 66 6f 72 6d 28 67  . ST_Transform(g
8d40: 65 6f 6d 2c 20 40 73 72 69 64 40 29 20 41 53 20  eom, @srid@) AS 
8d50: 67 65 6f 6d 0d 0a 46 52 4f 4d 20 27 40 61 74 74  geom..FROM '@att
8d60: 61 63 68 5f 73 63 68 65 6d 61 5f 6e 61 6d 65 40  ach_schema_name@
8d70: 27 2e 6d 75 6e 69 63 69 70 61 6c 69 74 69 65 73  '.municipalities
8d80: 5f 40 79 65 61 72 40 0d 0a 57 48 45 52 45 0d 0a  _@year@..WHERE..
8d90: 28 0d 0a 20 55 70 70 65 72 28 6e 61 6d 65 29 20  (.. Upper(name) 
8da0: 3d 20 55 70 70 65 72 28 27 40 6d 75 6e 69 63 69  = Upper('@munici
8db0: 70 61 6c 69 74 79 40 27 29 20 4f 52 20 55 70 70  pality@') OR Upp
8dc0: 65 72 28 70 72 6f 76 69 6e 63 65 29 20 3d 20 55  er(province) = U
8dd0: 70 70 65 72 28 27 40 70 72 6f 76 69 6e 63 65 40  pper('@province@
8de0: 27 29 20 4f 52 20 55 70 70 65 72 28 72 65 67 69  ') OR Upper(regi
8df0: 6f 6e 29 20 3d 20 55 70 70 65 72 28 27 40 72 65  on) = Upper('@re
8e00: 67 69 6f 6e 40 27 29 0d 0a 29 3b 0d 0a 2d 2d 20  gion@')..);..-- 
8e10: 2d 2d 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  -- -------------
8e20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8e30: 2d 2d 2d 2d 2d 20 2d 2d 0d 0a 2d 2d 20 70 72 6f  ----- --..-- pro
8e40: 70 65 72 6c 79 20 72 65 63 6f 76 65 72 69 6e 67  perly recovering
8e50: 20 74 68 65 20 77 6f 72 6b 20 74 61 62 6c 65 0d   the work table.
8e60: 0a 2d 2d 20 2d 2d 20 2d 2d 2d 2d 2d 2d 2d 2d 2d  .-- -- ---------
8e70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8e80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 20 2d 2d 0d 0a 2d 2d  --------- --..--
8e90: 20 53 45 4c 45 43 54 20 44 61 74 65 54 69 6d 65   SELECT DateTime
8ea0: 28 27 6e 6f 77 27 2c 27 6c 6f 63 61 6c 74 69 6d  ('now','localtim
8eb0: 65 27 29 2c 27 63 61 6c 6c 69 6e 67 3a 20 52 65  e'),'calling: Re
8ec0: 63 6f 76 65 72 47 65 6f 6d 65 74 72 79 43 6f 6c  coverGeometryCol
8ed0: 75 6d 6e 27 3b 0d 0a 53 45 4c 45 43 54 20 52 65  umn';..SELECT Re
8ee0: 63 6f 76 65 72 47 65 6f 6d 65 74 72 79 43 6f 6c  coverGeometryCol
8ef0: 75 6d 6e 28 27 74 72 61 6e 73 69 65 6e 74 5f 74  umn('transient_t
8f00: 61 62 6c 65 27 2c 20 27 67 65 6f 6d 27 2c 20 40  able', 'geom', @
8f10: 73 72 69 64 40 2c 20 27 4d 55 4c 54 49 50 4f 4c  srid@, 'MULTIPOL
8f20: 59 47 4f 4e 27 2c 20 27 58 59 27 29 3b 0d 0a 2d  YGON', 'XY');..-
8f30: 2d 20 2d 2d 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  - -- -----------
8f40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8f50: 2d 2d 2d 2d 2d 2d 2d 20 2d 2d 0d 0a 2d 2d 20 65  ------- --..-- e
8f60: 78 70 6f 72 74 69 6e 67 20 66 72 6f 6d 20 74 68  xporting from th
8f70: 65 20 77 6f 72 6b 20 74 61 62 6c 65 20 69 6e 74  e work table int
8f80: 6f 20 74 68 65 20 53 68 61 70 65 66 69 6c 65 0d  o the Shapefile.
8f90: 0a 2d 2d 20 2d 2d 20 2d 2d 2d 2d 2d 2d 2d 2d 2d  .-- -- ---------
8fa0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
8fb0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 20 2d 2d 0d 0a 2d 2d  --------- --..--
8fc0: 20 53 45 4c 45 43 54 20 44 61 74 65 54 69 6d 65   SELECT DateTime
8fd0: 28 27 6e 6f 77 27 2c 27 6c 6f 63 61 6c 74 69 6d  ('now','localtim
8fe0: 65 27 29 2c 27 63 61 6c 6c 69 6e 67 3a 20 45 78  e'),'calling: Ex
8ff0: 70 6f 72 74 53 68 70 27 3b 0d 0a 53 45 4c 45 43  portShp';..SELEC
9000: 54 20 45 78 70 6f 72 74 53 68 70 28 27 74 72 61  T ExportShp('tra
9010: 6e 73 69 65 6e 74 5f 74 61 62 6c 65 27 2c 20 27  nsient_table', '
9020: 67 65 6f 6d 27 2c 20 27 40 73 68 70 5f 64 69 72  geom', '@shp_dir
9030: 65 63 74 6f 72 79 40 2f 40 73 68 70 5f 66 69 6c  ectory@/@shp_fil
9040: 65 40 27 2c 20 27 43 50 31 32 35 32 27 29 3b 0d  e@', 'CP1252');.
9050: 0a 2d 2d 20 2d 2d 20 2d 2d 2d 2d 2d 2d 2d 2d 2d  .-- -- ---------
9060: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9070: 2d 2d 2d 2d 2d 2d 2d 2d 2d 20 2d 2d 0d 0a 2d 2d  --------- --..--
9080: 20 72 65 6d 6f 76 69 6e 67 20 74 68 65 20 77 6f   removing the wo
9090: 72 6b 20 74 61 62 6c 65 0d 0a 2d 2d 20 2d 2d 20  rk table..-- -- 
90a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
90b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
90c0: 2d 2d 20 2d 2d 0d 0a 2d 2d 20 53 45 4c 45 43 54  -- --..-- SELECT
90d0: 20 44 61 74 65 54 69 6d 65 28 27 6e 6f 77 27 2c   DateTime('now',
90e0: 27 6c 6f 63 61 6c 74 69 6d 65 27 29 2c 27 63 61  'localtime'),'ca
90f0: 6c 6c 69 6e 67 3a 20 44 72 6f 70 47 65 6f 54 61  lling: DropGeoTa
9100: 62 6c 65 27 3b 0d 0a 53 45 4c 45 43 54 20 44 72  ble';..SELECT Dr
9110: 6f 70 47 65 6f 54 61 62 6c 65 28 27 74 72 61 6e  opGeoTable('tran
9120: 73 69 65 6e 74 5f 74 61 62 6c 65 27 29 3b 0d 0a  sient_table');..
9130: 2d 2d 20 2d 2d 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  -- -- ----------
9140: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9150: 2d 2d 2d 2d 2d 2d 2d 2d 20 2d 2d 0d 0a 3c 2f 76  -------- --..</v
9160: 65 72 62 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c 65  erbatim>..<table
9170: 20 62 67 63 6f 6c 6f 72 3d 22 23 66 38 66 38 64   bgcolor="#f8f8d
9180: 38 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22  8" cellpadding="
9190: 36 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22  6" cellspacing="
91a0: 38 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 3c 75 3e  8"><tr><td>..<u>
91b0: 4e 6f 74 65 73 3c 2f 75 3e 3a 20 44 69 66 66 65  Notes</u>: Diffe
91c0: 72 65 6e 63 65 20 66 72 6f 6d 20 6d 61 69 6e 20  rence from main 
91d0: 53 61 6d 70 6c 65 3a 3c 62 72 3e 0d 0a 54 68 65  Sample:<br>..The
91e0: 20 63 61 6c 6c 69 6e 67 20 73 63 72 69 70 74 20   calling script 
91f0: 77 69 6c 6c 20 72 75 6e 20 61 67 61 69 6e 73 74  will run against
9200: 20 74 68 65 20 44 61 74 61 62 61 73 65 20 74 68   the Database th
9210: 61 74 20 63 6f 6e 74 61 69 6e 73 20 74 68 69 73  at contains this
9220: 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72   Stored Procedur
9230: 65 20 61 6e 64 20 41 54 54 41 43 48 20 74 68 65  e and ATTACH the
9240: 20 73 6f 75 72 63 65 20 44 61 74 61 62 61 73 65   source Database
9250: 20 75 73 69 6e 67 20 61 20 3c 62 3e 73 63 68 65   using a <b>sche
9260: 6d 61 2d 6e 61 6d 65 3c 2f 62 3e 2e 0d 0a 3c 75  ma-name</b>...<u
9270: 6c 3e 0d 0a 3c 6c 69 3e 55 73 65 20 6f 66 20 41  l>..<li>Use of A
9280: 54 54 41 43 48 2f 44 45 54 41 43 48 20 66 72 6f  TTACH/DETACH fro
9290: 6d 20 69 6e 73 69 64 65 20 61 20 53 74 6f 72 65  m inside a Store
92a0: 64 20 50 72 6f 63 65 64 75 72 65 73 20 77 69 6c  d Procedures wil
92b0: 6c 20 77 6f 72 6b 20 74 68 65 20 66 69 72 73 74  l work the first
92c0: 20 74 69 6d 65 2c 62 75 74 20 66 61 69 6c 20 77   time,but fail w
92d0: 68 65 6e 20 63 61 6c 6c 65 64 20 61 67 61 69 6e  hen called again
92e0: 20 77 69 74 68 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69   with..<ul>..<li
92f0: 3e 27 67 61 69 61 5f 73 71 6c 5f 70 72 6f 63 5f  >'gaia_sql_proc_
9300: 65 78 65 63 75 74 65 3a 20 3c 62 3e 64 61 74 61  execute: <b>data
9310: 62 61 73 65 20 64 62 5f 73 6f 75 72 63 65 20 69  base db_source i
9320: 73 20 61 6c 72 65 61 64 79 20 69 6e 20 75 73 65  s already in use
9330: 3c 2f 62 3e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e  </b></li>..</ul>
9340: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 54 65 6d 70 6f  </li>..<li>Tempo
9350: 72 61 72 79 20 54 41 42 4c 45 20 63 72 65 61 74  rary TABLE creat
9360: 65 64 20 69 6e 20 64 75 72 69 6e 67 20 74 68 65  ed in during the
9370: 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72   Stored Procedur
9380: 65 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 77 69 6c  e..<ul>..<li>wil
9390: 6c 20 62 65 20 63 6f 6e 74 61 69 6e 65 64 20 69  l be contained i
93a0: 6e 20 74 68 65 20 53 74 6f 72 65 64 20 50 72 6f  n the Stored Pro
93b0: 63 65 64 75 72 65 73 20 44 61 74 61 62 61 73 65  cedures Database
93c0: 20 61 6e 64 20 6e 6f 74 20 69 6e 20 74 68 65 20   and not in the 
93d0: 73 6f 75 72 63 65 20 44 61 74 61 62 61 73 65 2e  source Database.
93e0: 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 2f 6c 69  </li>..</ul></li
93f0: 3e 0d 0a 3c 6c 69 3e 53 45 4c 45 43 54 20 6d 65  >..<li>SELECT me
9400: 73 73 61 67 65 73 20 63 61 6c 6c 65 64 20 64 75  ssages called du
9410: 72 69 6e 67 20 74 68 65 20 53 74 6f 72 65 64 20  ring the Stored 
9420: 50 72 6f 63 65 64 75 72 65 0d 0a 3c 75 6c 3e 0d  Procedure..<ul>.
9430: 0a 3c 6c 69 3e 77 69 6c 6c 20 62 65 20 6e 6f 74  .<li>will be not
9440: 20 62 65 20 73 68 6f 77 6e 20 61 6e 64 20 68 61   be shown and ha
9450: 76 65 20 62 65 65 6e 20 63 6f 6d 6d 65 6e 74 65  ve been commente
9460: 64 20 6f 75 74 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75  d out.</li>..</u
9470: 6c 3e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 54 68 65  l></li>..<li>The
9480: 20 45 78 70 6f 72 74 20 53 68 61 70 65 20 64 69   Export Shape di
9490: 72 65 63 74 6f 72 79 20 61 6e 64 20 66 69 6c 65  rectory and file
94a0: 20 6e 61 6d 65 73 20 61 72 65 20 73 65 70 65 72   names are seper
94b0: 61 74 65 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 77  ate..<ul>..<li>w
94c0: 61 73 20 3c 62 3e 73 68 70 5f 70 61 74 68 3c 2f  as <b>shp_path</
94d0: 62 3e 2c 20 6e 6f 77 20 3c 62 3e 73 68 70 5f 64  b>, now <b>shp_d
94e0: 69 72 65 63 74 6f 72 79 3c 2f 62 3e 20 61 6e 64  irectory</b> and
94f0: 20 3c 62 3e 73 68 70 5f 66 69 6c 65 3c 2f 62 3e   <b>shp_file</b>
9500: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 54 68 65 20  .</li>..<li>The 
9510: 6e 65 65 64 65 64 20 64 69 72 65 63 74 6f 72 79  needed directory
9520: 20 22 2f 22 20 62 65 74 77 65 65 6e 20 73 68 70   "/" between shp
9530: 5f 64 69 72 65 63 74 6f 72 79 20 61 6e 64 20 73  _directory and s
9540: 68 70 5f 66 69 6c 65 20 77 69 6c 6c 20 62 65 20  hp_file will be 
9550: 61 64 64 65 64 20 68 65 72 65 2e 3c 2f 6c 69 3e  added here.</li>
9560: 0d 0a 3c 2f 75 6c 3e 3c 2f 6c 69 3e 0d 0a 3c 2f  ..</ul></li>..</
9570: 75 6c 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 3c  ul>..</td></tr><
9580: 2f 74 61 62 6c 65 3e 0d 0a 3c 62 72 3e 3c 68 72  /table>..<br><hr
9590: 3e 0d 0a 3c 68 33 3e 35 2e 32 20 43 72 65 61 74  >..<h3>5.2 Creat
95a0: 69 6e 67 20 53 74 6f 72 65 64 20 50 72 6f 63 65  ing Stored Proce
95b0: 64 75 72 65 20 44 61 74 61 62 61 73 65 3c 2f 68  dure Database</h
95c0: 33 3e 0d 0a 54 68 65 20 53 74 6f 72 65 64 20 50  3>..The Stored P
95d0: 72 6f 63 65 64 75 72 65 20 61 6e 64 20 70 6f 73  rocedure and pos
95e0: 73 69 62 6c 65 20 64 65 66 61 75 6c 74 20 76 61  sible default va
95f0: 6c 75 65 73 20 77 69 6c 6c 20 62 65 20 73 74 6f  lues will be sto
9600: 72 65 64 20 69 6e 20 74 68 65 20 63 72 65 61 74  red in the creat
9610: 65 64 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64  ed Stored Proced
9620: 75 72 65 73 20 44 61 74 61 62 61 73 65 2e 3c 62  ures Database.<b
9630: 72 3e 0d 0a 3c 62 3e 40 61 74 74 61 63 68 5f 73  r>..<b>@attach_s
9640: 63 68 65 6d 61 5f 6e 61 6d 65 40 3c 2f 62 3e 20  chema_name@</b> 
9650: 77 69 6c 6c 20 63 6f 6e 74 61 69 6e 20 74 68 65  will contain the
9660: 20 73 63 68 65 6d 61 2d 6e 61 6d 65 20 75 73 65   schema-name use
9670: 64 20 69 6e 20 74 68 65 20 63 61 6c 6c 69 6e 67  d in the calling
9680: 20 73 63 72 69 70 74 3a 0d 0a 3c 76 65 72 62 61   script:..<verba
9690: 74 69 6d 3e 0d 0a 2d 2d 20 2d 2d 20 2d 2d 2d 2d  tim>..-- -- ----
96a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
96b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 20 2d  -------------- -
96c0: 2d 0d 0a 2d 2d 20 65 78 70 6f 72 74 20 53 50 41  -..-- export SPA
96d0: 54 49 41 4c 49 54 45 5f 53 45 43 55 52 49 54 59  TIALITE_SECURITY
96e0: 3d 72 65 6c 61 78 65 64 0d 0a 2d 2d 20 72 6d 20  =relaxed..-- rm 
96f0: 73 74 6f 72 65 64 5f 70 72 6f 63 65 64 75 72 65  stored_procedure
9700: 5f 64 62 2e 64 62 0d 0a 2d 2d 20 73 70 61 74 69  _db.db..-- spati
9710: 61 6c 69 74 65 20 73 74 6f 72 65 64 5f 70 72 6f  alite stored_pro
9720: 63 65 64 75 72 65 5f 64 62 2e 64 62 20 0d 0a 3c  cedure_db.db ..<
9730: 2f 76 65 72 62 61 74 69 6d 3e 20 0d 0a 3c 74 61  /verbatim> ..<ta
9740: 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 66 38  ble bgcolor="#f8
9750: 66 38 64 38 22 20 63 65 6c 6c 70 61 64 64 69 6e  f8d8" cellpaddin
9760: 67 3d 22 36 22 20 63 65 6c 6c 73 70 61 63 69 6e  g="6" cellspacin
9770: 67 3d 22 38 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a  g="8"><tr><td>..
9780: 3c 75 3e 4e 6f 74 65 73 3c 2f 75 3e 3a 20 44 69  <u>Notes</u>: Di
9790: 66 66 65 72 65 6e 63 65 20 66 72 6f 6d 20 6d 61  fference from ma
97a0: 69 6e 20 53 61 6d 70 6c 65 3a 0d 0a 3c 75 6c 3e  in Sample:..<ul>
97b0: 0d 0a 3c 6c 69 3e 54 68 65 20 63 61 6c 6c 65 64  ..<li>The called
97c0: 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72   Stored Procedur
97d0: 65 20 69 73 20 73 70 65 63 69 66 69 63 20 74 6f  e is specific to
97e0: 20 74 68 65 20 41 54 54 41 43 48 65 64 20 73 6f   the ATTACHed so
97f0: 75 72 63 65 20 44 61 74 61 62 61 73 65 2e 0d 0a  urce Database...
9800: 3c 75 6c 3e 0d 0a 3c 6c 69 3e 63 61 72 65 20 6d  <ul>..<li>care m
9810: 75 73 74 20 62 65 20 74 61 6b 65 6e 20 74 68 61  ust be taken tha
9820: 74 20 74 68 65 79 20 62 6f 74 68 20 6d 61 74 63  t they both matc
9830: 68 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 2f 6c  h</li>..</ul></l
9840: 69 3e 0d 0a 3c 6c 69 3e 41 20 64 69 66 66 65 72  i>..<li>A differ
9850: 65 6e 74 20 53 6f 75 72 63 65 20 44 61 74 61 62  ent Source Datab
9860: 61 73 65 20 63 61 6e 20 62 65 20 61 64 64 65 64  ase can be added
9870: 20 64 75 72 69 6e 67 20 74 68 65 20 63 61 6c 6c   during the call
9880: 69 6e 67 20 73 63 72 69 70 74 0d 0a 3c 75 6c 3e  ing script..<ul>
9890: 0d 0a 3c 6c 69 3e 74 68 61 74 20 6d 75 73 74 20  ..<li>that must 
98a0: 63 61 6c 6c 20 61 20 63 6f 72 72 65 73 70 6f 6e  call a correspon
98b0: 64 69 6e 67 20 45 78 70 6f 72 74 20 53 74 6f 72  ding Export Stor
98c0: 65 64 20 50 72 6f 63 65 64 75 72 65 2e 3c 2f 6c  ed Procedure.</l
98d0: 69 3e 0d 0a 3c 2f 75 6c 3e 3c 2f 6c 69 3e 0d 0a  i>..</ul></li>..
98e0: 3c 6c 69 3e 54 68 65 20 53 68 61 70 65 20 6f 75  <li>The Shape ou
98f0: 74 70 75 74 20 64 69 72 65 63 74 6f 72 79 0d 0a  tput directory..
9900: 3c 75 6c 3e 0d 0a 3c 6c 69 3e 6d 61 79 20 62 65  <ul>..<li>may be
9910: 2c 20 62 75 74 20 6d 75 73 74 20 6e 6f 74 20 62  , but must not b
9920: 65 20 74 68 65 20 73 61 6d 65 20 66 6f 72 20 61  e the same for a
9930: 6c 6c 20 65 78 70 6f 72 74 65 64 20 53 68 61 70  ll exported Shap
9940: 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c  es.</li>..</ul><
9950: 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 2f 74  /li>..</ul>..</t
9960: 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d  d></tr></table>.
9970: 0a 3c 62 72 3e 3c 68 72 3e 0d 0a 3c 68 33 3e 35  .<br><hr>..<h3>5
9980: 2e 33 20 54 68 65 20 63 61 6c 6c 69 6e 67 20 73  .3 The calling s
9990: 63 72 69 70 74 2c 20 70 6f 73 73 69 62 6c 79 20  cript, possibly 
99a0: 63 61 6c 6c 69 6e 67 20 64 69 66 66 65 72 65 6e  calling differen
99b0: 63 65 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64  ce Stored Proced
99c0: 75 72 65 73 20 61 6e 64 20 73 6f 75 72 63 65 20  ures and source 
99d0: 44 61 74 61 62 61 73 65 73 3c 2f 68 33 3e 0d 0a  Databases</h3>..
99e0: 54 68 65 20 53 74 6f 72 65 64 20 50 72 6f 63 65  The Stored Proce
99f0: 64 75 72 65 20 61 6e 64 20 70 6f 73 73 69 62 6c  dure and possibl
9a00: 65 20 64 65 66 61 75 6c 74 20 76 61 6c 75 65 73  e default values
9a10: 20 77 69 6c 6c 20 62 65 20 73 74 6f 72 65 64 20   will be stored 
9a20: 69 6e 20 74 68 65 20 63 72 65 61 74 65 64 20 53  in the created S
9a30: 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65 73  tored Procedures
9a40: 20 44 61 74 61 62 61 73 65 2e 3c 62 72 3e 0d 0a   Database.<br>..
9a50: 44 69 66 66 65 72 65 6e 74 20 53 6f 75 72 63 65  Different Source
9a60: 20 44 61 74 61 62 61 73 65 73 2c 20 75 73 69 6e   Databases, usin
9a70: 67 20 64 69 66 66 65 72 65 6e 74 20 53 74 6f 72  g different Stor
9a80: 65 64 20 50 72 6f 63 65 64 75 72 65 2c 20 63 6f  ed Procedure, co
9a90: 75 6c 64 20 62 65 20 75 73 65 64 20 77 69 74 68  uld be used with
9aa0: 69 6e 20 6f 6e 65 20 73 63 72 69 70 74 3a 20 0d  in one script: .
9ab0: 0a 3c 76 65 72 62 61 74 69 6d 3e 2d 2d 20 2d 2d  .<verbatim>-- --
9ac0: 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d   ---------------
9ad0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9ae0: 2d 2d 2d 20 2d 2d 0d 0a 2d 2d 20 65 78 70 6f 72  --- --..-- expor
9af0: 74 20 53 50 41 54 49 41 4c 49 54 45 5f 53 45 43  t SPATIALITE_SEC
9b00: 55 52 49 54 59 3d 72 65 6c 61 78 65 64 0d 0a 2d  URITY=relaxed..-
9b10: 2d 20 73 70 61 74 69 61 6c 69 74 65 20 73 74 6f  - spatialite sto
9b20: 72 65 64 5f 70 72 6f 63 65 64 75 72 65 5f 64 62  red_procedure_db
9b30: 2e 64 62 20 20 63 72 65 61 74 65 64 20 77 69 74  .db  created wit
9b40: 68 20 27 73 74 6f 72 65 2e 65 78 70 6f 72 74 5f  h 'store.export_
9b50: 73 68 61 70 65 2e 73 70 2e 73 71 6c 27 0d 0a 2d  shape.sp.sql'..-
9b60: 2d 20 54 65 6d 70 6f 72 61 72 79 20 54 41 42 4c  - Temporary TABL
9b70: 45 53 20 63 72 65 61 74 65 64 20 69 6e 20 64 75  ES created in du
9b80: 72 69 6e 67 20 74 68 65 20 53 74 6f 72 65 64 20  ring the Stored 
9b90: 50 72 6f 63 65 64 75 72 65 0d 0a 2d 2d 20 20 77  Procedure..--  w
9ba0: 69 6c 6c 20 62 65 20 63 6f 6e 74 61 69 6e 65 64  ill be contained
9bb0: 20 69 6e 20 74 68 65 20 53 74 6f 72 65 64 20 50   in the Stored P
9bc0: 72 6f 63 65 64 75 72 65 73 20 44 61 74 61 62 61  rocedures Databa
9bd0: 73 65 20 61 6e 64 20 6e 6f 74 20 69 6e 20 74 68  se and not in th
9be0: 65 20 73 6f 75 72 63 65 20 44 61 74 61 62 61 73  e source Databas
9bf0: 65 2e 0d 0a 2d 2d 20 2d 2d 20 2d 2d 2d 2d 2d 2d  e...-- -- ------
9c00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9c10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 20 2d 2d 0d  ------------ --.
9c20: 0a 2d 2d 20 55 73 65 20 61 20 4c 6f 67 2d 66 69  .-- Use a Log-fi
9c30: 6c 65 20 66 6f 72 20 64 65 62 75 67 67 69 6e 67  le for debugging
9c40: 0d 0a 2d 2d 20 2d 3e 20 77 69 6c 6c 20 62 65 20  ..-- -> will be 
9c50: 77 72 69 74 74 65 6e 20 69 6e 20 74 68 65 20 73  written in the s
9c60: 61 6d 65 20 64 69 72 65 63 74 6f 72 79 20 61 73  ame directory as
9c70: 20 74 68 65 20 73 63 72 69 70 74 0d 0a 2d 2d 20   the script..-- 
9c80: 2d 2d 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  -- -------------
9c90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9ca0: 2d 2d 2d 2d 2d 20 2d 2d 0d 0a 53 45 4c 45 43 54  ----- --..SELECT
9cb0: 20 53 71 6c 50 72 6f 63 5f 53 65 74 4c 6f 67 66   SqlProc_SetLogf
9cc0: 69 6c 65 20 28 20 27 6c 6f 67 2e 73 65 6c 65 63  ile ( 'log.selec
9cd0: 74 2e 65 78 70 6f 72 74 5f 73 68 61 70 65 5f 66  t.export_shape_f
9ce0: 72 6f 6d 5f 64 62 2e 74 78 74 27 20 29 3b 0d 0a  rom_db.txt' );..
9cf0: 2d 2d 20 2d 2d 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  -- -- ----------
9d00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9d10: 2d 2d 2d 2d 2d 2d 2d 2d 20 2d 2d 0d 0a 2d 2d 20  -------- --..-- 
9d20: 41 74 74 61 63 68 20 73 6f 75 72 63 65 20 44 61  Attach source Da
9d30: 74 61 62 61 73 65 20 66 6f 72 20 75 73 65 20 66  tabase for use f
9d40: 72 6f 6d 20 74 68 69 73 20 73 63 72 69 70 74 0d  rom this script.
9d50: 0a 2d 2d 20 4e 6f 74 65 3a 20 75 73 65 20 6f 66  .-- Note: use of
9d60: 20 41 54 54 41 43 48 2f 44 45 54 41 43 48 20 66   ATTACH/DETACH f
9d70: 72 6f 6d 20 69 6e 73 69 64 65 20 61 0d 0a 2d 2d  rom inside a..--
9d80: 20 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75    Stored Procedu
9d90: 72 65 73 20 77 69 6c 6c 20 77 6f 72 6b 20 74 68  res will work th
9da0: 65 20 66 69 72 73 74 20 74 69 6d 65 2c 0d 0a 2d  e first time,..-
9db0: 2d 20 20 20 74 68 65 6e 20 66 61 69 6c 20 77 69  -   then fail wi
9dc0: 74 68 20 27 67 61 69 61 5f 73 71 6c 5f 70 72 6f  th 'gaia_sql_pro
9dd0: 63 5f 65 78 65 63 75 74 65 3a 20 64 61 74 61 62  c_execute: datab
9de0: 61 73 65 20 64 62 5f 73 6f 75 72 63 65 20 69 73  ase db_source is
9df0: 20 61 6c 72 65 61 64 79 20 69 6e 20 75 73 65 27   already in use'
9e00: 0d 0a 2d 2d 20 2d 2d 20 2d 2d 2d 2d 2d 2d 2d 2d  ..-- -- --------
9e10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9e20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 20 2d 2d 0d 0a 2d  ---------- --..-
9e30: 2d 20 53 45 4c 45 43 54 20 44 61 74 65 54 69 6d  - SELECT DateTim
9e40: 65 28 27 6e 6f 77 27 2c 27 6c 6f 63 61 6c 74 69  e('now','localti
9e50: 6d 65 27 29 2c 27 63 61 6c 6c 69 6e 67 3a 20 41  me'),'calling: A
9e60: 54 54 41 43 48 20 44 41 54 41 42 41 53 45 27 3b  TTACH DATABASE';
9e70: 0d 0a 2d 2d 20 2d 2d 20 2d 2d 2d 2d 2d 2d 2d 2d  ..-- -- --------
9e80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9e90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 20 2d 2d 0d 0a 2d  ---------- --..-
9ea0: 2d 20 54 68 65 20 75 73 65 64 20 73 63 68 65 6d  - The used schem
9eb0: 61 2d 6e 61 6d 65 20 6d 75 73 74 20 62 65 20 70  a-name must be p
9ec0: 61 73 73 65 64 20 6f 6e 20 74 6f 20 74 68 65 20  assed on to the 
9ed0: 63 61 6c 6c 65 64 20 53 74 6f 72 65 64 20 50 72  called Stored Pr
9ee0: 6f 63 65 64 75 72 65 0d 0a 2d 2d 20 2d 3e 20 27  ocedure..-- -> '
9ef0: 64 62 5f 73 6f 75 72 63 65 27 0d 0a 2d 2d 20 2d  db_source'..-- -
9f00: 2d 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  - --------------
9f10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9f20: 2d 2d 2d 2d 20 2d 2d 0d 0a 41 54 54 41 43 48 20  ---- --..ATTACH 
9f30: 44 41 54 41 42 41 53 45 20 27 73 6f 75 72 63 65  DATABASE 'source
9f40: 5f 64 62 2f 73 70 5f 73 61 6d 70 6c 65 5f 64 62  _db/sp_sample_db
9f50: 2e 64 62 27 20 41 53 20 64 62 5f 73 6f 75 72 63  .db' AS db_sourc
9f60: 65 3b 0d 0a 2d 2d 20 2d 2d 20 2d 2d 2d 2d 2d 2d  e;..-- -- ------
9f70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
9f80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 20 2d 2d 0d  ------------ --.
9f90: 0a 2d 2d 20 53 45 4c 45 43 54 20 44 61 74 65 54  .-- SELECT DateT
9fa0: 69 6d 65 28 27 6e 6f 77 27 2c 27 6c 6f 63 61 6c  ime('now','local
9fb0: 74 69 6d 65 27 29 2c 22 63 61 6c 6c 69 6e 67 3a  time'),"calling:
9fc0: 20 27 65 78 70 6f 72 74 5f 73 68 61 70 65 27 20   'export_shape' 
9fd0: 66 6f 72 20 4c 61 7a 69 6f 22 3b 0d 0a 53 45 4c  for Lazio";..SEL
9fe0: 45 43 54 20 53 74 6f 72 65 64 50 72 6f 63 5f 45  ECT StoredProc_E
9ff0: 78 65 63 75 74 65 28 20 27 65 78 70 6f 72 74 5f  xecute( 'export_
a000: 73 68 61 70 65 27 2c 0d 0a 20 20 20 20 27 40 61  shape',..    '@a
a010: 74 74 61 63 68 5f 73 63 68 65 6d 61 5f 6e 61 6d  ttach_schema_nam
a020: 65 40 3d 64 62 5f 73 6f 75 72 63 65 27 2c 0d 0a  e@=db_source',..
a030: 20 20 20 20 27 40 79 65 61 72 40 3d 32 30 30 31      '@year@=2001
a040: 27 2c 0d 0a 20 20 20 20 27 40 73 72 69 64 40 3d  ',..    '@srid@=
a050: 33 30 30 34 27 2c 0d 0a 20 20 20 20 27 40 72 65  3004',..    '@re
a060: 67 69 6f 6e 40 3d 4c 61 7a 69 6f 27 2c 0d 0a 20  gion@=Lazio',.. 
a070: 20 20 20 27 40 73 68 70 5f 66 69 6c 65 40 3d 6c     '@shp_file@=l
a080: 61 7a 69 6f 5f 32 30 30 31 5f 33 30 30 34 27 20  azio_2001_3004' 
a090: 29 3b 0d 0a 2d 2d 20 2d 2d 20 2d 2d 2d 2d 2d 2d  );..-- -- ------
a0a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
a0b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 20 2d 2d 0d  ------------ --.
a0c0: 0a 2d 2d 20 53 45 4c 45 43 54 20 44 61 74 65 54  .-- SELECT DateT
a0d0: 69 6d 65 28 27 6e 6f 77 27 2c 27 6c 6f 63 61 6c  ime('now','local
a0e0: 74 69 6d 65 27 29 2c 22 63 61 6c 6c 69 6e 67 3a  time'),"calling:
a0f0: 20 27 65 78 70 6f 72 74 5f 73 68 61 70 65 27 20   'export_shape' 
a100: 66 6f 72 20 50 75 67 6c 69 61 22 3b 0d 0a 53 45  for Puglia";..SE
a110: 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f 63 5f  LECT StoredProc_
a120: 45 78 65 63 75 74 65 28 20 27 65 78 70 6f 72 74  Execute( 'export
a130: 5f 73 68 61 70 65 27 2c 0d 0a 20 20 20 20 27 40  _shape',..    '@
a140: 61 74 74 61 63 68 5f 73 63 68 65 6d 61 5f 6e 61  attach_schema_na
a150: 6d 65 40 3d 64 62 5f 73 6f 75 72 63 65 27 2c 0d  me@=db_source',.
a160: 0a 20 20 20 20 27 40 79 65 61 72 40 3d 31 39 39  .    '@year@=199
a170: 31 27 2c 0d 0a 20 20 20 20 27 40 73 72 69 64 40  1',..    '@srid@
a180: 3d 34 33 32 36 27 2c 0d 0a 20 20 20 20 27 40 72  =4326',..    '@r
a190: 65 67 69 6f 6e 40 3d 70 75 67 6c 69 61 27 2c 0d  egion@=puglia',.
a1a0: 0a 20 20 20 20 27 40 73 68 70 5f 66 69 6c 65 40  .    '@shp_file@
a1b0: 3d 70 75 67 6c 69 61 5f 31 39 39 31 5f 34 33 32  =puglia_1991_432
a1c0: 36 27 20 29 3b 0d 0a 2d 2d 20 2d 2d 20 2d 2d 2d  6' );..-- -- ---
a1d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
a1e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 20  --------------- 
a1f0: 2d 2d 0d 0a 2d 2d 20 53 45 4c 45 43 54 20 44 61  --..-- SELECT Da
a200: 74 65 54 69 6d 65 28 27 6e 6f 77 27 2c 27 6c 6f  teTime('now','lo
a210: 63 61 6c 74 69 6d 65 27 29 2c 22 63 61 6c 6c 69  caltime'),"calli
a220: 6e 67 3a 20 27 65 78 70 6f 72 74 5f 73 68 61 70  ng: 'export_shap
a230: 65 27 20 66 6f 72 20 41 72 65 7a 7a 6f 22 3b 0d  e' for Arezzo";.
a240: 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50 72  .SELECT StoredPr
a250: 6f 63 5f 45 78 65 63 75 74 65 28 20 27 65 78 70  oc_Execute( 'exp
a260: 6f 72 74 5f 73 68 61 70 65 27 2c 0d 0a 20 20 20  ort_shape',..   
a270: 20 27 40 61 74 74 61 63 68 5f 73 63 68 65 6d 61   '@attach_schema
a280: 5f 6e 61 6d 65 40 3d 64 62 5f 73 6f 75 72 63 65  _name@=db_source
a290: 27 2c 0d 0a 20 20 20 20 27 40 79 65 61 72 40 3d  ',..    '@year@=
a2a0: 32 30 31 31 27 2c 0d 0a 20 20 20 20 27 40 73 72  2011',..    '@sr
a2b0: 69 64 40 3d 33 30 30 33 27 2c 0d 0a 20 20 20 20  id@=3003',..    
a2c0: 27 40 70 72 6f 76 69 6e 63 65 40 3d 41 52 45 5a  '@province@=AREZ
a2d0: 5a 4f 27 2c 0d 0a 20 20 20 20 27 40 73 68 70 5f  ZO',..    '@shp_
a2e0: 66 69 6c 65 40 3d 70 72 6f 76 69 6e 63 65 5f 61  file@=province_a
a2f0: 72 65 7a 7a 6f 5f 32 30 31 31 5f 33 30 30 33 27  rezzo_2011_3003'
a300: 20 29 3b 0d 0a 2d 2d 20 2d 2d 20 2d 2d 2d 2d 2d   );..-- -- -----
a310: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
a320: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 20 2d 2d  ------------- --
a330: 0d 0a 2d 2d 20 53 45 4c 45 43 54 20 44 61 74 65  ..-- SELECT Date
a340: 54 69 6d 65 28 27 6e 6f 77 27 2c 27 6c 6f 63 61  Time('now','loca
a350: 6c 74 69 6d 65 27 29 2c 22 63 61 6c 6c 69 6e 67  ltime'),"calling
a360: 3a 20 27 65 78 70 6f 72 74 5f 73 68 61 70 65 27  : 'export_shape'
a370: 20 66 6f 72 20 41 72 65 7a 7a 6f 22 3b 0d 0a 53   for Arezzo";..S
a380: 45 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f 63  ELECT StoredProc
a390: 5f 45 78 65 63 75 74 65 28 20 27 65 78 70 6f 72  _Execute( 'expor
a3a0: 74 5f 73 68 61 70 65 27 2c 0d 0a 20 20 20 20 27  t_shape',..    '
a3b0: 40 61 74 74 61 63 68 5f 73 63 68 65 6d 61 5f 6e  @attach_schema_n
a3c0: 61 6d 65 40 3d 64 62 5f 73 6f 75 72 63 65 27 2c  ame@=db_source',
a3d0: 0d 0a 20 20 20 20 27 40 79 65 61 72 40 3d 32 30  ..    '@year@=20
a3e0: 30 31 27 2c 0d 0a 20 20 20 20 27 40 73 72 69 64  01',..    '@srid
a3f0: 40 3d 33 30 30 33 27 2c 0d 0a 20 20 20 20 27 40  @=3003',..    '@
a400: 6d 75 6e 69 63 69 70 61 6c 69 74 79 40 3d 41 72  municipality@=Ar
a410: 65 7a 7a 6f 27 2c 0d 0a 20 20 20 20 27 40 73 68  ezzo',..    '@sh
a420: 70 5f 66 69 6c 65 40 3d 6d 75 6e 69 63 69 70 61  p_file@=municipa
a430: 6c 69 74 79 5f 61 72 65 7a 7a 6f 5f 32 30 30 31  lity_arezzo_2001
a440: 5f 33 30 30 33 27 20 29 3b 0d 0a 2d 2d 20 2d 2d  _3003' );..-- --
a450: 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d   ---------------
a460: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
a470: 2d 2d 2d 20 2d 2d 0d 0a 2d 2d 20 44 45 54 41 43  --- --..-- DETAC
a480: 48 20 73 6f 75 72 63 65 20 44 61 74 61 62 61 73  H source Databas
a490: 65 0d 0a 2d 2d 20 54 68 65 20 75 73 65 64 20 73  e..-- The used s
a4a0: 63 68 65 6d 61 2d 6e 61 6d 65 20 6d 75 73 74 20  chema-name must 
a4b0: 62 65 20 75 73 65 64 20 68 65 72 65 0d 0a 2d 2d  be used here..--
a4c0: 20 2d 3e 20 27 64 62 5f 73 6f 75 72 63 65 27 0d   -> 'db_source'.
a4d0: 0a 2d 2d 20 2d 2d 20 2d 2d 2d 2d 2d 2d 2d 2d 2d  .-- -- ---------
a4e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
a4f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 20 2d 2d 0d 0a 2d 2d  --------- --..--
a500: 20 53 45 4c 45 43 54 20 44 61 74 65 54 69 6d 65   SELECT DateTime
a510: 28 27 6e 6f 77 27 2c 27 6c 6f 63 61 6c 74 69 6d  ('now','localtim
a520: 65 27 29 2c 27 63 61 6c 6c 69 6e 67 3a 20 44 45  e'),'calling: DE
a530: 54 41 43 48 20 44 41 54 41 42 41 53 45 27 3b 0d  TACH DATABASE';.
a540: 0a 44 45 54 41 43 48 20 44 41 54 41 42 41 53 45  .DETACH DATABASE
a550: 20 64 62 5f 73 6f 75 72 63 65 3b 0d 0a 2d 2d 20   db_source;..-- 
a560: 2d 2d 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  -- -------------
a570: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
a580: 2d 2d 2d 2d 2d 20 2d 2d 0d 0a 2d 2d 20 53 45 4c  ----- --..-- SEL
a590: 45 43 54 20 44 61 74 65 54 69 6d 65 28 27 6e 6f  ECT DateTime('no
a5a0: 77 27 2c 27 6c 6f 63 61 6c 74 69 6d 65 27 29 2c  w','localtime'),
a5b0: 22 63 61 6c 6c 69 6e 67 3a 20 53 71 6c 50 72 6f  "calling: SqlPro
a5c0: 63 5f 47 65 74 4c 61 73 74 45 72 72 6f 72 22 3b  c_GetLastError";
a5d0: 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63  ..SELECT SqlProc
a5e0: 5f 47 65 74 4c 61 73 74 45 72 72 6f 72 28 29 3b  _GetLastError();
a5f0: 0d 0a 2d 2d 20 2d 2d 20 2d 2d 2d 2d 2d 2d 2d 2d  ..-- -- --------
a600: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
a610: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 20 2d 2d 0d 0a 3c  ---------- --..<
a620: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 74 61 62  /verbatim>..<tab
a630: 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 66 38 66  le bgcolor="#f8f
a640: 38 64 38 22 20 63 65 6c 6c 70 61 64 64 69 6e 67  8d8" cellpadding
a650: 3d 22 36 22 20 63 65 6c 6c 73 70 61 63 69 6e 67  ="6" cellspacing
a660: 3d 22 38 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 3c  ="8"><tr><td>..<
a670: 75 3e 4e 6f 74 65 73 3c 2f 75 3e 3a 20 44 69 66  u>Notes</u>: Dif
a680: 66 65 72 65 6e 63 65 20 66 72 6f 6d 20 6d 61 69  ference from mai
a690: 6e 20 53 61 6d 70 6c 65 3a 0d 0a 3c 75 6c 3e 0d  n Sample:..<ul>.
a6a0: 0a 3c 6c 69 3e 54 68 65 20 63 61 6c 6c 65 64 20  .<li>The called 
a6b0: 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65  Stored Procedure
a6c0: 20 61 73 73 75 6d 65 73 20 74 68 61 74 20 74 68   assumes that th
a6d0: 65 20 73 6f 75 72 63 65 20 44 61 74 61 62 61 73  e source Databas
a6e0: 65 20 68 61 73 20 62 65 65 6e 20 41 54 54 41 43  e has been ATTAC
a6f0: 48 65 64 2c 20 75 73 69 6e 67 20 74 68 65 20 67  Hed, using the g
a700: 69 76 65 6e 20 3c 62 3e 61 74 74 61 63 68 5f 73  iven <b>attach_s
a710: 63 68 65 6d 61 5f 6e 61 6d 65 3c 2f 62 3e 2e 0d  chema_name</b>..
a720: 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 69 66 20 74 68  .<ul>..<li>if th
a730: 65 20 75 73 65 64 20 73 63 68 65 6d 61 2d 6e 61  e used schema-na
a740: 6d 65 20 3c 62 3e 69 73 20 6e 6f 74 3c 2f 62 3e  me <b>is not</b>
a750: 20 74 68 65 20 73 61 6d 65 20 61 73 20 74 68 65   the same as the
a760: 20 73 65 74 20 64 65 66 61 75 6c 74 20 76 61 6c   set default val
a770: 75 65 2c 20 69 74 20 3c 62 3e 6d 75 73 74 3c 2f  ue, it <b>must</
a780: 62 3e 20 62 65 20 67 69 76 65 6e 20 61 73 20 61  b> be given as a
a790: 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72   Stored Procedur
a7a0: 65 20 70 61 72 61 6d 65 74 65 72 2e 3c 2f 6c 69  e parameter.</li
a7b0: 3e 0d 0a 3c 2f 75 6c 3e 3c 2f 6c 69 3e 0d 0a 3c  >..</ul></li>..<
a7c0: 6c 69 3e 54 68 65 20 53 68 61 70 65 20 6f 75 74  li>The Shape out
a7d0: 70 75 74 20 66 69 6e 65 2d 6e 61 6d 65 0d 0a 3c  put fine-name..<
a7e0: 75 6c 3e 0d 0a 3c 6c 69 3e 6d 75 73 74 20 62 65  ul>..<li>must be
a7f0: 20 3c 62 3e 75 6e 69 71 75 65 3c 2f 62 3e 20 77   <b>unique</b> w
a800: 69 74 68 69 6e 20 74 68 65 20 53 68 61 70 65 20  ithin the Shape 
a810: 6f 75 74 70 75 74 20 64 69 72 65 63 74 6f 72 79  output directory
a820: 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 2f 6c  .</li>..</ul></l
a830: 69 3e 0d 0a 3c 6c 69 3e 54 68 65 20 53 68 61 70  i>..<li>The Shap
a840: 65 20 6f 75 74 70 75 74 20 64 69 72 65 63 74 6f  e output directo
a850: 72 79 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 6d 61  ry..<ul>..<li>ma
a860: 79 20 62 65 2c 20 62 75 74 20 6d 75 73 74 20 6e  y be, but must n
a870: 6f 74 20 62 65 20 74 68 65 20 73 61 6d 65 20 66  ot be the same f
a880: 6f 72 20 61 6c 6c 20 65 78 70 6f 72 74 65 64 20  or all exported 
a890: 53 68 61 70 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 2f  Shapes.</li>..</
a8a0: 75 6c 3e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d  ul></li>..</ul>.
a8b0: 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62  .</td></tr></tab
a8c0: 6c 65 3e 0d 0a 3c 62 72 3e 3c 68 72 3e 0d 0a 3c  le>..<br><hr>..<
a8d0: 74 61 62 6c 65 20 77 69 64 74 68 3d 22 31 30 30  table width="100
a8e0: 25 22 3e 3c 74 72 3e 0d 0a 3c 74 64 20 77 69 64  %"><tr>..<td wid
a8f0: 74 68 3d 22 33 33 25 22 20 61 6c 69 67 6e 3d 22  th="33%" align="
a900: 6c 65 66 74 22 3e 3c 2f 74 64 3e 0d 0a 3c 74 64  left"></td>..<td
a910: 20 61 6c 69 67 6e 3d 22 63 65 6e 74 65 72 22 3e   align="center">
a920: 3c 61 20 68 72 65 66 3d 22 68 74 74 70 73 3a 2f  <a href="https:/
a930: 2f 77 77 77 2e 67 61 69 61 2d 67 69 73 2e 69 74  /www.gaia-gis.it
a940: 2f 66 6f 73 73 69 6c 2f 6c 69 62 73 70 61 74 69  /fossil/libspati
a950: 61 6c 69 74 65 2f 77 69 6b 69 3f 6e 61 6d 65 3d  alite/wiki?name=
a960: 34 2e 33 2e 30 2b 64 6f 63 22 3e 62 61 63 6b 20  4.3.0+doc">back 
a970: 74 6f 20 69 6e 64 65 78 3c 2f 61 3e 3c 2f 74 64  to index</a></td
a980: 3e 0d 0a 3c 74 64 20 77 69 64 74 68 3d 22 33 33  >..<td width="33
a990: 25 22 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22  %" align="right"
a9a0: 3e 3c 2f 74 64 3e 0d 0a 3c 2f 74 72 3e 3c 2f 74  ></td>..</tr></t
a9b0: 61 62 6c 65 3e 0a 5a 20 37 61 35 32 62 64 30 66  able>.Z 7a52bd0f
a9c0: 34 36 36 65 65 39 65 66 64 34 34 39 62 62 32 33  466ee9efd449bb23
a9d0: 39 35 36 33 65 63 66 31 0a                       9563ecf1.