Linked Values¶
Linked Values¶
1# This script demonstrates how db values may be read/written using lookup values
2
3ot = impact.gui.output_toolbox
4
5d = impact.active_drawing
6
7if not d.isNone():
8
9 # If a Table Relationship link is configured from an internal column to a custom table,
10 # it can be used in IDatabaseValues.load/Save. For example with DRAWINGS.d_market linked
11 # to MARKETS.m_key, you can then read/write any column in the MARKETS table using
12 # the D_MARKET link.
13
14 # If no Table Relationship is configured, you can also use an Advanced Query lookup from
15 # an internal column to a custom table. It can also be used in both IDatabaseValues.load/Save.
16 # However you must always use the defined display column in this case. For example with MARKETS.m_name
17 # defined as a lookup for DRAWINGS.d_market you can set values for D_MARKET.
18
19 # Use can use the relationship key syntax, or the shorthand syntax.
20 # Only ipDatabaseColumnType.dctInteger and ipDatabaseColumnType.dctCharacter lookup columns can be used to save values.
21
22 ot.add("--- Displaying any field from linked table ---")
23 ot.add("D_MARKET: " + d.database_values.load("D_MARKET"))
24 ot.add("D_MARKET: " + d.database_values.load("D_MARKET:M_NAME"))
25 ot.add("D_MARKET: " + d.database_values.load("D_MARKET:M_DESC"))
26 ot.add("D_MARKET: " + d.database_values.load("D_MARKET:M_DIST"))
27 ot.add("D_MARKET: " + d.database_values.load("D_MARKET:M_DATE"))
28 ot.add("D_MARKET: " + d.database_values.load("D_MARKET->MARKETS.M_NAME"))
29
30 ot.add("D_MARKET: " + d.database_values.load("D_SEGMENT"))
31 ot.add("D_MARKET: " + d.database_values.load("D_SEGMENT:MS_SEGMENT"))
32 ot.add("D_MARKET: " + d.database_values.load("D_SEGMENT->MARKSEG.MS_SEGMENT"))
33
34 # Remember for LAYERS columns you also need to qualify the child column name
35 # ot.add() "L_LAYRSTAT: " + d.active_layer.database_values.load("LAYERS.L_LAYRSTAT:ST_STATUS")
36 # ot.add() "L_LAYRSTAT: " + d.active_layer.database_values.load("LAYERS.L_LAYRSTAT->PLSTATUS.ST_STATUS")
37
38 # You can set values for D_MARKET using lookup values. If the value doesn't exist then None is assigned.
39 # You can check a value is assigned by re-reading the value.
40
41 ot.add("--- Setting by Index ---")
42 d.database_values.save("D_MARKET", 2)
43 ot.add("D_MARKET: " + d.database_values.load("D_MARKET"))
44 ot.add("D_MARKET: " + d.database_values.load("D_MARKET:M_NAME"))
45
46 ot.add("--- Setting by Lookup Choice ---")
47 d.database_values.save("D_MARKET:M_NAME", "Produce")
48 ot.add("D_MARKET: " + d.database_values.load("D_MARKET"))
49 ot.add("D_MARKET: " + d.database_values.load("D_MARKET:M_NAME"))
50
51 d.database_values.save("D_MARKET->MARKETS.M_NAME", "Computers")
52 ot.add("D_MARKET: " + d.database_values.load("D_MARKET"))
53 ot.add("D_MARKET: " + d.database_values.load("D_MARKET->MARKETS.M_NAME"))