Hex Artifact Content
Not logged in

Artifact bcbac9655a254471a61ab762c6ce120c1aa59c84:

Wiki page [Stored Procedures] by sandro 2017-11-26 19:06:52.
0000: 44 20 32 30 31 37 2d 31 31 2d 32 36 54 31 39 3a  D 2017-11-26T19:
0010: 30 36 3a 35 32 2e 32 39 39 0a 4c 20 53 74 6f 72  06:52.299.L Stor
0020: 65 64 5c 73 50 72 6f 63 65 64 75 72 65 73 0a 50  ed\sProcedures.P
0030: 20 62 64 62 65 30 36 64 38 37 39 63 65 30 34 65   bdbe06d879ce04e
0040: 31 33 38 62 62 34 37 37 62 36 65 37 65 32 62 61  138bb477b6e7e2ba
0050: 30 30 35 39 65 32 34 65 39 0a 55 20 73 61 6e 64  0059e24e9.U sand
0060: 72 6f 0a 57 20 32 39 34 37 33 0a 3c 74 61 62 6c  ro.W 29473.<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 73 69  h1>..Starting si
0240: 6e 63 65 20 76 65 72 73 69 6f 6e 20 3c 62 3e 34  nce version <b>4
0250: 2e 35 2e 30 3c 2f 62 3e 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 61 6c 6c 6f 77 65 64 20 62 79  ility allowed by
0330: 20 6d 69 78 69 6e 67 20 73 74 61 6e 64 61 72 64   mixing standard
0340: 20 3c 62 3e 3c 69 3e 53 51 4c 20 73 63 72 69 70   <b><i>SQL scrip
0350: 74 73 3c 2f 69 3e 3c 2f 62 3e 20 61 6e 64 20 3c  ts</i></b> and <
0360: 62 3e 3c 69 3e 56 61 72 69 61 62 6c 65 73 3c 2f  b><i>Variables</
0370: 69 3e 3c 2f 62 3e 20 74 6f 20 62 65 20 72 65 70  i></b> to be rep
0380: 6c 61 63 65 64 20 6a 75 73 74 20 62 65 66 6f 72  laced just befor
0390: 65 20 61 63 74 75 61 6c 20 65 78 65 63 75 74 69  e actual executi
03a0: 6f 6e 2e 0d 0a 49 74 27 73 20 6e 6f 74 20 6f 6e  on...It's not on
03b0: 6c 79 3a 20 74 68 69 6e 6b 20 6f 66 20 74 68 65  ly: think of the
03c0: 20 6d 61 6e 79 20 77 6f 6e 64 65 72 66 75 6c 20   many wonderful 
03d0: 6f 70 70 6f 72 74 75 6e 69 74 69 65 73 20 64 65  opportunities de
03e0: 72 69 76 69 6e 67 20 66 72 6f 6d 20 70 65 72 6d  riving from perm
03f0: 61 6e 65 6e 74 6c 79 20 73 74 6f 72 69 6e 67 20  anently storing 
0400: 77 69 74 68 69 6e 20 61 20 64 61 74 61 62 61 73  within a databas
0410: 65 20 73 75 63 68 20 3c 62 3e 3c 69 3e 53 51 4c  e such <b><i>SQL
0420: 20 53 63 72 69 70 74 73 20 77 69 74 68 20 56 61   Scripts with Va
0430: 72 69 61 62 6c 65 73 3c 2f 69 3e 3c 2f 62 3e 20  riables</i></b> 
0440: 73 6f 20 74 6f 20 6d 61 6b 65 20 61 73 20 73 69  so to make as si
0450: 6d 70 6c 65 20 61 73 20 70 6f 73 73 69 62 6c 65  mple as possible
0460: 20 61 75 74 6f 6d 61 74 69 6e 67 20 63 6f 6d 6d   automating comm
0470: 6f 6e 20 77 6f 72 6b 66 6c 6f 77 73 20 74 6f 20  on workflows to 
0480: 62 65 20 72 65 70 65 61 74 65 64 6c 79 20 65 78  be repeatedly ex
0490: 65 63 75 74 65 64 2e 0d 0a 54 68 69 73 20 65 78  ecuted...This ex
04a0: 61 63 74 6c 79 20 69 73 20 74 68 65 20 69 6e 74  actly is the int
04b0: 65 6e 64 65 64 20 73 63 6f 70 65 20 6f 66 20 74  ended scope of t
04c0: 68 69 73 20 6e 65 77 20 6d 6f 64 75 6c 65 2e 3c  his new module.<
04d0: 62 72 3e 3c 62 72 3e 0d 0a 57 65 27 6c 6c 20 73  br><br>..We'll s
04e0: 74 61 72 74 20 66 69 72 73 74 20 62 79 20 66 6f  tart first by fo
04f0: 72 6d 61 6c 6c 79 20 64 65 66 69 6e 69 6e 67 20  rmally defining 
0500: 66 65 77 20 62 61 73 69 63 20 63 6f 6e 63 65 70  few basic concep
0510: 74 73 20 61 6e 64 20 6f 62 6a 65 63 74 73 20 73  ts and objects s
0520: 6f 20 74 6f 20 61 76 6f 69 64 20 61 6e 79 20 70  o to avoid any p
0530: 6f 73 73 69 62 6c 65 20 63 6f 6e 66 75 73 69 6f  ossible confusio
0540: 6e 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e  n.<br><br>..<hr>
0550: 0d 0a 3c 68 32 3e 42 61 73 69 63 20 44 65 66 69  ..<h2>Basic Defi
0560: 6e 69 74 69 6f 6e 73 20 61 6e 64 20 43 6f 6e 63  nitions and Conc
0570: 65 70 74 73 3c 2f 68 32 3e 0d 0a 3c 6f 6c 3e 0d  epts</h2>..<ol>.
0580: 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 53 51 4c 20 53  .<li>..<h4>SQL S
0590: 74 61 74 65 6d 65 6e 74 3c 2f 68 34 3e 0d 0a 54  tatement</h4>..T
05a0: 68 65 20 6d 69 6e 69 6d 61 6c 20 65 78 65 63 75  he minimal execu
05b0: 74 69 6f 6e 20 75 6e 69 74 20 61 6c 6c 6f 77 65  tion unit allowe
05c0: 64 20 62 79 20 53 51 4c 20 73 79 6e 74 61 78 3b  d by SQL syntax;
05d0: 20 61 20 73 74 61 6e 64 2d 61 6c 6f 6e 65 20 53   a stand-alone S
05e0: 51 4c 20 64 69 72 65 63 74 69 76 65 20 74 6f 20  QL directive to 
05f0: 62 65 20 61 74 6f 6d 69 63 61 6c 6c 79 20 65 78  be atomically ex
0600: 65 63 75 74 65 64 20 69 6e 20 61 20 73 69 6e 67  ecuted in a sing
0610: 6c 65 20 73 74 65 70 2e 20 45 78 61 6d 70 6c 65  le step. Example
0620: 73 3a 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  s:..<verbatim>..
0630: 53 45 4c 45 43 54 20 69 64 2c 20 6e 61 6d 65 2c  SELECT id, name,
0640: 20 6d 65 61 73 75 72 65 20 46 52 4f 4d 20 73 6f   measure FROM so
0650: 6d 65 5f 74 61 62 6c 65 3b 0d 0a 2d 2d 2d 2d 2d  me_table;..-----
0660: 2d 2d 2d 2d 2d 2d 2d 0d 0a 44 45 4c 45 54 45 20  -------..DELETE 
0670: 46 52 4f 4d 20 73 6f 6d 65 5f 74 61 62 6c 65 20  FROM some_table 
0680: 57 48 45 52 45 20 6d 65 61 73 75 72 65 20 3e 20  WHERE measure > 
0690: 31 30 30 30 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d  1000;..---------
06a0: 2d 2d 2d 0d 0a 55 50 44 41 54 45 20 73 6f 6d 65  ---..UPDATE some
06b0: 5f 74 61 62 6c 65 20 53 45 54 20 6d 65 61 73 75  _table SET measu
06c0: 72 65 20 3d 20 6d 65 61 73 75 72 65 20 2f 20 31  re = measure / 1
06d0: 30 2e 30 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e  0.0..</verbatim>
06e0: 0d 0a 3c 75 3e 4e 6f 74 65 3c 2f 75 3e 3a 20 53  ..<u>Note</u>: S
06f0: 51 4c 20 53 74 61 74 65 6d 65 6e 74 73 20 61 72  QL Statements ar
0700: 65 20 75 73 75 61 6c 6c 79 20 65 78 70 65 63 74  e usually expect
0710: 65 64 20 74 6f 20 62 65 20 65 78 70 6c 69 63 69  ed to be explici
0720: 74 6c 79 20 74 65 72 6d 69 6e 61 74 65 64 20 62  tly terminated b
0730: 79 20 61 20 3c 62 3e 3c 69 3e 73 65 6d 69 63 6f  y a <b><i>semico
0740: 6c 6f 6e 3c 2f 69 3e 3c 2f 62 3e 20 28 3c 62 3e  lon</i></b> (<b>
0750: 3c 69 3e 3b 3c 2f 69 3e 3c 2f 62 3e 29 2e 3c 62  <i>;</i></b>).<b
0760: 72 3e 0d 0a 54 68 65 20 73 65 6d 69 63 6f 6c 6f  r>..The semicolo
0770: 6e 20 74 65 72 6d 69 6e 61 74 6f 72 20 63 61 6e  n terminator can
0780: 20 62 65 20 73 61 66 65 6c 79 20 73 75 70 70 72   be safely suppr
0790: 65 73 73 65 64 20 6f 6e 6c 79 20 77 68 65 6e 20  essed only when 
07a0: 74 68 65 20 53 51 4c 20 53 74 61 74 65 6d 65 6e  the SQL Statemen
07b0: 74 20 69 73 20 69 6d 6d 65 64 69 61 74 65 6c 79  t is immediately
07c0: 20 66 6f 6c 6c 6f 77 65 64 20 62 79 20 61 20 73   followed by a s
07d0: 74 72 69 6e 67 20 74 65 72 6d 69 6e 61 74 6f 72  tring terminator
07e0: 20 28 6c 65 61 64 69 6e 67 20 61 6e 64 20 74 72   (leading and tr
07f0: 61 69 6c 69 6e 67 20 73 65 71 75 65 6e 63 65 73  ailing sequences
0800: 20 6f 66 20 61 6c 6c 20 3c 62 3e 3c 69 3e 62 6c   of all <b><i>bl
0810: 61 6e 6b 73 3c 2f 69 3e 3c 2f 62 3e 20 77 69 6c  anks</i></b> wil
0820: 6c 20 62 65 20 61 6c 77 61 79 73 20 69 67 6e 6f  l be always igno
0830: 72 65 64 29 2e 0d 0a 3c 62 72 3e 3c 62 72 3e 3c  red)...<br><br><
0840: 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e  hr>..</li>..<li>
0850: 0d 0a 3c 68 34 3e 53 51 4c 20 53 63 72 69 70 74  ..<h4>SQL Script
0860: 3c 2f 68 34 3e 0d 0a 41 20 6d 6f 72 65 20 6f 72  </h4>..A more or
0870: 20 6c 65 73 73 20 63 6f 6d 70 6c 65 78 20 73 65   less complex se
0880: 71 75 65 6e 63 65 20 6f 66 20 3c 62 3e 3c 69 3e  quence of <b><i>
0890: 53 51 4c 20 53 74 61 74 65 6d 65 6e 74 73 3c 2f  SQL Statements</
08a0: 69 3e 3c 2f 62 3e 2c 20 70 6f 73 73 69 62 6c 79  i></b>, possibly
08b0: 20 69 6e 63 6c 75 64 69 6e 67 20 69 6e 74 65 72   including inter
08c0: 6c 65 61 76 65 64 20 3c 62 3e 3c 69 3e 43 6f 6d  leaved <b><i>Com
08d0: 6d 65 6e 74 73 3c 2f 69 3e 3c 2f 62 3e 20 61 6e  ments</i></b> an
08e0: 64 2f 6f 72 20 3c 62 3e 3c 69 3e 44 6f 74 20 4d  d/or <b><i>Dot M
08f0: 61 63 72 6f 73 3c 2f 69 3e 3c 2f 62 3e 2e 3c 62  acros</i></b>.<b
0900: 72 3e 0d 0a 53 51 4c 20 53 63 72 69 70 74 73 20  r>..SQL Scripts 
0910: 61 72 65 20 69 6e 74 65 6e 64 65 64 20 74 6f 20  are intended to 
0920: 62 65 20 65 78 65 63 75 74 65 64 20 69 6e 20 61  be executed in a
0930: 20 73 69 6e 67 6c 65 20 6d 6f 6e 6f 6c 69 74 68   single monolith
0940: 69 63 20 70 61 73 73 20 28 61 74 6f 6d 69 63 61  ic pass (atomica
0950: 6c 6c 79 20 6f 72 20 6e 6f 74 2c 20 64 65 70 65  lly or not, depe
0960: 6e 64 69 6e 67 20 6f 6e 20 69 6e 74 65 72 6e 61  nding on interna
0970: 6c 20 3c 62 3e 3c 69 3e 54 72 61 6e 73 61 63 74  l <b><i>Transact
0980: 69 6f 6e 3c 2f 69 3e 3c 2f 62 3e 20 68 61 6e 64  ion</i></b> hand
0990: 6c 69 6e 67 29 2e 20 45 78 61 6d 70 6c 65 3a 0d  ling). Example:.
09a0: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 2e 65 63  .<verbatim>...ec
09b0: 68 6f 20 6f 6e 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20  ho on....--..-- 
09c0: 73 74 61 72 74 69 6e 67 20 61 20 54 72 61 6e 73  starting a Trans
09d0: 61 63 74 69 6f 6e 0d 0a 2d 2d 0d 0a 42 45 47 49  action..--..BEGI
09e0: 4e 3b 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20 63 72 65  N;....--..-- cre
09f0: 61 74 69 6e 67 20 61 20 74 61 62 6c 65 0d 0a 2d  ating a table..-
0a00: 2d 0d 0a 43 52 45 41 54 45 20 54 41 42 4c 45 20  -..CREATE TABLE 
0a10: 65 78 61 6d 70 6c 65 20 28 0d 0a 20 20 69 64 20  example (..  id 
0a20: 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20  INTEGER PRIMARY 
0a30: 4b 45 59 20 41 55 54 4f 49 4e 43 52 45 4d 45 4e  KEY AUTOINCREMEN
0a40: 54 2c 0d 0a 20 20 6e 61 6d 65 20 54 45 58 54 20  T,..  name TEXT 
0a50: 4e 4f 54 20 4e 55 4c 4c 2c 0d 0a 20 20 76 61 6c  NOT NULL,..  val
0a60: 75 65 20 44 4f 55 42 4c 45 29 3b 0d 0a 0d 0a 2d  ue DOUBLE);....-
0a70: 2d 0d 0a 2d 2d 20 70 6f 70 75 6c 61 74 69 6e 67  -..-- populating
0a80: 20 74 68 65 20 74 61 62 6c 65 0d 0a 2d 2d 0d 0a   the table..--..
0a90: 49 4e 53 45 52 54 20 49 4e 54 4f 20 65 78 61 6d  INSERT INTO exam
0aa0: 70 6c 65 20 28 69 64 2c 20 6e 61 6d 65 2c 20 76  ple (id, name, v
0ab0: 61 6c 75 65 29 20 56 41 4c 55 45 53 20 28 4e 55  alue) VALUES (NU
0ac0: 4c 4c 2c 20 27 66 69 72 73 74 27 2c 20 31 32 2e  LL, 'first', 12.
0ad0: 33 34 29 3b 0d 0a 49 4e 53 45 52 54 20 49 4e 54  34);..INSERT INT
0ae0: 4f 20 65 78 61 6d 70 6c 65 20 28 69 64 2c 20 6e  O example (id, n
0af0: 61 6d 65 2c 20 76 61 6c 75 65 29 20 56 41 4c 55  ame, value) VALU
0b00: 45 53 20 28 4e 55 4c 4c 2c 20 27 73 65 63 6f 6e  ES (NULL, 'secon
0b10: 64 27 2c 20 35 36 2e 37 38 29 3b 0d 0a 49 4e 53  d', 56.78);..INS
0b20: 45 52 54 20 49 4e 54 4f 20 65 78 61 6d 70 6c 65  ERT INTO example
0b30: 20 28 69 64 2c 20 6e 61 6d 65 2c 20 76 61 6c 75   (id, name, valu
0b40: 65 29 20 56 41 4c 55 45 53 20 28 4e 55 4c 4c 2c  e) VALUES (NULL,
0b50: 20 27 74 68 69 72 64 27 2c 20 4e 55 4c 4c 29 3b   'third', NULL);
0b60: 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20 63 6f 6d 6d 69  ....--..-- commi
0b70: 74 74 69 6e 67 20 74 68 65 20 70 65 6e 64 69 6e  tting the pendin
0b80: 67 20 54 72 61 6e 73 61 63 74 69 6f 6e 0d 0a 2d  g Transaction..-
0b90: 2d 0d 0a 43 4f 4d 4d 49 54 3b 0d 0a 0d 0a 2e 71  -..COMMIT;.....q
0ba0: 75 69 74 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e  uit..</verbatim>
0bb0: 0d 0a 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c  ..<hr>..</li>..<
0bc0: 6c 69 3e 0d 0a 3c 68 34 3e 53 51 4c 20 56 61 72  li>..<h4>SQL Var
0bd0: 69 61 62 6c 65 3c 2f 68 34 3e 0d 0a 41 20 3c 62  iable</h4>..A <b
0be0: 3e 3c 69 3e 53 51 4c 20 56 61 72 69 61 62 6c 65  ><i>SQL Variable
0bf0: 3c 2f 69 3e 3c 2f 62 3e 20 69 73 20 6a 75 73 74  </i></b> is just
0c00: 20 61 20 3c 69 3e 3c 75 3e 6d 6e 65 6d 6f 6e 69   a <i><u>mnemoni
0c10: 63 20 73 79 6d 62 6f 6c 3c 2f 75 3e 3c 2f 69 3e  c symbol</u></i>
0c20: 20 65 6e 63 6c 6f 73 65 64 20 62 65 74 77 65 65   enclosed betwee
0c30: 6e 20 74 77 6f 20 3c 69 3e 3c 75 3e 73 70 65 63  n two <i><u>spec
0c40: 69 61 6c 20 6d 61 72 6b 65 72 73 3c 2f 75 3e 3c  ial markers</u><
0c50: 2f 69 3e 20 28 3c 62 3e 3c 69 3e 40 3c 2f 69 3e  /i> (<b><i>@</i>
0c60: 3c 2f 62 3e 20 6f 72 20 3c 62 3e 3c 69 3e 24 3c  </b> or <b><i>$<
0c70: 2f 69 3e 3c 2f 62 3e 29 2e 20 45 78 61 6d 70 6c  /i></b>). Exampl
0c80: 65 73 3a 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d  es:..<verbatim>.
0c90: 0a 40 74 61 62 6c 65 5f 6e 61 6d 65 40 0d 0a 40  .@table_name@..@
0ca0: 63 6f 6c 5f 6e 61 6d 65 40 0d 0a 24 76 61 6c 75  col_name@..$valu
0cb0: 65 24 0d 0a 24 72 61 64 69 75 73 24 0d 0a 3c 2f  e$..$radius$..</
0cc0: 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 75 3e 4e 6f  verbatim>..<u>No
0cd0: 74 65 3c 2f 75 3e 3a 20 75 73 69 6e 67 20 74 68  te</u>: using th
0ce0: 65 20 3c 62 3e 3c 69 3e 40 3c 2f 69 3e 3c 2f 62  e <b><i>@</i></b
0cf0: 3e 20 6f 72 20 74 68 65 20 3c 62 3e 3c 69 3e 24  > or the <b><i>$
0d00: 3c 2f 69 3e 3c 2f 62 3e 20 6d 61 72 6b 65 72 73  </i></b> markers
0d10: 20 69 73 20 6a 75 73 74 20 61 6e 20 3c 69 3e 3c   is just an <i><
0d20: 75 3e 61 65 73 74 68 65 74 69 63 20 63 68 6f 69  u>aesthetic choi
0d30: 63 65 3c 2f 75 3e 3c 2f 69 3e 3b 20 62 6f 74 68  ce</u></i>; both
0d40: 20 68 61 76 65 20 69 64 65 6e 74 69 63 61 6c 20   have identical 
0d50: 6d 65 61 6e 69 6e 67 20 61 6e 64 20 70 72 61 63  meaning and prac
0d60: 74 69 63 61 6c 20 65 66 66 65 63 74 2e 0d 0a 3c  tical effect...<
0d70: 62 72 3e 3c 62 72 3e 3c 68 72 3e 0d 0a 3c 2f 6c  br><br><hr>..</l
0d80: 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 53 51  i>..<li>..<h4>SQ
0d90: 4c 20 42 6f 64 79 3c 2f 68 34 3e 0d 0a 41 20 3c  L Body</h4>..A <
0da0: 62 3e 3c 69 3e 53 51 4c 20 53 63 72 69 70 74 3c  b><i>SQL Script<
0db0: 2f 69 3e 3c 2f 62 3e 20 69 6e 74 65 72 6e 61 6c  /i></b> internal
0dc0: 6c 79 20 75 73 69 6e 67 20 3c 62 3e 3c 69 3e 56  ly using <b><i>V
0dd0: 61 72 69 61 62 6c 65 73 3c 2f 69 3e 3c 2f 62 3e  ariables</i></b>
0de0: 2e 20 45 78 61 6d 70 6c 65 3a 0d 0a 3c 76 65 72  . Example:..<ver
0df0: 62 61 74 69 6d 3e 0d 0a 2e 65 63 68 6f 20 6f 6e  batim>...echo on
0e00: 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20 73 74 61 72 74  ....--..-- start
0e10: 69 6e 67 20 61 20 54 72 61 6e 73 61 63 74 69 6f  ing a Transactio
0e20: 6e 0d 0a 2d 2d 0d 0a 42 45 47 49 4e 3b 0d 0a 0d  n..--..BEGIN;...
0e30: 0a 2d 2d 0d 0a 2d 2d 20 63 72 65 61 74 69 6e 67  .--..-- creating
0e40: 20 61 20 74 61 62 6c 65 0d 0a 2d 2d 0d 0a 43 52   a table..--..CR
0e50: 45 41 54 45 20 54 41 42 4c 45 20 40 74 61 62 6c  EATE TABLE @tabl
0e60: 65 40 20 28 0d 0a 20 20 40 70 6b 40 20 49 4e 54  e@ (..  @pk@ INT
0e70: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59  EGER PRIMARY KEY
0e80: 20 41 55 54 4f 49 4e 43 52 45 4d 45 4e 54 2c 0d   AUTOINCREMENT,.
0e90: 0a 20 20 40 63 6f 6c 31 40 20 54 45 58 54 20 4e  .  @col1@ TEXT N
0ea0: 4f 54 20 4e 55 4c 4c 2c 0d 0a 20 20 40 63 6f 6c  OT NULL,..  @col
0eb0: 32 40 20 44 4f 55 42 4c 45 29 3b 0d 0a 0d 0a 2d  2@ DOUBLE);....-
0ec0: 2d 0d 0a 2d 2d 20 70 6f 70 75 6c 61 74 69 6e 67  -..-- populating
0ed0: 20 74 68 65 20 74 61 62 6c 65 0d 0a 2d 2d 0d 0a   the table..--..
0ee0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 40 74 61 62  INSERT INTO @tab
0ef0: 6c 65 40 20 28 40 70 6b 40 2c 20 40 63 6f 6c 31  le@ (@pk@, @col1
0f00: 40 2c 20 40 63 6f 6c 32 40 29 20 56 41 4c 55 45  @, @col2@) VALUE
0f10: 53 20 28 4e 55 4c 4c 2c 20 27 66 69 72 73 74 27  S (NULL, 'first'
0f20: 2c 20 31 32 2e 33 34 29 3b 0d 0a 49 4e 53 45 52  , 12.34);..INSER
0f30: 54 20 49 4e 54 4f 20 40 74 61 62 6c 65 40 20 28  T INTO @table@ (
0f40: 40 70 6b 40 2c 20 40 63 6f 6c 31 40 2c 20 40 63  @pk@, @col1@, @c
0f50: 6f 6c 32 40 29 20 56 41 4c 55 45 53 20 28 4e 55  ol2@) VALUES (NU
0f60: 4c 4c 2c 20 27 73 65 63 6f 6e 64 27 2c 20 35 36  LL, 'second', 56
0f70: 2e 37 38 29 3b 0d 0a 49 4e 53 45 52 54 20 49 4e  .78);..INSERT IN
0f80: 54 4f 20 40 74 61 62 6c 65 40 20 28 40 70 6b 40  TO @table@ (@pk@
0f90: 2c 20 40 63 6f 6c 32 40 2c 20 40 63 6f 6c 32 40  , @col2@, @col2@
0fa0: 29 20 56 41 4c 55 45 53 20 28 4e 55 4c 4c 2c 20  ) VALUES (NULL, 
0fb0: 27 74 68 69 72 64 27 2c 20 4e 55 4c 4c 29 3b 0d  'third', NULL);.
0fc0: 0a 0d 0a 2d 2d 0d 0a 2d 2d 20 63 6f 6d 6d 69 74  ...--..-- commit
0fd0: 74 69 6e 67 20 74 68 65 20 70 65 6e 64 69 6e 67  ting the pending
0fe0: 20 54 72 61 6e 73 61 63 74 69 6f 6e 0d 0a 2d 2d   Transaction..--
0ff0: 0d 0a 43 4f 4d 4d 49 54 3b 0d 0a 0d 0a 2e 71 75  ..COMMIT;.....qu
1000: 69 74 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d  it..</verbatim>.
1010: 0a 3c 75 3e 4e 6f 74 65 3c 2f 75 3e 3a 20 74 68  .<u>Note</u>: th
1020: 69 73 20 73 65 63 6f 6e 64 20 76 65 72 73 69 6f  is second versio
1030: 6e 20 69 73 20 6f 62 76 69 6f 75 73 6c 79 20 6d  n is obviously m
1040: 6f 72 65 20 66 6c 65 78 69 62 6c 65 20 74 68 61  ore flexible tha
1050: 6e 20 74 68 65 20 69 6e 69 74 69 61 6c 20 53 51  n the initial SQ
1060: 4c 20 73 63 72 69 70 74 2c 20 6a 75 73 74 20 62  L script, just b
1070: 65 63 61 75 73 65 20 74 68 65 72 65 20 61 72 65  ecause there are
1080: 6e 27 74 20 3c 75 3e 3c 69 3e 68 61 72 64 77 69  n't <u><i>hardwi
1090: 72 65 64 3c 2f 69 3e 3c 2f 75 3e 20 74 61 62 6c  red</i></u> tabl
10a0: 65 2d 6e 61 6d 65 73 20 61 6e 64 20 63 6f 6c 75  e-names and colu
10b0: 6d 6e 2d 6e 61 6d 65 73 2c 20 61 6c 6c 20 74 68  mn-names, all th
10c0: 65 6d 20 61 72 65 20 6e 6f 77 20 62 65 63 6f 6d  em are now becom
10d0: 65 20 70 75 72 65 6c 79 20 3c 75 3e 3c 69 3e 73  e purely <u><i>s
10e0: 79 6d 62 6f 6c 69 63 3c 2f 69 3e 3c 2f 75 3e 2e  ymbolic</i></u>.
10f0: 3c 62 72 3e 0d 0a 53 6f 20 77 65 20 61 72 65 20  <br>..So we are 
1100: 6e 6f 77 20 66 72 65 65 20 74 6f 20 72 65 75 73  now free to reus
1110: 65 20 6d 6f 72 65 20 74 69 6d 65 73 20 74 68 69  e more times thi
1120: 73 20 53 51 4c 20 42 6f 64 79 20 69 6e 20 64 69  s SQL Body in di
1130: 66 66 65 72 65 6e 74 20 63 6f 6e 74 65 78 74 73  fferent contexts
1140: 3b 20 77 65 20 6a 75 73 74 20 68 61 76 65 20 74  ; we just have t
1150: 6f 20 61 70 70 72 6f 70 72 69 61 74 65 6c 79 20  o appropriately 
1160: 73 65 74 20 74 68 65 20 56 61 72 69 61 62 6c 65  set the Variable
1170: 20 56 61 6c 75 65 73 20 6a 75 73 74 20 69 6d 6d   Values just imm
1180: 65 64 69 61 74 65 6c 79 20 62 65 66 6f 72 65 20  ediately before 
1190: 61 63 74 75 61 6c 20 65 78 65 63 75 74 69 6f 6e  actual execution
11a0: 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 62 3e 3c 69  .<br><br>..<b><i
11b0: 3e 53 51 4c 20 42 6f 64 69 65 73 3c 2f 69 3e 3c  >SQL Bodies</i><
11c0: 2f 62 3e 20 65 78 69 73 74 20 69 6e 20 74 77 6f  /b> exist in two
11d0: 20 64 69 66 66 65 72 65 6e 74 20 66 6f 72 6d 73   different forms
11e0: 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 3c 62 3e  :..<ul>..<li><b>
11f0: 72 61 77 3c 2f 62 3e 3a 20 73 74 69 6c 6c 20 69  raw</b>: still i
1200: 6e 63 6c 75 64 69 6e 67 20 73 79 6d 62 6f 6c 69  ncluding symboli
1210: 63 20 56 61 72 69 61 62 6c 65 73 2e 3c 2f 6c 69  c Variables.</li
1220: 3e 0d 0a 3c 6c 69 3e 3c 62 3e 63 6f 6f 6b 65 64  >..<li><b>cooked
1230: 3c 2f 62 3e 3a 20 70 72 65 73 65 6e 74 69 6e 67  </b>: presenting
1240: 20 61 6c 6c 20 73 79 6d 62 6f 6c 73 20 70 72 6f   all symbols pro
1250: 70 65 72 6c 79 20 72 65 70 6c 61 63 65 64 20 62  perly replaced b
1260: 79 20 74 68 65 69 72 20 61 63 74 75 61 6c 20 76  y their actual v
1270: 61 6c 75 65 73 2e 3c 62 72 3e 0d 0a 52 61 74 68  alues.<br>..Rath
1280: 65 72 20 6f 62 76 69 6f 75 73 6c 79 2c 20 79 6f  er obviously, yo
1290: 75 20 63 61 6e 20 73 75 63 63 65 73 73 66 75 6c  u can successful
12a0: 6c 79 20 65 78 65 63 75 74 65 20 6f 6e 6c 79 20  ly execute only 
12b0: 74 68 65 20 3c 62 3e 3c 69 3e 63 6f 6f 6b 65 64  the <b><i>cooked
12c0: 3c 2f 69 3e 3c 2f 62 3e 20 66 6f 72 6d 2e 3c 2f  </i></b> form.</
12d0: 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 62 72 3e  li>..</ul>..<br>
12e0: 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69  <hr>..</li>..<li
12f0: 3e 0d 0a 3c 68 34 3e 53 51 4c 20 50 72 6f 63 65  >..<h4>SQL Proce
1300: 64 75 72 65 20 42 4c 4f 42 20 6f 62 6a 65 63 74  dure BLOB object
1310: 3c 2f 68 34 3e 0d 0a 54 68 69 73 20 73 69 6d 70  </h4>..This simp
1320: 6c 79 20 69 73 20 61 20 3c 62 3e 3c 69 3e 42 4c  ly is a <b><i>BL
1330: 4f 42 20 65 6e 63 6f 64 65 64 3c 2f 69 3e 3c 2f  OB encoded</i></
1340: 62 3e 20 70 72 65 2d 63 6f 6d 70 69 6c 65 64 20  b> pre-compiled 
1350: 3c 62 3e 3c 69 3e 53 51 4c 20 42 6f 64 79 3c 2f  <b><i>SQL Body</
1360: 69 3e 3c 2f 62 3e 2c 20 61 6e 64 20 69 73 20 74  i></b>, and is t
1370: 68 65 20 75 73 75 61 6c 20 6f 62 6a 65 63 74 20  he usual object 
1380: 65 78 70 65 63 74 65 64 20 74 6f 20 62 65 20 65  expected to be e
1390: 78 63 68 61 6e 67 65 64 20 62 65 74 77 65 65 6e  xchanged between
13a0: 20 70 72 61 63 74 69 63 61 6c 6c 79 20 61 6c 6c   practically all
13b0: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 73 20 73   SQL functions s
13c0: 75 70 70 6f 72 74 69 6e 67 20 53 74 6f 72 65 64  upporting Stored
13d0: 20 50 72 6f 63 65 64 75 72 65 73 20 61 6e 64 20   Procedures and 
13e0: 61 6c 69 6b 65 2e 0d 0a 3c 62 72 3e 3c 62 72 3e  alike...<br><br>
13f0: 3c 68 72 3e 20 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c  <hr> ..</li>..<l
1400: 69 3e 0d 0a 3c 68 34 3e 53 74 6f 72 65 64 20 50  i>..<h4>Stored P
1410: 72 6f 63 65 64 75 72 65 3c 2f 68 34 3e 0d 0a 41  rocedure</h4>..A
1420: 20 3c 62 3e 3c 69 3e 53 51 4c 20 50 72 6f 63 65   <b><i>SQL Proce
1430: 64 75 72 65 20 42 4c 4f 42 20 6f 62 6a 65 63 74  dure BLOB object
1440: 3c 2f 69 3e 3c 2f 62 3e 20 70 65 72 6d 61 6e 65  </i></b> permane
1450: 6e 74 6c 79 20 73 74 6f 72 65 64 20 69 6e 74 6f  ntly stored into
1460: 20 61 20 64 61 74 61 62 61 73 65 2e 20 54 68 69   a database. Thi
1470: 73 20 77 69 6c 6c 20 6d 61 6b 65 20 65 61 73 69  s will make easi
1480: 65 72 20 72 65 75 73 69 6e 67 20 6d 6f 72 65 20  er reusing more 
1490: 74 69 6d 65 73 20 74 68 65 20 73 61 6d 65 20 53  times the same S
14a0: 51 4c 20 77 6f 72 6b 66 6c 6f 77 2c 20 70 65 72  QL workflow, per
14b0: 68 61 70 73 20 73 6f 20 74 6f 20 69 6d 70 6c 65  haps so to imple
14c0: 6d 65 6e 74 20 72 6f 75 74 69 6e 65 6c 79 20 70  ment routinely p
14d0: 65 72 69 6f 64 69 63 20 74 61 73 6b 73 20 28 74  eriodic tasks (t
14e0: 6f 20 62 65 20 65 78 65 63 75 74 65 64 20 64 61  o be executed da
14f0: 69 6c 79 20 2f 20 77 65 65 6b 6c 79 20 2f 20 6d  ily / weekly / m
1500: 6f 6e 74 68 6c 79 20 61 6e 64 20 73 6f 20 6f 6e  onthly and so on
1510: 29 2e 3c 62 72 3e 0d 0a 53 74 6f 72 65 64 20 50  ).<br>..Stored P
1520: 72 6f 63 65 64 75 72 65 73 20 61 6c 77 61 79 73  rocedures always
1530: 20 68 61 76 65 20 74 68 65 20 66 6f 6c 6c 6f 77   have the follow
1540: 69 6e 67 20 65 6c 65 6d 65 6e 74 73 3a 0d 0a 3c  ing elements:..<
1550: 75 6c 3e 0d 0a 3c 6c 69 3e 61 20 3c 62 3e 6e 61  ul>..<li>a <b>na
1560: 6d 65 3c 2f 62 3e 2c 20 69 6e 74 65 6e 64 65 64  me</b>, intended
1570: 20 74 6f 20 62 65 20 61 6e 20 75 6e 69 71 75 65   to be an unique
1580: 20 69 64 65 6e 74 69 66 69 65 72 20 28 3c 62 3e   identifier (<b>
1590: 3c 69 3e 50 72 69 6d 61 72 79 20 4b 65 79 3c 2f  <i>Primary Key</
15a0: 69 3e 3c 2f 62 3e 29 2e 3c 2f 6c 69 3e 0d 0a 3c  i></b>).</li>..<
15b0: 6c 69 3e 61 20 3c 62 3e 74 69 74 6c 65 3c 2f 62  li>a <b>title</b
15c0: 3e 2c 20 69 2e 65 2e 20 61 20 73 68 6f 72 74 20  >, i.e. a short 
15d0: 64 65 73 63 72 69 70 74 69 6f 6e 20 6f 66 20 74  description of t
15e0: 68 65 20 69 6e 74 65 6e 64 65 64 20 73 63 6f 70  he intended scop
15f0: 65 20 6f 66 20 74 68 65 20 53 74 6f 72 65 64 20  e of the Stored 
1600: 50 72 6f 63 65 64 75 72 65 2e 3c 2f 6c 69 3e 0d  Procedure.</li>.
1610: 0a 3c 6c 69 3e 61 20 3c 62 3e 53 51 4c 20 50 72  .<li>a <b>SQL Pr
1620: 6f 63 65 64 75 72 65 20 42 4c 4f 42 20 4f 62 6a  ocedure BLOB Obj
1630: 65 63 74 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c  ect</b>.</li>..<
1640: 2f 75 6c 3e 0d 0a 3c 62 72 3e 3c 68 72 3e 0d 0a  /ul>..<br><hr>..
1650: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34  </li>..<li>..<h4
1660: 3e 56 61 72 69 61 62 6c 65 20 77 69 74 68 20 56  >Variable with V
1670: 61 6c 75 65 20 73 74 72 69 6e 67 73 3c 2f 68 34  alue strings</h4
1680: 3e 0d 0a 42 65 66 6f 72 65 20 65 78 65 63 75 74  >..Before execut
1690: 69 6e 67 20 61 20 3c 62 3e 3c 69 3e 53 51 4c 20  ing a <b><i>SQL 
16a0: 42 6f 64 79 3c 2f 69 3e 3c 2f 62 3e 20 69 6e 63  Body</i></b> inc
16b0: 6c 75 64 69 6e 67 20 3c 62 3e 3c 69 3e 56 61 72  luding <b><i>Var
16c0: 69 61 62 6c 65 73 3c 2f 69 3e 3c 2f 62 3e 20 79  iables</i></b> y
16d0: 6f 75 20 61 72 65 20 6f 62 76 69 6f 75 73 6c 79  ou are obviously
16e0: 20 65 78 70 65 63 74 65 64 20 74 6f 20 73 65 74   expected to set
16f0: 20 73 6f 6d 65 20 61 70 70 72 6f 70 72 69 61 74   some appropriat
1700: 65 20 3c 62 3e 3c 69 3e 56 61 6c 75 65 3c 2f 69  e <b><i>Value</i
1710: 3e 3c 2f 62 3e 20 66 6f 72 20 65 61 63 68 20 56  ></b> for each V
1720: 61 72 69 61 62 6c 65 2c 20 73 6f 20 74 6f 20 61  ariable, so to a
1730: 6c 6c 6f 77 20 66 6f 72 20 72 65 70 6c 61 63 69  llow for replaci
1740: 6e 67 20 3c 75 3e 3c 69 3e 53 79 6d 62 6f 6c 73  ng <u><i>Symbols
1750: 3c 2f 69 3e 3c 2f 75 3e 20 77 69 74 68 20 61 63  </i></u> with ac
1760: 74 75 61 6c 20 3c 75 3e 3c 69 3e 56 61 6c 75 65  tual <u><i>Value
1770: 73 3c 2f 69 3e 3c 2f 75 3e 20 28 69 2e 65 2e 20  s</i></u> (i.e. 
1780: 66 6f 72 20 70 72 6f 70 65 72 6c 79 20 74 72 61  for properly tra
1790: 6e 73 66 6f 72 6d 69 6e 67 20 3c 62 3e 72 61 77  nsforming <b>raw
17a0: 3c 2f 62 3e 20 53 51 4c 20 69 6e 74 6f 20 3c 62  </b> SQL into <b
17b0: 3e 63 6f 6f 6b 65 64 3c 2f 62 3e 20 53 51 4c 29  >cooked</b> SQL)
17c0: 2e 3c 62 72 3e 0d 0a 41 20 3c 62 3e 3c 69 3e 56  .<br>..A <b><i>V
17d0: 61 72 69 61 62 6c 65 20 77 69 74 68 20 56 61 6c  ariable with Val
17e0: 75 65 3c 2f 69 3e 3c 2f 62 3e 20 73 74 72 69 6e  ue</i></b> strin
17f0: 67 20 73 69 6d 70 6c 79 20 69 73 20 61 6e 20 61  g simply is an a
1800: 70 70 72 6f 70 72 69 61 74 65 6c 79 20 77 65 6c  ppropriately wel
1810: 6c 2d 66 6f 72 6d 61 74 74 65 64 20 54 65 78 74  l-formatted Text
1820: 20 73 74 72 69 6e 67 20 64 65 63 6c 61 72 69 6e   string declarin
1830: 67 20 62 6f 74 68 20 74 68 65 20 53 79 6d 62 6f  g both the Symbo
1840: 6c 20 61 6e 64 20 74 68 65 20 63 6f 72 72 65 73  l and the corres
1850: 70 6f 6e 64 69 6e 67 20 72 65 70 6c 61 63 65 6d  ponding replacem
1860: 65 6e 74 20 56 61 6c 75 65 20 28 65 78 70 72 65  ent Value (expre
1870: 73 73 65 64 20 69 6e 20 69 74 73 20 74 65 78 74  ssed in its text
1880: 75 61 6c 20 72 65 70 72 65 73 65 6e 74 61 74 69  ual representati
1890: 6f 6e 29 2e 20 45 78 61 6d 70 6c 65 73 3a 0d 0a  on). Examples:..
18a0: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 40 76 61 6c  <verbatim>..@val
18b0: 75 65 5f 31 40 3d 31 32 33 34 20 20 20 20 20 20  ue_1@=1234      
18c0: 20 20 20 20 20 20 2d 2d 20 69 6e 74 65 67 65 72        -- integer
18d0: 20 76 61 6c 75 65 0d 0a 40 76 61 6c 75 65 5f 32   value..@value_2
18e0: 40 3d 31 32 2e 33 34 20 20 20 20 20 20 20 20 20  @=12.34         
18f0: 20 20 2d 2d 20 64 6f 75 62 6c 65 20 76 61 6c 75    -- double valu
1900: 65 0d 0a 40 76 61 6c 75 65 5f 33 40 3d 4e 65 77  e..@value_3@=New
1910: 20 59 6f 72 6b 20 43 69 74 79 20 20 20 2d 2d 20   York City   -- 
1920: 74 65 78 74 20 76 61 6c 75 65 0d 0a 40 76 61 6c  text value..@val
1930: 75 65 5f 34 40 3d 78 27 30 31 32 33 61 62 63 64  ue_4@=x'0123abcd
1940: 27 20 20 20 20 20 2d 2d 20 62 6c 6f 62 20 76 61  '     -- blob va
1950: 6c 75 65 0d 0a 40 76 61 6c 75 65 5f 35 40 3d 4e  lue..@value_5@=N
1960: 55 4c 4c 20 20 20 20 20 20 20 20 20 20 20 20 2d  ULL            -
1970: 2d 20 6e 75 6c 6c 20 76 61 6c 75 65 0d 0a 3c 2f  - null value..</
1980: 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c  verbatim>..<tabl
1990: 65 20 62 67 63 6f 6c 6f 72 3d 22 23 66 38 66 38  e bgcolor="#f8f8
19a0: 64 38 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d  d8" cellpadding=
19b0: 22 36 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d  "6" cellspacing=
19c0: 22 38 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 3c 75  "8"><tr><td>..<u
19d0: 3e 4e 6f 74 65 3c 2f 75 3e 3a 20 72 65 70 6c 61  >Note</u>: repla
19e0: 63 69 6e 67 20 56 61 72 69 61 62 6c 65 73 20 77  cing Variables w
19f0: 69 74 68 20 61 63 74 75 61 6c 20 56 61 6c 75 65  ith actual Value
1a00: 73 20 69 73 20 61 20 62 6c 69 6e 64 20 70 72 6f  s is a blind pro
1a10: 63 65 73 73 20 63 6f 6d 70 6c 65 74 65 6c 79 20  cess completely 
1a20: 69 6e 73 65 6e 73 69 62 6c 65 20 74 6f 20 74 68  insensible to th
1a30: 65 20 73 70 65 63 69 66 69 63 20 73 79 6e 74 61  e specific synta
1a40: 63 74 69 63 20 63 6f 6e 74 65 78 74 2e 3c 62 72  ctic context.<br
1a50: 3e 0d 0a 59 6f 75 20 61 72 65 20 66 75 6c 6c 79  >..You are fully
1a60: 20 72 65 73 70 6f 6e 73 69 62 6c 65 20 66 6f 72   responsible for
1a70: 20 63 6f 72 72 65 63 74 6c 79 20 61 70 70 6c 79   correctly apply
1a80: 20 73 69 6e 67 6c 65 2d 20 6f 72 20 64 6f 75 62   single- or doub
1a90: 6c 65 2d 71 75 6f 74 69 6e 67 20 77 68 65 72 65  le-quoting where
1aa0: 76 65 72 20 72 65 71 75 69 72 65 64 20 62 79 20  ver required by 
1ab0: 53 51 4c 20 73 79 6e 74 61 78 2e 0d 0a 3c 2f 74  SQL syntax...</t
1ac0: 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d  d></tr></table>.
1ad0: 0a 3c 62 72 3e 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e  .<br><hr>..</li>
1ae0: 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 53 74 6f 72  ..<li>..<h4>Stor
1af0: 65 64 20 56 61 72 69 61 62 6c 65 3c 2f 68 34 3e  ed Variable</h4>
1b00: 0d 0a 41 20 3c 62 3e 3c 69 3e 56 61 72 69 61 62  ..A <b><i>Variab
1b10: 6c 65 20 77 69 74 68 20 56 61 6c 75 65 3c 2f 69  le with Value</i
1b20: 3e 3c 2f 62 3e 20 70 65 72 6d 61 6e 65 6e 74 6c  ></b> permanentl
1b30: 79 20 73 74 6f 72 65 64 20 69 6e 74 6f 20 61 20  y stored into a 
1b40: 64 61 74 61 62 61 73 65 2e 3c 62 72 3e 0d 0a 53  database.<br>..S
1b50: 74 6f 72 65 64 20 56 61 72 69 61 62 6c 65 73 20  tored Variables 
1b60: 61 6c 77 61 79 73 20 68 61 76 65 20 74 68 65 20  always have the 
1b70: 66 6f 6c 6c 6f 77 69 6e 67 20 65 6c 65 6d 65 6e  following elemen
1b80: 74 73 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61  ts:..<ul>..<li>a
1b90: 20 3c 62 3e 6e 61 6d 65 3c 2f 62 3e 2c 20 69 6e   <b>name</b>, in
1ba0: 74 65 6e 64 65 64 20 74 6f 20 62 65 20 61 6e 20  tended to be an 
1bb0: 75 6e 69 71 75 65 20 69 64 65 6e 74 69 66 69 65  unique identifie
1bc0: 72 20 28 3c 62 3e 3c 69 3e 50 72 69 6d 61 72 79  r (<b><i>Primary
1bd0: 20 4b 65 79 3c 2f 69 3e 3c 2f 62 3e 29 2e 3c 2f   Key</i></b>).</
1be0: 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 3c 62 3e 74 69  li>..<li>a <b>ti
1bf0: 74 6c 65 3c 2f 62 3e 2c 20 69 2e 65 2e 20 61 20  tle</b>, i.e. a 
1c00: 73 68 6f 72 74 20 64 65 73 63 72 69 70 74 69 6f  short descriptio
1c10: 6e 20 6f 66 20 74 68 65 20 69 6e 74 65 6e 64 65  n of the intende
1c20: 64 20 73 63 6f 70 65 20 6f 66 20 74 68 65 20 53  d scope of the S
1c30: 74 6f 72 65 64 20 56 61 72 69 61 62 6c 65 2e 3c  tored Variable.<
1c40: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 3c 62 3e 56  /li>..<li>a <b>V
1c50: 61 6c 75 65 20 73 74 72 69 6e 67 3c 2f 62 3e 2e  alue string</b>.
1c60: 3c 2f 6c 69 3e 3c 62 72 3e 0d 0a 3c 2f 75 6c 3e  </li><br>..</ul>
1c70: 3c 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22  <table bgcolor="
1c80: 23 66 38 66 38 64 38 22 20 63 65 6c 6c 70 61 64  #f8f8d8" cellpad
1c90: 64 69 6e 67 3d 22 36 22 20 63 65 6c 6c 73 70 61  ding="6" cellspa
1ca0: 63 69 6e 67 3d 22 38 22 3e 3c 74 72 3e 3c 74 64  cing="8"><tr><td
1cb0: 3e 0d 0a 3c 75 3e 4e 6f 74 65 3c 2f 75 3e 3a 20  >..<u>Note</u>: 
1cc0: 74 68 65 20 69 6e 74 65 6e 64 65 64 20 73 63 6f  the intended sco
1cd0: 70 65 20 6f 66 20 3c 62 3e 53 74 6f 72 65 64 20  pe of <b>Stored 
1ce0: 56 61 72 69 61 62 6c 65 73 3c 2f 62 3e 20 69 73  Variables</b> is
1cf0: 20 74 6f 20 64 65 66 69 6e 65 20 61 70 70 72 6f   to define appro
1d00: 70 72 69 61 74 65 20 64 65 66 61 75 6c 74 20 76  priate default v
1d10: 61 6c 75 65 73 2e 3c 62 72 3e 0d 0a 49 66 20 61  alues.<br>..If a
1d20: 20 67 69 76 65 6e 20 3c 62 3e 56 61 72 69 61 62   given <b>Variab
1d30: 6c 65 3c 2f 62 3e 20 69 73 20 64 65 66 69 6e 65  le</b> is define
1d40: 64 20 77 69 74 68 69 6e 20 61 20 53 51 4c 20 42  d within a SQL B
1d50: 6f 64 79 20 62 65 69 6e 67 20 65 78 65 63 75 74  ody being execut
1d60: 65 64 2c 20 61 6e 64 20 6e 6f 20 63 6f 72 72 65  ed, and no corre
1d70: 73 70 6f 6e 64 69 6e 67 20 3c 62 3e 56 61 72 69  sponding <b>Vari
1d80: 61 62 6c 65 20 77 69 74 68 20 56 61 6c 75 65 3c  able with Value<
1d90: 2f 62 3e 20 61 72 67 75 6d 65 6e 74 20 68 61 73  /b> argument has
1da0: 20 62 65 65 6e 20 73 70 65 63 69 66 69 65 64 2c   been specified,
1db0: 20 74 68 65 6e 20 61 6e 20 61 74 74 65 6d 70 74   then an attempt
1dc0: 20 77 69 6c 6c 20 62 65 20 61 6c 77 61 79 73 20   will be always 
1dd0: 6d 61 64 65 20 69 6e 20 6f 72 64 65 72 20 74 6f  made in order to
1de0: 20 67 65 74 20 74 68 65 20 63 6f 72 72 65 73 70   get the corresp
1df0: 6f 6e 64 69 6e 67 20 3c 62 3e 53 74 6f 72 65 64  onding <b>Stored
1e00: 20 56 61 72 69 61 62 6c 65 3c 2f 62 3e 20 28 69   Variable</b> (i
1e10: 66 20 69 74 20 65 78 69 73 74 73 29 2e 3c 62 72  f it exists).<br
1e20: 3e 0d 0a 41 6e 20 65 78 70 6c 69 63 69 74 6c 79  >..An explicitly
1e30: 20 64 65 66 69 6e 65 64 20 3c 62 3e 56 61 72 69   defined <b>Vari
1e40: 61 62 6c 65 20 77 69 74 68 20 56 61 6c 75 65 3c  able with Value<
1e50: 2f 62 3e 20 61 72 67 75 6d 65 6e 74 20 77 69 6c  /b> argument wil
1e60: 6c 20 61 6c 77 61 79 73 20 74 61 6b 65 20 70 72  l always take pr
1e70: 65 63 65 64 65 6e 63 65 20 6f 76 65 72 20 74 68  ecedence over th
1e80: 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20  e corresponding 
1e90: 3c 62 3e 53 74 6f 72 65 64 20 56 61 72 69 61 62  <b>Stored Variab
1ea0: 6c 65 3c 2f 62 3e 3b 20 69 6e 20 6f 74 68 65 72  le</b>; in other
1eb0: 20 77 6f 72 64 73 20 61 20 3c 62 3e 53 74 6f 72   words a <b>Stor
1ec0: 65 64 20 56 61 72 69 61 62 6c 65 3c 2f 62 3e 20  ed Variable</b> 
1ed0: 28 69 66 20 64 65 66 69 6e 65 64 29 20 77 69 6c  (if defined) wil
1ee0: 6c 20 6a 75 73 74 20 62 65 20 63 6f 6e 73 69 64  l just be consid
1ef0: 65 72 65 64 20 61 73 20 61 20 64 65 66 61 75 6c  ered as a defaul
1f00: 74 20 76 61 6c 75 65 2e 0d 0a 3c 2f 74 64 3e 3c  t value...</td><
1f10: 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 62  /tr></table>..<b
1f20: 72 3e 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c  r><hr>..</li>..<
1f30: 6c 69 3e 0d 0a 3c 68 34 3e 53 51 4c 20 4c 6f 67  li>..<h4>SQL Log
1f40: 66 69 6c 65 3c 2f 68 34 3e 0d 0a 53 51 4c 20 71  file</h4>..SQL q
1f50: 75 65 72 69 65 73 20 77 69 6c 6c 20 75 73 75 61  ueries will usua
1f60: 6c 6c 79 20 72 65 74 75 72 6e 20 73 6f 6d 65 20  lly return some 
1f70: 3c 62 3e 72 65 73 75 6c 74 73 65 74 3c 2f 62 3e  <b>resultset</b>
1f80: 20 70 6f 74 65 6e 74 69 61 6c 6c 79 20 63 6f 6e   potentially con
1f90: 74 61 69 6e 69 6e 67 20 75 73 65 66 75 6c 20 69  taining useful i
1fa0: 6e 66 6f 72 6d 61 74 69 6f 6e 73 2e 3c 62 72 3e  nformations.<br>
1fb0: 0d 0a 42 75 74 20 65 78 65 63 75 74 69 6e 67 20  ..But executing 
1fc0: 61 20 3c 62 3e 53 51 4c 20 50 72 6f 63 65 64 75  a <b>SQL Procedu
1fd0: 72 65 3c 2f 62 3e 20 6f 72 20 3c 62 3e 53 74 6f  re</b> or <b>Sto
1fe0: 72 65 64 20 50 72 6f 63 65 64 75 72 65 3c 2f 62  red Procedure</b
1ff0: 3e 20 77 69 6c 6c 20 62 65 20 73 65 65 6e 20 62  > will be seen b
2000: 79 20 53 51 4c 69 74 65 20 6a 75 73 74 20 61 73  y SQLite just as
2010: 20 61 20 73 69 6d 70 6c 65 20 53 51 4c 20 66 75   a simple SQL fu
2020: 6e 63 74 69 6f 6e 20 63 61 6c 6c 20 73 69 6d 70  nction call simp
2030: 6c 79 20 72 65 74 75 72 6e 69 6e 67 20 61 20 66  ly returning a f
2040: 69 6e 61 6c 20 73 75 63 63 65 73 73 20 6f 72 20  inal success or 
2050: 66 61 69 6c 75 72 65 20 72 65 74 63 6f 64 65 2e  failure retcode.
2060: 3c 62 72 3e 0d 0a 41 6e 64 20 63 6f 6e 73 65 71  <br>..And conseq
2070: 75 65 6e 74 6c 79 20 61 6e 79 20 69 6e 66 6f 72  uently any infor
2080: 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 61 6c 6c  mation about all
2090: 20 74 68 65 20 69 6e 74 65 72 6d 65 64 69 61 74   the intermediat
20a0: 65 20 72 65 73 75 6c 74 73 65 74 73 20 69 6e 74  e resultsets int
20b0: 65 72 6e 61 6c 6c 79 20 70 72 6f 64 75 63 65 64  ernally produced
20c0: 20 62 79 20 74 68 65 20 65 78 65 63 75 74 69 6f   by the executio
20d0: 6e 20 62 6c 6f 63 6b 20 77 69 6c 6c 20 62 65 20  n block will be 
20e0: 6c 6f 73 74 20 66 6f 72 65 76 65 72 2e 3c 62 72  lost forever.<br
20f0: 3e 3c 62 72 3e 0d 0a 59 6f 75 20 63 61 6e 20 65  ><br>..You can e
2100: 76 65 6e 74 75 61 6c 6c 79 20 63 6f 6e 66 69 67  ventually config
2110: 75 72 65 20 61 6e 20 65 78 74 65 72 6e 61 6c 20  ure an external 
2120: 3c 62 3e 53 51 4c 20 4c 6f 67 66 69 6c 65 3c 2f  <b>SQL Logfile</
2130: 62 3e 20 73 6f 20 74 6f 20 70 65 72 6d 61 6e 65  b> so to permane
2140: 6e 74 6c 79 20 73 74 6f 72 65 20 61 6c 6c 20 69  ntly store all i
2150: 6e 74 65 72 6d 65 64 69 61 74 65 20 72 65 73 75  ntermediate resu
2160: 6c 74 73 65 74 73 20 69 6e 74 6f 20 61 6e 20 6f  ltsets into an o
2170: 72 64 69 6e 61 72 79 20 74 65 78 74 20 66 69 6c  rdinary text fil
2180: 65 2e 20 54 68 65 20 53 51 4c 20 4c 6f 67 66 69  e. The SQL Logfi
2190: 6c 65 20 73 75 70 70 6f 72 74 73 20 74 77 6f 20  le supports two 
21a0: 64 69 66 66 65 72 65 6e 74 20 6d 6f 64 65 73 3a  different modes:
21b0: 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 3c 62 3e 54  ..<ul>..<li><b>T
21c0: 72 75 6e 63 61 74 65 3c 2f 62 3e 3a 20 74 68 65  runcate</b>: the
21d0: 20 4c 6f 67 66 69 6c 65 20 77 69 6c 6c 20 62 65   Logfile will be
21e0: 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 20 63   automatically c
21f0: 72 65 61 74 65 64 20 69 66 20 6e 6f 74 20 61 6c  reated if not al
2200: 72 65 61 64 79 20 65 78 69 73 74 69 6e 67 2c 20  ready existing, 
2210: 61 6e 64 20 69 74 20 77 69 6c 6c 20 62 65 20 61  and it will be a
2220: 6c 77 61 79 73 20 74 72 75 6e 63 61 74 65 64 20  lways truncated 
2230: 62 65 66 6f 72 65 20 73 74 61 72 74 69 6e 67 20  before starting 
2240: 61 6e 20 65 78 65 63 75 74 69 6f 6e 20 75 6e 69  an execution uni
2250: 74 3b 20 69 6e 20 6f 74 68 65 72 20 77 6f 72 64  t; in other word
2260: 73 20 69 74 20 77 69 6c 6c 20 61 6c 77 61 79 73  s it will always
2270: 20 70 72 65 73 65 72 76 65 20 6a 75 73 74 20 74   preserve just t
2280: 68 65 20 72 65 73 75 6c 74 73 65 74 73 20 70 72  he resultsets pr
2290: 6f 64 75 63 65 64 20 62 79 20 74 68 65 20 6d 6f  oduced by the mo
22a0: 73 74 20 72 65 63 65 6e 74 20 65 78 65 63 75 74  st recent execut
22b0: 69 6f 6e 20 75 6e 69 74 2e 3c 2f 6c 69 3e 0d 0a  ion unit.</li>..
22c0: 3c 6c 69 3e 3c 62 3e 41 70 70 65 6e 64 3c 2f 62  <li><b>Append</b
22d0: 3e 3a 20 74 68 65 20 4c 6f 67 66 69 6c 65 20 77  >: the Logfile w
22e0: 69 6c 6c 20 62 65 20 61 75 74 6f 6d 61 74 69 63  ill be automatic
22f0: 61 6c 6c 79 20 63 72 65 61 74 65 64 20 69 66 20  ally created if 
2300: 6e 6f 74 20 61 6c 72 65 61 64 79 20 65 78 69 73  not already exis
2310: 74 69 6e 67 2c 20 61 6e 64 20 69 74 20 77 69 6c  ting, and it wil
2320: 6c 20 62 65 20 6e 65 76 65 72 20 74 72 75 6e 63  l be never trunc
2330: 61 74 65 64 20 62 65 66 6f 72 65 20 73 74 61 72  ated before star
2340: 74 69 6e 67 20 61 6e 20 65 78 65 63 75 74 69 6f  ting an executio
2350: 6e 20 75 6e 69 74 3b 20 69 6e 20 6f 74 68 65 72  n unit; in other
2360: 20 77 6f 72 64 73 20 69 74 20 77 69 6c 6c 20 70   words it will p
2370: 72 6f 67 72 65 73 73 69 76 65 6c 79 20 67 72 6f  rogressively gro
2380: 77 20 73 6f 20 74 6f 20 73 74 6f 72 65 20 61 6c  w so to store al
2390: 6c 20 74 68 65 20 72 65 73 75 6c 74 73 65 74 73  l the resultsets
23a0: 20 70 72 6f 64 75 63 65 64 20 62 79 20 66 6f 6c   produced by fol
23b0: 6c 6f 77 69 6e 67 20 65 78 65 63 75 74 69 6f 6e  lowing execution
23c0: 20 75 6e 69 74 73 2e 3c 62 72 3e 0d 0a 3c 75 3e   units.<br>..<u>
23d0: 4e 6f 74 65 3c 2f 75 3e 3a 20 79 6f 75 27 6c 6c  Note</u>: you'll
23e0: 20 62 65 20 6f 62 76 69 6f 75 73 6c 79 20 72 65   be obviously re
23f0: 71 75 69 72 65 64 20 74 6f 20 66 6c 75 73 68 20  quired to flush 
2400: 74 68 65 20 4c 6f 67 66 69 6c 65 20 66 72 6f 6d  the Logfile from
2410: 20 74 69 6d 65 20 74 6f 20 74 69 6d 65 20 73 6f   time to time so
2420: 20 74 6f 20 73 61 66 65 6c 79 20 61 76 6f 69 64   to safely avoid
2430: 20 74 6f 20 63 6f 6e 73 75 6d 65 20 74 6f 6f 20   to consume too 
2440: 6d 75 63 68 20 73 74 6f 72 61 67 65 20 73 70 61  much storage spa
2450: 63 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d  ce.</li>..</ul>.
2460: 0a 3c 2f 6c 69 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c  .</li>..</li>..<
2470: 2f 6f 6c 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a  /ol><br>..<hr>..
2480: 3c 68 32 3e 46 61 6d 69 6c 69 61 72 69 7a 69 6e  <h2>Familiarizin
2490: 67 20 77 69 74 68 20 53 51 4c 20 46 75 6e 63 74  g with SQL Funct
24a0: 69 6f 6e 73 3c 2f 68 32 3e 0d 0a 3c 6f 6c 3e 0d  ions</h2>..<ol>.
24b0: 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 48 61 6e 64 6c  .<li>..<h4>Handl
24c0: 69 6e 67 20 53 51 4c 20 50 72 6f 63 65 64 75 72  ing SQL Procedur
24d0: 65 20 42 4c 4f 42 20 6f 62 6a 65 63 74 73 3c 2f  e BLOB objects</
24e0: 68 34 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d  h4>..<verbatim>.
24f0: 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f  .SELECT SqlProc_
2500: 46 72 6f 6d 54 65 78 74 28 27 53 45 4c 45 43 54  FromText('SELECT
2510: 20 40 63 6f 6c 40 20 46 52 4f 4d 20 40 74 62 6c   @col@ FROM @tbl
2520: 40 27 29 3b 0d 0a 0d 0a 53 45 4c 45 43 54 20 53  @');....SELECT S
2530: 71 6c 50 72 6f 63 5f 46 72 6f 6d 46 69 6c 65 28  qlProc_FromFile(
2540: 27 2f 68 6f 6d 65 2f 6a 6f 65 2f 74 65 6d 70 6c  '/home/joe/templ
2550: 61 74 65 2e 74 78 74 27 2c 20 43 50 31 32 35 32  ate.txt', CP1252
2560: 27 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e  ');..</verbatim>
2570: 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 79 6f 75 20  ..<ul>..<li>you 
2580: 63 61 6e 20 63 72 65 61 74 65 20 61 20 53 51 4c  can create a SQL
2590: 20 50 72 6f 63 65 64 75 72 65 20 42 4c 4f 42 20   Procedure BLOB 
25a0: 6f 62 6a 65 63 74 20 62 79 20 64 69 72 65 63 74  object by direct
25b0: 6c 79 20 70 61 73 73 69 6e 67 20 61 20 54 65 78  ly passing a Tex
25c0: 74 20 53 51 4c 20 42 6f 64 79 2e 3c 2f 6c 69 3e  t SQL Body.</li>
25d0: 0d 0a 3c 6c 69 3e 6f 72 20 61 6c 74 65 72 6e 61  ..<li>or alterna
25e0: 74 69 76 65 6c 79 20 79 6f 75 20 63 61 6e 20 6c  tively you can l
25f0: 6f 61 64 20 74 68 65 20 53 51 4c 20 42 6f 64 79  oad the SQL Body
2600: 20 66 72 6f 6d 20 61 6e 20 65 78 74 65 72 6e 61   from an externa
2610: 6c 20 66 69 6c 65 2e 3c 62 72 3e 0d 0a 3c 75 3e  l file.<br>..<u>
2620: 4e 6f 74 65 3c 2f 75 3e 3a 20 74 68 69 73 20 69  Note</u>: this i
2630: 73 20 61 20 73 65 63 75 72 69 74 79 20 73 65 6e  s a security sen
2640: 73 69 62 6c 65 20 6f 70 65 72 61 74 69 6f 6e 2c  sible operation,
2650: 20 73 6f 20 79 6f 75 20 61 6c 77 61 79 73 20 6e   so you always n
2660: 65 65 64 20 74 6f 20 73 65 74 20 61 6e 20 65 78  eed to set an ex
2670: 70 6c 69 63 69 74 20 61 75 74 68 6f 72 69 7a 61  plicit authoriza
2680: 74 69 6f 6e 20 62 79 20 64 65 66 69 6e 69 6e 67  tion by defining
2690: 20 3c 62 3e 53 50 41 54 49 41 4c 49 54 45 5f 53   <b>SPATIALITE_S
26a0: 45 43 55 52 49 54 59 3d 72 65 6c 61 78 65 64 3c  ECURITY=relaxed<
26b0: 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 42  /b>.</li>..<li>B
26c0: 6f 74 68 20 66 75 6e 63 74 69 6f 6e 73 20 61 63  oth functions ac
26d0: 63 65 70 74 20 61 6e 20 6f 70 74 69 6f 6e 61 6c  cept an optional
26e0: 20 3c 62 3e 63 68 61 72 73 65 74 20 65 6e 63 6f   <b>charset enco
26f0: 64 69 6e 67 3c 2f 62 3e 20 61 72 67 75 6d 65 6e  ding</b> argumen
2700: 74 3b 20 69 6e 20 74 68 69 73 20 63 61 73 65 20  t; in this case 
2710: 74 68 65 20 53 51 4c 20 42 6f 64 79 20 77 69 6c  the SQL Body wil
2720: 6c 20 62 65 20 61 70 70 72 6f 70 72 69 61 74 65  l be appropriate
2730: 6c 79 20 63 6f 6e 76 65 72 74 65 64 20 66 72 6f  ly converted fro
2740: 6d 20 74 68 65 20 67 69 76 65 6e 20 63 68 61 72  m the given char
2750: 73 65 74 20 69 6e 74 6f 20 3c 62 3e 55 54 46 2d  set into <b>UTF-
2760: 38 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75  8</b>.</li>..</u
2770: 6c 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  l>..<verbatim>..
2780: 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 49  SELECT SqlProc_I
2790: 73 56 61 6c 69 64 20 28 20 53 71 6c 50 72 6f 63  sValid ( SqlProc
27a0: 5f 46 72 6f 6d 54 65 78 74 28 27 53 45 4c 45 43  _FromText('SELEC
27b0: 54 20 40 63 6f 6c 40 20 46 52 4f 4d 20 40 74 62  T @col@ FROM @tb
27c0: 6c 40 27 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a  l@') );..-----..
27d0: 31 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50  1....SELECT SqlP
27e0: 72 6f 63 5f 49 73 56 61 6c 69 64 20 28 20 4d 61  roc_IsValid ( Ma
27f0: 6b 65 50 6f 69 6e 74 28 31 31 2e 35 2c 20 34 32  kePoint(11.5, 42
2800: 2e 35 2c 20 34 33 32 36 29 20 29 3b 0d 0a 2d 2d  .5, 4326) );..--
2810: 2d 2d 2d 0d 0a 30 0d 0a 3c 2f 76 65 72 62 61 74  ---..0..</verbat
2820: 69 6d 3e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 79  im>..<ul>..<li>y
2830: 6f 75 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 71  ou can use <b>Sq
2840: 6c 50 72 6f 63 5f 49 73 56 61 6c 69 64 3c 2f 62  lProc_IsValid</b
2850: 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 63 68  > in order to ch
2860: 65 63 6b 20 69 66 20 61 20 67 65 6e 65 72 69 63  eck if a generic
2870: 20 42 4c 4f 42 20 72 65 61 6c 6c 79 20 69 73 20   BLOB really is 
2880: 61 20 76 61 6c 69 64 20 53 51 4c 20 50 72 6f 63  a valid SQL Proc
2890: 65 64 75 72 65 20 42 4c 4f 42 20 4f 62 6a 65 63  edure BLOB Objec
28a0: 74 2e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 76 65 72 62  t...</ul>..<verb
28b0: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 71  atim>..SELECT Sq
28c0: 6c 50 72 6f 63 5f 4e 75 6d 56 61 72 69 61 62 6c  lProc_NumVariabl
28d0: 65 73 20 28 20 53 71 6c 50 72 6f 63 5f 46 72 6f  es ( SqlProc_Fro
28e0: 6d 54 65 78 74 28 27 53 45 4c 45 43 54 20 40 63  mText('SELECT @c
28f0: 6f 6c 40 20 46 52 4f 4d 20 40 74 62 6c 40 27 29  ol@ FROM @tbl@')
2900: 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 32 0d 0a 0d   );..-----..2...
2910: 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f  .SELECT SqlProc_
2920: 56 61 72 69 61 62 6c 65 4e 20 28 53 71 6c 50 72  VariableN (SqlPr
2930: 6f 63 5f 46 72 6f 6d 54 65 78 74 28 27 53 45 4c  oc_FromText('SEL
2940: 45 43 54 20 40 63 6f 6c 40 20 46 52 4f 4d 20 40  ECT @col@ FROM @
2950: 74 62 6c 40 27 29 2c 20 30 29 3b 0d 0a 2d 2d 2d  tbl@'), 0);..---
2960: 2d 2d 0d 0a 40 63 6f 6c 40 0d 0a 0d 0a 53 45 4c  --..@col@....SEL
2970: 45 43 54 20 53 71 6c 50 72 6f 63 5f 56 61 72 69  ECT SqlProc_Vari
2980: 61 62 6c 65 4e 20 28 53 71 6c 50 72 6f 63 5f 46  ableN (SqlProc_F
2990: 72 6f 6d 54 65 78 74 28 27 53 45 4c 45 43 54 20  romText('SELECT 
29a0: 40 63 6f 6c 40 20 46 52 4f 4d 20 40 74 62 6c 40  @col@ FROM @tbl@
29b0: 27 29 2c 20 31 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a  '), 1);..-----..
29c0: 40 74 62 6c 40 0d 0a 0d 0a 53 45 4c 45 43 54 20  @tbl@....SELECT 
29d0: 53 71 6c 50 72 6f 63 5f 41 6c 6c 56 61 72 69 61  SqlProc_AllVaria
29e0: 62 6c 65 73 20 28 53 71 6c 50 72 6f 63 5f 46 72  bles (SqlProc_Fr
29f0: 6f 6d 54 65 78 74 28 27 53 45 4c 45 43 54 20 40  omText('SELECT @
2a00: 63 6f 6c 40 20 46 52 4f 4d 20 40 74 62 6c 40 27  col@ FROM @tbl@'
2a10: 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 40 63 6f  ) );..-----..@co
2a20: 6c 40 20 40 74 62 6c 40 0d 0a 3c 2f 76 65 72 62  l@ @tbl@..</verb
2a30: 61 74 69 6d 3e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69  atim>..<ul>..<li
2a40: 3e 79 6f 75 20 63 61 6e 20 75 73 65 20 3c 62 3e  >you can use <b>
2a50: 53 71 6c 50 72 6f 63 5f 4e 75 6d 56 61 72 69 61  SqlProc_NumVaria
2a60: 62 6c 65 73 3c 2f 62 3e 20 69 6e 20 6f 72 64 65  bles</b> in orde
2a70: 72 20 74 6f 20 63 68 65 63 6b 20 68 6f 77 20 6d  r to check how m
2a80: 61 6e 79 20 56 61 72 69 61 62 6c 65 73 20 61 72  any Variables ar
2a90: 65 20 64 65 66 69 6e 65 64 20 62 79 20 61 20 53  e defined by a S
2aa0: 51 4c 20 50 72 6f 63 65 64 75 72 65 20 42 4c 4f  QL Procedure BLO
2ab0: 42 20 4f 62 6a 65 63 74 2e 3c 2f 6c 69 3e 0d 0a  B Object.</li>..
2ac0: 3c 6c 69 3e 61 6e 64 20 79 6f 75 20 63 61 6e 20  <li>and you can 
2ad0: 75 73 65 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 56  use <b>SqlProc_V
2ae0: 61 72 69 61 62 6c 65 4e 3c 2f 62 3e 20 69 6e 20  ariableN</b> in 
2af0: 6f 72 64 65 72 20 74 6f 20 72 65 74 72 69 65 76  order to retriev
2b00: 65 20 61 20 56 61 72 69 61 62 6c 65 20 4e 61 6d  e a Variable Nam
2b10: 65 20 62 79 20 73 70 65 63 69 66 79 69 6e 67 20  e by specifying 
2b20: 69 74 73 20 72 65 6c 61 74 69 76 65 20 3c 62 3e  its relative <b>
2b30: 49 6e 64 65 78 3c 2f 62 3e 20 28 46 69 72 73 74  Index</b> (First
2b40: 20 56 61 72 69 61 62 6c 65 20 61 6c 77 61 79 73   Variable always
2b50: 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20   corresponds to 
2b60: 3c 62 3e 49 6e 64 65 78 3d 30 3c 2f 62 3e 29 2e  <b>Index=0</b>).
2b70: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 64 20 66  </li>..<li>and f
2b80: 69 6e 61 6c 6c 79 20 79 6f 75 20 63 61 6e 20 75  inally you can u
2b90: 73 65 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 41 6c  se <b>SqlProc_Al
2ba0: 6c 56 61 72 69 61 62 6c 65 73 3c 2f 62 3e 20 69  lVariables</b> i
2bb0: 6e 20 6f 72 64 65 72 20 74 6f 20 64 69 72 65 63  n order to direc
2bc0: 74 6c 79 20 67 65 74 20 61 6c 6c 20 56 61 72 69  tly get all Vari
2bd0: 61 62 6c 65 20 4e 61 6d 65 73 20 66 6f 72 6d 61  able Names forma
2be0: 74 74 65 64 20 61 73 20 61 20 73 70 61 63 65 2d  tted as a space-
2bf0: 73 65 70 61 72 61 74 65 64 20 6c 69 73 74 2e 3c  separated list.<
2c00: 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 62 72  /li>..</ul>..<br
2c10: 3e 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c  ><hr>..</li>..<l
2c20: 69 3e 0d 0a 3c 68 34 3e 45 72 72 6f 72 20 68 61  i>..<h4>Error ha
2c30: 6e 64 6c 69 6e 67 3c 2f 68 34 3e 0d 0a 3c 76 65  ndling</h4>..<ve
2c40: 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20  rbatim>..SELECT 
2c50: 53 71 6c 50 72 6f 63 5f 47 65 74 4c 61 73 74 45  SqlProc_GetLastE
2c60: 72 72 6f 72 28 29 3b 0d 0a 3c 2f 76 65 72 62 61  rror();..</verba
2c70: 74 69 6d 3e 0d 0a 41 6c 6c 20 74 68 65 73 65 20  tim>..All these 
2c80: 66 75 6e 63 74 69 6f 6e 73 20 77 69 6c 6c 20 72  functions will r
2c90: 61 69 73 65 20 61 6e 20 45 78 63 65 70 74 69 6f  aise an Exceptio
2ca0: 6e 20 6f 6e 20 69 6e 76 61 6c 69 64 20 61 72 67  n on invalid arg
2cb0: 75 6d 65 6e 74 73 20 6f 72 20 65 72 72 6f 72 73  uments or errors
2cc0: 2e 3c 62 72 3e 0d 0a 42 79 20 63 61 6c 6c 69 6e  .<br>..By callin
2cd0: 67 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 47 65 74  g <b>SqlProc_Get
2ce0: 4c 61 73 74 45 72 72 6f 72 3c 2f 62 3e 20 79 6f  LastError</b> yo
2cf0: 75 27 6c 6c 20 75 73 75 61 6c 6c 79 20 67 65 74  u'll usually get
2d00: 20 61 20 6d 6f 72 65 20 64 65 74 61 69 6c 65 64   a more detailed
2d10: 20 65 78 70 6c 61 6e 61 74 69 6f 6e 20 61 62 6f   explanation abo
2d20: 75 74 20 74 68 65 20 73 70 65 63 69 66 69 63 20  ut the specific 
2d30: 63 61 75 73 65 20 61 63 63 6f 75 6e 74 69 6e 67  cause accounting
2d40: 20 66 6f 72 20 74 68 65 20 66 61 69 6c 75 72 65   for the failure
2d50: 2e 0d 0a 3c 62 72 3e 3c 62 72 3e 3c 68 72 3e 0d  ...<br><br><hr>.
2d60: 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68  .</li>..<li>..<h
2d70: 34 3e 43 72 65 61 74 69 6e 67 20 56 61 72 69 61  4>Creating Varia
2d80: 62 6c 65 73 20 77 69 74 68 20 56 61 6c 75 65 73  bles with Values
2d90: 3c 2f 68 34 3e 0d 0a 3c 76 65 72 62 61 74 69 6d  </h4>..<verbatim
2da0: 3e 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f  >..SELECT SqlPro
2db0: 63 5f 56 61 72 56 61 6c 75 65 20 28 27 76 61 72  c_VarValue ('var
2dc0: 27 2c 20 4e 55 4c 4c 29 3b 0d 0a 2d 2d 2d 2d 2d  ', NULL);..-----
2dd0: 0d 0a 40 76 61 72 40 3d 4e 55 4c 4c 0d 0a 0d 0a  ..@var@=NULL....
2de0: 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 56  SELECT SqlProc_V
2df0: 61 72 56 61 6c 75 65 20 28 27 76 61 72 27 2c 20  arValue ('var', 
2e00: 31 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 40 76 61 72  1);..-----..@var
2e10: 40 3d 31 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 71  @=1....SELECT Sq
2e20: 6c 50 72 6f 63 5f 56 61 72 56 61 6c 75 65 20 28  lProc_VarValue (
2e30: 27 76 61 72 27 2c 20 31 30 2e 35 29 3b 0d 0a 2d  'var', 10.5);..-
2e40: 2d 2d 2d 2d 0d 0a 40 76 61 72 40 3d 31 30 2e 35  ----..@var@=10.5
2e50: 30 30 30 30 30 30 30 30 30 0d 0a 0d 0a 53 45 4c  000000000....SEL
2e60: 45 43 54 20 53 71 6c 50 72 6f 63 5f 56 61 72 56  ECT SqlProc_VarV
2e70: 61 6c 75 65 20 28 27 76 61 72 27 2c 20 27 61 6c  alue ('var', 'al
2e80: 70 68 61 20 62 65 74 61 27 29 3b 0d 0a 2d 2d 2d  pha beta');..---
2e90: 2d 2d 0d 0a 40 76 61 72 40 3d 61 6c 70 68 61 20  --..@var@=alpha 
2ea0: 62 65 74 61 0d 0a 0d 0a 53 45 4c 45 43 54 20 53  beta....SELECT S
2eb0: 71 6c 50 72 6f 63 5f 56 61 72 56 61 6c 75 65 20  qlProc_VarValue 
2ec0: 28 27 76 61 72 27 2c 20 4d 61 6b 65 50 6f 69 6e  ('var', MakePoin
2ed0: 74 28 31 31 2e 35 2c 20 34 32 2e 35 2c 20 34 33  t(11.5, 42.5, 43
2ee0: 32 36 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 40  26) );..-----..@
2ef0: 76 61 72 40 3d 78 27 30 30 30 31 45 36 31 30 30  var@=x'0001E6100
2f00: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 32  0000000000000002
2f10: 37 34 30 30 30 30 30 30 30 30 30 30 30 34 30 34  7400000000000404
2f20: 35 34 30 30 30 30 30 30 30 30 30 30 30 30 30 32  5400000000000002
2f30: 37 34 30 30 30 30 30 30 30 30 30 30 30 34 30 34  7400000000000404
2f40: 35 34 30 37 43 30 31 30 30 30 30 30 30 30 30 30  5407C01000000000
2f50: 30 30 30 30 30 30 30 30 30 32 37 34 30 30 30 30  0000000002740000
2f60: 30 30 30 30 30 30 30 34 30 34 35 34 30 46 45 27  0000000404540FE'
2f70: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c  ..</verbatim>..<
2f80: 75 3e 4e 6f 74 65 3c 2f 75 3e 3a 20 68 61 6e 64  u>Note</u>: hand
2f90: 20 77 72 69 74 69 6e 67 20 56 61 72 69 61 62 6c   writing Variabl
2fa0: 65 20 77 69 74 68 20 56 61 6c 75 65 20 73 74 72  e with Value str
2fb0: 69 6e 67 73 20 69 73 20 61 20 72 61 74 68 65 72  ings is a rather
2fc0: 20 74 72 69 76 69 61 6c 20 6f 70 65 72 61 74 69   trivial operati
2fd0: 6f 6e 2c 20 73 6f 20 63 61 6c 6c 69 6e 67 20 74  on, so calling t
2fe0: 68 69 73 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e  his SQL function
2ff0: 20 69 73 20 6f 66 74 65 6e 20 6b 69 6e 64 20 6f   is often kind o
3000: 66 20 61 6e 20 6f 76 65 72 6b 69 6c 6c 2e 20 45  f an overkill. E
3010: 78 63 65 70 74 2c 20 6d 61 79 20 62 65 2c 20 69  xcept, may be, i
3020: 6e 20 74 68 65 20 63 61 73 65 20 6f 66 20 42 4c  n the case of BL
3030: 4f 42 20 76 61 6c 75 65 73 2e 0d 0a 3c 62 72 3e  OB values...<br>
3040: 3c 62 72 3e 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d  <br><hr>..</li>.
3050: 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 52 61 77 20 61  .<li>..<h4>Raw a
3060: 6e 64 20 43 6f 6f 6b 65 64 20 53 51 4c 20 2d 20  nd Cooked SQL - 
3070: 72 65 70 6c 61 63 69 6e 67 20 53 79 6d 62 6f 6c  replacing Symbol
3080: 73 20 77 69 74 68 20 74 68 65 69 72 20 61 63 74  s with their act
3090: 75 61 6c 20 56 61 6c 75 65 73 3c 2f 68 34 3e 0d  ual Values</h4>.
30a0: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c  .<verbatim>..SEL
30b0: 45 43 54 20 53 71 6c 50 72 6f 63 5f 52 61 77 53  ECT SqlProc_RawS
30c0: 51 4c 20 28 20 53 71 6c 50 72 6f 63 5f 46 72 6f  QL ( SqlProc_Fro
30d0: 6d 54 65 78 74 28 27 53 45 4c 45 43 54 20 40 63  mText('SELECT @c
30e0: 6f 6c 40 20 46 52 4f 4d 20 40 74 62 6c 40 3b 27  ol@ FROM @tbl@;'
30f0: 29 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 53 45 4c  ) );..-----..SEL
3100: 45 43 54 20 40 63 6f 6c 40 20 46 52 4f 4d 20 40  ECT @col@ FROM @
3110: 74 62 6c 40 3b 0d 0a 0d 0a 53 45 4c 45 43 54 20  tbl@;....SELECT 
3120: 53 71 6c 50 72 6f 63 5f 43 6f 6f 6b 65 64 53 51  SqlProc_CookedSQ
3130: 4c 20 28 20 53 71 6c 50 72 6f 63 5f 46 72 6f 6d  L ( SqlProc_From
3140: 54 65 78 74 28 27 53 45 4c 45 43 54 20 40 63 6f  Text('SELECT @co
3150: 6c 40 20 46 52 4f 4d 20 40 74 62 6c 40 3b 27 29  l@ FROM @tbl@;')
3160: 2c 0d 0a 20 20 20 20 27 40 63 6f 6c 40 3d 66 69  ,..    '@col@=fi
3170: 72 73 74 5f 6e 61 6d 65 27 2c 0d 0a 20 20 20 20  rst_name',..    
3180: 27 40 74 62 6c 40 3d 70 68 6f 6e 65 5f 62 6f 6f  '@tbl@=phone_boo
3190: 6b 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 53 45  k' );..-----..SE
31a0: 4c 45 43 54 20 66 69 72 73 74 5f 6e 61 6d 65 20  LECT first_name 
31b0: 46 52 4f 4d 20 70 68 6f 6e 65 5f 62 6f 6f 6b 3b  FROM phone_book;
31c0: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c  ..</verbatim>..<
31d0: 75 6c 3e 0d 0a 3c 6c 69 3e 79 6f 75 20 63 61 6e  ul>..<li>you can
31e0: 20 75 73 65 20 3c 62 3e 53 71 6c 50 72 6f 63 5f   use <b>SqlProc_
31f0: 52 61 77 53 51 4c 3c 2f 62 3e 20 69 6e 20 6f 72  RawSQL</b> in or
3200: 64 65 72 20 74 6f 20 64 69 72 65 63 74 6c 79 20  der to directly 
3210: 63 68 65 63 6b 20 74 68 65 20 53 51 4c 20 42 6f  check the SQL Bo
3220: 64 79 20 65 6e 63 61 70 73 75 6c 61 74 65 64 20  dy encapsulated 
3230: 69 6e 74 6f 20 73 20 53 51 4c 20 50 72 6f 63 65  into s SQL Proce
3240: 64 75 72 65 20 42 4c 4f 42 20 4f 62 6a 65 63 74  dure BLOB Object
3250: 3b 20 61 6c 6c 20 69 6e 69 74 69 61 6c 20 56 61  ; all initial Va
3260: 72 69 61 62 6c 65 20 64 65 66 69 6e 69 74 69 6f  riable definitio
3270: 6e 73 20 77 69 6c 6c 20 62 65 20 63 61 72 65 66  ns will be caref
3280: 75 6c 6c 79 20 70 72 65 73 65 72 76 65 64 2e 3c  ully preserved.<
3290: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 64 20 79 6f  /li>..<li>and yo
32a0: 75 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 71 6c  u can use <b>Sql
32b0: 50 72 6f 63 5f 43 6f 6f 6b 65 64 53 51 4c 3c 2f  Proc_CookedSQL</
32c0: 62 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 64  b> in order to d
32d0: 69 72 65 63 74 6c 79 20 63 68 65 63 6b 20 74 68  irectly check th
32e0: 65 20 53 51 4c 20 42 6f 64 79 20 61 73 20 69 74  e SQL Body as it
32f0: 20 61 63 74 75 61 6c 6c 79 20 61 70 70 65 61 72   actually appear
3300: 73 20 61 66 74 65 72 20 72 65 70 6c 61 63 69 6e  s after replacin
3310: 67 20 61 6c 6c 20 72 65 71 75 69 72 65 64 20 56  g all required V
3320: 61 72 69 61 62 6c 65 20 56 61 6c 75 65 73 2e 3c  ariable Values.<
3330: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 42 6f 74 68 20 66  /li>..<li>Both f
3340: 75 6e 63 74 69 6f 6e 73 20 61 72 65 20 6d 61 69  unctions are mai
3350: 6e 6c 79 20 69 6e 74 65 6e 64 65 64 20 66 6f 72  nly intended for
3360: 20 73 75 70 70 6f 72 74 69 6e 67 20 64 65 62 75   supporting debu
3370: 67 67 69 6e 67 20 61 63 74 69 76 69 74 69 65 73  gging activities
3380: 2c 20 73 6f 20 74 6f 20 6d 61 6b 65 20 61 73 20  , so to make as 
3390: 65 61 73 79 20 61 73 20 70 6f 73 73 69 62 6c 65  easy as possible
33a0: 20 69 64 65 6e 74 69 66 79 69 6e 67 20 65 76 65   identifying eve
33b0: 6e 74 75 61 6c 20 65 72 72 6f 72 73 2e 3c 2f 6c  ntual errors.</l
33c0: 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d 0a 3c  i>..</ul><br>..<
33d0: 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23  table bgcolor="#
33e0: 66 38 66 38 64 38 22 20 63 65 6c 6c 70 61 64 64  f8f8d8" cellpadd
33f0: 69 6e 67 3d 22 36 22 20 63 65 6c 6c 73 70 61 63  ing="6" cellspac
3400: 69 6e 67 3d 22 38 22 3e 3c 74 72 3e 3c 74 64 3e  ing="8"><tr><td>
3410: 0d 0a 3c 75 3e 4e 6f 74 65 3c 2f 75 3e 3a 20 3c  ..<u>Note</u>: <
3420: 62 3e 53 71 6c 50 72 6f 63 5f 43 6f 6f 6b 65 64  b>SqlProc_Cooked
3430: 53 51 4c 3c 2f 62 3e 20 77 69 6c 6c 20 61 63 63  SQL</b> will acc
3440: 65 70 74 20 61 6e 20 61 72 62 69 74 72 61 72 79  ept an arbitrary
3450: 20 6c 69 73 74 20 6f 66 20 3c 62 3e 56 61 72 69   list of <b>Vari
3460: 61 62 6c 65 20 77 69 74 68 20 56 61 6c 75 65 3c  able with Value<
3470: 2f 62 3e 20 61 72 67 75 6d 65 6e 74 73 2e 0d 0a  /b> arguments...
3480: 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 6e 20 65 6d 70  <ul>..<li>an emp
3490: 74 79 20 6c 69 73 74 20 28 6e 6f 20 56 61 72 69  ty list (no Vari
34a0: 61 62 6c 65 73 20 77 69 74 68 20 56 61 6c 75 65  ables with Value
34b0: 73 20 61 74 20 61 6c 6c 29 20 69 73 20 61 20 70  s at all) is a p
34c0: 65 72 66 65 63 74 6c 79 20 6c 65 67 61 6c 20 63  erfectly legal c
34d0: 6f 6e 64 69 74 69 6f 6e 20 28 63 6f 75 6c 64 20  ondition (could 
34e0: 65 76 65 6e 74 75 61 6c 6c 79 20 6c 65 61 64 20  eventually lead 
34f0: 74 6f 20 61 6e 20 69 6e 76 61 6c 69 64 20 43 6f  to an invalid Co
3500: 6f 6b 65 64 20 53 51 4c 20 42 6f 64 79 2c 20 73  oked SQL Body, s
3510: 65 65 20 62 65 6c 6f 77 29 2e 3c 2f 6c 69 3e 0d  ee below).</li>.
3520: 0a 3c 6c 69 3e 61 6c 6c 20 61 72 67 75 6d 65 6e  .<li>all argumen
3530: 74 73 20 66 72 6f 6d 20 74 68 65 20 73 65 63 6f  ts from the seco
3540: 6e 64 20 75 6e 74 69 6c 20 74 68 65 20 65 6e 64  nd until the end
3550: 20 61 72 65 20 65 78 70 65 63 74 65 64 20 74 6f   are expected to
3560: 20 62 65 20 77 65 6c 6c 2d 66 6f 72 6d 65 64 20   be well-formed 
3570: 56 61 72 69 61 62 6c 65 73 20 77 69 74 68 20 56  Variables with V
3580: 61 6c 75 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  alues.</li>..<li
3590: 3e 79 6f 75 20 63 61 6e 20 64 65 66 69 6e 65 20  >you can define 
35a0: 61 73 20 6d 75 63 68 20 61 73 20 3c 62 3e 31 36  as much as <b>16
35b0: 3c 2f 62 3e 20 64 69 66 66 65 72 65 6e 74 20 56  </b> different V
35c0: 61 72 69 61 62 6c 65 73 20 77 69 74 68 20 56 61  ariables with Va
35d0: 6c 75 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e  lues.</li>..<li>
35e0: 61 6e 79 20 61 74 74 65 6d 70 74 20 74 6f 20 64  any attempt to d
35f0: 65 66 69 6e 65 20 74 77 69 63 65 20 61 20 56 61  efine twice a Va
3600: 6c 75 65 20 66 6f 72 20 74 68 65 20 73 61 6d 65  lue for the same
3610: 20 56 61 72 69 61 62 6c 65 20 77 69 6c 6c 20 62   Variable will b
3620: 65 20 61 6c 77 61 79 73 20 63 6f 6e 73 69 64 65  e always conside
3630: 72 65 64 20 61 73 20 61 20 66 61 74 61 6c 20 65  red as a fatal e
3640: 72 72 6f 72 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e  rror.</li>..<li>
3650: 69 66 20 6f 6e 65 20 6f 66 20 74 68 65 20 56 61  if one of the Va
3660: 72 69 61 62 6c 65 20 61 72 67 75 6d 65 6e 74 73  riable arguments
3670: 20 64 6f 65 73 20 6e 6f 74 20 6d 61 74 63 68 20   does not match 
3680: 6f 6e 65 20 74 68 65 20 56 61 72 69 61 62 6c 65  one the Variable
3690: 73 20 69 6e 74 65 72 6e 61 6c 6c 79 20 64 65 66  s internally def
36a0: 69 6e 65 64 20 62 79 20 74 68 65 20 52 61 77 20  ined by the Raw 
36b0: 53 51 4c 20 42 6f 64 79 20 69 74 20 77 69 6c 6c  SQL Body it will
36c0: 20 62 65 20 73 69 6d 70 6c 79 20 69 67 6e 6f 72   be simply ignor
36d0: 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 69 66  ed.</li>..<li>if
36e0: 20 61 20 56 61 72 69 61 62 6c 65 20 64 65 66 69   a Variable defi
36f0: 6e 65 64 20 69 6e 74 6f 20 74 68 65 20 52 61 77  ned into the Raw
3700: 20 53 51 4c 20 42 6f 64 79 20 64 6f 65 73 20 6e   SQL Body does n
3710: 6f 74 20 6d 61 74 63 68 65 73 20 61 20 63 6f 72  ot matches a cor
3720: 72 65 73 70 6f 6e 64 69 6e 67 20 56 61 72 69 61  responding Varia
3730: 62 6c 65 20 61 72 67 75 6d 65 6e 74 20 74 68 65  ble argument the
3740: 6e 20 69 74 20 77 69 6c 6c 20 72 65 70 6c 61 63  n it will replac
3750: 65 64 20 62 79 20 61 20 64 65 66 61 75 6c 74 20  ed by a default 
3760: 27 3c 62 3e 4e 55 4c 4c 3c 2f 62 3e 27 20 73 74  '<b>NULL</b>' st
3770: 72 69 6e 67 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e  ring.</li>..<li>
3780: 74 68 65 20 73 61 6d 65 20 69 64 65 6e 74 69 63  the same identic
3790: 61 6c 20 72 75 6c 65 73 20 66 6f 72 20 70 61 73  al rules for pas
37a0: 73 69 6e 67 20 56 61 72 69 61 62 6c 65 2d 56 61  sing Variable-Va
37b0: 6c 75 65 20 61 72 67 75 6d 65 6e 74 73 20 61 70  lue arguments ap
37c0: 70 6c 79 20 74 6f 20 3c 62 3e 53 71 6c 50 72 6f  ply to <b>SqlPro
37d0: 63 5f 43 6f 6f 6b 65 64 53 51 4c 3c 2f 62 3e 2c  c_CookedSQL</b>,
37e0: 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 45 78 65 63   <b>SqlProc_Exec
37f0: 75 74 65 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e 53  ute</b> and <b>S
3800: 74 6f 72 65 64 50 72 6f 63 5f 45 78 65 63 75 74  toredProc_Execut
3810: 65 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75  e</b>.</li>..</u
3820: 6c 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f  l>..</td></tr></
3830: 74 61 62 6c 65 3e 0d 0a 3c 62 72 3e 3c 68 72 3e  table>..<br><hr>
3840: 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c  ..</li>..<li>..<
3850: 68 34 3e 45 78 65 63 75 74 69 6e 67 20 61 20 53  h4>Executing a S
3860: 51 4c 20 50 72 6f 63 65 64 75 72 65 3c 2f 68 34  QL Procedure</h4
3870: 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53  >..<verbatim>..S
3880: 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 45 78  ELECT SqlProc_Ex
3890: 65 63 75 74 65 20 28 53 71 6c 50 72 6f 63 5f 46  ecute (SqlProc_F
38a0: 72 6f 6d 54 65 78 74 28 27 53 45 4c 45 43 54 20  romText('SELECT 
38b0: 40 63 6f 6c 40 20 46 52 4f 4d 20 40 74 62 6c 40  @col@ FROM @tbl@
38c0: 3b 27 29 2c 0d 0a 20 20 20 20 27 40 63 6f 6c 40  ;'),..    '@col@
38d0: 3d 66 69 72 73 74 5f 6e 61 6d 65 27 2c 0d 0a 20  =first_name',.. 
38e0: 20 20 20 27 40 74 62 6c 40 3d 70 68 6f 6e 65 5f     '@tbl@=phone_
38f0: 62 6f 6f 6b 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d  book' );..-----.
3900: 0a 53 71 6c 50 72 6f 63 20 65 78 63 65 70 74 69  .SqlProc excepti
3910: 6f 6e 20 2d 20 61 20 66 61 74 61 6c 20 53 51 4c  on - a fatal SQL
3920: 20 65 72 72 6f 72 20 77 61 73 20 65 6e 63 6f 75   error was encou
3930: 6e 74 65 72 65 64 2e 0d 0a 0d 0a 53 45 4c 45 43  ntered.....SELEC
3940: 54 20 53 71 6c 50 72 6f 63 5f 47 65 74 4c 61 73  T SqlProc_GetLas
3950: 74 45 72 72 6f 72 28 29 3b 0d 0a 2d 2d 2d 2d 2d  tError();..-----
3960: 0d 0a 67 61 69 61 5f 73 71 6c 5f 70 72 6f 63 5f  ..gaia_sql_proc_
3970: 65 78 65 63 75 74 65 3a 20 6e 6f 20 73 75 63 68  execute: no such
3980: 20 74 61 62 6c 65 3a 20 70 68 6f 6e 65 5f 62 6f   table: phone_bo
3990: 6f 6b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d  ok..</verbatim>.
39a0: 0a 79 6f 75 20 63 61 6e 20 75 73 65 20 3c 62 3e  .you can use <b>
39b0: 53 71 6c 50 72 6f 63 5f 45 78 65 63 75 74 65 3c  SqlProc_Execute<
39c0: 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20  /b> in order to 
39d0: 64 69 72 65 63 74 6c 79 20 65 78 65 63 75 74 65  directly execute
39e0: 20 74 68 65 20 77 68 6f 6c 65 20 53 51 4c 20 42   the whole SQL B
39f0: 6f 64 79 20 61 73 20 61 20 73 69 6e 67 6c 65 20  ody as a single 
3a00: 6d 6f 6e 6f 6c 69 74 68 69 63 20 75 6e 69 74 2e  monolithic unit.
3a10: 3c 62 72 3e 0d 0a 41 74 20 74 68 65 20 65 6e 64  <br>..At the end
3a20: 20 6f 66 20 74 68 65 20 70 72 6f 63 65 73 73 20   of the process 
3a30: 3c 62 3e 31 3c 2f 62 3e 20 28 61 6b 61 20 3c 62  <b>1</b> (aka <b
3a40: 3e 54 72 75 65 3c 2f 62 3e 29 20 77 69 6c 6c 20  >True</b>) will 
3a50: 62 65 20 72 65 74 75 72 6e 65 64 20 6f 6e 20 66  be returned on f
3a60: 75 6c 6c 20 73 75 63 63 65 73 73 3b 20 61 6e 20  ull success; an 
3a70: 45 78 63 65 70 74 69 6f 6e 20 77 69 6c 6c 20 62  Exception will b
3a80: 65 20 72 61 69 73 65 64 20 6f 6e 20 66 61 69 6c  e raised on fail
3a90: 75 72 65 2c 20 61 73 20 69 74 20 68 61 70 70 65  ure, as it happe
3aa0: 6e 73 20 69 6e 20 74 68 69 73 20 65 78 61 6d 70  ns in this examp
3ab0: 6c 65 2c 20 61 6e 64 20 69 6e 20 74 68 69 73 20  le, and in this 
3ac0: 63 61 73 65 20 79 6f 75 20 63 61 6e 20 74 68 65  case you can the
3ad0: 6e 20 75 73 65 20 3c 62 3e 53 71 6c 50 72 6f 63  n use <b>SqlProc
3ae0: 5f 47 65 74 4c 61 73 74 45 72 72 6f 72 3c 2f 62  _GetLastError</b
3af0: 3e 20 73 6f 20 74 6f 20 72 65 74 72 69 65 76 65  > so to retrieve
3b00: 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69   the correspondi
3b10: 6e 67 20 53 51 4c 20 65 72 72 6f 72 20 6d 65 73  ng SQL error mes
3b20: 73 61 67 65 2e 0d 0a 3c 62 72 3e 3c 62 72 3e 0d  sage...<br><br>.
3b30: 0a 3c 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72 3d  .<table bgcolor=
3b40: 22 23 66 38 66 38 64 38 22 20 63 65 6c 6c 70 61  "#f8f8d8" cellpa
3b50: 64 64 69 6e 67 3d 22 36 22 20 63 65 6c 6c 73 70  dding="6" cellsp
3b60: 61 63 69 6e 67 3d 22 38 22 3e 3c 74 72 3e 3c 74  acing="8"><tr><t
3b70: 64 3e 0d 0a 3c 75 3e 4e 6f 74 65 3c 2f 75 3e 3a  d>..<u>Note</u>:
3b80: 20 61 6c 6c 20 3c 62 3e 44 6f 74 20 4d 61 63 72   all <b>Dot Macr
3b90: 6f 73 3c 2f 62 3e 20 65 76 65 6e 74 75 61 6c 6c  os</b> eventuall
3ba0: 79 20 66 6f 75 6e 64 20 77 69 74 68 69 6e 20 74  y found within t
3bb0: 68 65 20 53 51 4c 20 42 6f 64 79 20 62 65 69 6e  he SQL Body bein
3bc0: 67 20 65 78 65 63 75 74 65 64 20 77 69 6c 6c 20  g executed will 
3bd0: 62 65 20 61 6c 77 61 79 73 20 73 69 6c 65 6e 74  be always silent
3be0: 6c 79 20 69 67 6e 6f 72 65 64 2e 3c 62 72 3e 0d  ly ignored.<br>.
3bf0: 0a 54 68 65 20 73 61 6d 65 20 72 75 6c 65 20 61  .The same rule a
3c00: 70 70 6c 69 65 73 20 74 6f 20 3c 62 3e 53 74 6f  pplies to <b>Sto
3c10: 72 65 64 50 72 6f 63 5f 45 78 65 63 75 74 65 3c  redProc_Execute<
3c20: 2f 62 3e 20 61 73 20 77 65 6c 6c 2e 3c 2f 62 3e  /b> as well.</b>
3c30: 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61  ..</td></tr></ta
3c40: 62 6c 65 3e 0d 0a 3c 62 72 3e 3c 68 72 3e 0d 0a  ble>..<br><hr>..
3c50: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34  </li>..<li>..<h4
3c60: 3e 48 61 6e 64 6c 69 6e 67 20 53 51 4c 20 53 74  >Handling SQL St
3c70: 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65 73 3c  ored Procedures<
3c80: 2f 68 34 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e  /h4>..<verbatim>
3c90: 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50  ..SELECT StoredP
3ca0: 72 6f 63 5f 43 72 65 61 74 65 54 61 62 6c 65 73  roc_CreateTables
3cb0: 28 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c  ();..-----..1..<
3cc0: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 79 6f 75 20  /verbatim>..you 
3cd0: 63 61 6e 20 75 73 65 20 3c 62 3e 53 74 6f 72 65  can use <b>Store
3ce0: 64 50 72 6f 63 5f 43 72 65 61 74 65 54 61 62 6c  dProc_CreateTabl
3cf0: 65 73 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20  es</b> in order 
3d00: 74 6f 20 63 72 65 61 74 65 20 6f 6e 20 79 6f 75  to create on you
3d10: 72 20 63 75 72 72 65 6e 74 6c 79 20 63 6f 6e 6e  r currently conn
3d20: 65 63 74 65 64 20 64 61 74 61 62 61 73 65 20 61  ected database a
3d30: 6c 6c 20 3c 62 3e 6d 65 74 61 74 61 62 6c 65 73  ll <b>metatables
3d40: 3c 2f 62 3e 20 72 65 71 75 69 72 65 64 20 74 6f  </b> required to
3d50: 20 70 65 72 6d 61 6e 65 6e 74 6c 79 20 72 65 67   permanently reg
3d60: 69 73 74 65 72 20 53 74 6f 72 65 64 20 50 72 6f  ister Stored Pro
3d70: 63 65 64 75 72 65 73 20 61 6e 64 20 53 74 6f 72  cedures and Stor
3d80: 65 64 20 56 61 72 69 61 62 6c 65 73 2e 3c 62 72  ed Variables.<br
3d90: 3e 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65 20 62 67  ><br>..<table bg
3da0: 63 6f 6c 6f 72 3d 22 23 66 38 66 38 64 38 22 20  color="#f8f8d8" 
3db0: 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 36 22 20  cellpadding="6" 
3dc0: 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 38 22 3e  cellspacing="8">
3dd0: 3c 74 72 3e 3c 74 64 3e 0d 0a 3c 75 3e 4e 6f 74  <tr><td>..<u>Not
3de0: 65 3c 2f 75 3e 3a 20 61 6e 79 20 6e 65 77 20 64  e</u>: any new d
3df0: 61 74 61 62 61 73 65 20 63 72 65 61 74 65 64 20  atabase created 
3e00: 62 79 20 53 70 61 74 69 61 4c 69 74 65 20 34 2e  by SpatiaLite 4.
3e10: 35 2e 30 20 28 61 6e 64 20 73 75 62 73 65 71 75  5.0 (and subsequ
3e20: 65 6e 74 20 76 65 72 73 69 6f 6e 73 29 20 77 69  ent versions) wi
3e30: 6c 6c 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79  ll automatically
3e40: 20 73 75 70 70 6f 72 74 20 74 68 65 20 53 74 6f   support the Sto
3e50: 72 65 64 20 50 72 6f 63 65 64 75 72 65 73 20 6d  red Procedures m
3e60: 65 74 61 74 61 62 6c 65 73 2e 0d 0a 45 78 70 6c  etatables...Expl
3e70: 69 63 69 74 6c 79 20 63 61 6c 6c 69 6e 67 20 74  icitly calling t
3e80: 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 69 73 20  his function is 
3e90: 6d 61 69 6e 6c 79 20 75 73 65 66 75 6c 20 69 6e  mainly useful in
3ea0: 20 6f 72 64 65 72 20 74 6f 20 72 65 74 72 6f 66   order to retrof
3eb0: 69 74 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64  it Stored Proced
3ec0: 75 72 65 73 20 73 75 70 70 6f 72 74 20 6f 6e 20  ures support on 
3ed0: 61 6c 72 65 61 64 79 20 65 78 69 73 74 69 6e 67  already existing
3ee0: 20 64 61 74 61 62 61 73 65 73 20 63 72 65 61 74   databases creat
3ef0: 65 20 62 79 20 70 72 65 76 69 6f 75 73 20 76 65  e by previous ve
3f00: 72 73 69 6f 6e 73 2e 0d 0a 43 61 6c 6c 69 6e 67  rsions...Calling
3f10: 20 3c 62 3e 53 74 6f 72 65 64 50 72 6f 63 5f 43   <b>StoredProc_C
3f20: 72 65 61 74 65 54 61 62 6c 65 73 3c 2f 62 3e 20  reateTables</b> 
3f30: 6f 6e 20 62 65 68 61 6c 66 20 6f 66 20 61 20 64  on behalf of a d
3f40: 61 74 61 62 61 73 65 20 61 6c 72 65 61 64 79 20  atabase already 
3f50: 73 75 70 70 6f 72 74 69 6e 67 20 74 68 65 20 53  supporting the S
3f60: 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65 73  tored Procedures
3f70: 20 6d 65 74 61 74 61 62 6c 65 20 69 73 20 61 6e   metatable is an
3f80: 20 68 61 72 6d 6c 65 73 73 20 6f 70 65 72 61 74   harmless operat
3f90: 69 6f 6e 20 73 69 6d 70 6c 79 20 72 65 74 75 72  ion simply retur
3fa0: 6e 69 6e 67 20 3c 62 3e 31 3c 2f 62 3e 20 28 66  ning <b>1</b> (f
3fb0: 75 6c 6c 20 73 75 63 63 65 73 73 29 2e 0d 0a 3c  ull success)...<
3fc0: 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65  /td></tr></table
3fd0: 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53  >..<verbatim>..S
3fe0: 45 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f 63  ELECT StoredProc
3ff0: 5f 52 65 67 69 73 74 65 72 20 28 20 27 73 70 5f  _Register ( 'sp_
4000: 31 27 2c 20 27 61 20 73 61 6d 70 6c 65 20 53 74  1', 'a sample St
4010: 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65 20 66  ored Procedure f
4020: 6f 72 20 74 65 73 74 69 6e 67 27 2c 20 53 71 6c  or testing', Sql
4030: 50 72 6f 63 5f 46 72 6f 6d 54 65 78 74 28 27 53  Proc_FromText('S
4040: 45 4c 45 43 54 20 40 63 6f 6c 40 20 46 52 4f 4d  ELECT @col@ FROM
4050: 20 40 74 62 6c 40 3b 27 20 29 29 3b 0d 0a 2d 2d   @tbl@;' ));..--
4060: 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74  ---..1..</verbat
4070: 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 75 73 65  im>..you can use
4080: 20 3c 62 3e 53 74 6f 72 65 64 50 72 6f 63 5f 52   <b>StoredProc_R
4090: 65 67 69 73 74 65 72 3c 2f 62 3e 20 69 6e 20 6f  egister</b> in o
40a0: 72 64 65 72 20 74 6f 20 70 65 72 6d 61 6e 65 6e  rder to permanen
40b0: 74 6c 79 20 72 65 67 69 73 74 65 72 20 61 20 53  tly register a S
40c0: 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65 2e  tored Procedure.
40d0: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45  ..<verbatim>..SE
40e0: 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f 63 5f  LECT StoredProc_
40f0: 44 65 6c 65 74 65 20 28 20 27 73 70 5f 31 27 20  Delete ( 'sp_1' 
4100: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f  );..-----..1..</
4110: 76 65 72 62 61 74 69 6d 3e 0d 0a 79 6f 75 20 63  verbatim>..you c
4120: 61 6e 20 75 73 65 20 3c 62 3e 53 74 6f 72 65 64  an use <b>Stored
4130: 50 72 6f 63 5f 44 65 6c 65 74 65 3c 2f 62 3e 20  Proc_Delete</b> 
4140: 69 6e 20 6f 72 64 65 72 20 74 6f 20 70 65 72 6d  in order to perm
4150: 61 6e 65 6e 74 6c 79 20 72 65 6d 6f 76 65 20 61  anently remove a
4160: 20 70 72 65 76 69 6f 75 73 6c 79 20 72 65 67 69   previously regi
4170: 73 74 65 72 65 64 20 53 74 6f 72 65 64 20 50 72  stered Stored Pr
4180: 6f 63 65 64 75 72 65 2e 0d 0a 3c 76 65 72 62 61  ocedure...<verba
4190: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 71 6c  tim>..SELECT Sql
41a0: 50 72 6f 63 5f 52 61 77 53 51 4c 20 28 20 53 74  Proc_RawSQL ( St
41b0: 6f 72 65 64 50 72 6f 63 5f 47 65 74 20 28 20 27  oredProc_Get ( '
41c0: 73 70 5f 31 27 20 29 20 29 3b 0d 0a 2d 2d 2d 2d  sp_1' ) );..----
41d0: 2d 0d 0a 53 45 4c 45 43 54 20 40 63 6f 6c 40 20  -..SELECT @col@ 
41e0: 46 52 4f 4d 20 40 74 62 6c 40 3b 0d 0a 3c 2f 76  FROM @tbl@;..</v
41f0: 65 72 62 61 74 69 6d 3e 0d 0a 79 6f 75 20 63 61  erbatim>..you ca
4200: 6e 20 75 73 65 20 3c 62 3e 53 74 6f 72 65 64 50  n use <b>StoredP
4210: 72 6f 63 5f 47 65 74 3c 2f 62 3e 20 69 6e 20 6f  roc_Get</b> in o
4220: 72 64 65 72 20 74 6f 20 72 65 74 72 69 65 76 65  rder to retrieve
4230: 20 74 68 65 20 53 51 4c 20 50 72 6f 63 65 64 75   the SQL Procedu
4240: 72 65 20 42 4c 4f 42 20 4f 62 6a 65 63 74 20 66  re BLOB Object f
4250: 72 6f 6d 20 61 20 72 65 67 69 73 74 65 72 65 64  rom a registered
4260: 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72   Stored Procedur
4270: 65 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  e...<verbatim>..
4280: 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f  SELECT StoredPro
4290: 63 5f 55 70 64 61 74 65 54 69 74 6c 65 20 28 20  c_UpdateTitle ( 
42a0: 27 73 70 5f 31 27 2c 20 27 74 68 69 73 20 54 69  'sp_1', 'this Ti
42b0: 74 6c 65 20 77 61 73 20 63 68 61 6e 67 65 64 27  tle was changed'
42c0: 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c   );..-----..1..<
42d0: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 79 6f 75 20  /verbatim>..you 
42e0: 63 61 6e 20 75 73 65 20 3c 62 3e 53 74 6f 72 65  can use <b>Store
42f0: 64 50 72 6f 63 5f 55 70 64 61 74 65 54 69 74 6c  dProc_UpdateTitl
4300: 65 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74  e</b> in order t
4310: 6f 20 6d 6f 64 69 66 79 20 74 68 65 20 54 69 74  o modify the Tit
4320: 6c 65 20 6f 66 20 61 6e 20 61 6c 72 65 61 64 79  le of an already
4330: 20 72 65 67 69 73 74 65 72 65 64 20 53 74 6f 72   registered Stor
4340: 65 64 20 50 72 6f 63 65 64 75 72 65 2e 0d 0a 3c  ed Procedure...<
4350: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43  verbatim>..SELEC
4360: 54 20 53 74 6f 72 65 64 50 72 6f 63 5f 55 70 64  T StoredProc_Upd
4370: 61 74 65 53 71 6c 42 6f 64 79 20 28 20 27 73 70  ateSqlBody ( 'sp
4380: 5f 31 27 2c 20 53 71 6c 50 72 6f 63 5f 46 72 6f  _1', SqlProc_Fro
4390: 6d 46 69 6c 65 28 27 2f 68 6f 6d 65 2f 6a 6f 65  mFile('/home/joe
43a0: 2f 73 71 6c 5f 73 63 72 69 70 74 73 2f 73 74 6f  /sql_scripts/sto
43b0: 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 5f 76 32  red_proc_test_v2
43c0: 2e 74 78 74 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d  .txt' );..-----.
43d0: 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d  .1..</verbatim>.
43e0: 0a 79 6f 75 20 63 61 6e 20 75 73 65 20 3c 62 3e  .you can use <b>
43f0: 53 74 6f 72 65 64 50 72 6f 63 5f 55 70 64 61 74  StoredProc_Updat
4400: 65 53 71 6c 42 6f 64 79 3c 2f 62 3e 20 69 6e 20  eSqlBody</b> in 
4410: 6f 72 64 65 72 20 74 6f 20 6d 6f 64 69 66 79 20  order to modify 
4420: 74 68 65 20 53 71 6c 20 42 6f 64 79 20 6f 66 20  the Sql Body of 
4430: 61 6e 20 61 6c 72 65 61 64 79 20 72 65 67 69 73  an already regis
4440: 74 65 72 65 64 20 53 74 6f 72 65 64 20 50 72 6f  tered Stored Pro
4450: 63 65 64 75 72 65 20 28 65 2e 67 2e 20 62 65 63  cedure (e.g. bec
4460: 61 75 73 65 20 79 6f 75 27 76 65 20 64 69 73 63  ause you've disc
4470: 6f 76 65 72 65 64 20 61 6e 64 20 66 69 78 65 64  overed and fixed
4480: 20 73 6f 6d 65 20 62 75 67 20 61 66 66 65 63 74   some bug affect
4490: 69 6e 67 20 74 68 65 20 70 72 65 76 69 6f 75 73  ing the previous
44a0: 20 53 51 4c 20 69 6d 70 6c 65 6d 65 6e 74 61 74   SQL implementat
44b0: 69 6f 6e 29 2e 3c 76 65 72 62 61 74 69 6d 3e 0d  ion).<verbatim>.
44c0: 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50 72  .SELECT StoredPr
44d0: 6f 63 5f 45 78 65 63 75 74 65 20 28 20 27 73 70  oc_Execute ( 'sp
44e0: 5f 31 27 2c 0d 0a 20 20 20 20 27 40 63 6f 6c 40  _1',..    '@col@
44f0: 3d 73 72 69 64 27 2c 0d 0a 20 20 20 20 27 40 74  =srid',..    '@t
4500: 62 6c 40 3d 73 70 61 74 69 61 6c 5f 72 65 66 5f  bl@=spatial_ref_
4510: 73 79 73 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a  sys' );..-----..
4520: 31 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a  1..</verbatim>..
4530: 61 6e 64 20 66 69 6e 61 6c 6c 79 20 79 6f 75 20  and finally 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 45 78 65 63 75 74 65 3c 2f 62  dProc_Execute</b
4560: 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 64 69  > in order to di
4570: 72 65 63 74 6c 79 20 65 78 65 63 75 74 65 20 61  rectly execute a
4580: 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72   Stored Procedur
4590: 65 20 61 73 20 61 20 73 69 6e 67 6c 65 20 6d 6f  e as a single mo
45a0: 6e 6f 6c 69 74 68 69 63 20 75 6e 69 74 2e 3c 62  nolithic unit.<b
45b0: 72 3e 0d 0a 3c 62 72 3e 3c 62 72 3e 3c 68 72 3e  r>..<br><br><hr>
45c0: 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c  ..</li>..<li>..<
45d0: 68 34 3e 48 61 6e 64 6c 69 6e 67 20 53 51 4c 20  h4>Handling SQL 
45e0: 53 74 6f 72 65 64 20 56 61 72 69 61 62 6c 65 73  Stored Variables
45f0: 3c 2f 68 34 3e 0d 0a 3c 76 65 72 62 61 74 69 6d  </h4>..<verbatim
4600: 3e 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64  >..SELECT Stored
4610: 56 61 72 5f 52 65 67 69 73 74 65 72 20 28 20 27  Var_Register ( '
4620: 70 69 27 2c 20 27 61 6e 20 75 6e 69 76 65 72 73  pi', 'an univers
4630: 61 6c 6c 79 20 75 73 65 66 75 6c 20 63 6f 6e 73  ally useful cons
4640: 74 61 6e 74 27 2c 20 27 33 2e 31 34 27 20 29 3b  tant', '3.14' );
4650: 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65  ..-----..1..</ve
4660: 72 62 61 74 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e  rbatim>..you can
4670: 20 75 73 65 20 3c 62 3e 53 74 6f 72 65 64 56 61   use <b>StoredVa
4680: 72 5f 52 65 67 69 73 74 65 72 3c 2f 62 3e 20 69  r_Register</b> i
4690: 6e 20 6f 72 64 65 72 20 74 6f 20 70 65 72 6d 61  n order to perma
46a0: 6e 65 6e 74 6c 79 20 72 65 67 69 73 74 65 72 20  nently register 
46b0: 61 20 53 74 6f 72 65 64 20 56 61 72 69 61 62 6c  a Stored Variabl
46c0: 65 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  e...<verbatim>..
46d0: 53 45 4c 45 43 54 20 53 74 6f 72 65 64 56 61 72  SELECT StoredVar
46e0: 5f 44 65 6c 65 74 65 20 28 20 27 70 69 27 20 29  _Delete ( 'pi' )
46f0: 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76  ;..-----..1..</v
4700: 65 72 62 61 74 69 6d 3e 0d 0a 79 6f 75 20 63 61  erbatim>..you ca
4710: 6e 20 75 73 65 20 3c 62 3e 53 74 6f 72 65 64 56  n use <b>StoredV
4720: 61 72 5f 44 65 6c 65 74 65 3c 2f 62 3e 20 69 6e  ar_Delete</b> in
4730: 20 6f 72 64 65 72 20 74 6f 20 70 65 72 6d 61 6e   order to perman
4740: 65 6e 74 6c 79 20 72 65 6d 6f 76 65 20 61 20 70  ently remove a p
4750: 72 65 76 69 6f 75 73 6c 79 20 72 65 67 69 73 74  reviously regist
4760: 65 72 65 64 20 53 74 6f 72 65 64 20 56 61 72 69  ered Stored Vari
4770: 61 62 6c 65 2e 0d 0a 3c 76 65 72 62 61 74 69 6d  able...<verbatim
4780: 3e 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64  >..SELECT Stored
4790: 56 61 72 5f 47 65 74 20 28 20 27 70 69 27 20 29  Var_Get ( 'pi' )
47a0: 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 40 50 49 40 3d 33  ;..-----..@PI@=3
47b0: 2e 31 34 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e  .14..</verbatim>
47c0: 0d 0a 79 6f 75 20 63 61 6e 20 75 73 65 20 3c 62  ..you can use <b
47d0: 3e 53 74 6f 72 65 64 56 61 72 5f 47 65 74 3c 2f  >StoredVar_Get</
47e0: 62 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 72  b> in order to r
47f0: 65 74 72 69 65 76 65 20 74 68 65 20 56 61 72 69  etrieve the Vari
4800: 61 62 6c 65 20 77 69 74 68 20 56 61 6c 75 65 20  able with Value 
4810: 73 74 72 69 6e 67 20 66 72 6f 6d 20 61 20 72 65  string from a re
4820: 67 69 73 74 65 72 65 64 20 53 74 6f 72 65 64 20  gistered Stored 
4830: 56 61 72 69 61 62 6c 65 2e 0d 0a 3c 76 65 72 62  Variable...<verb
4840: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 74  atim>..SELECT St
4850: 6f 72 65 64 56 61 72 5f 55 70 64 61 74 65 54 69  oredVar_UpdateTi
4860: 74 6c 65 20 28 20 27 70 69 27 2c 20 27 50 49 20  tle ( 'pi', 'PI 
4870: 2d 20 74 68 65 20 6d 61 67 69 63 20 6e 75 6d 62  - the magic numb
4880: 65 72 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31  er' );..-----..1
4890: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 79  ..</verbatim>..y
48a0: 6f 75 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 74  ou can use <b>St
48b0: 6f 72 65 64 56 61 72 5f 55 70 64 61 74 65 54 69  oredVar_UpdateTi
48c0: 74 6c 65 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72  tle</b> in order
48d0: 20 74 6f 20 6d 6f 64 69 66 79 20 74 68 65 20 54   to modify the T
48e0: 69 74 6c 65 20 6f 66 20 61 6e 20 61 6c 72 65 61  itle of an alrea
48f0: 64 79 20 72 65 67 69 73 74 65 72 65 64 20 53 74  dy registered St
4900: 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65 2e 0d  ored Procedure..
4910: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c  .<verbatim>..SEL
4920: 45 43 54 20 53 74 6f 72 65 64 56 61 72 5f 55 70  ECT StoredVar_Up
4930: 64 61 74 65 56 61 6c 75 65 20 28 20 27 70 69 27  dateValue ( 'pi'
4940: 2c 20 27 33 2e 31 34 31 35 39 32 36 35 33 35 27  , '3.1415926535'
4950: 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c   );..-----..1..<
4960: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 61 6e 64 20  /verbatim>..and 
4970: 66 69 6e 61 6c 6c 79 20 79 6f 75 20 63 61 6e 20  finally you can 
4980: 75 73 65 20 3c 62 3e 53 74 6f 72 65 64 56 61 72  use <b>StoredVar
4990: 5f 55 70 64 61 74 65 56 61 6c 75 65 3c 2f 62 3e  _UpdateValue</b>
49a0: 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 6d 6f 64   in order to mod
49b0: 69 66 79 20 74 68 65 20 56 61 72 69 61 62 6c 65  ify the Variable
49c0: 20 77 69 74 68 20 56 61 6c 75 65 20 6f 66 20 61   with Value of a
49d0: 6e 20 61 6c 72 65 61 64 79 20 72 65 67 69 73 74  n already regist
49e0: 65 72 65 64 20 53 74 6f 72 65 64 20 56 61 72 69  ered Stored Vari
49f0: 61 62 6c 65 2e 0d 0a 3c 2f 6c 69 3e 3c 62 72 3e  able...</li><br>
4a00: 3c 68 72 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e  <hr>..<li>..<h4>
4a10: 48 61 6e 64 6c 69 6e 67 20 74 68 65 20 53 51 4c  Handling the SQL
4a20: 20 4c 6f 67 66 69 6c 65 3c 2f 68 34 3e 0d 0a 3c   Logfile</h4>..<
4a30: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43  verbatim>..SELEC
4a40: 54 20 53 71 6c 50 72 6f 63 5f 53 65 74 4c 6f 67  T SqlProc_SetLog
4a50: 66 69 6c 65 20 28 20 27 2f 68 6f 6d 65 2f 73 61  file ( '/home/sa
4a60: 6e 64 72 6f 2f 73 71 6c 5f 6c 6f 67 2e 74 78 74  ndro/sql_log.txt
4a70: 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a  ' );..-----..1..
4a80: 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63  ..SELECT SqlProc
4a90: 5f 53 65 74 4c 6f 67 66 69 6c 65 20 28 20 27 2f  _SetLogfile ( '/
4aa0: 68 6f 6d 65 2f 73 61 6e 64 72 6f 2f 73 71 6c 5f  home/sandro/sql_
4ab0: 6c 6f 67 2e 74 78 74 27 2c 20 31 29 3b 0d 0a 2d  log.txt', 1);..-
4ac0: 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a 53 45 4c 45 43  ----..1....SELEC
4ad0: 54 20 53 71 6c 50 72 6f 63 5f 53 65 74 4c 6f 67  T SqlProc_SetLog
4ae0: 66 69 6c 65 20 28 20 4e 55 4c 4c 20 29 3b 0d 0a  file ( NULL );..
4af0: 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62  -----..1..</verb
4b00: 61 74 69 6d 3e 0d 0a 59 6f 75 20 63 61 6e 20 75  atim>..You can u
4b10: 73 65 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 53 65  se <b>SqlProc_Se
4b20: 74 4c 6f 67 66 69 6c 65 28 29 3c 2f 62 3e 20 69  tLogfile()</b> i
4b30: 6e 20 6f 72 64 65 72 20 74 6f 20 65 6e 61 62 6c  n order to enabl
4b40: 65 20 6f 72 20 64 69 73 61 62 6c 65 20 74 68 65  e or disable the
4b50: 20 53 51 4c 20 4c 6f 67 66 69 6c 65 3a 0d 0a 3c   SQL Logfile:..<
4b60: 75 6c 3e 0d 0a 3c 6c 69 3e 74 68 65 20 66 69 72  ul>..<li>the fir
4b70: 73 74 20 66 6f 72 6d 20 28 73 69 6e 67 6c 65 20  st form (single 
4b80: 61 72 67 75 6d 65 6e 74 29 20 6a 75 73 74 20 72  argument) just r
4b90: 65 71 75 69 72 65 73 20 74 6f 20 64 65 66 69 6e  equires to defin
4ba0: 65 20 74 68 65 20 3c 62 3e 61 62 73 6f 6c 75 74  e the <b>absolut
4bb0: 65 3c 2f 62 3e 20 6f 72 20 3c 62 3e 72 65 6c 61  e</b> or <b>rela
4bc0: 74 69 76 65 20 70 61 74 68 6e 61 6d 65 3c 2f 62  tive pathname</b
4bd0: 3e 20 6f 66 20 74 68 65 20 69 6e 74 65 6e 64 65  > of the intende
4be0: 64 20 4c 6f 67 66 69 6c 65 2e 3c 62 72 3e 0d 0a  d Logfile.<br>..
4bf0: 41 20 4c 6f 67 66 69 6c 65 20 64 65 66 69 6e 65  A Logfile define
4c00: 64 20 69 6e 20 73 75 63 68 20 61 20 77 61 79 20  d in such a way 
4c10: 77 69 6c 6c 20 62 65 20 61 6c 77 61 79 73 20 6f  will be always o
4c20: 70 65 72 61 74 65 20 69 6e 20 3c 62 3e 54 72 75  perate in <b>Tru
4c30: 6e 63 61 74 65 3c 2f 62 3e 20 6d 6f 64 65 2e 3c  ncate</b> mode.<
4c40: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 74 68 65 20 73 65  /li>..<li>the se
4c50: 63 6f 6e 64 20 66 6f 72 6d 20 28 74 77 6f 20 61  cond form (two a
4c60: 72 67 75 6d 65 6e 74 73 29 20 73 75 70 70 6f 72  rguments) suppor
4c70: 74 73 20 61 20 66 75 72 74 68 65 72 20 3c 62 3e  ts a further <b>
4c80: 6d 6f 64 65 3c 2f 62 3e 20 61 72 67 75 6d 65 6e  mode</b> argumen
4c90: 74 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 69 66  t:..<ul>..<li>if
4ca0: 20 73 65 74 20 74 6f 20 3c 62 3e 46 41 4c 53 45   set to <b>FALSE
4cb0: 3c 2f 62 3e 20 28 3c 62 3e 30 3c 2f 62 3e 2c 20  </b> (<b>0</b>, 
4cc0: 64 65 66 61 75 6c 74 20 76 61 6c 75 65 29 20 74  default value) t
4cd0: 68 65 20 4c 6f 67 66 69 6c 65 20 77 69 6c 6c 20  he Logfile will 
4ce0: 6f 70 65 72 61 74 65 20 69 6e 20 3c 62 3e 54 72  operate in <b>Tr
4cf0: 75 6e 63 61 74 65 3c 2f 62 3e 20 6d 6f 64 65 2e  uncate</b> mode.
4d00: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 69 66 20 73 65  </li>..<li>if se
4d10: 74 20 74 6f 20 3c 62 3e 54 52 55 45 3c 2f 62 3e  t to <b>TRUE</b>
4d20: 20 28 61 6e 79 20 6f 74 68 65 72 20 76 61 6c 75   (any other valu
4d30: 65 20 64 69 66 66 65 72 65 6e 74 20 66 72 6f 6d  e different from
4d40: 20 3c 62 3e 30 3c 2f 62 3e 29 20 74 68 65 20 4c   <b>0</b>) the L
4d50: 6f 67 66 69 6c 65 20 77 69 6c 6c 20 6f 70 65 72  ogfile will oper
4d60: 61 74 65 20 69 6e 20 3c 62 3e 41 70 70 65 6e 64  ate in <b>Append
4d70: 3c 2f 62 3e 20 6d 6f 64 65 2e 3c 2f 6c 69 3e 0d  </b> mode.</li>.
4d80: 0a 3c 2f 75 6c 3e 0d 0a 3c 6c 69 3e 66 69 6e 61  .</ul>..<li>fina
4d90: 6c 6c 79 2c 20 79 6f 75 20 63 61 6e 20 70 61 73  lly, you can pas
4da0: 73 20 61 20 3c 62 3e 4e 55 4c 4c 3c 2f 62 3e 20  s a <b>NULL</b> 
4db0: 70 61 74 68 20 61 72 67 75 6d 65 6e 74 20 69 6e  path argument in
4dc0: 20 6f 72 64 65 72 20 74 6f 20 69 6d 6d 65 64 69   order to immedi
4dd0: 61 74 65 6c 79 20 64 69 73 61 62 6c 65 20 74 68  ately disable th
4de0: 65 20 4c 6f 67 66 69 6c 65 2e 3c 2f 6c 69 3e 0d  e Logfile.</li>.
4df0: 0a 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c  .</li>..</ul>..<
4e00: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43  verbatim>..SELEC
4e10: 54 20 53 71 6c 50 72 6f 63 5f 47 65 74 4c 6f 67  T SqlProc_GetLog
4e20: 66 69 6c 65 28 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a  file();..-----..
4e30: 2f 68 6f 6d 65 2f 73 61 6e 64 72 6f 2f 73 71 6c  /home/sandro/sql
4e40: 5f 6c 6f 67 2e 74 78 74 0d 0a 0d 0a 53 45 4c 45  _log.txt....SELE
4e50: 43 54 20 53 71 6c 50 72 6f 63 5f 47 65 74 4c 6f  CT SqlProc_GetLo
4e60: 67 66 69 6c 65 28 29 3b 0d 0a 2d 2d 2d 2d 2d 0d  gfile();..-----.
4e70: 0a 4e 55 4c 4c 0d 0a 3c 2f 76 65 72 62 61 74 69  .NULL..</verbati
4e80: 6d 3e 0d 0a 59 6f 75 20 63 61 6e 20 75 73 65 20  m>..You can use 
4e90: 3c 62 3e 53 71 6c 50 72 6f 63 5f 47 65 74 4c 6f  <b>SqlProc_GetLo
4ea0: 67 66 69 6c 65 28 29 3c 2f 62 3e 20 69 6e 20 6f  gfile()</b> in o
4eb0: 72 64 65 72 20 74 6f 20 63 68 65 63 6b 20 69 66  rder to check if
4ec0: 20 74 68 65 20 63 75 72 72 65 6e 74 20 44 42 2d   the current DB-
4ed0: 63 6f 6e 6e 65 63 74 69 6f 6e 20 69 73 20 73 75  connection is su
4ee0: 70 70 6f 72 74 65 64 20 62 79 20 73 6f 6d 65 20  pported by some 
4ef0: 4c 6f 67 66 69 6c 65 20 6f 72 20 6e 6f 74 2e 3c  Logfile or not.<
4f00: 62 72 3e 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65 20  br><br>..<table 
4f10: 62 67 63 6f 6c 6f 72 3d 22 23 66 38 66 38 64 38  bgcolor="#f8f8d8
4f20: 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 36  " cellpadding="6
4f30: 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 38  " cellspacing="8
4f40: 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 3c 75 3e 4e  "><tr><td>..<u>N
4f50: 6f 74 65 3c 2f 75 3e 3a 20 74 68 65 20 4c 6f 67  ote</u>: the Log
4f60: 66 69 6c 65 20 73 65 74 74 69 6e 67 20 69 73 20  file setting is 
4f70: 70 65 72 6d 61 6e 65 6e 74 20 6f 6e 20 61 20 70  permanent on a p
4f80: 65 72 2d 63 6f 6e 6e 65 63 74 69 6f 6e 20 62 61  er-connection ba
4f90: 73 69 73 2e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e  sis...<ul>..<li>
4fa0: 61 6e 79 20 6e 65 77 20 44 42 2d 63 6f 6e 6e 65  any new DB-conne
4fb0: 63 74 69 6f 6e 20 77 69 6c 6c 20 61 6c 77 61 79  ction will alway
4fc0: 73 20 73 74 61 72 74 20 62 79 20 6b 65 65 70 69  s start by keepi
4fd0: 6e 67 20 74 68 65 20 4c 6f 67 66 69 6c 65 20 64  ng the Logfile d
4fe0: 69 73 61 62 6c 65 64 2e 3c 62 72 3e 0d 0a 59 6f  isabled.<br>..Yo
4ff0: 75 20 61 72 65 20 61 6c 77 61 79 73 20 72 65 71  u are always req
5000: 75 69 72 65 64 20 74 6f 20 70 65 72 66 6f 72 6d  uired to perform
5010: 20 61 6e 20 65 78 70 6c 69 63 69 74 20 63 61 6c   an explicit cal
5020: 6c 20 74 6f 20 3c 62 3e 53 71 6c 50 72 6f 63 5f  l to <b>SqlProc_
5030: 53 65 74 4c 6f 67 66 69 6c 65 28 29 3c 2f 62 3e  SetLogfile()</b>
5040: 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 65 66 66   in order to eff
5050: 65 63 74 69 76 65 6c 79 20 65 6e 61 62 6c 65 20  ectively enable 
5060: 61 20 4c 6f 67 66 69 6c 65 2e 3c 2f 6c 69 3e 0d  a Logfile.</li>.
5070: 0a 3c 6c 69 3e 6f 6e 63 65 20 61 20 4c 6f 67 66  .<li>once a Logf
5080: 69 6c 65 20 68 61 73 20 62 65 65 6e 20 65 6e 61  ile has been ena
5090: 62 6c 65 64 20 69 74 20 77 69 6c 6c 20 63 6f 6e  bled it will con
50a0: 74 69 6e 75 65 20 74 6f 20 73 75 70 70 6f 72 74  tinue to support
50b0: 20 74 68 65 20 63 75 72 72 65 6e 74 20 44 42 2d   the current DB-
50c0: 63 6f 6e 6e 65 63 74 69 6f 6e 20 64 75 72 69 6e  connection durin
50d0: 67 20 61 6c 6c 20 69 74 73 20 6c 69 66 65 73 70  g all its lifesp
50e0: 61 6e 2c 20 69 66 20 6e 6f 74 20 65 78 70 6c 69  an, if not expli
50f0: 63 69 74 6c 79 20 64 69 73 61 62 6c 65 64 20 69  citly disabled i
5100: 6e 20 74 68 65 20 61 66 74 65 72 20 77 68 69 6c  n the after whil
5110: 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 4c 6f 67  e.</li>..<li>Log
5120: 66 69 6c 65 20 73 65 74 74 69 6e 67 73 20 61 72  file settings ar
5130: 65 20 73 74 72 69 63 74 6c 79 20 63 6f 6e 66 69  e strictly confi
5140: 6e 65 64 20 77 69 74 68 69 6e 67 20 74 68 65 20  ned withing the 
5150: 63 75 72 72 65 6e 74 20 44 42 2d 63 6f 6e 6e 65  current DB-conne
5160: 63 74 69 6f 6e 2c 20 61 6e 64 20 77 69 6c 6c 20  ction, and will 
5170: 6e 65 76 65 72 20 70 72 6f 70 61 67 61 74 65 20  never propagate 
5180: 62 65 74 77 65 65 6e 20 66 6f 6c 6c 6f 77 69 6e  between followin
5190: 67 20 73 65 73 73 69 6f 6e 73 2e 3c 2f 6c 69 3e  g sessions.</li>
51a0: 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 2f 74 64 3e 3c 2f  ..</ul>..</td></
51b0: 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 2f 6c  tr></table>..</l
51c0: 69 3e 0d 0a 3c 2f 6f 6c 3e 0d 0a 3c 62 72 3e 3c  i>..</ol>..<br><
51d0: 68 72 3e 0d 0a 3c 68 32 3e 54 75 74 6f 72 69 61  hr>..<h2>Tutoria
51e0: 6c 20 23 31 3c 2f 68 32 3e 0d 0a 3c 74 61 62 6c  l #1</h2>..<tabl
51f0: 65 20 62 67 63 6f 6c 6f 72 3d 22 23 66 38 66 38  e bgcolor="#f8f8
5200: 64 38 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d  d8" cellpadding=
5210: 22 36 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d  "6" cellspacing=
5220: 22 38 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 41 6c  "8"><tr><td>..Al
5230: 6c 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20  l the following 
5240: 74 75 74 6f 72 69 61 6c 73 20 61 72 65 20 62 61  tutorials are ba
5250: 73 65 64 20 6f 6e 20 74 68 65 20 73 61 6d 65 20  sed on the same 
5260: 73 61 6d 70 6c 65 20 64 61 74 61 62 61 73 65 3a  sample database:
5270: 20 70 6c 65 61 73 65 20 3c 61 20 68 72 65 66 3d   please <a href=
5280: 22 68 74 74 70 3a 2f 2f 77 77 77 2e 67 61 69 61  "http://www.gaia
5290: 2d 67 69 73 2e 69 74 2f 67 61 69 61 2d 73 69 6e  -gis.it/gaia-sin
52a0: 73 2f 73 70 5f 73 61 6d 70 6c 65 5f 64 62 2e 37  s/sp_sample_db.7
52b0: 7a 22 3e 64 6f 77 6e 6c 6f 61 64 20 69 74 3c 2f  z">download it</
52c0: 61 3e 20 62 65 66 6f 72 65 20 67 6f 69 6e 67 20  a> before going 
52d0: 66 75 72 74 68 65 72 20 61 77 61 79 2e 0d 0a 3c  further away...<
52e0: 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65  /td></tr></table
52f0: 3e 3c 62 72 3e 0d 0a 41 73 20 79 6f 75 20 63 61  ><br>..As you ca
5300: 6e 20 65 61 73 69 6c 79 20 63 68 65 63 6b 20 74  n easily check t
5310: 68 69 73 20 64 61 74 61 62 61 73 65 20 63 6f 6e  his database con
5320: 74 61 69 6e 73 20 74 68 72 65 65 20 53 70 61 74  tains three Spat
5330: 69 61 6c 20 54 61 62 6c 65 73 20 72 65 70 72 65  ial Tables repre
5340: 73 65 6e 74 69 6e 67 20 74 68 65 20 3c 62 3e 3c  senting the <b><
5350: 69 3e 41 64 6d 69 6e 69 73 74 72 61 74 69 76 65  i>Administrative
5360: 20 42 6f 75 6e 64 61 72 69 65 73 3c 2f 69 3e 3c   Boundaries</i><
5370: 2f 62 3e 20 6f 66 20 61 6c 6c 20 49 74 61 6c 69  /b> of all Itali
5380: 61 6e 20 4d 75 6e 69 63 69 70 61 6c 69 74 69 65  an Municipalitie
5390: 73 20 61 73 20 6f 66 66 69 63 69 61 6c 6c 79 20  s as officially 
53a0: 64 65 74 65 72 6d 69 6e 65 64 20 62 79 20 3c 61  determined by <a
53b0: 20 68 72 65 66 3d 22 68 74 74 70 73 3a 2f 2f 65   href="https://e
53c0: 6e 2e 77 69 6b 69 70 65 64 69 61 2e 6f 72 67 2f  n.wikipedia.org/
53d0: 77 69 6b 69 2f 4e 61 74 69 6f 6e 61 6c 5f 49 6e  wiki/National_In
53e0: 73 74 69 74 75 74 65 5f 6f 66 5f 53 74 61 74 69  stitute_of_Stati
53f0: 73 74 69 63 73 5f 28 49 74 61 6c 79 29 22 3e 49  stics_(Italy)">I
5400: 53 54 41 54 3c 2f 61 3e 3a 0d 0a 3c 75 6c 3e 0d  STAT</a>:..<ul>.
5410: 0a 3c 6c 69 3e 74 68 65 72 65 20 61 72 65 20 74  .<li>there are t
5420: 68 72 65 65 20 64 69 66 66 65 72 65 6e 74 20 74  hree different t
5430: 61 62 6c 65 73 2c 20 65 61 63 68 20 6f 6e 65 20  ables, each one 
5440: 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 74 6f  corresponding to
5450: 20 61 20 73 70 65 63 69 66 69 63 20 4e 61 74 69   a specific Nati
5460: 6f 6e 61 6c 20 43 65 6e 73 75 73 20 28 79 65 61  onal Census (yea
5470: 72 73 20 31 39 39 31 2c 20 32 30 30 31 20 61 6e  rs 1991, 2001 an
5480: 64 20 32 30 31 31 20 61 72 65 20 61 76 61 69 6c  d 2011 are avail
5490: 61 62 6c 65 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  able).</li>..<li
54a0: 3e 61 6c 6c 20 74 68 72 65 65 20 74 61 62 6c 65  >all three table
54b0: 73 20 68 61 76 65 20 65 78 61 63 74 6c 79 20 74  s have exactly t
54c0: 68 65 20 73 61 6d 65 20 6c 61 79 6f 75 74 2e 3c  he same layout.<
54d0: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 41 64 6d 69 6e 69  /li>..<li>Admini
54e0: 73 74 72 61 74 69 76 65 20 42 6f 75 6e 64 61 72  strative Boundar
54f0: 69 65 73 20 61 72 65 20 61 6c 77 61 79 73 20 72  ies are always r
5500: 65 70 72 65 73 65 6e 74 65 64 20 61 73 20 4d 75  epresented as Mu
5510: 6c 74 69 50 6f 6c 79 67 6f 6e 73 20 28 53 72 69  ltiPolygons (Sri
5520: 64 3d 33 32 36 33 32 29 2e 0d 0a 3c 2f 75 6c 3e  d=32632)...</ul>
5530: 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65 20 62 67 63  <br>..<table bgc
5540: 6f 6c 6f 72 3d 22 23 66 38 66 38 64 38 22 20 63  olor="#f8f8d8" c
5550: 65 6c 6c 70 61 64 64 69 6e 67 3d 22 36 22 20 63  ellpadding="6" c
5560: 65 6c 6c 73 70 61 63 69 6e 67 3d 22 38 22 3e 3c  ellspacing="8"><
5570: 74 72 3e 3c 74 64 3e 0d 0a 3c 68 34 3e 54 68 65  tr><td>..<h4>The
5580: 20 50 72 6f 62 6c 65 6d 3c 2f 68 34 3e 0d 0a 57   Problem</h4>..W
5590: 65 27 6c 6c 20 67 6f 20 74 6f 20 69 6d 70 6c 65  e'll go to imple
55a0: 6d 65 6e 74 20 61 20 3c 62 3e 50 72 6f 63 65 64  ment a <b>Proced
55b0: 75 72 65 3c 2f 62 3e 20 69 6e 74 65 6e 64 65 64  ure</b> intended
55c0: 20 74 6f 20 65 78 70 6f 72 74 20 73 65 6c 65 63   to export selec
55d0: 74 65 64 20 53 68 61 70 65 66 69 6c 65 73 2e 0d  ted Shapefiles..
55e0: 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 54 68 65 20 43  .<ul>..<li>The C
55f0: 65 6e 73 75 73 20 59 65 61 72 20 6d 75 73 74 20  ensus Year must 
5600: 62 65 20 66 72 65 65 6c 79 20 73 65 6c 65 63 74  be freely select
5610: 61 62 6c 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e  able.</li>..<li>
5620: 41 20 72 65 71 75 69 72 65 64 20 66 65 61 74 75  A required featu
5630: 72 65 20 69 73 20 61 6c 6c 6f 77 69 6e 67 20 66  re is allowing f
5640: 6f 72 20 66 72 65 65 6c 79 20 66 69 6c 74 65 72  or freely filter
5650: 69 6e 67 20 61 20 73 69 6e 67 6c 65 20 4d 75 6e  ing a single Mun
5660: 69 63 69 70 61 6c 69 74 79 20 6f 72 20 61 6c 6c  icipality or all
5670: 20 4d 75 6e 69 63 69 70 61 6c 69 74 69 65 73 20   Municipalities 
5680: 62 65 6c 6f 6e 67 69 6e 67 20 74 6f 20 74 68 65  belonging to the
5690: 20 73 61 6d 65 20 50 72 6f 76 69 6e 63 65 20 6f   same Province o
56a0: 72 20 52 65 67 69 6f 6e 2e 3c 2f 6c 69 3e 0d 0a  r Region.</li>..
56b0: 3c 6c 69 3e 52 65 70 72 6f 6a 65 63 74 69 6e 67  <li>Reprojecting
56c0: 20 74 6f 20 73 6f 6d 65 20 61 6c 74 65 72 6e 61   to some alterna
56d0: 74 69 76 65 20 53 52 49 44 20 73 68 6f 75 6c 64  tive SRID should
56e0: 20 62 65 20 61 20 73 75 70 70 6f 72 74 65 64 20   be a supported 
56f0: 66 65 61 74 75 72 65 2e 3c 2f 6c 69 3e 0d 0a 3c  feature.</li>..<
5700: 6c 69 3e 57 68 69 6c 65 20 64 6f 69 6e 67 20 61  li>While doing a
5710: 6c 6c 20 74 68 69 73 20 77 65 27 6c 6c 20 6f 62  ll this we'll ob
5720: 76 69 6f 75 73 6c 79 20 74 72 79 20 74 6f 20 74  viously try to t
5730: 61 6b 65 20 66 75 6c 6c 20 61 64 76 61 6e 74 61  ake full advanta
5740: 67 65 20 66 72 6f 6d 20 75 73 69 6e 67 20 3c 62  ge from using <b
5750: 3e 56 61 72 69 61 62 6c 65 73 3c 2f 62 3e 20 73  >Variables</b> s
5760: 6f 20 74 6f 20 6d 61 6b 65 20 74 68 65 20 50 72  o to make the Pr
5770: 6f 63 65 64 75 72 65 20 61 73 20 67 65 6e 65 72  ocedure as gener
5780: 69 63 20 61 6e 64 20 66 6c 65 78 69 62 6c 65 20  ic and flexible 
5790: 61 73 20 70 6f 73 73 69 62 6c 65 2e 3c 2f 6c 69  as possible.</li
57a0: 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 2f 74 64 3e 3c  >..</ul>..</td><
57b0: 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 3c 62 72 3e  /tr></table><br>
57c0: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 2d 2d  ..<verbatim>..--
57d0: 0d 0a 2d 2d 20 72 65 6d 6f 76 69 6e 67 20 74 68  ..-- removing th
57e0: 65 20 77 6f 72 6b 20 74 61 62 6c 65 20 28 6a 75  e work table (ju
57f0: 73 74 20 69 6e 20 63 61 73 65 20 69 74 20 61 6c  st in case it al
5800: 72 65 61 64 79 20 65 78 69 73 74 73 29 0d 0a 2d  ready exists)..-
5810: 2d 0d 0a 53 45 4c 45 43 54 20 44 72 6f 70 47 65  -..SELECT DropGe
5820: 6f 54 61 62 6c 65 28 27 74 72 61 6e 73 69 65 6e  oTable('transien
5830: 74 5f 74 61 62 6c 65 27 29 3b 0d 0a 0d 0a 2d 2d  t_table');....--
5840: 0d 0a 2d 2d 20 69 6e 73 65 72 74 69 6e 67 20 73  ..-- inserting s
5850: 65 6c 65 63 74 65 64 20 64 61 74 61 20 69 6e 74  elected data int
5860: 6f 20 74 68 65 20 77 6f 72 6b 20 74 61 62 6c 65  o the work table
5870: 0d 0a 2d 2d 0d 0a 43 52 45 41 54 45 20 54 41 42  ..--..CREATE TAB
5880: 4c 45 20 74 72 61 6e 73 69 65 6e 74 5f 74 61 62  LE transient_tab
5890: 6c 65 20 41 53 0d 0a 53 45 4c 45 43 54 20 69 64  le AS..SELECT id
58a0: 2c 20 69 73 74 61 74 2c 20 6e 61 6d 65 2c 20 70  , istat, name, p
58b0: 72 6f 76 69 6e 63 65 2c 20 72 65 67 69 6f 6e 2c  rovince, region,
58c0: 20 53 54 5f 54 72 61 6e 73 66 6f 72 6d 28 67 65   ST_Transform(ge
58d0: 6f 6d 2c 20 40 73 72 69 64 40 29 20 41 53 20 67  om, @srid@) AS g
58e0: 65 6f 6d 0d 0a 46 52 4f 4d 20 6d 75 6e 69 63 69  eom..FROM munici
58f0: 70 61 6c 69 74 69 65 73 5f 40 79 65 61 72 40 0d  palities_@year@.
5900: 0a 57 48 45 52 45 20 28 55 70 70 65 72 28 6e 61  .WHERE (Upper(na
5910: 6d 65 29 20 3d 20 55 70 70 65 72 28 27 40 6d 75  me) = Upper('@mu
5920: 6e 69 63 69 70 61 6c 69 74 79 40 27 29 20 4f 52  nicipality@') OR
5930: 20 55 70 70 65 72 28 70 72 6f 76 69 6e 63 65 29   Upper(province)
5940: 20 3d 20 55 70 70 65 72 28 27 40 70 72 6f 76 69   = Upper('@provi
5950: 6e 63 65 40 27 29 20 4f 52 20 55 70 70 65 72 28  nce@') OR Upper(
5960: 72 65 67 69 6f 6e 29 20 3d 20 55 70 70 65 72 28  region) = Upper(
5970: 27 40 72 65 67 69 6f 6e 40 27 29 29 3b 0d 0a 0d  '@region@'));...
5980: 0a 2d 2d 0d 0a 2d 2d 20 70 72 6f 70 65 72 6c 79  .--..-- properly
5990: 20 72 65 63 6f 76 65 72 69 6e 67 20 74 68 65 20   recovering the 
59a0: 77 6f 72 6b 20 74 61 62 6c 65 0d 0a 2d 2d 0d 0a  work table..--..
59b0: 53 45 4c 45 43 54 20 52 65 63 6f 76 65 72 47 65  SELECT RecoverGe
59c0: 6f 6d 65 74 72 79 43 6f 6c 75 6d 6e 28 27 74 72  ometryColumn('tr
59d0: 61 6e 73 69 65 6e 74 5f 74 61 62 6c 65 27 2c 20  ansient_table', 
59e0: 27 67 65 6f 6d 27 2c 20 40 73 72 69 64 40 2c 20  'geom', @srid@, 
59f0: 27 4d 55 4c 54 49 50 4f 4c 59 47 4f 4e 27 2c 20  'MULTIPOLYGON', 
5a00: 27 58 59 27 29 3b 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d  'XY');....--..--
5a10: 20 65 78 70 6f 72 74 69 6e 67 20 66 72 6f 6d 20   exporting from 
5a20: 74 68 65 20 77 6f 72 6b 20 74 61 62 6c 65 20 69  the work table i
5a30: 6e 74 6f 20 74 68 65 20 53 68 61 70 65 66 69 6c  nto the Shapefil
5a40: 65 0d 0a 2d 2d 0d 0a 53 45 4c 45 43 54 20 45 78  e..--..SELECT Ex
5a50: 70 6f 72 74 53 68 70 28 27 74 72 61 6e 73 69 65  portShp('transie
5a60: 6e 74 5f 74 61 62 6c 65 27 2c 20 27 67 65 6f 6d  nt_table', 'geom
5a70: 27 2c 20 27 40 73 68 70 5f 70 61 74 68 40 27 2c  ', '@shp_path@',
5a80: 20 27 43 50 31 32 35 32 27 29 3b 0d 0a 0d 0a 2d   'CP1252');....-
5a90: 2d 0d 0a 2d 2d 20 72 65 6d 6f 76 69 6e 67 20 74  -..-- removing t
5aa0: 68 65 20 77 6f 72 6b 20 74 61 62 6c 65 0d 0a 2d  he work table..-
5ab0: 2d 0d 0a 53 45 4c 45 43 54 20 44 72 6f 70 47 65  -..SELECT DropGe
5ac0: 6f 54 61 62 6c 65 28 27 74 72 61 6e 73 69 65 6e  oTable('transien
5ad0: 74 5f 74 61 62 6c 65 27 29 3b 0d 0a 3c 2f 76 65  t_table');..</ve
5ae0: 72 62 61 74 69 6d 3e 0d 0a 41 73 20 79 6f 75 20  rbatim>..As you 
5af0: 63 61 6e 20 73 65 65 20 74 68 65 20 70 72 6f 70  can see the prop
5b00: 6f 73 65 64 20 69 6d 70 6c 65 6d 65 6e 74 61 74  osed implementat
5b10: 69 6f 6e 20 69 73 20 62 61 73 69 63 61 6c 6c 79  ion is basically
5b20: 20 73 69 6d 70 6c 65 2e 20 4e 6f 77 20 79 6f 75   simple. Now you
5b30: 20 73 69 6d 70 6c 79 20 68 61 76 65 20 74 6f 20   simply have to 
5b40: 3c 62 3e 63 75 74 26 70 61 73 74 65 3c 2f 62 3e  <b>cut&paste</b>
5b50: 20 74 68 65 20 61 62 6f 76 65 20 53 51 4c 20 62   the above SQL b
5b60: 6f 64 79 20 73 61 76 69 6e 67 20 69 74 20 69 6e  ody saving it in
5b70: 74 6f 20 61 20 66 69 6c 65 20 6e 61 6d 65 64 20  to a file named 
5b80: 3c 62 3e 74 65 73 74 5f 73 70 2e 74 78 74 3c 2f  <b>test_sp.txt</
5b90: 62 3e 20 66 6f 72 20 66 75 72 74 68 65 72 20 75  b> for further u
5ba0: 73 61 67 65 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 46  sage.<br><br>..F
5bb0: 65 77 20 69 6e 74 65 72 65 73 74 69 6e 67 20 64  ew interesting d
5bc0: 65 74 61 69 6c 73 20 77 6f 72 74 68 20 74 6f 20  etails worth to 
5bd0: 62 65 20 65 78 70 6c 61 69 6e 65 64 3a 0d 0a 3c  be explained:..<
5be0: 75 6c 3e 0d 0a 3c 6c 69 3e 56 61 72 69 61 62 6c  ul>..<li>Variabl
5bf0: 65 20 3c 62 3e 40 79 65 61 72 40 3c 2f 62 3e 20  e <b>@year@</b> 
5c00: 69 73 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 73  is intended to s
5c10: 65 6c 65 63 74 20 77 68 69 63 68 20 73 70 65 63  elect which spec
5c20: 69 66 69 63 20 53 70 61 74 69 61 6c 20 54 61 62  ific Spatial Tab
5c30: 6c 65 20 77 69 6c 6c 20 62 65 20 71 75 65 72 69  le will be queri
5c40: 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 56 61  ed.</li>..<li>Va
5c50: 72 69 61 62 6c 65 20 3c 62 3e 40 73 72 69 64 40  riable <b>@srid@
5c60: 3c 2f 62 3e 20 69 73 20 69 6e 74 65 6e 64 65 64  </b> is intended
5c70: 20 74 6f 20 73 70 65 63 69 66 79 20 74 68 65 20   to specify the 
5c80: 6f 75 74 70 75 74 20 53 52 49 44 2e 3c 2f 6c 69  output SRID.</li
5c90: 3e 0d 0a 3c 6c 69 3e 56 61 72 69 61 62 6c 65 20  >..<li>Variable 
5ca0: 3c 62 3e 40 73 68 70 5f 70 61 74 68 40 3c 2f 62  <b>@shp_path@</b
5cb0: 3e 20 69 73 20 69 6e 74 65 6e 64 65 64 20 74 6f  > is intended to
5cc0: 20 73 70 65 63 69 66 79 20 74 68 65 20 70 61 74   specify the pat
5cd0: 68 6e 61 6d 65 20 6f 66 20 74 68 65 20 6f 75 74  hname of the out
5ce0: 70 75 74 20 53 68 61 70 65 66 69 6c 65 2e 3c 2f  put Shapefile.</
5cf0: 6c 69 3e 0d 0a 3c 6c 69 3e 56 61 72 69 61 62 6c  li>..<li>Variabl
5d00: 65 73 20 3c 62 3e 40 6d 75 6e 69 63 69 70 61 6c  es <b>@municipal
5d10: 69 74 79 40 3c 2f 62 3e 2c 20 3c 62 3e 40 70 72  ity@</b>, <b>@pr
5d20: 6f 76 69 6e 63 65 40 3c 2f 62 3e 20 61 6e 64 20  ovince@</b> and 
5d30: 3c 62 3e 40 72 65 67 69 6f 6e 40 3c 2f 62 3e 20  <b>@region@</b> 
5d40: 61 72 65 20 69 6e 74 65 6e 64 65 64 20 74 6f 20  are intended to 
5d50: 73 70 65 63 69 66 79 20 74 68 65 20 69 6e 74 65  specify the inte
5d60: 6e 64 65 64 20 66 69 6c 74 65 72 69 6e 67 20 63  nded filtering c
5d70: 72 69 74 65 72 69 61 2e 3c 62 72 3e 0d 0a 54 68  riteria.<br>..Th
5d80: 69 73 20 69 73 20 61 20 6c 69 74 74 6c 65 20 62  is is a little b
5d90: 69 74 20 74 72 69 63 6b 79 2c 20 73 6f 20 77 65  it tricky, so we
5da0: 27 6c 6c 20 67 6f 20 69 6e 20 66 75 72 74 68 65  'll go in furthe
5db0: 72 20 64 65 70 74 68 3a 0d 0a 3c 75 6c 3e 0d 0a  r depth:..<ul>..
5dc0: 3c 6c 69 3e 54 68 65 73 65 20 56 61 72 69 61 62  <li>These Variab
5dd0: 6c 65 73 20 61 72 65 20 65 78 70 65 63 74 65 64  les are expected
5de0: 20 74 6f 20 62 65 20 61 63 74 75 61 6c 6c 79 20   to be actually 
5df0: 72 65 70 6c 61 63 65 64 20 62 79 20 3c 62 3e 74  replaced by <b>t
5e00: 65 78 74 20 73 74 72 69 6e 67 20 76 61 6c 75 65  ext string value
5e10: 73 3c 2f 62 3e 3b 20 73 6f 20 77 65 27 76 65 20  s</b>; so we've 
5e20: 63 6f 6e 73 69 73 74 65 6e 74 6c 79 20 3c 62 3e  consistently <b>
5e30: 73 69 6e 67 6c 65 2d 71 75 6f 74 65 64 3c 2f 62  single-quoted</b
5e40: 3e 20 74 68 65 20 76 61 72 69 61 62 6c 65 20 73  > the variable s
5e50: 79 6d 62 6f 6c 2c 20 73 6f 20 74 6f 20 61 6c 6c  ymbol, so to all
5e60: 6f 77 20 66 6f 72 20 61 6e 20 65 61 73 69 65 72  ow for an easier
5e70: 20 76 61 6c 75 65 20 72 65 70 6c 61 63 65 6d 65   value replaceme
5e80: 6e 74 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 57 65  nt.</li>..<li>We
5e90: 20 61 72 65 20 73 79 73 74 65 6d 61 74 69 63 61   are systematica
5ea0: 6c 6c 79 20 75 73 69 6e 67 20 74 68 65 20 3c 62  lly using the <b
5eb0: 3e 55 70 70 65 72 28 29 3c 2f 62 3e 20 66 75 6e  >Upper()</b> fun
5ec0: 63 74 69 6f 6e 20 73 69 6d 70 6c 79 20 62 65 63  ction simply bec
5ed0: 61 75 73 65 20 50 72 6f 76 69 6e 63 65 20 61 6e  ause Province an
5ee0: 64 20 52 65 67 69 6f 6e 20 6e 61 6d 65 20 61 72  d Region name ar
5ef0: 65 20 61 6c 6c 2d 75 70 70 65 72 63 61 73 65 20  e all-uppercase 
5f00: 69 6e 20 79 65 61 72 73 20 31 39 39 31 20 61 6e  in years 1991 an
5f10: 64 20 32 30 30 31 20 62 75 74 20 6e 6f 74 20 6f  d 2001 but not o
5f20: 6e 20 79 65 61 72 20 32 30 31 31 2e 3c 62 72 3e  n year 2011.<br>
5f30: 0d 0a 53 79 73 74 65 6d 61 74 69 63 61 6c 6c 79  ..Systematically
5f40: 20 75 73 69 6e 67 20 55 70 70 65 72 28 29 20 77   using Upper() w
5f50: 69 6c 6c 20 68 6f 6d 6f 67 65 6e 69 7a 65 20 61  ill homogenize a
5f60: 6c 6c 20 6e 61 6d 65 73 20 69 6e 20 61 20 63 6f  ll names in a co
5f70: 6e 73 69 73 74 65 6e 74 20 77 61 79 2e 3c 2f 6c  nsistent way.</l
5f80: 69 3e 0d 0a 3c 6c 69 3e 57 65 20 61 72 65 20 75  i>..<li>We are u
5f90: 73 69 6e 67 20 74 68 72 65 65 20 73 65 70 61 72  sing three separ
5fa0: 61 74 65 20 63 6f 6d 70 61 72 69 73 6f 6e 73 20  ate comparisons 
5fb0: 28 6f 6e 65 20 66 6f 72 20 4d 75 6e 69 63 69 70  (one for Municip
5fc0: 61 6c 69 74 79 2c 20 6f 6e 65 20 66 6f 72 20 50  ality, one for P
5fd0: 72 6f 76 69 6e 63 65 20 61 6e 64 20 6f 6e 65 20  rovince and one 
5fe0: 66 6f 72 20 52 65 67 69 6f 6e 29 20 63 6f 6e 6e  for Region) conn
5ff0: 65 63 74 65 64 20 62 79 20 3c 62 3e 4f 52 3c 2f  ected by <b>OR</
6000: 62 3e 20 6c 6f 67 69 63 61 6c 20 6f 70 65 72 61  b> logical opera
6010: 74 6f 72 73 20 73 6f 20 74 6f 20 6d 61 6b 65 20  tors so to make 
6020: 70 6f 73 73 69 62 6c 65 20 73 70 65 63 69 66 79  possible specify
6030: 69 6e 67 20 6a 75 73 74 20 61 20 73 69 6e 67 6c  ing just a singl
6040: 65 20 66 69 6c 74 65 72 20 63 6c 61 75 73 65 2e  e filter clause.
6050: 3c 62 72 3e 0d 0a 3c 75 3e 52 65 63 61 6c 6c 3c  <br>..<u>Recall<
6060: 2f 75 3e 3a 20 75 6e 61 73 73 69 67 6e 65 64 20  /u>: unassigned 
6070: 56 61 72 69 61 62 6c 65 73 20 77 69 6c 6c 20 64  Variables will d
6080: 65 66 61 75 6c 74 20 74 6f 20 4e 55 4c 4c 3b 20  efault to NULL; 
6090: 73 6f 20 62 79 20 6a 75 73 74 20 64 65 63 6c 61  so by just decla
60a0: 72 69 6e 67 20 0d 0a 3c 62 3e 40 70 72 6f 76 69  ring ..<b>@provi
60b0: 6e 63 65 40 3d 41 72 65 7a 7a 6f 3c 2f 62 3e 20  nce@=Arezzo</b> 
60c0: 77 65 27 6c 6c 20 74 68 65 6e 20 67 65 74 20 61  we'll then get a
60d0: 20 3c 62 3e 3c 69 3e 63 6f 6f 6b 65 64 3c 2f 69   <b><i>cooked</i
60e0: 3e 3c 2f 62 3e 20 57 48 45 52 45 20 63 6c 61 75  ></b> WHERE clau
60f0: 73 65 20 6c 69 6b 65 20 74 68 69 73 3a 0d 0a 3c  se like this:..<
6100: 76 65 72 62 61 74 69 6d 3e 0d 0a 57 48 45 52 45  verbatim>..WHERE
6110: 20 28 55 70 70 65 72 28 6e 61 6d 65 29 20 3d 20   (Upper(name) = 
6120: 55 70 70 65 72 28 27 4e 55 4c 4c 27 29 20 4f 52  Upper('NULL') OR
6130: 20 55 70 70 65 72 28 70 72 6f 76 69 6e 63 65 29   Upper(province)
6140: 20 3d 20 55 70 70 65 72 28 27 41 72 65 7a 7a 6f   = Upper('Arezzo
6150: 27 29 20 4f 52 20 55 70 70 65 72 28 72 65 67 69  ') OR Upper(regi
6160: 6f 6e 29 20 3d 20 55 70 70 65 72 28 27 4e 55 4c  on) = Upper('NUL
6170: 4c 27 29 29 0d 0a 3c 2f 76 65 72 62 61 74 69 6d  L'))..</verbatim
6180: 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d  >..</li>..</ul>.
6190: 0a 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c  .</li>..</ul>..<
61a0: 62 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d  br>..<verbatim>.
61b0: 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f  .SELECT SqlProc_
61c0: 45 78 65 63 75 74 65 28 20 53 71 6c 50 72 6f 63  Execute( SqlProc
61d0: 5f 46 72 6f 6d 46 69 6c 65 20 28 27 43 3a 2f 75  _FromFile ('C:/u
61e0: 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f  sers/joe/stored_
61f0: 70 72 6f 63 5f 74 65 73 74 2f 74 65 73 74 5f 73  proc_test/test_s
6200: 70 2e 74 78 74 27 29 2c 0d 0a 20 20 27 40 73 72  p.txt'),..  '@sr
6210: 69 64 40 3d 33 30 30 34 27 2c 20 27 40 79 65 61  id@=3004', '@yea
6220: 72 40 3d 32 30 30 31 27 2c 20 27 40 72 65 67 69  r@=2001', '@regi
6230: 6f 6e 40 3d 4c 61 7a 69 6f 27 2c 20 27 40 73 68  on@=Lazio', '@sh
6240: 70 5f 70 61 74 68 40 3d 43 3a 2f 75 73 65 72 73  p_path@=C:/users
6250: 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70 72 6f 63  /joe/stored_proc
6260: 5f 74 65 73 74 2f 6c 61 7a 69 6f 5f 32 30 30 31  _test/lazio_2001
6270: 5f 33 30 30 34 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d  _3004');..-----.
6280: 0a 31 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 71 6c  .1....SELECT Sql
6290: 50 72 6f 63 5f 45 78 65 63 75 74 65 28 20 53 71  Proc_Execute( Sq
62a0: 6c 50 72 6f 63 5f 46 72 6f 6d 46 69 6c 65 20 28  lProc_FromFile (
62b0: 27 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74  'C:/users/joe/st
62c0: 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f 74  ored_proc_test/t
62d0: 65 73 74 5f 73 70 2e 74 78 74 27 29 2c 0d 0a 20  est_sp.txt'),.. 
62e0: 20 27 40 73 72 69 64 40 3d 34 33 32 36 27 2c 20   '@srid@=4326', 
62f0: 27 40 79 65 61 72 40 3d 31 39 39 31 27 2c 20 27  '@year@=1991', '
6300: 40 72 65 67 69 6f 6e 40 3d 70 75 67 6c 69 61 27  @region@=puglia'
6310: 2c 20 27 40 73 68 70 5f 70 61 74 68 40 3d 43 3a  , '@shp_path@=C:
6320: 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65  /users/joe/store
6330: 64 5f 70 72 6f 63 5f 74 65 73 74 2f 70 75 67 6c  d_proc_test/pugl
6340: 69 61 5f 31 39 39 31 5f 34 33 32 36 27 29 3b 0d  ia_1991_4326');.
6350: 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a 53 45 4c  .-----..1....SEL
6360: 45 43 54 20 53 71 6c 50 72 6f 63 5f 45 78 65 63  ECT SqlProc_Exec
6370: 75 74 65 28 20 53 71 6c 50 72 6f 63 5f 46 72 6f  ute( SqlProc_Fro
6380: 6d 46 69 6c 65 20 28 27 43 3a 2f 75 73 65 72 73  mFile ('C:/users
6390: 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70 72 6f 63  /joe/stored_proc
63a0: 5f 74 65 73 74 2f 74 65 73 74 5f 73 70 2e 74 78  _test/test_sp.tx
63b0: 74 27 29 2c 0d 0a 20 20 27 40 73 72 69 64 40 3d  t'),..  '@srid@=
63c0: 33 30 30 33 27 2c 20 27 40 79 65 61 72 40 3d 32  3003', '@year@=2
63d0: 30 31 31 27 2c 20 27 40 70 72 6f 76 69 6e 63 65  011', '@province
63e0: 40 3d 41 52 45 5a 5a 4f 27 2c 20 27 40 73 68 70  @=AREZZO', '@shp
63f0: 5f 70 61 74 68 40 3d 43 3a 2f 75 73 65 72 73 2f  _path@=C:/users/
6400: 6a 6f 65 2f 75 63 73 35 67 62 2f 73 74 6f 72 65  joe/ucs5gb/store
6410: 64 5f 70 72 6f 63 5f 74 65 73 74 2f 61 72 65 7a  d_proc_test/arez
6420: 7a 6f 5f 32 30 31 31 5f 33 30 30 33 27 29 3b 0d  zo_2011_3003');.
6430: 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a 53 45 4c  .-----..1....SEL
6440: 45 43 54 20 53 71 6c 50 72 6f 63 5f 45 78 65 63  ECT SqlProc_Exec
6450: 75 74 65 28 20 53 71 6c 50 72 6f 63 5f 46 72 6f  ute( SqlProc_Fro
6460: 6d 46 69 6c 65 20 28 27 43 3a 2f 75 73 65 72 73  mFile ('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 74 65 73 74 5f 73 70 2e 74 78  _test/test_sp.tx
6490: 74 27 29 2c 0d 0a 20 20 27 40 73 72 69 64 40 3d  t'),..  '@srid@=
64a0: 33 30 30 33 27 2c 20 27 40 79 65 61 72 40 3d 32  3003', '@year@=2
64b0: 30 30 31 27 2c 20 27 40 6d 75 6e 69 63 69 70 61  001', '@municipa
64c0: 6c 69 74 79 40 3d 41 52 45 5a 5a 4f 27 2c 20 27  lity@=AREZZO', '
64d0: 40 73 68 70 5f 70 61 74 68 40 3d 43 3a 2f 75 73  @shp_path@=C:/us
64e0: 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70  ers/joe/stored_p
64f0: 72 6f 63 5f 74 65 73 74 2f 63 6f 6d 5f 61 72 65  roc_test/com_are
6500: 7a 7a 6f 5f 32 30 30 31 5f 33 30 30 33 27 29 3b  zzo_2001_3003');
6510: 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65  ..-----..1..</ve
6520: 72 62 61 74 69 6d 3e 0d 0a 49 6e 20 74 68 69 73  rbatim>..In this
6530: 20 66 69 72 73 74 20 74 75 74 6f 72 69 61 6c 20   first tutorial 
6540: 77 65 27 6c 6c 20 61 6c 77 61 79 73 20 3c 62 3e  we'll always <b>
6550: 65 78 65 63 75 74 65 3c 2f 62 3e 20 61 20 50 72  execute</b> a Pr
6560: 6f 63 65 64 75 72 65 20 6c 6f 61 64 65 64 20 66  ocedure loaded f
6570: 72 6f 6d 20 61 6e 20 65 78 74 65 72 6e 61 6c 20  rom an external 
6580: 66 69 6c 65 2e 3c 62 72 3e 0d 0a 41 73 20 79 6f  file.<br>..As yo
6590: 75 20 63 61 6e 20 73 65 65 20 65 78 65 63 75 74  u can see execut
65a0: 69 6e 67 20 61 20 50 72 6f 63 65 64 75 72 65 20  ing a Procedure 
65b0: 69 73 20 61 20 73 74 72 61 69 67 68 74 66 6f 72  is a straightfor
65c0: 77 61 72 64 20 74 61 73 6b 3b 20 79 6f 75 20 73  ward task; you s
65d0: 69 6d 70 6c 79 20 68 61 76 65 20 74 6f 20 73 70  imply have to sp
65e0: 65 63 69 66 79 20 61 6e 20 61 70 70 72 6f 70 72  ecify an appropr
65f0: 69 61 74 65 20 6c 69 73 74 20 6f 66 20 3c 62 3e  iate list of <b>
6600: 56 61 72 69 61 62 6c 65 20 56 61 6c 75 65 73 3c  Variable Values<
6610: 2f 62 3e 20 61 6e 64 20 74 68 61 74 27 73 20 61  /b> and that's a
6620: 6c 6c 2e 0d 0a 3c 68 72 3e 0d 0a 3c 68 32 3e 54  ll...<hr>..<h2>T
6630: 75 74 6f 72 69 61 6c 20 23 32 3c 2f 68 32 3e 0d  utorial #2</h2>.
6640: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c  .<verbatim>..SEL
6650: 45 43 54 20 53 74 6f 72 65 64 50 72 6f 63 5f 52  ECT StoredProc_R
6660: 65 67 69 73 74 65 72 28 20 27 6d 79 5f 70 72 6f  egister( 'my_pro
6670: 63 27 2c 20 27 61 20 53 74 6f 72 65 64 20 50 72  c', 'a Stored Pr
6680: 6f 63 65 64 75 72 65 20 66 6f 72 20 65 78 70 6f  ocedure for expo
6690: 72 74 69 6e 67 20 73 65 6c 65 63 74 65 64 20 53  rting selected S
66a0: 68 61 70 65 66 69 6c 65 73 27 2c 20 53 71 6c 50  hapefiles', SqlP
66b0: 72 6f 63 5f 46 72 6f 6d 46 69 6c 65 20 28 27 43  roc_FromFile ('C
66c0: 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72  :/users/joe/stor
66d0: 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f 74 65 73  ed_proc_test/tes
66e0: 74 5f 73 70 2e 74 78 74 27 29 20 29 3b 0d 0a 3c  t_sp.txt') );..<
66f0: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 69 73  /verbatim>..This
6700: 20 73 65 63 6f 6e 64 20 74 75 74 6f 72 69 61 6c   second tutorial
6710: 20 69 73 20 73 75 62 73 74 61 6e 74 69 61 6c 6c   is substantiall
6720: 79 20 74 68 65 20 73 61 6d 65 20 6f 66 20 74 68  y the same of th
6730: 65 20 66 69 72 73 74 20 6f 6e 65 2e 3c 62 72 3e  e first one.<br>
6740: 0d 0a 54 68 65 20 75 6e 69 71 75 65 20 64 69 66  ..The unique dif
6750: 66 65 72 65 6e 63 65 20 69 73 20 74 68 61 74 20  ference is that 
6760: 6e 6f 77 20 77 65 27 6c 6c 20 67 6f 20 74 6f 20  now we'll go to 
6770: 70 65 72 6d 61 6e 65 6e 74 6c 79 20 72 65 67 69  permanently regi
6780: 73 74 65 72 65 64 20 61 20 3c 62 3e 53 74 6f 72  stered a <b>Stor
6790: 65 64 20 50 72 6f 63 65 64 75 72 65 3c 2f 62 3e  ed Procedure</b>
67a0: 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53  ...<verbatim>..S
67b0: 45 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f 63  ELECT StoredProc
67c0: 5f 45 78 65 63 75 74 65 28 20 27 6d 79 5f 70 72  _Execute( 'my_pr
67d0: 6f 63 27 2c 20 27 40 73 72 69 64 40 3d 33 30 30  oc', '@srid@=300
67e0: 34 27 2c 20 27 40 79 65 61 72 40 3d 32 30 30 31  4', '@year@=2001
67f0: 27 2c 20 27 40 72 65 67 69 6f 6e 40 3d 4c 61 7a  ', '@region@=Laz
6800: 69 6f 27 2c 20 27 40 73 68 70 5f 70 61 74 68 40  io', '@shp_path@
6810: 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74  =C:/users/joe/st
6820: 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f 6c  ored_proc_test/l
6830: 61 7a 69 6f 5f 32 30 30 31 5f 33 30 30 34 27 29  azio_2001_3004')
6840: 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a 53  ;..-----..1....S
6850: 45 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f 63  ELECT StoredProc
6860: 5f 45 78 65 63 75 74 65 28 20 27 6d 79 5f 70 72  _Execute( 'my_pr
6870: 6f 63 27 2c 20 27 40 73 72 69 64 40 3d 34 33 32  oc', '@srid@=432
6880: 36 27 2c 20 27 40 79 65 61 72 40 3d 31 39 39 31  6', '@year@=1991
6890: 27 2c 20 27 40 72 65 67 69 6f 6e 40 3d 70 75 67  ', '@region@=pug
68a0: 6c 69 61 27 2c 20 27 40 73 68 70 5f 70 61 74 68  lia', '@shp_path
68b0: 40 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73  @=C:/users/joe/s
68c0: 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f  tored_proc_test/
68d0: 70 75 67 6c 69 61 5f 31 39 39 31 5f 34 33 32 36  puglia_1991_4326
68e0: 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d  ');..-----..1...
68f0: 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50 72  .SELECT StoredPr
6900: 6f 63 5f 45 78 65 63 75 74 65 28 20 27 6d 79 5f  oc_Execute( 'my_
6910: 70 72 6f 63 27 2c 20 27 40 73 72 69 64 40 3d 33  proc', '@srid@=3
6920: 30 30 33 27 2c 20 27 40 79 65 61 72 40 3d 32 30  003', '@year@=20
6930: 31 31 27 2c 20 27 40 70 72 6f 76 69 6e 63 65 40  11', '@province@
6940: 3d 41 52 45 5a 5a 4f 27 2c 20 27 40 73 68 70 5f  =AREZZO', '@shp_
6950: 70 61 74 68 40 3d 43 3a 2f 75 73 65 72 73 2f 6a  path@=C:/users/j
6960: 6f 65 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74  oe/stored_proc_t
6970: 65 73 74 2f 61 72 65 7a 7a 6f 5f 32 30 31 31 5f  est/arezzo_2011_
6980: 33 30 30 33 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a  3003');..-----..
6990: 31 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72  1....SELECT Stor
69a0: 65 64 50 72 6f 63 5f 45 78 65 63 75 74 65 28 20  edProc_Execute( 
69b0: 27 6d 79 5f 70 72 6f 63 27 2c 20 27 40 73 72 69  'my_proc', '@sri
69c0: 64 40 3d 33 30 30 33 27 2c 20 27 40 79 65 61 72  d@=3003', '@year
69d0: 40 3d 32 30 30 31 27 2c 20 27 40 6d 75 6e 69 63  @=2001', '@munic
69e0: 69 70 61 6c 69 74 79 40 3d 41 52 45 5a 5a 4f 27  ipality@=AREZZO'
69f0: 2c 20 27 40 73 68 70 5f 70 61 74 68 40 3d 43 3a  , '@shp_path@=C:
6a00: 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65  /users/joe/store
6a10: 64 5f 70 72 6f 63 5f 74 65 73 74 2f 63 6f 6d 5f  d_proc_test/com_
6a20: 61 72 65 7a 7a 6f 5f 32 30 30 31 5f 33 30 30 33  arezzo_2001_3003
6a30: 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c  ');..-----..1..<
6a40: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 45 78 65 63  /verbatim>..Exec
6a50: 75 74 69 6e 67 20 61 20 53 74 6f 72 65 64 20 50  uting a Stored P
6a60: 72 6f 63 65 64 75 72 65 20 69 73 6e 27 74 20 76  rocedure isn't v
6a70: 65 72 79 20 64 69 66 66 65 72 65 6e 74 20 66 72  ery different fr
6a80: 6f 6d 20 65 78 65 63 75 74 69 6e 67 20 61 20 50  om executing a P
6a90: 72 6f 63 65 64 75 72 65 20 73 74 6f 72 65 64 20  rocedure stored 
6aa0: 69 6e 74 6f 20 61 6e 20 65 78 74 65 72 6e 61 6c  into an external
6ab0: 20 66 69 6c 65 2e 3c 62 72 3e 0d 0a 3c 74 61 62   file.<br>..<tab
6ac0: 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 66 38 66  le bgcolor="#f8f
6ad0: 38 64 38 22 20 63 65 6c 6c 70 61 64 64 69 6e 67  8d8" cellpadding
6ae0: 3d 22 36 22 20 63 65 6c 6c 73 70 61 63 69 6e 67  ="6" cellspacing
6af0: 3d 22 38 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 45  ="8"><tr><td>..E
6b00: 78 65 63 75 74 69 6e 67 20 79 6f 75 72 20 50 72  xecuting your Pr
6b10: 6f 63 65 64 75 72 65 73 20 66 72 6f 6d 20 65 78  ocedures from ex
6b20: 74 65 72 6e 61 6c 20 66 69 6c 65 73 20 6f 72 20  ternal files or 
6b30: 70 65 72 6d 61 6e 65 6e 74 6c 79 20 72 65 67 69  permanently regi
6b40: 73 74 65 72 69 6e 67 20 53 74 6f 72 65 64 20 50  stering Stored P
6b50: 72 6f 63 65 64 75 72 65 73 20 64 69 72 65 63 74  rocedures direct
6b60: 6c 79 20 77 69 74 68 69 6e 20 61 20 64 61 74 61  ly within a data
6b70: 62 61 73 65 20 69 73 20 61 20 6d 61 74 74 65 72  base is a matter
6b80: 20 6f 66 20 66 72 65 65 20 63 68 6f 69 63 65 2e   of free choice.
6b90: 3c 62 72 3e 0d 0a 49 66 20 79 6f 75 20 61 72 65  <br>..If you are
6ba0: 20 70 6c 61 6e 6e 69 6e 67 20 74 6f 20 64 65 70   planning to dep
6bb0: 6c 6f 79 20 61 20 50 72 6f 63 65 64 75 72 65 20  loy a Procedure 
6bc0: 69 6e 74 65 6e 64 65 64 20 74 6f 20 73 75 70 70  intended to supp
6bd0: 6f 72 74 20 6d 61 6e 79 20 64 69 66 66 65 72 65  ort many differe
6be0: 6e 74 20 64 61 74 61 62 61 73 65 73 2c 20 74 68  nt databases, th
6bf0: 65 6e 20 75 73 69 6e 67 20 61 6e 20 65 78 74 65  en using an exte
6c00: 72 6e 61 6c 20 66 69 6c 65 20 63 6f 75 6c 64 20  rnal file could 
6c10: 70 72 6f 62 61 62 6c 79 20 73 69 6d 70 6c 69 66  probably simplif
6c20: 79 20 79 6f 75 72 20 77 6f 72 6b 2e 3c 62 72 3e  y your work.<br>
6c30: 0d 0a 42 75 74 20 69 66 20 79 6f 75 20 61 72 65  ..But if you are
6c40: 20 70 6c 61 6e 6e 69 6e 67 20 74 6f 20 64 65 70   planning to dep
6c50: 6c 6f 79 20 61 20 50 72 6f 63 65 64 75 72 65 20  loy a Procedure 
6c60: 69 6e 74 65 6e 64 65 64 20 74 6f 20 61 75 74 6f  intended to auto
6c70: 6d 61 74 65 20 6d 61 6e 79 20 72 6f 75 74 69 6e  mate many routin
6c80: 65 6c 79 20 74 61 73 6b 20 74 6f 20 62 65 20 65  ely task to be e
6c90: 78 65 63 75 74 65 64 20 6d 6f 72 65 20 61 6e 64  xecuted more and
6ca0: 20 6d 6f 72 65 20 74 69 6d 65 73 20 6f 6e 20 74   more times on t
6cb0: 68 65 20 73 61 6d 65 20 64 61 74 61 62 61 73 65  he same database
6cc0: 2c 20 74 68 65 6e 20 70 65 72 6d 61 6e 65 6e 74  , then permanent
6cd0: 6c 79 20 72 65 67 69 73 74 65 72 69 6e 67 20 61  ly registering a
6ce0: 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72   Stored Procedur
6cf0: 65 20 77 6f 75 6c 64 20 70 72 6f 62 61 62 6c 79  e would probably
6d00: 20 62 65 20 62 65 74 74 65 72 2e 0d 0a 3c 2f 74   be better...</t
6d10: 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d  d></tr></table>.
6d20: 0a 3c 62 72 3e 3c 68 72 3e 0d 0a 3c 68 32 3e 54  .<br><hr>..<h2>T
6d30: 75 74 6f 72 69 61 6c 20 23 33 3c 2f 68 32 3e 0d  utorial #3</h2>.
6d40: 0a 54 68 69 73 20 6c 61 74 65 73 74 20 74 75 74  .This latest tut
6d50: 6f 72 69 61 6c 20 69 73 20 6a 75 73 74 20 61 20  orial is just a 
6d60: 73 6d 61 6c 6c 20 76 61 72 69 61 74 69 6f 6e 20  small variation 
6d70: 6f 6e 20 74 68 65 20 74 68 65 6d 65 20 69 6e 74  on the theme int
6d80: 65 6e 64 65 64 20 74 6f 20 68 69 67 68 6c 69 67  ended to highlig
6d90: 68 74 20 73 6f 6d 65 20 70 6f 74 65 6e 74 69 61  ht some potentia
6da0: 6c 6c 79 20 64 61 6e 67 65 72 6f 75 73 20 70 69  lly dangerous pi
6db0: 74 66 61 6c 6c 73 20 72 65 6c 61 74 65 64 20 74  tfalls related t
6dc0: 6f 20 3c 62 3e 73 69 6e 67 6c 65 2d 71 75 6f 74  o <b>single-quot
6dd0: 69 6e 67 3c 2f 62 3e 2e 20 0d 0a 3c 76 65 72 62  ing</b>. ..<verb
6de0: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 74  atim>..SELECT St
6df0: 6f 72 65 64 50 72 6f 63 5f 45 78 65 63 75 74 65  oredProc_Execute
6e00: 28 20 27 6d 79 5f 70 72 6f 63 27 29 2c 20 27 40  ( 'my_proc'), '@
6e10: 73 72 69 64 40 3d 33 30 30 33 27 2c 20 27 40 79  srid@=3003', '@y
6e20: 65 61 72 40 3d 32 30 31 31 27 2c 20 27 40 6d 75  ear@=2011', '@mu
6e30: 6e 69 63 69 70 61 6c 69 74 79 40 3d 72 69 6f 20  nicipality@=rio 
6e40: 6e 65 6c 6c 27 27 65 6c 62 61 27 2c 20 27 40 73  nell''elba', '@s
6e50: 68 70 5f 70 61 74 68 40 3d 43 3a 2f 75 73 65 72  hp_path@=C:/user
6e60: 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70 72 6f  s/joe/stored_pro
6e70: 63 5f 74 65 73 74 2f 72 69 6f 5f 65 6c 62 61 5f  c_test/rio_elba_
6e80: 32 30 31 31 5f 33 30 30 33 27 29 3b 0d 0a 2d 2d  2011_3003');..--
6e90: 2d 2d 2d 0d 0a 53 74 6f 72 65 64 50 72 6f 63 20  ---..StoredProc 
6ea0: 65 78 63 65 70 74 69 6f 6e 20 2d 20 61 20 66 61  exception - a fa
6eb0: 74 61 6c 20 53 51 4c 20 65 72 72 6f 72 20 77 61  tal SQL error wa
6ec0: 73 20 65 6e 63 6f 75 6e 74 65 72 65 64 2e 0d 0a  s encountered...
6ed0: 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63  ..SELECT SqlProc
6ee0: 5f 47 65 74 4c 61 73 74 45 72 72 6f 72 28 29 3b  _GetLastError();
6ef0: 0d 0a 2d 2d 2d 2d 2d 0d 0a 67 61 69 61 5f 73 71  ..-----..gaia_sq
6f00: 6c 5f 70 72 6f 63 5f 65 78 65 63 75 74 65 3a 20  l_proc_execute: 
6f10: 6e 65 61 72 20 22 65 6c 62 61 22 3a 20 73 79 6e  near "elba": syn
6f20: 74 61 78 20 65 72 72 6f 72 0d 0a 3c 2f 76 65 72  tax error..</ver
6f30: 62 61 74 69 6d 3e 0d 0a 54 68 69 73 20 66 69 72  batim>..This fir
6f40: 73 74 20 6e 61 69 76 65 20 61 74 74 65 6d 70 74  st naive attempt
6f50: 20 77 69 6c 6c 20 66 61 69 6c 2c 20 61 6e 64 20   will fail, and 
6f60: 3c 62 3e 53 71 6c 50 72 6f 63 5f 47 65 74 4c 61  <b>SqlProc_GetLa
6f70: 73 74 45 72 72 6f 72 3c 2f 62 3e 20 77 69 6c 6c  stError</b> will
6f80: 20 65 78 70 6c 61 69 6e 20 77 68 79 20 69 74 20   explain why it 
6f90: 66 61 69 6c 65 64 2e 20 57 65 27 76 65 20 70 61  failed. We've pa
6fa0: 73 73 65 64 20 61 20 3c 62 3e 27 40 6d 75 6e 69  ssed a <b>'@muni
6fb0: 63 69 70 61 6c 69 74 79 40 3d 72 69 6f 20 6e 65  cipality@=rio ne
6fc0: 6c 6c 27 27 65 6c 62 61 27 3c 2f 62 3e 20 56 61  ll''elba'</b> Va
6fd0: 72 69 61 62 6c 65 20 77 69 74 68 20 56 61 6c 75  riable with Valu
6fe0: 65 2c 20 74 68 61 74 20 77 69 6c 6c 20 6c 65 61  e, that will lea
6ff0: 64 20 74 6f 20 61 20 3c 62 3e 63 6f 6f 6b 65 64  d to a <b>cooked
7000: 3c 2f 62 3e 20 57 48 45 52 45 20 63 6c 61 75 73  </b> WHERE claus
7010: 65 20 6c 69 6b 65 20 74 68 69 73 3a 0d 0a 3c 76  e like this:..<v
7020: 65 72 62 61 74 69 6d 3e 0d 0a 57 48 45 52 45 20  erbatim>..WHERE 
7030: 28 55 70 70 65 72 28 6e 61 6d 65 29 20 3d 20 55  (Upper(name) = U
7040: 70 70 65 72 28 27 72 69 6f 20 6e 65 6c 6c 27 65  pper('rio nell'e
7050: 6c 62 61 27 29 20 4f 52 20 55 70 70 65 72 28 70  lba') OR Upper(p
7060: 72 6f 76 69 6e 63 65 29 20 3d 20 55 70 70 65 72  rovince) = Upper
7070: 28 27 4e 55 4c 4c 27 29 20 4f 52 20 55 70 70 65  ('NULL') OR Uppe
7080: 72 28 72 65 67 69 6f 6e 29 20 3d 20 55 70 70 65  r(region) = Uppe
7090: 72 28 27 4e 55 4c 4c 27 29 29 0d 0a 3c 2f 76 65  r('NULL'))..</ve
70a0: 72 62 61 74 69 6d 3e 0d 0a 49 74 27 73 20 72 61  rbatim>..It's ra
70b0: 74 68 65 72 20 6f 62 76 69 6f 75 73 20 74 68 61  ther obvious tha
70c0: 74 20 3c 62 3e 27 72 69 6f 20 6e 65 6c 6c 27 65  t <b>'rio nell'e
70d0: 6c 62 61 27 3c 2f 62 3e 20 69 73 20 61 6e 20 69  lba'</b> is an i
70e0: 6c 6c 65 67 61 6c 20 53 51 4c 20 74 65 78 74 20  llegal SQL text 
70f0: 73 74 72 69 6e 67 3b 20 74 68 65 20 63 6f 72 72  string; the corr
7100: 65 63 74 20 73 79 6e 74 61 78 20 73 68 6f 75 6c  ect syntax shoul
7110: 64 20 62 65 20 69 6e 73 74 65 61 64 20 3c 62 3e  d be instead <b>
7120: 27 72 69 6f 20 6e 65 6c 6c 27 27 65 6c 62 61 27  'rio nell''elba'
7130: 3c 2f 62 3e 2e 0d 0a 3c 62 72 3e 3c 62 72 3e 0d  </b>...<br><br>.
7140: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c  .<verbatim>..SEL
7150: 45 43 54 20 53 74 6f 72 65 64 50 72 6f 63 5f 45  ECT StoredProc_E
7160: 78 65 63 75 74 65 28 20 27 6d 79 5f 70 72 6f 63  xecute( 'my_proc
7170: 27 29 2c 20 27 40 73 72 69 64 40 3d 33 30 30 33  '), '@srid@=3003
7180: 27 2c 20 27 40 79 65 61 72 40 3d 32 30 31 31 27  ', '@year@=2011'
7190: 2c 20 27 40 6d 75 6e 69 63 69 70 61 6c 69 74 79  , '@municipality
71a0: 40 3d 72 69 6f 20 6e 65 6c 6c 27 27 27 27 65 6c  @=rio nell''''el
71b0: 62 61 27 2c 20 27 40 73 68 70 5f 70 61 74 68 40  ba', '@shp_path@
71c0: 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74  =C:/users/joe/st
71d0: 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f 72  ored_proc_test/r
71e0: 69 6f 5f 65 6c 62 61 5f 32 30 31 31 5f 33 30 30  io_elba_2011_300
71f0: 33 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a  3');..-----..1..
7200: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 52 65 73  </verbatim>..Res
7210: 6f 6c 76 69 6e 67 20 73 75 63 68 20 61 6e 20 69  olving such an i
7220: 73 73 75 65 20 69 73 20 72 61 74 68 65 72 20 74  ssue is rather t
7230: 72 69 76 69 61 6c 3b 20 77 65 20 6a 75 73 74 20  rivial; we just 
7240: 68 61 76 65 20 74 6f 20 75 73 65 20 3c 62 3e 66  have to use <b>f
7250: 6f 75 72 3c 2f 62 3e 20 63 6f 6e 73 65 63 75 74  our</b> consecut
7260: 69 76 65 20 73 69 6e 67 6c 65 2d 71 75 6f 74 65  ive single-quote
7270: 73 20 73 6f 20 74 6f 20 63 6f 72 72 65 63 74 6c  s so to correctl
7280: 79 20 65 73 63 61 70 65 20 74 68 65 20 73 74 72  y escape the str
7290: 69 6e 67 20 76 61 6c 75 65 2e 0d 0a 3c 62 72 3e  ing value...<br>
72a0: 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65 20 77 69 64  <br>..<table wid
72b0: 74 68 3d 22 31 30 30 25 22 3e 3c 74 72 3e 0d 0a  th="100%"><tr>..
72c0: 3c 74 64 20 77 69 64 74 68 3d 22 33 33 25 22 20  <td width="33%" 
72d0: 61 6c 69 67 6e 3d 22 6c 65 66 74 22 3e 3c 2f 74  align="left"></t
72e0: 64 3e 0d 0a 3c 74 64 20 61 6c 69 67 6e 3d 22 63  d>..<td align="c
72f0: 65 6e 74 65 72 22 3e 3c 61 20 68 72 65 66 3d 22  enter"><a href="
7300: 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67 61 69 61  https://www.gaia
7310: 2d 67 69 73 2e 69 74 2f 66 6f 73 73 69 6c 2f 6c  -gis.it/fossil/l
7320: 69 62 73 70 61 74 69 61 6c 69 74 65 2f 77 69 6b  ibspatialite/wik
7330: 69 3f 6e 61 6d 65 3d 34 2e 33 2e 30 2b 64 6f 63  i?name=4.3.0+doc
7340: 22 3e 62 61 63 6b 20 74 6f 20 69 6e 64 65 78 3c  ">back to index<
7350: 2f 61 3e 3c 2f 74 64 3e 0d 0a 3c 74 64 20 77 69  /a></td>..<td wi
7360: 64 74 68 3d 22 33 33 25 22 20 61 6c 69 67 6e 3d  dth="33%" align=
7370: 22 72 69 67 68 74 22 3e 3c 2f 74 64 3e 0d 0a 3c  "right"></td>..<
7380: 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0a 5a 20 65  /tr></table>.Z e
7390: 39 31 66 62 36 39 37 32 33 63 34 31 39 64 63 33  91fb69723c419dc3
73a0: 37 34 37 61 66 66 32 63 61 66 33 61 63 37 32 0a  747aff2caf3ac72.