Wiki page
[tutorial] by
sandro
2018-07-29 14:18:15.
0000: 44 20 32 30 31 38 2d 30 37 2d 32 39 54 31 34 3a D 2018-07-29T14:
0010: 31 38 3a 31 35 2e 33 31 33 0a 4c 20 74 75 74 6f 18:15.313.L tuto
0020: 72 69 61 6c 0a 50 20 33 39 62 34 64 37 39 66 61 rial.P 39b4d79fa
0030: 38 35 39 31 63 30 34 39 63 64 61 36 39 36 33 33 8591c049cda69633
0040: 30 30 61 31 64 35 30 37 66 65 33 64 39 39 62 0a 00a1d507fe3d99b.
0050: 55 20 73 61 6e 64 72 6f 0a 57 20 32 35 33 34 31 U sandro.W 25341
0060: 0a 42 61 63 6b 20 74 6f 20 3c 62 3e 56 69 72 74 .Back to <b>Virt
0070: 75 61 6c 50 47 3c 2f 62 3e 20 3c 61 20 68 72 65 ualPG</b> <a hre
0080: 66 3d 22 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67 f="https://www.g
0090: 61 69 61 2d 67 69 73 2e 69 74 2f 66 6f 73 73 69 aia-gis.it/fossi
00a0: 6c 2f 76 69 72 74 75 61 6c 70 67 2f 69 6e 64 65 l/virtualpg/inde
00b0: 78 22 3e 68 6f 6d 65 20 70 61 67 65 3c 2f 61 3e x">home page</a>
00c0: 0d 0a 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 32 3e ..<br><br>..<h2>
00d0: 55 70 64 61 74 65 64 20 64 6f 63 75 6d 65 6e 74 Updated document
00e0: 61 74 69 6f 6e 20 73 75 70 70 6f 72 74 69 6e 67 ation supporting
00f0: 20 56 69 72 74 75 61 6c 50 47 20 76 32 3c 2f 68 VirtualPG v2</h
0100: 32 3e 0d 0a 3c 74 61 62 6c 65 20 63 65 6c 6c 73 2>..<table cells
0110: 70 61 63 69 6e 67 3d 22 36 22 20 63 65 6c 6c 70 pacing="6" cellp
0120: 61 64 64 69 6e 67 3d 22 36 22 20 62 67 63 6f 6c adding="6" bgcol
0130: 6f 72 3d 22 23 66 66 64 30 38 30 22 3e 3c 74 72 or="#ffd080"><tr
0140: 3e 3c 74 64 3e 0d 0a 3c 68 33 3e 57 61 72 6e 69 ><td>..<h3>Warni
0150: 6e 67 3c 2f 68 33 3e 0d 0a 54 68 65 20 66 6f 6c ng</h3>..The fol
0160: 6c 6f 77 69 6e 67 20 69 6e 66 6f 72 6d 61 74 69 lowing informati
0170: 6f 6e 73 20 63 6f 72 72 65 73 70 6f 6e 64 20 74 ons correspond t
0180: 6f 20 74 68 65 20 6d 6f 73 74 20 72 65 63 65 6e o the most recen
0190: 74 20 3c 62 3e 56 65 72 73 69 6f 6e 20 32 3c 2f t <b>Version 2</
01a0: 62 3e 20 6f 66 20 56 69 72 74 75 61 6c 50 47 2c b> of VirtualPG,
01b0: 20 61 6e 64 20 63 6f 75 6c 64 20 6e 6f 74 20 61 and could not a
01c0: 6c 77 61 79 73 20 61 64 65 71 75 61 74 65 6c 79 lways adequately
01d0: 20 63 6f 76 65 72 20 74 68 65 20 70 72 65 76 69 cover the previ
01e0: 6f 75 73 20 76 65 72 73 69 6f 6e 73 2c 20 74 68 ous versions, th
01f0: 61 74 20 61 72 65 20 6e 6f 77 20 64 65 63 6c 61 at are now decla
0200: 72 65 64 20 6f 62 73 6f 6c 65 74 65 2e 3c 62 72 red obsolete.<br
0210: 3e 0d 0a 49 66 20 79 6f 75 20 61 72 65 20 73 74 >..If you are st
0220: 69 6c 6c 20 75 73 69 6e 67 20 61 6e 79 20 70 72 ill using any pr
0230: 65 76 69 6f 75 73 20 76 65 72 73 69 6f 6e 20 79 evious version y
0240: 6f 75 20 61 72 65 20 77 61 72 6d 6c 79 20 72 65 ou are warmly re
0250: 63 63 6f 6d 6d 65 6e 64 65 64 20 74 6f 20 71 75 ccommended to qu
0260: 69 63 6b 6c 79 20 75 70 64 61 74 65 20 79 6f 75 ickly update you
0270: 72 20 73 6f 66 74 77 61 72 65 2e 0d 0a 3c 2f 74 r software...</t
0280: 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d d></tr></table>.
0290: 0a 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 74 61 62 6c .<br><br>..<tabl
02a0: 65 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 36 e cellspacing="6
02b0: 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 36 " cellpadding="6
02c0: 22 20 62 67 63 6f 6c 6f 72 3d 22 23 64 30 66 66 " bgcolor="#d0ff
02d0: 38 30 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 3c 68 80"><tr><td>..<h
02e0: 33 3e 53 68 6f 72 74 20 73 75 6d 6d 61 72 79 20 3>Short summary
02f0: 6f 66 20 64 69 66 66 65 72 65 6e 63 65 73 20 62 of differences b
0300: 65 74 77 65 65 6e 20 65 61 72 6c 69 65 72 20 76 etween earlier v
0310: 65 72 73 69 6f 6e 73 20 61 6e 64 20 76 32 3c 2f ersions and v2</
0320: 68 33 3e 0d 0a 3c 6f 6c 3e 0d 0a 3c 6c 69 3e 6e h3>..<ol>..<li>n
0330: 6f 77 20 56 69 72 74 75 61 6c 50 47 20 69 73 20 ow VirtualPG is
0340: 61 76 61 69 6c 61 62 6c 65 20 61 73 20 20 62 6f available as bo
0350: 74 68 20 61 20 73 74 61 6e 64 61 72 64 20 43 2f th a standard C/
0360: 43 2b 2b 20 6c 69 62 72 61 72 79 20 28 3c 62 3e C++ library (<b>
0370: 6c 69 62 76 69 72 74 75 61 6c 70 67 3c 2f 62 3e libvirtualpg</b>
0380: 29 20 61 6e 64 20 61 20 64 79 6e 61 6d 69 63 20 ) and a dynamic
0390: 65 78 74 65 6e 73 69 6f 6e 20 6d 6f 64 75 6c 65 extension module
03a0: 20 74 6f 20 53 51 4c 69 74 65 20 28 3c 62 3e 6d to SQLite (<b>m
03b0: 6f 64 5f 76 69 72 74 75 61 6c 70 67 3c 2f 62 3e od_virtualpg</b>
03c0: 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 6e 6f 77 ).</li>..<li>now
03d0: 20 74 68 65 20 75 73 65 72 20 63 61 6e 20 66 72 the user can fr
03e0: 65 65 6c 79 20 63 68 6f 6f 73 65 20 68 69 73 2f eely choose his/
03f0: 68 65 72 20 70 72 65 66 65 72 72 65 64 20 66 6f her preferred fo
0400: 72 6d 61 74 20 66 6f 72 20 44 41 54 45 20 2f 20 rmat for DATE /
0410: 54 49 4d 45 20 2f 20 54 49 4d 45 53 54 41 4d 50 TIME / TIMESTAMP
0420: 20 76 61 6c 75 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c values.</li>..<
0430: 6c 69 3e 54 72 61 6e 73 61 63 74 69 6f 6e 73 20 li>Transactions
0440: 28 42 45 47 49 4e 20 2f 20 43 4f 4d 4d 49 54 20 (BEGIN / COMMIT
0450: 2f 20 52 4f 4c 4c 42 41 43 4b 29 20 61 72 65 20 / ROLLBACK) are
0460: 6e 6f 77 20 66 75 6c 6c 79 20 68 6f 6e 6f 75 72 now fully honour
0470: 65 64 20 61 6c 73 6f 20 6f 6e 20 74 68 65 20 50 ed also on the P
0480: 6f 73 74 67 72 65 53 51 4c 20 73 69 64 65 2e 3c ostgreSQL side.<
0490: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 57 72 69 74 65 20 /li>..<li>Write
04a0: 6f 70 65 72 61 74 69 6f 6e 73 20 28 49 4e 53 45 operations (INSE
04b0: 52 20 2f 20 55 50 44 41 54 45 20 2f 20 44 45 4c R / UPDATE / DEL
04c0: 45 54 45 29 20 61 72 65 20 6e 6f 77 20 61 6c 6c ETE) are now all
04d0: 6f 77 65 64 20 6f 6e 6c 79 20 69 66 20 74 68 65 owed only if the
04e0: 20 50 6f 73 74 67 72 65 53 51 4c 20 75 73 65 72 PostgreSQL user
04f0: 20 68 61 73 20 74 68 65 20 63 6f 72 72 65 73 70 has the corresp
0500: 6f 6e 64 69 6e 67 20 47 52 41 4e 54 20 70 65 72 onding GRANT per
0510: 6d 69 73 73 69 6f 6e 73 2e 3c 2f 6c 69 3e 0d 0a missions.</li>..
0520: 3c 6c 69 3e 57 72 69 74 65 20 6f 70 65 72 61 74 <li>Write operat
0530: 69 6f 6e 73 20 63 61 6e 20 62 65 20 65 6e 61 62 ions can be enab
0540: 6c 65 64 20 6f 6e 6c 79 20 66 6f 72 20 50 6f 73 led only for Pos
0550: 74 67 72 65 53 51 4c 20 54 61 62 6c 65 73 20 65 tgreSQL Tables e
0560: 78 70 6c 69 63 69 74 6c 79 20 64 65 63 6c 61 72 xplicitly declar
0570: 69 6e 67 20 61 20 50 52 49 4d 41 52 59 20 4b 45 ing a PRIMARY KE
0580: 59 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 6f 6c 3e 0d 0a Y.</li>..</ol>..
0590: 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c </td></tr></tabl
05a0: 65 3e 0d 0a 3c 68 32 3e 61 62 6f 75 74 20 56 69 e>..<h2>about Vi
05b0: 72 74 75 61 6c 50 47 3c 2f 68 32 3e 0d 0a 3c 62 rtualPG</h2>..<b
05c0: 3e 56 69 72 74 75 61 6c 50 47 20 32 3c 2f 62 3e >VirtualPG 2</b>
05d0: 20 69 73 20 61 76 61 69 6c 61 62 6c 65 20 62 6f is available bo
05e0: 74 68 20 61 73 20 61 20 3c 69 3e 63 6c 61 73 73 th as a <i>class
05f0: 69 63 20 3c 62 3e 43 2f 43 2b 2b 3c 2f 62 3e 20 ic <b>C/C++</b>
0600: 6c 69 62 72 61 72 79 3c 2f 69 3e 20 61 6e 64 20 library</i> and
0610: 61 73 20 61 20 3c 69 3e 6c 6f 61 64 61 62 6c 65 as a <i>loadable
0620: 20 64 79 6e 61 6d 69 63 20 65 78 74 65 6e 73 69 dynamic extensi
0630: 6f 6e 20 6d 6f 64 75 6c 65 3c 2f 69 3e 20 66 6f on module</i> fo
0640: 72 20 62 6f 74 68 20 3c 62 3e 53 51 4c 69 74 65 r both <b>SQLite
0650: 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e 53 70 61 74 </b> and <b>Spat
0660: 69 61 4c 69 74 65 3c 2f 62 3e 2e 3c 62 72 3e 0d iaLite</b>.<br>.
0670: 0a 54 68 65 20 69 6e 74 65 6e 64 65 64 20 73 63 .The intended sc
0680: 6f 70 65 20 6f 66 20 56 69 72 74 75 61 6c 50 47 ope of VirtualPG
0690: 20 69 73 20 73 75 70 70 6f 72 74 69 6e 67 20 64 is supporting d
06a0: 69 72 65 63 74 20 64 61 74 61 20 65 78 63 68 61 irect data excha
06b0: 6e 67 65 20 66 6f 72 6d 2f 74 6f 20 3c 62 3e 50 nge form/to <b>P
06c0: 6f 73 74 67 72 65 53 51 4c 3c 2f 62 3e 20 2f 20 ostgreSQL</b> /
06d0: 3c 62 3e 50 6f 73 74 47 49 53 3c 2f 62 3e 20 74 <b>PostGIS</b> t
06e0: 61 72 67 65 74 73 20 61 6e 64 20 3c 62 3e 53 51 argets and <b>SQ
06f0: 4c 69 74 65 3c 2f 62 3e 20 73 69 6d 70 6c 79 20 Lite</b> simply
0700: 75 73 69 6e 67 20 62 61 73 69 63 2c 20 70 6c 61 using basic, pla
0710: 69 6e 20 3c 69 3e 53 51 4c 20 73 74 61 74 65 6d in <i>SQL statem
0720: 65 6e 74 73 3c 2f 69 3e 2e 3c 62 72 3e 3c 62 72 ents</i>.<br><br
0730: 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 56 69 72 >..<hr>..<h3>Vir
0740: 74 75 61 6c 50 47 20 61 73 20 61 20 73 74 61 6e tualPG as a stan
0750: 64 61 72 64 20 43 2f 43 2b 2b 20 6c 69 62 72 61 dard C/C++ libra
0760: 72 79 3c 2f 68 33 3e 0d 0a 54 68 65 72 65 20 69 ry</h3>..There i
0770: 73 20 76 65 72 79 20 6c 69 74 74 6c 65 20 74 6f s very little to
0780: 20 73 61 79 20 61 62 6f 75 74 20 56 69 72 74 75 say about Virtu
0790: 61 6c 50 47 20 61 73 20 61 20 6c 69 62 72 61 72 alPG as a librar
07a0: 79 2c 20 62 65 63 61 75 73 65 20 69 74 20 69 6d y, because it im
07b0: 70 6c 65 6d 65 6e 74 73 20 6a 75 73 74 20 74 77 plements just tw
07c0: 6f 20 43 20 66 75 6e 63 74 69 6f 6e 73 3a 0d 0a o C functions:..
07d0: 3c 6f 6c 3e 0d 0a 3c 6c 69 3e 3c 62 3e 56 49 52 <ol>..<li><b>VIR
07e0: 54 55 41 4c 50 47 5f 44 45 43 4c 41 52 45 20 63 TUALPG_DECLARE c
07f0: 6f 6e 73 74 20 63 68 61 72 20 2a 76 69 72 74 75 onst char *virtu
0800: 61 6c 70 67 5f 76 65 72 73 69 6f 6e 20 28 76 6f alpg_version (vo
0810: 69 64 29 3b 3c 2f 62 3e 0d 0a 3c 75 6c 3e 0d 0a id);</b>..<ul>..
0820: 3c 6c 69 3e 74 68 69 73 20 66 69 72 73 74 20 41 <li>this first A
0830: 50 49 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 74 PI will return t
0840: 68 65 20 63 75 72 72 65 6e 74 20 76 65 72 73 69 he current versi
0850: 6f 6e 20 6f 66 20 74 68 65 20 6c 69 62 72 61 72 on of the librar
0860: 79 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 2f y.</li>..</ul></
0870: 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 56 49 52 54 li>..<li><b>VIRT
0880: 55 41 4c 50 47 5f 44 45 43 4c 41 52 45 20 69 6e UALPG_DECLARE in
0890: 74 20 76 69 72 74 75 61 6c 70 67 5f 65 78 74 65 t virtualpg_exte
08a0: 6e 73 69 6f 6e 5f 69 6e 69 74 20 28 73 71 6c 69 nsion_init (sqli
08b0: 74 65 33 20 2a 64 62 5f 68 61 6e 64 6c 65 29 3b te3 *db_handle);
08c0: 3c 2f 62 3e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e </b>..<ul>..<li>
08d0: 74 68 69 73 20 73 65 63 6f 6e 64 20 41 50 49 20 this second API
08e0: 69 73 20 69 6e 74 65 6e 65 64 20 74 6f 20 69 6e is intened to in
08f0: 69 74 69 61 6c 69 7a 65 20 74 68 65 20 56 69 72 itialize the Vir
0900: 74 75 61 6c 50 47 20 65 78 74 65 6e 73 69 6f 6e tualPG extension
0910: 20 6d 6f 64 75 6c 65 3a 0d 0a 3c 75 6c 3e 0d 0a module:..<ul>..
0920: 3c 6c 69 3e 3c 62 3e 64 62 5f 68 61 6e 64 6c 65 <li><b>db_handle
0930: 3c 2f 62 3e 20 6d 75 73 74 20 62 65 20 61 20 76 </b> must be a v
0940: 61 6c 69 64 20 68 61 6e 64 6c 65 20 74 6f 20 73 alid handle to s
0950: 6f 6d 65 20 61 6c 72 65 61 64 79 20 65 73 74 61 ome already esta
0960: 62 6c 69 73 68 65 64 20 53 51 4c 69 74 65 20 63 blished SQLite c
0970: 6f 6e 6e 65 63 74 69 6f 6e 2e 3c 2f 6c 69 3e 0d onnection.</li>.
0980: 0a 3c 6c 69 3e 74 68 65 20 72 65 74 75 72 6e 20 .<li>the return
0990: 76 61 6c 75 65 20 77 69 6c 6c 20 62 65 20 3c 62 value will be <b
09a0: 3e 53 51 4c 49 54 45 5f 4f 4b 3c 2f 62 3e 20 69 >SQLITE_OK</b> i
09b0: 66 20 74 68 65 20 65 78 74 65 6e 73 69 6f 6e 20 f the extension
09c0: 6d 6f 64 75 6c 65 20 68 61 73 20 62 65 65 6e 20 module has been
09d0: 73 75 63 63 65 73 66 75 6c 6c 79 20 20 69 6e 69 succesfully ini
09e0: 74 69 61 6c 69 7a 65 64 2e 3c 2f 6c 69 3e 0d 0a tialized.</li>..
09f0: 3c 2f 75 6c 3e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c </ul></li>..</ul
0a00: 3e 3c 2f 6c 69 3e 0d 0a 3c 2f 6f 6c 3e 0d 0a 3c ></li>..</ol>..<
0a10: 62 3e 4e 6f 74 65 73 3c 2f 62 3e 3a 3c 62 72 3e b>Notes</b>:<br>
0a20: 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 74 68 65 20 ..<ul>..<li>the
0a30: 3c 62 3e 56 69 72 74 75 61 6c 50 47 3c 2f 62 3e <b>VirtualPG</b>
0a40: 20 65 78 74 65 6e 73 69 6f 6e 20 64 6f 65 73 20 extension does
0a50: 6e 6f 74 20 6e 65 63 65 73 73 61 72 69 6c 79 20 not necessarily
0a60: 72 65 71 75 69 72 65 20 74 6f 20 62 65 20 73 75 require to be su
0a70: 70 70 6f 72 74 65 64 20 62 79 20 74 68 65 20 3c pported by the <
0a80: 62 3e 53 70 61 74 69 61 4c 69 74 65 3c 2f 62 3e b>SpatiaLite</b>
0a90: 20 65 78 74 65 6e 73 69 6f 6e 3b 20 74 68 65 79 extension; they
0aa0: 20 61 72 65 20 69 6e 64 65 70 65 6e 64 65 6e 74 are independent
0ab0: 20 74 68 65 20 6f 6e 65 20 66 72 6f 6d 20 74 68 the one from th
0ac0: 65 20 6f 74 68 65 72 2e 3c 2f 6c 69 3e 0d 0a 3c e other.</li>..<
0ad0: 6c 69 3e 74 68 65 20 72 65 6c 61 74 69 76 65 20 li>the relative
0ae0: 6f 72 64 65 72 20 69 6e 20 77 68 69 63 68 20 74 order in which t
0af0: 68 65 20 74 77 6f 20 65 78 74 65 6e 73 69 6f 6e he two extension
0b00: 73 20 61 72 65 20 65 76 65 6e 74 75 61 6c 6c 79 s are eventually
0b10: 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 69 73 20 initialized is
0b20: 61 62 73 6f 6c 75 74 65 6c 79 20 6e 6f 74 20 72 absolutely not r
0b30: 65 6c 65 76 61 6e 74 2e 3c 2f 6c 69 3e 0d 0a 3c elevant.</li>..<
0b40: 6c 69 3e 68 6f 77 65 76 65 72 2c 20 77 68 65 6e li>however, when
0b50: 20 56 69 72 74 75 61 6c 50 47 20 69 73 20 62 61 VirtualPG is ba
0b60: 63 6b 65 64 20 75 70 20 62 79 20 53 70 61 74 69 cked up by Spati
0b70: 61 4c 69 74 65 2c 20 79 6f 75 27 6c 6c 20 61 6c aLite, you'll al
0b80: 77 61 79 73 20 62 65 20 61 62 6c 65 20 74 6f 20 ways be able to
0b90: 65 6e 71 75 69 72 79 20 69 6e 20 66 75 6c 6c 20 enquiry in full
0ba0: 64 65 74 61 69 6c 20 61 6e 79 20 65 72 72 6f 72 detail any error
0bb0: 20 6d 65 73 73 61 67 65 20 72 61 69 73 65 64 20 message raised
0bc0: 62 79 20 50 6f 73 74 67 72 65 53 51 4c 20 62 79 by PostgreSQL by
0bd0: 20 63 61 6c 6c 69 6e 67 20 74 68 65 20 53 51 4c calling the SQL
0be0: 20 66 75 6e 63 74 69 6f 6e 20 3c 62 3e 50 6f 73 function <b>Pos
0bf0: 74 67 72 65 53 71 6c 5f 47 65 74 4c 61 73 74 4d tgreSql_GetLastM
0c00: 65 73 73 61 67 65 28 29 3c 2f 62 3e 2e 3c 62 72 essage()</b>.<br
0c10: 3e 0d 0a 74 68 69 73 20 69 73 20 61 20 72 65 61 >..this is a rea
0c20: 6c 6c 79 20 75 73 65 66 75 6c 20 64 69 61 67 6e lly useful diagn
0c30: 6f 73 74 69 63 20 66 75 6e 63 74 69 6f 6e 2c 20 ostic function,
0c40: 61 6e 64 20 77 69 6c 6c 20 67 72 65 61 74 6c 79 and will greatly
0c50: 20 69 6d 70 72 6f 76 65 20 74 68 65 20 75 73 61 improve the usa
0c60: 62 69 6c 69 74 79 20 6f 66 20 56 69 72 74 75 61 bility of Virtua
0c70: 6c 50 47 2c 20 61 6c 6c 6f 77 69 6e 67 20 66 6f lPG, allowing fo
0c80: 72 20 61 20 73 69 6d 70 6c 69 66 69 65 64 20 61 r a simplified a
0c90: 6e 64 20 65 61 73 69 65 72 20 64 65 62 75 67 67 nd easier debugg
0ca0: 69 6e 67 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 77 ing.</li>..<li>w
0cb0: 68 65 6e 20 53 70 61 74 69 61 4c 69 74 65 27 73 hen SpatiaLite's
0cc0: 20 73 75 70 70 6f 72 74 20 69 73 20 75 6e 61 76 support is unav
0cd0: 61 69 6c 61 62 6c 65 2c 20 56 69 72 74 75 61 6c ailable, Virtual
0ce0: 50 47 20 77 69 6c 6c 20 73 69 6d 70 6c 79 20 61 PG will simply a
0cf0: 74 74 65 6d 70 74 20 74 6f 20 6f 75 74 70 75 74 ttempt to output
0d00: 20 74 68 65 20 65 72 72 6f 72 20 6d 65 73 73 61 the error messa
0d10: 67 65 20 63 6f 6d 69 6e 67 20 66 72 6f 6d 20 50 ge coming from P
0d20: 6f 73 74 67 72 65 53 51 4c 20 6f 6e 20 74 68 65 ostgreSQL on the
0d30: 20 73 74 61 6e 64 61 72 64 20 65 72 72 6f 72 20 standard error
0d40: 28 69 66 20 61 76 61 69 6c 61 62 6c 65 29 2e 3c (if available).<
0d50: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 4e 6f 74 /li>..<li><b>Not
0d60: 65 3c 2f 62 3e 3a 20 74 68 65 20 64 69 61 67 6e e</b>: the diagn
0d70: 6f 73 74 69 63 20 53 51 4c 20 66 75 6e 63 74 69 ostic SQL functi
0d80: 6f 6e 20 3c 62 3e 50 6f 73 74 67 72 65 53 51 4c on <b>PostgreSQL
0d90: 5f 47 65 74 4c 61 73 74 45 72 72 6f 72 28 29 20 _GetLastError()
0da0: 3c 2f 62 3e 72 65 71 75 69 72 65 73 20 75 73 69 </b>requires usi
0db0: 6e 67 20 53 70 61 74 69 61 4c 69 74 65 20 76 65 ng SpatiaLite ve
0dc0: 72 73 69 6f 6e 20 35 2e 30 2e 30 20 6f 72 20 6c rsion 5.0.0 or l
0dd0: 61 74 65 72 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c ater.</li>..</ul
0de0: 3e 3c 62 72 3e 0d 0a 3c 62 3e 61 20 76 65 72 79 ><br>..<b>a very
0df0: 20 73 6b 65 6c 65 74 61 6c 20 43 20 73 6f 75 72 skeletal C sour
0e00: 63 65 20 73 61 6d 70 6c 65 3c 2f 62 3e 0d 0a 3c ce sample</b>..<
0e10: 76 65 72 62 61 74 69 6d 3e 0d 0a 23 69 6e 63 6c verbatim>..#incl
0e20: 75 64 65 20 3c 73 74 64 6c 69 62 2e 68 3e 0d 0a ude <stdlib.h>..
0e30: 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e #include <stdio.
0e40: 68 3e 0d 0a 23 69 6e 63 6c 75 64 65 20 3c 73 71 h>..#include <sq
0e50: 6c 69 74 65 33 2e 68 3e 0d 0a 23 69 6e 63 6c 75 lite3.h>..#inclu
0e60: 64 65 20 3c 76 69 72 74 75 61 6c 70 67 2e 68 3e de <virtualpg.h>
0e70: 0d 0a 0d 0a 69 6e 74 0d 0a 6d 61 69 6e 20 28 69 ....int..main (i
0e80: 6e 74 20 61 72 67 63 2c 20 63 68 61 72 20 2a 61 nt argc, char *a
0e90: 72 67 76 5b 5d 29 0d 0a 7b 0d 0a 20 20 20 20 63 rgv[])..{.. c
0ea0: 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 20 onst char *path
0eb0: 3d 20 2e 2e 2e 20 73 6f 6d 65 20 76 61 6c 75 65 = ... some value
0ec0: 20 2e 2e 2e 2e 0d 0a 20 20 20 20 73 71 6c 69 74 ...... sqlit
0ed0: 65 33 20 2a 68 61 6e 64 6c 65 3b 0d 0a 20 20 20 e3 *handle;..
0ee0: 20 76 69 72 74 75 61 6c 50 51 20 76 69 72 74 75 virtualPQ virtu
0ef0: 61 6c 5f 61 70 69 3b 0d 0a 20 20 20 20 69 6e 74 al_api;.. int
0f00: 20 72 65 74 3b 0d 0a 0d 0a 2f 2a 20 6f 70 65 6e ret;..../* open
0f10: 69 6e 67 20 74 68 65 20 53 51 4c 69 74 65 20 63 ing the SQLite c
0f20: 6f 6e 6e 65 63 74 69 6f 6e 20 2a 2f 0d 0a 20 20 onnection */..
0f30: 20 20 72 65 74 20 3d 20 73 71 6c 69 74 65 33 5f ret = sqlite3_
0f40: 6f 70 65 6e 5f 76 32 20 28 70 61 74 68 2c 20 26 open_v2 (path, &
0f50: 68 61 6e 64 6c 65 2c 20 53 51 4c 49 54 45 5f 4f handle, SQLITE_O
0f60: 50 45 4e 5f 52 45 41 44 57 52 49 54 45 2c 20 4e PEN_READWRITE, N
0f70: 55 4c 4c 29 3b 0d 0a 20 20 20 20 69 66 20 28 72 ULL);.. if (r
0f80: 65 74 20 21 3d 20 53 51 4c 49 54 45 5f 4f 4b 29 et != SQLITE_OK)
0f90: 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 20 20 20 20 .. {..
0fa0: 20 2e 2e 2e 20 65 72 72 6f 72 20 68 61 6e 64 6c ... error handl
0fb0: 69 6e 67 20 2e 2e 2e 0d 0a 20 20 20 20 7d 0d 0a ing ..... }..
0fc0: 0d 0a 2f 2a 20 69 6e 69 74 69 61 6c 69 7a 69 6e ../* initializin
0fd0: 67 20 74 68 65 20 50 51 20 76 69 72 74 75 61 6c g the PQ virtual
0fe0: 20 41 50 49 20 2a 2f 0d 0a 20 20 20 20 76 69 72 API */.. vir
0ff0: 74 75 61 6c 5f 61 70 69 2e 50 51 63 6c 65 61 72 tual_api.PQclear
1000: 20 3d 20 2e 2e 2e 0d 0a 20 20 20 20 76 69 72 74 = ..... virt
1010: 75 61 6c 5f 61 70 69 2e 50 51 63 6f 6e 6e 65 63 ual_api.PQconnec
1020: 74 64 62 20 3d 20 2e 2e 2e 0d 0a 20 20 20 20 2e tdb = ..... .
1030: 2e 2e 0d 0a 0d 0a 2f 2a 20 69 6e 69 74 69 61 6c ....../* initial
1040: 69 7a 69 6e 67 20 56 69 72 74 75 61 6c 50 47 20 izing VirtualPG
1050: 2a 2f 0d 0a 20 20 20 20 72 65 74 20 3d 20 76 69 */.. ret = vi
1060: 72 74 75 61 6c 70 67 5f 65 78 74 65 6e 73 69 6f rtualpg_extensio
1070: 6e 5f 69 6e 69 74 20 28 68 61 6e 64 6c 65 2c 20 n_init (handle,
1080: 26 76 69 72 74 75 61 6c 5f 61 70 69 29 3b 0d 0a &virtual_api);..
1090: 20 20 20 20 69 66 20 28 72 65 74 20 21 3d 20 53 if (ret != S
10a0: 51 4c 49 54 45 5f 4f 4b 29 0d 0a 20 20 20 20 7b QLITE_OK).. {
10b0: 0d 0a 20 20 20 20 20 20 20 20 2e 2e 2e 20 65 72 .. ... er
10c0: 72 6f 72 20 68 61 6e 64 6c 69 6e 67 20 2e 2e 2e ror handling ...
10d0: 0d 0a 20 20 20 20 7d 0d 0a 20 20 20 20 65 6c 73 .. }.. els
10e0: 65 0d 0a 20 20 20 20 20 20 20 20 66 70 72 69 6e e.. fprin
10f0: 74 66 20 28 73 74 64 65 72 72 2c 20 22 6f 6b 2c tf (stderr, "ok,
1100: 20 56 69 72 74 75 61 6c 50 47 20 73 75 63 63 65 VirtualPG succe
1110: 73 66 75 6c 6c 79 20 69 6e 69 74 69 61 6c 69 7a sfully initializ
1120: 65 64 5c 6e 22 29 3b 0d 0a 0d 0a 2f 2a 20 64 69 ed\n");..../* di
1130: 73 63 6f 6e 6e 65 63 74 69 6e 67 20 66 72 6f 6d sconnecting from
1140: 20 53 51 4c 69 74 65 20 61 6e 64 20 65 78 69 74 SQLite and exit
1150: 69 6e 67 20 2a 2f 0d 0a 20 20 20 20 73 71 6c 69 ing */.. sqli
1160: 74 65 33 5f 63 6c 6f 73 65 20 28 68 61 6e 64 6c te3_close (handl
1170: 65 29 3b 0d 0a 20 20 20 20 72 65 74 75 72 6e 20 e);.. return
1180: 30 3b 0d 0a 7d 0d 0a 3c 2f 76 65 72 62 61 74 69 0;..}..</verbati
1190: 6d 3e 0d 0a 3c 68 33 3e 61 62 6f 75 74 20 76 69 m>..<h3>about vi
11a0: 72 74 75 61 6c 50 51 3c 2f 68 33 3e 0d 0a 3c 62 rtualPQ</h3>..<b
11b0: 3e 6c 69 62 76 69 72 74 75 61 6c 70 67 3c 2f 62 >libvirtualpg</b
11c0: 3e 20 64 65 70 65 6e 64 73 20 6f 6e 20 74 68 65 > depends on the
11d0: 20 50 6f 73 74 67 72 65 53 51 4c 20 63 6c 69 65 PostgreSQL clie
11e0: 6e 74 20 6c 69 62 72 61 72 79 20 28 3c 62 3e 6c nt library (<b>l
11f0: 69 62 70 71 3c 2f 62 3e 29 20 62 75 74 20 79 6f ibpq</b>) but yo
1200: 75 20 63 61 6e 20 66 72 65 65 6c 79 20 63 68 6f u can freely cho
1210: 6f 73 65 20 62 65 74 77 65 65 6e 20 74 77 6f 20 ose between two
1220: 61 6c 74 65 72 6e 61 74 69 76 65 20 6d 65 63 68 alternative mech
1230: 61 6e 69 73 6d 73 20 66 6f 72 20 6c 69 6e 6b 69 anisms for linki
1240: 6e 67 20 3c 62 3e 6c 69 62 70 71 3c 2f 62 3e 3a ng <b>libpq</b>:
1250: 0d 0a 3c 6f 6c 3e 0d 0a 3c 6c 69 3e 3c 62 3e 3c ..<ol>..<li><b><
1260: 69 3e 68 61 72 64 2d 6c 69 6e 6b 69 6e 67 3c 2f i>hard-linking</
1270: 69 3e 3c 2f 62 3e 20 28 61 6b 61 20 3c 62 3e 3c i></b> (aka <b><
1280: 69 3e 65 61 72 6c 79 2d 62 69 6e 64 69 6e 67 3c i>early-binding<
1290: 2f 69 3e 3c 2f 62 3e 29 3a 20 74 68 69 73 20 69 /i></b>): this i
12a0: 73 20 74 68 65 20 6d 6f 73 74 20 66 61 6d 69 6c s the most famil
12b0: 69 61 72 20 6f 6e 65 2e 3c 62 72 3e 0d 0a 79 6f iar one.<br>..yo
12c0: 75 20 6a 75 73 74 20 68 61 76 65 20 74 6f 20 64 u just have to d
12d0: 69 72 65 63 74 6c 79 20 6c 69 6e 6b 20 3c 62 3e irectly link <b>
12e0: 2d 6c 70 71 3c 2f 62 3e 20 74 6f 20 74 68 65 20 -lpq</b> to the
12f0: 61 70 70 6c 69 63 61 74 69 6f 6e 20 63 61 6c 6c application call
1300: 69 6e 67 20 3c 62 3e 6c 69 62 76 69 72 74 75 61 ing <b>libvirtua
1310: 6c 70 67 3c 2f 62 3e 3b 20 74 68 65 6e 20 79 6f lpg</b>; then yo
1320: 75 72 20 63 6f 64 65 2c 20 77 68 65 6e 20 63 61 ur code, when ca
1330: 6c 6c 69 6e 67 20 3c 62 3e 76 69 72 74 75 61 6c lling <b>virtual
1340: 70 67 5f 65 78 74 65 6e 73 69 6f 6e 5f 69 6e 69 pg_extension_ini
1350: 74 28 29 3c 2f 62 3e 2c 20 77 69 6c 6c 20 64 69 t()</b>, will di
1360: 72 65 63 74 6c 79 20 70 61 73 73 20 61 6c 6c 20 rectly pass all
1370: 50 51 20 41 50 49 20 70 6f 69 6e 74 65 72 73 20 PQ API pointers
1380: 74 6f 20 74 68 65 20 65 78 74 65 6e 73 69 6f 6e to the extension
1390: 20 6d 6f 64 75 6c 65 2e 3c 62 72 3e 0d 0a 54 68 module.<br>..Th
13a0: 69 73 20 77 61 79 20 79 6f 75 72 20 61 70 70 6c is way your appl
13b0: 69 63 61 74 69 6f 6e 20 77 69 6c 6c 20 66 75 6c ication will ful
13c0: 6c 79 20 64 65 70 65 6e 64 20 66 72 6f 6d 20 74 ly depend from t
13d0: 68 65 20 64 79 6e 61 6d 69 63 20 6c 69 62 72 61 he dynamic libra
13e0: 72 79 20 3c 62 3e 6c 69 62 70 71 3c 2f 62 3e 3b ry <b>libpq</b>;
13f0: 20 69 66 20 74 68 69 73 20 73 68 6f 75 6c 64 20 if this should
1400: 65 76 65 72 20 66 61 69 6c 20 74 6f 20 62 65 20 ever fail to be
1410: 6c 6f 61 64 65 64 20 66 6f 72 20 61 6e 79 20 72 loaded for any r
1420: 65 61 73 6f 6e 20 79 6f 75 72 20 61 70 70 6c 69 eason your appli
1430: 63 61 74 69 6f 6e 20 77 69 6c 6c 20 62 65 20 63 cation will be c
1440: 6f 6d 70 6c 65 74 65 6c 79 20 75 6e 61 62 6c 65 ompletely unable
1450: 20 74 6f 20 73 74 61 72 74 2e 3c 2f 6c 69 3e 0d to start.</li>.
1460: 0a 3c 6c 69 3e 3c 62 3e 3c 69 3e 73 6f 66 74 2d .<li><b><i>soft-
1470: 6c 69 6e 6b 69 6e 67 3c 2f 69 3e 3c 2f 62 3e 20 linking</i></b>
1480: 28 61 6b 61 20 3c 62 3e 3c 69 3e 6c 61 74 65 2d (aka <b><i>late-
1490: 62 69 6e 64 69 6e 67 3c 2f 69 3e 3c 2f 62 3e 29 binding</i></b>)
14a0: 3a 20 79 6f 75 72 20 61 70 70 6c 69 63 61 74 69 : your applicati
14b0: 6f 6e 20 77 69 6c 6c 20 61 6c 77 61 79 73 20 73 on will always s
14c0: 74 61 72 74 20 77 69 74 68 6f 75 74 20 6c 6f 61 tart without loa
14d0: 64 69 6e 67 20 3c 62 3e 6c 69 62 70 71 3c 2f 62 ding <b>libpq</b
14e0: 3e 3b 20 74 68 69 73 20 64 79 6e 61 6d 69 63 20 >; this dynamic
14f0: 6c 69 62 72 61 72 79 20 77 69 6c 6c 20 62 65 20 library will be
1500: 61 63 74 75 61 6c 6c 79 20 6c 6f 61 64 65 64 20 actually loaded
1510: 6f 6e 6c 79 20 77 68 65 6e 20 72 65 61 6c 6c 79 only when really
1520: 20 72 65 71 75 69 72 65 64 2e 3c 62 72 3e 0d 0a required.<br>..
1530: 49 66 2c 20 66 6f 72 20 61 6e 79 20 72 65 61 73 If, for any reas
1540: 6f 6e 2c 20 3c 62 3e 6c 69 62 70 71 3c 2f 62 3e on, <b>libpq</b>
1550: 20 73 68 6f 75 6c 64 20 65 76 65 72 20 66 61 69 should ever fai
1560: 6c 20 74 6f 20 62 65 20 6c 6f 61 64 65 64 20 79 l to be loaded y
1570: 6f 75 72 20 61 70 70 6c 69 63 61 74 69 6f 6e 20 our application
1580: 77 69 6c 6c 20 73 75 72 76 69 76 65 20 77 69 74 will survive wit
1590: 68 6f 75 74 20 6e 65 67 61 74 69 76 65 20 65 66 hout negative ef
15a0: 66 65 63 74 73 20 28 65 78 63 65 70 74 20 74 68 fects (except th
15b0: 61 6e 20 50 6f 73 74 67 72 65 53 51 4c 20 69 6e an PostgreSQL in
15c0: 74 65 67 72 61 74 69 6f 6e 20 77 69 6c 6c 20 62 tegration will b
15d0: 65 20 6f 62 76 69 6f 75 73 6c 79 20 75 6e 61 76 e obviously unav
15e0: 61 69 6c 61 62 6c 65 29 2e 3c 2f 6c 69 3e 0d 0a ailable).</li>..
15f0: 3c 2f 6f 6c 3e 0d 0a 3c 76 65 72 62 61 74 69 6d </ol>..<verbatim
1600: 3e 0d 0a 20 20 20 20 76 69 72 74 75 61 6c 50 51 >.. virtualPQ
1610: 20 76 69 72 74 75 61 6c 5f 61 70 69 3b 0d 0a 0d virtual_api;...
1620: 0a 2a 2f 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 .*/ initializati
1630: 6f 6e 20 6f 66 20 74 68 65 20 76 69 72 74 75 61 on of the virtua
1640: 6c 20 41 50 49 20 62 61 73 65 64 20 6f 6e 20 68 l API based on h
1650: 61 72 64 2d 6c 69 6e 6b 65 64 20 4c 69 62 50 51 ard-linked LibPQ
1660: 20 2a 2f 0d 0a 20 20 20 20 76 69 72 74 75 61 6c */.. virtual
1670: 5f 61 70 69 2e 50 51 63 6c 65 61 72 20 3d 20 50 _api.PQclear = P
1680: 51 63 6c 65 61 72 3b 0d 0a 20 20 20 20 76 69 72 Qclear;.. vir
1690: 74 75 61 6c 5f 61 70 69 2e 50 51 63 6f 6e 6e 65 tual_api.PQconne
16a0: 63 74 64 62 20 3d 20 50 51 63 6f 6e 6e 65 63 74 ctdb = PQconnect
16b0: 64 62 3b 0d 0a 20 20 20 20 76 69 72 74 75 61 6c db;.. virtual
16c0: 5f 61 70 69 2e 50 51 65 72 72 6f 72 4d 65 73 73 _api.PQerrorMess
16d0: 61 67 65 20 3d 20 50 51 65 72 72 6f 72 4d 65 73 age = PQerrorMes
16e0: 73 61 67 65 3b 0d 0a 20 20 20 20 76 69 72 74 75 sage;.. virtu
16f0: 61 6c 5f 61 70 69 2e 50 51 65 78 65 63 20 3d 20 al_api.PQexec =
1700: 50 51 65 78 65 63 3b 0d 0a 20 20 20 20 76 69 72 PQexec;.. vir
1710: 74 75 61 6c 5f 61 70 69 2e 50 51 66 69 6e 69 73 tual_api.PQfinis
1720: 68 20 3d 20 50 51 66 69 6e 69 73 68 3b 0d 0a 20 h = PQfinish;..
1730: 20 20 20 76 69 72 74 75 61 6c 5f 61 70 69 2e 50 virtual_api.P
1740: 51 67 65 74 69 73 6e 75 6c 6c 20 3d 20 50 51 67 Qgetisnull = PQg
1750: 65 74 69 73 6e 75 6c 6c 3b 0d 0a 20 20 20 20 76 etisnull;.. v
1760: 69 72 74 75 61 6c 5f 61 70 69 2e 50 51 67 65 74 irtual_api.PQget
1770: 76 61 6c 75 65 20 3d 20 50 51 67 65 74 76 61 6c value = PQgetval
1780: 75 65 3b 0d 0a 20 20 20 20 76 69 72 74 75 61 6c ue;.. virtual
1790: 5f 61 70 69 2e 50 51 6c 69 62 56 65 72 73 69 6f _api.PQlibVersio
17a0: 6e 20 3d 20 50 51 6c 69 62 56 65 72 73 69 6f 6e n = PQlibVersion
17b0: 3b 0d 0a 20 20 20 20 76 69 72 74 75 61 6c 5f 61 ;.. virtual_a
17c0: 70 69 2e 50 51 6e 66 69 65 6c 64 73 20 3d 20 50 pi.PQnfields = P
17d0: 51 6e 66 69 65 6c 64 73 3b 0d 0a 20 20 20 20 76 Qnfields;.. v
17e0: 69 72 74 75 61 6c 5f 61 70 69 2e 50 51 6e 74 75 irtual_api.PQntu
17f0: 70 6c 65 73 20 3d 20 50 51 6e 74 75 70 6c 65 73 ples = PQntuples
1800: 3b 0d 0a 20 20 20 20 76 69 72 74 75 61 6c 5f 61 ;.. virtual_a
1810: 70 69 2e 50 51 72 65 73 75 6c 74 53 74 61 74 75 pi.PQresultStatu
1820: 73 20 3d 20 50 51 72 65 73 75 6c 74 53 74 61 74 s = PQresultStat
1830: 75 73 3b 0d 0a 20 20 20 20 76 69 72 74 75 61 6c us;.. virtual
1840: 5f 61 70 69 2e 50 51 73 74 61 74 75 73 20 3d 20 _api.PQstatus =
1850: 50 51 73 74 61 74 75 73 3b 0d 0a 3c 2f 76 65 72 PQstatus;..</ver
1860: 62 61 74 69 6d 3e 0d 0a 54 68 65 20 61 62 6f 76 batim>..The abov
1870: 65 20 63 6f 64 65 20 73 6e 69 70 70 65 74 20 65 e code snippet e
1880: 78 65 6d 70 6c 69 66 69 65 73 20 68 6f 77 2d 74 xemplifies how-t
1890: 6f 20 69 6e 69 74 69 61 6c 69 7a 65 20 74 68 65 o initialize the
18a0: 20 56 69 72 74 75 61 6c 20 41 50 49 20 69 6e 20 Virtual API in
18b0: 74 68 65 20 3c 62 3e 68 61 72 64 2d 6c 69 6e 6b the <b>hard-link
18c0: 65 64 3c 2f 62 3e 20 73 63 65 6e 61 72 69 6f 2e ed</b> scenario.
18d0: 3c 62 72 3e 0d 0a 3c 75 3e 3c 62 3e 4e 6f 74 65 <br>..<u><b>Note
18e0: 3c 2f 75 3e 3c 2f 62 3e 3a 20 69 6e 20 74 68 69 </u></b>: in thi
18f0: 73 20 63 61 73 65 20 79 6f 75 72 20 61 70 70 6c s case your appl
1900: 69 63 61 74 69 6f 6e 20 69 73 20 65 78 70 65 63 ication is expec
1910: 74 65 64 20 74 6f 20 62 65 20 6c 69 6e 6b 65 64 ted to be linked
1920: 20 62 79 20 73 70 65 63 69 66 79 69 6e 67 20 28 by specifying (
1930: 61 74 20 6c 65 61 73 74 29 20 3c 62 3e 2d 6c 76 at least) <b>-lv
1940: 69 72 74 75 61 6c 70 67 20 2d 6c 73 71 6c 69 74 irtualpg -lsqlit
1950: 65 33 20 2d 6c 70 71 3c 2f 62 3e 2e 0d 0a 3c 76 e3 -lpq</b>...<v
1960: 65 72 62 61 74 69 6d 3e 0d 0a 20 20 20 20 76 69 erbatim>.. vi
1970: 72 74 75 61 6c 50 51 20 76 69 72 74 75 61 6c 5f rtualPQ virtual_
1980: 61 70 69 3b 20 0d 0a 20 20 20 20 77 78 44 79 6e api; .. wxDyn
1990: 61 6d 69 63 4c 69 62 72 61 72 79 20 44 79 6e 61 amicLibrary Dyna
19a0: 6d 69 63 4c 69 62 50 51 3b 0d 0a 0d 0a 2a 2f 20 micLibPQ;....*/
19b0: 69 6e 69 74 69 61 6c 69 7a 61 74 69 6f 6e 20 6f initialization o
19c0: 66 20 74 68 65 20 76 69 72 74 75 61 6c 20 41 50 f the virtual AP
19d0: 49 20 62 61 73 65 64 20 6f 6e 20 64 79 6e 61 6d I based on dynam
19e0: 69 63 61 6c 6c 79 20 6c 6f 61 64 65 64 20 4c 69 ically loaded Li
19f0: 62 50 51 20 2a 2f 0d 0a 20 20 20 20 69 66 20 28 bPQ */.. if (
1a00: 44 79 6e 61 6d 69 63 4c 69 62 50 51 2e 4c 6f 61 DynamicLibPQ.Loa
1a10: 64 28 70 61 74 68 2c 20 77 78 44 4c 5f 51 55 49 d(path, wxDL_QUI
1a20: 45 54 29 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20 ET)).. {..
1a30: 20 20 20 62 6f 6f 6c 20 6f 6b 3b 0d 0a 20 20 20 bool ok;..
1a40: 20 20 20 76 69 72 74 75 61 6c 5f 61 70 69 2e 50 virtual_api.P
1a50: 51 63 6c 65 61 72 20 3d 20 28 76 6f 69 64 20 28 Qclear = (void (
1a60: 2a 29 28 50 47 72 65 73 75 6c 74 20 2a 29 29 20 *)(PGresult *))
1a70: 20 20 20 20 20 20 0d 0a 20 20 20 20 20 20 20 20 ..
1a80: 20 20 20 20 20 44 79 6e 61 6d 69 63 4c 69 62 50 DynamicLibP
1a90: 51 2e 47 65 74 53 79 6d 62 6f 6c 28 77 78 54 28 Q.GetSymbol(wxT(
1aa0: 22 50 51 63 6c 65 61 72 22 29 2c 20 26 6f 6b 29 "PQclear"), &ok)
1ab0: 3b 0d 0a 20 20 20 20 20 20 76 69 72 74 75 61 6c ;.. virtual
1ac0: 5f 61 70 69 2e 50 51 63 6f 6e 6e 65 63 74 64 62 _api.PQconnectdb
1ad0: 20 3d 20 28 50 47 63 6f 6e 6e 20 2a 20 28 2a 29 = (PGconn * (*)
1ae0: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 63 6f 6e (const char *con
1af0: 6e 69 6e 66 6f 29 29 0d 0a 20 20 20 20 20 20 20 ninfo))..
1b00: 20 20 20 20 20 20 44 79 6e 61 6d 69 63 4c 69 62 DynamicLib
1b10: 50 51 2e 47 65 74 53 79 6d 62 6f 6c 28 77 78 54 PQ.GetSymbol(wxT
1b20: 28 22 50 51 63 6f 6e 6e 65 63 74 64 62 22 29 2c ("PQconnectdb"),
1b30: 20 26 6f 6b 29 3b 0d 0a 20 20 20 20 20 20 76 69 &ok);.. vi
1b40: 72 74 75 61 6c 5f 61 70 69 2e 50 51 65 72 72 6f rtual_api.PQerro
1b50: 72 4d 65 73 73 61 67 65 20 3d 20 28 63 68 61 72 rMessage = (char
1b60: 20 2a 28 2a 29 28 63 6f 6e 73 74 20 50 47 63 6f *(*)(const PGco
1b70: 6e 6e 20 2a 20 63 6f 6e 6e 29 29 0d 0a 20 20 20 nn * conn))..
1b80: 20 20 20 20 20 20 20 20 20 20 44 79 6e 61 6d 69 Dynami
1b90: 63 4c 69 62 50 51 2e 47 65 74 53 79 6d 62 6f 6c cLibPQ.GetSymbol
1ba0: 28 77 78 54 28 22 50 51 65 72 72 6f 72 4d 65 73 (wxT("PQerrorMes
1bb0: 73 61 67 65 22 29 2c 20 26 6f 6b 29 3b 0d 0a 20 sage"), &ok);..
1bc0: 20 20 20 20 20 76 69 72 74 75 61 6c 5f 61 70 69 virtual_api
1bd0: 2e 50 51 65 78 65 63 20 3d 20 28 50 47 72 65 73 .PQexec = (PGres
1be0: 75 6c 74 20 2a 20 28 2a 29 28 50 47 63 6f 6e 6e ult * (*)(PGconn
1bf0: 20 2a 20 63 6f 6e 6e 2c 20 63 6f 6e 73 74 20 63 * conn, const c
1c00: 68 61 72 20 2a 63 6f 6d 6d 61 6e 64 29 29 0d 0a har *command))..
1c10: 20 20 20 20 20 20 20 20 20 20 20 20 20 44 79 6e Dyn
1c20: 61 6d 69 63 4c 69 62 50 51 2e 47 65 74 53 79 6d amicLibPQ.GetSym
1c30: 62 6f 6c 28 77 78 54 28 22 50 51 65 78 65 63 22 bol(wxT("PQexec"
1c40: 29 2c 20 26 6f 6b 29 3b 0d 0a 20 20 20 20 20 20 ), &ok);..
1c50: 76 69 72 74 75 61 6c 5f 61 70 69 2e 50 51 66 69 virtual_api.PQfi
1c60: 6e 69 73 68 20 3d 20 28 76 6f 69 64 20 28 2a 29 nish = (void (*)
1c70: 28 50 47 63 6f 6e 6e 20 2a 20 63 6f 6e 6e 29 29 (PGconn * conn))
1c80: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 44 .. D
1c90: 79 6e 61 6d 69 63 4c 69 62 50 51 2e 47 65 74 53 ynamicLibPQ.GetS
1ca0: 79 6d 62 6f 6c 28 77 78 54 28 22 50 51 66 69 6e ymbol(wxT("PQfin
1cb0: 69 73 68 22 29 2c 20 26 6f 6b 29 3b 0d 0a 20 20 ish"), &ok);..
1cc0: 20 20 20 20 76 69 72 74 75 61 6c 5f 61 70 69 2e virtual_api.
1cd0: 50 51 67 65 74 69 73 6e 75 6c 6c 20 3d 20 28 69 PQgetisnull = (i
1ce0: 6e 74 20 28 2a 29 28 63 6f 6e 73 74 20 50 47 72 nt (*)(const PGr
1cf0: 65 73 75 6c 74 20 2a 20 72 65 73 2c 20 69 6e 74 esult * res, int
1d00: 20 72 6f 77 5f 6e 75 6d 62 65 72 2c 20 69 6e 74 row_number, int
1d10: 20 63 6f 6c 75 6d 6e 5f 6e 75 6d 62 65 72 29 29 column_number))
1d20: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 44 .. D
1d30: 79 6e 61 6d 69 63 4c 69 62 50 51 2e 47 65 74 53 ynamicLibPQ.GetS
1d40: 79 6d 62 6f 6c 28 77 78 54 28 22 50 51 67 65 74 ymbol(wxT("PQget
1d50: 69 73 6e 75 6c 6c 22 29 2c 20 26 6f 6b 29 3b 0d isnull"), &ok);.
1d60: 0a 20 20 20 20 20 20 76 69 72 74 75 61 6c 5f 61 . virtual_a
1d70: 70 69 2e 50 51 67 65 74 76 61 6c 75 65 20 3d 20 pi.PQgetvalue =
1d80: 28 63 68 61 72 20 2a 28 2a 29 28 63 6f 6e 73 74 (char *(*)(const
1d90: 20 50 47 72 65 73 75 6c 74 20 2a 20 72 65 73 2c PGresult * res,
1da0: 20 69 6e 74 20 72 6f 77 5f 6e 75 6d 62 65 72 2c int row_number,
1db0: 20 69 6e 74 20 63 6f 6c 75 6d 6e 5f 6e 75 6d 62 int column_numb
1dc0: 65 72 29 29 0d 0a 20 20 20 20 20 20 20 20 20 20 er))..
1dd0: 20 20 20 44 79 6e 61 6d 69 63 4c 69 62 50 51 2e DynamicLibPQ.
1de0: 47 65 74 53 79 6d 62 6f 6c 28 77 78 54 28 22 50 GetSymbol(wxT("P
1df0: 51 67 65 74 76 61 6c 75 65 22 29 2c 20 26 6f 6b Qgetvalue"), &ok
1e00: 29 3b 0d 0a 20 20 20 20 20 20 76 69 72 74 75 61 );.. virtua
1e10: 6c 5f 61 70 69 2e 50 51 6c 69 62 56 65 72 73 69 l_api.PQlibVersi
1e20: 6f 6e 20 3d 20 28 69 6e 74 20 28 2a 29 28 76 6f on = (int (*)(vo
1e30: 69 64 29 29 0d 0a 20 20 20 20 20 20 20 20 20 20 id))..
1e40: 20 20 20 44 79 6e 61 6d 69 63 4c 69 62 50 51 2e DynamicLibPQ.
1e50: 47 65 74 53 79 6d 62 6f 6c 28 77 78 54 28 22 50 GetSymbol(wxT("P
1e60: 51 6c 69 62 56 65 72 73 69 6f 6e 22 29 2c 20 26 QlibVersion"), &
1e70: 6f 6b 29 3b 0d 0a 20 20 20 20 20 20 76 69 72 74 ok);.. virt
1e80: 75 61 6c 5f 61 70 69 2e 50 51 6e 66 69 65 6c 64 ual_api.PQnfield
1e90: 73 20 3d 20 28 69 6e 74 20 28 2a 29 28 63 6f 6e s = (int (*)(con
1ea0: 73 74 20 50 47 72 65 73 75 6c 74 20 2a 20 72 65 st PGresult * re
1eb0: 73 29 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 s))..
1ec0: 20 20 44 79 6e 61 6d 69 63 4c 69 62 50 51 2e 47 DynamicLibPQ.G
1ed0: 65 74 53 79 6d 62 6f 6c 28 77 78 54 28 22 50 51 etSymbol(wxT("PQ
1ee0: 6e 66 69 65 6c 64 73 22 29 2c 20 26 6f 6b 29 3b nfields"), &ok);
1ef0: 0d 0a 20 20 20 20 20 20 76 69 72 74 75 61 6c 5f .. virtual_
1f00: 61 70 69 2e 50 51 6e 74 75 70 6c 65 73 20 3d 20 api.PQntuples =
1f10: 28 69 6e 74 20 28 2a 29 28 63 6f 6e 73 74 20 50 (int (*)(const P
1f20: 47 72 65 73 75 6c 74 20 2a 20 72 65 73 29 29 0d Gresult * res)).
1f30: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 44 79 . Dy
1f40: 6e 61 6d 69 63 4c 69 62 50 51 2e 47 65 74 53 79 namicLibPQ.GetSy
1f50: 6d 62 6f 6c 28 77 78 54 28 22 50 51 6e 74 75 70 mbol(wxT("PQntup
1f60: 6c 65 73 22 29 2c 20 26 6f 6b 29 3b 0d 0a 20 20 les"), &ok);..
1f70: 20 20 20 20 76 69 72 74 75 61 6c 5f 61 70 69 2e virtual_api.
1f80: 50 51 72 65 73 75 6c 74 53 74 61 74 75 73 20 3d PQresultStatus =
1f90: 20 28 45 78 65 63 53 74 61 74 75 73 54 79 70 65 (ExecStatusType
1fa0: 28 2a 29 28 63 6f 6e 73 74 20 50 47 72 65 73 75 (*)(const PGresu
1fb0: 6c 74 20 2a 20 72 65 73 29 29 0d 0a 20 20 20 20 lt * res))..
1fc0: 20 20 20 20 20 20 20 20 20 44 79 6e 61 6d 69 63 Dynamic
1fd0: 4c 69 62 50 51 2e 47 65 74 53 79 6d 62 6f 6c 28 LibPQ.GetSymbol(
1fe0: 77 78 54 28 22 50 51 72 65 73 75 6c 74 53 74 61 wxT("PQresultSta
1ff0: 74 75 73 22 29 2c 20 26 6f 6b 29 3b 0d 0a 20 20 tus"), &ok);..
2000: 20 20 20 20 76 69 72 74 75 61 6c 5f 61 70 69 2e virtual_api.
2010: 50 51 73 74 61 74 75 73 20 3d 20 28 43 6f 6e 6e PQstatus = (Conn
2020: 53 74 61 74 75 73 54 79 70 65 28 2a 29 28 63 6f StatusType(*)(co
2030: 6e 73 74 20 50 47 63 6f 6e 6e 20 2a 20 63 6f 6e nst PGconn * con
2040: 6e 29 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20 n))..
2050: 20 20 44 79 6e 61 6d 69 63 4c 69 62 50 51 2e 47 DynamicLibPQ.G
2060: 65 74 53 79 6d 62 6f 6c 28 77 78 54 28 22 50 51 etSymbol(wxT("PQ
2070: 73 74 61 74 75 73 22 29 2c 20 26 6f 6b 29 3b 0d status"), &ok);.
2080: 0a 20 20 20 20 7d 0d 0a 3c 2f 76 65 72 62 61 74 . }..</verbat
2090: 69 6d 3e 0d 0a 54 68 69 73 20 73 65 63 6f 6e 64 im>..This second
20a0: 20 63 6f 64 65 20 73 6e 69 70 70 65 74 20 65 78 code snippet ex
20b0: 65 6d 70 6c 69 66 69 65 73 20 68 6f 77 2d 74 6f emplifies how-to
20c0: 20 69 6e 69 74 69 61 6c 69 7a 65 20 74 68 65 20 initialize the
20d0: 56 69 72 74 75 61 6c 20 41 50 49 20 69 6e 20 74 Virtual API in t
20e0: 68 65 20 3c 62 3e 6c 61 74 65 20 62 69 6e 64 69 he <b>late bindi
20f0: 6e 67 3c 2f 62 3e 20 73 63 65 6e 61 72 69 6f 2e ng</b> scenario.
2100: 3c 62 72 3e 0d 0a 54 68 65 20 63 6f 64 65 20 69 <br>..The code i
2110: 73 20 62 61 73 65 64 20 6f 6e 20 74 68 65 20 63 s based on the c
2120: 72 6f 73 73 2d 70 6c 61 74 66 6f 72 6d 20 63 6c ross-platform cl
2130: 61 73 73 20 3c 62 3e 77 78 44 79 6e 61 6d 69 63 ass <b>wxDynamic
2140: 4c 69 62 72 61 72 79 3c 2f 62 3e 20 73 75 70 70 Library</b> supp
2150: 6f 72 74 65 64 20 62 79 20 3c 62 3e 77 78 57 69 orted by <b>wxWi
2160: 64 67 65 74 73 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a dgets</b>.<br>..
2170: 4c 69 6e 75 78 20 6e 61 74 69 76 65 6c 79 20 73 Linux natively s
2180: 75 70 70 6f 72 74 73 20 3c 62 3e 64 6c 6f 70 65 upports <b>dlope
2190: 6e 28 29 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e 64 n()</b> and <b>d
21a0: 6c 73 79 6d 28 29 3c 2f 62 3e 2c 20 77 68 69 6c lsym()</b>, whil
21b0: 73 74 20 57 69 6e 64 6f 77 73 20 73 75 70 70 6f st Windows suppo
21c0: 72 74 73 20 69 74 73 20 6f 77 6e 20 3c 62 3e 4c rts its own <b>L
21d0: 6f 61 64 4c 69 62 72 61 72 79 28 29 3c 2f 62 3e oadLibrary()</b>
21e0: 20 61 6e 64 20 3c 62 3e 47 65 74 50 72 6f 63 41 and <b>GetProcA
21f0: 64 64 72 65 73 73 28 29 3c 2f 62 3e 3b 20 61 6c ddress()</b>; al
2200: 6c 20 74 68 65 6d 20 61 72 65 20 76 65 72 79 20 l them are very
2210: 73 69 6d 69 6c 61 72 20 69 6e 20 64 65 73 69 67 similar in desig
2220: 6e 2c 20 61 6e 64 20 74 68 65 20 6f 76 65 72 61 n, and the overa
2230: 6c 6c 20 61 70 70 72 6f 61 63 68 20 69 73 20 61 ll approach is a
2240: 6c 6d 6f 73 74 20 74 68 65 20 73 61 6d 65 2e 3c lmost the same.<
2250: 62 72 3e 0d 0a 3c 75 3e 3c 62 3e 4e 6f 74 65 3c br>..<u><b>Note<
2260: 2f 75 3e 3c 2f 62 3e 3a 20 69 6e 20 74 68 69 73 /u></b>: in this
2270: 20 63 61 73 65 20 79 6f 75 72 20 61 70 70 6c 69 case your appli
2280: 63 61 74 69 6f 6e 20 69 73 20 65 78 70 65 63 74 cation is expect
2290: 65 64 20 74 6f 20 62 65 20 6c 69 6e 6b 65 64 20 ed to be linked
22a0: 62 79 20 73 70 65 63 69 66 79 69 6e 67 20 6f 6e by specifying on
22b0: 6c 79 20 3c 62 3e 2d 6c 76 69 72 74 75 61 6c 70 ly <b>-lvirtualp
22c0: 67 20 2d 6c 73 71 6c 69 74 65 33 3c 2f 62 3e 2c g -lsqlite3</b>,
22d0: 20 62 75 74 20 6e 6f 74 20 3c 62 3e 2d 6c 70 71 but not <b>-lpq
22e0: 3c 2f 62 3e 2e 0d 0a 3c 62 72 3e 3c 62 72 3e 0d </b>...<br><br>.
22f0: 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 56 69 72 74 75 .<hr>..<h3>Virtu
2300: 61 6c 50 47 20 61 73 20 61 20 64 79 6e 61 6d 69 alPG as a dynami
2310: 63 20 65 78 74 65 6e 73 69 6f 6e 20 6d 6f 64 75 c extension modu
2320: 6c 65 3c 2f 68 33 3e 0d 0a 54 68 65 20 65 78 74 le</h3>..The ext
2330: 65 6e 73 69 6f 6e 20 6d 6f 64 75 6c 65 20 73 69 ension module si
2340: 6d 70 6c 79 20 69 73 20 61 6e 20 6f 72 64 69 6e mply is an ordin
2350: 61 72 79 20 3c 69 3e 64 79 6e 61 6d 69 63 20 6c ary <i>dynamic l
2360: 69 62 72 61 72 79 3c 2f 69 3e 20 28 3c 62 3e 2e ibrary</i> (<b>.
2370: 64 6c 6c 3c 2f 62 3e 20 6f 6e 20 57 69 6e 64 6f dll</b> on Windo
2380: 77 73 2c 20 3c 62 3e 2e 73 6f 3c 2f 62 3e 20 6f ws, <b>.so</b> o
2390: 6e 20 55 6e 69 78 20 61 6e 64 20 4c 69 6e 75 78 n Unix and Linux
23a0: 2c 20 3c 62 3e 2e 64 79 6c 69 62 3c 2f 62 3e 20 , <b>.dylib</b>
23b0: 6f 6e 20 4d 61 63 20 4f 73 20 58 29 3b 20 73 6f on Mac Os X); so
23c0: 20 74 68 65 20 66 69 72 73 74 20 74 68 69 6e 67 the first thing
23d0: 20 74 6f 20 62 65 20 64 6f 6e 65 20 69 6e 20 6f to be done in o
23e0: 72 64 65 72 20 74 6f 20 61 63 74 69 76 61 74 65 rder to activate
23f0: 20 74 68 69 73 20 65 78 74 65 6e 73 69 6f 6e 20 this extension
2400: 69 73 20 6c 6f 61 64 69 6e 67 20 74 68 65 20 63 is loading the c
2410: 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 6c 69 62 orresponding lib
2420: 72 61 72 79 20 66 72 6f 6d 20 61 20 76 61 6c 69 rary from a vali
2430: 64 20 53 51 4c 69 74 65 2f 53 70 61 74 69 61 4c d SQLite/SpatiaL
2440: 69 74 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 2e 0d ite connection..
2450: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c .<verbatim>..SEL
2460: 45 43 54 20 6c 6f 61 64 5f 65 78 74 65 6e 73 69 ECT load_extensi
2470: 6f 6e 28 27 6d 6f 64 5f 76 69 72 74 75 61 6c 70 on('mod_virtualp
2480: 67 27 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 0d 0a 4e 55 g');..------..NU
2490: 4c 4c 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d LL..</verbatim>.
24a0: 0a 3c 62 3e 4e 6f 74 65 3c 2f 62 3e 3a 0d 0a 3c .<b>Note</b>:..<
24b0: 75 6c 3e 0d 0a 3c 6c 69 3e 74 68 69 73 20 6d 65 ul>..<li>this me
24c0: 63 68 61 6e 69 73 6d 20 6a 75 73 74 20 72 65 6c chanism just rel
24d0: 69 65 73 20 6f 6e 20 74 68 65 20 69 6e 74 65 72 ies on the inter
24e0: 6e 61 6c 20 63 61 70 61 62 69 6c 69 74 69 65 73 nal capabilities
24f0: 20 6f 66 20 53 51 4c 69 74 65 2c 20 73 6f 20 69 of SQLite, so i
2500: 74 27 73 20 65 78 70 65 63 74 65 64 20 74 6f 20 t's expected to
2510: 77 6f 72 6b 20 6f 6e 20 61 6e 79 20 70 6f 73 73 work on any poss
2520: 69 62 6c 65 20 6c 61 6e 67 75 61 67 65 3a 20 4a ible language: J
2530: 61 76 61 2c 20 50 79 74 68 6f 6e 2c 20 50 48 50 ava, Python, PHP
2540: 2c 20 43 23 20 61 6e 64 20 73 6f 20 6f 6e 2e 3c , C# and so on.<
2550: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6c 6c 20 72 65 /li>..<li>all re
2560: 63 65 6e 74 20 76 65 72 73 69 6f 6e 73 20 6f 66 cent versions of
2570: 20 53 51 4c 69 74 65 20 61 72 65 20 73 6d 61 72 SQLite are smar
2580: 74 20 65 6e 6f 75 67 68 20 74 6f 20 6e 6f 74 20 t enough to not
2590: 72 65 71 75 69 72 65 20 73 70 65 63 69 66 79 69 require specifyi
25a0: 6e 67 20 61 6e 79 20 70 6c 61 74 66 6f 72 6d 2d ng any platform-
25b0: 64 65 70 65 6e 64 65 6e 74 20 73 75 66 66 69 78 dependent suffix
25c0: 2e 3c 62 72 3e 0d 0a 6a 75 73 74 20 70 61 73 73 .<br>..just pass
25d0: 69 6e 67 20 3c 62 3e 6d 6f 64 5f 73 70 61 74 69 ing <b>mod_spati
25e0: 61 6c 69 74 65 3c 2f 62 3e 20 61 73 20 74 68 65 alite</b> as the
25f0: 20 65 78 74 65 6e 73 69 6f 6e 20 6e 61 6d 65 20 extension name
2600: 73 68 6f 75 6c 64 20 62 65 20 65 6e 6f 75 67 68 should be enough
2610: 20 6f 6e 20 61 6e 79 20 63 6f 72 72 65 63 74 6c on any correctl
2620: 79 20 63 6f 6e 66 69 67 75 72 65 64 20 70 6c 61 y configured pla
2630: 74 66 6f 72 6d 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 tform.</li>..<li
2640: 3e 74 68 65 20 3c 62 3e 56 69 72 74 75 61 6c 50 >the <b>VirtualP
2650: 47 3c 2f 62 3e 20 65 78 74 65 6e 73 69 6f 6e 20 G</b> extension
2660: 64 6f 65 73 20 6e 6f 74 20 6e 65 63 65 73 73 61 does not necessa
2670: 72 69 6c 79 20 72 65 71 75 69 72 65 20 74 6f 20 rily require to
2680: 62 65 20 73 75 70 70 6f 72 74 65 64 20 62 79 20 be supported by
2690: 74 68 65 20 3c 62 3e 53 70 61 74 69 61 4c 69 74 the <b>SpatiaLit
26a0: 65 3c 2f 62 3e 20 65 78 74 65 6e 73 69 6f 6e 3b e</b> extension;
26b0: 20 74 68 65 79 20 61 72 65 20 69 6e 64 65 70 65 they are indepe
26c0: 6e 64 65 6e 74 20 74 68 65 20 6f 6e 65 20 66 72 ndent the one fr
26d0: 6f 6d 20 74 68 65 20 6f 74 68 65 72 2e 3c 2f 6c om the other.</l
26e0: 69 3e 0d 0a 3c 6c 69 3e 74 68 65 20 72 65 6c 61 i>..<li>the rela
26f0: 74 69 76 65 20 6f 72 64 65 72 20 69 6e 20 77 68 tive order in wh
2700: 69 63 68 20 74 68 65 20 74 77 6f 20 65 78 74 65 ich the two exte
2710: 6e 73 69 6f 6e 73 20 61 72 65 20 65 76 65 6e 74 nsions are event
2720: 75 61 6c 6c 79 20 6c 6f 61 64 65 65 64 20 69 73 ually loadeed is
2730: 20 61 62 73 6f 6c 75 74 65 6c 79 20 6e 6f 74 20 absolutely not
2740: 72 65 6c 65 76 61 6e 74 2e 3c 2f 6c 69 3e 0d 0a relevant.</li>..
2750: 3c 6c 69 3e 68 6f 77 65 76 65 72 2c 20 77 68 65 <li>however, whe
2760: 6e 20 56 69 72 74 75 61 6c 50 47 20 69 73 20 62 n VirtualPG is b
2770: 61 63 6b 65 64 20 75 70 20 62 79 20 53 70 61 74 acked up by Spat
2780: 69 61 4c 69 74 65 2c 20 79 6f 75 27 6c 6c 20 61 iaLite, you'll a
2790: 6c 77 61 79 73 20 62 65 20 61 62 6c 65 20 74 6f lways be able to
27a0: 20 65 6e 71 75 69 72 79 20 69 6e 20 66 75 6c 6c enquiry in full
27b0: 20 64 65 74 61 69 6c 20 61 6e 79 20 65 72 72 6f detail any erro
27c0: 72 20 6d 65 73 73 61 67 65 20 72 61 69 73 65 64 r message raised
27d0: 20 62 79 20 50 6f 73 74 67 72 65 53 51 4c 20 62 by PostgreSQL b
27e0: 79 20 63 61 6c 6c 69 6e 67 20 74 68 65 20 53 51 y calling the SQ
27f0: 4c 20 66 75 6e 63 74 69 6f 6e 20 3c 62 3e 50 6f L function <b>Po
2800: 73 74 67 72 65 53 71 6c 5f 47 65 74 4c 61 73 74 stgreSql_GetLast
2810: 4d 65 73 73 61 67 65 28 29 3c 2f 62 3e 2e 3c 62 Message()</b>.<b
2820: 72 3e 0d 0a 74 68 69 73 20 69 73 20 61 20 72 65 r>..this is a re
2830: 61 6c 6c 79 20 75 73 65 66 75 6c 20 64 69 61 67 ally useful diag
2840: 6e 6f 73 74 69 63 20 66 75 6e 63 74 69 6f 6e 2c nostic function,
2850: 20 61 6e 64 20 77 69 6c 6c 20 67 72 65 61 74 6c and will greatl
2860: 79 20 69 6d 70 72 6f 76 65 20 74 68 65 20 75 73 y improve the us
2870: 61 62 69 6c 69 74 79 20 6f 66 20 56 69 72 74 75 ability of Virtu
2880: 61 6c 50 47 2c 20 61 6c 6c 6f 77 69 6e 67 20 66 alPG, allowing f
2890: 6f 72 20 61 20 73 69 6d 70 6c 69 66 69 65 64 20 or a simplified
28a0: 61 6e 64 20 65 61 73 69 65 72 20 64 65 62 75 67 and easier debug
28b0: 67 69 6e 67 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e ging.</li>..<li>
28c0: 77 68 65 6e 20 53 70 61 74 69 61 4c 69 74 65 27 when SpatiaLite'
28d0: 73 20 73 75 70 70 6f 72 74 20 69 73 20 75 6e 61 s support is una
28e0: 76 61 69 6c 61 62 6c 65 2c 20 56 69 72 74 75 61 vailable, Virtua
28f0: 6c 50 47 20 77 69 6c 6c 20 73 69 6d 70 6c 79 20 lPG will simply
2900: 61 74 74 65 6d 70 74 20 74 6f 20 6f 75 74 70 75 attempt to outpu
2910: 74 20 74 68 65 20 65 72 72 6f 72 20 6d 65 73 73 t the error mess
2920: 61 67 65 20 63 6f 6d 69 6e 67 20 66 72 6f 6d 20 age coming from
2930: 50 6f 73 74 67 72 65 53 51 4c 20 6f 6e 20 74 68 PostgreSQL on th
2940: 65 20 73 74 61 6e 64 61 72 64 20 65 72 72 6f 72 e standard error
2950: 20 28 69 66 20 61 76 61 69 6c 61 62 6c 65 29 2e (if available).
2960: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 4e 6f </li>..<li><b>No
2970: 74 65 3c 2f 62 3e 3a 20 74 68 65 20 64 69 61 67 te</b>: the diag
2980: 6e 6f 73 74 69 63 20 53 51 4c 20 66 75 6e 63 74 nostic SQL funct
2990: 69 6f 6e 20 3c 62 3e 50 6f 73 74 67 72 65 53 51 ion <b>PostgreSQ
29a0: 4c 5f 47 65 74 4c 61 73 74 45 72 72 6f 72 28 29 L_GetLastError()
29b0: 20 3c 2f 62 3e 72 65 71 75 69 72 65 73 20 75 73 </b>requires us
29c0: 69 6e 67 20 53 70 61 74 69 61 4c 69 74 65 20 76 ing SpatiaLite v
29d0: 65 72 73 69 6f 6e 20 35 2e 30 2e 30 20 6f 72 20 ersion 5.0.0 or
29e0: 6c 61 74 65 72 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 later.</li>..</u
29f0: 6c 3e 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65 20 63 l><br>..<table c
2a00: 65 6c 6c 73 70 61 63 69 6e 67 3d 22 36 22 20 63 ellspacing="6" c
2a10: 65 6c 6c 70 61 64 64 69 6e 67 3d 22 36 22 20 62 ellpadding="6" b
2a20: 67 63 6f 6c 6f 72 3d 22 23 66 66 66 66 65 38 22 gcolor="#ffffe8"
2a30: 20 77 69 64 74 68 3d 22 31 30 30 25 22 3e 0d 0a width="100%">..
2a40: 3c 74 72 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 63 <tr><td align="c
2a50: 65 6e 74 65 72 22 3e 3c 62 3e 55 73 65 66 75 6c enter"><b>Useful
2a60: 20 68 69 6e 74 73 20 61 6e 64 20 73 75 67 67 65 hints and sugge
2a70: 73 74 69 6f 6e 73 3a 20 74 72 6f 75 62 6c 65 73 stions: troubles
2a80: 68 6f 6f 74 69 6e 67 3c 2f 62 3e 3c 2f 74 64 3e hooting</b></td>
2a90: 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 3c </tr>..<tr><td><
2aa0: 68 72 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c hr></td></tr>..<
2ab0: 74 72 3e 3c 74 64 3e 0d 0a 54 68 69 73 20 6f 70 tr><td>..This op
2ac0: 65 72 61 74 69 6f 6e 20 63 6f 75 6c 64 20 65 76 eration could ev
2ad0: 65 6e 74 75 61 6c 6c 79 20 66 61 69 6c 20 66 6f entually fail fo
2ae0: 72 20 73 65 76 65 72 61 6c 20 64 69 66 66 65 72 r several differ
2af0: 65 6e 74 20 72 65 61 73 6f 6e 73 3a 20 68 65 72 ent reasons: her
2b00: 65 20 61 72 65 20 74 68 65 20 6d 6f 73 74 20 66 e are the most f
2b10: 72 65 71 75 65 6e 74 73 3a 0d 0a 3c 75 6c 3e 0d requents:..<ul>.
2b20: 0a 3c 6c 69 3e 59 6f 75 20 61 72 65 20 75 73 69 .<li>You are usi
2b30: 6e 67 20 73 6f 6d 65 20 6f 64 64 20 76 65 72 73 ng some odd vers
2b40: 69 6f 6e 20 6f 66 20 53 51 4c 69 74 65 33 2f 6c ion of SQLite3/l
2b50: 69 62 73 71 6c 69 74 65 33 20 66 6f 72 62 69 64 ibsqlite3 forbid
2b60: 64 69 6e 67 20 74 6f 20 6c 6f 61 64 20 61 6e 79 ding to load any
2b70: 20 64 79 6e 61 6d 69 63 20 65 78 74 65 6e 73 69 dynamic extensi
2b80: 6f 6e 73 2e 3c 62 72 3e 0d 0a 54 68 69 73 20 66 ons.<br>..This f
2b90: 65 61 74 75 72 65 20 63 6f 75 6c 64 20 65 76 65 eature could eve
2ba0: 6e 74 75 61 6c 6c 79 20 62 65 20 64 69 73 61 62 ntually be disab
2bb0: 6c 65 64 20 61 74 20 62 75 69 6c 64 20 74 69 6d led at build tim
2bc0: 65 3b 20 69 66 20 74 68 69 73 20 69 73 20 79 6f e; if this is yo
2bd0: 75 72 20 63 61 73 65 20 79 6f 75 20 73 69 6d 70 ur case you simp
2be0: 6c 65 20 68 61 76 65 20 74 6f 20 73 77 69 74 63 le have to switc
2bf0: 68 20 74 6f 20 73 6f 6d 65 20 64 69 66 66 65 72 h to some differ
2c00: 65 6e 74 20 53 51 4c 69 74 65 20 74 6f 6f 6c 6b ent SQLite toolk
2c10: 69 74 20 73 75 70 70 6f 72 74 69 6e 67 20 64 79 it supporting dy
2c20: 6e 61 6d 69 63 20 65 78 74 65 6e 73 69 6f 6e 73 namic extensions
2c30: 20 6f 72 20 62 75 69 6c 64 20 6f 6e 65 20 62 79 or build one by
2c40: 20 79 6f 75 72 73 65 6c 66 2e 3c 2f 6c 69 3e 0d yourself.</li>.
2c50: 0a 3c 6c 69 3e 54 68 65 20 6f 70 65 72 61 74 69 .<li>The operati
2c60: 6e 67 20 73 79 73 74 65 6d 20 63 6f 75 6c 64 20 ng system could
2c70: 62 65 20 75 6e 61 62 6c 65 20 74 6f 20 63 6f 72 be unable to cor
2c80: 72 65 63 74 6c 79 20 6c 6f 63 61 74 65 20 74 68 rectly locate th
2c90: 65 20 64 79 6e 61 6d 69 63 20 6c 69 62 72 61 72 e dynamic librar
2ca0: 79 20 74 6f 20 62 65 20 6c 6f 61 64 65 64 2e 3c y to be loaded.<
2cb0: 62 72 3e 0d 0a 54 68 65 20 6d 6f 73 74 20 72 65 br>..The most re
2cc0: 63 65 6e 74 20 76 65 72 73 69 6f 6e 73 20 6f 66 cent versions of
2cd0: 20 53 51 4c 69 74 65 20 61 72 65 20 73 6d 61 72 SQLite are smar
2ce0: 74 20 65 6e 6f 75 67 68 20 74 6f 20 61 75 74 6f t enough to auto
2cf0: 6d 61 74 69 63 61 6c 6c 79 20 68 61 6e 64 6c 65 matically handle
2d00: 20 61 6e 79 20 70 6c 61 74 66 6f 72 6d 20 73 70 any platform sp
2d10: 65 63 69 66 69 63 20 73 75 66 66 69 78 3a 20 73 ecific suffix: s
2d20: 6f 20 79 6f 75 20 61 72 65 20 6e 6f 20 6c 6f 6e o you are no lon
2d30: 67 65 72 20 72 65 71 75 69 72 65 64 20 74 6f 20 ger required to
2d40: 73 70 65 63 69 66 79 20 61 6e 79 20 3c 62 3e 2e specify any <b>.
2d50: 64 6c 6c 3c 2f 62 3e 20 6f 72 20 3c 62 3e 2e 73 dll</b> or <b>.s
2d60: 6f 3c 2f 62 3e 20 73 75 66 66 69 78 2e 3c 62 72 o</b> suffix.<br
2d70: 3e 0d 0a 49 66 20 79 6f 75 20 77 69 73 68 20 74 >..If you wish t
2d80: 6f 20 64 6f 20 73 6f 2c 20 79 6f 75 20 63 61 6e o do so, you can
2d90: 20 65 76 65 6e 74 75 61 6c 6c 79 20 73 70 65 63 eventually spec
2da0: 69 66 79 20 74 68 65 20 66 75 6c 6c 20 70 61 74 ify the full pat
2db0: 68 20 6c 65 61 64 69 6e 67 20 74 6f 20 74 68 65 h leading to the
2dc0: 20 64 79 6e 61 6d 69 63 20 6c 69 62 72 61 72 79 dynamic library
2dd0: 2c 20 74 68 69 73 20 69 6e 63 6c 75 64 69 6e 67 , this including
2de0: 20 61 6e 79 20 73 75 66 66 69 78 2e 3c 62 72 3e any suffix.<br>
2df0: 0d 0a 54 68 65 20 64 65 66 61 75 6c 74 20 62 65 ..The default be
2e00: 68 61 76 69 6f 75 72 20 6f 66 20 3c 62 3e 6c 6f haviour of <b>lo
2e10: 61 64 5f 65 78 74 65 6e 73 69 6f 6e 28 29 3c 2f ad_extension()</
2e20: 62 3e 20 69 73 20 74 68 65 20 6f 6e 65 20 74 6f b> is the one to
2e30: 20 73 65 61 72 63 68 20 74 68 65 20 72 65 71 75 search the requ
2e40: 69 72 65 64 20 64 79 6e 61 6d 69 63 20 6c 69 62 ired dynamic lib
2e50: 72 61 72 79 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 rary following t
2e60: 68 65 20 73 74 61 6e 64 61 72 64 20 70 6c 61 74 he standard plat
2e70: 66 6f 72 6d 20 73 70 65 63 69 66 69 63 20 72 75 form specific ru
2e80: 6c 65 73 3b 20 70 6c 65 61 73 65 20 63 6f 6e 73 les; please cons
2e90: 75 6c 74 20 74 68 65 20 61 70 70 72 6f 70 72 69 ult the appropri
2ea0: 61 74 65 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f ate documentatio
2eb0: 6e 20 66 6f 72 20 6d 6f 72 65 20 73 70 65 63 69 n for more speci
2ec0: 66 69 63 20 64 65 74 61 69 6c 73 2e 0d 0a 3c 2f fic details...</
2ed0: 6c 69 3e 0d 0a 3c 6c 69 3e 54 68 65 20 64 79 6e li>..<li>The dyn
2ee0: 61 6d 69 63 20 6c 69 62 72 61 72 79 20 69 74 73 amic library its
2ef0: 65 6c 66 20 63 6f 75 6c 64 20 62 65 20 63 6f 72 elf could be cor
2f00: 72 65 63 74 6c 79 20 6c 6f 63 61 74 65 64 2c 20 rectly located,
2f10: 62 75 74 20 73 6f 6d 65 20 66 75 72 74 68 65 72 but some further
2f20: 20 64 65 70 65 6e 64 69 6e 67 20 6c 69 62 72 61 depending libra
2f30: 72 79 20 63 6f 75 6c 64 20 6e 6f 74 2c 20 74 68 ry could not, th
2f40: 75 73 20 66 6f 72 62 69 64 64 69 6e 67 20 74 6f us forbidding to
2f50: 20 6c 6f 61 64 20 74 68 65 20 6d 61 69 6e 20 6c load the main l
2f60: 69 62 72 61 72 79 2e 3c 62 72 3e 0d 0a 3c 75 3e ibrary.<br>..<u>
2f70: 50 6c 65 61 73 65 20 6e 6f 74 65 3c 2f 75 3e 3a Please note</u>:
2f80: 20 3c 62 3e 56 69 72 74 75 61 6c 50 47 3c 2f 62 <b>VirtualPG</b
2f90: 3e 20 64 65 70 65 6e 64 73 20 6f 6e 20 74 68 65 > depends on the
2fa0: 20 50 6f 73 74 67 72 65 53 51 4c 20 6f 77 6e 20 PostgreSQL own
2fb0: 63 6c 69 65 6e 74 20 6c 69 62 72 61 72 79 20 28 client library (
2fc0: 3c 62 3e 6c 69 62 70 71 3c 2f 62 3e 29 2e 3c 2f <b>libpq</b>).</
2fd0: 6c 69 3e 0d 0a 3c 6c 69 3e 49 6e 20 61 6e 79 20 li>..<li>In any
2fe0: 63 61 73 65 2c 20 69 66 20 79 6f 75 20 61 72 65 case, if you are
2ff0: 20 75 73 69 6e 67 20 73 6f 6d 65 20 69 6e 74 65 using some inte
3000: 72 61 63 74 69 76 65 20 74 6f 6f 6c 20 73 75 63 ractive tool suc
3010: 68 20 61 73 20 3c 62 3e 73 71 6c 69 74 65 33 3c h as <b>sqlite3<
3020: 2f 62 3e 20 6f 72 20 3c 62 3e 73 70 61 74 69 61 /b> or <b>spatia
3030: 6c 69 74 65 3c 2f 62 3e 20 73 6f 6d 65 20 75 73 lite</b> some us
3040: 65 66 75 6c 20 61 6e 64 20 6d 65 61 6e 69 6e 67 eful and meaning
3050: 66 75 6c 20 65 72 72 6f 72 20 6d 65 73 73 61 67 ful error messag
3060: 65 20 77 69 6c 6c 20 73 75 72 65 6c 79 20 62 65 e will surely be
3070: 20 64 69 73 70 6c 61 79 65 64 20 65 78 70 6c 61 displayed expla
3080: 69 6e 69 6e 67 20 74 68 65 20 66 61 69 6c 75 72 ining the failur
3090: 65 20 63 61 75 73 65 2e 3c 62 72 3e 0d 0a 54 68 e cause.<br>..Th
30a0: 69 73 20 63 6f 75 6c 64 20 6e 6f 74 20 62 65 20 is could not be
30b0: 73 75 70 70 6f 72 74 65 64 20 77 68 69 6c 65 20 supported while
30c0: 61 74 74 65 6d 70 74 69 6e 67 20 74 6f 20 6c 6f attempting to lo
30d0: 61 64 20 61 6e 20 65 78 74 65 6e 73 69 6f 6e 20 ad an extension
30e0: 66 72 6f 6d 20 73 6f 6d 65 20 6c 61 6e 67 75 61 from some langua
30f0: 67 65 20 62 69 6e 64 69 6e 67 20 28 65 2e 67 2e ge binding (e.g.
3100: 20 3c 62 3e 2e 4e 45 54 3c 2f 62 3e 2c 20 3c 62 <b>.NET</b>, <b
3110: 3e 50 79 74 68 6f 6e 3c 2f 62 3e 20 6f 72 20 3c >Python</b> or <
3120: 62 3e 4a 61 76 61 3c 2f 62 3e 29 2e 0d 0a 49 6e b>Java</b>)...In
3130: 20 74 68 69 73 20 63 61 73 65 20 61 74 74 65 6d this case attem
3140: 70 74 69 6e 67 20 74 6f 20 69 64 65 6e 74 69 66 pting to identif
3150: 79 20 74 68 65 20 72 65 61 6c 20 65 72 72 6f 72 y the real error
3160: 20 63 61 75 73 65 20 63 6f 75 6c 64 20 62 65 20 cause could be
3170: 72 65 61 6c 6c 79 20 70 61 69 6e 66 75 6c 20 64 really painful d
3180: 75 65 20 74 6f 20 70 6f 6f 72 20 61 6e 64 20 73 ue to poor and s
3190: 6c 6f 70 70 79 20 64 69 61 67 6e 6f 73 74 69 63 loppy diagnostic
31a0: 20 73 75 70 70 6f 72 74 2e 3c 2f 6c 69 3e 0d 0a support.</li>..
31b0: 3c 6c 69 3e 54 68 65 72 65 20 61 72 65 20 6e 6f <li>There are no
31c0: 20 75 6e 69 76 65 72 73 61 6c 20 72 75 6c 65 73 universal rules
31d0: 20 64 69 63 74 61 74 69 6e 67 20 77 68 65 72 65 dictating where
31e0: 20 74 6f 20 70 6c 61 63 65 20 79 6f 75 72 20 65 to place your e
31f0: 78 74 65 6e 73 69 6f 6e 20 6d 6f 64 75 6c 65 73 xtension modules
3200: 3b 20 61 20 67 6f 6f 64 20 73 75 67 67 65 73 74 ; a good suggest
3210: 69 6f 6e 20 69 73 20 74 6f 20 61 6c 77 61 79 73 ion is to always
3220: 20 70 6c 61 63 65 20 61 6c 6c 20 74 68 65 6d 20 place all them
3230: 69 6e 20 74 68 65 20 6d 6f 73 74 20 61 70 70 72 in the most appr
3240: 6f 70 72 69 61 74 65 20 73 79 73 74 65 6d 20 64 opriate system d
3250: 69 72 65 63 74 6f 72 79 2e 3c 2f 6c 69 3e 0d 0a irectory.</li>..
3260: 3c 2f 75 6c 3e 0d 0a 3c 62 3e 49 6d 70 6f 72 74 </ul>..<b>Import
3270: 61 6e 74 20 6e 6f 74 69 63 65 3c 2f 62 3e 3a 20 ant notice</b>:
3280: 73 74 61 72 74 69 6e 67 20 73 69 6e 63 65 20 76 starting since v
3290: 65 72 73 69 6f 6e 20 3c 62 3e 33 2e 37 2e 31 37 ersion <b>3.7.17
32a0: 3c 2f 62 3e 20 53 51 4c 69 74 65 20 69 6e 74 72 </b> SQLite intr
32b0: 6f 64 75 63 65 64 20 6d 61 6e 79 20 69 6e 74 65 oduced many inte
32c0: 72 65 73 74 69 6e 67 20 61 64 76 61 6e 63 65 64 resting advanced
32d0: 20 66 65 61 74 75 72 65 73 20 74 6f 20 3c 62 3e features to <b>
32e0: 6c 6f 61 64 5f 65 78 74 65 6e 73 69 6f 6e 28 29 load_extension()
32f0: 3c 2f 62 3e 3b 0d 0a 65 61 72 6c 69 65 72 20 76 </b>;..earlier v
3300: 65 72 73 69 6f 6e 73 20 6f 66 20 53 51 4c 69 74 ersions of SQLit
3310: 65 20 63 6f 75 6c 64 20 70 72 6f 62 61 62 6c 79 e could probably
3320: 20 62 65 20 73 6f 6d 65 77 61 79 20 6c 69 6d 69 be someway limi
3330: 74 65 64 2e 0d 0a 49 66 20 74 68 69 73 20 69 73 ted...If this is
3340: 20 79 6f 75 72 20 63 61 73 65 2c 20 70 6c 65 61 your case, plea
3350: 73 65 20 63 6f 6e 73 69 64 65 72 20 74 68 61 74 se consider that
3360: 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 73 70 65 :..<ul>..<li>spe
3370: 63 69 66 79 69 6e 67 20 61 6e 79 20 3c 62 3e 2e cifying any <b>.
3380: 64 6c 6c 3c 2f 62 3e 2c 20 3c 62 3e 2e 73 6f 3c dll</b>, <b>.so<
3390: 2f 62 3e 20 6f 72 20 3c 62 3e 2e 64 79 6c 69 62 /b> or <b>.dylib
33a0: 3c 2f 62 3e 20 73 75 66 66 69 78 20 63 6f 75 6c </b> suffix coul
33b0: 64 20 62 65 20 73 74 72 69 63 74 6c 79 20 72 65 d be strictly re
33c0: 71 75 69 72 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c quired.</li>..<l
33d0: 69 3e 61 73 20 69 74 20 63 6f 75 6c 64 20 62 65 i>as it could be
33e0: 20 72 65 71 75 69 72 65 64 20 74 6f 20 65 78 70 required to exp
33f0: 6c 69 63 69 74 6c 79 20 73 70 65 63 69 66 79 20 licitly specify
3400: 74 68 65 20 65 78 74 65 6e 73 69 6f 6e 20 65 6e the extension en
3410: 74 72 79 20 70 6f 69 6e 74 2e 3c 2f 6c 69 3e 0d try point.</li>.
3420: 0a 3c 6c 69 3e 61 63 63 6f 72 64 69 6e 67 6c 79 .<li>accordingly
3430: 20 74 6f 20 61 6c 6c 20 74 68 69 73 2c 20 79 6f to all this, yo
3440: 75 27 6c 6c 20 70 72 6f 62 61 62 6c 79 20 62 65 u'll probably be
3450: 20 72 65 71 75 69 72 65 64 20 74 6f 20 70 61 73 required to pas
3460: 73 20 61 72 67 75 6d 65 6e 74 73 20 6c 69 6b 65 s arguments like
3470: 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6f the following o
3480: 6e 65 73 20 74 6f 20 3c 62 3e 6c 6f 61 64 5f 65 nes to <b>load_e
3490: 78 74 65 6e 73 69 6f 6e 28 29 3c 2f 62 3e 20 77 xtension()</b> w
34a0: 68 69 6c 65 20 75 73 69 6e 67 20 73 6f 6d 65 20 hile using some
34b0: 6f 62 73 6f 6c 65 74 65 20 53 51 4c 69 74 65 33 obsolete SQLite3
34c0: 20 76 65 72 73 69 6f 6e 2e 3c 2f 6c 69 3e 0d 0a version.</li>..
34d0: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 <verbatim>..SELE
34e0: 43 54 20 6c 6f 61 64 5f 65 78 74 65 6e 73 69 6f CT load_extensio
34f0: 6e 28 27 2f 75 73 72 2f 6c 6f 63 61 6c 2f 6c 69 n('/usr/local/li
3500: 62 2f 6d 6f 64 5f 76 69 72 74 75 61 6c 70 67 2e b/mod_virtualpg.
3510: 73 6f 27 2c 20 27 73 71 6c 69 74 65 33 5f 76 69 so', 'sqlite3_vi
3520: 72 74 75 61 6c 70 67 5f 69 6e 69 74 27 29 3b 0d rtualpg_init');.
3530: 0a 2d 2d 2d 2d 2d 2d 0d 0a 4e 55 4c 4c 0d 0a 3c .------..NULL..<
3540: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 2f 75 6c /verbatim>..</ul
3550: 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c >..</td></tr>..<
3560: 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 3c 68 72 /table><br>..<hr
3570: 3e 0d 0a 3c 68 32 3e 55 73 69 6e 67 20 56 69 72 >..<h2>Using Vir
3580: 74 75 61 6c 50 47 3a 20 61 6e 20 53 51 4c 20 70 tualPG: an SQL p
3590: 65 72 73 70 65 63 74 69 76 65 3c 2f 68 32 3e 0d erspective</h2>.
35a0: 0a 3c 68 33 3e 43 72 65 61 74 69 6e 67 20 56 69 .<h3>Creating Vi
35b0: 72 74 75 61 6c 50 6f 73 74 67 72 65 73 20 74 61 rtualPostgres ta
35c0: 62 6c 65 73 3c 2f 68 33 3e 0d 0a 41 66 74 65 72 bles</h3>..After
35d0: 20 73 75 63 63 65 73 73 66 75 6c 6c 79 20 6c 6f successfully lo
35e0: 61 64 69 6e 67 20 74 68 65 20 3c 62 3e 76 69 72 ading the <b>vir
35f0: 74 75 61 6c 70 67 3c 2f 62 3e 20 64 79 6e 61 6d tualpg</b> dynam
3600: 69 63 20 65 78 74 65 6e 73 69 6f 6e 20 79 6f 75 ic extension you
3610: 20 61 72 65 20 6e 6f 77 20 72 65 61 64 79 20 74 are now ready t
3620: 6f 20 63 72 65 61 74 65 20 3c 62 3e 56 69 72 74 o create <b>Virt
3630: 75 61 6c 50 6f 73 74 67 65 73 3c 2f 62 3e 20 74 ualPostges</b> t
3640: 61 62 6c 65 73 2e 3c 62 72 3e 0d 0a 54 68 65 73 ables.<br>..Thes
3650: 65 20 61 72 65 20 3c 69 3e 71 75 69 74 65 20 61 e are <i>quite a
3660: 6c 6d 6f 73 74 3c 2f 69 3e 20 6f 72 64 69 6e 61 lmost</i> ordina
3670: 72 79 20 44 42 20 74 61 62 6c 65 73 20 61 73 20 ry DB tables as
3680: 61 6e 79 20 6f 74 68 65 72 3b 20 79 6f 75 20 63 any other; you c
3690: 61 6e 20 65 78 65 63 75 74 65 20 61 6e 79 20 72 an execute any r
36a0: 65 67 75 6c 61 72 20 53 51 4c 20 73 74 61 74 65 egular SQL state
36b0: 6d 65 6e 74 20 28 3c 69 3e 53 45 4c 45 43 54 3c ment (<i>SELECT<
36c0: 2f 69 3e 2c 20 3c 69 3e 49 4e 53 45 52 54 3c 2f /i>, <i>INSERT</
36d0: 69 3e 2c 20 3c 69 3e 55 50 44 41 54 45 3c 2f 69 i>, <i>UPDATE</i
36e0: 3e 20 6f 72 20 3c 69 3e 44 45 4c 45 54 45 3c 2f > or <i>DELETE</
36f0: 69 3e 29 20 62 79 20 73 70 65 63 69 66 79 69 6e i>) by specifyin
3700: 67 20 74 68 65 73 65 20 56 69 72 74 75 61 6c 20 g these Virtual
3710: 54 61 62 6c 65 73 20 61 73 20 74 68 65 20 73 65 Tables as the se
3720: 6c 65 63 74 65 64 20 74 61 72 67 65 74 2e 3c 62 lected target.<b
3730: 72 3e 0d 0a 54 68 65 72 65 20 69 73 20 6f 6e 6c r>..There is onl
3740: 79 20 61 20 73 74 72 6f 6e 67 20 64 69 66 66 65 y a strong diffe
3750: 72 65 6e 63 65 20 64 69 73 74 69 6e 67 75 69 73 rence distinguis
3760: 68 69 6e 67 20 61 20 3c 62 3e 56 69 72 74 75 61 hing a <b>Virtua
3770: 6c 50 6f 73 74 67 72 65 73 3c 2f 62 3e 20 74 61 lPostgres</b> ta
3780: 62 6c 65 3b 20 69 74 27 73 20 70 68 79 73 69 63 ble; it's physic
3790: 61 6c 20 6c 6f 63 61 74 69 6f 6e 20 69 73 6e 27 al location isn'
37a0: 74 20 77 69 74 68 69 6e 20 74 68 65 20 63 75 72 t within the cur
37b0: 72 65 6e 74 6c 79 20 63 6f 6e 6e 65 63 74 65 64 rently connected
37c0: 20 53 51 4c 69 74 65 20 44 42 2c 20 62 75 74 20 SQLite DB, but
37d0: 69 73 20 69 6e 73 74 65 61 64 20 77 69 74 68 69 is instead withi
37e0: 6e 20 73 6f 6d 65 20 3c 62 3e 50 6f 73 74 67 72 n some <b>Postgr
37f0: 65 53 51 4c 3c 2f 62 3e 20 44 42 4d 53 2e 3c 62 eSQL</b> DBMS.<b
3800: 72 3e 0d 0a 53 6f 20 61 20 56 69 72 74 75 61 6c r>..So a Virtual
3810: 50 6f 73 74 67 72 65 73 20 74 61 62 6c 65 20 65 Postgres table e
3820: 66 66 65 63 74 69 76 65 6c 79 20 61 63 74 73 20 ffectively acts
3830: 61 73 20 61 20 3c 69 3e 62 72 69 64 67 65 3c 2f as a <i>bridge</
3840: 69 3e 20 6a 6f 69 6e 69 6e 67 20 53 51 4c 69 74 i> joining SQLit
3850: 65 20 61 6e 64 20 50 6f 73 74 67 72 65 73 2c 20 e and Postgres,
3860: 61 6e 64 20 61 6c 6c 6f 77 69 6e 67 20 74 6f 20 and allowing to
3870: 70 65 72 66 6f 72 6d 20 61 6e 79 20 6b 69 6e 64 perform any kind
3880: 20 6f 66 20 63 72 6f 73 73 20 64 61 74 61 20 65 of cross data e
3890: 78 63 68 61 6e 67 65 20 28 3c 69 3e 69 6e 20 62 xchange (<i>in b
38a0: 6f 74 68 20 64 69 72 65 63 74 69 6f 6e 73 3c 2f oth directions</
38b0: 69 3e 29 20 69 6e 20 74 68 65 20 65 61 73 69 65 i>) in the easie
38c0: 73 74 20 77 61 79 2e 0d 0a 3c 76 65 72 62 61 74 st way...<verbat
38d0: 69 6d 3e 0d 0a 43 52 45 41 54 45 20 56 49 52 54 im>..CREATE VIRT
38e0: 55 41 4c 20 54 41 42 4c 45 20 70 67 5f 69 6e 20 UAL TABLE pg_in
38f0: 0d 0a 20 20 20 20 55 53 49 4e 47 20 56 69 72 74 .. USING Virt
3900: 75 61 6c 50 6f 73 74 67 72 65 73 20 28 27 68 6f ualPostgres ('ho
3910: 73 74 3d 6c 6f 63 61 6c 68 6f 73 74 20 70 6f 72 st=localhost por
3920: 74 3d 35 34 33 32 20 64 62 6e 61 6d 65 3d 67 69 t=5432 dbname=gi
3930: 73 20 75 73 65 72 3d 73 61 6e 64 72 6f 20 70 61 s user=sandro pa
3940: 73 73 77 6f 72 64 3d 73 65 63 72 65 74 27 2c 20 ssword=secret',
3950: 6d 79 5f 73 63 68 65 6d 61 2c 20 6d 79 5f 74 61 my_schema, my_ta
3960: 62 6c 65 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 ble);..</verbati
3970: 6d 3e 0d 0a 54 68 69 73 20 53 51 4c 20 73 74 61 m>..This SQL sta
3980: 74 65 6d 65 6e 74 20 77 69 6c 6c 20 63 72 65 61 tement will crea
3990: 74 65 20 69 6e 74 6f 20 74 68 65 20 53 51 4c 69 te into the SQLi
39a0: 74 65 20 44 42 20 61 20 74 61 62 6c 65 20 6e 61 te DB a table na
39b0: 6d 65 64 20 3c 62 3e 70 67 5f 69 6e 3c 2f 62 3e med <b>pg_in</b>
39c0: 20 77 72 61 70 70 69 6e 67 20 74 68 65 20 50 6f wrapping the Po
39d0: 73 74 67 72 65 53 51 4c 20 74 61 62 6c 65 20 6e stgreSQL table n
39e0: 61 6d 65 64 20 3c 62 3e 6d 79 5f 73 63 68 65 6d amed <b>my_schem
39f0: 61 3c 2f 62 3e 2e 3c 62 3e 6d 79 5f 74 61 62 6c a</b>.<b>my_tabl
3a00: 65 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a 44 61 74 61 e</b>.<br>..Data
3a10: 20 66 6f 72 20 74 68 69 73 20 74 61 62 6c 65 20 for this table
3a20: 77 69 6c 6c 20 63 6f 6e 74 69 6e 75 65 20 74 6f will continue to
3a30: 20 62 65 20 73 74 6f 72 65 64 20 77 69 74 68 69 be stored withi
3a40: 6e 20 74 68 65 20 50 6f 73 74 67 72 65 73 20 6f n the Postgres o
3a50: 77 6e 20 64 61 74 61 20 73 70 61 63 65 2c 20 62 wn data space, b
3a60: 75 74 20 77 69 6c 6c 20 62 65 20 6e 6f 77 20 61 ut will be now a
3a70: 63 63 65 73 73 69 62 6c 65 20 66 6f 72 20 53 51 ccessible for SQ
3a80: 4c 69 74 65 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 Lite:..<ul>..<li
3a90: 3e 74 68 65 20 66 69 72 73 74 20 61 72 67 75 6d >the first argum
3aa0: 65 6e 74 20 74 6f 20 56 69 72 74 75 61 6c 50 6f ent to VirtualPo
3ab0: 73 74 67 72 65 73 20 69 73 20 74 68 65 20 3c 69 stgres is the <i
3ac0: 3e 63 6f 6e 6e 65 63 74 69 6f 6e 20 73 74 72 69 >connection stri
3ad0: 6e 67 3c 2f 69 3e 20 72 65 71 75 69 72 65 64 20 ng</i> required
3ae0: 69 6e 20 6f 72 64 65 72 20 74 6f 20 65 73 74 61 in order to esta
3af0: 62 6c 69 73 68 20 61 20 63 6f 6e 6e 65 63 74 69 blish a connecti
3b00: 6f 6e 20 74 6f 20 74 68 65 20 50 6f 73 74 67 72 on to the Postgr
3b10: 65 73 20 44 42 4d 53 20 73 65 72 76 65 72 2e 3c es DBMS server.<
3b20: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 73 65 63 6f 6e 64 /li>..<li>second
3b30: 20 61 6e 64 20 74 68 69 72 64 20 61 72 67 75 6d and third argum
3b40: 65 6e 74 73 20 72 65 73 70 65 63 74 69 76 65 6c ents respectivel
3b50: 79 20 61 72 65 20 74 68 65 20 3c 69 3e 73 63 68 y are the <i>sch
3b60: 65 6d 61 20 6e 61 6d 65 3c 2f 69 3e 20 61 6e 64 ema name</i> and
3b70: 20 74 68 65 20 3c 69 3e 74 61 62 6c 65 20 6e 61 the <i>table na
3b80: 6d 65 3c 2f 69 3e 20 69 64 65 6e 74 69 66 79 69 me</i> identifyi
3b90: 6e 67 20 74 68 65 20 50 6f 73 74 67 72 65 73 20 ng the Postgres
3ba0: 74 61 72 67 65 74 20 74 61 62 6c 65 2e 3c 2f 6c target table.</l
3bb0: 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 76 65 72 62 i>..</ul>..<verb
3bc0: 61 74 69 6d 3e 0d 0a 43 52 45 41 54 45 20 56 49 atim>..CREATE VI
3bd0: 52 54 55 41 4c 20 54 41 42 4c 45 20 70 67 5f 69 RTUAL TABLE pg_i
3be0: 6e 20 0d 0a 20 20 20 20 55 53 49 4e 47 20 56 69 n .. USING Vi
3bf0: 72 74 75 61 6c 50 6f 73 74 67 72 65 73 20 28 27 rtualPostgres ('
3c00: 68 6f 73 74 61 64 64 72 3d 31 39 32 2e 31 36 38 hostaddr=192.168
3c10: 2e 31 2e 39 31 20 70 6f 72 74 3d 35 34 33 32 20 .1.91 port=5432
3c20: 64 62 6e 61 6d 65 3d 67 69 73 20 75 73 65 72 3d dbname=gis user=
3c30: 73 61 6e 64 72 6f 20 70 61 73 73 77 6f 72 64 3d sandro password=
3c40: 73 65 63 72 65 74 27 2c 20 6d 79 5f 73 63 68 65 secret', my_sche
3c50: 6d 61 2c 20 6d 79 5f 74 61 62 6c 65 29 3b 0d 0a ma, my_table);..
3c60: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 53 61 6d </verbatim>..Sam
3c70: 65 20 61 73 20 61 62 6f 76 65 2c 20 74 68 69 73 e as above, this
3c80: 20 74 69 6d 65 20 65 73 74 61 62 6c 69 73 68 69 time establishi
3c90: 6e 67 20 61 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 ng a connection
3ca0: 74 6f 20 61 20 50 6f 73 74 67 72 65 73 20 69 6e to a Postgres in
3cb0: 73 74 61 6e 63 65 20 72 75 6e 6e 69 6e 67 20 6f stance running o
3cc0: 6e 20 73 6f 6d 65 20 64 69 66 66 65 72 65 6e 74 n some different
3cd0: 20 63 6f 6d 70 75 74 65 72 20 6f 6e 20 74 68 65 computer on the
3ce0: 20 73 61 6d 65 20 6c 6f 63 61 6c 20 61 72 65 61 same local area
3cf0: 20 6e 65 74 77 6f 72 6b 2e 3c 62 72 3e 0d 0a 3c network.<br>..<
3d00: 76 65 72 62 61 74 69 6d 3e 0d 0a 43 52 45 41 54 verbatim>..CREAT
3d10: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 E VIRTUAL TABLE
3d20: 70 67 5f 69 6e 20 0d 0a 20 20 20 20 55 53 49 4e pg_in .. USIN
3d30: 47 20 56 69 72 74 75 61 6c 50 6f 73 74 67 72 65 G VirtualPostgre
3d40: 73 20 28 27 68 6f 73 74 3d 77 77 77 2e 68 75 6d s ('host=www.hum
3d50: 70 74 79 64 75 6d 70 74 79 2e 63 6f 6d 20 70 6f ptydumpty.com po
3d60: 72 74 3d 35 34 33 32 20 64 62 6e 61 6d 65 3d 67 rt=5432 dbname=g
3d70: 69 73 20 75 73 65 72 3d 73 61 6e 64 72 6f 20 70 is user=sandro p
3d80: 61 73 73 77 6f 72 64 3d 73 65 63 72 65 74 27 2c assword=secret',
3d90: 20 6d 79 5f 73 63 68 65 6d 61 2c 20 6d 79 5f 74 my_schema, my_t
3da0: 61 62 6c 65 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 able);..</verbat
3db0: 69 6d 3e 0d 0a 49 6e 20 74 68 69 73 20 74 68 69 im>..In this thi
3dc0: 72 64 20 76 61 72 69 61 74 69 6f 6e 20 77 65 27 rd variation we'
3dd0: 6c 6c 20 63 6f 6e 6e 65 63 74 20 74 6f 20 61 20 ll connect to a
3de0: 50 6f 73 74 67 72 65 73 20 69 6e 73 74 61 6e 63 Postgres instanc
3df0: 65 20 72 75 6e 6e 69 6e 67 20 6f 6e 20 73 6f 6d e running on som
3e00: 65 20 72 65 6d 6f 74 65 20 73 65 72 76 65 72 20 e remote server
3e10: 61 63 63 65 73 73 65 64 20 74 68 6f 75 67 68 20 accessed though
3e20: 61 20 77 69 64 65 20 61 72 65 61 20 6e 65 74 77 a wide area netw
3e30: 6f 72 6b 2e 3c 62 72 3e 0d 0a 50 6c 65 61 73 65 ork.<br>..Please
3e40: 20 63 6f 6e 73 75 6c 74 20 74 68 65 20 50 6f 73 consult the Pos
3e50: 74 67 72 65 73 20 6f 77 6e 20 64 6f 63 75 6d 65 tgres own docume
3e60: 6e 74 61 74 69 6f 6e 20 66 6f 72 20 61 6e 79 20 ntation for any
3e70: 6f 74 68 65 72 20 64 65 74 61 69 6c 20 61 62 6f other detail abo
3e80: 75 74 20 3c 69 3e 63 6f 6e 6e 65 63 74 69 6f 6e ut <i>connection
3e90: 20 73 74 72 69 6e 67 73 3c 2f 69 3e 2e 0d 0a 3c strings</i>...<
3ea0: 68 33 3e 43 72 65 61 74 69 6e 67 20 56 69 72 74 h3>Creating Virt
3eb0: 75 61 6c 50 6f 73 74 67 72 65 73 20 74 61 62 6c ualPostgres tabl
3ec0: 65 73 3a 20 66 75 6c 6c 20 73 79 6e 74 61 78 20 es: full syntax
3ed0: 65 78 70 6c 61 69 6e 65 64 3c 2f 68 33 3e 0d 0a explained</h3>..
3ee0: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 43 52 45 41 <verbatim>..CREA
3ef0: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 TE VIRTUAL TABLE
3f00: 20 73 6f 6d 65 6e 61 6d 65 20 55 53 49 4e 47 20 somename USING
3f10: 56 69 72 74 75 61 6c 50 6f 73 74 67 72 65 73 20 VirtualPostgres
3f20: 7b 63 6f 6e 6e 5f 69 6e 66 6f 2c 20 73 63 68 65 {conn_info, sche
3f30: 6d 61 2c 20 74 61 62 6c 65 20 5b 20 2c 20 72 65 ma, table [ , re
3f40: 61 64 5f 77 72 69 74 65 5f 66 6c 61 67 20 5b 20 ad_write_flag [
3f50: 2c 20 6a 75 6c 69 61 6e 5f 66 6c 61 67 20 5d 5d , julian_flag ]]
3f60: 20 7d 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e };..</verbatim>
3f70: 0d 0a 53 75 70 70 6f 72 74 65 64 20 61 72 67 75 ..Supported argu
3f80: 6d 65 6e 74 73 3a 0d 0a 3c 6f 6c 3e 0d 0a 3c 6c ments:..<ol>..<l
3f90: 69 3e 3c 69 3e 6d 61 6e 64 61 74 6f 72 79 3c 2f i><i>mandatory</
3fa0: 69 3e 3a 20 3c 62 3e 63 6f 6e 6e 5f 69 6e 66 6f i>: <b>conn_info
3fb0: 3c 2f 62 3e 20 28 3c 69 3e 54 65 78 74 20 53 74 </b> (<i>Text St
3fc0: 72 69 6e 67 3c 2f 69 3e 29 3c 62 72 3e 0d 0a 61 ring</i>)<br>..a
3fd0: 6e 79 20 76 61 6c 69 64 20 63 6f 6e 6e 65 63 74 ny valid connect
3fe0: 69 6f 6e 20 73 74 72 69 6e 67 20 61 63 63 65 70 ion string accep
3ff0: 74 65 64 20 62 79 20 50 6f 73 74 67 72 65 53 51 ted by PostgreSQ
4000: 4c 2e 20 46 6f 72 20 66 75 72 74 68 65 72 20 64 L. For further d
4010: 65 74 61 69 6c 73 20 70 6c 65 61 73 65 20 63 6f etails please co
4020: 6e 73 75 6c 74 20 74 68 65 20 3c 61 20 68 72 65 nsult the <a hre
4030: 66 3d 22 22 3e 50 6f 73 74 67 72 65 53 51 4c 20 f="">PostgreSQL
4040: 6f 77 6e 3c 2f 61 3e 20 64 6f 63 75 6d 65 6e 74 own</a> document
4050: 61 74 69 6f 6e 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 ation.</li>..<li
4060: 3e 3c 69 3e 6d 61 6e 64 61 74 6f 72 79 3c 2f 69 ><i>mandatory</i
4070: 3e 3a 20 3c 62 3e 73 63 68 65 6d 61 3c 2f 62 3e >: <b>schema</b>
4080: 20 28 3c 69 3e 54 65 78 74 20 53 74 72 69 6e 67 (<i>Text String
4090: 3c 2f 69 3e 29 3c 62 72 3e 0d 0a 6e 61 6d 65 20 </i>)<br>..name
40a0: 6f 66 20 74 68 65 20 50 6f 73 67 72 65 53 51 4c of the PosgreSQL
40b0: 20 53 63 68 65 6d 61 20 63 6f 6e 74 61 69 6e 69 Schema containi
40c0: 6e 67 20 74 68 65 20 54 61 62 6c 65 20 74 6f 20 ng the Table to
40d0: 62 65 20 77 72 61 70 70 65 64 2e 3c 2f 6c 69 3e be wrapped.</li>
40e0: 0d 0a 3c 6c 69 3e 3c 69 3e 6d 61 6e 64 61 74 6f ..<li><i>mandato
40f0: 72 79 3c 2f 69 3e 3a 20 3c 62 3e 74 61 62 6c 65 ry</i>: <b>table
4100: 3c 2f 62 3e 20 28 3c 69 3e 54 65 78 74 20 53 74 </b> (<i>Text St
4110: 72 69 6e 67 3c 2f 69 3e 29 3c 62 72 3e 0d 0a 6e ring</i>)<br>..n
4120: 61 6d 65 20 6f 66 20 74 68 65 20 50 6f 73 67 72 ame of the Posgr
4130: 65 53 51 4c 20 54 61 62 6c 65 20 28 6f 72 20 56 eSQL Table (or V
4140: 69 65 77 29 20 74 6f 20 62 65 20 77 72 61 70 70 iew) to be wrapp
4150: 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 69 ed.</li>..<li><i
4160: 3e 6f 70 74 69 6f 6e 61 6c 3c 2f 69 3e 3a 20 3c >optional</i>: <
4170: 62 3e 72 65 61 64 5f 77 72 69 74 65 5f 66 6c 61 b>read_write_fla
4180: 67 3c 2f 62 3e 20 28 3c 69 3e 54 65 78 74 20 53 g</b> (<i>Text S
4190: 74 72 69 6e 67 3c 2f 69 3e 29 3a 0d 0a 3c 75 6c tring</i>):..<ul
41a0: 3e 0d 0a 3c 6c 69 3e 3c 62 3e 57 3c 2f 62 3e 3a >..<li><b>W</b>:
41b0: 20 74 68 65 20 54 61 62 6c 65 20 77 69 6c 6c 20 the Table will
41c0: 73 75 70 70 6f 72 74 20 62 6f 74 68 20 72 65 61 support both rea
41d0: 64 20 61 6e 64 20 77 72 69 74 65 20 6f 70 65 72 d and write oper
41e0: 61 74 69 6f 6e 73 2c 20 65 6e 61 62 6c 69 6e 67 ations, enabling
41f0: 20 53 45 4c 45 43 54 20 2f 20 49 4e 53 45 52 54 SELECT / INSERT
4200: 20 2f 20 55 50 44 41 54 45 20 2f 20 44 45 4c 45 / UPDATE / DELE
4210: 54 45 20 73 74 61 74 65 6d 65 6e 74 73 2e 3c 2f TE statements.</
4220: 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 2d 3c 2f 62 li>..<li><b>-</b
4230: 3e 3a 20 74 68 65 20 54 61 62 6c 65 20 77 69 6c >: the Table wil
4240: 6c 20 6a 75 73 74 20 73 75 70 70 6f 72 74 20 72 l just support r
4250: 65 61 64 20 6f 70 65 72 61 74 69 6f 6e 73 3a 20 ead operations:
4260: 53 45 4c 45 43 54 20 73 74 61 74 65 6d 65 6e 74 SELECT statement
4270: 73 20 77 69 6c 6c 20 62 65 20 65 6e 61 62 6c 65 s will be enable
4280: 64 2c 20 62 75 74 20 49 4e 53 45 52 54 20 2f 20 d, but INSERT /
4290: 55 50 44 41 54 45 20 2f 20 44 45 4c 45 54 45 20 UPDATE / DELETE
42a0: 77 69 6c 6c 20 62 65 20 64 69 73 61 62 6c 65 64 will be disabled
42b0: 2e 3c 62 72 3e 0d 0a 3c 62 3e 4e 6f 74 65 3c 2f .<br>..<b>Note</
42c0: 62 3e 3a 20 74 68 69 73 20 69 73 20 74 68 65 20 b>: this is the
42d0: 64 65 66 61 75 6c 74 20 73 65 74 74 69 6e 67 2e default setting.
42e0: 20 56 69 72 74 75 61 6c 50 47 20 61 6c 77 61 79 VirtualPG alway
42f0: 73 20 72 65 71 75 69 72 65 73 20 61 6e 20 65 78 s requires an ex
4300: 70 6c 69 63 69 74 20 61 75 74 68 6f 72 69 7a 61 plicit authoriza
4310: 74 69 6f 6e 20 69 6e 20 6f 72 64 65 72 20 74 6f tion in order to
4320: 20 65 6e 61 62 6c 65 20 77 72 69 74 65 20 6f 70 enable write op
4330: 65 72 61 74 69 6f 6e 73 2e 3c 2f 6c 69 3e 20 0d erations.</li> .
4340: 0a 3c 2f 75 6c 3e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 .</ul></li>..<li
4350: 3e 3c 69 3e 6f 70 74 69 6f 6e 61 6c 3c 2f 69 3e ><i>optional</i>
4360: 3a 20 3c 62 3e 6a 75 6c 69 61 6e 5f 66 6c 61 67 : <b>julian_flag
4370: 3c 2f 62 3e 20 28 3c 69 3e 54 65 78 74 20 53 74 </b> (<i>Text St
4380: 72 69 6e 67 3c 2f 69 3e 29 3a 0d 0a 3c 75 6c 3e ring</i>):..<ul>
4390: 0d 0a 3c 6c 69 3e 3c 62 3e 4a 3c 2f 62 3e 3a 20 ..<li><b>J</b>:
43a0: 44 41 54 45 20 2f 20 54 49 4d 45 20 2f 20 54 49 DATE / TIME / TI
43b0: 4d 45 53 54 41 4d 50 20 76 61 6c 75 65 73 20 77 MESTAMP values w
43c0: 69 6c 6c 20 62 65 20 74 72 61 6e 73 6c 61 74 65 ill be translate
43d0: 64 20 69 6e 74 6f 20 74 68 65 20 63 6f 72 72 65 d into the corre
43e0: 73 70 6f 6e 64 69 6e 67 20 3c 61 20 68 72 65 66 sponding <a href
43f0: 3d 22 68 74 74 70 73 3a 2f 2f 65 6e 2e 77 69 6b ="https://en.wik
4400: 69 70 65 64 69 61 2e 6f 72 67 2f 77 69 6b 69 2f ipedia.org/wiki/
4410: 4a 75 6c 69 61 6e 5f 64 61 79 22 3e 4a 75 6c 69 Julian_day">Juli
4420: 61 6e 20 44 61 79 20 4e 75 6d 62 65 72 73 3c 2f an Day Numbers</
4430: 61 3e 20 28 46 4c 4f 41 54 20 76 61 6c 75 65 73 a> (FLOAT values
4440: 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e ).</li>..<li><b>
4450: 2d 3c 2f 62 3e 3a 20 44 41 54 45 20 2f 20 54 49 -</b>: DATE / TI
4460: 4d 45 20 2f 20 54 49 4d 45 53 54 41 4d 50 20 76 ME / TIMESTAMP v
4470: 61 6c 75 65 73 20 77 69 6c 6c 20 62 65 20 74 72 alues will be tr
4480: 61 6e 73 6c 61 74 65 64 20 69 6e 74 6f 20 74 68 anslated into th
4490: 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 e corresponding
44a0: 73 74 61 6e 64 61 72 64 20 53 51 4c 20 54 65 78 standard SQL Tex
44b0: 74 20 53 74 72 69 6e 67 73 2e 2e 3c 62 72 3e 0d t Strings..<br>.
44c0: 0a 3c 62 3e 4e 6f 74 65 3c 2f 62 3e 3a 20 74 68 .<b>Note</b>: th
44d0: 69 73 20 69 73 20 74 68 65 20 64 65 66 61 75 6c is is the defaul
44e0: 74 20 73 65 74 74 69 6e 67 2e 20 56 69 72 74 75 t setting. Virtu
44f0: 61 6c 50 47 20 61 6c 77 61 79 73 20 72 65 71 75 alPG always requ
4500: 69 72 65 73 20 61 6e 20 65 78 70 6c 69 63 69 74 ires an explicit
4510: 20 61 75 74 68 6f 72 69 7a 61 74 69 6f 6e 20 69 authorization i
4520: 6e 20 6f 72 64 65 72 20 74 6f 20 65 6e 61 62 6c n order to enabl
4530: 65 20 4a 75 6c 69 61 6e 20 44 61 79 73 2e 3c 2f e Julian Days.</
4540: 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 2f 6c 69 3e 0d li>..</ul></li>.
4550: 0a 3c 2f 6f 6c 3e 3c 62 72 3e 3c 62 72 3e 0d 0a .</ol><br><br>..
4560: 3c 74 61 62 6c 65 20 63 65 6c 6c 73 70 61 63 69 <table cellspaci
4570: 6e 67 3d 22 36 22 20 63 65 6c 6c 70 61 64 64 69 ng="6" cellpaddi
4580: 6e 67 3d 22 36 22 20 62 67 63 6f 6c 6f 72 3d 22 ng="6" bgcolor="
4590: 23 66 66 66 66 65 38 22 20 77 69 64 74 68 3d 22 #ffffe8" width="
45a0: 31 30 30 25 22 3e 0d 0a 3c 74 72 3e 3c 74 64 20 100%">..<tr><td
45b0: 61 6c 69 67 6e 3d 22 63 65 6e 74 65 72 22 3e 3c align="center"><
45c0: 62 3e 55 73 65 66 75 6c 20 68 69 6e 74 73 3a 20 b>Useful hints:
45d0: 63 6f 6e 6e 65 63 74 69 6e 67 20 74 6f 20 72 65 connecting to re
45e0: 6d 6f 74 65 20 50 6f 73 74 67 72 65 53 51 4c 20 mote PostgreSQL
45f0: 69 73 74 61 6e 63 65 73 20 76 69 61 20 50 6f 72 istances via Por
4600: 74 20 46 6f 72 77 61 72 64 69 6e 67 20 2f 20 53 t Forwarding / S
4610: 53 48 20 54 75 6e 6e 65 6c 69 6e 67 3c 2f 62 3e SH Tunneling</b>
4620: 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e </td></tr>..<tr>
4630: 3c 74 64 3e 3c 68 72 3e 3c 2f 74 64 3e 3c 2f 74 <td><hr></td></t
4640: 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 0d 0a 57 68 r>..<tr><td>..Wh
4650: 65 6e 65 76 65 72 20 79 6f 75 20 72 65 71 75 69 enever you requi
4660: 72 65 20 74 6f 20 63 6f 6e 6e 65 63 74 20 73 6f re to connect so
4670: 6d 65 20 72 65 6d 6f 74 65 20 50 6f 73 74 67 72 me remote Postgr
4680: 65 53 51 4c 20 69 73 74 61 6e 63 65 20 28 69 2e eSQL istance (i.
4690: 65 2e 20 6f 6e 65 20 61 63 74 75 61 6c 6c 79 20 e. one actually
46a0: 72 75 6e 6e 69 6e 67 20 6f 6e 20 73 6f 6d 65 20 running on some
46b0: 72 65 6d 6f 74 65 20 73 65 72 76 65 72 20 72 65 remote server re
46c0: 71 75 69 72 69 6e 67 20 74 6f 20 65 73 74 61 62 quiring to estab
46d0: 6c 69 73 68 20 61 20 3c 62 3e 4c 41 4e 3c 2f 62 lish a <b>LAN</b
46e0: 3e 20 6f 72 20 3c 62 3e 57 41 4e 3c 2f 62 3e 20 > or <b>WAN</b>
46f0: 63 6f 6e 6e 65 63 74 69 6f 6e 29 20 79 6f 75 20 connection) you
4700: 73 68 6f 75 6c 64 20 61 6c 77 61 79 73 20 73 65 should always se
4710: 72 69 6f 75 73 6c 79 20 63 6f 6e 73 69 64 65 72 riously consider
4720: 20 75 73 69 6e 67 20 3c 62 3e 53 53 48 20 54 75 using <b>SSH Tu
4730: 6e 6e 65 6c 69 6e 67 3c 2f 62 3e 20 2f 20 3c 62 nneling</b> / <b
4740: 3e 50 6f 72 74 20 46 6f 72 77 61 72 64 69 6e 67 >Port Forwarding
4750: 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a 54 68 69 73 20 </b>.<br>..This
4760: 63 6f 75 6c 64 20 67 72 65 61 74 6c 79 20 73 69 could greatly si
4770: 6d 70 6c 69 66 79 20 79 6f 75 72 20 61 70 70 72 mplify your appr
4780: 6f 61 63 68 2c 20 65 6e 73 75 72 69 6e 67 20 61 oach, ensuring a
4790: 74 20 74 68 65 20 73 61 6d 65 20 74 69 6d 65 20 t the same time
47a0: 61 6e 20 75 6e 63 6f 6d 70 72 6f 6d 69 73 65 64 an uncompromised
47b0: 20 73 61 66 65 74 79 2e 3c 62 72 3e 3c 62 72 3e safety.<br><br>
47c0: 0d 0a 50 6c 65 61 73 65 20 72 65 61 64 20 3c 61 ..Please read <a
47d0: 20 68 72 65 66 3d 22 68 74 74 70 73 3a 2f 2f 77 href="https://w
47e0: 77 77 2e 67 61 69 61 2d 67 69 73 2e 69 74 2f 66 ww.gaia-gis.it/f
47f0: 6f 73 73 69 6c 2f 76 69 72 74 75 61 6c 70 67 2f ossil/virtualpg/
4800: 77 69 6b 69 3f 6e 61 6d 65 3d 70 6f 72 74 2d 66 wiki?name=port-f
4810: 6f 72 77 61 72 64 69 6e 67 22 3e 74 68 69 73 20 orwarding">this
4820: 57 69 6b 69 20 70 61 67 65 3c 2f 61 3e 20 66 6f Wiki page</a> fo
4830: 72 20 6d 6f 72 65 20 73 70 65 63 69 66 69 63 20 r more specific
4840: 64 65 74 61 69 6c 73 20 61 62 6f 75 74 20 53 53 details about SS
4850: 48 20 54 75 6e 6e 65 6c 69 6e 67 20 61 6e 64 20 H Tunneling and
4860: 50 6f 72 74 20 46 6f 72 77 61 72 64 69 6e 67 2e Port Forwarding.
4870: 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 ..</td></tr></ta
4880: 62 6c 65 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a ble><br>..<hr>..
4890: 3c 68 33 3e 42 61 73 69 63 20 53 51 4c 20 6f 70 <h3>Basic SQL op
48a0: 65 72 61 74 69 6f 6e 73 3c 2f 68 33 3e 0d 0a 3c erations</h3>..<
48b0: 76 65 72 62 61 74 69 6d 3e 0d 0a 50 52 41 47 4d verbatim>..PRAGM
48c0: 41 20 74 61 62 6c 65 5f 69 6e 66 6f 28 70 67 5f A table_info(pg_
48d0: 69 6e 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d in);..</verbatim
48e0: 3e 0d 0a 59 6f 75 20 63 61 6e 20 65 78 65 63 75 >..You can execu
48f0: 74 65 20 74 68 65 20 61 62 6f 76 65 20 50 52 41 te the above PRA
4900: 47 4d 41 20 64 69 72 65 63 74 69 76 65 20 69 6e GMA directive in
4910: 20 6f 72 64 65 72 20 74 6f 20 69 64 65 6e 74 69 order to identi
4920: 66 79 20 61 6c 6c 20 63 6f 6c 75 6d 6e 73 20 64 fy all columns d
4930: 65 63 6c 61 72 65 64 20 62 79 20 74 68 65 20 50 eclared by the P
4940: 6f 73 74 67 72 65 73 20 74 61 62 6c 65 2c 20 61 ostgres table, a
4950: 6e 64 20 74 68 65 69 72 20 63 6f 72 72 65 73 70 nd their corresp
4960: 6f 6e 64 69 6e 67 20 64 61 74 61 2d 74 79 70 65 onding data-type
4970: 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 ...<verbatim>..S
4980: 45 4c 45 43 54 20 61 2c 20 62 2c 20 63 2c 20 43 ELECT a, b, c, C
4990: 6f 75 6e 74 28 2a 29 20 41 53 20 63 6e 74 0d 0a ount(*) AS cnt..
49a0: 46 52 4f 4d 20 70 67 5f 69 6e 0d 0a 57 48 45 52 FROM pg_in..WHER
49b0: 45 20 65 20 49 53 20 4e 4f 54 20 4e 55 4c 4c 0d E e IS NOT NULL.
49c0: 0a 47 52 4f 55 50 20 42 59 20 61 2c 20 62 2c 20 .GROUP BY a, b,
49d0: 63 0d 0a 4f 52 44 45 52 20 42 59 20 63 6e 74 20 c..ORDER BY cnt
49e0: 44 45 53 43 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 DESC;..</verbati
49f0: 6d 3e 0d 0a 59 6f 75 20 63 61 6e 20 65 78 65 63 m>..You can exec
4a00: 75 74 65 20 61 6e 79 20 6b 69 6e 64 20 6f 66 20 ute any kind of
4a10: 3c 62 3e 53 45 4c 45 43 54 3c 2f 62 3e 20 71 75 <b>SELECT</b> qu
4a20: 65 72 79 20 75 73 69 6e 67 20 61 20 56 69 72 74 ery using a Virt
4a30: 75 61 6c 50 6f 73 74 67 72 65 73 20 74 61 62 6c ualPostgres tabl
4a40: 65 2c 20 65 78 61 63 74 6c 79 20 61 73 20 69 66 e, exactly as if
4a50: 20 69 74 20 77 61 73 20 61 20 67 65 6e 75 69 6e it was a genuin
4a60: 65 20 6e 61 74 69 76 65 20 74 61 62 6c 65 2e 0d e native table..
4a70: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 43 52 45 .<verbatim>..CRE
4a80: 41 54 45 20 54 41 42 4c 45 20 69 6d 70 6f 72 74 ATE TABLE import
4a90: 65 64 5f 66 72 6f 6d 5f 70 67 20 41 53 0d 0a 53 ed_from_pg AS..S
4aa0: 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 70 67 5f ELECT * FROM pg_
4ab0: 69 6e 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e in;..</verbatim>
4ac0: 0d 0a 59 6f 75 20 63 61 6e 20 6f 62 76 69 6f 75 ..You can obviou
4ad0: 73 6c 79 20 63 72 65 61 74 65 20 61 6e 64 20 70 sly create and p
4ae0: 6f 70 75 6c 61 74 65 20 61 20 6c 6f 63 61 6c 20 opulate a local
4af0: 63 6f 70 79 20 6f 66 20 74 68 65 20 72 65 6d 6f copy of the remo
4b00: 74 65 20 50 6f 73 74 67 72 65 73 20 74 61 62 6c te Postgres tabl
4b10: 65 3a 20 6e 6f 77 20 61 6c 6c 20 64 61 74 61 20 e: now all data
4b20: 61 72 65 20 70 65 72 6d 61 6e 65 6e 74 6c 79 20 are permanently
4b30: 73 74 6f 72 65 64 20 77 69 74 68 69 6e 20 79 6f stored within yo
4b40: 75 72 20 53 51 4c 69 74 65 20 44 42 2e 0d 0a 3c ur SQLite DB...<
4b50: 76 65 72 62 61 74 69 6d 3e 0d 0a 42 45 47 49 4e verbatim>..BEGIN
4b60: 3b 0d 0a 43 4f 4d 4d 49 54 3b 0d 0a 52 4f 4c 4c ;..COMMIT;..ROLL
4b70: 42 41 43 4b 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 BACK;..</verbati
4b80: 6d 3e 0d 0a 54 72 61 6e 73 61 63 74 69 6f 6e 73 m>..Transactions
4b90: 20 61 72 65 20 68 6f 6e 6f 75 72 65 64 20 6f 6e are honoured on
4ba0: 20 74 68 65 20 50 6f 73 74 67 72 65 53 51 4c 20 the PostgreSQL
4bb0: 73 69 64 65 20 61 73 20 77 65 6c 6c 2c 20 77 68 side as well, wh
4bc0: 65 6e 20 61 20 56 69 72 74 75 61 6c 50 6f 73 74 en a VirtualPost
4bd0: 67 72 65 73 20 54 61 62 6c 65 20 73 75 70 70 6f gres Table suppo
4be0: 72 74 73 20 49 4e 53 45 52 54 20 2f 20 55 50 44 rts INSERT / UPD
4bf0: 41 54 45 20 2f 20 44 45 4c 45 54 45 20 73 74 61 ATE / DELETE sta
4c00: 74 65 6d 65 6e 74 73 2e 0d 0a 3c 76 65 72 62 61 tements...<verba
4c10: 74 69 6d 3e 0d 0a 44 52 4f 50 20 54 41 42 4c 45 tim>..DROP TABLE
4c20: 20 70 67 5f 69 6e 3b 0d 0a 3c 2f 76 65 72 62 61 pg_in;..</verba
4c30: 74 69 6d 3e 0d 0a 46 69 6e 61 6c 6c 79 2c 20 79 tim>..Finally, y
4c40: 6f 75 20 63 61 6e 20 64 72 6f 70 20 74 68 65 20 ou can drop the
4c50: 56 69 72 74 75 61 6c 50 6f 73 74 67 72 65 73 20 VirtualPostgres
4c60: 74 61 62 6c 65 2c 20 61 6e 64 20 74 68 69 73 20 table, and this
4c70: 77 69 6c 6c 20 69 6d 6d 65 64 69 61 74 65 6c 79 will immediately
4c80: 20 74 65 72 6d 69 6e 61 74 65 20 74 68 65 20 63 terminate the c
4c90: 6f 6e 6e 65 63 74 69 6f 6e 20 74 6f 20 74 68 65 onnection to the
4ca0: 20 50 6f 73 74 67 72 65 73 20 44 42 4d 53 2e 3c Postgres DBMS.<
4cb0: 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c br><br>..<hr>..<
4cc0: 68 33 3e 64 61 74 61 2d 74 79 70 65 20 6d 61 70 h3>data-type map
4cd0: 70 69 6e 67 20 61 6e 64 20 72 65 6c 61 74 65 64 ping and related
4ce0: 20 63 6f 6e 76 65 72 73 69 6f 6e 73 3c 2f 68 33 conversions</h3
4cf0: 3e 0d 0a 52 61 74 68 65 72 20 6f 62 76 69 6f 75 >..Rather obviou
4d00: 73 6c 79 20 53 51 4c 69 74 65 20 61 6e 64 20 50 sly SQLite and P
4d10: 6f 73 74 67 72 65 73 20 73 75 70 70 6f 72 74 73 ostgres supports
4d20: 20 76 65 72 79 20 64 69 66 66 65 72 65 6e 74 20 very different
4d30: 6b 69 6e 64 20 6f 66 20 64 61 74 61 2d 74 79 70 kind of data-typ
4d40: 65 73 2e 20 54 68 65 20 66 65 77 20 66 6f 6c 6c es. The few foll
4d50: 6f 77 69 6e 67 20 72 75 6c 65 73 20 61 70 70 6c owing rules appl
4d60: 79 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 6e y:..<ul>..<li>an
4d70: 79 20 6b 69 6e 64 20 6f 66 20 3c 62 3e 49 4e 54 y kind of <b>INT
4d80: 45 47 45 52 3c 2f 62 3e 20 76 61 6c 75 65 20 69 EGER</b> value i
4d90: 73 20 70 72 65 73 65 72 76 65 64 20 61 73 20 73 s preserved as s
4da0: 75 63 68 20 28 74 68 69 73 20 69 6e 63 6c 75 64 uch (this includ
4db0: 69 6e 67 20 3c 62 3e 42 49 47 49 4e 54 3c 2f 62 ing <b>BIGINT</b
4dc0: 3e 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 74 68 >).</li>..<li>th
4dd0: 65 20 73 61 6d 65 20 69 73 20 66 6f 72 20 3c 62 e same is for <b
4de0: 3e 46 4c 4f 41 54 3c 2f 62 3e 20 76 61 6c 75 65 >FLOAT</b> value
4df0: 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e s.</li>..<li><b>
4e00: 4d 4f 4e 45 59 3c 2f 62 3e 20 61 6e 64 20 3c 62 MONEY</b> and <b
4e10: 3e 4e 55 4d 45 52 49 43 3c 2f 62 3e 20 76 61 6c >NUMERIC</b> val
4e20: 75 65 73 20 61 72 65 20 63 6f 6e 76 65 72 74 65 ues are converte
4e30: 64 20 69 6e 74 6f 20 3c 62 3e 46 4c 4f 41 54 3c d into <b>FLOAT<
4e40: 2f 62 3e 20 76 61 6c 75 65 73 2e 3c 2f 6c 69 3e /b> values.</li>
4e50: 0d 0a 3c 6c 69 3e 3c 62 3e 43 48 41 52 3c 2f 62 ..<li><b>CHAR</b
4e60: 3e 20 61 6e 64 20 3c 62 3e 56 41 52 43 48 41 52 > and <b>VARCHAR
4e70: 3c 2f 62 3e 20 76 61 6c 75 65 73 20 61 72 65 20 </b> values are
4e80: 61 6c 77 61 79 73 20 63 6f 6e 76 65 72 74 65 64 always converted
4e90: 20 69 6e 74 6f 20 3c 62 3e 54 45 58 54 3c 2f 62 into <b>TEXT</b
4ea0: 3e 20 76 61 6c 75 65 73 2e 3c 2f 6c 69 3e 0d 0a > values.</li>..
4eb0: 3c 6c 69 3e 48 61 6e 64 6c 69 6e 67 20 6f 66 20 <li>Handling of
4ec0: 3c 62 3e 44 41 54 45 3c 2f 62 3e 2c 20 3c 62 3e <b>DATE</b>, <b>
4ed0: 54 49 4d 45 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e TIME</b> and <b>
4ee0: 54 49 4d 45 53 54 41 4d 50 3c 2f 62 3e 20 76 61 TIMESTAMP</b> va
4ef0: 6c 75 65 73 20 64 65 70 65 6e 64 73 20 6f 6e 20 lues depends on
4f00: 74 68 65 20 73 70 65 63 69 66 63 20 66 6c 61 67 the specifc flag
4f10: 20 28 3c 62 3e 4a 3c 2f 62 3e 29 20 64 65 63 6c (<b>J</b>) decl
4f20: 61 72 65 64 20 69 6e 20 74 68 65 20 3c 62 3e 43 ared in the <b>C
4f30: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 REATE VIRTUAL TA
4f40: 42 4c 45 3c 2f 62 3e 20 73 74 61 74 65 6d 65 6e BLE</b> statemen
4f50: 74 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 73 t:..<ul>..<li>as
4f60: 20 3c 62 3e 54 65 78 74 20 76 61 6c 75 65 73 3c <b>Text values<
4f70: 2f 62 3e 3c 62 72 3e 0d 0a 44 41 54 45 2c 20 54 /b><br>..DATE, T
4f80: 49 4d 45 20 61 6e 64 20 54 49 4d 45 53 54 41 4d IME and TIMESTAM
4f90: 50 20 76 61 6c 75 65 73 20 61 72 65 20 61 6c 77 P values are alw
4fa0: 61 79 73 20 63 6f 6e 76 65 72 74 65 64 20 69 6e ays converted in
4fb0: 74 6f 20 3c 62 3e 54 45 58 54 20 73 74 72 69 6e to <b>TEXT strin
4fc0: 67 3c 2f 62 3e 20 61 63 63 6f 72 64 69 6e 67 6c g</b> accordingl
4fd0: 79 20 74 6f 20 74 68 65 20 73 74 61 6e 64 61 72 y to the standar
4fe0: 64 20 53 51 4c 20 72 65 70 72 65 73 65 6e 74 61 d SQL representa
4ff0: 74 69 6f 6e 73 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c tions:..<ul>..<l
5000: 69 3e 61 6e 20 65 78 61 6d 70 6c 65 20 6f 66 20 i>an example of
5010: 44 41 54 45 20 76 61 6c 75 65 3a 20 3c 62 3e 32 DATE value: <b>2
5020: 30 31 38 2d 30 38 2d 31 36 3c 2f 62 3e 3c 2f 6c 018-08-16</b></l
5030: 69 3e 0d 0a 3c 6c 69 3e 61 6e 20 65 78 61 6d 70 i>..<li>an examp
5040: 6c 65 20 6f 66 20 54 49 4d 45 20 76 61 6c 75 65 le of TIME value
5050: 3a 20 3c 62 3e 31 32 3a 33 30 3a 34 35 3c 2f 62 : <b>12:30:45</b
5060: 3e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 20 65 ></li>..<li>an e
5070: 78 61 6d 70 6c 65 20 6f 66 20 54 49 4d 45 53 54 xample of TIMEST
5080: 41 4d 50 20 76 61 6c 75 65 3a 20 3c 62 3e 32 30 AMP value: <b>20
5090: 31 38 2d 30 38 2d 31 36 20 31 32 3a 33 30 3a 34 18-08-16 12:30:4
50a0: 35 3c 2f 62 3e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 5</b></li>..</ul
50b0: 3e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 73 20 3c ></li>..<li>as <
50c0: 62 3e 4a 75 6c 69 61 6e 20 4e 75 6d 62 65 72 73 b>Julian Numbers
50d0: 3c 2f 62 3e 3c 62 72 3e 0d 0a 44 41 54 45 2c 20 </b><br>..DATE,
50e0: 54 49 4d 45 20 61 6e 64 20 54 49 4d 45 53 54 41 TIME and TIMESTA
50f0: 4d 50 20 76 61 6c 75 65 73 20 61 72 65 20 61 6c MP values are al
5100: 77 61 79 73 20 63 6f 6e 76 65 72 74 65 64 20 69 ways converted i
5110: 6e 74 6f 20 3c 62 3e 46 4c 4f 41 54 3c 2f 62 3e nto <b>FLOAT</b>
5120: 20 76 61 6c 75 65 73 20 63 6f 72 72 65 73 70 6f values correspo
5130: 6e 64 69 6e 67 20 74 6f 20 74 68 65 20 3c 61 20 nding to the <a
5140: 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f 77 77 77 href="http://www
5150: 2e 73 71 6c 69 74 65 2e 6f 72 67 2f 6c 61 6e 67 .sqlite.org/lang
5160: 5f 64 61 74 65 66 75 6e 63 2e 68 74 6d 6c 22 3e _datefunc.html">
5170: 4a 75 6c 69 61 6e 44 61 79 3c 2f 61 3e 20 6e 6f JulianDay</a> no
5180: 74 61 74 69 6f 6e 20 73 75 70 70 6f 72 74 65 64 tation supported
5190: 20 62 79 20 53 51 4c 69 74 65 2e 3c 62 72 3e 0d by SQLite.<br>.
51a0: 0a 59 6f 75 20 63 61 6e 20 74 68 65 6e 20 69 6e .You can then in
51b0: 76 6f 6b 65 20 74 68 65 20 61 70 70 72 6f 70 72 voke the appropr
51c0: 69 61 74 65 20 66 75 6e 63 74 69 6f 6e 20 62 65 iate function be
51d0: 74 77 65 65 6e 20 3c 62 3e 44 61 74 65 28 29 3c tween <b>Date()<
51e0: 2f 62 3e 2c 20 3c 62 3e 54 69 6d 65 28 29 3c 2f /b>, <b>Time()</
51f0: 62 3e 20 6f 72 20 3c 62 3e 44 61 74 65 54 69 6d b> or <b>DateTim
5200: 65 28 29 3c 2f 62 3e 20 73 6f 20 74 6f 20 67 65 e()</b> so to ge
5210: 74 20 62 61 63 6b 20 74 68 65 20 73 74 61 6e 64 t back the stand
5220: 61 72 64 20 53 51 4c 20 6e 6f 74 61 74 69 6f 6e ard SQL notation
5230: 20 66 6f 72 20 64 61 74 65 73 20 61 6e 64 20 74 for dates and t
5240: 69 6d 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e imes.</li>..<li>
5250: 3c 62 3e 48 69 6e 74 3c 2f 62 3e 3a 20 75 73 69 <b>Hint</b>: usi
5260: 6e 67 20 54 45 58 54 20 73 74 72 69 6e 67 73 20 ng TEXT strings
5270: 69 73 20 6d 6f 72 65 20 6e 61 74 75 72 61 6c 20 is more natural
5280: 61 6e 64 20 6d 61 6b 65 20 65 61 73 69 65 72 20 and make easier
5290: 72 65 61 64 69 6e 67 20 74 68 65 20 64 61 74 65 reading the date
52a0: 2d 74 69 6d 65 20 72 65 6c 61 74 65 64 20 76 61 -time related va
52b0: 6c 75 65 73 2e 3c 62 72 3e 0d 0a 75 73 69 6e 67 lues.<br>..using
52c0: 20 4a 55 4c 49 41 4e 20 4e 55 4d 42 45 52 53 20 JULIAN NUMBERS
52d0: 6d 61 6b 65 20 73 69 6d 70 6c 65 72 20 70 65 72 make simpler per
52e0: 66 6f 72 6d 69 6e 67 20 64 61 74 65 2d 74 69 6d forming date-tim
52f0: 65 20 72 65 6c 61 74 65 64 20 63 6f 6d 70 75 74 e related comput
5300: 61 74 69 6f 6e 73 2c 20 61 73 20 65 2e 67 2e 20 ations, as e.g.
5310: 63 6f 6d 70 75 74 69 6e 67 20 74 68 65 20 65 6c computing the el
5320: 61 70 73 65 64 20 69 6e 74 65 72 76 61 6c 20 28 apsed interval (
5330: 69 6e 20 64 61 79 73 29 20 62 65 74 77 65 65 6e in days) between
5340: 20 74 77 6f 20 64 61 74 65 73 2e 3c 2f 6c 69 3e two dates.</li>
5350: 0d 0a 3c 2f 75 6c 3e 3c 2f 6c 69 3e 0d 0a 3c 6c ..</ul></li>..<l
5360: 69 3e 3c 62 3e 42 4f 4f 4c 3c 2f 62 3e 20 76 61 i><b>BOOL</b> va
5370: 6c 75 65 73 20 61 72 65 20 61 6c 77 61 79 73 20 lues are always
5380: 63 6f 6e 76 65 72 74 65 64 20 69 6e 74 6f 20 3c converted into <
5390: 62 3e 49 4e 54 45 47 45 52 3c 2f 62 3e 20 76 61 b>INTEGER</b> va
53a0: 6c 75 65 73 3a 20 3c 62 3e 30 3c 2f 62 3e 20 63 lues: <b>0</b> c
53b0: 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 74 6f 20 orresponding to
53c0: 3c 62 3e 46 41 4c 53 45 3c 2f 62 3e 2e 3c 2f 6c <b>FALSE</b>.</l
53d0: 69 3e 0d 0a 3c 6c 69 3e 50 6f 73 74 67 72 65 73 i>..<li>Postgres
53e0: 20 73 75 70 70 6f 72 74 73 20 6d 75 6c 74 69 70 supports multip
53f0: 6c 65 20 76 61 6c 75 65 73 20 74 6f 20 62 65 20 le values to be
5400: 73 74 6f 72 65 64 20 69 6e 74 6f 20 74 68 65 20 stored into the
5410: 73 61 6d 65 20 63 6f 6c 75 6d 6e 20 28 3c 62 3e same column (<b>
5420: 41 52 52 41 59 3c 2f 62 3e 29 3a 20 53 51 4c 69 ARRAY</b>): SQLi
5430: 74 65 20 68 61 73 20 6e 6f 20 73 69 6d 69 6c 61 te has no simila
5440: 72 20 63 61 70 61 62 69 6c 69 74 79 2c 20 73 6f r capability, so
5450: 20 61 6e 79 20 41 52 52 41 59 20 76 61 6c 75 65 any ARRAY value
5460: 20 77 69 6c 6c 20 73 69 6d 70 6c 79 20 62 65 20 will simply be
5470: 63 6f 6e 76 65 72 74 65 64 20 69 6e 74 6f 20 61 converted into a
5480: 20 3c 62 3e 54 45 58 54 3c 2f 62 3e 20 73 74 72 <b>TEXT</b> str
5490: 69 6e 67 2c 20 65 2e 67 2e 20 61 73 20 69 6e 20 ing, e.g. as in
54a0: 3c 62 3e 27 7b 31 2c 32 2c 33 7d 27 3c 2f 62 3e <b>'{1,2,3}'</b>
54b0: 20 6f 72 20 3c 62 3e 27 7b 61 6c 70 68 61 2c 62 or <b>'{alpha,b
54c0: 65 74 61 2c 67 61 6d 6d 61 2c 64 65 6c 74 61 7d eta,gamma,delta}
54d0: 27 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 '</b>.</li>..<li
54e0: 3e 61 6e 79 20 62 69 6e 61 72 79 20 76 61 6c 75 >any binary valu
54f0: 65 20 28 61 73 20 65 2e 67 2e 20 3c 62 3e 42 59 e (as e.g. <b>BY
5500: 54 45 41 3c 2f 62 3e 29 20 77 69 6c 6c 20 62 65 TEA</b>) will be
5510: 20 73 69 6d 70 6c 79 20 63 6f 6e 76 65 72 74 65 simply converte
5520: 64 20 69 6e 74 6f 20 61 20 3c 62 3e 54 45 58 54 d into a <b>TEXT
5530: 3c 2f 62 3e 20 76 61 6c 75 65 20 63 6f 6e 74 61 </b> value conta
5540: 69 6e 69 6e 67 20 74 68 65 20 63 6f 72 72 65 73 ining the corres
5550: 70 6f 6e 64 69 6e 67 20 68 65 78 61 64 65 63 69 ponding hexadeci
5560: 6d 61 6c 20 6e 6f 74 61 74 69 6f 6e 2c 20 65 2e mal notation, e.
5570: 67 2e 20 61 73 20 69 6e 20 3c 62 3e 27 30 31 30 g. as in <b>'010
5580: 31 30 30 30 30 32 30 45 38 36 34 30 30 30 30 43 1000020E8640000C
5590: 34 46 43 33 34 42 41 38 34 34 38 32 34 34 31 35 4FC34BA844824415
55a0: 30 43 31 42 35 44 35 34 31 42 38 35 33 34 31 27 0C1B5D541B85341'
55b0: 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c </b>.</li>..</ul
55c0: 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 33 ><br>..<hr>..<h3
55d0: 3e 68 61 6e 64 6c 69 6e 67 20 50 6f 73 74 47 49 >handling PostGI
55e0: 53 20 67 65 6f 6d 65 74 72 69 65 73 3c 2f 68 33 S geometries</h3
55f0: 3e 0d 0a 50 6f 73 74 47 49 53 20 6f 77 6e 20 67 >..PostGIS own g
5600: 65 6f 6d 65 74 72 69 65 73 20 73 69 6d 70 6c 79 eometries simply
5610: 20 61 72 65 20 72 65 70 72 65 73 65 6e 74 65 64 are represented
5620: 20 62 79 20 61 20 3c 62 3e 42 59 54 45 41 3c 2f by a <b>BYTEA</
5630: 62 3e 20 76 61 6c 75 65 20 74 6f 20 62 65 20 69 b> value to be i
5640: 6e 74 65 72 70 72 65 74 65 64 20 61 63 63 6f 72 nterpreted accor
5650: 64 69 6e 67 6c 79 20 74 6f 20 3c 62 3e 45 57 4b dingly to <b>EWK
5660: 42 3c 2f 62 3e 20 66 6f 72 6d 61 74 20 73 70 65 B</b> format spe
5670: 63 69 66 69 63 61 74 69 6f 6e 73 2e 0d 0a 3c 76 cifications...<v
5680: 65 72 62 61 74 69 6d 3e 0d 0a 43 52 45 41 54 45 erbatim>..CREATE
5690: 20 54 41 42 4c 45 20 66 72 6f 6d 5f 70 6f 73 74 TABLE from_post
56a0: 67 69 73 20 41 53 0d 0a 53 45 4c 45 43 54 20 2a gis AS..SELECT *
56b0: 20 46 52 4f 4d 20 70 67 5f 69 6e 3b 0d 0a 0d 0a FROM pg_in;....
56c0: 55 50 44 41 54 45 20 66 72 6f 6d 5f 70 6f 73 74 UPDATE from_post
56d0: 67 69 73 20 53 45 54 20 67 65 6f 6d 65 74 72 79 gis SET geometry
56e0: 20 3d 20 47 65 6f 6d 46 72 6f 6d 45 57 4b 42 28 = GeomFromEWKB(
56f0: 67 65 6f 6d 65 74 72 79 29 3b 0d 0a 0d 0a 53 45 geometry);....SE
5700: 4c 45 43 54 20 44 49 53 54 49 4e 43 54 20 53 54 LECT DISTINCT ST
5710: 5f 47 65 6f 6d 65 74 72 79 54 79 70 65 28 67 65 _GeometryType(ge
5720: 6f 6d 65 74 72 79 29 2c 20 53 54 5f 53 72 69 64 ometry), ST_Srid
5730: 28 67 65 6f 6d 65 74 72 79 29 2c 20 43 6f 6f 72 (geometry), Coor
5740: 64 44 69 6d 65 6e 73 69 6f 6e 28 67 65 6f 6d 65 dDimension(geome
5750: 74 72 79 29 0d 0a 46 52 4f 4d 20 66 72 6f 6d 5f try)..FROM from_
5760: 70 6f 73 74 67 69 73 3b 0d 0a 2d 2d 2d 2d 2d 2d postgis;..------
5770: 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45 53 54 52 49 ------..LINESTRI
5780: 4e 47 7c 32 35 38 33 32 7c 58 59 0d 0a 0d 0a 53 NG|25832|XY....S
5790: 45 4c 45 43 54 20 52 65 63 6f 76 65 72 47 65 6f ELECT RecoverGeo
57a0: 6d 65 74 72 79 43 6f 6c 75 6d 6e 28 27 66 72 6f metryColumn('fro
57b0: 6d 5f 70 6f 73 74 67 69 73 27 2c 20 27 67 65 6f m_postgis', 'geo
57c0: 6d 65 74 72 79 27 2c 20 32 35 38 33 32 2c 20 27 metry', 25832, '
57d0: 4c 49 4e 45 53 54 52 49 4e 47 27 2c 20 27 58 59 LINESTRING', 'XY
57e0: 27 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ');..-----------
57f0: 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69 6d -..1..</verbatim
5800: 3e 0d 0a 54 68 69 73 20 73 65 71 75 65 6e 63 65 >..This sequence
5810: 20 6f 66 20 53 51 4c 20 73 74 61 74 65 6d 65 6e of SQL statemen
5820: 74 73 20 28 53 70 61 74 69 61 4c 69 74 65 20 73 ts (SpatiaLite s
5830: 75 70 70 6f 72 74 20 69 73 20 73 74 72 69 63 74 upport is strict
5840: 6c 79 20 72 65 71 75 69 72 65 64 29 20 77 69 6c ly required) wil
5850: 6c 20 74 72 61 6e 73 66 65 72 20 61 20 66 75 6c l transfer a ful
5860: 6c 79 20 71 75 61 6c 69 66 69 65 64 20 47 65 6f ly qualified Geo
5870: 6d 65 74 72 79 20 74 61 62 6c 65 20 66 72 6f 6d metry table from
5880: 20 50 6f 73 74 47 49 53 20 74 6f 20 53 70 61 74 PostGIS to Spat
5890: 69 61 4c 69 74 65 3a 0d 0a 3c 75 6c 3e 0d 0a 3c iaLite:..<ul>..<
58a0: 6c 69 3e 3c 62 3e 73 74 65 70 20 31 3c 2f 62 3e li><b>step 1</b>
58b0: 3a 20 66 69 72 73 74 20 77 65 27 6c 6c 20 74 72 : first we'll tr
58c0: 61 6e 73 66 65 72 20 74 68 65 20 77 68 6f 6c 65 ansfer the whole
58d0: 20 50 6f 73 74 47 49 53 20 74 61 62 6c 65 20 69 PostGIS table i
58e0: 6e 74 6f 20 53 51 4c 69 74 65 3b 20 67 65 6f 6d nto SQLite; geom
58f0: 65 74 72 69 65 73 20 61 72 65 20 73 74 69 6c 6c etries are still
5900: 20 72 65 70 72 65 73 65 6e 74 65 64 20 62 79 20 represented by
5910: 74 68 65 69 72 20 3c 62 3e 45 57 4b 42 3c 2f 62 their <b>EWKB</b
5920: 3e 20 68 65 78 61 64 65 63 69 6d 61 6c 20 6e 6f > hexadecimal no
5930: 74 61 74 69 6f 6e 73 2e 3c 2f 6c 69 3e 0d 0a 3c tations.</li>..<
5940: 6c 69 3e 3c 62 3e 73 74 65 70 20 32 3c 2f 62 3e li><b>step 2</b>
5950: 3a 20 74 68 65 6e 20 77 65 27 6c 6c 20 75 73 65 : then we'll use
5960: 20 74 68 65 20 3c 62 3e 47 65 6f 6d 46 72 6f 6d the <b>GeomFrom
5970: 45 57 4b 42 28 29 3c 2f 62 3e 20 53 51 4c 20 66 EWKB()</b> SQL f
5980: 75 6e 63 74 69 6f 6e 20 73 6f 20 74 6f 20 67 65 unction so to ge
5990: 74 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 t the correspond
59a0: 69 6e 67 20 3c 62 3e 53 70 61 74 69 61 4c 69 74 ing <b>SpatiaLit
59b0: 65 27 73 20 42 4c 4f 42 3c 2f 62 3e 20 66 6f 72 e's BLOB</b> for
59c0: 20 65 61 63 68 20 67 65 6f 6d 65 74 72 79 2e 3c each geometry.<
59d0: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 73 74 65 /li>..<li><b>ste
59e0: 70 20 33 3c 2f 62 3e 3a 20 6e 6f 77 20 77 65 20 p 3</b>: now we
59f0: 73 69 6d 70 6c 79 20 68 61 76 65 20 74 6f 20 64 simply have to d
5a00: 69 73 63 6f 76 65 72 20 74 68 65 20 54 79 70 65 iscover the Type
5a10: 2c 20 53 52 49 44 20 61 6e 64 20 44 69 6d 65 6e , SRID and Dimen
5a20: 73 69 6f 6e 73 20 64 65 63 6c 61 72 65 64 20 62 sions declared b
5a30: 79 20 74 68 65 73 65 20 67 65 6f 6d 65 74 72 69 y these geometri
5a40: 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 es.</li>..<li><b
5a50: 3e 73 74 65 70 20 34 3c 2f 62 3e 3a 20 61 6e 64 >step 4</b>: and
5a60: 20 66 69 6e 61 6c 6c 79 20 77 65 20 63 61 6e 20 finally we can
5a70: 6e 6f 77 20 72 65 63 6f 76 65 72 20 61 20 66 75 now recover a fu
5a80: 6c 6c 20 71 75 61 6c 69 66 69 65 64 20 53 70 61 ll qualified Spa
5a90: 74 69 61 4c 69 74 65 27 73 20 6f 77 6e 20 28 3c tiaLite's own (<
5aa0: 69 3e 6e 61 74 69 76 65 3c 2f 69 3e 29 20 47 65 i>native</i>) Ge
5ab0: 6f 6d 65 74 72 79 20 63 6f 6c 75 6d 6e 2e 3c 2f ometry column.</
5ac0: 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d 0a li>..</ul><br>..
5ad0: 3c 68 72 3e 0d 0a 3c 68 33 3e 65 78 70 6f 72 74 <hr>..<h3>export
5ae0: 69 6e 67 20 64 61 74 61 20 66 72 6f 6d 20 53 51 ing data from SQ
5af0: 4c 69 74 65 20 74 6f 20 50 6f 73 74 67 72 65 73 Lite to Postgres
5b00: 2f 50 6f 73 74 47 49 53 3c 2f 68 33 3e 0d 0a 46 /PostGIS</h3>..F
5b10: 6f 72 20 72 61 74 68 65 72 20 6f 62 76 69 6f 75 or rather obviou
5b20: 73 20 73 65 63 75 72 69 74 79 20 72 65 61 73 6f s security reaso
5b30: 6e 73 2c 20 61 6c 6c 20 56 69 72 74 75 61 6c 50 ns, all VirtualP
5b40: 6f 73 74 67 72 65 73 20 74 61 62 6c 65 73 20 61 ostgres tables a
5b50: 72 65 20 64 65 63 6c 61 72 65 64 20 74 6f 20 62 re declared to b
5b60: 65 20 3c 69 3e 72 65 61 64 2d 6f 6e 6c 79 3c 2f e <i>read-only</
5b70: 69 3e 20 62 79 20 64 65 66 61 75 6c 74 2e 3c 62 i> by default.<b
5b80: 72 3e 0d 0a 54 68 69 73 20 61 63 74 75 61 6c 6c r>..This actuall
5b90: 79 20 6d 65 61 6e 73 20 74 68 61 74 20 79 6f 75 y means that you
5ba0: 20 61 72 65 20 65 6e 61 62 6c 65 64 20 74 6f 20 are enabled to
5bb0: 65 78 65 63 75 74 65 20 61 6e 79 20 70 6f 73 73 execute any poss
5bc0: 69 62 6c 65 20 3c 62 3e 53 45 4c 45 43 54 3c 2f ible <b>SELECT</
5bd0: 62 3e 20 71 75 65 72 79 2c 20 62 75 74 20 61 6e b> query, but an
5be0: 79 20 3c 62 3e 49 4e 53 45 52 54 3c 2f 62 3e 2c y <b>INSERT</b>,
5bf0: 20 3c 62 3e 55 50 44 41 54 45 3c 2f 62 3e 20 6f <b>UPDATE</b> o
5c00: 72 20 3c 62 3e 44 45 4c 45 54 45 3c 2f 62 3e 20 r <b>DELETE</b>
5c10: 6f 70 65 72 61 74 69 6f 6e 20 61 66 66 65 63 74 operation affect
5c20: 69 6e 67 20 74 68 65 20 50 6f 73 74 67 72 65 73 ing the Postgres
5c30: 20 44 42 4d 53 20 69 73 20 73 74 72 69 63 74 6c DBMS is strictl
5c40: 79 20 66 6f 72 62 69 64 64 65 6e 2e 0d 0a 3c 76 y forbidden...<v
5c50: 65 72 62 61 74 69 6d 3e 0d 0a 43 52 45 41 54 45 erbatim>..CREATE
5c60: 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 70 VIRTUAL TABLE p
5c70: 67 5f 6f 75 74 20 0d 0a 20 20 20 20 55 53 49 4e g_out .. USIN
5c80: 47 20 56 69 72 74 75 61 6c 50 6f 73 74 67 72 65 G VirtualPostgre
5c90: 73 20 28 27 68 6f 73 74 61 64 64 72 3d 31 39 32 s ('hostaddr=192
5ca0: 2e 31 36 38 2e 31 2e 39 31 20 70 6f 72 74 3d 35 .168.1.91 port=5
5cb0: 34 33 32 20 64 62 6e 61 6d 65 3d 67 69 73 20 75 432 dbname=gis u
5cc0: 73 65 72 3d 73 61 6e 64 72 6f 20 70 61 73 73 77 ser=sandro passw
5cd0: 6f 72 64 3d 73 65 63 72 65 74 27 2c 20 6d 79 5f ord=secret', my_
5ce0: 73 63 68 65 6d 61 2c 20 6d 79 5f 74 61 62 6c 65 schema, my_table
5cf0: 2c 20 57 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 , W);..</verbati
5d00: 6d 3e 0d 0a 41 20 73 70 65 63 69 61 6c 20 3c 62 m>..A special <b
5d10: 3e 57 3c 2f 62 3e 20 66 6c 61 67 20 6d 75 73 74 >W</b> flag must
5d20: 20 62 65 20 73 70 65 63 69 66 69 65 64 20 77 68 be specified wh
5d30: 65 6e 20 63 72 65 61 74 69 6e 67 20 61 20 56 69 en creating a Vi
5d40: 72 74 75 61 6c 50 6f 73 74 67 72 65 73 20 54 61 rtualPostgres Ta
5d50: 62 6c 65 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 ble in order to
5d60: 61 6c 6c 6f 77 20 66 6f 72 20 75 6e 63 6f 6e 73 allow for uncons
5d70: 74 72 61 69 6e 65 64 20 3c 69 3e 72 65 61 64 2d trained <i>read-
5d80: 77 72 69 74 65 3c 2f 69 3e 20 6f 70 65 72 61 74 write</i> operat
5d90: 69 6f 6e 73 2c 20 74 68 69 73 20 69 6e 63 6c 75 ions, this inclu
5da0: 64 69 6e 67 20 61 6e 79 20 3c 62 3e 49 4e 53 45 ding any <b>INSE
5db0: 52 54 3c 2f 62 3e 2c 20 3c 62 3e 55 50 44 41 54 RT</b>, <b>UPDAT
5dc0: 45 3c 2f 62 3e 20 6f 72 20 3c 62 3e 44 45 4c 45 E</b> or <b>DELE
5dd0: 54 45 3c 2f 62 3e 20 73 74 61 74 65 6d 65 6e 74 TE</b> statement
5de0: 20 61 66 66 65 63 74 69 6e 67 20 74 68 65 20 50 affecting the P
5df0: 6f 73 74 67 72 65 73 20 44 42 4d 53 2e 0d 0a 3c ostgres DBMS...<
5e00: 76 65 72 62 61 74 69 6d 3e 0d 0a 42 45 47 49 4e verbatim>..BEGIN
5e10: 3b 0d 0a 0d 0a 44 45 4c 45 54 45 20 46 52 4f 4d ;....DELETE FROM
5e20: 20 70 67 5f 6f 75 74 3b 0d 0a 0d 0a 49 4e 53 45 pg_out;....INSE
5e30: 52 54 20 49 4e 54 4f 20 70 67 5f 6f 75 74 20 28 RT INTO pg_out (
5e40: 66 6c 64 5f 61 2c 20 66 6c 64 5f 62 2c 20 66 6c fld_a, fld_b, fl
5e50: 64 5f 63 2c 20 67 65 6f 6d 65 74 72 79 29 0d 0a d_c, geometry)..
5e60: 53 45 4c 45 43 54 20 66 6c 64 5f 61 2c 20 66 6c SELECT fld_a, fl
5e70: 64 5f 62 2c 20 66 6c 64 5f 63 2c 20 41 73 45 57 d_b, fld_c, AsEW
5e80: 4b 42 28 67 65 6f 6d 65 74 72 79 29 0d 0a 46 52 KB(geometry)..FR
5e90: 4f 4d 20 73 6f 6d 65 5f 74 61 62 6c 65 3b 0d 0a OM some_table;..
5ea0: 0d 0a 43 4f 4d 4d 49 54 3b 0d 0a 3c 2f 76 65 72 ..COMMIT;..</ver
5eb0: 62 61 74 69 6d 3e 0d 0a 49 6e 20 74 68 65 20 61 batim>..In the a
5ec0: 62 6f 76 65 20 65 78 61 6d 70 6c 65 20 77 65 27 bove example we'
5ed0: 6c 6c 20 64 65 6c 65 74 65 20 66 69 72 73 74 20 ll delete first
5ee0: 61 6e 79 20 61 6c 72 65 61 64 79 20 65 78 69 73 any already exis
5ef0: 74 69 6e 67 20 72 6f 77 20 66 72 6f 6d 20 74 68 ting row from th
5f00: 65 20 50 6f 73 74 47 49 53 20 74 61 62 6c 65 3b e PostGIS table;
5f10: 20 74 68 65 6e 20 77 65 27 6c 6c 20 73 69 6d 70 then we'll simp
5f20: 6c 79 20 74 72 61 6e 73 66 65 72 20 74 68 65 20 ly transfer the
5f30: 77 68 6f 6c 65 20 74 61 62 6c 65 20 66 72 6f 6d whole table from
5f40: 20 53 70 61 74 69 61 4c 69 74 65 20 69 6e 74 6f SpatiaLite into
5f50: 20 50 6f 73 74 47 49 53 2e 3c 62 72 3e 0d 0a 50 PostGIS.<br>..P
5f60: 6c 65 61 73 65 20 6e 6f 74 65 2c 20 77 65 27 6c lease note, we'l
5f70: 6c 20 69 6e 76 6f 6b 65 20 74 68 65 20 3c 62 3e l invoke the <b>
5f80: 41 73 45 57 4b 42 28 29 3c 2f 62 3e 20 53 51 4c AsEWKB()</b> SQL
5f90: 20 66 75 6e 63 74 69 6f 6e 20 69 6e 20 6f 72 64 function in ord
5fa0: 65 72 20 74 6f 20 63 6f 6e 76 65 72 74 20 61 6e er to convert an
5fb0: 79 20 53 70 61 74 69 61 4c 69 74 65 27 73 20 6f y SpatiaLite's o
5fc0: 77 6e 20 3c 62 3e 42 4c 4f 42 3c 2f 62 3e 20 67 wn <b>BLOB</b> g
5fd0: 65 6f 6d 65 74 72 79 20 69 6e 74 6f 20 74 68 65 eometry into the
5fe0: 20 65 71 75 69 76 61 6c 65 6e 74 20 3c 62 3e 42 equivalent <b>B
5ff0: 59 54 45 41 20 45 57 4b 42 3c 2f 62 3e 20 6e 6f YTEA EWKB</b> no
6000: 74 61 74 69 6f 6e 20 72 65 71 75 69 72 65 64 20 tation required
6010: 62 79 20 50 6f 73 74 47 49 53 2e 3c 62 72 3e 3c by PostGIS.<br><
6020: 62 72 3e 0d 0a 3c 62 3e 4e 6f 74 65 3c 2f 62 3e br>..<b>Note</b>
6030: 3a 20 73 74 61 72 74 69 6e 67 20 61 20 54 72 61 : starting a Tra
6040: 6e 73 61 63 74 69 6f 6e 20 28 3c 62 3e 42 45 47 nsaction (<b>BEG
6050: 49 4e 2f 43 4f 4d 4d 49 54 3c 2f 62 3e 29 20 6f IN/COMMIT</b>) o
6060: 6e 20 74 68 65 20 50 6f 73 67 72 65 53 51 4c 20 n the PosgreSQL
6070: 73 69 64 65 20 61 6c 77 61 79 73 20 69 73 20 61 side always is a
6080: 20 73 75 67 67 65 73 74 65 64 20 67 6f 6f 64 20 suggested good
6090: 70 72 61 63 74 69 63 65 20 77 68 65 6e 20 77 72 practice when wr
60a0: 69 74 69 6e 67 20 6d 61 6e 79 20 64 61 74 61 20 iting many data
60b0: 6f 6e 20 74 68 65 20 50 6f 73 74 67 72 65 53 51 on the PostgreSQ
60c0: 4c 20 74 61 72 67 65 74 2c 20 61 6e 64 20 77 69 L target, and wi
60d0: 6c 6c 20 68 61 76 65 20 61 20 70 6f 73 69 74 69 ll have a positi
60e0: 76 65 20 69 6d 70 61 63 74 20 6f 6e 20 6f 76 65 ve impact on ove
60f0: 72 61 6c 6c 20 70 65 72 66 6f 72 6d 61 6e 63 65 rall performance
6100: 73 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 74 61 62 s.<br><br>..<tab
6110: 6c 65 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 le cellspacing="
6120: 36 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 6" cellpadding="
6130: 36 22 20 62 67 63 6f 6c 6f 72 3d 22 23 66 66 66 6" bgcolor="#fff
6140: 66 65 38 22 20 77 69 64 74 68 3d 22 31 30 30 25 fe8" width="100%
6150: 22 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 6c 69 67 ">..<tr><td alig
6160: 6e 3d 22 63 65 6e 74 65 72 22 3e 3c 62 3e 43 61 n="center"><b>Ca
6170: 76 65 61 74 3a 20 41 73 45 57 4b 42 28 29 3c 2f veat: AsEWKB()</
6180: 62 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 b></td></tr>..<t
6190: 72 3e 3c 74 64 3e 3c 68 72 3e 3c 2f 74 64 3e 3c r><td><hr></td><
61a0: 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 0d 0a /tr>..<tr><td>..
61b0: 41 6c 6c 20 65 61 72 6c 69 65 72 20 76 65 72 73 All earlier vers
61c0: 69 6f 6e 73 20 6f 66 20 53 70 61 74 69 61 4c 69 ions of SpatiaLi
61d0: 74 65 20 72 65 6c 65 61 73 65 64 20 62 65 66 6f te released befo
61e0: 72 65 20 3c 62 3e 34 2e 32 2e 30 3c 2f 62 3e 20 re <b>4.2.0</b>
61f0: 73 75 70 70 6f 72 74 65 64 20 61 20 62 75 67 67 supported a bugg
6200: 69 73 68 20 41 73 45 57 4b 42 28 29 20 69 6d 70 ish AsEWKB() imp
6210: 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 63 6f 6d 70 lementation comp
6220: 6c 65 74 65 6c 79 20 75 6e 61 62 6c 65 20 74 6f letely unable to
6230: 20 63 72 65 61 74 65 20 76 61 6c 69 64 20 45 57 create valid EW
6240: 4b 42 20 47 65 6f 6d 65 74 72 69 65 73 20 74 6f KB Geometries to
6250: 20 62 65 20 70 61 73 73 65 64 20 74 6f 20 50 6f be passed to Po
6260: 73 74 47 49 53 2e 3c 62 72 3e 0d 0a 55 73 69 6e stGIS.<br>..Usin
6270: 67 20 76 65 72 73 69 6f 6e 20 3c 62 3e 34 2e 32 g version <b>4.2
6280: 2e 30 3c 2f 62 3e 20 28 6f 72 20 61 6e 79 20 6c .0</b> (or any l
6290: 61 74 65 72 29 20 69 73 20 73 74 72 69 63 74 6c ater) is strictl
62a0: 79 20 72 65 71 75 69 72 65 64 20 73 6f 20 74 6f y required so to
62b0: 20 72 65 61 6c 6c 79 20 67 65 74 20 61 20 77 6f really get a wo
62c0: 72 6b 69 6e 67 20 69 6d 70 6c 65 6d 65 6e 74 61 rking implementa
62d0: 74 69 6f 6e 20 6f 66 20 41 73 45 57 4b 4b 28 29 tion of AsEWKK()
62e0: 2e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c ...</td></tr>..<
62f0: 2f 74 61 62 6c 65 3e 0d 0a 3c 62 72 3e 0d 0a 42 /table>..<br>..B
6300: 61 63 6b 20 74 6f 20 3c 62 3e 56 69 72 74 75 61 ack to <b>Virtua
6310: 6c 50 47 3c 2f 62 3e 20 3c 61 20 68 72 65 66 3d lPG</b> <a href=
6320: 22 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67 61 69 "https://www.gai
6330: 61 2d 67 69 73 2e 69 74 2f 66 6f 73 73 69 6c 2f a-gis.it/fossil/
6340: 76 69 72 74 75 61 6c 70 67 2f 69 6e 64 65 78 22 virtualpg/index"
6350: 3e 68 6f 6d 65 20 70 61 67 65 3c 2f 61 3e 0a 5a >home page</a>.Z
6360: 20 34 66 66 32 65 37 61 36 36 39 38 34 63 63 35 4ff2e7a66984cc5
6370: 64 62 63 35 63 33 31 62 61 65 32 33 36 36 34 63 dbc5c31bae23664c
6380: 39 0a 9.