Hex Artifact Content
Not logged in

Artifact d6069e7bf8c7f124a0618f3a52b3facd2bc4b786:

Wiki page [VirtualElementary] by sandro 2014-09-22 22:55:15.
0000: 44 20 32 30 31 34 2d 30 39 2d 32 32 54 32 32 3a  D 2014-09-22T22:
0010: 35 35 3a 31 35 2e 31 39 34 0a 4c 20 56 69 72 74  55:15.194.L Virt
0020: 75 61 6c 45 6c 65 6d 65 6e 74 61 72 79 0a 55 20  ualElementary.U 
0030: 73 61 6e 64 72 6f 0a 57 20 34 31 32 37 0a 3c 68  sandro.W 4127.<h
0040: 32 3e 61 62 6f 75 74 20 56 69 72 74 75 61 6c 45  2>about VirtualE
0050: 6c 65 6d 65 6e 74 61 72 79 3c 2f 68 32 3e 0d 0a  lementary</h2>..
0060: 3c 62 3e 56 69 72 74 75 61 6c 45 6c 65 6d 65 6e  <b>VirtualElemen
0070: 74 61 72 79 3c 2f 62 3e 20 69 73 20 61 20 6e 65  tary</b> is a ne
0080: 77 20 3c 62 3e 56 69 72 74 75 61 6c 20 54 61 62  w <b>Virtual Tab
0090: 6c 65 3c 2f 62 3e 20 64 72 69 76 65 72 20 69 6e  le</b> driver in
00a0: 74 72 6f 64 75 63 65 64 20 73 74 61 72 74 69 6e  troduced startin
00b0: 67 20 73 69 6e 63 65 20 53 70 61 74 69 61 4c 69  g since SpatiaLi
00c0: 74 65 20 76 65 72 73 69 6f 6e 20 3c 62 3e 34 2e  te version <b>4.
00d0: 32 2e 31 3c 2f 62 3e 3c 62 72 3e 0d 0a 54 68 65  2.1</b><br>..The
00e0: 20 69 6e 74 65 6e 64 65 64 20 73 63 6f 70 65 20   intended scope 
00f0: 6f 66 20 74 68 69 73 20 76 69 72 74 75 61 6c 20  of this virtual 
0100: 6d 6f 64 75 6c 65 20 69 73 20 74 68 65 20 6f 6e  module is the on
0110: 65 20 74 6f 20 73 65 70 61 72 61 74 65 20 63 6f  e to separate co
0120: 6d 70 6c 65 78 20 67 65 6f 6d 65 74 72 69 65 73  mplex geometries
0130: 20 28 61 73 20 65 2e 67 2e 20 3c 69 3e 4d 75 6c   (as e.g. <i>Mul
0140: 74 69 4c 69 6e 65 73 74 72 69 6e 67 3c 2f 69 3e  tiLinestring</i>
0150: 20 6f 72 20 3c 69 3e 4d 75 6c 74 69 50 6f 6c 79   or <i>MultiPoly
0160: 67 6f 6e 3c 2f 69 3e 29 20 69 6e 74 6f 20 6d 61  gon</i>) into ma
0170: 6e 79 20 64 69 73 74 69 6e 63 74 20 65 6c 65 6d  ny distinct elem
0180: 65 6e 74 73 2c 20 73 6f 20 74 68 61 74 20 65 61  ents, so that ea
0190: 63 68 20 73 69 6e 67 6c 65 20 72 6f 77 20 72 65  ch single row re
01a0: 74 75 72 6e 65 64 20 69 6e 74 6f 20 74 68 65 20  turned into the 
01b0: 72 65 73 75 6c 74 73 65 74 20 77 69 6c 6c 20 61  resultset will a
01c0: 6c 77 61 79 73 20 63 6f 72 72 65 73 70 6f 6e 64  lways correspond
01d0: 20 74 6f 20 61 6e 20 65 6c 65 6d 65 6e 74 61 72   to an elementar
01e0: 79 20 47 65 6f 6d 65 74 72 79 2e 3c 62 72 3e 0d  y Geometry.<br>.
01f0: 0a 41 6e 79 77 61 79 20 74 68 65 20 6f 72 69 67  .Anyway the orig
0200: 69 6e 20 66 6f 72 20 65 76 65 72 79 20 65 6c 65  in for every ele
0210: 6d 65 6e 74 61 72 79 20 47 65 6f 6d 65 74 72 79  mentary Geometry
0220: 20 77 69 6c 6c 20 62 65 20 61 6c 77 61 79 73 20   will be always 
0230: 63 61 72 65 66 75 6c 6c 79 20 70 72 65 73 65 72  carefully preser
0240: 76 65 64 2c 20 73 6f 20 74 6f 20 6d 61 6b 65 20  ved, so to make 
0250: 65 61 73 79 20 72 65 2d 61 67 67 72 65 67 61 74  easy re-aggregat
0260: 69 6e 67 20 79 65 74 20 61 67 61 69 6e 20 74 68  ing yet again th
0270: 65 20 6f 72 69 67 69 6e 61 6c 20 63 6f 6d 70 6c  e original compl
0280: 65 78 20 47 65 6f 6d 65 74 72 69 65 73 20 69 66  ex Geometries if
0290: 20 61 6e 64 20 77 68 65 6e 20 72 65 71 75 69 72   and when requir
02a0: 65 64 2e 0d 0a 3c 68 32 3e 74 68 65 20 45 6c 65  ed...<h2>the Ele
02b0: 6d 65 6e 74 61 72 79 47 65 6f 6d 65 74 72 69 65  mentaryGeometrie
02c0: 73 20 74 61 62 6c 65 3c 2f 68 32 3e 0d 0a 41 6e  s table</h2>..An
02d0: 79 20 6e 65 77 20 44 42 2d 66 69 6c 65 20 63 72  y new DB-file cr
02e0: 65 61 74 65 64 20 75 73 69 6e 67 20 76 65 72 73  eated using vers
02f0: 69 6f 6e 20 3c 62 3e 34 2e 32 2e 31 3c 2f 62 3e  ion <b>4.2.1</b>
0300: 20 28 6f 72 20 61 6e 79 20 6c 61 74 65 72 29 20   (or any later) 
0310: 77 69 6c 6c 20 61 6c 77 61 79 73 20 69 6e 63 6c  will always incl
0320: 75 64 65 20 61 20 74 61 62 6c 65 20 6e 61 6d 65  ude a table name
0330: 64 20 3c 62 3e 45 6c 65 6d 65 6e 74 61 72 79 47  d <b>ElementaryG
0340: 65 6f 6d 65 74 72 69 65 73 3c 2f 62 3e 20 63 6f  eometries</b> co
0350: 72 72 65 73 70 6f 6e 64 69 6e 67 20 74 6f 20 61  rresponding to a
0360: 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 3c 62  n instance of <b
0370: 3e 56 69 72 74 75 61 6c 45 6c 65 6d 65 6e 74 61  >VirtualElementa
0380: 72 79 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a 53 75 63  ry</b>.<br>..Suc
0390: 68 20 74 61 62 6c 65 20 77 69 6c 6c 20 6f 62 76  h table will obv
03a0: 69 6f 75 73 6c 79 20 6d 69 73 73 20 69 6e 20 61  iously miss in a
03b0: 6c 6c 20 44 42 2d 66 69 6c 65 73 20 63 72 65 61  ll DB-files crea
03c0: 74 65 64 20 75 73 69 6e 67 20 61 6e 79 20 65 61  ted using any ea
03d0: 72 6c 69 65 72 20 76 65 72 73 69 6f 6e 3b 20 61  rlier version; a
03e0: 6e 79 77 61 79 20 61 64 64 69 6e 67 20 74 68 65  nyway adding the
03f0: 20 3c 62 3e 56 69 72 74 75 61 6c 45 6c 65 6d 65   <b>VirtualEleme
0400: 6e 74 61 72 79 3c 2f 62 3e 20 73 75 70 70 6f 72  ntary</b> suppor
0410: 74 20 69 6e 20 73 75 63 68 20 44 42 2d 66 69 6c  t in such DB-fil
0420: 65 73 20 69 73 20 72 65 61 6c 6c 79 20 73 69 6d  es is really sim
0430: 70 6c 65 2e 3c 62 72 3e 0d 0a 4a 75 73 74 20 65  ple.<br>..Just e
0440: 78 65 63 75 74 65 20 74 68 65 20 66 6f 6c 6c 6f  xecute the follo
0450: 77 69 6e 67 20 53 51 4c 20 73 74 61 74 65 6d 65  wing SQL stateme
0460: 6e 74 3a 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d  nt:..<verbatim>.
0470: 0a 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20  .CREATE VIRTUAL 
0480: 54 41 42 4c 45 20 45 6c 65 6d 65 6e 74 61 72 79  TABLE Elementary
0490: 47 65 6f 6d 65 74 72 69 65 73 20 55 53 49 4e 47  Geometries USING
04a0: 20 56 69 72 74 75 61 6c 45 6c 65 6d 65 6e 74 61   VirtualElementa
04b0: 72 79 28 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69  ry();..</verbati
04c0: 6d 3e 0d 0a 3c 68 32 3e 68 6f 77 20 69 74 20 77  m>..<h2>how it w
04d0: 6f 72 6b 73 20 2d 20 61 20 70 72 61 63 74 69 63  orks - a practic
04e0: 61 6c 20 65 78 61 6d 70 6c 65 3c 2f 68 32 3e 0d  al example</h2>.
04f0: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 43 52 45  .<verbatim>..CRE
0500: 41 54 45 20 54 41 42 4c 45 20 74 65 73 74 20 28  ATE TABLE test (
0510: 0d 0a 20 20 20 20 69 64 20 49 4e 54 45 47 45 52  ..    id INTEGER
0520: 20 50 52 49 4d 41 52 59 20 4b 45 59 20 41 55 54   PRIMARY KEY AUT
0530: 4f 49 4e 43 52 45 4d 45 4e 54 2c 0d 0a 20 20 20  OINCREMENT,..   
0540: 20 6e 61 6d 65 20 54 45 58 54 29 3b 0d 0a 0d 0a   name TEXT);....
0550: 53 45 4c 45 43 54 20 41 64 64 47 65 6f 6d 65 74  SELECT AddGeomet
0560: 72 79 43 6f 6c 75 6d 6e 28 27 74 65 73 74 27 2c  ryColumn('test',
0570: 20 27 67 65 6f 6d 27 2c 20 34 33 32 36 2c 20 27   'geom', 4326, '
0580: 4d 55 4c 54 49 4c 49 4e 45 53 54 52 49 4e 47 27  MULTILINESTRING'
0590: 2c 20 27 58 59 27 29 3b 0d 0a 0d 0a 49 4e 53 45  , 'XY');....INSE
05a0: 52 54 20 49 4e 54 4f 20 74 65 73 74 20 28 69 64  RT INTO test (id
05b0: 2c 20 6e 61 6d 65 2c 20 67 65 6f 6d 29 20 56 41  , name, geom) VA
05c0: 4c 55 45 53 20 28 4e 55 4c 4c 2c 20 27 6f 6e 65  LUES (NULL, 'one
05d0: 27 2c 0d 0a 20 20 20 20 53 54 5f 47 65 6f 6d 46  ',..    ST_GeomF
05e0: 72 6f 6d 54 65 78 74 28 27 4d 55 4c 54 49 4c 49  romText('MULTILI
05f0: 4e 45 53 54 52 49 4e 47 28 28 30 20 30 2c 20 30  NESTRING((0 0, 0
0600: 20 31 29 29 27 2c 20 34 33 32 36 29 29 3b 0d 0a   1))', 4326));..
0610: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 65 73 74  INSERT INTO test
0620: 20 28 69 64 2c 20 6e 61 6d 65 2c 20 67 65 6f 6d   (id, name, geom
0630: 29 20 56 41 4c 55 45 53 20 28 4e 55 4c 4c 2c 20  ) VALUES (NULL, 
0640: 27 74 77 6f 27 2c 0d 0a 20 20 20 20 53 54 5f 47  'two',..    ST_G
0650: 65 6f 6d 46 72 6f 6d 54 65 78 74 28 27 4d 55 4c  eomFromText('MUL
0660: 54 49 4c 49 4e 45 53 54 52 49 4e 47 28 28 30 20  TILINESTRING((0 
0670: 30 2c 20 30 20 31 29 2c 20 28 31 20 30 2c 20 31  0, 0 1), (1 0, 1
0680: 20 31 29 29 27 2c 20 34 33 32 36 29 29 3b 0d 0a   1))', 4326));..
0690: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 65 73 74  INSERT INTO test
06a0: 20 28 69 64 2c 20 6e 61 6d 65 2c 20 67 65 6f 6d   (id, name, geom
06b0: 29 20 56 41 4c 55 45 53 20 28 4e 55 4c 4c 2c 20  ) VALUES (NULL, 
06c0: 27 74 68 72 65 65 27 2c 0d 0a 20 20 20 20 53 54  'three',..    ST
06d0: 5f 47 65 6f 6d 46 72 6f 6d 54 65 78 74 28 27 4d  _GeomFromText('M
06e0: 55 4c 54 49 4c 49 4e 45 53 54 52 49 4e 47 28 28  ULTILINESTRING((
06f0: 30 20 30 2c 20 30 20 31 29 2c 20 28 31 20 30 2c  0 0, 0 1), (1 0,
0700: 20 31 20 31 29 2c 20 28 32 20 30 2c 20 32 20 31   1 1), (2 0, 2 1
0710: 29 29 27 2c 20 34 33 32 36 29 29 3b 0d 0a 3c 2f  ))', 4326));..</
0720: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 69 6e 63 65  verbatim>..Since
0730: 20 6e 6f 77 20 77 65 27 76 65 20 73 69 6d 70 6c   now we've simpl
0740: 79 20 63 72 65 61 74 65 64 20 61 6e 64 20 70 6f  y created and po
0750: 70 75 6c 61 74 65 64 20 61 20 74 61 62 6c 65 20  pulated a table 
0760: 63 6f 6e 74 61 69 6e 69 6e 67 20 4d 75 6c 74 69  containing Multi
0770: 4c 69 6e 65 73 74 72 69 6e 67 73 3b 20 6e 6f 77  Linestrings; now
0780: 20 77 65 27 6c 6c 20 74 65 73 74 20 74 68 65 20   we'll test the 
0790: 45 6c 65 6d 65 6e 74 61 72 79 47 65 6f 6d 65 74  ElementaryGeomet
07a0: 72 69 65 73 20 74 61 62 6c 65 2e 0d 0a 3c 76 65  ries table...<ve
07b0: 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20  rbatim>..SELECT 
07c0: 2a 20 46 52 4f 4d 20 45 6c 65 6d 65 6e 74 61 72  * FROM Elementar
07d0: 79 47 65 6f 6d 65 74 72 69 65 73 0d 0a 57 48 45  yGeometries..WHE
07e0: 52 45 20 66 5f 74 61 62 6c 65 5f 6e 61 6d 65 20  RE f_table_name 
07f0: 3d 20 27 74 65 73 74 27 20 41 4e 44 20 6f 72 69  = 'test' AND ori
0800: 67 69 6e 5f 72 6f 77 69 64 20 3d 20 32 3b 0d 0a  gin_rowid = 2;..
0810: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0820: 0d 0a 6d 61 69 6e 09 74 65 73 74 09 67 65 6f 6d  ..main.test.geom
0830: 09 32 09 30 09 42 4c 4f 42 20 73 7a 3d 38 30 20  .2.0.BLOB sz=80 
0840: 47 45 4f 4d 45 54 52 59 0d 0a 6d 61 69 6e 09 74  GEOMETRY..main.t
0850: 65 73 74 09 67 65 6f 6d 09 32 09 31 09 42 4c 4f  est.geom.2.1.BLO
0860: 42 20 73 7a 3d 38 30 20 47 45 4f 4d 45 54 52 59  B sz=80 GEOMETRY
0870: 0d 0a 0d 0a 0d 0a 53 45 4c 45 43 54 20 6f 72 69  ......SELECT ori
0880: 67 69 6e 5f 72 6f 77 69 64 2c 20 69 74 65 6d 5f  gin_rowid, item_
0890: 6e 6f 2c 20 53 54 5f 41 73 54 65 78 74 28 67 65  no, ST_AsText(ge
08a0: 6f 6d 65 74 72 79 29 0d 0a 46 52 4f 4d 20 45 6c  ometry)..FROM El
08b0: 65 6d 65 6e 74 61 72 79 47 65 6f 6d 65 74 72 69  ementaryGeometri
08c0: 65 73 0d 0a 57 48 45 52 45 20 64 62 5f 70 72 65  es..WHERE db_pre
08d0: 66 69 78 20 3d 20 27 6d 61 69 6e 27 20 41 4e 44  fix = 'main' AND
08e0: 20 66 5f 74 61 62 6c 65 5f 6e 61 6d 65 20 3d 20   f_table_name = 
08f0: 27 74 65 73 74 27 0d 0a 20 20 20 41 4e 44 20 66  'test'..   AND f
0900: 5f 67 65 6f 6d 65 74 72 79 5f 63 6f 6c 75 6d 6e  _geometry_column
0910: 20 3d 20 27 67 65 6f 6d 27 20 41 4e 44 20 6f 72   = 'geom' AND or
0920: 69 67 69 6e 5f 72 6f 77 69 64 20 3d 20 33 3b 0d  igin_rowid = 3;.
0930: 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .---------------
0940: 2d 0d 0a 33 09 30 09 4c 49 4e 45 53 54 52 49 4e  -..3.0.LINESTRIN
0950: 47 28 32 30 20 32 30 2c 20 32 30 20 32 31 29 0d  G(20 20, 20 21).
0960: 0a 33 09 31 09 4c 49 4e 45 53 54 52 49 4e 47 28  .3.1.LINESTRING(
0970: 32 31 20 32 30 2c 20 32 31 20 32 31 29 0d 0a 33  21 20, 21 21)..3
0980: 09 32 09 4c 49 4e 45 53 54 52 49 4e 47 28 32 32  .2.LINESTRING(22
0990: 20 32 30 2c 20 32 32 20 32 31 29 0d 0a 3c 2f 76   20, 22 21)..</v
09a0: 65 72 62 61 74 69 6d 3e 0d 0a 3c 75 6c 3e 0d 0a  erbatim>..<ul>..
09b0: 3c 6c 69 3e 74 68 65 20 3c 62 3e 45 6c 65 6d 65  <li>the <b>Eleme
09c0: 6e 74 61 72 79 47 65 6f 6d 65 74 72 69 65 73 3c  ntaryGeometries<
09d0: 2f 62 3e 20 74 61 62 6c 65 20 70 72 6f 76 69 64  /b> table provid
09e0: 65 73 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67  es the following
09f0: 20 63 6f 6c 75 6d 6e 73 3a 0d 0a 3c 75 6c 3e 0d   columns:..<ul>.
0a00: 0a 3c 6c 69 3e 3c 62 3e 64 62 5f 70 72 65 66 69  .<li><b>db_prefi
0a10: 78 3c 2f 62 3e 3a 20 74 68 65 20 73 79 6d 62 6f  x</b>: the symbo
0a20: 6c 69 63 20 70 72 65 66 69 78 20 69 64 65 6e 74  lic prefix ident
0a30: 69 66 79 69 6e 67 20 65 61 63 68 20 3c 61 20 68  ifying each <a h
0a40: 72 65 66 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e  ref="http://www.
0a50: 73 71 6c 69 74 65 2e 6f 72 67 2f 6c 61 6e 67 5f  sqlite.org/lang_
0a60: 61 74 74 61 63 68 2e 68 74 6d 6c 22 3e 61 74 74  attach.html">att
0a70: 61 63 68 65 64 20 64 61 74 61 62 61 73 65 3c 2f  ached database</
0a80: 61 3e 3b 20 74 68 65 20 44 42 2d 66 69 6c 65 20  a>; the DB-file 
0a90: 64 69 72 65 63 74 6c 79 20 61 73 73 6f 63 69 61  directly associa
0aa0: 74 65 64 20 74 6f 20 74 68 65 20 63 75 72 72 65  ted to the curre
0ab0: 6e 74 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 61 6c  nt connection al
0ac0: 77 61 79 73 20 63 6f 72 72 65 73 70 6f 6e 64 73  ways corresponds
0ad0: 20 74 6f 20 74 68 65 20 3c 62 3e 6d 61 69 6e 3c   to the <b>main<
0ae0: 2f 62 3e 20 70 72 65 66 69 78 2e 3c 2f 6c 69 3e  /b> prefix.</li>
0af0: 0d 0a 3c 6c 69 3e 3c 62 3e 66 5f 74 61 62 6c 65  ..<li><b>f_table
0b00: 5f 6e 61 6d 65 3c 2f 62 3e 3a 20 74 68 65 20 6e  _name</b>: the n
0b10: 61 6d 65 20 6f 66 20 74 68 65 20 74 61 72 67 65  ame of the targe
0b20: 74 20 74 61 62 6c 65 2e 3c 2f 6c 69 3e 0d 0a 3c  t table.</li>..<
0b30: 6c 69 3e 3c 62 3e 66 5f 67 65 6f 6d 65 74 72 79  li><b>f_geometry
0b40: 5f 63 6f 6c 75 6d 6e 3c 2f 62 3e 3a 20 74 68 65  _column</b>: the
0b50: 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 74 61 72   name of the tar
0b60: 67 65 74 20 67 65 6f 6d 65 74 72 79 2e 3c 2f 6c  get geometry.</l
0b70: 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 6f 72 69 67 69  i>..<li><b>origi
0b80: 6e 5f 72 6f 77 69 64 3c 2f 62 3e 3a 20 74 68 65  n_rowid</b>: the
0b90: 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 52   corresponding R
0ba0: 4f 57 49 44 20 69 6e 74 6f 20 74 68 65 20 6f 72  OWID into the or
0bb0: 69 67 69 6e 20 74 61 62 6c 65 2e 3c 2f 6c 69 3e  igin table.</li>
0bc0: 0d 0a 3c 6c 69 3e 3c 62 3e 69 74 65 6d 5f 6e 6f  ..<li><b>item_no
0bd0: 3c 2f 62 3e 3a 20 70 72 6f 67 72 65 73 73 69 76  </b>: progressiv
0be0: 65 20 6e 75 6d 62 65 72 20 69 6e 64 69 76 69 64  e number individ
0bf0: 75 61 6c 6c 79 20 69 64 65 6e 74 69 66 79 69 6e  ually identifyin
0c00: 67 20 65 61 63 68 20 65 6c 65 6d 65 6e 74 61 72  g each elementar
0c10: 79 20 47 65 6f 6d 65 74 72 79 20 77 69 74 68 69  y Geometry withi
0c20: 6e 20 69 74 73 20 52 4f 57 49 44 20 66 61 6d 69  n its ROWID fami
0c30: 6c 79 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62  ly.</li>..<li><b
0c40: 3e 67 65 6f 6d 65 74 72 79 3c 2f 62 3e 3a 20 61  >geometry</b>: a
0c50: 6e 20 65 6c 65 6d 65 6e 74 61 72 79 20 47 65 6f  n elementary Geo
0c60: 6d 65 74 72 79 20 69 74 65 6d 2e 3c 2f 6c 69 3e  metry item.</li>
0c70: 0d 0a 3c 2f 75 6c 3e 3c 2f 6c 69 3e 0d 0a 3c 6c  ..</ul></li>..<l
0c80: 69 3e 65 76 65 72 79 20 3c 62 3e 53 45 4c 45 43  i>every <b>SELEC
0c90: 54 3c 2f 62 3e 20 73 74 61 74 65 6d 65 6e 74 20  T</b> statement 
0ca0: 72 65 66 65 72 65 6e 63 69 6e 67 20 3c 62 3e 45  referencing <b>E
0cb0: 6c 65 6d 65 6e 74 61 72 79 47 65 6f 6d 65 74 72  lementaryGeometr
0cc0: 69 65 73 3c 2f 62 3e 20 6d 75 73 74 20 69 6e 63  ies</b> must inc
0cd0: 6c 75 64 65 20 61 20 3c 62 3e 57 48 45 52 45 3c  lude a <b>WHERE<
0ce0: 2f 62 3e 20 63 6c 61 75 73 65 20 73 70 65 63 69  /b> clause speci
0cf0: 66 79 69 6e 67 20 61 74 20 6c 65 61 73 74 20 74  fying at least t
0d00: 68 65 20 69 6e 74 65 6e 64 65 64 20 3c 62 3e 66  he intended <b>f
0d10: 5f 74 61 62 6c 65 5f 6e 61 6d 65 3c 2f 62 3e 20  _table_name</b> 
0d20: 61 6e 64 20 3c 62 3e 6f 72 69 67 69 6e 5f 72 6f  and <b>origin_ro
0d30: 77 69 64 3c 2f 62 3e 20 76 61 6c 75 65 73 2e 3c  wid</b> values.<
0d40: 62 72 3e 0d 0a 54 68 65 20 3c 62 3e 64 62 5f 70  br>..The <b>db_p
0d50: 72 65 66 69 78 3c 2f 62 3e 20 65 6c 65 6d 65 6e  refix</b> elemen
0d60: 74 20 69 66 20 6e 6f 74 20 73 70 65 63 69 66 69  t if not specifi
0d70: 65 64 20 61 6c 77 61 79 73 20 69 6d 70 6c 69 65  ed always implie
0d80: 73 20 74 68 65 20 3c 62 3e 6d 61 69 6e 3c 2f 62  s the <b>main</b
0d90: 3e 20 44 42 2e 3c 62 72 3e 0d 0a 53 70 65 63 69  > DB.<br>..Speci
0da0: 66 79 69 6e 67 20 3c 62 3e 66 5f 67 65 6f 6d 65  fying <b>f_geome
0db0: 74 72 79 5f 63 6f 6c 75 6d 6e 3c 2f 62 3e 20 69  try_column</b> i
0dc0: 73 20 6f 70 74 69 6f 6e 61 6c 2c 20 65 78 63 65  s optional, exce
0dd0: 70 74 20 77 68 65 6e 20 74 68 65 20 74 61 72 67  pt when the targ
0de0: 65 74 20 74 61 62 6c 65 20 73 75 70 70 6f 72 74  et table support
0df0: 73 20 6d 6f 72 65 20 74 68 61 6e 20 61 20 73 69  s more than a si
0e00: 6e 67 6c 65 20 47 65 6f 6d 65 74 72 79 20 63 6f  ngle Geometry co
0e10: 6c 75 6d 6e 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c  lumn.</li>..</ul
0e20: 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53  >..<verbatim>..S
0e30: 45 4c 45 43 54 20 74 2e 69 64 2c 20 65 2e 69 74  ELECT t.id, e.it
0e40: 65 6d 5f 6e 6f 2c 20 74 2e 6e 61 6d 65 2c 20 53  em_no, t.name, S
0e50: 54 5f 41 73 54 65 78 74 28 65 2e 67 65 6f 6d 65  T_AsText(e.geome
0e60: 74 72 79 29 0d 0a 46 52 4f 4d 20 74 65 73 74 20  try)..FROM test 
0e70: 41 53 20 74 0d 0a 4a 4f 49 4e 20 45 6c 65 6d 65  AS t..JOIN Eleme
0e80: 6e 74 61 72 79 47 65 6f 6d 65 74 72 69 65 73 20  ntaryGeometries 
0e90: 41 53 20 65 20 4f 4e 20 28 65 2e 66 5f 74 61 62  AS e ON (e.f_tab
0ea0: 6c 65 5f 6e 61 6d 65 20 3d 20 27 74 65 73 74 27  le_name = 'test'
0eb0: 20 41 4e 44 20 65 2e 6f 72 69 67 69 6e 5f 72 6f   AND e.origin_ro
0ec0: 77 69 64 20 3d 20 74 2e 69 64 29 3b 0d 0a 2d 2d  wid = t.id);..--
0ed0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0ee0: 2d 2d 2d 0d 0a 31 09 30 09 6f 6e 65 09 4c 49 4e  ---..1.0.one.LIN
0ef0: 45 53 54 52 49 4e 47 28 30 20 30 2c 20 30 20 31  ESTRING(0 0, 0 1
0f00: 29 0d 0a 32 09 30 09 74 77 6f 09 4c 49 4e 45 53  )..2.0.two.LINES
0f10: 54 52 49 4e 47 28 31 30 20 31 30 2c 20 31 30 20  TRING(10 10, 10 
0f20: 31 31 29 0d 0a 32 09 31 09 74 77 6f 09 4c 49 4e  11)..2.1.two.LIN
0f30: 45 53 54 52 49 4e 47 28 31 31 20 31 30 2c 20 31  ESTRING(11 10, 1
0f40: 31 20 31 31 29 0d 0a 33 09 30 09 74 68 72 65 65  1 11)..3.0.three
0f50: 09 4c 49 4e 45 53 54 52 49 4e 47 28 32 30 20 32  .LINESTRING(20 2
0f60: 30 2c 20 32 30 20 32 31 29 0d 0a 33 09 31 09 74  0, 20 21)..3.1.t
0f70: 68 72 65 65 09 4c 49 4e 45 53 54 52 49 4e 47 28  hree.LINESTRING(
0f80: 32 31 20 32 30 2c 20 32 31 20 32 31 29 0d 0a 33  21 20, 21 21)..3
0f90: 09 32 09 74 68 72 65 65 09 4c 49 4e 45 53 54 52  .2.three.LINESTR
0fa0: 49 4e 47 28 32 32 20 32 30 2c 20 32 32 20 32 31  ING(22 20, 22 21
0fb0: 29 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a  )..</verbatim>..
0fc0: 54 68 69 73 20 66 69 6e 61 6c 20 65 78 61 6d 70  This final examp
0fd0: 6c 65 20 73 68 6f 77 73 20 68 6f 77 20 79 6f 75  le shows how you
0fe0: 20 63 61 6e 20 63 6f 6e 73 74 72 75 63 74 20 61   can construct a
0ff0: 20 53 51 4c 20 71 75 65 72 79 20 64 79 6e 61 6d   SQL query dynam
1000: 69 63 61 6c 6c 79 20 72 65 73 6f 6c 76 69 6e 67  ically resolving
1010: 0d 0a 61 6c 6c 20 63 6f 6d 70 6c 65 78 20 67 65  ..all complex ge
1020: 6f 6d 65 74 72 69 65 73 20 66 6f 72 6d 20 61 20  ometries form a 
1030: 77 68 6f 6c 65 20 74 61 62 6c 65 20 69 6e 74 6f  whole table into
1040: 20 69 6e 64 69 76 69 64 75 61 6c 20 65 6c 65 6d   individual elem
1050: 65 6e 74 61 72 79 20 69 74 65 6d 73 2e 0a 5a 20  entary items..Z 
1060: 64 34 39 32 64 66 39 37 31 35 31 63 61 33 32 38  d492df97151ca328
1070: 31 36 35 65 34 39 39 35 31 63 30 64 36 65 66 64  165e49951c0d6efd
1080: 0a                                               .