Wiki page
[Stored Procedures] by
sandro
2017-11-05 00:02:33.
0000: 44 20 32 30 31 37 2d 31 31 2d 30 35 54 30 30 3a D 2017-11-05T00:
0010: 30 32 3a 33 33 2e 37 34 36 0a 4c 20 53 74 6f 72 02:33.746.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 35 64 34 63 32 35 64 33 63 35 37 35 32 32 b5d4c25d3c57522
0040: 33 65 37 63 37 32 38 33 36 30 65 64 63 32 63 64 3e7c728360edc2cd
0050: 30 36 66 64 38 32 31 36 63 0a 55 20 73 61 6e 64 06fd8216c.U sand
0060: 72 6f 0a 57 20 32 35 34 36 38 0a 3c 74 61 62 6c ro.W 25468.<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 4e 6f 74 20 6f 6e 6c 79 3a 20 74 on...Not only: t
03b0: 68 69 6e 6b 20 6f 66 20 6d 61 6e 79 20 77 6f 6e hink of many won
03c0: 64 65 72 66 75 6c 20 6f 70 70 6f 72 74 75 6e 69 derful opportuni
03d0: 74 69 65 73 20 64 65 72 69 76 69 6e 67 20 66 72 ties deriving fr
03e0: 6f 6d 20 70 65 72 6d 61 6e 65 6e 74 6c 79 20 73 om permanently s
03f0: 74 6f 72 69 6e 67 20 77 69 74 68 69 6e 20 61 20 toring within a
0400: 64 61 74 61 62 61 73 65 20 73 75 63 68 20 3c 62 database such <b
0410: 3e 3c 69 3e 53 51 4c 20 53 63 72 69 70 74 73 20 ><i>SQL Scripts
0420: 77 69 74 68 20 56 61 72 69 61 62 6c 65 73 3c 2f with Variables</
0430: 69 3e 3c 2f 62 3e 20 73 6f 20 74 6f 20 6d 61 6b i></b> so to mak
0440: 65 20 61 73 20 73 69 6d 70 6c 65 20 61 73 20 70 e as simple as p
0450: 6f 73 73 69 62 6c 65 20 61 75 74 6f 6d 61 74 69 ossible automati
0460: 6e 67 20 63 6f 6d 6d 6f 6e 20 77 6f 72 6b 66 6c ng common workfl
0470: 6f 77 73 20 74 6f 20 62 65 20 72 65 70 65 61 74 ows to be repeat
0480: 65 64 6c 79 20 65 78 65 63 75 74 65 64 2e 0d 0a edly executed...
0490: 54 68 69 73 20 65 78 61 63 74 6c 79 20 69 73 20 This exactly is
04a0: 74 68 65 20 69 6e 74 65 6e 64 65 64 20 73 63 6f the intended sco
04b0: 70 65 20 6f 66 20 74 68 69 73 20 6e 65 77 20 6d pe of this new m
04c0: 6f 64 75 6c 65 2e 3c 62 72 3e 3c 62 72 3e 0d 0a odule.<br><br>..
04d0: 57 65 27 6c 6c 20 73 74 61 72 74 20 66 69 72 73 We'll start firs
04e0: 74 20 62 79 20 66 6f 72 6d 61 6c 6c 79 20 64 65 t by formally de
04f0: 66 69 6e 69 6e 67 20 66 65 77 20 62 61 73 69 63 fining few basic
0500: 20 63 6f 6e 63 65 70 74 73 20 61 6e 64 20 6f 62 concepts and ob
0510: 6a 65 63 74 73 20 73 6f 20 74 6f 20 61 76 6f 69 jects so to avoi
0520: 64 20 61 6e 79 20 70 6f 73 73 69 62 6c 65 20 63 d any possible c
0530: 6f 6e 66 75 73 69 6f 6e 2e 3c 62 72 3e 3c 62 72 onfusion.<br><br
0540: 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 32 3e 42 61 73 >..<hr>..<h2>Bas
0550: 69 63 20 44 65 66 69 6e 69 74 69 6f 6e 73 20 61 ic Definitions a
0560: 6e 64 20 43 6f 6e 63 65 70 74 73 3c 2f 68 32 3e nd Concepts</h2>
0570: 0d 0a 3c 6f 6c 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 ..<ol>..<li>..<h
0580: 34 3e 53 51 4c 20 53 74 61 74 65 6d 65 6e 74 3c 4>SQL Statement<
0590: 2f 68 34 3e 0d 0a 54 68 65 20 6d 69 6e 69 6d 61 /h4>..The minima
05a0: 6c 20 65 78 65 63 75 74 69 6f 6e 20 75 6e 69 74 l execution unit
05b0: 20 61 6c 6c 6f 77 65 64 20 62 79 20 53 51 4c 20 allowed by SQL
05c0: 73 79 6e 74 61 78 3b 20 61 20 73 74 61 6e 64 2d syntax; a stand-
05d0: 61 6c 6f 6e 65 20 53 51 4c 20 64 69 72 65 63 74 alone SQL direct
05e0: 69 76 65 20 74 6f 20 62 65 20 61 74 6f 6d 69 63 ive to be atomic
05f0: 61 6c 6c 79 20 65 78 65 63 75 74 65 64 20 69 6e ally executed in
0600: 20 61 20 73 69 6e 67 6c 65 20 73 74 65 70 2e 20 a single step.
0610: 45 78 61 6d 70 6c 65 73 3a 0d 0a 3c 76 65 72 62 Examples:..<verb
0620: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 69 64 atim>..SELECT id
0630: 2c 20 6e 61 6d 65 2c 20 6d 65 61 73 75 72 65 20 , name, measure
0640: 46 52 4f 4d 20 73 6f 6d 65 5f 74 61 62 6c 65 3b FROM some_table;
0650: 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a ..------------..
0660: 44 45 4c 45 54 45 20 46 52 4f 4d 20 73 6f 6d 65 DELETE FROM some
0670: 5f 74 61 62 6c 65 20 57 48 45 52 45 20 6d 65 61 _table WHERE mea
0680: 73 75 72 65 20 3e 20 31 30 30 30 3b 0d 0a 2d 2d sure > 1000;..--
0690: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 55 50 44 41 ----------..UPDA
06a0: 54 45 20 73 6f 6d 65 5f 74 61 62 6c 65 20 53 45 TE some_table SE
06b0: 54 20 6d 65 61 73 75 72 65 20 3d 20 6d 65 61 73 T measure = meas
06c0: 75 72 65 20 2f 20 31 30 2e 30 0d 0a 3c 2f 76 65 ure / 10.0..</ve
06d0: 72 62 61 74 69 6d 3e 0d 0a 3c 75 3e 4e 6f 74 65 rbatim>..<u>Note
06e0: 3c 2f 75 3e 3a 20 53 51 4c 20 53 74 61 74 65 6d </u>: SQL Statem
06f0: 65 6e 74 73 20 61 72 65 20 75 73 75 61 6c 6c 79 ents are usually
0700: 20 65 78 70 65 63 74 65 64 20 74 6f 20 62 65 20 expected to be
0710: 65 78 70 6c 69 63 69 74 6c 79 20 74 65 72 6d 69 explicitly termi
0720: 6e 61 74 65 64 20 62 79 20 61 20 3c 62 3e 3c 69 nated by a <b><i
0730: 3e 73 65 6d 69 63 6f 6c 6f 6e 3c 2f 69 3e 3c 2f >semicolon</i></
0740: 62 3e 20 28 3c 62 3e 3c 69 3e 3b 3c 2f 69 3e 3c b> (<b><i>;</i><
0750: 2f 62 3e 29 2e 3c 62 72 3e 0d 0a 54 68 65 20 73 /b>).<br>..The s
0760: 65 6d 69 63 6f 6c 6f 6e 20 74 65 72 6d 69 6e 61 emicolon termina
0770: 74 6f 72 20 63 61 6e 20 62 65 20 73 61 66 65 6c tor can be safel
0780: 79 20 73 75 70 70 72 65 73 73 65 64 20 6f 6e 6c y suppressed onl
0790: 79 20 77 68 65 6e 20 74 68 65 20 53 51 4c 20 53 y when the SQL S
07a0: 74 61 74 65 6d 65 6e 74 20 69 73 20 69 6d 6d 65 tatement is imme
07b0: 64 69 61 74 65 6c 79 20 66 6f 6c 6c 6f 77 65 64 diately followed
07c0: 20 62 79 20 61 20 73 74 72 69 6e 67 20 74 65 72 by a string ter
07d0: 6d 69 6e 61 74 6f 72 20 28 6c 65 61 64 69 6e 67 minator (leading
07e0: 20 61 6e 64 20 74 72 61 69 6c 69 6e 67 20 73 65 and trailing se
07f0: 71 75 65 6e 63 65 73 20 6f 66 20 61 6c 6c 20 3c quences of all <
0800: 62 3e 3c 69 3e 62 6c 61 6e 6b 73 3c 2f 69 3e 3c b><i>blanks</i><
0810: 2f 62 3e 20 77 69 6c 6c 20 62 65 20 61 6c 77 61 /b> will be alwa
0820: 79 73 20 69 67 6e 6f 72 65 64 29 2e 0d 0a 3c 62 ys ignored)...<b
0830: 72 3e 3c 62 72 3e 3c 68 72 3e 0d 0a 3c 2f 6c 69 r><br><hr>..</li
0840: 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 53 51 4c >..<li>..<h4>SQL
0850: 20 53 63 72 69 70 74 3c 2f 68 34 3e 0d 0a 41 20 Script</h4>..A
0860: 6d 6f 72 65 20 6f 72 20 6c 65 73 73 20 63 6f 6d more or less com
0870: 70 6c 65 78 20 73 65 71 75 65 6e 63 65 20 6f 66 plex sequence of
0880: 20 3c 62 3e 3c 69 3e 53 51 4c 20 53 74 61 74 65 <b><i>SQL State
0890: 6d 65 6e 74 73 3c 2f 69 3e 3c 2f 62 3e 2c 20 70 ments</i></b>, p
08a0: 6f 73 73 69 62 6c 79 20 69 6e 63 6c 75 64 69 6e ossibly includin
08b0: 67 20 69 6e 74 65 72 6c 65 61 76 65 64 20 3c 62 g interleaved <b
08c0: 3e 3c 69 3e 43 6f 6d 6d 65 6e 74 73 3c 2f 69 3e ><i>Comments</i>
08d0: 3c 2f 62 3e 20 61 6e 64 2f 6f 72 20 3c 62 3e 3c </b> and/or <b><
08e0: 69 3e 44 6f 74 20 4d 61 63 72 6f 73 3c 2f 69 3e i>Dot Macros</i>
08f0: 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a 53 51 4c 20 53 </b>.<br>..SQL S
0900: 63 72 69 70 74 73 20 61 72 65 20 69 6e 74 65 6e cripts are inten
0910: 64 65 64 20 74 6f 20 62 65 20 65 78 65 63 75 74 ded to be execut
0920: 65 64 20 69 6e 20 61 20 73 69 6e 67 6c 65 20 6d ed in a single m
0930: 6f 6e 6f 6c 69 74 68 69 63 20 70 61 73 73 20 28 onolithic pass (
0940: 61 74 6f 6d 69 63 20 6f 72 20 6e 6f 74 2c 20 64 atomic or not, d
0950: 65 70 65 6e 64 69 6e 67 20 6f 6e 20 69 6e 74 65 epending on inte
0960: 72 6e 61 6c 20 3c 62 3e 3c 69 3e 54 72 61 6e 73 rnal <b><i>Trans
0970: 61 63 74 69 6f 6e 3c 2f 69 3e 3c 2f 62 3e 20 68 action</i></b> h
0980: 61 6e 64 6c 69 6e 67 29 2e 20 45 78 61 6d 70 6c andling). Exampl
0990: 65 3a 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a e:..<verbatim>..
09a0: 2e 65 63 68 6f 20 6f 6e 0d 0a 0d 0a 2d 2d 0d 0a .echo on....--..
09b0: 2d 2d 20 73 74 61 72 74 69 6e 67 20 61 20 54 72 -- starting a Tr
09c0: 61 6e 73 61 63 74 69 6f 6e 0d 0a 2d 2d 0d 0a 42 ansaction..--..B
09d0: 45 47 49 4e 3b 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20 EGIN;....--..--
09e0: 63 72 65 61 74 69 6e 67 20 61 20 74 61 62 6c 65 creating a table
09f0: 0d 0a 2d 2d 0d 0a 43 52 45 41 54 45 20 54 41 42 ..--..CREATE TAB
0a00: 4c 45 20 65 78 61 6d 70 6c 65 20 28 0d 0a 20 20 LE example (..
0a10: 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 id INTEGER PRIMA
0a20: 52 59 20 4b 45 59 20 41 55 54 4f 49 4e 43 52 45 RY KEY AUTOINCRE
0a30: 4d 45 4e 54 2c 0d 0a 20 20 6e 61 6d 65 20 54 45 MENT,.. name TE
0a40: 58 54 20 4e 4f 54 20 4e 55 4c 4c 2c 0d 0a 20 20 XT NOT NULL,..
0a50: 76 61 6c 75 65 20 44 4f 55 42 4c 45 29 3b 0d 0a value DOUBLE);..
0a60: 0d 0a 2d 2d 0d 0a 2d 2d 20 70 6f 70 75 6c 61 74 ..--..-- populat
0a70: 69 6e 67 20 74 68 65 20 74 61 62 6c 65 0d 0a 2d ing the table..-
0a80: 2d 0d 0a 49 4e 53 45 52 54 20 49 4e 54 4f 20 65 -..INSERT INTO e
0a90: 78 61 6d 70 6c 65 20 28 69 64 2c 20 6e 61 6d 65 xample (id, name
0aa0: 2c 20 76 61 6c 75 65 29 20 56 41 4c 55 45 53 20 , value) VALUES
0ab0: 28 4e 55 4c 4c 2c 20 27 66 69 72 73 74 27 2c 20 (NULL, 'first',
0ac0: 31 32 2e 33 34 29 3b 0d 0a 49 4e 53 45 52 54 20 12.34);..INSERT
0ad0: 49 4e 54 4f 20 65 78 61 6d 70 6c 65 20 28 69 64 INTO example (id
0ae0: 2c 20 6e 61 6d 65 2c 20 76 61 6c 75 65 29 20 56 , name, value) V
0af0: 41 4c 55 45 53 20 28 4e 55 4c 4c 2c 20 27 73 65 ALUES (NULL, 'se
0b00: 63 6f 6e 64 27 2c 20 35 36 2e 37 38 29 3b 0d 0a cond', 56.78);..
0b10: 49 4e 53 45 52 54 20 49 4e 54 4f 20 65 78 61 6d INSERT INTO exam
0b20: 70 6c 65 20 28 69 64 2c 20 6e 61 6d 65 2c 20 76 ple (id, name, v
0b30: 61 6c 75 65 29 20 56 41 4c 55 45 53 20 28 4e 55 alue) VALUES (NU
0b40: 4c 4c 2c 20 27 74 68 69 72 64 27 2c 20 4e 55 4c LL, 'third', NUL
0b50: 4c 29 3b 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20 63 6f L);....--..-- co
0b60: 6d 6d 69 74 74 69 6e 67 20 74 68 65 20 70 65 6e mmitting the pen
0b70: 64 69 6e 67 20 54 72 61 6e 73 61 63 74 69 6f 6e ding Transaction
0b80: 0d 0a 2d 2d 0d 0a 43 4f 4d 4d 49 54 3b 0d 0a 0d ..--..COMMIT;...
0b90: 0a 2e 71 75 69 74 0d 0a 3c 2f 76 65 72 62 61 74 ..quit..</verbat
0ba0: 69 6d 3e 0d 0a 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e im>..<hr>..</li>
0bb0: 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 53 51 4c 20 ..<li>..<h4>SQL
0bc0: 56 61 72 69 61 62 6c 65 3c 2f 68 34 3e 0d 0a 41 Variable</h4>..A
0bd0: 20 3c 62 3e 3c 69 3e 53 51 4c 20 56 61 72 69 61 <b><i>SQL Varia
0be0: 62 6c 65 3c 2f 69 3e 3c 2f 62 3e 20 69 73 20 6a ble</i></b> is j
0bf0: 75 73 74 20 61 20 3c 69 3e 3c 75 3e 6d 6e 65 6d ust a <i><u>mnem
0c00: 6f 6e 69 63 20 73 79 6d 62 6f 6c 3c 2f 75 3e 3c onic symbol</u><
0c10: 2f 69 3e 20 65 6e 63 6c 6f 73 65 64 20 62 65 74 /i> enclosed bet
0c20: 77 65 65 6e 20 74 77 6f 20 3c 69 3e 3c 75 3e 73 ween two <i><u>s
0c30: 70 65 63 69 61 6c 20 6d 61 72 6b 65 72 73 3c 2f pecial markers</
0c40: 75 3e 3c 2f 69 3e 20 28 3c 62 3e 3c 69 3e 40 3c u></i> (<b><i>@<
0c50: 2f 69 3e 3c 2f 62 3e 20 6f 72 20 3c 62 3e 3c 69 /i></b> or <b><i
0c60: 3e 24 3c 2f 69 3e 3c 2f 62 3e 29 2e 20 45 78 61 >$</i></b>). Exa
0c70: 6d 70 6c 65 73 3a 0d 0a 3c 76 65 72 62 61 74 69 mples:..<verbati
0c80: 6d 3e 0d 0a 40 74 61 62 6c 65 5f 6e 61 6d 65 40 m>..@table_name@
0c90: 0d 0a 40 63 6f 6c 5f 6e 61 6d 65 40 0d 0a 24 76 ..@col_name@..$v
0ca0: 61 6c 75 65 24 0d 0a 24 72 61 64 69 75 73 24 0d alue$..$radius$.
0cb0: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 75 .</verbatim>..<u
0cc0: 3e 4e 6f 74 65 3c 2f 75 3e 3a 20 75 73 69 6e 67 >Note</u>: using
0cd0: 20 74 68 65 20 3c 62 3e 3c 69 3e 40 3c 2f 69 3e the <b><i>@</i>
0ce0: 3c 2f 62 3e 20 6f 72 20 74 68 65 20 3c 62 3e 3c </b> or the <b><
0cf0: 69 3e 24 3c 2f 69 3e 3c 2f 62 3e 20 6d 61 72 6b i>$</i></b> mark
0d00: 65 72 73 20 69 73 20 6a 75 73 74 20 61 6e 20 3c ers is just an <
0d10: 69 3e 3c 75 3e 61 65 73 74 68 65 74 69 63 20 63 i><u>aesthetic c
0d20: 68 6f 69 63 65 3c 2f 75 3e 3c 2f 69 3e 3b 20 62 hoice</u></i>; b
0d30: 6f 74 68 20 68 61 76 65 20 69 64 65 6e 74 69 63 oth have identic
0d40: 61 6c 20 6d 65 61 6e 69 6e 67 20 61 6e 64 20 70 al meaning and p
0d50: 72 61 63 74 69 63 61 6c 20 65 66 66 65 63 74 2e ractical effect.
0d60: 0d 0a 3c 62 72 3e 3c 62 72 3e 3c 68 72 3e 0d 0a ..<br><br><hr>..
0d70: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 </li>..<li>..<h4
0d80: 3e 53 51 4c 20 42 6f 64 79 3c 2f 68 34 3e 0d 0a >SQL Body</h4>..
0d90: 41 20 3c 62 3e 3c 69 3e 53 51 4c 20 53 63 72 69 A <b><i>SQL Scri
0da0: 70 74 3c 2f 69 3e 3c 2f 62 3e 20 69 6e 74 65 72 pt</i></b> inter
0db0: 6e 61 6c 6c 79 20 75 73 69 6e 67 20 3c 62 3e 3c nally using <b><
0dc0: 69 3e 56 61 72 69 61 62 6c 65 73 3c 2f 69 3e 3c i>Variables</i><
0dd0: 2f 62 3e 2e 20 45 78 61 6d 70 6c 65 3a 0d 0a 3c /b>. Example:..<
0de0: 76 65 72 62 61 74 69 6d 3e 0d 0a 2e 65 63 68 6f verbatim>...echo
0df0: 20 6f 6e 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20 73 74 on....--..-- st
0e00: 61 72 74 69 6e 67 20 61 20 54 72 61 6e 73 61 63 arting a Transac
0e10: 74 69 6f 6e 0d 0a 2d 2d 0d 0a 42 45 47 49 4e 3b tion..--..BEGIN;
0e20: 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20 63 72 65 61 74 ....--..-- creat
0e30: 69 6e 67 20 61 20 74 61 62 6c 65 0d 0a 2d 2d 0d ing a table..--.
0e40: 0a 43 52 45 41 54 45 20 54 41 42 4c 45 20 40 74 .CREATE TABLE @t
0e50: 61 62 6c 65 40 20 28 0d 0a 20 20 40 70 6b 40 20 able@ (.. @pk@
0e60: 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 INTEGER PRIMARY
0e70: 4b 45 59 20 41 55 54 4f 49 4e 43 52 45 4d 45 4e KEY AUTOINCREMEN
0e80: 54 2c 0d 0a 20 20 40 63 6f 6c 31 40 20 54 45 58 T,.. @col1@ TEX
0e90: 54 20 4e 4f 54 20 4e 55 4c 4c 2c 0d 0a 20 20 40 T NOT NULL,.. @
0ea0: 63 6f 6c 32 40 20 44 4f 55 42 4c 45 29 3b 0d 0a col2@ DOUBLE);..
0eb0: 0d 0a 2d 2d 0d 0a 2d 2d 20 70 6f 70 75 6c 61 74 ..--..-- populat
0ec0: 69 6e 67 20 74 68 65 20 74 61 62 6c 65 0d 0a 2d ing the table..-
0ed0: 2d 0d 0a 49 4e 53 45 52 54 20 49 4e 54 4f 20 40 -..INSERT INTO @
0ee0: 74 61 62 6c 65 40 20 28 40 70 6b 40 2c 20 40 63 table@ (@pk@, @c
0ef0: 6f 6c 31 40 2c 20 40 63 6f 6c 32 40 29 20 56 41 ol1@, @col2@) VA
0f00: 4c 55 45 53 20 28 4e 55 4c 4c 2c 20 27 66 69 72 LUES (NULL, 'fir
0f10: 73 74 27 2c 20 31 32 2e 33 34 29 3b 0d 0a 49 4e st', 12.34);..IN
0f20: 53 45 52 54 20 49 4e 54 4f 20 40 74 61 62 6c 65 SERT INTO @table
0f30: 40 20 28 40 70 6b 40 2c 20 40 63 6f 6c 31 40 2c @ (@pk@, @col1@,
0f40: 20 40 63 6f 6c 32 40 29 20 56 41 4c 55 45 53 20 @col2@) VALUES
0f50: 28 4e 55 4c 4c 2c 20 27 73 65 63 6f 6e 64 27 2c (NULL, 'second',
0f60: 20 35 36 2e 37 38 29 3b 0d 0a 49 4e 53 45 52 54 56.78);..INSERT
0f70: 20 49 4e 54 4f 20 40 74 61 62 6c 65 40 20 28 40 INTO @table@ (@
0f80: 70 6b 40 2c 20 40 63 6f 6c 32 40 2c 20 40 63 6f pk@, @col2@, @co
0f90: 6c 32 40 29 20 56 41 4c 55 45 53 20 28 4e 55 4c l2@) VALUES (NUL
0fa0: 4c 2c 20 27 74 68 69 72 64 27 2c 20 4e 55 4c 4c L, 'third', NULL
0fb0: 29 3b 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20 63 6f 6d );....--..-- com
0fc0: 6d 69 74 74 69 6e 67 20 74 68 65 20 70 65 6e 64 mitting the pend
0fd0: 69 6e 67 20 54 72 61 6e 73 61 63 74 69 6f 6e 0d ing Transaction.
0fe0: 0a 2d 2d 0d 0a 43 4f 4d 4d 49 54 3b 0d 0a 0d 0a .--..COMMIT;....
0ff0: 2e 71 75 69 74 0d 0a 3c 2f 76 65 72 62 61 74 69 .quit..</verbati
1000: 6d 3e 0d 0a 3c 75 3e 4e 6f 74 65 3c 2f 75 3e 3a m>..<u>Note</u>:
1010: 20 74 68 69 73 20 73 65 63 6f 6e 64 20 76 65 72 this second ver
1020: 73 69 6f 6e 20 69 73 20 6f 62 76 69 6f 75 73 6c sion is obviousl
1030: 79 20 6d 6f 72 65 20 66 6c 65 78 69 62 6c 65 20 y more flexible
1040: 74 68 61 6e 20 74 68 65 20 69 6e 69 74 69 61 6c than the initial
1050: 20 53 51 4c 20 73 63 72 69 70 74 2c 20 6a 75 73 SQL script, jus
1060: 74 20 62 65 63 61 75 73 65 20 74 68 65 72 65 20 t because there
1070: 61 72 65 6e 27 74 20 3c 75 3e 3c 69 3e 68 61 72 aren't <u><i>har
1080: 64 77 69 72 65 64 3c 2f 69 3e 3c 2f 75 3e 20 74 dwired</i></u> t
1090: 61 62 6c 65 2d 6e 61 6d 65 73 20 61 6e 64 20 63 able-names and c
10a0: 6f 6c 75 6d 6e 2d 6e 61 6d 65 73 2c 20 61 6c 6c olumn-names, all
10b0: 20 74 68 65 6d 20 61 72 65 20 6e 6f 77 20 62 65 them are now be
10c0: 63 6f 6d 65 20 3c 75 3e 3c 69 3e 73 79 6d 62 6f come <u><i>symbo
10d0: 6c 69 63 3c 2f 69 3e 3c 2f 75 3e 2e 3c 62 72 3e lic</i></u>.<br>
10e0: 0d 0a 53 6f 20 77 65 20 61 72 65 20 6e 6f 77 20 ..So we are now
10f0: 66 72 65 65 20 74 6f 20 72 65 75 73 65 20 6d 6f free to reuse mo
1100: 72 65 20 74 69 6d 65 73 20 74 68 69 73 20 53 51 re times this SQ
1110: 4c 20 42 6f 64 79 20 69 6e 20 64 69 66 66 65 72 L Body in differ
1120: 65 6e 74 20 63 6f 6e 74 65 78 74 73 3b 20 77 65 ent contexts; we
1130: 20 6a 75 73 74 20 68 61 76 65 20 74 6f 20 61 70 just have to ap
1140: 70 72 6f 70 72 69 61 74 65 6c 79 20 73 65 74 20 propriately set
1150: 74 68 65 20 56 61 72 69 61 62 6c 65 20 56 61 6c the Variable Val
1160: 75 65 73 20 6a 75 73 74 20 69 6d 6d 65 64 69 61 ues just immedia
1170: 74 65 6c 79 20 62 65 66 6f 72 65 20 61 63 74 75 tely before actu
1180: 61 6c 20 65 78 65 63 75 74 69 6f 6e 2e 3c 62 72 al execution.<br
1190: 3e 3c 62 72 3e 0d 0a 3c 62 3e 3c 69 3e 53 51 4c ><br>..<b><i>SQL
11a0: 20 42 6f 64 69 65 73 3c 2f 69 3e 3c 2f 62 3e 20 Bodies</i></b>
11b0: 65 78 69 73 74 20 69 6e 20 74 77 6f 20 64 69 66 exist in two dif
11c0: 66 65 72 65 6e 74 20 66 6f 72 6d 73 3a 0d 0a 3c ferent forms:..<
11d0: 75 6c 3e 0d 0a 3c 6c 69 3e 3c 62 3e 72 61 77 3c ul>..<li><b>raw<
11e0: 2f 62 3e 3a 20 73 74 69 6c 6c 20 69 6e 63 6c 75 /b>: still inclu
11f0: 64 69 6e 67 20 73 79 6d 62 6f 6c 69 63 20 56 61 ding symbolic Va
1200: 72 69 61 62 6c 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c riables.</li>..<
1210: 6c 69 3e 3c 62 3e 63 6f 6f 6b 65 64 3c 2f 62 3e li><b>cooked</b>
1220: 3a 20 70 72 65 73 65 6e 74 69 6e 67 20 61 6c 6c : presenting all
1230: 20 73 79 6d 62 6f 6c 73 20 70 72 6f 70 65 72 6c symbols properl
1240: 79 20 72 65 70 6c 61 63 65 64 20 62 79 20 74 68 y replaced by th
1250: 65 69 72 20 61 63 74 75 61 6c 20 76 61 6c 75 65 eir actual value
1260: 73 2e 3c 62 72 3e 0d 0a 52 61 74 68 65 72 20 6f s.<br>..Rather o
1270: 62 76 69 6f 75 73 6c 79 2c 20 79 6f 75 20 63 61 bviously, you ca
1280: 6e 20 73 75 63 63 65 73 73 66 75 6c 6c 79 20 65 n successfully e
1290: 78 65 63 75 74 65 20 6f 6e 6c 79 20 74 68 65 20 xecute only the
12a0: 3c 62 3e 3c 69 3e 63 6f 6f 6b 65 64 3c 2f 69 3e <b><i>cooked</i>
12b0: 3c 2f 62 3e 20 66 6f 72 6d 2e 3c 2f 6c 69 3e 0d </b> form.</li>.
12c0: 0a 3c 2f 75 6c 3e 0d 0a 3c 62 72 3e 3c 68 72 3e .</ul>..<br><hr>
12d0: 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c ..</li>..<li>..<
12e0: 68 34 3e 53 51 4c 20 50 72 6f 63 65 64 75 72 65 h4>SQL Procedure
12f0: 20 42 4c 4f 42 20 6f 62 6a 65 63 74 3c 2f 68 34 BLOB object</h4
1300: 3e 0d 0a 54 68 69 73 20 73 69 6d 70 6c 79 20 69 >..This simply i
1310: 73 20 61 20 3c 62 3e 3c 69 3e 42 4c 4f 42 20 65 s a <b><i>BLOB e
1320: 6e 63 6f 64 65 64 3c 2f 69 3e 3c 2f 62 3e 20 70 ncoded</i></b> p
1330: 72 65 2d 63 6f 6d 70 69 6c 65 64 20 3c 62 3e 3c re-compiled <b><
1340: 69 3e 53 51 4c 20 42 6f 64 79 3c 2f 69 3e 3c 2f i>SQL Body</i></
1350: 62 3e 2c 20 61 6e 64 20 69 73 20 74 68 65 20 75 b>, and is the u
1360: 73 75 61 6c 20 74 61 72 67 65 74 20 65 78 70 65 sual target expe
1370: 63 74 65 64 20 74 6f 20 62 65 20 68 61 6e 64 6c cted to be handl
1380: 65 64 20 62 79 20 70 72 61 63 74 69 63 61 6c 6c ed by practicall
1390: 79 20 61 6c 6c 20 53 51 4c 20 66 75 6e 63 74 69 y all SQL functi
13a0: 6f 6e 73 20 73 75 70 70 6f 72 74 69 6e 67 20 53 ons supporting S
13b0: 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65 73 tored Procedures
13c0: 20 61 6e 64 20 61 6c 69 6b 65 2e 0d 0a 3c 62 72 and alike...<br
13d0: 3e 3c 62 72 3e 3c 68 72 3e 20 0d 0a 3c 2f 6c 69 ><br><hr> ..</li
13e0: 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 53 74 6f >..<li>..<h4>Sto
13f0: 72 65 64 20 50 72 6f 63 65 64 75 72 65 3c 2f 68 red Procedure</h
1400: 34 3e 0d 0a 41 20 3c 62 3e 3c 69 3e 53 51 4c 20 4>..A <b><i>SQL
1410: 50 72 6f 63 65 64 75 72 65 20 42 4c 4f 42 20 6f Procedure BLOB o
1420: 62 6a 65 63 74 3c 2f 69 3e 3c 2f 62 3e 20 70 65 bject</i></b> pe
1430: 72 6d 61 6e 65 6e 74 6c 79 20 73 74 6f 72 65 64 rmanently stored
1440: 20 69 6e 74 6f 20 61 20 64 61 74 61 62 61 73 65 into a database
1450: 2e 20 54 68 69 73 20 77 69 6c 6c 20 6d 61 6b 65 . This will make
1460: 20 65 61 73 69 65 72 20 72 65 75 73 69 6e 67 20 easier reusing
1470: 6d 6f 72 65 20 74 69 6d 65 73 20 74 68 65 20 73 more times the s
1480: 61 6d 65 20 53 51 4c 20 77 6f 72 6b 66 6c 6f 77 ame SQL workflow
1490: 2c 20 70 65 72 68 61 70 73 20 73 6f 20 74 6f 20 , perhaps so to
14a0: 69 6d 70 6c 65 6d 65 6e 74 20 72 6f 75 74 69 6e implement routin
14b0: 65 6c 79 20 70 65 72 69 6f 64 69 63 20 74 61 73 ely periodic tas
14c0: 6b 73 20 28 74 6f 20 62 65 20 65 78 65 63 75 74 ks (to be execut
14d0: 65 64 20 64 61 69 6c 79 20 2f 20 77 65 65 6b 6c ed daily / weekl
14e0: 79 20 2f 20 6d 6f 6e 74 68 6c 79 20 61 6e 64 20 y / monthly and
14f0: 73 6f 20 6f 6e 29 2e 3c 62 72 3e 0d 0a 53 74 6f so on).<br>..Sto
1500: 72 65 64 20 50 72 6f 63 65 64 75 72 65 73 20 61 red Procedures a
1510: 6c 77 61 79 73 20 68 61 76 65 20 74 68 65 20 66 lways have the f
1520: 6f 6c 6c 6f 77 69 6e 67 20 65 6c 65 6d 65 6e 74 ollowing element
1530: 73 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 20 s:..<ul>..<li>a
1540: 3c 62 3e 6e 61 6d 65 3c 2f 62 3e 2c 20 69 6e 74 <b>name</b>, int
1550: 65 6e 64 65 64 20 74 6f 20 62 65 20 61 6e 20 75 ended to be an u
1560: 6e 69 71 75 65 20 69 64 65 6e 74 69 66 69 65 72 nique identifier
1570: 20 28 3c 62 3e 3c 69 3e 50 72 69 6d 61 72 79 20 (<b><i>Primary
1580: 4b 65 79 3c 2f 69 3e 3c 2f 62 3e 29 2e 3c 2f 6c Key</i></b>).</l
1590: 69 3e 0d 0a 3c 6c 69 3e 61 20 3c 62 3e 74 69 74 i>..<li>a <b>tit
15a0: 6c 65 3c 2f 62 3e 2c 20 69 2e 65 2e 20 61 20 73 le</b>, i.e. a s
15b0: 68 6f 72 74 20 64 65 73 63 72 69 70 74 69 6f 6e hort description
15c0: 20 6f 66 20 74 68 65 20 69 6e 74 65 6e 64 65 64 of the intended
15d0: 20 73 63 6f 70 65 20 6f 66 20 74 68 65 20 53 74 scope of the St
15e0: 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65 2e 3c ored Procedure.<
15f0: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 3c 62 3e 53 /li>..<li>a <b>S
1600: 51 4c 20 50 72 6f 63 65 64 75 72 65 20 42 4c 4f QL Procedure BLO
1610: 42 20 4f 62 6a 65 63 74 3c 2f 62 3e 2e 3c 2f 6c B Object</b>.</l
1620: 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 62 72 3e 3c i>..</ul>..<br><
1630: 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e hr>..</li>..<li>
1640: 0d 0a 3c 68 34 3e 56 61 72 69 61 62 6c 65 20 77 ..<h4>Variable w
1650: 69 74 68 20 56 61 6c 75 65 20 73 74 72 69 6e 67 ith Value string
1660: 73 3c 2f 68 34 3e 0d 0a 42 65 66 6f 72 65 20 65 s</h4>..Before e
1670: 78 65 63 75 74 69 6e 67 20 61 20 3c 62 3e 3c 69 xecuting a <b><i
1680: 3e 53 51 4c 20 42 6f 64 79 3c 2f 69 3e 3c 2f 62 >SQL Body</i></b
1690: 3e 20 69 6e 63 6c 75 64 69 6e 67 20 3c 62 3e 3c > including <b><
16a0: 69 3e 56 61 72 69 61 62 6c 65 73 3c 2f 69 3e 3c i>Variables</i><
16b0: 2f 62 3e 20 79 6f 75 20 61 72 65 20 6f 62 76 69 /b> you are obvi
16c0: 6f 75 73 6c 79 20 65 78 70 65 63 74 65 64 20 74 ously expected t
16d0: 6f 20 73 65 74 20 73 6f 6d 65 20 61 70 70 72 6f o set some appro
16e0: 70 72 69 61 74 65 20 3c 62 3e 3c 69 3e 56 61 6c priate <b><i>Val
16f0: 75 65 3c 2f 69 3e 3c 2f 62 3e 20 66 6f 72 20 65 ue</i></b> for e
1700: 61 63 68 20 56 61 72 69 61 62 6c 65 2c 20 73 6f ach Variable, so
1710: 20 74 6f 20 61 6c 6c 6f 77 20 66 6f 72 20 72 65 to allow for re
1720: 70 6c 61 63 69 6e 67 20 3c 75 3e 3c 69 3e 53 79 placing <u><i>Sy
1730: 6d 62 6f 6c 73 3c 2f 69 3e 3c 2f 75 3e 20 77 69 mbols</i></u> wi
1740: 74 68 20 61 63 74 75 61 6c 20 3c 75 3e 3c 69 3e th actual <u><i>
1750: 56 61 6c 75 65 73 3c 2f 69 3e 3c 2f 75 3e 20 28 Values</i></u> (
1760: 69 2e 65 2e 20 66 6f 72 20 70 72 6f 70 65 72 6c i.e. for properl
1770: 79 20 74 72 61 6e 73 66 6f 72 6d 69 6e 67 20 3c y transforming <
1780: 62 3e 72 61 77 3c 2f 62 3e 20 53 51 4c 20 69 6e b>raw</b> SQL in
1790: 74 6f 20 3c 62 3e 63 6f 6f 6b 65 64 3c 2f 62 3e to <b>cooked</b>
17a0: 20 53 51 4c 29 2e 3c 62 72 3e 0d 0a 41 20 3c 62 SQL).<br>..A <b
17b0: 3e 3c 69 3e 56 61 72 69 61 62 6c 65 20 77 69 74 ><i>Variable wit
17c0: 68 20 56 61 6c 75 65 3c 2f 69 3e 3c 2f 62 3e 20 h Value</i></b>
17d0: 73 74 72 69 6e 67 20 73 69 6d 70 6c 79 20 69 73 string simply is
17e0: 20 61 6e 20 61 70 70 72 6f 70 72 69 61 74 65 6c an appropriatel
17f0: 79 20 77 65 6c 6c 2d 66 6f 72 6d 61 74 74 65 64 y well-formatted
1800: 20 54 65 78 74 20 73 74 72 69 6e 67 20 64 65 63 Text string dec
1810: 6c 61 72 69 6e 67 20 62 6f 74 68 20 74 68 65 20 laring both the
1820: 53 79 6d 62 6f 6c 20 61 6e 64 20 74 68 65 20 63 Symbol and the c
1830: 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 72 65 70 orresponding rep
1840: 6c 61 63 65 6d 65 6e 74 20 56 61 6c 75 65 20 28 lacement Value (
1850: 65 78 70 72 65 73 73 65 64 20 69 6e 20 69 74 73 expressed in its
1860: 20 74 65 78 74 75 61 6c 20 72 65 70 72 65 73 65 textual represe
1870: 6e 74 61 74 69 6f 6e 29 2e 20 45 78 61 6d 70 6c ntation). Exampl
1880: 65 73 3a 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d es:..<verbatim>.
1890: 0a 40 76 61 6c 75 65 5f 31 40 3d 31 32 33 34 20 .@value_1@=1234
18a0: 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 69 6e -- in
18b0: 74 65 67 65 72 20 76 61 6c 75 65 0d 0a 40 76 61 teger value..@va
18c0: 6c 75 65 5f 32 40 3d 31 32 2e 33 34 20 20 20 20 lue_2@=12.34
18d0: 20 20 20 20 20 20 20 2d 2d 20 64 6f 75 62 6c 65 -- double
18e0: 20 76 61 6c 75 65 0d 0a 40 76 61 6c 75 65 5f 33 value..@value_3
18f0: 40 3d 4e 65 77 20 59 6f 72 6b 20 43 69 74 79 20 @=New York City
1900: 20 20 2d 2d 20 74 65 78 74 20 76 61 6c 75 65 0d -- text value.
1910: 0a 40 76 61 6c 75 65 5f 34 40 3d 78 27 30 31 32 .@value_4@=x'012
1920: 33 61 62 63 64 27 20 20 20 20 20 2d 2d 20 62 6c 3abcd' -- bl
1930: 6f 62 20 76 61 6c 75 65 0d 0a 40 76 61 6c 75 65 ob value..@value
1940: 5f 35 40 3d 4e 55 4c 4c 20 20 20 20 20 20 20 20 _5@=NULL
1950: 20 20 20 20 2d 2d 20 6e 75 6c 6c 20 76 61 6c 75 -- null valu
1960: 65 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a e..</verbatim>..
1970: 3c 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 <table bgcolor="
1980: 23 66 38 66 38 64 38 22 20 63 65 6c 6c 70 61 64 #f8f8d8" cellpad
1990: 64 69 6e 67 3d 22 36 22 20 63 65 6c 6c 73 70 61 ding="6" cellspa
19a0: 63 69 6e 67 3d 22 38 22 3e 3c 74 72 3e 3c 74 64 cing="8"><tr><td
19b0: 3e 0d 0a 3c 75 3e 4e 6f 74 65 3c 2f 75 3e 3a 20 >..<u>Note</u>:
19c0: 72 65 70 6c 61 63 69 6e 67 20 56 61 72 69 61 62 replacing Variab
19d0: 6c 65 73 20 77 69 74 68 20 61 63 74 75 61 6c 20 les with actual
19e0: 56 61 6c 75 65 73 20 69 73 20 61 20 62 6c 69 6e Values is a blin
19f0: 64 20 70 72 6f 63 65 73 73 20 63 6f 6d 70 6c 65 d process comple
1a00: 74 65 6c 79 20 69 6e 73 65 6e 73 69 62 6c 65 20 tely insensible
1a10: 74 6f 20 74 68 65 20 73 70 65 63 69 66 69 63 20 to the specific
1a20: 73 79 6e 74 61 63 74 69 63 20 63 6f 6e 74 65 78 syntactic contex
1a30: 74 2e 3c 62 72 3e 0d 0a 59 6f 75 20 61 72 65 20 t.<br>..You are
1a40: 66 75 6c 6c 79 20 72 65 73 70 6f 6e 73 69 62 6c fully responsibl
1a50: 65 20 66 6f 72 20 63 6f 72 72 65 63 74 6c 79 20 e for correctly
1a60: 61 70 70 6c 79 20 73 69 6e 67 6c 65 2d 20 6f 72 apply single- or
1a70: 20 64 6f 75 62 6c 65 2d 71 75 6f 74 69 6e 67 20 double-quoting
1a80: 77 68 65 72 65 76 65 72 20 72 65 71 75 69 72 65 wherever require
1a90: 64 20 62 79 20 53 51 4c 20 73 79 6e 74 61 78 2e d by SQL syntax.
1aa0: 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 ..</td></tr></ta
1ab0: 62 6c 65 3e 0d 0a 3c 62 72 3e 3c 68 72 3e 0d 0a ble>..<br><hr>..
1ac0: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 </li>..<li>..<h4
1ad0: 3e 53 74 6f 72 65 64 20 56 61 72 69 61 62 6c 65 >Stored Variable
1ae0: 3c 2f 68 34 3e 0d 0a 41 20 3c 62 3e 3c 69 3e 56 </h4>..A <b><i>V
1af0: 61 72 69 61 62 6c 65 20 77 69 74 68 20 56 61 6c ariable with Val
1b00: 75 65 20 73 74 72 69 6e 67 3c 2f 69 3e 3c 2f 62 ue string</i></b
1b10: 3e 20 70 65 72 6d 61 6e 65 6e 74 6c 79 20 73 74 > permanently st
1b20: 6f 72 65 64 20 69 6e 74 6f 20 61 20 64 61 74 61 ored into a data
1b30: 62 61 73 65 2e 3c 62 72 3e 0d 0a 53 74 6f 72 65 base.<br>..Store
1b40: 64 20 56 61 72 69 61 62 6c 65 73 20 61 6c 77 61 d Variables alwa
1b50: 79 73 20 68 61 76 65 20 74 68 65 20 66 6f 6c 6c ys have the foll
1b60: 6f 77 69 6e 67 20 65 6c 65 6d 65 6e 74 73 3a 0d owing elements:.
1b70: 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 20 3c 62 3e .<ul>..<li>a <b>
1b80: 6e 61 6d 65 3c 2f 62 3e 2c 20 69 6e 74 65 6e 64 name</b>, intend
1b90: 65 64 20 74 6f 20 62 65 20 61 6e 20 75 6e 69 71 ed to be an uniq
1ba0: 75 65 20 69 64 65 6e 74 69 66 69 65 72 20 28 3c ue identifier (<
1bb0: 62 3e 3c 69 3e 50 72 69 6d 61 72 79 20 4b 65 79 b><i>Primary Key
1bc0: 3c 2f 69 3e 3c 2f 62 3e 29 2e 3c 2f 6c 69 3e 0d </i></b>).</li>.
1bd0: 0a 3c 6c 69 3e 61 20 3c 62 3e 74 69 74 6c 65 3c .<li>a <b>title<
1be0: 2f 62 3e 2c 20 69 2e 65 2e 20 61 20 73 68 6f 72 /b>, i.e. a shor
1bf0: 74 20 64 65 73 63 72 69 70 74 69 6f 6e 20 6f 66 t description of
1c00: 20 74 68 65 20 69 6e 74 65 6e 64 65 64 20 73 63 the intended sc
1c10: 6f 70 65 20 6f 66 20 74 68 65 20 53 74 6f 72 65 ope of the Store
1c20: 64 20 56 61 72 69 61 62 6c 65 2e 3c 2f 6c 69 3e d Variable.</li>
1c30: 0d 0a 3c 6c 69 3e 61 20 3c 62 3e 56 61 72 69 61 ..<li>a <b>Varia
1c40: 62 6c 65 20 77 69 74 68 20 56 61 6c 75 65 20 73 ble with Value s
1c50: 74 72 69 6e 67 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d tring</b>.</li>.
1c60: 0a 3c 2f 75 6c 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c .</ul>..</li>..<
1c70: 2f 6c 69 3e 0d 0a 3c 2f 6f 6c 3e 3c 62 72 3e 0d /li>..</ol><br>.
1c80: 0a 3c 68 72 3e 0d 0a 3c 68 32 3e 46 61 6d 69 6c .<hr>..<h2>Famil
1c90: 69 61 72 69 7a 69 6e 67 20 77 69 74 68 20 53 51 iarizing with SQ
1ca0: 4c 20 46 75 6e 63 74 69 6f 6e 73 3c 2f 68 32 3e L Functions</h2>
1cb0: 0d 0a 3c 6f 6c 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 ..<ol>..<li>..<h
1cc0: 34 3e 48 61 6e 64 6c 69 6e 67 20 53 51 4c 20 50 4>Handling SQL P
1cd0: 72 6f 63 65 64 75 72 65 20 42 4c 4f 42 20 6f 62 rocedure BLOB ob
1ce0: 6a 65 63 74 73 3c 2f 68 34 3e 0d 0a 3c 76 65 72 jects</h4>..<ver
1cf0: 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 batim>..SELECT S
1d00: 71 6c 50 72 6f 63 5f 46 72 6f 6d 54 65 78 74 28 qlProc_FromText(
1d10: 27 53 45 4c 45 43 54 20 40 63 6f 6c 40 20 46 52 'SELECT @col@ FR
1d20: 4f 4d 20 40 74 62 6c 40 27 29 3b 0d 0a 0d 0a 53 OM @tbl@');....S
1d30: 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 46 72 ELECT SqlProc_Fr
1d40: 6f 6d 46 69 6c 65 28 27 2f 68 6f 6d 65 2f 6a 6f omFile('/home/jo
1d50: 65 2f 74 65 6d 70 6c 61 74 65 2e 74 78 74 27 2c e/template.txt',
1d60: 20 43 50 31 32 35 32 27 29 3b 0d 0a 3c 2f 76 65 CP1252');..</ve
1d70: 72 62 61 74 69 6d 3e 0d 0a 3c 75 6c 3e 0d 0a 3c rbatim>..<ul>..<
1d80: 6c 69 3e 79 6f 75 20 63 61 6e 20 63 72 65 61 74 li>you can creat
1d90: 65 20 61 20 53 51 4c 20 50 72 6f 63 65 64 75 72 e a SQL Procedur
1da0: 65 20 42 4c 4f 42 20 6f 62 6a 65 63 74 20 62 79 e BLOB object by
1db0: 20 64 69 72 65 63 74 6c 79 20 70 61 73 73 69 6e directly passin
1dc0: 67 20 61 20 54 65 78 74 20 53 51 4c 20 42 6f 64 g a Text SQL Bod
1dd0: 79 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 6f 72 20 y.</li>..<li>or
1de0: 61 6c 74 65 72 6e 61 74 69 76 65 6c 79 20 79 6f alternatively yo
1df0: 75 20 63 61 6e 20 6c 6f 61 64 20 74 68 65 20 53 u can load the S
1e00: 51 4c 20 42 6f 64 79 20 66 72 6f 6d 20 61 6e 20 QL Body from an
1e10: 65 78 74 65 72 6e 61 6c 20 66 69 6c 65 2e 3c 62 external file.<b
1e20: 72 3e 0d 0a 3c 75 3e 4e 6f 74 65 3c 2f 75 3e 3a r>..<u>Note</u>:
1e30: 20 74 68 69 73 20 69 73 20 61 20 73 65 63 75 72 this is a secur
1e40: 69 74 79 20 73 65 6e 73 69 62 6c 65 20 6f 70 65 ity sensible ope
1e50: 72 61 74 69 6f 6e 2c 20 73 6f 20 79 6f 75 20 61 ration, so you a
1e60: 6c 77 61 79 73 20 6e 65 65 64 20 74 6f 20 73 65 lways need to se
1e70: 74 20 61 6e 20 65 78 70 6c 69 63 69 74 20 61 75 t an explicit au
1e80: 74 68 6f 72 69 7a 61 74 69 6f 6e 20 62 79 20 64 thorization by d
1e90: 65 66 69 6e 69 6e 67 20 3c 62 3e 53 50 41 54 49 efining <b>SPATI
1ea0: 41 4c 49 54 45 5f 53 45 43 55 52 49 54 59 3d 72 ALITE_SECURITY=r
1eb0: 65 6c 61 78 65 64 3c 2f 62 3e 2e 3c 2f 6c 69 3e elaxed</b>.</li>
1ec0: 0d 0a 3c 6c 69 3e 42 6f 74 68 20 66 75 6e 63 74 ..<li>Both funct
1ed0: 69 6f 6e 73 20 61 63 63 65 70 74 20 61 6e 20 6f ions accept an o
1ee0: 70 74 69 6f 6e 61 6c 20 3c 62 3e 63 68 61 72 73 ptional <b>chars
1ef0: 65 74 20 65 6e 63 6f 64 69 6e 67 3c 2f 62 3e 20 et encoding</b>
1f00: 61 72 67 75 6d 65 6e 74 3b 20 69 6e 20 74 68 69 argument; in thi
1f10: 73 20 63 61 73 65 20 74 68 65 20 53 51 4c 20 42 s case the SQL B
1f20: 6f 64 79 20 77 69 6c 6c 20 62 65 20 61 70 70 72 ody will be appr
1f30: 6f 70 72 69 61 74 65 6c 79 20 63 6f 6e 76 65 72 opriately conver
1f40: 74 65 64 20 66 72 6f 6d 20 74 68 65 20 67 69 76 ted from the giv
1f50: 65 6e 20 63 68 61 72 73 65 74 20 69 6e 74 6f 20 en charset into
1f60: 3c 62 3e 55 54 46 2d 38 3c 2f 62 3e 2e 3c 2f 6c <b>UTF-8</b>.</l
1f70: 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 76 65 72 62 i>..</ul>..<verb
1f80: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 71 atim>..SELECT Sq
1f90: 6c 50 72 6f 63 5f 49 73 56 61 6c 69 64 20 28 20 lProc_IsValid (
1fa0: 53 71 6c 50 72 6f 63 5f 46 72 6f 6d 54 65 78 74 SqlProc_FromText
1fb0: 28 27 53 45 4c 45 43 54 20 40 63 6f 6c 40 20 46 ('SELECT @col@ F
1fc0: 52 4f 4d 20 40 74 62 6c 40 27 29 20 29 3b 0d 0a ROM @tbl@') );..
1fd0: 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a 53 45 4c 45 -----..1....SELE
1fe0: 43 54 20 53 71 6c 50 72 6f 63 5f 49 73 56 61 6c CT SqlProc_IsVal
1ff0: 69 64 20 28 20 4d 61 6b 65 50 6f 69 6e 74 28 31 id ( MakePoint(1
2000: 31 2e 35 2c 20 34 32 2e 35 2c 20 34 33 32 36 29 1.5, 42.5, 4326)
2010: 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 30 0d 0a 3c );..-----..0..<
2020: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 75 6c 3e /verbatim>..<ul>
2030: 0d 0a 3c 6c 69 3e 79 6f 75 20 63 61 6e 20 75 73 ..<li>you can us
2040: 65 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 49 73 56 e <b>SqlProc_IsV
2050: 61 6c 69 64 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 alid</b> in orde
2060: 72 20 74 6f 20 63 68 65 63 6b 20 69 66 20 61 20 r to check if a
2070: 67 65 6e 65 72 69 63 20 42 4c 4f 42 20 72 65 61 generic BLOB rea
2080: 6c 6c 79 20 69 73 20 61 20 76 61 6c 69 64 20 53 lly is a valid S
2090: 51 4c 20 50 72 6f 63 65 64 75 72 65 20 42 4c 4f QL Procedure BLO
20a0: 42 20 4f 62 6a 65 63 74 2e 0d 0a 3c 2f 75 6c 3e B Object...</ul>
20b0: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 ..<verbatim>..SE
20c0: 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 4e 75 6d LECT SqlProc_Num
20d0: 56 61 72 69 61 62 6c 65 73 20 28 20 53 71 6c 50 Variables ( SqlP
20e0: 72 6f 63 5f 46 72 6f 6d 54 65 78 74 28 27 53 45 roc_FromText('SE
20f0: 4c 45 43 54 20 40 63 6f 6c 40 20 46 52 4f 4d 20 LECT @col@ FROM
2100: 40 74 62 6c 40 27 29 20 29 3b 0d 0a 2d 2d 2d 2d @tbl@') );..----
2110: 2d 0d 0a 32 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 -..2....SELECT S
2120: 71 6c 50 72 6f 63 5f 56 61 72 69 61 62 6c 65 4e qlProc_VariableN
2130: 20 28 53 71 6c 50 72 6f 63 5f 46 72 6f 6d 54 65 (SqlProc_FromTe
2140: 78 74 28 27 53 45 4c 45 43 54 20 40 63 6f 6c 40 xt('SELECT @col@
2150: 20 46 52 4f 4d 20 40 74 62 6c 40 27 29 2c 20 30 FROM @tbl@'), 0
2160: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 40 63 6f 6c 40 );..-----..@col@
2170: 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 ....SELECT SqlPr
2180: 6f 63 5f 56 61 72 69 61 62 6c 65 4e 20 28 53 71 oc_VariableN (Sq
2190: 6c 50 72 6f 63 5f 46 72 6f 6d 54 65 78 74 28 27 lProc_FromText('
21a0: 53 45 4c 45 43 54 20 40 63 6f 6c 40 20 46 52 4f SELECT @col@ FRO
21b0: 4d 20 40 74 62 6c 40 27 29 2c 20 31 29 3b 0d 0a M @tbl@'), 1);..
21c0: 2d 2d 2d 2d 2d 0d 0a 40 74 62 6c 40 0d 0a 0d 0a -----..@tbl@....
21d0: 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 41 SELECT SqlProc_A
21e0: 6c 6c 56 61 72 69 61 62 6c 65 73 20 28 53 71 6c llVariables (Sql
21f0: 50 72 6f 63 5f 46 72 6f 6d 54 65 78 74 28 27 53 Proc_FromText('S
2200: 45 4c 45 43 54 20 40 63 6f 6c 40 20 46 52 4f 4d ELECT @col@ FROM
2210: 20 40 74 62 6c 40 27 29 20 29 3b 0d 0a 2d 2d 2d @tbl@') );..---
2220: 2d 2d 0d 0a 40 63 6f 6c 40 20 40 74 62 6c 40 0d --..@col@ @tbl@.
2230: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 75 .</verbatim>..<u
2240: 6c 3e 0d 0a 3c 6c 69 3e 79 6f 75 20 63 61 6e 20 l>..<li>you can
2250: 75 73 65 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 4e use <b>SqlProc_N
2260: 75 6d 56 61 72 69 61 62 6c 65 73 3c 2f 62 3e 20 umVariables</b>
2270: 69 6e 20 6f 72 64 65 72 20 74 6f 20 63 68 65 63 in order to chec
2280: 6b 20 68 6f 77 20 6d 61 6e 79 20 56 61 72 69 61 k how many Varia
2290: 62 6c 65 73 20 61 72 65 20 64 65 66 69 6e 65 64 bles are defined
22a0: 20 62 79 20 61 20 53 51 4c 20 50 72 6f 63 65 64 by a SQL Proced
22b0: 75 72 65 20 42 4c 4f 42 20 4f 62 6a 65 63 74 2e ure BLOB Object.
22c0: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 64 20 79 </li>..<li>and y
22d0: 6f 75 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 71 ou can use <b>Sq
22e0: 6c 50 72 6f 63 5f 56 61 72 69 61 62 6c 65 4e 3c lProc_VariableN<
22f0: 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 /b> in order to
2300: 72 65 74 72 69 65 76 65 20 61 20 56 61 72 69 61 retrieve a Varia
2310: 62 6c 65 20 4e 61 6d 65 20 62 79 20 73 70 65 63 ble Name by spec
2320: 69 66 79 69 6e 67 20 69 74 73 20 72 65 6c 61 74 ifying its relat
2330: 69 76 65 20 3c 62 3e 49 6e 64 65 78 3c 2f 62 3e ive <b>Index</b>
2340: 20 28 46 69 72 73 74 20 56 61 72 69 61 62 6c 65 (First Variable
2350: 20 61 6c 77 61 79 73 20 63 6f 72 72 65 73 70 6f always correspo
2360: 6e 64 73 20 74 6f 20 3c 62 3e 49 6e 64 65 78 3d nds to <b>Index=
2370: 30 3c 2f 62 3e 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 0</b>).</li>..<l
2380: 69 3e 61 6e 64 20 66 69 6e 61 6c 6c 79 20 79 6f i>and finally yo
2390: 75 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 71 6c u can use <b>Sql
23a0: 50 72 6f 63 5f 41 6c 6c 56 61 72 69 61 62 6c 65 Proc_AllVariable
23b0: 73 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74 s</b> in order t
23c0: 6f 20 64 69 72 65 63 74 6c 79 20 67 65 74 20 61 o directly get a
23d0: 6c 6c 20 56 61 72 69 61 62 6c 65 20 4e 61 6d 65 ll Variable Name
23e0: 73 20 66 6f 72 6d 61 74 74 65 64 20 61 73 20 61 s formatted as a
23f0: 20 73 70 61 63 65 2d 73 65 70 61 72 61 74 65 64 space-separated
2400: 20 6c 69 73 74 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 list.</li>..</u
2410: 6c 3e 0d 0a 3c 62 72 3e 3c 68 72 3e 0d 0a 3c 2f l>..<br><hr>..</
2420: 6c 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 45 li>..<li>..<h4>E
2430: 72 72 6f 72 20 68 61 6e 64 6c 69 6e 67 3c 2f 68 rror handling</h
2440: 34 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 4>..<verbatim>..
2450: 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 47 SELECT SqlProc_G
2460: 65 74 4c 61 73 74 45 72 72 6f 72 28 29 3b 0d 0a etLastError();..
2470: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 41 6c 6c </verbatim>..All
2480: 20 74 68 65 73 65 20 66 75 6e 63 74 69 6f 6e 73 these functions
2490: 20 77 69 6c 6c 20 72 61 69 73 65 20 61 6e 20 45 will raise an E
24a0: 78 63 65 70 74 69 6f 6e 20 6f 6e 20 69 6e 76 61 xception on inva
24b0: 6c 69 64 20 61 72 67 75 6d 65 6e 74 73 20 6f 72 lid arguments or
24c0: 20 65 72 72 6f 72 73 2e 3c 62 72 3e 0d 0a 42 79 errors.<br>..By
24d0: 20 63 61 6c 6c 69 6e 67 20 3c 62 3e 53 71 6c 50 calling <b>SqlP
24e0: 72 6f 63 5f 47 65 74 4c 61 73 74 45 72 72 6f 72 roc_GetLastError
24f0: 3c 2f 62 3e 20 79 6f 75 27 6c 6c 20 75 73 75 61 </b> you'll usua
2500: 6c 6c 79 20 67 65 74 20 61 20 6d 6f 72 65 20 64 lly get a more d
2510: 65 74 61 69 6c 65 64 20 65 78 70 6c 61 6e 61 74 etailed explanat
2520: 69 6f 6e 20 61 62 6f 75 74 20 74 68 65 20 73 70 ion about the sp
2530: 65 63 69 66 69 63 20 63 61 75 73 65 20 61 63 63 ecific cause acc
2540: 6f 75 6e 74 69 6e 67 20 66 6f 72 20 74 68 65 20 ounting for the
2550: 66 61 69 6c 75 72 65 2e 0d 0a 3c 62 72 3e 3c 62 failure...<br><b
2560: 72 3e 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c r><hr>..</li>..<
2570: 6c 69 3e 0d 0a 3c 68 34 3e 43 72 65 61 74 69 6e li>..<h4>Creatin
2580: 67 20 56 61 72 69 61 62 6c 65 73 20 77 69 74 68 g Variables with
2590: 20 56 61 6c 75 65 73 3c 2f 68 34 3e 0d 0a 3c 76 Values</h4>..<v
25a0: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 erbatim>..SELECT
25b0: 20 53 71 6c 50 72 6f 63 5f 56 61 72 56 61 6c 75 SqlProc_VarValu
25c0: 65 20 28 27 76 61 72 27 2c 20 4e 55 4c 4c 29 3b e ('var', NULL);
25d0: 0d 0a 2d 2d 2d 2d 2d 0d 0a 40 76 61 72 40 3d 4e ..-----..@var@=N
25e0: 55 4c 4c 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 71 ULL....SELECT Sq
25f0: 6c 50 72 6f 63 5f 56 61 72 56 61 6c 75 65 20 28 lProc_VarValue (
2600: 27 76 61 72 27 2c 20 31 29 3b 0d 0a 2d 2d 2d 2d 'var', 1);..----
2610: 2d 0d 0a 40 76 61 72 40 3d 31 0d 0a 0d 0a 53 45 -..@var@=1....SE
2620: 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 56 61 72 LECT SqlProc_Var
2630: 56 61 6c 75 65 20 28 27 76 61 72 27 2c 20 31 30 Value ('var', 10
2640: 2e 35 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 40 76 61 .5);..-----..@va
2650: 72 40 3d 31 30 2e 35 30 30 30 30 30 30 30 30 30 r@=10.5000000000
2660: 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 ....SELECT SqlPr
2670: 6f 63 5f 56 61 72 56 61 6c 75 65 20 28 27 76 61 oc_VarValue ('va
2680: 72 27 2c 20 27 61 6c 70 68 61 20 62 65 74 61 27 r', 'alpha beta'
2690: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 40 76 61 72 40 );..-----..@var@
26a0: 3d 61 6c 70 68 61 20 62 65 74 61 0d 0a 0d 0a 53 =alpha beta....S
26b0: 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 56 61 ELECT SqlProc_Va
26c0: 72 56 61 6c 75 65 20 28 27 76 61 72 27 2c 20 4d rValue ('var', M
26d0: 61 6b 65 50 6f 69 6e 74 28 31 31 2e 35 2c 20 34 akePoint(11.5, 4
26e0: 32 2e 35 2c 20 34 33 32 36 29 20 29 3b 0d 0a 2d 2.5, 4326) );..-
26f0: 2d 2d 2d 2d 0d 0a 40 76 61 72 40 3d 78 27 30 30 ----..@var@=x'00
2700: 30 31 45 36 31 30 30 30 30 30 30 30 30 30 30 30 01E6100000000000
2710: 30 30 30 30 30 30 32 37 34 30 30 30 30 30 30 30 0000002740000000
2720: 30 30 30 30 34 30 34 35 34 30 30 30 30 30 30 30 0000404540000000
2730: 30 30 30 30 30 30 32 37 34 30 30 30 30 30 30 30 0000002740000000
2740: 30 30 30 30 34 30 34 35 34 30 37 43 30 31 30 30 00004045407C0100
2750: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 0000000000000000
2760: 32 37 34 30 30 30 30 30 30 30 30 30 30 30 34 30 2740000000000040
2770: 34 35 34 30 46 45 27 0d 0a 3c 2f 76 65 72 62 61 4540FE'..</verba
2780: 74 69 6d 3e 0d 0a 3c 75 3e 4e 6f 74 65 3c 2f 75 tim>..<u>Note</u
2790: 3e 3a 20 68 61 6e 64 20 77 72 69 74 69 6e 67 20 >: hand writing
27a0: 56 61 72 69 61 62 6c 65 20 77 69 74 68 20 56 61 Variable with Va
27b0: 6c 75 65 20 73 74 72 69 6e 67 73 20 69 73 20 61 lue strings is a
27c0: 20 72 61 74 68 65 72 20 74 72 69 76 69 61 6c 20 rather trivial
27d0: 6f 70 65 72 61 74 69 6f 6e 2c 20 73 6f 20 63 61 operation, so ca
27e0: 6c 6c 69 6e 67 20 74 68 69 73 20 53 51 4c 20 66 lling this SQL f
27f0: 75 6e 63 74 69 6f 6e 20 69 73 20 6f 66 74 65 6e unction is often
2800: 20 6b 69 6e 64 20 6f 66 20 61 6e 20 6f 76 65 72 kind of an over
2810: 6b 69 6c 6c 2e 20 45 78 63 65 70 74 2c 20 6d 61 kill. Except, ma
2820: 79 20 62 65 2c 20 69 6e 20 74 68 65 20 63 61 73 y be, in the cas
2830: 65 20 6f 66 20 42 4c 4f 42 20 76 61 6c 75 65 73 e of BLOB values
2840: 2e 0d 0a 3c 62 72 3e 3c 62 72 3e 3c 68 72 3e 0d ...<br><br><hr>.
2850: 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 0d 0a 3c 68 .</li>..<li>..<h
2860: 34 3e 52 61 77 20 61 6e 64 20 43 6f 6f 6b 65 64 4>Raw and Cooked
2870: 20 53 51 4c 20 2d 20 72 65 70 6c 61 63 69 6e 67 SQL - replacing
2880: 20 53 79 6d 62 6f 6c 73 20 77 69 74 68 20 74 68 Symbols with th
2890: 65 69 72 20 61 63 74 75 61 6c 20 56 61 6c 75 65 eir actual Value
28a0: 73 3c 2f 68 34 3e 0d 0a 3c 76 65 72 62 61 74 69 s</h4>..<verbati
28b0: 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 m>..SELECT SqlPr
28c0: 6f 63 5f 52 61 77 53 51 4c 20 28 20 53 71 6c 50 oc_RawSQL ( SqlP
28d0: 72 6f 63 5f 46 72 6f 6d 54 65 78 74 28 27 53 45 roc_FromText('SE
28e0: 4c 45 43 54 20 40 63 6f 6c 40 20 46 52 4f 4d 20 LECT @col@ FROM
28f0: 40 74 62 6c 40 3b 27 29 20 29 3b 0d 0a 2d 2d 2d @tbl@;') );..---
2900: 2d 2d 0d 0a 53 45 4c 45 43 54 20 40 63 6f 6c 40 --..SELECT @col@
2910: 20 46 52 4f 4d 20 40 74 62 6c 40 3b 0d 0a 0d 0a FROM @tbl@;....
2920: 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 43 SELECT SqlProc_C
2930: 6f 6f 6b 65 64 53 51 4c 20 28 20 53 71 6c 50 72 ookedSQL ( SqlPr
2940: 6f 63 5f 46 72 6f 6d 54 65 78 74 28 27 53 45 4c oc_FromText('SEL
2950: 45 43 54 20 40 63 6f 6c 40 20 46 52 4f 4d 20 40 ECT @col@ FROM @
2960: 74 62 6c 40 3b 27 29 2c 0d 0a 20 20 20 20 27 40 tbl@;'),.. '@
2970: 63 6f 6c 40 3d 66 69 72 73 74 5f 6e 61 6d 65 27 col@=first_name'
2980: 2c 0d 0a 20 20 20 20 27 40 74 62 6c 40 3d 70 68 ,.. '@tbl@=ph
2990: 6f 6e 65 5f 62 6f 6f 6b 27 20 29 3b 0d 0a 2d 2d one_book' );..--
29a0: 2d 2d 2d 0d 0a 53 45 4c 45 43 54 20 66 69 72 73 ---..SELECT firs
29b0: 74 5f 6e 61 6d 65 20 46 52 4f 4d 20 70 68 6f 6e t_name FROM phon
29c0: 65 5f 62 6f 6f 6b 3b 0d 0a 3c 2f 76 65 72 62 61 e_book;..</verba
29d0: 74 69 6d 3e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e tim>..<ul>..<li>
29e0: 79 6f 75 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 you can use <b>S
29f0: 71 6c 50 72 6f 63 5f 52 61 77 53 51 4c 3c 2f 62 qlProc_RawSQL</b
2a00: 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 64 69 > in order to di
2a10: 72 65 63 74 6c 79 20 63 68 65 63 6b 20 74 68 65 rectly check the
2a20: 20 53 51 4c 20 42 6f 64 79 20 65 6e 63 61 70 73 SQL Body encaps
2a30: 75 6c 61 74 65 64 20 69 6e 74 6f 20 73 20 53 51 ulated into s SQ
2a40: 4c 20 50 72 6f 63 65 64 75 72 65 20 42 4c 4f 42 L Procedure BLOB
2a50: 20 4f 62 6a 65 63 74 3b 20 61 6c 6c 20 69 6e 69 Object; all ini
2a60: 74 69 61 6c 20 56 61 72 69 61 62 6c 65 20 64 65 tial Variable de
2a70: 66 69 6e 69 74 69 6f 6e 73 20 77 69 6c 6c 20 62 finitions will b
2a80: 65 20 63 61 72 65 66 75 6c 6c 79 20 70 72 65 73 e carefully pres
2a90: 65 72 76 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 erved.</li>..<li
2aa0: 3e 61 6e 64 20 79 6f 75 20 63 61 6e 20 75 73 65 >and you can use
2ab0: 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 43 6f 6f 6b <b>SqlProc_Cook
2ac0: 65 64 53 51 4c 3c 2f 62 3e 20 69 6e 20 6f 72 64 edSQL</b> in ord
2ad0: 65 72 20 74 6f 20 64 69 72 65 63 74 6c 79 20 63 er to directly c
2ae0: 68 65 63 6b 20 74 68 65 20 53 51 4c 20 42 6f 64 heck the SQL Bod
2af0: 79 20 61 73 20 69 74 20 61 63 74 75 61 6c 6c 79 y as it actually
2b00: 20 61 70 70 65 61 72 73 20 61 66 74 65 72 20 72 appears after r
2b10: 65 70 6c 61 63 69 6e 67 20 61 6c 6c 20 72 65 71 eplacing all req
2b20: 75 69 72 65 64 20 56 61 72 69 61 62 6c 65 20 56 uired Variable V
2b30: 61 6c 75 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 alues.</li>..<li
2b40: 3e 42 6f 74 68 20 66 75 6e 63 74 69 6f 6e 73 20 >Both functions
2b50: 61 72 65 20 6d 61 69 6e 6c 79 20 69 6e 74 65 6e are mainly inten
2b60: 64 65 64 20 66 6f 72 20 73 75 70 70 6f 72 74 69 ded for supporti
2b70: 6e 67 20 64 65 62 75 67 67 69 6e 67 20 61 63 74 ng debugging act
2b80: 69 76 69 74 69 65 73 2c 20 73 6f 20 74 6f 20 6d ivities, so to m
2b90: 61 6b 65 20 61 73 20 65 61 73 79 20 61 73 20 70 ake as easy as p
2ba0: 6f 73 73 69 62 6c 65 20 69 64 65 6e 74 69 66 79 ossible identify
2bb0: 69 6e 67 20 65 76 65 6e 74 75 61 6c 20 65 72 72 ing eventual err
2bc0: 6f 72 73 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e ors.</li>..</ul>
2bd0: 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65 20 62 67 63 <br>..<table bgc
2be0: 6f 6c 6f 72 3d 22 23 66 38 66 38 64 38 22 20 63 olor="#f8f8d8" c
2bf0: 65 6c 6c 70 61 64 64 69 6e 67 3d 22 36 22 20 63 ellpadding="6" c
2c00: 65 6c 6c 73 70 61 63 69 6e 67 3d 22 38 22 3e 3c ellspacing="8"><
2c10: 74 72 3e 3c 74 64 3e 0d 0a 3c 75 3e 4e 6f 74 65 tr><td>..<u>Note
2c20: 3c 2f 75 3e 3a 20 3c 62 3e 53 71 6c 50 72 6f 63 </u>: <b>SqlProc
2c30: 5f 43 6f 6f 6b 65 64 53 51 4c 3c 2f 62 3e 20 77 _CookedSQL</b> w
2c40: 69 6c 6c 20 61 63 63 65 70 74 20 61 6e 20 61 72 ill accept an ar
2c50: 62 69 74 72 61 72 79 20 6c 69 73 74 20 6f 66 20 bitrary list of
2c60: 3c 62 3e 56 61 72 69 61 62 6c 65 20 77 69 74 68 <b>Variable with
2c70: 20 56 61 6c 75 65 3c 2f 62 3e 20 61 72 67 75 6d Value</b> argum
2c80: 65 6e 74 73 2e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 ents...<ul>..<li
2c90: 3e 61 6e 20 65 6d 70 74 79 20 6c 69 73 74 20 28 >an empty list (
2ca0: 6e 6f 20 56 61 72 69 61 62 6c 65 73 20 77 69 74 no Variables wit
2cb0: 68 20 56 61 6c 75 65 73 20 61 74 20 61 6c 6c 29 h Values at all)
2cc0: 20 69 73 20 61 20 70 65 72 66 65 63 74 6c 79 20 is a perfectly
2cd0: 6c 65 67 61 6c 20 63 6f 6e 64 69 74 69 6f 6e 20 legal condition
2ce0: 28 63 6f 75 6c 64 20 65 76 65 6e 74 75 61 6c 6c (could eventuall
2cf0: 79 20 6c 65 61 64 20 74 6f 20 61 6e 20 69 6e 76 y lead to an inv
2d00: 61 6c 69 64 20 43 6f 6f 6b 65 64 20 53 51 4c 20 alid Cooked SQL
2d10: 42 6f 64 79 2c 20 73 65 65 20 62 65 6c 6f 77 29 Body, see below)
2d20: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6c 6c 20 .</li>..<li>all
2d30: 61 72 67 75 6d 65 6e 74 73 20 66 72 6f 6d 20 74 arguments from t
2d40: 68 65 20 73 65 63 6f 6e 64 20 75 6e 74 69 6c 20 he second until
2d50: 74 68 65 20 65 6e 64 20 61 72 65 20 65 78 70 65 the end are expe
2d60: 63 74 65 64 20 74 6f 20 62 65 20 77 65 6c 6c 2d cted to be well-
2d70: 66 6f 72 6d 65 64 20 56 61 72 69 61 62 6c 65 73 formed Variables
2d80: 20 77 69 74 68 20 56 61 6c 75 65 73 2e 3c 2f 6c with Values.</l
2d90: 69 3e 0d 0a 3c 6c 69 3e 79 6f 75 20 63 61 6e 20 i>..<li>you can
2da0: 64 65 66 69 6e 65 20 61 73 20 6d 75 63 68 20 61 define as much a
2db0: 73 20 3c 62 3e 31 36 3c 2f 62 3e 20 64 69 66 66 s <b>16</b> diff
2dc0: 65 72 65 6e 74 20 56 61 72 69 61 62 6c 65 73 20 erent Variables
2dd0: 77 69 74 68 20 56 61 6c 75 65 73 2e 3c 2f 6c 69 with Values.</li
2de0: 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 61 74 74 65 6d >..<li>any attem
2df0: 70 74 20 74 6f 20 64 65 66 69 6e 65 20 74 77 69 pt to define twi
2e00: 63 65 20 61 20 56 61 6c 75 65 20 66 6f 72 20 74 ce a Value for t
2e10: 68 65 20 73 61 6d 65 20 56 61 72 69 61 62 6c 65 he same Variable
2e20: 20 77 69 6c 6c 20 62 65 20 61 6c 77 61 79 73 20 will be always
2e30: 63 6f 6e 73 69 64 65 72 65 64 20 61 73 20 61 20 considered as a
2e40: 66 61 74 61 6c 20 65 72 72 6f 72 2e 3c 2f 6c 69 fatal error.</li
2e50: 3e 0d 0a 3c 6c 69 3e 69 66 20 6f 6e 65 20 6f 66 >..<li>if one of
2e60: 20 74 68 65 20 56 61 72 69 61 62 6c 65 20 61 72 the Variable ar
2e70: 67 75 6d 65 6e 74 73 20 64 6f 65 73 20 6e 6f 74 guments does not
2e80: 20 6d 61 74 63 68 20 6f 6e 65 20 74 68 65 20 56 match one the V
2e90: 61 72 69 61 62 6c 65 73 20 69 6e 74 65 72 6e 61 ariables interna
2ea0: 6c 6c 79 20 64 65 66 69 6e 65 64 20 62 79 20 74 lly defined by t
2eb0: 68 65 20 52 61 77 20 53 51 4c 20 42 6f 64 79 20 he Raw SQL Body
2ec0: 69 74 20 77 69 6c 6c 20 62 65 20 73 69 6d 70 6c it will be simpl
2ed0: 79 20 69 67 6e 6f 72 65 64 2e 3c 2f 6c 69 3e 0d y ignored.</li>.
2ee0: 0a 3c 6c 69 3e 69 66 20 61 20 56 61 72 69 61 62 .<li>if a Variab
2ef0: 6c 65 20 64 65 66 69 6e 65 64 20 69 6e 74 6f 20 le defined into
2f00: 74 68 65 20 52 61 77 20 53 51 4c 20 42 6f 64 79 the Raw SQL Body
2f10: 20 64 6f 65 73 20 6e 6f 74 20 6d 61 74 63 68 65 does not matche
2f20: 73 20 61 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e s a correspondin
2f30: 67 20 56 61 72 69 61 62 6c 65 20 61 72 67 75 6d g Variable argum
2f40: 65 6e 74 20 74 68 65 6e 20 69 74 20 77 69 6c 6c ent then it will
2f50: 20 72 65 70 6c 61 63 65 64 20 62 79 20 61 20 64 replaced by a d
2f60: 65 66 61 75 6c 74 20 27 3c 62 3e 4e 55 4c 4c 3c efault '<b>NULL<
2f70: 2f 62 3e 27 20 73 74 72 69 6e 67 2e 3c 2f 6c 69 /b>' string.</li
2f80: 3e 0d 0a 3c 6c 69 3e 74 68 65 20 73 61 6d 65 20 >..<li>the same
2f90: 69 64 65 6e 74 69 63 61 6c 20 72 75 6c 65 73 20 identical rules
2fa0: 66 6f 72 20 70 61 73 73 69 6e 67 20 56 61 72 69 for passing Vari
2fb0: 61 62 6c 65 2d 56 61 6c 75 65 20 61 72 67 75 6d able-Value argum
2fc0: 65 6e 74 73 20 61 70 70 6c 79 20 74 6f 20 3c 62 ents apply to <b
2fd0: 3e 53 71 6c 50 72 6f 63 5f 43 6f 6f 6b 65 64 53 >SqlProc_CookedS
2fe0: 51 4c 3c 2f 62 3e 2c 20 3c 62 3e 53 71 6c 50 72 QL</b>, <b>SqlPr
2ff0: 6f 63 5f 45 78 65 63 75 74 65 3c 2f 62 3e 20 61 oc_Execute</b> a
3000: 6e 64 20 3c 62 3e 53 74 6f 72 65 64 50 72 6f 63 nd <b>StoredProc
3010: 5f 45 78 65 63 75 74 65 3c 2f 62 3e 2e 3c 2f 6c _Execute</b>.</l
3020: 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 2f 74 64 3e i>..</ul>..</td>
3030: 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c </tr></table>..<
3040: 62 72 3e 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a br><hr>..</li>..
3050: 3c 6c 69 3e 0d 0a 3c 68 34 3e 45 78 65 63 75 74 <li>..<h4>Execut
3060: 69 6e 67 20 61 20 53 51 4c 20 50 72 6f 63 65 64 ing a SQL Proced
3070: 75 72 65 3c 2f 68 34 3e 0d 0a 3c 76 65 72 62 61 ure</h4>..<verba
3080: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 71 6c tim>..SELECT Sql
3090: 50 72 6f 63 5f 45 78 65 63 75 74 65 20 28 53 71 Proc_Execute (Sq
30a0: 6c 50 72 6f 63 5f 46 72 6f 6d 54 65 78 74 28 27 lProc_FromText('
30b0: 53 45 4c 45 43 54 20 40 63 6f 6c 40 20 46 52 4f SELECT @col@ FRO
30c0: 4d 20 40 74 62 6c 40 3b 27 29 2c 0d 0a 20 20 20 M @tbl@;'),..
30d0: 20 27 40 63 6f 6c 40 3d 66 69 72 73 74 5f 6e 61 '@col@=first_na
30e0: 6d 65 27 2c 0d 0a 20 20 20 20 27 40 74 62 6c 40 me',.. '@tbl@
30f0: 3d 70 68 6f 6e 65 5f 62 6f 6f 6b 27 20 29 3b 0d =phone_book' );.
3100: 0a 2d 2d 2d 2d 2d 0d 0a 53 71 6c 50 72 6f 63 20 .-----..SqlProc
3110: 65 78 63 65 70 74 69 6f 6e 20 2d 20 61 20 66 61 exception - a fa
3120: 74 61 6c 20 53 51 4c 20 65 72 72 6f 72 20 77 61 tal SQL error wa
3130: 73 20 65 6e 63 6f 75 6e 74 65 72 65 64 2e 0d 0a s encountered...
3140: 0d 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 ..SELECT SqlProc
3150: 5f 47 65 74 4c 61 73 74 45 72 72 6f 72 28 29 3b _GetLastError();
3160: 0d 0a 2d 2d 2d 2d 2d 0d 0a 67 61 69 61 5f 73 71 ..-----..gaia_sq
3170: 6c 5f 70 72 6f 63 5f 65 78 65 63 75 74 65 3a 20 l_proc_execute:
3180: 6e 6f 20 73 75 63 68 20 74 61 62 6c 65 3a 20 70 no such table: p
3190: 68 6f 6e 65 5f 62 6f 6f 6b 0d 0a 3c 2f 76 65 72 hone_book..</ver
31a0: 62 61 74 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 batim>..you can
31b0: 75 73 65 20 3c 62 3e 53 71 6c 50 72 6f 63 5f 45 use <b>SqlProc_E
31c0: 78 65 63 75 74 65 3c 2f 62 3e 20 69 6e 20 6f 72 xecute</b> in or
31d0: 64 65 72 20 74 6f 20 64 69 72 65 63 74 6c 79 20 der to directly
31e0: 65 78 65 63 75 74 65 20 74 68 65 20 77 68 6f 6c execute the whol
31f0: 65 20 53 51 4c 20 42 6f 64 79 20 61 73 20 61 20 e SQL Body as a
3200: 73 69 6e 67 6c 65 20 6d 6f 6e 6f 6c 69 74 68 69 single monolithi
3210: 63 20 75 6e 69 74 2e 3c 62 72 3e 0d 0a 41 74 20 c unit.<br>..At
3220: 74 68 65 20 65 6e 64 20 6f 66 20 74 68 65 20 70 the end of the p
3230: 72 6f 63 65 73 73 20 3c 62 3e 31 3c 2f 62 3e 20 rocess <b>1</b>
3240: 28 61 6b 61 20 3c 62 3e 54 72 75 65 3c 2f 62 3e (aka <b>True</b>
3250: 29 20 77 69 6c 6c 20 62 65 20 72 65 74 75 72 6e ) will be return
3260: 65 64 20 6f 6e 20 66 75 6c 6c 20 73 75 63 63 65 ed on full succe
3270: 73 73 3b 20 61 6e 20 45 78 63 65 70 74 69 6f 6e ss; an Exception
3280: 20 77 69 6c 6c 20 62 65 20 72 61 69 73 65 64 20 will be raised
3290: 6f 6e 20 66 61 69 6c 75 72 65 2c 20 61 73 20 69 on failure, as i
32a0: 74 20 68 61 70 70 65 6e 73 20 69 6e 20 74 68 69 t happens in thi
32b0: 73 20 65 78 61 6d 70 6c 65 2c 20 61 6e 64 20 69 s example, and i
32c0: 6e 20 74 68 69 73 20 63 61 73 65 20 79 6f 75 20 n this case you
32d0: 63 61 6e 20 74 68 65 6e 20 75 73 65 20 3c 62 3e can then use <b>
32e0: 53 71 6c 50 72 6f 63 5f 47 65 74 4c 61 73 74 45 SqlProc_GetLastE
32f0: 72 72 6f 72 3c 2f 62 3e 20 73 6f 20 74 6f 20 72 rror</b> so to r
3300: 65 74 72 69 65 76 65 20 74 68 65 20 63 6f 72 72 etrieve the corr
3310: 65 73 70 6f 6e 64 69 6e 67 20 53 51 4c 20 65 72 esponding SQL er
3320: 72 6f 72 72 20 6d 65 73 73 61 67 65 2e 0d 0a 3c rorr message...<
3330: 62 72 3e 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65 20 br><br>..<table
3340: 62 67 63 6f 6c 6f 72 3d 22 23 66 38 66 38 64 38 bgcolor="#f8f8d8
3350: 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 36 " cellpadding="6
3360: 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 38 " cellspacing="8
3370: 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 3c 75 3e 4e "><tr><td>..<u>N
3380: 6f 74 65 3c 2f 75 3e 3a 20 61 6c 6c 20 3c 62 3e ote</u>: all <b>
3390: 44 6f 74 20 4d 61 63 72 6f 73 3c 2f 62 3e 20 65 Dot Macros</b> e
33a0: 76 65 6e 74 75 61 6c 6c 79 20 66 6f 75 6e 64 20 ventually found
33b0: 77 69 74 68 69 6e 20 74 68 65 20 53 51 4c 20 42 within the SQL B
33c0: 6f 64 79 20 62 65 69 6e 67 20 65 78 65 63 75 74 ody being execut
33d0: 65 64 20 77 69 6c 6c 20 62 65 20 61 6c 77 61 79 ed will be alway
33e0: 73 20 73 69 6c 65 6e 74 6c 79 20 69 67 6e 6f 72 s silently ignor
33f0: 65 64 2e 3c 62 72 3e 0d 0a 54 68 65 20 73 61 6d ed.<br>..The sam
3400: 65 20 72 75 6c 65 20 61 70 70 6c 69 65 73 20 74 e rule applies t
3410: 6f 20 3c 62 3e 53 74 6f 72 65 64 50 72 6f 63 5f o <b>StoredProc_
3420: 45 78 65 63 75 74 65 3c 2f 62 3e 20 61 73 20 77 Execute</b> as w
3430: 65 6c 6c 2e 3c 2f 62 3e 0d 0a 3c 2f 74 64 3e 3c ell.</b>..</td><
3440: 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 62 /tr></table>..<b
3450: 72 3e 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c r><hr>..</li>..<
3460: 6c 69 3e 0d 0a 3c 68 34 3e 48 61 6e 64 6c 69 6e li>..<h4>Handlin
3470: 67 20 53 51 4c 20 53 74 6f 72 65 64 20 50 72 6f g SQL Stored Pro
3480: 63 65 64 75 72 65 73 3c 2f 68 34 3e 0d 0a 3c 76 cedures</h4>..<v
3490: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 erbatim>..SELECT
34a0: 20 53 74 6f 72 65 64 50 72 6f 63 5f 43 72 65 61 StoredProc_Crea
34b0: 74 65 54 61 62 6c 65 73 28 29 3b 0d 0a 2d 2d 2d teTables();..---
34c0: 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69 --..1..</verbati
34d0: 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 75 73 65 20 m>..you can use
34e0: 3c 62 3e 53 74 6f 72 65 64 50 72 6f 63 5f 43 72 <b>StoredProc_Cr
34f0: 65 61 74 65 54 61 62 6c 65 73 3c 2f 62 3e 20 69 eateTables</b> i
3500: 6e 20 6f 72 64 65 72 20 74 6f 20 63 72 65 61 74 n order to creat
3510: 65 20 6f 6e 20 79 6f 75 72 20 63 75 72 72 65 6e e on your curren
3520: 74 6c 79 20 63 6f 6e 6e 65 63 74 65 64 20 64 61 tly connected da
3530: 74 61 62 61 73 65 20 61 6c 6c 20 3c 62 3e 6d 65 tabase all <b>me
3540: 74 61 74 61 62 6c 65 73 3c 2f 62 3e 20 72 65 71 tatables</b> req
3550: 75 69 72 65 64 20 74 6f 20 70 65 72 6d 61 6e 65 uired to permane
3560: 6e 74 6c 79 20 72 65 67 69 73 74 65 72 20 53 74 ntly register St
3570: 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65 73 20 ored Procedures
3580: 61 6e 64 20 53 74 6f 72 65 64 20 56 61 72 69 61 and Stored Varia
3590: 62 6c 65 73 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c bles.<br><br>..<
35a0: 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 table bgcolor="#
35b0: 66 38 66 38 64 38 22 20 63 65 6c 6c 70 61 64 64 f8f8d8" cellpadd
35c0: 69 6e 67 3d 22 36 22 20 63 65 6c 6c 73 70 61 63 ing="6" cellspac
35d0: 69 6e 67 3d 22 38 22 3e 3c 74 72 3e 3c 74 64 3e ing="8"><tr><td>
35e0: 0d 0a 3c 75 3e 4e 6f 74 65 3c 2f 75 3e 3a 20 61 ..<u>Note</u>: a
35f0: 6e 79 20 6e 65 77 20 64 61 74 61 62 61 73 65 20 ny new database
3600: 63 72 65 61 74 65 64 20 62 79 20 53 70 61 74 69 created by Spati
3610: 61 4c 69 74 65 20 34 2e 35 2e 30 20 28 61 6e 64 aLite 4.5.0 (and
3620: 20 73 75 62 73 65 71 75 65 6e 74 20 76 65 72 73 subsequent vers
3630: 69 6f 6e 73 29 20 77 69 6c 6c 20 61 75 74 6f 6d ions) will autom
3640: 61 74 69 63 61 6c 6c 79 20 73 75 70 70 6f 72 74 atically support
3650: 20 74 68 65 20 53 74 6f 72 65 64 20 50 72 6f 63 the Stored Proc
3660: 65 64 75 72 65 73 20 6d 65 74 61 74 61 62 6c 65 edures metatable
3670: 73 2e 0d 0a 45 78 70 6c 69 63 69 74 6c 79 20 63 s...Explicitly c
3680: 61 6c 6c 69 6e 67 20 74 68 69 73 20 66 75 6e 63 alling this func
3690: 74 69 6f 6e 20 69 73 20 6d 61 69 6e 6c 79 20 75 tion is mainly u
36a0: 73 65 66 75 6c 20 69 6e 20 6f 72 64 65 72 20 74 seful in order t
36b0: 6f 20 72 65 74 72 6f 66 69 74 20 53 74 6f 72 65 o retrofit Store
36c0: 64 20 50 72 6f 63 65 64 75 72 65 73 20 73 75 70 d Procedures sup
36d0: 70 6f 72 74 20 6f 6e 20 61 6c 72 65 61 64 79 20 port on already
36e0: 65 78 69 73 74 69 6e 67 20 64 61 74 61 62 61 73 existing databas
36f0: 65 73 20 63 72 65 61 74 65 20 62 79 20 70 72 65 es create by pre
3700: 76 69 6f 75 73 20 76 65 72 73 69 6f 6e 73 2e 0d vious versions..
3710: 0a 43 61 6c 6c 69 6e 67 20 3c 62 3e 53 74 6f 72 .Calling <b>Stor
3720: 65 64 50 72 6f 63 5f 43 72 65 61 74 65 54 61 62 edProc_CreateTab
3730: 6c 65 73 3c 2f 62 3e 20 6f 6e 20 62 65 68 61 6c les</b> on behal
3740: 66 20 6f 66 20 61 20 64 61 74 61 62 61 73 65 20 f of a database
3750: 61 6c 72 65 61 64 79 20 73 75 70 70 6f 72 74 69 already supporti
3760: 6e 67 20 74 68 65 20 53 74 6f 72 65 64 20 50 72 ng the Stored Pr
3770: 6f 63 65 64 75 72 65 73 20 6d 65 74 61 74 61 62 ocedures metatab
3780: 6c 65 20 69 73 20 61 6e 20 68 61 72 6d 6c 65 73 le is an harmles
3790: 73 20 6f 70 65 72 61 74 69 6f 6e 20 73 69 6d 70 s operation simp
37a0: 6c 79 20 72 65 74 75 72 6e 69 6e 67 20 3c 62 3e ly returning <b>
37b0: 31 3c 2f 62 3e 20 28 66 75 6c 6c 20 73 75 63 63 1</b> (full succ
37c0: 65 73 73 29 2e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 ess)...</td></tr
37d0: 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 76 65 72 62 ></table>..<verb
37e0: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 74 atim>..SELECT St
37f0: 6f 72 65 64 50 72 6f 63 5f 52 65 67 69 73 74 65 oredProc_Registe
3800: 72 20 28 20 27 73 70 5f 31 27 2c 20 27 61 20 73 r ( 'sp_1', 'a s
3810: 61 6d 70 6c 65 20 53 74 6f 72 65 64 20 50 72 6f ample Stored Pro
3820: 63 65 64 75 72 65 20 66 6f 72 20 74 65 73 74 69 cedure for testi
3830: 6e 67 27 2c 20 53 71 6c 50 72 6f 63 5f 46 72 6f ng', SqlProc_Fro
3840: 6d 54 65 78 74 28 27 53 45 4c 45 43 54 20 40 63 mText('SELECT @c
3850: 6f 6c 40 20 46 52 4f 4d 20 40 74 62 6c 40 3b 27 ol@ FROM @tbl@;'
3860: 20 29 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a ));..-----..1..
3870: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 79 6f 75 </verbatim>..you
3880: 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 74 6f 72 can use <b>Stor
3890: 65 64 50 72 6f 63 5f 52 65 67 69 73 74 65 72 3c edProc_Register<
38a0: 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 /b> in order to
38b0: 70 65 72 6d 61 6e 65 6e 74 6c 79 20 72 65 67 69 permanently regi
38c0: 73 74 65 72 20 61 20 53 74 6f 72 65 64 20 50 72 ster a Stored Pr
38d0: 6f 63 65 64 75 72 65 2e 0d 0a 3c 76 65 72 62 61 ocedure...<verba
38e0: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 74 6f tim>..SELECT Sto
38f0: 72 65 64 50 72 6f 63 5f 44 65 6c 65 74 65 20 28 redProc_Delete (
3900: 20 27 73 70 5f 31 27 20 29 3b 0d 0a 2d 2d 2d 2d 'sp_1' );..----
3910: 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69 6d -..1..</verbatim
3920: 3e 0d 0a 79 6f 75 20 63 61 6e 20 75 73 65 20 3c >..you can use <
3930: 62 3e 53 74 6f 72 65 64 50 72 6f 63 5f 44 65 6c b>StoredProc_Del
3940: 65 74 65 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72 ete</b> in order
3950: 20 74 6f 20 70 65 72 6d 61 6e 65 6e 74 6c 79 20 to permanently
3960: 72 65 6d 6f 76 65 20 61 20 70 72 65 76 69 6f 75 remove a previou
3970: 73 6c 79 20 72 65 67 69 73 74 65 72 65 64 20 53 sly registered S
3980: 74 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65 2e tored Procedure.
3990: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 ..<verbatim>..SE
39a0: 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f 52 61 77 LECT SqlProc_Raw
39b0: 53 51 4c 20 28 20 53 74 6f 72 65 64 50 72 6f 63 SQL ( StoredProc
39c0: 5f 47 65 74 20 28 20 27 73 70 5f 31 27 20 29 20 _Get ( 'sp_1' )
39d0: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 53 45 4c 45 43 );..-----..SELEC
39e0: 54 20 40 63 6f 6c 40 20 46 52 4f 4d 20 40 74 62 T @col@ FROM @tb
39f0: 6c 40 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e l@;..</verbatim>
3a00: 0d 0a 79 6f 75 20 63 61 6e 20 75 73 65 20 3c 62 ..you can use <b
3a10: 3e 53 74 6f 72 65 64 50 72 6f 63 5f 47 65 74 3c >StoredProc_Get<
3a20: 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 /b> in order to
3a30: 72 65 74 72 69 65 76 65 20 74 68 65 20 53 51 4c retrieve the SQL
3a40: 20 50 72 6f 63 65 64 75 72 65 20 42 4c 4f 42 20 Procedure BLOB
3a50: 4f 62 6a 65 63 74 20 66 72 6f 6d 20 61 20 72 65 Object from a re
3a60: 67 69 73 74 65 72 65 64 20 53 74 6f 72 65 64 20 gistered Stored
3a70: 50 72 6f 63 65 64 75 72 65 2e 0d 0a 3c 76 65 72 Procedure...<ver
3a80: 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 batim>..SELECT S
3a90: 74 6f 72 65 64 50 72 6f 63 5f 55 70 64 61 74 65 toredProc_Update
3aa0: 54 69 74 6c 65 20 28 20 27 73 70 5f 31 27 2c 20 Title ( 'sp_1',
3ab0: 27 74 68 69 73 20 54 69 74 6c 65 20 77 61 73 20 'this Title was
3ac0: 63 68 61 6e 67 65 64 27 20 29 3b 0d 0a 2d 2d 2d changed' );..---
3ad0: 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69 --..1..</verbati
3ae0: 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 75 73 65 20 m>..you can use
3af0: 3c 62 3e 53 74 6f 72 65 64 50 72 6f 63 5f 55 70 <b>StoredProc_Up
3b00: 64 61 74 65 54 69 74 6c 65 3c 2f 62 3e 20 69 6e dateTitle</b> in
3b10: 20 6f 72 64 65 72 20 74 6f 20 6d 6f 64 69 66 79 order to modify
3b20: 20 74 68 65 20 54 69 74 6c 65 20 6f 66 20 61 6e the Title of an
3b30: 20 61 6c 72 65 61 64 79 20 72 65 67 69 73 74 65 already registe
3b40: 72 65 64 20 53 74 6f 72 65 64 20 50 72 6f 63 65 red Stored Proce
3b50: 64 75 72 65 2e 0d 0a 3c 76 65 72 62 61 74 69 6d dure...<verbatim
3b60: 3e 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64 >..SELECT Stored
3b70: 50 72 6f 63 5f 55 70 64 61 74 65 53 71 6c 42 6f Proc_UpdateSqlBo
3b80: 64 79 20 28 20 27 73 70 5f 31 27 2c 20 53 71 6c dy ( 'sp_1', Sql
3b90: 50 72 6f 63 5f 46 72 6f 6d 46 69 6c 65 28 27 2f Proc_FromFile('/
3ba0: 68 6f 6d 65 2f 6a 6f 65 2f 73 71 6c 5f 73 63 72 home/joe/sql_scr
3bb0: 69 70 74 73 2f 73 74 6f 72 65 64 5f 70 72 6f 63 ipts/stored_proc
3bc0: 5f 74 65 73 74 5f 76 32 2e 74 78 74 27 20 29 3b _test_v2.txt' );
3bd0: 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 ..-----..1..</ve
3be0: 72 62 61 74 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e rbatim>..you can
3bf0: 20 75 73 65 20 3c 62 3e 53 74 6f 72 65 64 50 72 use <b>StoredPr
3c00: 6f 63 5f 55 70 64 61 74 65 53 71 6c 42 6f 64 79 oc_UpdateSqlBody
3c10: 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f </b> in order to
3c20: 20 6d 6f 64 69 66 79 20 74 68 65 20 53 71 6c 20 modify the Sql
3c30: 42 6f 64 79 20 6f 66 20 61 6e 20 61 6c 72 65 61 Body of an alrea
3c40: 64 79 20 72 65 67 69 73 74 65 72 65 64 20 53 74 dy registered St
3c50: 6f 72 65 64 20 50 72 6f 63 65 64 75 72 65 20 28 ored Procedure (
3c60: 65 2e 67 2e 20 62 65 63 61 75 73 65 20 79 6f 75 e.g. because you
3c70: 27 76 65 20 64 69 73 63 6f 76 65 72 65 64 20 61 've discovered a
3c80: 6e 64 20 66 69 78 65 64 20 73 6f 6d 65 20 62 75 nd fixed some bu
3c90: 67 20 61 66 66 65 63 74 69 6e 67 20 74 68 65 20 g affecting the
3ca0: 70 72 65 76 69 6f 75 73 20 53 51 4c 20 69 6d 70 previous SQL imp
3cb0: 6c 65 6d 65 6e 74 61 74 69 6f 6e 29 2e 3c 76 65 lementation).<ve
3cc0: 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 rbatim>..SELECT
3cd0: 53 74 6f 72 65 64 50 72 6f 63 5f 45 78 65 63 75 StoredProc_Execu
3ce0: 74 65 20 28 20 27 73 70 5f 31 27 2c 0d 0a 20 20 te ( 'sp_1',..
3cf0: 20 20 27 40 63 6f 6c 40 3d 73 72 69 64 27 2c 0d '@col@=srid',.
3d00: 0a 20 20 20 20 27 40 74 62 6c 40 3d 73 70 61 74 . '@tbl@=spat
3d10: 69 61 6c 5f 72 65 66 5f 73 79 73 27 20 29 3b 0d ial_ref_sys' );.
3d20: 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 .-----..1..</ver
3d30: 62 61 74 69 6d 3e 0d 0a 61 6e 64 20 66 69 6e 61 batim>..and fina
3d40: 6c 6c 79 20 79 6f 75 20 63 61 6e 20 75 73 65 20 lly you can use
3d50: 3c 62 3e 53 74 6f 72 65 64 50 72 6f 63 5f 45 78 <b>StoredProc_Ex
3d60: 65 63 75 74 65 3c 2f 62 3e 20 69 6e 20 6f 72 64 ecute</b> in ord
3d70: 65 72 20 74 6f 20 64 69 72 65 63 74 6c 79 20 65 er to directly e
3d80: 78 65 63 75 74 65 20 61 20 53 74 6f 72 65 64 20 xecute a Stored
3d90: 50 72 6f 63 65 64 75 72 65 20 61 73 20 61 20 73 Procedure as a s
3da0: 69 6e 67 6c 65 20 6d 6f 6e 6f 6c 69 74 68 69 63 ingle monolithic
3db0: 20 75 6e 69 74 2e 3c 62 72 3e 0d 0a 3c 62 72 3e unit.<br>..<br>
3dc0: 3c 62 72 3e 3c 68 72 3e 0d 0a 3c 2f 6c 69 3e 0d <br><hr>..</li>.
3dd0: 0a 3c 6c 69 3e 0d 0a 3c 68 34 3e 48 61 6e 64 6c .<li>..<h4>Handl
3de0: 69 6e 67 20 53 51 4c 20 53 74 6f 72 65 64 20 56 ing SQL Stored V
3df0: 61 72 69 61 62 6c 65 73 3c 2f 68 34 3e 0d 0a 3c ariables</h4>..<
3e00: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 verbatim>..SELEC
3e10: 54 20 53 74 6f 72 65 64 56 61 72 5f 52 65 67 69 T StoredVar_Regi
3e20: 73 74 65 72 20 28 20 27 76 61 72 5f 31 27 2c 20 ster ( 'var_1',
3e30: 27 61 6e 20 75 6e 69 76 65 72 73 61 6c 6c 79 20 'an universally
3e40: 75 73 65 66 75 6c 20 63 6f 6e 73 74 61 6e 74 27 useful constant'
3e50: 2c 20 27 40 50 49 40 3d 33 2e 31 34 27 20 29 3b , '@PI@=3.14' );
3e60: 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 ..-----..1..</ve
3e70: 72 62 61 74 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e rbatim>..you can
3e80: 20 75 73 65 20 3c 62 3e 53 74 6f 72 65 64 56 61 use <b>StoredVa
3e90: 72 5f 52 65 67 69 73 74 65 72 3c 2f 62 3e 20 69 r_Register</b> i
3ea0: 6e 20 6f 72 64 65 72 20 74 6f 20 70 65 72 6d 61 n order to perma
3eb0: 6e 65 6e 74 6c 79 20 72 65 67 69 73 74 65 72 20 nently register
3ec0: 61 20 53 74 6f 72 65 64 20 56 61 72 69 61 62 6c a Stored Variabl
3ed0: 65 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a e...<verbatim>..
3ee0: 53 45 4c 45 43 54 20 53 74 6f 72 65 64 56 61 72 SELECT StoredVar
3ef0: 5f 44 65 6c 65 74 65 20 28 20 27 76 61 72 5f 31 _Delete ( 'var_1
3f00: 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a ' );..-----..1..
3f10: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 79 6f 75 </verbatim>..you
3f20: 20 63 61 6e 20 75 73 65 20 3c 62 3e 53 74 6f 72 can use <b>Stor
3f30: 65 64 56 61 72 5f 44 65 6c 65 74 65 3c 2f 62 3e edVar_Delete</b>
3f40: 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 70 65 72 in order to per
3f50: 6d 61 6e 65 6e 74 6c 79 20 72 65 6d 6f 76 65 20 manently remove
3f60: 61 20 70 72 65 76 69 6f 75 73 6c 79 20 72 65 67 a previously reg
3f70: 69 73 74 65 72 65 64 20 53 74 6f 72 65 64 20 56 istered Stored V
3f80: 61 72 69 61 62 6c 65 2e 0d 0a 3c 76 65 72 62 61 ariable...<verba
3f90: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 74 6f tim>..SELECT Sto
3fa0: 72 65 64 56 61 72 5f 47 65 74 20 28 20 27 76 61 redVar_Get ( 'va
3fb0: 72 5f 31 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a r_1' );..-----..
3fc0: 40 50 49 40 3d 33 2e 31 34 0d 0a 3c 2f 76 65 72 @PI@=3.14..</ver
3fd0: 62 61 74 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 batim>..you can
3fe0: 75 73 65 20 3c 62 3e 53 74 6f 72 65 64 56 61 72 use <b>StoredVar
3ff0: 5f 47 65 74 3c 2f 62 3e 20 69 6e 20 6f 72 64 65 _Get</b> in orde
4000: 72 20 74 6f 20 72 65 74 72 69 65 76 65 20 74 68 r to retrieve th
4010: 65 20 56 61 72 69 61 62 6c 65 20 77 69 74 68 20 e Variable with
4020: 56 61 6c 75 65 20 73 74 72 69 6e 67 20 66 72 6f Value string fro
4030: 6d 20 61 20 72 65 67 69 73 74 65 72 65 64 20 53 m a registered S
4040: 74 6f 72 65 64 20 56 61 72 69 61 62 6c 65 2e 0d tored Variable..
4050: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c .<verbatim>..SEL
4060: 45 43 54 20 53 74 6f 72 65 64 56 61 72 5f 55 70 ECT StoredVar_Up
4070: 64 61 74 65 54 69 74 6c 65 20 28 20 27 76 61 72 dateTitle ( 'var
4080: 5f 31 27 2c 20 27 50 49 20 2d 20 74 68 65 20 6d _1', 'PI - the m
4090: 61 67 69 63 20 6e 75 6d 62 65 72 27 20 29 3b 0d agic number' );.
40a0: 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 .-----..1..</ver
40b0: 62 61 74 69 6d 3e 0d 0a 79 6f 75 20 63 61 6e 20 batim>..you can
40c0: 75 73 65 20 3c 62 3e 53 74 6f 72 65 64 56 61 72 use <b>StoredVar
40d0: 5f 55 70 64 61 74 65 54 69 74 6c 65 3c 2f 62 3e _UpdateTitle</b>
40e0: 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 6d 6f 64 in order to mod
40f0: 69 66 79 20 74 68 65 20 54 69 74 6c 65 20 6f 66 ify the Title of
4100: 20 61 6e 20 61 6c 72 65 61 64 79 20 72 65 67 69 an already regi
4110: 73 74 65 72 65 64 20 53 74 6f 72 65 64 20 50 72 stered Stored Pr
4120: 6f 63 65 64 75 72 65 2e 0d 0a 3c 76 65 72 62 61 ocedure...<verba
4130: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 74 6f tim>..SELECT Sto
4140: 72 65 64 56 61 72 5f 55 70 64 61 74 65 56 61 6c redVar_UpdateVal
4150: 75 65 20 28 20 27 76 61 72 5f 31 27 2c 20 27 40 ue ( 'var_1', '@
4160: 50 49 40 3d 33 2e 31 34 31 35 39 32 36 35 33 35 PI@=3.1415926535
4170: 27 20 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a ' );..-----..1..
4180: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 61 6e 64 </verbatim>..and
4190: 20 66 69 6e 61 6c 6c 79 20 79 6f 75 20 63 61 6e finally you can
41a0: 20 75 73 65 20 3c 62 3e 53 74 6f 72 65 64 56 61 use <b>StoredVa
41b0: 72 5f 55 70 64 61 74 65 56 61 6c 75 65 3c 2f 62 r_UpdateValue</b
41c0: 3e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 6d 6f > in order to mo
41d0: 64 69 66 79 20 74 68 65 20 56 61 72 69 61 62 6c dify the Variabl
41e0: 65 20 77 69 74 68 20 56 61 6c 75 65 20 6f 66 20 e with Value of
41f0: 61 6e 20 61 6c 72 65 61 64 79 20 72 65 67 69 73 an already regis
4200: 74 65 72 65 64 20 53 74 6f 72 65 64 20 56 61 72 tered Stored Var
4210: 69 61 62 6c 65 2e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c iable...</li>..<
4220: 2f 6f 6c 3e 0d 0a 3c 62 72 3e 3c 68 72 3e 0d 0a /ol>..<br><hr>..
4230: 3c 68 32 3e 54 75 74 6f 72 69 61 6c 20 23 31 3c <h2>Tutorial #1<
4240: 2f 68 32 3e 0d 0a 3c 74 61 62 6c 65 20 62 67 63 /h2>..<table bgc
4250: 6f 6c 6f 72 3d 22 23 66 38 66 38 64 38 22 20 63 olor="#f8f8d8" c
4260: 65 6c 6c 70 61 64 64 69 6e 67 3d 22 36 22 20 63 ellpadding="6" c
4270: 65 6c 6c 73 70 61 63 69 6e 67 3d 22 38 22 3e 3c ellspacing="8"><
4280: 74 72 3e 3c 74 64 3e 0d 0a 41 6c 6c 20 74 68 65 tr><td>..All the
4290: 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 75 74 6f 72 following tutor
42a0: 69 61 6c 73 20 61 72 65 20 62 61 73 65 64 20 6f ials are based o
42b0: 6e 20 74 68 65 20 73 61 6d 65 20 73 61 6d 70 6c n the same sampl
42c0: 65 20 64 61 74 61 62 61 73 65 3a 20 70 6c 65 61 e database: plea
42d0: 73 65 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 se <a href="http
42e0: 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73 2e ://www.gaia-gis.
42f0: 69 74 2f 67 61 69 61 2d 73 69 6e 73 2f 73 70 5f it/gaia-sins/sp_
4300: 73 61 6d 70 6c 65 5f 64 62 2e 37 7a 22 3e 64 6f sample_db.7z">do
4310: 77 6e 6c 6f 61 64 20 69 74 3c 2f 61 3e 20 62 65 wnload it</a> be
4320: 66 6f 72 65 20 67 6f 69 6e 67 20 66 75 72 74 68 fore going furth
4330: 65 72 20 61 77 61 79 2e 0d 0a 3c 2f 74 64 3e 3c er away...</td><
4340: 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 3c 62 72 3e /tr></table><br>
4350: 0d 0a 41 73 20 79 6f 75 20 63 61 6e 20 65 61 73 ..As you can eas
4360: 69 6c 79 20 63 68 65 63 6b 20 74 68 69 73 20 64 ily check this d
4370: 61 74 61 62 61 73 65 20 63 6f 6e 74 61 69 6e 73 atabase contains
4380: 20 74 68 72 65 65 20 53 70 61 74 69 61 6c 20 54 three Spatial T
4390: 61 62 6c 65 73 20 72 65 70 72 65 73 65 6e 74 69 ables representi
43a0: 6e 67 20 74 68 65 20 3c 62 3e 3c 69 3e 41 64 6d ng the <b><i>Adm
43b0: 69 6e 69 73 74 72 61 74 69 76 65 20 42 6f 75 6e inistrative Boun
43c0: 64 61 72 69 65 73 3c 2f 69 3e 3c 2f 62 3e 20 6f daries</i></b> o
43d0: 66 20 61 6c 6c 20 49 74 61 6c 69 61 6e 20 4d 75 f all Italian Mu
43e0: 6e 69 63 69 70 61 6c 69 74 69 65 73 20 61 73 20 nicipalities as
43f0: 6f 66 66 69 63 69 61 6c 6c 79 20 64 65 74 65 72 officially deter
4400: 6d 69 6e 65 64 20 62 79 20 3c 61 20 68 72 65 66 mined by <a href
4410: 3d 22 68 74 74 70 73 3a 2f 2f 65 6e 2e 77 69 6b ="https://en.wik
4420: 69 70 65 64 69 61 2e 6f 72 67 2f 77 69 6b 69 2f ipedia.org/wiki/
4430: 4e 61 74 69 6f 6e 61 6c 5f 49 6e 73 74 69 74 75 National_Institu
4440: 74 65 5f 6f 66 5f 53 74 61 74 69 73 74 69 63 73 te_of_Statistics
4450: 5f 28 49 74 61 6c 79 29 22 3e 49 53 54 41 54 3c _(Italy)">ISTAT<
4460: 2f 61 3e 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e /a>:..<ul>..<li>
4470: 74 68 65 72 65 20 61 72 65 20 74 68 72 65 65 20 there are three
4480: 64 69 66 66 65 72 65 6e 74 20 74 61 62 6c 65 73 different tables
4490: 2c 20 65 61 63 68 20 6f 6e 65 20 63 6f 72 72 65 , each one corre
44a0: 73 70 6f 6e 64 69 6e 67 20 74 6f 20 61 20 73 70 sponding to a sp
44b0: 65 63 69 66 69 63 20 4e 61 74 69 6f 6e 61 6c 20 ecific National
44c0: 43 65 6e 73 75 73 20 28 79 65 61 72 73 20 31 39 Census (years 19
44d0: 39 31 2c 20 32 30 30 31 20 61 6e 64 20 32 30 31 91, 2001 and 201
44e0: 31 20 61 72 65 20 61 76 61 69 6c 61 62 6c 65 29 1 are available)
44f0: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6c 6c 20 .</li>..<li>all
4500: 74 68 72 65 65 20 74 61 62 6c 65 73 20 68 61 76 three tables hav
4510: 65 20 65 78 61 63 74 6c 79 20 74 68 65 20 73 61 e exactly the sa
4520: 6d 65 20 6c 61 79 6f 75 74 2e 3c 2f 6c 69 3e 0d me layout.</li>.
4530: 0a 3c 6c 69 3e 41 64 6d 69 6e 69 73 74 72 61 74 .<li>Administrat
4540: 69 76 65 20 42 6f 75 6e 64 61 72 69 65 73 20 61 ive Boundaries a
4550: 72 65 20 61 6c 77 61 79 73 20 72 65 70 72 65 73 re always repres
4560: 65 6e 74 65 64 20 61 73 20 4d 75 6c 74 69 50 6f ented as MultiPo
4570: 6c 79 67 6f 6e 73 20 28 53 72 69 64 3d 33 32 36 lygons (Srid=326
4580: 33 32 29 2e 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d 32)...</ul><br>.
4590: 0a 3c 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72 3d .<table bgcolor=
45a0: 22 23 66 38 66 38 64 38 22 20 63 65 6c 6c 70 61 "#f8f8d8" cellpa
45b0: 64 64 69 6e 67 3d 22 36 22 20 63 65 6c 6c 73 70 dding="6" cellsp
45c0: 61 63 69 6e 67 3d 22 38 22 3e 3c 74 72 3e 3c 74 acing="8"><tr><t
45d0: 64 3e 0d 0a 3c 68 34 3e 54 68 65 20 50 72 6f 62 d>..<h4>The Prob
45e0: 6c 65 6d 3c 2f 68 34 3e 0d 0a 57 65 27 6c 6c 20 lem</h4>..We'll
45f0: 67 6f 20 74 6f 20 69 6d 70 6c 65 6d 65 6e 74 20 go to implement
4600: 61 20 3c 62 3e 50 72 6f 63 65 64 75 72 65 3c 2f a <b>Procedure</
4610: 62 3e 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 65 b> intended to e
4620: 78 70 6f 72 74 20 73 65 6c 65 63 74 65 64 20 53 xport selected S
4630: 68 61 70 65 66 69 6c 65 73 2e 0d 0a 3c 75 6c 3e hapefiles...<ul>
4640: 0d 0a 3c 6c 69 3e 54 68 65 20 43 65 6e 73 75 73 ..<li>The Census
4650: 20 59 65 61 72 20 6d 75 73 74 20 62 65 20 66 72 Year must be fr
4660: 65 65 6c 79 20 73 65 6c 65 63 74 61 62 6c 65 2e eely selectable.
4670: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 41 20 72 65 71 </li>..<li>A req
4680: 75 69 72 65 64 20 66 65 61 74 75 72 65 20 69 73 uired feature is
4690: 20 61 6c 6c 6f 77 69 6e 67 20 66 6f 72 20 66 72 allowing for fr
46a0: 65 65 6c 79 20 66 69 6c 74 65 72 69 6e 67 20 61 eely filtering a
46b0: 20 73 69 6e 67 6c 65 20 4d 75 6e 69 63 69 70 61 single Municipa
46c0: 6c 69 74 79 20 6f 72 20 61 6c 6c 20 4d 75 6e 69 lity or all Muni
46d0: 63 69 70 61 6c 69 74 69 65 73 20 62 65 6c 6f 6e cipalities belon
46e0: 67 69 6e 67 20 74 6f 20 74 68 65 20 73 61 6d 65 ging to the same
46f0: 20 50 72 6f 76 69 6e 63 65 20 6f 72 20 52 65 67 Province or Reg
4700: 69 6f 6e 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 52 ion.</li>..<li>R
4710: 65 70 72 6f 6a 65 63 74 69 6e 67 20 74 6f 20 73 eprojecting to s
4720: 6f 6d 65 20 61 6c 74 65 72 6e 61 74 69 76 65 20 ome alternative
4730: 53 52 49 44 20 73 68 6f 75 6c 64 20 62 65 20 61 SRID should be a
4740: 20 73 75 70 70 6f 72 74 65 64 20 66 65 61 74 75 supported featu
4750: 72 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 57 68 re.</li>..<li>Wh
4760: 69 6c 65 20 64 6f 69 6e 67 20 61 6c 6c 20 74 68 ile doing all th
4770: 69 73 20 77 65 27 6c 6c 20 6f 62 76 69 6f 75 73 is we'll obvious
4780: 6c 79 20 74 72 79 20 74 6f 20 74 61 6b 65 20 66 ly try to take f
4790: 75 6c 6c 20 61 64 76 61 6e 74 61 67 65 20 66 72 ull advantage fr
47a0: 6f 6d 20 75 73 69 6e 67 20 3c 62 3e 56 61 72 69 om using <b>Vari
47b0: 61 62 6c 65 73 3c 2f 62 3e 20 73 6f 20 74 6f 20 ables</b> so to
47c0: 6d 61 6b 65 20 74 68 65 20 50 72 6f 63 65 64 75 make the Procedu
47d0: 72 65 20 61 73 20 67 65 6e 65 72 69 63 20 61 6e re as generic an
47e0: 64 20 66 6c 65 78 69 62 6c 65 20 61 73 20 70 6f d flexible as po
47f0: 73 73 69 62 6c 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f ssible.</li>..</
4800: 75 6c 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 3c ul>..</td></tr><
4810: 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 3c 76 65 /table><br>..<ve
4820: 72 62 61 74 69 6d 3e 0d 0a 2d 2d 0d 0a 2d 2d 20 rbatim>..--..--
4830: 72 65 6d 6f 76 69 6e 67 20 74 68 65 20 77 6f 72 removing the wor
4840: 6b 20 74 61 62 6c 65 20 28 6a 75 73 74 20 69 6e k table (just in
4850: 20 63 61 73 65 20 69 74 20 61 6c 72 65 61 64 79 case it already
4860: 20 65 78 69 73 74 73 29 0d 0a 2d 2d 0d 0a 53 45 exists)..--..SE
4870: 4c 45 43 54 20 44 72 6f 70 47 65 6f 54 61 62 6c LECT DropGeoTabl
4880: 65 28 27 74 72 61 6e 73 69 65 6e 74 5f 74 61 62 e('transient_tab
4890: 6c 65 27 29 3b 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20 le');....--..--
48a0: 69 6e 73 65 72 74 69 6e 67 20 73 65 6c 65 63 74 inserting select
48b0: 65 64 20 64 61 74 61 20 69 6e 74 6f 20 74 68 65 ed data into the
48c0: 20 77 6f 72 6b 20 74 61 62 6c 65 0d 0a 2d 2d 0d work table..--.
48d0: 0a 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 72 .CREATE TABLE tr
48e0: 61 6e 73 69 65 6e 74 5f 74 61 62 6c 65 20 41 53 ansient_table AS
48f0: 0d 0a 53 45 4c 45 43 54 20 69 64 2c 20 69 73 74 ..SELECT id, ist
4900: 61 74 2c 20 6e 61 6d 65 2c 20 70 72 6f 76 69 6e at, name, provin
4910: 63 65 2c 20 72 65 67 69 6f 6e 2c 20 53 54 5f 54 ce, region, ST_T
4920: 72 61 6e 73 66 6f 72 6d 28 67 65 6f 6d 2c 20 40 ransform(geom, @
4930: 73 72 69 64 40 29 20 41 53 20 67 65 6f 6d 0d 0a srid@) AS geom..
4940: 46 52 4f 4d 20 6d 75 6e 69 63 69 70 61 6c 69 74 FROM municipalit
4950: 69 65 73 5f 40 79 65 61 72 40 0d 0a 57 48 45 52 ies_@year@..WHER
4960: 45 20 28 55 70 70 65 72 28 6e 61 6d 65 29 20 3d E (Upper(name) =
4970: 20 55 70 70 65 72 28 27 40 6d 75 6e 69 63 69 70 Upper('@municip
4980: 61 6c 69 74 79 40 27 29 20 4f 52 20 55 70 70 65 ality@') OR Uppe
4990: 72 28 70 72 6f 76 69 6e 63 65 29 20 3d 20 55 70 r(province) = Up
49a0: 70 65 72 28 27 40 70 72 6f 76 69 6e 63 65 40 27 per('@province@'
49b0: 29 20 4f 52 20 55 70 70 65 72 28 72 65 67 69 6f ) OR Upper(regio
49c0: 6e 29 20 3d 20 55 70 70 65 72 28 27 40 72 65 67 n) = Upper('@reg
49d0: 69 6f 6e 40 27 29 29 3b 0d 0a 0d 0a 2d 2d 0d 0a ion@'));....--..
49e0: 2d 2d 20 70 72 6f 70 65 72 6c 79 20 72 65 63 6f -- properly reco
49f0: 76 65 72 69 6e 67 20 74 68 65 20 77 6f 72 6b 20 vering the work
4a00: 74 61 62 6c 65 0d 0a 2d 2d 0d 0a 53 45 4c 45 43 table..--..SELEC
4a10: 54 20 52 65 63 6f 76 65 72 47 65 6f 6d 65 74 72 T RecoverGeometr
4a20: 79 43 6f 6c 75 6d 6e 28 27 74 72 61 6e 73 69 65 yColumn('transie
4a30: 6e 74 5f 74 61 62 6c 65 27 2c 20 27 67 65 6f 6d nt_table', 'geom
4a40: 27 2c 20 40 73 72 69 64 40 2c 20 27 4d 55 4c 54 ', @srid@, 'MULT
4a50: 49 50 4f 4c 59 47 4f 4e 27 2c 20 27 58 59 27 29 IPOLYGON', 'XY')
4a60: 3b 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 20 65 78 70 6f ;....--..-- expo
4a70: 72 74 69 6e 67 20 66 72 6f 6d 20 74 68 65 20 77 rting from the w
4a80: 6f 72 6b 20 74 61 62 6c 65 20 69 6e 74 6f 20 74 ork table into t
4a90: 68 65 20 53 68 61 70 65 66 69 6c 65 0d 0a 2d 2d he Shapefile..--
4aa0: 0d 0a 53 45 4c 45 43 54 20 45 78 70 6f 72 74 53 ..SELECT ExportS
4ab0: 68 70 28 27 74 72 61 6e 73 69 65 6e 74 5f 74 61 hp('transient_ta
4ac0: 62 6c 65 27 2c 20 27 67 65 6f 6d 27 2c 20 27 40 ble', 'geom', '@
4ad0: 73 68 70 5f 70 61 74 68 40 27 2c 20 27 43 50 31 shp_path@', 'CP1
4ae0: 32 35 32 27 29 3b 0d 0a 0d 0a 2d 2d 0d 0a 2d 2d 252');....--..--
4af0: 20 72 65 6d 6f 76 69 6e 67 20 74 68 65 20 77 6f removing the wo
4b00: 72 6b 20 74 61 62 6c 65 0d 0a 2d 2d 0d 0a 53 45 rk table..--..SE
4b10: 4c 45 43 54 20 44 72 6f 70 47 65 6f 54 61 62 6c LECT DropGeoTabl
4b20: 65 28 27 74 72 61 6e 73 69 65 6e 74 5f 74 61 62 e('transient_tab
4b30: 6c 65 27 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 le');..</verbati
4b40: 6d 3e 0d 0a 41 73 20 79 6f 75 20 63 61 6e 20 73 m>..As you can s
4b50: 65 65 20 74 68 65 20 70 72 6f 70 6f 73 65 64 20 ee the proposed
4b60: 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 69 implementation i
4b70: 73 20 62 61 73 69 63 61 6c 6c 79 20 73 69 6d 70 s basically simp
4b80: 6c 65 2e 20 4e 6f 77 20 79 6f 75 20 73 69 6d 70 le. Now you simp
4b90: 6c 79 20 68 61 76 65 20 74 6f 20 3c 62 3e 63 75 ly have to <b>cu
4ba0: 74 26 70 61 73 74 65 3c 2f 62 3e 20 74 68 65 20 t&paste</b> the
4bb0: 61 62 6f 76 65 20 53 51 4c 20 62 6f 64 79 20 73 above SQL body s
4bc0: 61 76 69 6e 67 20 69 74 20 69 6e 74 6f 20 61 20 aving it into a
4bd0: 66 69 6c 65 20 6e 61 6d 65 64 20 3c 62 3e 74 65 file named <b>te
4be0: 73 74 5f 73 70 2e 74 78 74 3c 2f 62 3e 20 66 6f st_sp.txt</b> fo
4bf0: 72 20 66 75 72 74 68 65 72 20 75 73 61 67 65 2e r further usage.
4c00: 3c 62 72 3e 3c 62 72 3e 0d 0a 46 65 77 20 69 6e <br><br>..Few in
4c10: 74 65 72 65 73 74 69 6e 67 20 64 65 74 61 69 6c teresting detail
4c20: 73 20 77 6f 72 74 68 20 74 6f 20 62 65 20 65 78 s worth to be ex
4c30: 70 6c 61 69 6e 65 64 3a 0d 0a 3c 75 6c 3e 0d 0a plained:..<ul>..
4c40: 3c 6c 69 3e 56 61 72 69 61 62 6c 65 20 3c 62 3e <li>Variable <b>
4c50: 40 79 65 61 72 40 3c 2f 62 3e 20 69 73 20 69 6e @year@</b> is in
4c60: 74 65 6e 64 65 64 20 74 6f 20 73 65 6c 65 63 74 tended to select
4c70: 20 77 68 69 63 68 20 73 70 65 63 69 66 69 63 20 which specific
4c80: 53 70 61 74 69 61 6c 20 54 61 62 6c 65 20 77 69 Spatial Table wi
4c90: 6c 6c 20 62 65 20 71 75 65 72 69 65 64 2e 3c 2f ll be queried.</
4ca0: 6c 69 3e 0d 0a 3c 6c 69 3e 56 61 72 69 61 62 6c li>..<li>Variabl
4cb0: 65 20 3c 62 3e 40 73 72 69 64 40 3c 2f 62 3e 20 e <b>@srid@</b>
4cc0: 69 73 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 73 is intended to s
4cd0: 70 65 63 69 66 79 20 74 68 65 20 6f 75 74 70 75 pecify the outpu
4ce0: 74 20 53 52 49 44 2e 3c 2f 6c 69 3e 0d 0a 3c 6c t SRID.</li>..<l
4cf0: 69 3e 56 61 72 69 61 62 6c 65 20 3c 62 3e 40 73 i>Variable <b>@s
4d00: 68 70 5f 70 61 74 68 40 3c 2f 62 3e 20 69 73 20 hp_path@</b> is
4d10: 69 6e 74 65 6e 64 65 64 20 74 6f 20 73 70 65 63 intended to spec
4d20: 69 66 79 20 74 68 65 20 70 61 74 68 6e 61 6d 65 ify the pathname
4d30: 20 6f 66 20 74 68 65 20 6f 75 74 70 75 74 20 53 of the output S
4d40: 68 61 70 65 66 69 6c 65 2e 3c 2f 6c 69 3e 0d 0a hapefile.</li>..
4d50: 3c 6c 69 3e 56 61 72 69 61 62 6c 65 73 20 3c 62 <li>Variables <b
4d60: 3e 40 6d 75 6e 69 63 69 70 61 6c 69 74 79 40 3c >@municipality@<
4d70: 2f 62 3e 2c 20 3c 62 3e 40 70 72 6f 76 69 6e 63 /b>, <b>@provinc
4d80: 65 40 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e 40 72 e@</b> and <b>@r
4d90: 65 67 69 6f 6e 40 3c 2f 62 3e 20 61 72 65 20 69 egion@</b> are i
4da0: 6e 74 65 6e 64 65 64 20 74 6f 20 73 70 65 63 69 ntended to speci
4db0: 66 79 20 74 68 65 20 69 6e 74 65 6e 64 65 64 20 fy the intended
4dc0: 66 69 6c 74 65 72 69 6e 67 20 63 72 69 74 65 72 filtering criter
4dd0: 69 61 2e 3c 62 72 3e 0d 0a 54 68 69 73 20 69 73 ia.<br>..This is
4de0: 20 61 20 6c 69 74 74 6c 65 20 62 69 74 20 74 72 a little bit tr
4df0: 69 63 6b 79 2c 20 73 6f 20 77 65 27 6c 6c 20 67 icky, so we'll g
4e00: 6f 20 69 6e 20 66 75 72 74 68 65 72 20 64 65 70 o in further dep
4e10: 74 68 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 54 th:..<ul>..<li>T
4e20: 68 65 73 65 20 56 61 72 69 61 62 6c 65 73 20 61 hese Variables a
4e30: 72 65 20 65 78 70 65 63 74 65 64 20 74 6f 20 62 re expected to b
4e40: 65 20 61 63 74 75 61 6c 6c 79 20 72 65 70 6c 61 e actually repla
4e50: 63 65 64 20 62 79 20 3c 62 3e 74 65 78 74 20 73 ced by <b>text s
4e60: 74 72 69 6e 67 20 76 61 6c 75 65 73 3c 2f 62 3e tring values</b>
4e70: 3b 20 73 6f 20 77 65 27 76 65 20 63 6f 6e 73 69 ; so we've consi
4e80: 73 74 65 6e 74 6c 79 20 3c 62 3e 73 69 6e 67 6c stently <b>singl
4e90: 65 2d 71 75 6f 74 65 64 3c 2f 62 3e 20 74 68 65 e-quoted</b> the
4ea0: 20 76 61 72 69 61 62 6c 65 20 73 79 6d 62 6f 6c variable symbol
4eb0: 2c 20 73 6f 20 74 6f 20 61 6c 6c 6f 77 20 66 6f , so to allow fo
4ec0: 72 20 61 6e 20 65 61 73 69 65 72 20 76 61 6c 75 r an easier valu
4ed0: 65 20 72 65 70 6c 61 63 65 6d 65 6e 74 2e 3c 2f e replacement.</
4ee0: 6c 69 3e 0d 0a 3c 6c 69 3e 57 65 20 61 72 65 20 li>..<li>We are
4ef0: 73 79 73 74 65 6d 61 74 69 63 61 6c 6c 79 20 75 systematically u
4f00: 73 69 6e 67 20 74 68 65 20 3c 62 3e 55 70 70 65 sing the <b>Uppe
4f10: 72 28 29 3c 2f 62 3e 20 66 75 6e 63 74 69 6f 6e r()</b> function
4f20: 20 73 69 6d 70 6c 79 20 62 65 63 61 75 73 65 20 simply because
4f30: 50 72 6f 76 69 6e 63 65 20 61 6e 64 20 52 65 67 Province and Reg
4f40: 69 6f 6e 20 6e 61 6d 65 20 61 72 65 20 61 6c 6c ion name are all
4f50: 2d 75 70 70 65 72 63 61 73 65 20 69 6e 20 79 65 -uppercase in ye
4f60: 61 72 73 20 31 39 39 31 20 61 6e 64 20 32 30 30 ars 1991 and 200
4f70: 31 20 62 75 74 20 6e 6f 74 20 6f 6e 20 79 65 61 1 but not on yea
4f80: 72 20 32 30 31 31 2e 3c 62 72 3e 0d 0a 53 79 73 r 2011.<br>..Sys
4f90: 74 65 6d 61 74 69 63 61 6c 6c 79 20 75 73 69 6e tematically usin
4fa0: 67 20 55 70 70 65 72 28 29 20 77 69 6c 6c 20 68 g Upper() will h
4fb0: 6f 6d 6f 67 65 6e 69 7a 65 20 61 6c 6c 20 6e 61 omogenize all na
4fc0: 6d 65 73 20 69 6e 20 61 20 63 6f 6e 73 69 73 74 mes in a consist
4fd0: 65 6e 74 20 77 61 79 2e 3c 2f 6c 69 3e 0d 0a 3c ent way.</li>..<
4fe0: 6c 69 3e 57 65 20 61 72 65 20 75 73 69 6e 67 20 li>We are using
4ff0: 74 68 72 65 65 20 73 65 70 61 72 61 74 65 20 63 three separate c
5000: 6f 6d 70 61 72 69 73 6f 6e 73 20 28 6f 6e 65 20 omparisons (one
5010: 66 6f 72 20 4d 75 6e 69 63 69 70 61 6c 69 74 79 for Municipality
5020: 2c 20 6f 6e 65 20 66 6f 72 20 50 72 6f 76 69 6e , one for Provin
5030: 63 65 20 61 6e 64 20 6f 6e 65 20 66 6f 72 20 52 ce and one for R
5040: 65 67 69 6f 6e 29 20 63 6f 6e 6e 65 63 74 65 64 egion) connected
5050: 20 62 79 20 3c 62 3e 4f 52 3c 2f 62 3e 20 6c 6f by <b>OR</b> lo
5060: 67 69 63 61 6c 20 6f 70 65 72 61 74 6f 72 73 20 gical operators
5070: 73 6f 20 74 6f 20 6d 61 6b 65 20 70 6f 73 73 69 so to make possi
5080: 62 6c 65 20 73 70 65 63 69 66 79 69 6e 67 20 6a ble specifying j
5090: 75 73 74 20 61 20 73 69 6e 67 6c 65 20 66 69 6c ust a single fil
50a0: 74 65 72 20 63 6c 61 75 73 65 2e 3c 62 72 3e 0d ter clause.<br>.
50b0: 0a 3c 75 3e 52 65 63 61 6c 6c 3c 2f 75 3e 3a 20 .<u>Recall</u>:
50c0: 75 6e 61 73 73 69 67 6e 65 64 20 56 61 72 69 61 unassigned Varia
50d0: 62 6c 65 73 20 77 69 6c 6c 20 64 65 66 61 75 6c bles will defaul
50e0: 74 20 74 6f 20 4e 55 4c 4c 3b 20 73 6f 20 62 79 t to NULL; so by
50f0: 20 6a 75 73 74 20 64 65 63 6c 61 72 69 6e 67 20 just declaring
5100: 0d 0a 3c 62 3e 40 70 72 6f 76 69 6e 63 65 40 3d ..<b>@province@=
5110: 41 72 65 7a 7a 6f 3c 2f 62 3e 20 77 65 27 6c 6c Arezzo</b> we'll
5120: 20 74 68 65 6e 20 67 65 74 20 61 20 3c 62 3e 3c then get a <b><
5130: 69 3e 63 6f 6f 6b 65 64 3c 2f 69 3e 3c 2f 62 3e i>cooked</i></b>
5140: 20 57 48 45 52 45 20 63 6c 61 75 73 65 20 6c 69 WHERE clause li
5150: 6b 65 20 74 68 69 73 3a 0d 0a 3c 76 65 72 62 61 ke this:..<verba
5160: 74 69 6d 3e 0d 0a 57 48 45 52 45 20 28 55 70 70 tim>..WHERE (Upp
5170: 65 72 28 6e 61 6d 65 29 20 3d 20 55 70 70 65 72 er(name) = Upper
5180: 28 27 4e 55 4c 4c 27 29 20 4f 52 20 55 70 70 65 ('NULL') OR Uppe
5190: 72 28 70 72 6f 76 69 6e 63 65 29 20 3d 20 55 70 r(province) = Up
51a0: 70 65 72 28 27 41 72 65 7a 7a 6f 27 29 20 4f 52 per('Arezzo') OR
51b0: 20 55 70 70 65 72 28 72 65 67 69 6f 6e 29 20 3d Upper(region) =
51c0: 20 55 70 70 65 72 28 27 4e 55 4c 4c 27 29 29 0d Upper('NULL')).
51d0: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 2f .</verbatim>..</
51e0: 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 2f 6c 69 li>..</ul>..</li
51f0: 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 62 72 3e 0d 0a >..</ul>..<br>..
5200: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 <verbatim>..SELE
5210: 43 54 20 53 71 6c 50 72 6f 63 5f 45 78 65 63 75 CT SqlProc_Execu
5220: 74 65 28 20 53 71 6c 50 72 6f 63 5f 46 72 6f 6d te( SqlProc_From
5230: 46 69 6c 65 20 28 27 43 3a 2f 75 73 65 72 73 2f File ('C:/users/
5240: 6a 6f 65 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f joe/stored_proc_
5250: 74 65 73 74 2f 74 65 73 74 5f 73 70 2e 74 78 74 test/test_sp.txt
5260: 27 29 2c 0d 0a 20 20 27 40 73 72 69 64 40 3d 33 '),.. '@srid@=3
5270: 30 30 34 27 2c 20 27 40 79 65 61 72 40 3d 32 30 004', '@year@=20
5280: 30 31 27 2c 20 27 40 72 65 67 69 6f 6e 40 3d 4c 01', '@region@=L
5290: 61 7a 69 6f 27 2c 20 27 40 73 68 70 5f 70 61 74 azio', '@shp_pat
52a0: 68 40 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f h@=C:/users/joe/
52b0: 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 stored_proc_test
52c0: 2f 6c 61 7a 69 6f 5f 32 30 30 31 5f 33 30 30 34 /lazio_2001_3004
52d0: 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d ');..-----..1...
52e0: 0a 53 45 4c 45 43 54 20 53 71 6c 50 72 6f 63 5f .SELECT SqlProc_
52f0: 45 78 65 63 75 74 65 28 20 53 71 6c 50 72 6f 63 Execute( SqlProc
5300: 5f 46 72 6f 6d 46 69 6c 65 20 28 27 43 3a 2f 75 _FromFile ('C:/u
5310: 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f sers/joe/stored_
5320: 70 72 6f 63 5f 74 65 73 74 2f 74 65 73 74 5f 73 proc_test/test_s
5330: 70 2e 74 78 74 27 29 2c 0d 0a 20 20 27 40 73 72 p.txt'),.. '@sr
5340: 69 64 40 3d 34 33 32 36 27 2c 20 27 40 79 65 61 id@=4326', '@yea
5350: 72 40 3d 31 39 39 31 27 2c 20 27 40 72 65 67 69 r@=1991', '@regi
5360: 6f 6e 40 3d 70 75 67 6c 69 61 27 2c 20 27 40 73 on@=puglia', '@s
5370: 68 70 5f 70 61 74 68 40 3d 43 3a 2f 75 73 65 72 hp_path@=C:/user
5380: 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70 72 6f s/joe/stored_pro
5390: 63 5f 74 65 73 74 2f 70 75 67 6c 69 61 5f 31 39 c_test/puglia_19
53a0: 39 31 5f 34 33 32 36 27 29 3b 0d 0a 2d 2d 2d 2d 91_4326');..----
53b0: 2d 0d 0a 31 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 -..1....SELECT S
53c0: 71 6c 50 72 6f 63 5f 45 78 65 63 75 74 65 28 20 qlProc_Execute(
53d0: 53 71 6c 50 72 6f 63 5f 46 72 6f 6d 46 69 6c 65 SqlProc_FromFile
53e0: 20 28 27 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f ('C:/users/joe/
53f0: 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 stored_proc_test
5400: 2f 74 65 73 74 5f 73 70 2e 74 78 74 27 29 2c 0d /test_sp.txt'),.
5410: 0a 20 20 27 40 73 72 69 64 40 3d 33 30 30 33 27 . '@srid@=3003'
5420: 2c 20 27 40 79 65 61 72 40 3d 32 30 31 31 27 2c , '@year@=2011',
5430: 20 27 40 70 72 6f 76 69 6e 63 65 40 3d 41 52 45 '@province@=ARE
5440: 5a 5a 4f 27 2c 20 27 40 73 68 70 5f 70 61 74 68 ZZO', '@shp_path
5450: 40 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 75 @=C:/users/joe/u
5460: 63 73 35 67 62 2f 73 74 6f 72 65 64 5f 70 72 6f cs5gb/stored_pro
5470: 63 5f 74 65 73 74 2f 61 72 65 7a 7a 6f 5f 32 30 c_test/arezzo_20
5480: 31 31 5f 33 30 30 33 27 29 3b 0d 0a 2d 2d 2d 2d 11_3003');..----
5490: 2d 0d 0a 31 0d 0a 0d 0a 53 45 4c 45 43 54 20 53 -..1....SELECT S
54a0: 71 6c 50 72 6f 63 5f 45 78 65 63 75 74 65 28 20 qlProc_Execute(
54b0: 53 71 6c 50 72 6f 63 5f 46 72 6f 6d 46 69 6c 65 SqlProc_FromFile
54c0: 20 28 27 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f ('C:/users/joe/
54d0: 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 stored_proc_test
54e0: 2f 74 65 73 74 5f 73 70 2e 74 78 74 27 29 2c 0d /test_sp.txt'),.
54f0: 0a 20 20 27 40 73 72 69 64 40 3d 33 30 30 33 27 . '@srid@=3003'
5500: 2c 20 27 40 79 65 61 72 40 3d 32 30 30 31 27 2c , '@year@=2001',
5510: 20 27 40 6d 75 6e 69 63 69 70 61 6c 69 74 79 40 '@municipality@
5520: 3d 41 52 45 5a 5a 4f 27 2c 20 27 40 73 68 70 5f =AREZZO', '@shp_
5530: 70 61 74 68 40 3d 43 3a 2f 75 73 65 72 73 2f 6a path@=C:/users/j
5540: 6f 65 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 oe/stored_proc_t
5550: 65 73 74 2f 63 6f 6d 5f 61 72 65 7a 7a 6f 5f 32 est/com_arezzo_2
5560: 30 30 31 5f 33 30 30 33 27 29 3b 0d 0a 2d 2d 2d 001_3003');..---
5570: 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69 --..1..</verbati
5580: 6d 3e 0d 0a 49 6e 20 74 68 69 73 20 66 69 72 73 m>..In this firs
5590: 74 20 74 75 74 6f 72 69 61 6c 20 77 65 27 6c 6c t tutorial we'll
55a0: 20 61 6c 77 61 79 73 20 3c 62 3e 65 78 65 63 75 always <b>execu
55b0: 74 65 3c 2f 62 3e 20 61 20 50 72 6f 63 65 64 75 te</b> a Procedu
55c0: 72 65 20 6c 6f 61 64 65 64 20 66 72 6f 6d 20 61 re loaded from a
55d0: 6e 20 65 78 74 65 72 6e 61 6c 20 66 69 6c 65 2e n external file.
55e0: 3c 62 72 3e 0d 0a 41 73 20 79 6f 75 20 63 61 6e <br>..As you can
55f0: 20 73 65 65 20 65 78 65 63 75 74 69 6e 67 20 61 see executing a
5600: 20 50 72 6f 63 65 64 75 72 65 20 69 73 20 61 20 Procedure is a
5610: 73 74 72 61 69 67 68 74 66 6f 72 77 61 72 64 20 straightforward
5620: 74 61 73 6b 3b 20 79 6f 75 20 73 69 6d 70 6c 79 task; you simply
5630: 20 68 61 76 65 20 74 6f 20 73 70 65 63 69 66 79 have to specify
5640: 20 61 6e 20 61 70 70 72 6f 70 72 69 61 74 65 20 an appropriate
5650: 6c 69 73 74 20 6f 66 20 3c 62 3e 56 61 72 69 61 list of <b>Varia
5660: 62 6c 65 20 56 61 6c 75 65 73 3c 2f 62 3e 20 61 ble Values</b> a
5670: 6e 64 20 74 68 61 74 27 73 20 61 6c 6c 2e 0d 0a nd that's all...
5680: 3c 68 72 3e 0d 0a 3c 68 32 3e 54 75 74 6f 72 69 <hr>..<h2>Tutori
5690: 61 6c 20 23 32 3c 2f 68 32 3e 0d 0a 3c 76 65 72 al #2</h2>..<ver
56a0: 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 batim>..SELECT S
56b0: 74 6f 72 65 64 50 72 6f 63 5f 52 65 67 69 73 74 toredProc_Regist
56c0: 65 72 28 20 27 6d 79 5f 70 72 6f 63 27 2c 20 27 er( 'my_proc', '
56d0: 61 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 75 a Stored Procedu
56e0: 72 65 20 66 6f 72 20 65 78 70 6f 72 74 69 6e 67 re for exporting
56f0: 20 73 65 6c 65 63 74 65 64 20 53 68 61 70 65 66 selected Shapef
5700: 69 6c 65 73 27 2c 20 53 71 6c 50 72 6f 63 5f 46 iles', SqlProc_F
5710: 72 6f 6d 46 69 6c 65 20 28 27 43 3a 2f 75 73 65 romFile ('C:/use
5720: 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70 72 rs/joe/stored_pr
5730: 6f 63 5f 74 65 73 74 2f 74 65 73 74 5f 73 70 2e oc_test/test_sp.
5740: 74 78 74 27 29 20 29 3b 0d 0a 3c 2f 76 65 72 62 txt') );..</verb
5750: 61 74 69 6d 3e 0d 0a 54 68 69 73 20 73 65 63 6f atim>..This seco
5760: 6e 64 20 74 75 74 6f 72 69 61 6c 20 69 73 20 73 nd tutorial is s
5770: 75 62 73 74 61 6e 74 69 61 6c 6c 79 20 74 68 65 ubstantially the
5780: 20 73 61 6d 65 20 6f 66 20 74 68 65 20 66 69 72 same of the fir
5790: 73 74 20 6f 6e 65 2e 3c 62 72 3e 0d 0a 54 68 65 st one.<br>..The
57a0: 20 75 6e 69 71 75 65 20 64 69 66 66 65 72 65 6e unique differen
57b0: 63 65 20 69 73 20 74 68 61 74 20 6e 6f 77 20 77 ce is that now w
57c0: 65 27 6c 6c 20 67 6f 20 74 6f 20 70 65 72 6d 61 e'll go to perma
57d0: 6e 65 6e 74 6c 79 20 72 65 67 69 73 74 65 72 65 nently registere
57e0: 64 20 61 20 3c 62 3e 53 74 6f 72 65 64 20 50 72 d a <b>Stored Pr
57f0: 6f 63 65 64 75 72 65 3c 2f 62 3e 2e 0d 0a 3c 76 ocedure</b>...<v
5800: 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 erbatim>..SELECT
5810: 20 53 74 6f 72 65 64 50 72 6f 63 5f 45 78 65 63 StoredProc_Exec
5820: 75 74 65 28 20 27 6d 79 5f 70 72 6f 63 27 2c 20 ute( 'my_proc',
5830: 27 40 73 72 69 64 40 3d 33 30 30 34 27 2c 20 27 '@srid@=3004', '
5840: 40 79 65 61 72 40 3d 32 30 30 31 27 2c 20 27 40 @year@=2001', '@
5850: 72 65 67 69 6f 6e 40 3d 4c 61 7a 69 6f 27 2c 20 region@=Lazio',
5860: 27 40 73 68 70 5f 70 61 74 68 40 3d 43 3a 2f 75 '@shp_path@=C:/u
5870: 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f sers/joe/stored_
5880: 70 72 6f 63 5f 74 65 73 74 2f 6c 61 7a 69 6f 5f proc_test/lazio_
5890: 32 30 30 31 5f 33 30 30 34 27 29 3b 0d 0a 2d 2d 2001_3004');..--
58a0: 2d 2d 2d 0d 0a 31 0d 0a 0d 0a 53 45 4c 45 43 54 ---..1....SELECT
58b0: 20 53 74 6f 72 65 64 50 72 6f 63 5f 45 78 65 63 StoredProc_Exec
58c0: 75 74 65 28 20 27 6d 79 5f 70 72 6f 63 27 2c 20 ute( 'my_proc',
58d0: 27 40 73 72 69 64 40 3d 34 33 32 36 27 2c 20 27 '@srid@=4326', '
58e0: 40 79 65 61 72 40 3d 31 39 39 31 27 2c 20 27 40 @year@=1991', '@
58f0: 72 65 67 69 6f 6e 40 3d 70 75 67 6c 69 61 27 2c region@=puglia',
5900: 20 27 40 73 68 70 5f 70 61 74 68 40 3d 43 3a 2f '@shp_path@=C:/
5910: 75 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 users/joe/stored
5920: 5f 70 72 6f 63 5f 74 65 73 74 2f 70 75 67 6c 69 _proc_test/pugli
5930: 61 5f 31 39 39 31 5f 34 33 32 36 27 29 3b 0d 0a a_1991_4326');..
5940: 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a 53 45 4c 45 -----..1....SELE
5950: 43 54 20 53 74 6f 72 65 64 50 72 6f 63 5f 45 78 CT StoredProc_Ex
5960: 65 63 75 74 65 28 20 27 6d 79 5f 70 72 6f 63 27 ecute( 'my_proc'
5970: 2c 20 27 40 73 72 69 64 40 3d 33 30 30 33 27 2c , '@srid@=3003',
5980: 20 27 40 79 65 61 72 40 3d 32 30 31 31 27 2c 20 '@year@=2011',
5990: 27 40 70 72 6f 76 69 6e 63 65 40 3d 41 52 45 5a '@province@=AREZ
59a0: 5a 4f 27 2c 20 27 40 73 68 70 5f 70 61 74 68 40 ZO', '@shp_path@
59b0: 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 2f 73 74 =C:/users/joe/st
59c0: 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 74 2f 61 ored_proc_test/a
59d0: 72 65 7a 7a 6f 5f 32 30 31 31 5f 33 30 30 33 27 rezzo_2011_3003'
59e0: 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a );..-----..1....
59f0: 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50 72 6f SELECT StoredPro
5a00: 63 5f 45 78 65 63 75 74 65 28 20 27 6d 79 5f 70 c_Execute( 'my_p
5a10: 72 6f 63 27 2c 20 27 40 73 72 69 64 40 3d 33 30 roc', '@srid@=30
5a20: 30 33 27 2c 20 27 40 79 65 61 72 40 3d 32 30 30 03', '@year@=200
5a30: 31 27 2c 20 27 40 6d 75 6e 69 63 69 70 61 6c 69 1', '@municipali
5a40: 74 79 40 3d 41 52 45 5a 5a 4f 27 2c 20 27 40 73 ty@=AREZZO', '@s
5a50: 68 70 5f 70 61 74 68 40 3d 43 3a 2f 75 73 65 72 hp_path@=C:/user
5a60: 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f 70 72 6f s/joe/stored_pro
5a70: 63 5f 74 65 73 74 2f 63 6f 6d 5f 61 72 65 7a 7a c_test/com_arezz
5a80: 6f 5f 32 30 30 31 5f 33 30 30 33 27 29 3b 0d 0a o_2001_3003');..
5a90: 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 -----..1..</verb
5aa0: 61 74 69 6d 3e 0d 0a 45 78 65 63 75 74 69 6e 67 atim>..Executing
5ab0: 20 61 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 a Stored Proced
5ac0: 75 72 65 20 69 73 6e 27 74 20 76 65 72 79 20 64 ure isn't very d
5ad0: 69 66 66 65 72 65 6e 74 20 66 72 6f 6d 20 65 78 ifferent from ex
5ae0: 65 63 75 74 69 6e 67 20 61 20 50 72 6f 63 65 64 ecuting a Proced
5af0: 75 72 65 20 73 74 6f 72 65 64 20 69 6e 74 6f 20 ure stored into
5b00: 61 6e 20 65 78 74 65 72 6e 61 6c 20 66 69 6c 65 an external file
5b10: 2e 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65 20 62 67 .<br>..<table bg
5b20: 63 6f 6c 6f 72 3d 22 23 66 38 66 38 64 38 22 20 color="#f8f8d8"
5b30: 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 36 22 20 cellpadding="6"
5b40: 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 38 22 3e cellspacing="8">
5b50: 3c 74 72 3e 3c 74 64 3e 0d 0a 45 78 65 63 75 74 <tr><td>..Execut
5b60: 69 6e 67 20 79 6f 75 72 20 50 72 6f 63 65 64 75 ing your Procedu
5b70: 72 65 73 20 66 72 6f 6d 20 65 78 74 65 72 6e 61 res from externa
5b80: 6c 20 66 69 6c 65 73 20 6f 72 20 70 65 72 6d 61 l files or perma
5b90: 6e 65 6e 74 6c 79 20 72 65 67 69 73 74 65 72 69 nently registeri
5ba0: 6e 67 20 53 74 6f 72 65 64 20 50 72 6f 63 65 64 ng Stored Proced
5bb0: 75 72 65 73 20 64 69 72 65 63 74 6c 79 20 77 69 ures directly wi
5bc0: 74 68 69 6e 20 61 20 64 61 74 61 62 61 73 65 20 thin a database
5bd0: 69 73 20 61 20 6d 61 74 74 65 72 20 6f 66 20 66 is a matter of f
5be0: 72 65 65 20 63 68 6f 69 63 65 2e 3c 62 72 3e 0d ree choice.<br>.
5bf0: 0a 49 66 20 79 6f 75 20 61 72 65 20 70 6c 61 6e .If you are plan
5c00: 6e 69 6e 67 20 74 6f 20 64 65 70 6c 6f 79 20 61 ning to deploy a
5c10: 20 50 72 6f 63 65 64 75 72 65 20 69 6e 74 65 6e Procedure inten
5c20: 64 65 64 20 74 6f 20 73 75 70 70 6f 72 74 20 6d ded to support m
5c30: 61 6e 79 20 64 69 66 66 65 72 65 6e 74 20 64 61 any different da
5c40: 74 61 62 61 73 65 73 2c 20 74 68 65 6e 20 75 73 tabases, then us
5c50: 69 6e 67 20 61 6e 20 65 78 74 65 72 6e 61 6c 20 ing an external
5c60: 66 69 6c 65 20 63 6f 75 6c 64 20 70 72 6f 62 61 file could proba
5c70: 62 6c 79 20 73 69 6d 70 6c 69 66 79 20 79 6f 75 bly simplify you
5c80: 72 20 77 6f 72 6b 2e 3c 62 72 3e 0d 0a 42 75 74 r work.<br>..But
5c90: 20 69 66 20 79 6f 75 20 61 72 65 20 70 6c 61 6e if you are plan
5ca0: 6e 69 6e 67 20 74 6f 20 64 65 70 6c 6f 79 20 61 ning to deploy a
5cb0: 20 50 72 6f 63 65 64 75 72 65 20 69 6e 74 65 6e Procedure inten
5cc0: 64 65 64 20 74 6f 20 61 75 74 6f 6d 61 74 65 20 ded to automate
5cd0: 6d 61 6e 79 20 72 6f 75 74 69 6e 65 6c 79 20 74 many routinely t
5ce0: 61 73 6b 20 74 6f 20 62 65 20 65 78 65 63 75 74 ask to be execut
5cf0: 65 64 20 6d 6f 72 65 20 61 6e 64 20 6d 6f 72 65 ed more and more
5d00: 20 74 69 6d 65 73 20 6f 6e 20 74 68 65 20 73 61 times on the sa
5d10: 6d 65 20 64 61 74 61 62 61 73 65 2c 20 74 68 65 me database, the
5d20: 6e 20 70 65 72 6d 61 6e 65 6e 74 6c 79 20 72 65 n permanently re
5d30: 67 69 73 74 65 72 69 6e 67 20 61 20 53 74 6f 72 gistering a Stor
5d40: 65 64 20 50 72 6f 63 65 64 75 72 65 20 77 6f 75 ed Procedure wou
5d50: 6c 64 20 70 72 6f 62 61 62 6c 79 20 62 65 20 62 ld probably be b
5d60: 65 74 74 65 72 2e 0d 0a 3c 2f 74 64 3e 3c 2f 74 etter...</td></t
5d70: 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 62 72 3e r></table>..<br>
5d80: 3c 68 72 3e 0d 0a 3c 68 32 3e 54 75 74 6f 72 69 <hr>..<h2>Tutori
5d90: 61 6c 20 23 33 3c 2f 68 32 3e 0d 0a 54 68 69 73 al #3</h2>..This
5da0: 20 6c 61 74 65 73 74 20 74 75 74 6f 72 69 61 6c latest tutorial
5db0: 20 69 73 20 6a 75 73 74 20 61 20 73 6d 61 6c 6c is just a small
5dc0: 20 76 61 72 69 61 74 69 6f 6e 20 6f 6e 20 74 68 variation on th
5dd0: 65 20 74 68 65 6d 65 20 69 6e 74 65 6e 64 65 64 e theme intended
5de0: 20 74 6f 20 68 69 67 68 6c 69 67 68 74 20 73 6f to highlight so
5df0: 6d 65 20 70 6f 74 65 6e 74 69 61 6c 6c 79 20 64 me potentially d
5e00: 61 6e 67 65 72 6f 75 73 20 70 69 74 66 61 6c 6c angerous pitfall
5e10: 73 20 72 65 6c 61 74 65 64 20 74 6f 20 3c 62 3e s related to <b>
5e20: 73 69 6e 67 6c 65 2d 71 75 6f 74 69 6e 67 3c 2f single-quoting</
5e30: 62 3e 2e 20 0d 0a 3c 76 65 72 62 61 74 69 6d 3e b>. ..<verbatim>
5e40: 0d 0a 53 45 4c 45 43 54 20 53 74 6f 72 65 64 50 ..SELECT StoredP
5e50: 72 6f 63 5f 45 78 65 63 75 74 65 28 20 27 6d 79 roc_Execute( 'my
5e60: 5f 70 72 6f 63 27 29 2c 20 27 40 73 72 69 64 40 _proc'), '@srid@
5e70: 3d 33 30 30 33 27 2c 20 27 40 79 65 61 72 40 3d =3003', '@year@=
5e80: 32 30 31 31 27 2c 20 27 40 6d 75 6e 69 63 69 70 2011', '@municip
5e90: 61 6c 69 74 79 40 3d 72 69 6f 20 6e 65 6c 6c 27 ality@=rio nell'
5ea0: 27 65 6c 62 61 27 2c 20 27 40 73 68 70 5f 70 61 'elba', '@shp_pa
5eb0: 74 68 40 3d 43 3a 2f 75 73 65 72 73 2f 6a 6f 65 th@=C:/users/joe
5ec0: 2f 73 74 6f 72 65 64 5f 70 72 6f 63 5f 74 65 73 /stored_proc_tes
5ed0: 74 2f 72 69 6f 5f 65 6c 62 61 5f 32 30 31 31 5f t/rio_elba_2011_
5ee0: 33 30 30 33 27 29 3b 0d 0a 2d 2d 2d 2d 2d 0d 0a 3003');..-----..
5ef0: 53 74 6f 72 65 64 50 72 6f 63 20 65 78 63 65 70 StoredProc excep
5f00: 74 69 6f 6e 20 2d 20 61 20 66 61 74 61 6c 20 53 tion - a fatal S
5f10: 51 4c 20 65 72 72 6f 72 20 77 61 73 20 65 6e 63 QL error was enc
5f20: 6f 75 6e 74 65 72 65 64 2e 0d 0a 0d 0a 53 45 4c ountered.....SEL
5f30: 45 43 54 20 53 71 6c 50 72 6f 63 5f 47 65 74 4c ECT SqlProc_GetL
5f40: 61 73 74 45 72 72 6f 72 28 29 3b 0d 0a 2d 2d 2d astError();..---
5f50: 2d 2d 0d 0a 67 61 69 61 5f 73 71 6c 5f 70 72 6f --..gaia_sql_pro
5f60: 63 5f 65 78 65 63 75 74 65 3a 20 6e 65 61 72 20 c_execute: near
5f70: 22 65 6c 62 61 22 3a 20 73 79 6e 74 61 78 20 65 "elba": syntax e
5f80: 72 72 6f 72 0d 0a 3c 2f 76 65 72 62 61 74 69 6d rror..</verbatim
5f90: 3e 0d 0a 54 68 69 73 20 66 69 72 73 74 20 6e 61 >..This first na
5fa0: 69 76 65 20 61 74 74 65 6d 70 74 20 77 69 6c 6c ive attempt will
5fb0: 20 66 61 69 6c 2c 20 61 6e 64 20 3c 62 3e 53 71 fail, and <b>Sq
5fc0: 6c 50 72 6f 63 5f 47 65 74 4c 61 73 74 45 72 72 lProc_GetLastErr
5fd0: 6f 72 3c 2f 62 3e 20 77 69 6c 6c 20 65 78 70 6c or</b> will expl
5fe0: 61 69 6e 20 77 68 79 20 69 74 20 66 61 69 6c 65 ain why it faile
5ff0: 64 2e 20 57 65 27 76 65 20 70 61 73 73 65 64 20 d. We've passed
6000: 61 20 3c 62 3e 27 40 6d 75 6e 69 63 69 70 61 6c a <b>'@municipal
6010: 69 74 79 40 3d 72 69 6f 20 6e 65 6c 6c 27 27 65 ity@=rio nell''e
6020: 6c 62 61 27 3c 2f 62 3e 20 56 61 72 69 61 62 6c lba'</b> Variabl
6030: 65 20 77 69 74 68 20 56 61 6c 75 65 2c 20 74 68 e with Value, th
6040: 61 74 20 77 69 6c 6c 20 6c 65 61 64 20 74 6f 20 at will lead to
6050: 61 20 3c 62 3e 63 6f 6f 6b 65 64 3c 2f 62 3e 20 a <b>cooked</b>
6060: 57 48 45 52 45 20 63 6c 61 75 73 65 20 6c 69 6b WHERE clause lik
6070: 65 20 74 68 69 73 3a 0d 0a 3c 76 65 72 62 61 74 e this:..<verbat
6080: 69 6d 3e 0d 0a 57 48 45 52 45 20 28 55 70 70 65 im>..WHERE (Uppe
6090: 72 28 6e 61 6d 65 29 20 3d 20 55 70 70 65 72 28 r(name) = Upper(
60a0: 27 72 69 6f 20 6e 65 6c 6c 27 65 6c 62 61 27 29 'rio nell'elba')
60b0: 20 4f 52 20 55 70 70 65 72 28 70 72 6f 76 69 6e OR Upper(provin
60c0: 63 65 29 20 3d 20 55 70 70 65 72 28 27 4e 55 4c ce) = Upper('NUL
60d0: 4c 27 29 20 4f 52 20 55 70 70 65 72 28 72 65 67 L') OR Upper(reg
60e0: 69 6f 6e 29 20 3d 20 55 70 70 65 72 28 27 4e 55 ion) = Upper('NU
60f0: 4c 4c 27 29 29 0d 0a 3c 2f 76 65 72 62 61 74 69 LL'))..</verbati
6100: 6d 3e 0d 0a 49 74 27 73 20 72 61 74 68 65 72 20 m>..It's rather
6110: 6f 62 76 69 6f 75 73 20 74 68 61 74 20 3c 62 3e obvious that <b>
6120: 27 72 69 6f 20 6e 65 6c 6c 27 65 6c 62 61 27 3c 'rio nell'elba'<
6130: 2f 62 3e 20 69 73 20 61 6e 20 69 6c 6c 65 67 61 /b> is an illega
6140: 6c 20 53 51 4c 20 74 65 78 74 20 73 74 72 69 6e l SQL text strin
6150: 67 3b 20 74 68 65 20 63 6f 72 72 65 63 74 20 73 g; the correct s
6160: 79 6e 74 61 78 20 73 68 6f 75 6c 64 20 62 65 20 yntax should be
6170: 69 6e 73 74 65 61 64 20 3c 62 3e 27 72 69 6f 20 instead <b>'rio
6180: 6e 65 6c 6c 27 27 65 6c 62 61 27 3c 2f 62 3e 2e nell''elba'</b>.
6190: 0d 0a 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 76 65 72 ..<br><br>..<ver
61a0: 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 batim>..SELECT S
61b0: 74 6f 72 65 64 50 72 6f 63 5f 45 78 65 63 75 74 toredProc_Execut
61c0: 65 28 20 27 6d 79 5f 70 72 6f 63 27 29 2c 20 27 e( 'my_proc'), '
61d0: 40 73 72 69 64 40 3d 33 30 30 33 27 2c 20 27 40 @srid@=3003', '@
61e0: 79 65 61 72 40 3d 32 30 31 31 27 2c 20 27 40 6d year@=2011', '@m
61f0: 75 6e 69 63 69 70 61 6c 69 74 79 40 3d 72 69 6f unicipality@=rio
6200: 20 6e 65 6c 6c 27 27 27 27 65 6c 62 61 27 2c 20 nell''''elba',
6210: 27 40 73 68 70 5f 70 61 74 68 40 3d 43 3a 2f 75 '@shp_path@=C:/u
6220: 73 65 72 73 2f 6a 6f 65 2f 73 74 6f 72 65 64 5f sers/joe/stored_
6230: 70 72 6f 63 5f 74 65 73 74 2f 72 69 6f 5f 65 6c proc_test/rio_el
6240: 62 61 5f 32 30 31 31 5f 33 30 30 33 27 29 3b 0d ba_2011_3003');.
6250: 0a 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 .-----..1..</ver
6260: 62 61 74 69 6d 3e 0d 0a 52 65 73 6f 6c 76 69 6e batim>..Resolvin
6270: 67 20 73 75 63 68 20 61 6e 20 69 73 73 75 65 20 g such an issue
6280: 69 73 20 72 61 74 68 65 72 20 74 72 69 76 69 61 is rather trivia
6290: 6c 3b 20 77 65 20 6a 75 73 74 20 68 61 76 65 20 l; we just have
62a0: 74 6f 20 75 73 65 20 3c 62 3e 66 6f 75 72 3c 2f to use <b>four</
62b0: 62 3e 20 63 6f 6e 73 65 63 75 74 69 76 65 20 73 b> consecutive s
62c0: 69 6e 67 6c 65 2d 71 75 6f 74 65 73 20 73 6f 20 ingle-quotes so
62d0: 74 6f 20 63 6f 72 72 65 63 74 6c 79 20 65 73 63 to correctly esc
62e0: 61 70 65 20 74 68 65 20 73 74 72 69 6e 67 20 76 ape the string v
62f0: 61 6c 75 65 2e 0d 0a 3c 62 72 3e 3c 62 72 3e 0d alue...<br><br>.
6300: 0a 3c 74 61 62 6c 65 20 77 69 64 74 68 3d 22 31 .<table width="1
6310: 30 30 25 22 3e 3c 74 72 3e 0d 0a 3c 74 64 20 77 00%"><tr>..<td w
6320: 69 64 74 68 3d 22 33 33 25 22 20 61 6c 69 67 6e idth="33%" align
6330: 3d 22 6c 65 66 74 22 3e 3c 2f 74 64 3e 0d 0a 3c ="left"></td>..<
6340: 74 64 20 61 6c 69 67 6e 3d 22 63 65 6e 74 65 72 td align="center
6350: 22 3e 3c 61 20 68 72 65 66 3d 22 68 74 74 70 73 "><a href="https
6360: 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73 2e ://www.gaia-gis.
6370: 69 74 2f 66 6f 73 73 69 6c 2f 6c 69 62 73 70 61 it/fossil/libspa
6380: 74 69 61 6c 69 74 65 2f 77 69 6b 69 3f 6e 61 6d tialite/wiki?nam
6390: 65 3d 34 2e 33 2e 30 2b 64 6f 63 22 3e 62 61 63 e=4.3.0+doc">bac
63a0: 6b 20 74 6f 20 69 6e 64 65 78 3c 2f 61 3e 3c 2f k to index</a></
63b0: 74 64 3e 0d 0a 3c 74 64 20 77 69 64 74 68 3d 22 td>..<td width="
63c0: 33 33 25 22 20 61 6c 69 67 6e 3d 22 72 69 67 68 33%" align="righ
63d0: 74 22 3e 3c 2f 74 64 3e 0d 0a 3c 2f 74 72 3e 3c t"></td>..</tr><
63e0: 2f 74 61 62 6c 65 3e 0a 5a 20 32 62 66 34 63 37 /table>.Z 2bf4c7
63f0: 65 66 38 61 62 39 34 34 34 32 34 38 39 34 61 37 ef8ab944424894a7
6400: 65 30 34 34 66 64 65 34 33 34 0a e044fde434.